How to import VRML into a scenegraph... correctly

I’ve tried several different loaders but with little success. Only some seem to work with the .wrl files I’ve created and, when they do, I can’t get any textures in. The loader I was using was the one available at: http://www.cybergarage.org/vrml/ which loaded the models but no textures or anything… I tried another one that worked but wouldn’t work for MY vrml files. I also tried the XJ3D but, had trouble making it work and I gave up (I didn’t download cygwin like the installation instructions tell you to - I just tried extracting jars and importing the packages created by them). I’m creating my .wrl files from some .flt models that I have using 3Dexploration. There are many options to set when exporting to .wrl and, I think they have an effect on whether the model will end up with textures or not… I have tried many combinations but, I mostly export as VRML 2.0 files with texture and pixel coordinates but nothing else.

–> Does anyone know of a VERY EASY, VERY STRAIGHTFORWARD, VERY SIMPLE way to import a .wrl (or .wrz) model into a Java3D scenegraph (i.e. what loader to use and how EXACTLY to make it work properly including the textures and such.) and what is the PROPER way to export to .wrl?

THANK YOU VERY MUCH in advance…

I use the vrml97.jar. I’m not really sure where I got this loader from. Anyways, it will only do vrml 2.0 and it does load textures; however, the textures get lights applied to them so all objects with textures on them have their own spot light. This is not good if you want to have realistic lighting.

VRML97.jar works fine.

You can find it inside the J3DFlyThrough demo available at the Java3D homepage.

Also with textures you just have to find the TextureAttributes.REPLACE and replace it with TextureAttributes.MODULATE. Its in the file called AppearenceNode as far as I remember.

You can find it by reverse engineering the jar file. Should be ok, because its community-source.

By replacing TextureAttributes.REPLACE, does this fix the lighting issues w/ textures?

yes.

Since you have done the dirty work of de-compiling, anyway of posting that here - or could you e-mail it to me?

Well, if they have a material node offcause.

Your problem is not caused by spotlights, but because there is no lightning applied at all. Only the colours of the textures is applied(REPLACE replaces lighting and shading with texture, MODULATE multiply texture colour values with L&S values).

In fact REPLACE is the VRML97 compliant way to do textures. But it sucks nowadays, where hardware can easily do MODULATE.

So go in and change it…or consider the neverwinternights-loader.

Regards
Nikolai V. Chr.
IFAD A/S

Hmm, I might have it somewhere still.

I dont use vrml97.jar any longer, I switched to the Xj3D project. If you are making your own real-time/gaming engine I can’t advise you to do the same though. After every release its a real pain to use if you only wants a model loader.

Ill take a look and see if I can find it and e-mail you.

Ok, after messing with this for a while I have come up w/ a solution. You can grab the shape objects from the groups. Once you have the shape you can then set the texture attributes you desire. The following code sets the texture attribute to BLEND. I tried all 4 of the differnt modes, MODULATE, DECAL, REPLACE, and BLEND.

BLEND was the only one that when there were no lights, the object w/ texture was dark, and when there were lights, all lighting worked correctly.

     Appearance tempAp = shape.getAppearance();
     TextureAttributes tempAtt = tempAp.getTextureAttributes();
     if(tempAtt != null){
        tempAtt.setTextureMode(TextureAttributes.BLEND);
     }