Skip to main content

Material file not loading?

14 replies [Last post]
zamirathe
Offline
Joined: 2010-07-28

Well, I have gotten a little more progress I suppose, but I am still stuck. It seems my .mtl file is not loading at all. Plus, I have a really weird looking dragon show up. Here is a snippet of my code. Forgive me, I don't know if there are any code bbcodes available here.

WyvernApplet2.java (without FileReader)
int flags = ObjectFile.RESIZE;
if (!noTriangulate) flags |= ObjectFile.TRIANGULATE;
if (!noStripify) flags |= ObjectFile.STRIPIFY;

ObjectFile f = new ObjectFile(flags);
Scene s = null;
if (filename == null) {
filename = "wyvern2poseray.obj";
}
try {
s = f.load(filename);
}
catch (FileNotFoundException e) {
System.err.println(e);
System.exit(1);
}
catch (ParsingErrorException e) {
System.err.println(e);
System.exit(1);
}
catch (IncorrectFormatException e) {
System.err.println(e);
System.exit(1);
}

objTrans.addChild(s.getSceneGroup());

When I have that code, I get these. The code allows for rotation so I moved the dragon so you can see that the wing membranes are not visible until you look at the back of them. http://www.zenathia.com/Wyvern2load1.png and http://www.zenathia.com/Wyvern2load2.png

WyvernApplet2.java (with FileReader)
int flags = ObjectFile.RESIZE;
if (!noTriangulate) flags |= ObjectFile.TRIANGULATE;
if (!noStripify) flags |= ObjectFile.STRIPIFY;

ObjectFile f = new ObjectFile(flags);
Scene s = null;
if (filename == null) {
filename = "wyvern2poseray.obj";
}
try {
s = f.load(new FileReader(filename));
}
catch (FileNotFoundException e) {
System.err.println(e);
System.exit(1);
}
catch (ParsingErrorException e) {
System.err.println(e);
System.exit(1);
}
catch (IncorrectFormatException e) {
System.err.println(e);
System.exit(1);
}

objTrans.addChild(s.getSceneGroup());

Now I get these. You can see there is more definition to the dragon, but still no color and the wing membranes are still only visible from the back.
http://www.zenathia.com/Wyvern2filereader1.png and http://www.zenathia.com/Wyvern2filereader2.png

Here is the beginning of my material file, which is in the same directory as the object file.

#==================================================

#Material list

#This file has been created by PoseRay v3.12.2.456

#3D model to POV-Ray/Moray Converter.

#Author: FlyerX

#Email: flyerx_2000@yahoo.com

#Web: http://mysite.verizon.net/sfg0000/

#==================================================

#==================================================

newmtl SkinBody

Ns 2.5

Ka 0 0 0

Kd 1 0 0

Ks 0 0 0

d 1

#r 0

#blend 0

#cell_hi

#==================================================

newmtl SkinHead

Ns 2.5

Ka 0 0 0

Kd 1 0 0

Ks 0 0 0

d 1

#r 0

#blend 0

#cell_hi

I have checked the .obj file and it has mtllib wyvern2poseray.mtl at the top and each face has a usemtl for it. I don't know how to check to see if it has free form geometry...

I am sorry that I didn't provide a link to the applet itself. I am having file permission errors when I run it as an applet when loading the .obj file when running it on my local system. Which I don't understand since it is in the same directory as the .jar file. I even tried signing the applet and still got a permission error trying to read the file.

Any help would be appreciated as I have been stuck looking at a stark white wyvern for days now and nothing I have tried has worked. Plus, having the wings show up only from the back is a bit weird. As my hubby says, "he has magic wings." Plus, if anyone has an idea for a loader that will read the d for display and make transparent those that have d 0 would be great.

I have uploaded my code (which is modified from the objload example so I understand what is required and why, plus it had everything I was trying to learn in it) as well as all the necessary files in case you want to look at the full files.
http://www.zenathia.com/WyvernApplet2.java
http://www.zenathia.com/wyvern2poseray.obj
http://www.zenathia.com/wyvern2poseray.mtl

Be warned, the object file is 14.4 Megabytes.

Message was edited by: zamirathe

