Bump mapping with node

i used the testBumpMappimg.java

in this example Mark Powell used a torus and i want to use a model

which i load

  Node maggie = null;
             
               try {
               converter.convert(model.openStream(), BO);
                 maggie = (Node) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
            } catch (IOException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
            }
             maggie.setModelBound(new BoundingSphere());
             maggie.updateModelBound();



a few lines later i want to use the example code

  BumpMapColorController c = new BumpMapColorController(maggie);
               maggie.addController(c); // npe

             MaterialState ms = DisplaySystem.getDisplaySystem().getRenderer()
                   .createMaterialState();
             ms.setColorMaterial(MaterialState.CM_DIFFUSE);
             maggie.setRenderState(ms);
             maggie.updateRenderState();


it works fine with the torus object but not with a node

also a little bit later these lines aren`t possible

//maggie.copyTextureCoords(0, 0, 1);
             //maggie.getBatch(0).scaleTextureCoordinates(0, 8);


also works fine with torus

so.. is node the wrong class ?

u need to copy the texture coordinates onto the actual geometry objects like TriMesh or TriangleBatch.

sorry but  :?


TriMesh tm = new TriMesh();
tm.copyTextureCoords(0, 0, 1);



i have now idee, there is now connection between node and mesh

A node can have a Geometry as a child, which a TriMesh is… the TriMesh contains batches, which in its own contain texture information, vertex information, etc.



In other words:



Node —> Geometry —> TriMesh —> Batch —> FloatBuffer



Where arrows denote containing, not inheritance necessarily.

okay, i can create a quad, call it wall and set up the texture

i can add it the node called maggie and in the end to the rootnode

so i have my model without texture and a wall with texture



but i want want the texture on my model, not a wall or other simple mesh



and the only way to load a model seems to be as a node

i tried to cast it, but now way

You cant apply the bumpmapping to a node, instead you have to apply it to all the children of the node via the method node.getChildren(); These children will most likely be Geometry. You can than apply the bumpmapping to this geometry.



Hope this helps


           ...
           vert.load(TestFragmentProgramState.class.getClassLoader().getResource(BRICK_VP));
           vert.setEnabled(true);
         
           frag.load(TestFragmentProgramState.class.getClassLoader().getResource(BRICK_FP));
           frag.setEnabled(true);
          
           FloatBuffer tex1 = BufferUtils.createVector2Buffer(4);
           FloatBuffer.allocate(400000);
         // tex1.limit(40000);
            for (int x = 0; x < 4; x++){
                tex1.put(1.0f).put(0.0f);
            }
           
           FloatBuffer tex2 = BufferUtils.createVector2Buffer(4);
         // tex2.limit(40000);
           for (int x = 0; x < 4; x++){
               tex2.put(0.0f).put(1.0f);
           }
           for(int i = 0; i < maggie.getChildren().size(); i++){
              
              if(maggie.getChildren().get(i) instanceof Geometry){
                 System.out.println("instanceof");
                 Geometry s = (Geometry) maggie.getChildren().get(i);
                               
              s.setRenderState(brick);
                            
               s.setTextureBuffer(0, tex1, 1); //  ->problem
                           
               s.setTextureBuffer(0, tex2, 2);
                           
              s.setRenderState(vert);
               s.setRenderState(frag);
              
               s.setRenderState(cs);
              
              }
              
           }


SCHWERWIEGEND: Exception in game loop
java.lang.IllegalArgumentException
at java.nio.Buffer.limit(Buffer.java:249)
at com.jme.renderer.lwjgl.LWJGLRenderer.predrawGeometry(Unknown Source)
at com.jme.renderer.lwjgl.LWJGLRenderer.draw(Unknown Source)
at com.jme.scene.batch.TriangleBatch.draw(Unknown Source)
at com.jme.scene.TriMesh.draw(Unknown Source)
at com.jme.scene.Spatial.onDraw(Unknown Source)
at com.jme.scene.Node.draw(Unknown Source)
at com.jme.scene.Spatial.onDraw(Unknown Source)
at com.jme.renderer.lwjgl.LWJGLRenderer.draw(Unknown Source)
at com.jme.renderer.pass.RenderPass.doRender(Unknown Source)
at com.jme.renderer.pass.Pass.renderPass(Unknown Source)
at com.jme.renderer.pass.BasicPassManager.renderPasses(Unknown Source)
at com.jme.app.SimplePassGame.render(Unknown Source)
at com.jme.app.BaseGame.start(Unknown Source)
at demo.demo.main(demo.java:85)

whats wrong with the buffer, is it so hard to create bumpmapping  :?

and no example in the whole internet