Loading Terragen OBJ

Hi,

I had modified the obj loader to generate per-vertex color data. The color value is based on the Z coord.

Because the terragen obj exporter don´t generate normals, i exported the terragen data into lwo files, then imported in blender and exported in obj. Blender not only generate normals, but also material files.

The results:

http://personales.ya.com/angon/screen.jpg

This is the jar with the classes: http://personales.ya.com/angon/terragenInXith.jar

Those are the files you need: http://personales.ya.com/angon/xith_pruebas/files/terreno3.obj (7MB), http://personales.ya.com/angon/xith_pruebas/files/terreno3.mtl

When generate terragen files, limit the height between 0 and 256.
Be careful with the size of the terrain or you have out of memory errors!!

I´m working with Xith3d for short time and my english is very poor, don’t kill me :wink:

thanks all

I forgot:

use cursors, re-pag and av-pag to move

left click + mouse motion to rotate

I get the following exeption loading the obj file:


org.angon.xith3d.loader.obj.OBJTerragenLoader:  ignoring unknown OBJ tag:  "HTTP/1.1 200 OK"
org.angon.xith3d.loader.obj.OBJTerragenLoader:  ignoring unknown OBJ tag:  "Date: Mon, 23 Jan 2006 17:39:10 GMT"
org.angon.xith3d.loader.obj.OBJTerragenLoader:  ignoring unknown OBJ tag:  "Server: Apache"
org.angon.xith3d.loader.obj.OBJTerragenLoader:  ignoring unknown OBJ tag:  "cache-control: no-cache"
org.angon.xith3d.loader.obj.OBJTerragenLoader:  ignoring unknown OBJ tag:  "P3P: CP='NOI DSP COR CURa ADMa DEVa TAIa PSAa PSDa OUR IND UNI C
OM NAV INT CNT', policyref = 'http://personales.ya.com/w3c/p3p.xml'"
org.angon.xith3d.loader.obj.OBJTerragenLoader:  ignoring unknown OBJ tag:  "Keep-Alive: timeout=15, max=999"
org.angon.xith3d.loader.obj.OBJTerragenLoader:  ignoring unknown OBJ tag:  "Connection: Keep-Alive"
org.angon.xith3d.loader.obj.OBJTerragenLoader:  ignoring unknown OBJ tag:  "Transfer-Encoding: chunked"
org.angon.xith3d.loader.obj.OBJTerragenLoader:  ignoring unknown OBJ tag:  "Content-Type: text/plain"
org.angon.xith3d.loader.obj.OBJTerragenLoader:  ignoring unknown OBJ tag:  "2000"
org.xith3d.loaders.obj.MaterialLibLoader2:  ignoring unknown material tag:  "d 1.000000"
org.xith3d.loaders.obj.MaterialLibLoader2:  ignoring unknown material tag:  "illum 2"
org.angon.xith3d.loader.obj.OBJTerragenLoader:  ignoring unknown OBJ tag:  "o terreno2_terreno2"
java.util.NoSuchElementException
java.util.NoSuchElementException
        at java.util.StringTokenizer.nextToken(StringTokenizer.java:332)
        at org.xith3d.loaders.obj.VertexList.add(VertexList.java:25)
        at org.angon.xith3d.loader.obj.OBJTerragenLoader.load(OBJTerragenLoader.java:72)
        at org.xith3d.loaders.obj.OBJLoader2.load(OBJLoader2.java:207)
        at org.xith3d.loaders.obj.OBJLoader2.load(OBJLoader2.java:194)
        at org.angon.xith3d.loader.obj.OBJTerragenLoader.load(OBJTerragenLoader.java:35)
        at org.angon.xith3d.loader.obj.test.OBJTerragenTest.loadOBJ(OBJTerragenTest.java:166)
        at org.angon.xith3d.loader.obj.test.OBJTerragenTest.access$1(OBJTerragenTest.java:161)
        at org.angon.xith3d.loader.obj.test.OBJTerragenTest$1.actionPerformed(OBJTerragenTest.java:122)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
        at javax.swing.AbstractButton.doClick(AbstractButton.java:302)
        at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1000)
        at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1041)
        at java.awt.Component.processMouseEvent(Component.java:5488)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
        at java.awt.Component.processEvent(Component.java:5253)
        at java.awt.Container.processEvent(Container.java:1966)
        at java.awt.Component.dispatchEventImpl(Component.java:3955)
        at java.awt.Container.dispatchEventImpl(Container.java:2024)
        at java.awt.Component.dispatchEvent(Component.java:3803)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
        at java.awt.Container.dispatchEventImpl(Container.java:2010)
        at java.awt.Component.dispatchEvent(Component.java:3803)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at com.xith3d.scenegraph.Group.addChild(Group.java:78)
        at org.angon.xith3d.loader.obj.test.OBJTerragenTest$1.actionPerformed(OBJTerragenTest.java:122)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
        at javax.swing.AbstractButton.doClick(AbstractButton.java:302)
        at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1000)
        at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1041)
        at java.awt.Component.processMouseEvent(Component.java:5488)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
        at java.awt.Component.processEvent(Component.java:5253)
        at java.awt.Container.processEvent(Container.java:1966)
        at java.awt.Component.dispatchEventImpl(Component.java:3955)
        at java.awt.Container.dispatchEventImpl(Container.java:2024)
        at java.awt.Component.dispatchEvent(Component.java:3803)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
        at java.awt.Container.dispatchEventImpl(Container.java:2010)
        at java.awt.Component.dispatchEvent(Component.java:3803)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