Thought I would add one thing I did find out. I put in the flag REVERSE for the ObjectFile and it turns the dragon black. The front of the wings could now be seen, but not the back. No luck getting the material file to load though.

Message was edited by: zamirathe

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
interactivemesh
Offline
Joined: 2006-06-07

[b]Details[/b]

In the jnlp-dragon-applet sample the applet class and both dragon models are separated into individual Java archives. A model-jar also includes the model's '.mtl'-file or the texture images. So the Java archive is a proper container for one or several models. If the Java runtime doesn't find the models to be loaded in the main applet-jar it searches for them in all the other jars. The model-jars are downloaded from the server and locally cached not before the program requests for them due to the declaration 'download="lazy"'.

This approach works for un-signed Java/FX applets and Web Start applications. For a local application the resources have to be stored within its jar-file if their path is relative (?).

[b]j3dforumdragon2.jar[/b]
com/interactivemesh/j3d/community/test/dragon/J3DForumDragon2.class

[b]dragon2.jar[/b]
com/interactivemesh/j3d/community/test/dragon/J3DForumDragon2/resources/dragon2.mtl
com/interactivemesh/j3d/community/test/dragon/J3DForumDragon2/resources/dragon2.obj

[b]wyvern2poseray.jar[/b]
com/interactivemesh/j3d/community/test/dragon/J3DForumDragon2/resources/wyvern2poseray.mtl
com/interactivemesh/j3d/community/test/dragon/J3DForumDragon2/resources/wyvern2poseray.obj

[b]www.interactivemesh.org/off/dragon/J3DForumDragon2.html[/b]
[code]


[/code]

[b]www.interactivemesh.org/off/dragon/webstart/j3dforumdragon2.jnlp[/b]
[code]

codebase="http://www.interactivemesh.org/off/dragon/webstart/"
href="j3dforumdragon2.jnlp">

J3DForum Dragon2
InteractiveMesh

J3DForum Dragon2





width="1000" height="700" name="J3DForumDragon2">


[/code]

August

Message was edited by: interactivemesh

zamirathe
Offline
Joined: 2010-07-28

Thought I would let you know that when I went to http://www.interactivemesh.org/off/dragon/J3DForumDragon2.html on my Windows (Vista) Desktop that does NOT have Java 3D installed, and using IE 8, I got this:

[code]Aug 13, 2010 1:31:02 AM javax.media.j3d.NativePipeline getSupportedOglVendor
SEVERE: java.lang.UnsatisfiedLinkError: no j3dcore-ogl-chk in java.library.path
java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: no j3dcore-d3d in java.library.path
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.UnsatisfiedLinkError: no j3dcore-d3d in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at javax.media.j3d.NativePipeline$1.run(NativePipeline.java:231)
at java.security.AccessController.doPrivileged(Native Method)
at javax.media.j3d.NativePipeline.loadLibrary(NativePipeline.java:200)
at javax.media.j3d.NativePipeline.loadLibraries(NativePipeline.java:157)
at javax.media.j3d.MasterControl.loadLibraries(MasterControl.java:987)
at javax.media.j3d.VirtualUniverse.(VirtualUniverse.java:299)
at javax.media.j3d.Canvas3D.(Canvas3D.java:3881)
at com.interactivemesh.j3d.community.test.dragon.J3DForumDragon2.(J3DForumDragon2.java:149)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception: java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: no j3dcore-d3d in java.library.path[/code]

I took your jnlp code and modified it to run my applet. I did get it to not produce the error that I gave above. However, in order to do it, I had to put in http://download.java.net/media/java3d/webstart/release/java3d-1.5.1.jnlp instead of http://download.java.net/media/java3d/webstart/release/java3d-latest.jnlp to get it to work. Apparently it doesn't like the update to 1.5.2. I still get security errors as my jar file isn't signed, but I can deal with that.

Message was edited by: zamirathe

interactivemesh
Offline
Joined: 2006-06-07

The dragon applet runs fine on my Vista 64 bit/JRE 6u21-b07 system with IE 8 32 and 64 bit. Your exception is thrown on my Win 7 64 bit/JRE 6u21-b07 system with IE 8 64 bit. Please, see also the corresponding JNLP thread.

