JME2 tutorials

Hi all, im new to JME and 3d programming but im working with JME2 now, and im going through the tutorials now.

All tutorials needed some modification in order to work with JME2, some of them were already described in the wiki JME to JME2 changes. I managed to get them all fixed untill i encounterd example 12 Hello_LOD.

This one simply does not work, i get a null pointer exception… and i cant figure out what i should change.

the exception:



19-sep-2008 14:31:22 class HelloLOD start()

SEVERE: Exception in game loop

java.lang.NullPointerException

at com.jme.scene.lod.ClodMesh.<init>(ClodMesh.java:105)

at com.jme.scene.lod.AreaClodMesh.<init>(AreaClodMesh.java:101)

at HelloLOD.getClodNodeFromParent(HelloLOD.java:139)

at HelloLOD.simpleInitGame(HelloLOD.java:95)

at com.jme.app.BaseSimpleGame.initGame(BaseSimpleGame.java:527)

at com.jme.app.BaseGame.start(BaseGame.java:71)

at HelloLOD.main(HelloLOD.java:45)



The exception comes from the line:

AreaClodMesh acm = new AreaClodMesh("part" + i,(TriMesh) meshParent.getChild(i), null);



I even tried giving the child a texture (using the HelloKeyInput example)

but it didnt work… does anyone know how to solve this?



thank you in advance,



ps: some contributions for the 'JME to JME2 changes' wiki page:



HelloNode

JME1 =

rootNode.setLightCombineMode(LightState.OFF);

JME2 =

rootNode.setLightCombineMode(rootNode.getLightCombineMode().Off);



HelloTrimash:

JME1=

m.reconstruct(BufferUtils.createFloatBuffer(vertexes),BufferUtils.createFloatBuffer(normals),

BufferUtils.createFloatBuffer(colors),BufferUtils.createFloatBuffer(texCoords),

BufferUtils.createIntBuffer(indexes));

JME2=

  m.reconstruct(BufferUtils.createFloatBuffer(vertexes),BufferUtils.createFloatBuffer(normals),

BufferUtils.createFloatBuffer(colors),new TexCoords(BufferUtils.createFloatBuffer(texCoords)),

BufferUtils.createIntBuffer(indexes));



HelloMousePick

JME1=

as.setTestFunction(AlphaState.TF_GREATER);



JME2=

BlendState.TestFunction.GreaterThan





fpsNode = statNode





Errors in text:

hello_states

monkeyLoc = HelloStates.class.getClassLoader().getResource("jmetest/data/images/Monkey.tga"); should be:

monkeyLoc = HelloStates.class.getClassLoader().getResource("jmetest/data/images/Monkey.jpg");

In the tables, 'my box' has the texture, not sphere.



HelloKeyInput

getResource("jmetest/data/images/Monkey.tga"); = getResource("jmetest/data/images/Monkey.jpg");

I am working on making the tutorials jME 2, but I am still at the installation step(as you can see), but you can find the source for the jME 2 versions of the tutorials in the src/com/jMEtest folder. If you scroll down there is a folder for it. That code should work fine.

I am getting the same NullPointerException by using the LOD tutorial that came with JME2 from svn.



Sep 19, 2008 7:01:02 PM class jmetest.TutorialGuide.HelloLOD start()

SEVERE: Exception in game loop

java.lang.NullPointerException

at com.jme.scene.lod.ClodMesh.<init>(ClodMesh.java:105)

at com.jme.scene.lod.AreaClodMesh.<init>(AreaClodMesh.java:101)

at jmetest.TutorialGuide.HelloLOD.getClodNodeFromParent(HelloLOD.java:169)

at jmetest.TutorialGuide.HelloLOD.simpleInitGame(HelloLOD.java:109)

at com.jme.app.BaseSimpleGame.initGame(BaseSimpleGame.java:527)

at com.jme.app.BaseGame.start(BaseGame.java:71)

at jmetest.TutorialGuide.HelloLOD.main(HelloLOD.java:79)

Sep 19, 2008 7:01:02 PM com.jme.app.BaseSimpleGame cleanup

INFO: Cleaning up resources.

Sep 19, 2008 7:01:02 PM com.jme.app.BaseGame start

INFO: Application ending.



This seems to be a problem with the ClodMesh class itself rather than the tutorial.

Hmm… I wonder what that is? I'm sure it will be fixed soon, if not when I make my tutorials on the Wiki for jME 2(The setup guide for Netbeans now goes over compiling and setting up a project with jME 2, yay!).

Hi,



I have the same problem.

Does anyone already has a Solution for the problem?

textBuf is anArray which has 1 element but this is empty. So the Method returns null.

Accessing null.data then trows the NPE.



    public TexCoords getTextureCoords(int textureUnit) {
        if (texBuf == null)
            return null;
        if (textureUnit >= texBuf.size())
            return null;
        return texBuf.get(textureUnit);
    }



initialized is the Array in the Geometry Constructor:


    public Geometry() {
        super();
        texBuf = new ArrayList<TexCoords>(1);
        texBuf.add(null);
    }



so, what to do.

- init the array not with null, but with an actual TexCoords element ?
- add null checks before accessing the return value from getTextureCoords(int textureUnit) ?
- make sure that the Geom has a filled Texturecoords Array before creating the  AreaClodMesh? HelloLOD.java: 169

i'd vote for nr.1

this would be a patch with a simple null check



Index: src/com/jme/scene/lod/ClodMesh.java

===================================================================

— src/com/jme/scene/lod/ClodMesh.java (revision 4031)

+++ src/com/jme/scene/lod/ClodMesh.java (working copy)

@@ -102,7 +102,7 @@

         this(name, BufferUtils.clone(data.getVertexBuffer()),

                 BufferUtils.clone(data.getNormalBuffer()),

                 BufferUtils.clone(data.getColorBuffer()),

-                new TexCoords(BufferUtils.clone(data.getTextureCoords(0).coords)),

+                new TexCoords(BufferUtils.clone(data.getTextureCoords(0)==null?null:data.getTextureCoords(0).coords)),

                 BufferUtils.clone(data.getIndexBuffer()), records);

     }





http://www.jmonkeyengine.com/jmeforum/index.php?topic=9306.0





edit:

this fix is commited now see also issue 17

Hi,how to download user's manual for jME1.0?Thank u!

There isn't really much of a user's guide to be downloaded, but there are lots of tutorials on this site that can be used to teach you about jME.