Im using Java 1.5.0_04…
The exception seems to come from the StringTokenizer and not from your code.
If you can tell on what versions you have tested it on id be pleased to try testing this again :slight_smile:

Obviously you’re parsing an HTTP-header… why?

I don´t know where the bug is ???

Please, download the obj and the mtl to the hard disk. Verify the obj don´t have HTTP-header inserted by the web server. This is the begining of the file:

# Blender OBJ File: C:/blender/blender-2.37a-windows/.blender/untitled.blend
# www.blender.org
mtllib terreno3.mtl
o terreno2_terreno2
v 0.000000 0.000000 73.066330
v 11.718750 0.000000 71.002365
v 23.437500 0.000000 65.095154
v 35.156250 0.000000 59.269215
v 46.875000 0.000000 51.538433
v 58.593750 0.000000 50.123905
v 70.312500 0.000000 51.307514
v 82.031250 0.000000 50.007015
v 93.750000 0.000000 48.594082
v 105.468750 0.000000 42.627319
v 117.187500 0.000000 37.938297
v 128.906250 0.000000 37.162228
v 140.625000 0.000000 34.147972
v 152.343750 0.000000 29.164997
v 164.062500 0.000000 26.168726
v 175.781250 0.000000 25.259737

You can see the source code. The obj loader is still the same. Try to load another obj, please.

I´m using java 1.4.2_08, but i test it with 1.5 and works.

I know this is a noobie question but what is the advantage of generating normals and material files?

I am currently just loading an Obj file exported from Terragen and am wondering about the benifits
of changing my setup to something similar to angon2006’s. Could anyone tell me the pros / cons
to altering my setup?

Thanks

I begin loading a terragen exported obj, but the result terrain was very “flat”.

To calculate the lighting, i think, the render engine use the material of the face, the light sources and the face normal. Also it´s use the vertex color.

When you load and obj without material/normals, you can generate it. Extends DefaultNodeFactory class and make the work that blender do for me. It´ll been a better method than mine.

Someone know, if in xith, are something like Java3D’s NormalGenerator?? Having the face with her 3 vertex, it´s may be easy to obtain the normal. ???

Ok, so thats the problem, ill remove the header and test again :wink:

IIRC, there is a function in Xith that compute the normals for a whole mesh. But I remember using it I got numerous error messages, and I abandoned it (because 2D game = only textured quads, normals specified by hand :smiley: )