Would you consider making your dragon models public/open source (Java 3D license)? Would it be okay if I continue using the two published models for further tests even if there is no license so far?

August

zamirathe
Offline
Joined: 2010-07-28

Since I forgot to mention, my Vista desktop is 32 bit and my Linux (Ubuntu) laptop is also 32 bit.

Actually, I am working on the programming for someone else. I do know for a fact that the models themselves were bought from http://www.daz3d.com/, loaded into Daz Studio, and then she exported it as an obj file and sent it to me. To be quite honest, I am not even sure if Daz will allow the usage of their models in Java 3D. Thank you for making me realize that. I have personally sent Daz an email on the issue. I am going to remove the unpackaged object files from my website until told otherwise. I will let you know what I am told. Hopefully it will only be a few days.

Though since they do have a license on the Daz website, they cannot be made open source.

interactivemesh
Offline
Joined: 2006-06-07

I removed all files from my server and all links in this thread to be on the safe side. August

interactivemesh
Offline
Joined: 2006-06-07

removed

Message was edited by: interactivemesh

zamirathe
Offline
Joined: 2010-07-28

Well, I thought about it today, and I have come to the conclusion that having a little bit longer download initially would be better than the space needed to hold possibly hundreds or even thousands of obj files for each dragon. Since there are over 4 million combinations for one dragon, and 4 dragon types, I don't think any server can hold that amount of object files. I will just have Java do the coloration for me.

Now to research off-screen rendering to create thumbnails of the dragons.

Thank you interactivemesh for your help! I really appreciate it. Though it still worries me that you couldn't load the applet when it used Applet Viewer. I got it to load in Firefox, Chrome (on Linux) and IE (Windows Vista) with no problems.

interactivemesh
Offline
Joined: 2006-06-07

Hi,

in none of the Material properties in your '.mtl' file the [b]'illum'[/b] attribute is set. The default value in the Java 3D obj-Loader is set to '0'. In consequence 'Material.setLightingEnable(false)' is called which results in a white rendered model. I added 'illum 2' to each Material and got a colored dragon.

See also javadoc of com.sun.j3d.loaders.objectfile.ObjectFile

August

zamirathe
Offline
Joined: 2010-07-28

I tried that, putting the illum after the d, and then before the Ns and I still got a white dragon.

I brought up my windows machine and installed everything on it. I am still getting the same thing. White dragon with wing membranes only showing from the back. So it isn't my installation on my Linux machine. The windows is running the latest jdk and jre as well as the latest Java 3d.

Each of the materials in the material file now look like this.

newmtl SkinBody

Ka 0 0 0

Kd 1 0 0

Ks 0 0 0

illum 2

Ns 2.5

d 1

#r 0

#blend 0

#cell_hi

Still no color.

Message was edited by: zamirathe

interactivemesh
Offline
Joined: 2006-06-07

