Model loading doesnt accept a bounding box ? Thread problem?

Ok i have a strange problem. I tried to load some models into a chase view (merged some tutorials).

When i did that with the "obj" file in jmetest it worked fine.

So i tried to load an MD3 model (supplied as well with jme).



Here is the code

private void buildPlayer() {
Md3ToJme converter=new Md3ToJme();
        URL laura=TestMd3JmeWrite.class.getClassLoader().getResource("jmetest/data/model/lara/lara_lower.md3");
        URL model=TestMd3JmeWrite.class.getClassLoader().getResource("jmetest/data/model/lara/default.bmp");
        ByteArrayOutputStream BO=new ByteArrayOutputStream();
        try {
            converter.convert(laura.openStream(),BO);
            JmeBinaryReader jbr=new JmeBinaryReader();
            player=jbr.loadBinaryFormat(new ByteArrayInputStream(BO.toByteArray()));
            TextureState ts=display.getRenderer().createTextureState();
            ts.setTexture(TextureManager.loadTexture(model,Texture.MM_LINEAR,Texture.FM_LINEAR));
            ts.setEnabled(true);
            player.setRenderState(ts);
       
            player.setLocalTranslation(new Vector3f(100,0, 100));
            player.setWorldBound(new BoundingBox());
      player.updateWorldBound();

    rootNode.attachChild(player);
           
       
        } catch (IOException e) {  // Just in case anything happens
            System.out.println("Damn exceptions!" + e);
            e.printStackTrace();
            System.exit(0);
        }
}


As you can see i set the WorldBound to be a BoundingBox (just as i did with the obj file).

After this method buildChaseCam is invoked which looks like this:
private void buildChaseCamera() {
      Vector3f targetOffset = new Vector3f();
     
      targetOffset.y = ((BoundingBox) player.getWorldBound()).yExtent * 10.5f;
      HashMap props = new HashMap();
      props.put(ThirdPersonMouseLook.PROP_MAXROLLOUT, "30");
      props.put(ThirdPersonMouseLook.PROP_MINROLLOUT, "0");
      props.put(ChaseCamera.PROP_TARGETOFFSET, targetOffset);
     
     
      chaser = new ChaseCamera(cam, player, props);
      chaser.setActionSpeed(100f);
  }

That WORKS !
So at that point i MUST have a bounding box !
But then when it goes to stateUpdate i get a class cast exception saying: "java.lang.ClassCastException: com.jme.bounding.BoundingSphere"
The code where that happens is below (line in bold)

  float characterMinHeight = tb.getHeight(player
              .getLocalTranslation())+((BoundingBox)player.getWorldBound()).yExtent;

      if (!Float.isInfinite(characterMinHeight) && !Float.isNaN(characterMinHeight)) {
          player.getLocalTranslation().y = characterMinHeight;
      }

This happens when stateUpdate is called by the GameStateManager.

I dont see how this can happen since BEFORE that exception the log says:
INFO: Child (MD3 File) attached to this node (XML loaded scene)
21.10.2005 11:11:51 com.jme.scene.Node attachChild
INFO: Child (XML loaded scene) attached to this node (Scene graph node)

So there seems to be no way the player wasnt already loaded and the bounding box set ?

Any ideas ?

some other observation… when i set the height at 20f (fixed) then the scene loads but the model is not visible

you are setting the world bound.  You need to be setting (and updating) the model bound.

renanse said:

you are setting the world bound.  You need to be setting (and updating) the model bound.

Thought about that too but Node doesnt have that method.
Its a method of the Geometry class.
I see only the setWorldBound method in Node.

Interestingly when you look at the tutorials there they use it(modelbound) and attach it to a node, then ask for the worldbound of the node.

You set bounds (model only, and make sure you call updateModelBound) ONLY ON geometry items.  Ever.  Period.  End of story. :slight_smile:



If you think you want the bounds from a Node, what you are really asking for is the sum of its childrens' boundings.  To get that you first attach children that already have their model bounds properly set and updated.  Then you call updateWorldBounds on the Node.  Finally you can access the WorldBound of the Node.



Never will a User need to call setWorldBound.  It is there for internal engine usage.  In fact, perhaps the name needs to be changed to avoid the temptation.

renanse said:

You set bounds (model only, and make sure you call updateModelBound) ONLY ON geometry items.  Ever.  Period.  End of story. :)

If you think you want the bounds from a Node, what you are really asking for is the sum of its childrens' boundings.  To get that you first attach children that already have their model bounds properly set and updated.  Then you call updateWorldBounds on the Node.  Finally you can access the WorldBound of the Node.

Never will a User need to call setWorldBound.  It is there for internal engine usage.  In fact, perhaps the name needs to be changed to avoid the temptation.


The problem here is that i load a node through the framework and dont build up models that i then attach to a node.
If i understand you correctly then you say that i would need to call getChildren and then iterate through them givin each one of them (provided it is a geometry) a modelbound ?

Is there no other way to (generically) get the height of a node ?

The model loading sets bounding volumes automatically. Sphere by default, to change to Box you set the appropriate property:



JmeBinaryReader reader =new JmeBinaryReader();

reader.setProperty("bound","box");


will try it out