Bounding boxes question

Hey guys,



im loading an OBJ model and i cant get the bounding right. Basically it puts the whole model into one giant bounding box. I want bounding boxes around each object in the model. Also, lets say the model has a right triangle made out of a cube in it for jumping a vehicle with, how can i make the bounds smooth so the vehicle can drive up on the ramp.



The model is basically 3 cubes and a cube cut in half to make a ramp.



Heres the code im using now:


Spatial model = (Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
                     
                      model.setModelBound( new BoundingBox() );
         model.updateModelBound();
         
                      StaticPhysicsNode modelContainer = getPhysicsSpace().createStaticNode();
         modelContainer.attachChild(model);
         modelContaine.generatePhysicsGeometry();
         rootNode.attachChild(modelContainer);



thanks, andy

Alright i figured it out!



It was really simple actually, I had to set modelContainer.generatePhysicsGeometry(true); instead of just modelContainer.generatePhysicsGeometry();



Oh well… Now that ive got this worked out im going to try getting the models of my city loaded!



Edit:

Well this actually isnt such a great idea since doing the triangle accuracy is way too intensive… I'll keep reading on how to do efficient collision detection…

OK whew, now i've figured out what ive been doing wrong… Sorry to post a 3rd time in the thread, but I know very well someone will have this same question and I want to help out as much as possible…



Heres the deal:



I was importing the object into jme as a wavefront model (.obj)… Apparently, you cannot use this code if youre using obj format


Node model = (Node) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));



If you do, youll get something about you cant cast a trimesh to node error or something. I've seen someone else post about this on the forum and they found if they used "Spatial" instead of Node in the above code, they could use their obj model.. But if you use obj, it seems like using spatial jme doesn't actually fine tune the bounding boxes for collision. It just makes one huge box no matter what... Which really isn't what i wanted at all, (it would make an invisible barrier around the object obviously)

So heres how i was able to use Node on my model (using Node let jme detect the contours of the model i guess?) which was simple. Don't use obj format! I use 3ds format now and the bounding boxes perfectly conform to the model! I dont have to use the triangle accuracy either.

Well i hope this helps someone else! Hopefully by the end of the summer ill be advanced enough to write some awesome how tos and let everyone play the games i make (I plan on making them donate ware too :D)

heres the code I am now using:


Node gamemap = new Node();
           URL modelURL=ChangeToYourClassesName.class.getClassLoader().getResource("boxes.3ds");
           //URL textureURL=ChangeToYourClassesName.class.getClassLoader().getResource("data/model/");
           BinaryImporter importer = BinaryImporter.getInstance();
           FormatConverter converter2=new MaxToJme(); // com.jmex.model.XMLparser.Converters.*
           ByteArrayOutputStream BO=new ByteArrayOutputStream();
           try {
               converter2.convert( modelURL.openStream(), BO );
               gamemap=(Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
               //gamemap.setCullMode( SceneElement.CULL_NEVER );
               gamemap.setModelBound( new BoundingBox() );
               gamemap.updateModelBound();
           } catch (IOException e) {
               e.printStackTrace();
               System.exit(0);
           }


        DynamicPhysicsNode modelContainer = getPhysicsSpace().createDynamicNode();
       //attach the model you just loaded to the physics container
                 modelContainer.attachChild(gamemap);
       
         modelContainer.generatePhysicsGeometry();
         
         modelContainer.getLocalScale().set(2f, 2f, 2f);
         modelContainer.getLocalTranslation().set(new Vector3f(170, 0, 150));
         
         modelContainer.setMaterial(Material.IRON);
         modelContainer.setModelBound(new BoundingBox());
         modelContainer.updateModelBound();
         modelContainer.setMaterial( Material.IRON );
         
         rootNode.attachChild(modelContainer);