Locked SharedMesh example

hi everyone, I was trying to lock a sharedmesh and I was getting lots of flat colored textures or no performance gains.I couldnt find an example so after I got it to work I made a quick test class, and here it is, youll have to substitute your image for wood.png

public class TestLockedSharedMesh extends SimpleGame {

   public static void main(String[] args) {
      TestLockedSharedMesh app = new TestLockedSharedMesh();
      app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG);
      app.start();

   }

   protected void simpleInitGame() {
      cam.setLocation(new Vector3f(0f, 0f, 1100f));
      cam.setDirection(new Vector3f(0, 0, -1));
      cam.update();
      lightState.setEnabled(false);

      URL url;
      url = this.getClass().getClassLoader().getResource("wood.png");

      TextureState ts = display.getRenderer().createTextureState();
      Texture t0 = TextureManager.loadTexture(url, Texture.MM_LINEAR,
            Texture.FM_LINEAR);

      ts.setTexture(t0);

      AlphaState as = DisplaySystem.getDisplaySystem().getRenderer()
            .createAlphaState();
      as.setEnabled(true);
      as.setBlendEnabled(true);
      as.setSrcFunction(AlphaState.SB_SRC_ALPHA);
      as.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);
      as.setTestEnabled(true);
      as.setTestFunction(AlphaState.TF_GREATER);

      Quad quad = new Quad("quad", 32, 32);
      quad.setModelBound(new BoundingBox());
      quad.updateModelBound();
      quad.setRenderState(ts);
      quad.setRenderState(as);
      // this lock doesnt work
      // quad.lock();

      for (int x = 0; x < 1000; x++) {
         // Test.this.x = x;
         SharedMesh sm = new SharedMesh("Share", quad);

         sm.getLocalTranslation().z = x;

         sm.updateGeometricState(0, false);
         // this lock works
         sm.lock();
         rootNode.attachChild(sm);

      }
      // this lock doesnt work
      // quad.lock();

   }

}


If you take a look at this thread, I am seeing exactly the same thing.

I believe mud2005 is saying he got it working and his code is an example of it working… ?

I believe mud2005 is saying he got it working and his code is an example of it working... ?
yes, sorry if I didnt make that clear.

If you take a look at this thread, I am seeing exactly the same thing.
yeah thats why I posted this, funny thing is now that im trying I cant seem to recreate the "flat color" problem. before thats all I could get.

Whoops, yes I see that now.  Basically I tried the exact same things and the only way I made it work was similar to what you are doing, though, I put all the SharedMeshes into a node and then locked that node which I think has the same effect, but now that I think about it, I'll try it both ways and see if there's a difference.



It was suggested to try and lock the target mesh as well, and any time I did that I got the same result you had - flat colored Meshes every time.  I've also gotten one mesh to be textured properly and all other meshes present but "invisible" - no color, no texture, nothing, but if I turned on bounding boxes I could see them.  This all came from experimenting on trying to lock the target mesh.  Locking the SharedMesh node doesn't seem to cause these issues, but I wondered if I was getting the maximum benefit out of it - seems like I am.

I've also gotten one mesh to be textured properly and all other meshes present but "invisible" - no color, no texture, nothing, but if I turned on bounding boxes I could see them.
yup thats what happens in the above example if you uncomment either one of the locks on the quad.