[b]zamirathe[/b], you are right: when using your source code (what I haven't done before) the dragon will be rendered in white color even if 'illum 2' is added. I assume the issue is caused by the FileReader. As you plan to run your program as an applet the following loading approach is recommended:

- add a 'resources' folder to your source code folder and place the '.obj' and '.mtl' files there

../WyvernApplet2.java
../resources/wyvern2poseray.obj
../resources/wyvern2poseray.mtl

- replace 's = f.load(new FileReader(filename))' with

[code]
import java.net.URL;

URL dragonUrl = this.getClass().getResource("resources/wyvern2poseray.obj");
s = f.load(dragonUrl);
[/code]
- ensure that the resources with their full path are added to your archive WyvernApplet2.jar

- as your dragon is already triangulated the flag TRIANGULATE should not be set

[b]Issue 2[/b]: The wing membranes are still only visible from the back.

The wings are constructed with a backside only. To make this side also visible from the front add a PolygonAttributes instance to all wing Appearances before the dragon is added to the scene graph:

[code]
Hashtable namedObjects = s.getNamedObjects();

String[] names = {"lforearm", "lwingfinger1", "lwingfinger2", "lwingfinger3",
"rforearm", "rwingfinger1", "rwingfinger2", "rwingfinger3" };

PolygonAttributes polygonAttr = new PolygonAttributes();
polygonAttr.setCullFace(PolygonAttributes.CULL_NONE);
polygonAttr.setBackFaceNormalFlip(true);

for (String name : names) {
Shape3D shape = (Shape3D)namedObjects.get(name);
shape.getAppearance().setPolygonAttributes(polygonAttr);
}
[/code]
[b]Issue 3[/b]: Enclose your code with [code ] and [/code ] (Drop the blanks).

Hope this helps. Any issue left?

August

zamirathe
Offline
Joined: 2010-07-28

I will try what you said, thank you! I actually just figured out the PolygonAttributes trick right before I checked this post again for today and in turn found out you can't set more than one appearance to an object.

I did not see this answered in a previous thread. Is putting the .obj and .mtl files in the jar file mandatory? I want to keep the loading for people running the applet to a minimum, and that means putting the huge object files outside of the jar. Especially since I am looking at 6-7 object files, each 14-20 Megs a piece.

Now, I know an applet by default is untrusted, but it won't read the .obj file when it is in the same directory. Do I need to use the URL functions to open up a connection to the "host", even if it is only running on my computer for testing?

Okay, I tried what you said and it worked partially. The wings now show correctly, but still no color. It does finally work as an applet now though! So, to see what I mean, go to http://www.zenathia.com/javatest.html

To see the source, you can download them at:
http://www.zenathia.com/WyvernApplet4.java
http://www.zenathia.com/resources/dragon2.obj
http://www.zenathia.com/resources/dragon2.mtl

I will make some changes to my model where the Java did the coloring to show you what it should look like. I'll post again when I get it uploaded.

Actually, that went faster than I thought. Here is how it should look.
http://www.zenathia.com/javatest2.html

Message was edited by: zamirathe

Message was edited by: zamirathe

interactivemesh
Offline
Joined: 2006-06-07

First fast reply:

- Your new dragon2.obj file does not include the link to the dragon2.mtl file. Insert 'mtllib dragon2.mtl' before the first 'v' line. Then the color will be shown.

- None of your applets run on my system. The exceptions 'java.lang.ClassNotFoundException: WyvernApplet4' and 'java.lang.ClassNotFoundException: WyvernApplet5' are thrown, although these classes are there as far as I found out. I ran them successful locally. (Even this Java 3D sample doesn't run: https://java3d.dev.java.net/applets/FourByFour.html)

- To solve this and to answer your other question I will create a JNLP-file for dragon2 and install it on my server.

August

zamirathe
Offline
Joined: 2010-07-28

Ah yes, I forgot I had taken out the reference to the material file after it wasn't working. It is loading now, but I guess I need to adjust the coloration a bit.

I wonder why you can't load the applet. It is using the Applet Launcher. It runs fine on my 3 computers here at home with the Java 6 update 21 plugin installed. I specifically wanted it so that people didn't have to have anything but the plugin installed to see it.

The applet you have is really interesting. I'll see if I can pull up the jnlp you created to see what it does.

To give some more info, I want to create these dragons images on the fly. There will only be one dragon shown per applet, but the coloration is based on the dragon's genetics. A total of 5 areas (which I put a different color in each of my test models) and 21 possible colors for each. I know how to do all the genetic code through php. I wanted to be able to just copy the appropriate obj and mtl file to a dragons folder, rename them to the dragon number, edit the object file to point to the right mtl file, edit the mtl file to have the correct coloration, then send parameters to the applet for which obj file to pull, and which parts to make transparent (they might not have horns at all for an example). The applet would then load up the object and material file for that dragon, make the parts transparent, set up the mouse controls, and display the dragon. I would like to know if something like that is even possible. If it isn't, then I could have the Java do the coloration as in my javatest2 example. It would take longer to display, but it is better than trying to figure out how to break up png files into layers and layer a dragon together with php for a static image. :)

Hope that helps to understand why I am asking all these questions.

interactivemesh
Offline
Joined: 2006-06-07

Some ideas:

- Don't use the mtl-file, ignore the loaded Appearance
- Create 21 Appearances for the 21 possible colors
- Assign the appropriate Appearance to all Shape3Ds of one area

- Drop the texture coordinates to reduce the file size if no texture image is used
- Drop the normals if smoothing groups are declared within the file and let the loader calculate them

August