Adding physics BoundingBox to model

I am having the worst time trying to figure out how to create a bounding box form a model I've loaded in JME3.  Right now I'm using the Collada Loader library because for some reason, the native OGREXML won't work in this file (incredibly frustrating, I have no clue what is going on with that.).



Here is what I've trying to do in code.  I've used the FancyCar file as an example, but I'm getting an exception when I run:






Material mat = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
        /*
         *This attempts to load a COLLADA file using the ColladaLoader library
         */
        assetManager.registerLocator("../", FileLocator.class.getName());
        assetManager.registerLoader(ColladaLoader.class.getName(), "dae");
        Spatial car = assetManager.loadModel("dependencies/scale.dae");
        float scale = 1f;
        car.scale(scale, scale, scale);
        final Geometry geo = (Geometry) car;
        BoundingBox carBox = (BoundingBox) geo.getModelBound();
        final Vector3f extent = carBox.getExtent(null);
        CompoundCollisionShape compoundShape = new CompoundCollisionShape();
        compoundShape.addChildShape(new BoxCollisionShape(extent), Vector3f.UNIT_Y);
        PhysicsNode CarPhysics = new PhysicsNode(carGeo, compoundShape);       
        rootNode.attachChild(car);
// Now test to see if it exists in the physics world
        Ray ray = new Ray(Vector3f.ZERO, Vector3f.UNIT_Z);
        CollisionResults res = new CollisionResults();
        CarPhysics.collideWith(ray, res);
        ...





The error I'm getting occurs at this point "        final Geometry carGeo = (Geometry) car;" and reads as follows:
Jul 29, 2010 1:42:33 PM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.ClassCastException: com.jme3.scene.Node cannot be cast to com.jme3.scene.Geometry
        at RayTest.RayClosestCollision.setup(RayClosestCollision.java:143)



I've taken that part pretty much exactly from the FancyCar  "findGeom" method which returns a Spatial cast as a Geometry so I can't really see a problem with it.

You are searching a spatial by its name using the code you copied. The Spatial you find in your loaded scenegraph is a Node. You try to cast it to a Geometry. Wont work. Seach a Geometry or make the code work with Nodes.

or he could just use attachDebugShape?

normen said:

You are searching a spatial by its name using the code you copied. The Spatial you find in your loaded scenegraph is a Node. You try to cast it to a Geometry. Wont work. Search a Geometry or make the code work with Nodes.


I'm not sure I understand what you mean here. In my code, I'm not doing the search part like in FancyCar. I'm directly trying to cast the Spatial as a Geometry. This is just the end result of the "findGeom" method from FancyCar after it has searched the model for the part it is looking for. Am I wrong about that? Are you referring to how Jme Internally tries to case a Spatial to a Geometry?

I attempted to just load the model directly to a Geometry using the following, but aI get the same error:
  Geometry car =  (Geometry) assetManager.loadModel("dependencies/scale.dae");

I attempted to load the model as a Node, but I don't knwo how to create a BoundingBox for a Node as it doesn't have a "getModelBound()" method. :
        Node car =  (Node) assetManager.loadModel("dependencies/scale.dae");


Please forgive my ignorance about all this.I know it must be frustrating.  Since I am new to all this, I'm really not sure how I would do either of your suggestions. I may not even be asking the right question. I basically am trying to load my model, and make it so I can drive it around. I had it working in Jme2 at one point, but that code is long gone now that i've switched to JME3, and it wouldn't translate to the new version anyway.

If you want to see the collision shape which is attached to a physics node.



do ,



PhysicsNode lala = new PhysicsNode(node,collisionshape,pos,mass) //might be wrong cnt remember
lala.attachDebugShape(assetManager);



And thats it, you can see exactly what your collision shape is - if you find a solution for easily showing the bounding box for any object - id like to see it!
morrowsend said:

I attempted to just load the model directly to a Geometry using the following, but aI get the same error:
  Geometry car =  (Geometry) assetManager.loadModel("dependencies/scale.dae");

I attempted to load the model as a Node, but I don't knwo how to create a BoundingBox for a Node as it doesn't have a "getModelBound()" method. :
        Node car =   (Node) assetManager.loadModel("dependencies/scale.dae");
Please forgive my ignorance about all this.I know it must be frustrating.  Since I am new to all this, I'm really not sure how I would do either of your suggestions. I may not even be asking the right question. I basically am trying to load my model, and make it so I can drive it around. I had it working in Jme2 at one point, but that code is long gone now that i've switched to JME3, and it wouldn't translate to the new version anyway.

Hm.. Ok. You know about classes and inheritance, right? And then you have the scenegraph, the "tree" of your scene. Spatial is the base class of all objects in the tree. A "Node" extends "Spatial" and can have children (to really form the tree), a "Geometry" also extends Spatial, but holds info about a mesh and its material. So a Geometry is not a Node, thats why you cant cast it there. The thing you load from a disk can only then be a Geometry when it is a single mesh, if the model contains multiple meshes the importer has to create a Node and attach all meshes to it, thats why you get a Node in return.
Hope this helps,
Normen

I really appreciate everyone's help on this.



@renegadeandy

I'm not able to even create the physics node as I can't create a collisionShape. I get stopped a  full 5 lines above that, when I was to create the Geometry.





@Norman

I have a better understanding now of the role between Nodes and Geometries and Spatials. Even reading the Wiki didn't seem to click for me like what you said.



Since I am new, I'm not sure of all the properties of my models. Basically I'm creating them in Google Sketchup (I know it is not the best however it is the easiest and most available software and a key factor for me in this project is to allow my end users to create custom models and terrains for the game using it.) The terrains must come from Google Earth.  I can export Google earth data to Sketchup, and then I'm exporting the Sketchup file as a Collada.



The Car model itself consists of several different parts and two major groups. I have a body which is grouped all together and then each wheel is grouped separately. I assumed that this would create a box for the body, and each wheel would be separate.  I noticed that in the FancyCar demo, it seems like part names form the, model are used to strip out a part, such as a "FrontLeftWheel" etc. My hope was to be able to do the same thing.





When I load the model in as a Spacial, it must get loaded as a Node.  I see that now. But I still can't figure out how to actually use my model though because as far as I can tell, there is no way to get a collision shape or bounding box for a node.

I've got a OGRE Mesh file that has nothing but a mesh inside it. It is still not working. The file as well as the material file and image are attached. Could someone take a look and tell me why I can't load this as a Geometry?







Also, I'm still curious as to how I might be able to load in a vehicle model then separate it part by part like the Fancycar demo. My COLLADA model of the vehicle is also attached (bot7.dae) If someone could look at it and give me some idea of how I might be able to break it down, I would greatly appreciate it. Basically I would like to treat the body of the robot as a box, but I don't think it is exporting the whole body as a mesh, it is a Node and each part that makes up the body is a mesh.  I'm not quite sure how to fix that. I attempted to load in just a box with wheels (car.dae) as well which also failed but actually got a lot farther along in the loading process than any other attempt.





I feel I am close to getting this, but I'm just missing a few little things here and there.

It will never be a Geometry, its always a Node with Geometrys attached, load the Node, do getChildren(), iterate over the list and do what you have to do to the attached Geometrys.

You always have the answer normen! I have been keeping me eye on this thread for a number of days now - and that was the same answer I was going to give - but thought ill hold it back until somebody else says something incase I am wrong! :smiley:

I've been using the Fancycar demo, and am loading the car.dae file. It calls the findGeom method, which does what you mentioned. Things seem to be found however now I am having trouble with Materials I think. below is the build log that shows what and where the errors are. Might this be a problem with the Collada loader? This model loads perfectly fine by itself and in the other example codes so I don't understand why it might have a problem here.





Abbreviated BuildLog:



Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (Model) attached to this node (COLLADA SCENE)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (Car) attached to this node (Model)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (mesh1) attached to this node (Car)

APPLYING MATERIAL material_0_24

MATERIAL 32498805 APP TO 8385974

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (model) attached to this node (null)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child () attached to this node (mesh1)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (mesh2) attached to this node (Car)

Aug 2, 2010 11:16:13 PM jme3dae.utilities.MatrixTransformer transform

SEVERE:

java.lang.NumberFormatException: empty String

APPLYING MATERIAL material_0_24

        at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:994)

MATERIAL 32498805 APP TO 20327011

APPLYING MATERIAL material_0_24

MATERIAL 32498805 APP TO 9874812

APPLYING MATERIAL material_0_24

MATERIAL 32498805 APP TO 7819553

APPLYING MATERIAL material_0_24

MATERIAL 32498805 APP TO 24080548

        at java.lang.Float.parseFloat(Float.java:422)

        at jme3dae.utilities.MatrixTransformer.transform(MatrixTransformer.java:42)

        at jme3dae.utilities.MatrixTransformer.transform(MatrixTransformer.java:13)

        at jme3dae.DAENode.getContent(DAENode.java:195)

        at jme3dae.collada14.transformers.TransformationElementTransformer.pushMatrix(TransformationElementTransformer.java:94)

        at jme3dae.collada14.transformers.TransformationElementTransformer.transform(TransformationElementTransformer.java:56)

        at jme3dae.collada14.transformers.SceneTransformer.parseNode(SceneTransformer.java:161)

        at jme3dae.collada14.transformers.SceneTransformer.parseNode(SceneTransformer.java:176)

        at jme3dae.collada14.transformers.SceneTransformer.parseVisualScene(SceneTransformer.java:131)

        at jme3dae.collada14.transformers.SceneTransformer.parseInstanceVisualScene(SceneTransformer.java:84)

        at jme3dae.collada14.transformers.SceneTransformer.transform(SceneTransformer.java:61)

        at jme3dae.collada14.ColladaDocumentV14.transform(ColladaDocumentV14.java:70)

        at jme3dae.collada14.ColladaDocumentV14.transform(ColladaDocumentV14.java:30)

        at jme3dae.ColladaLoader.load(ColladaLoader.java:41)

        at jme3dae.ColladaLoader.load(ColladaLoader.java:18)

        at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:162)

        at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:282)

        at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:292)

        at RayTest.TestFancyCar.buildPlayer(TestFancyCar.java:142)

        at RayTest.TestFancyCar.simpleInitApp(TestFancyCar.java:70)

        at com.jme3.app.SimpleBulletApplication.initialize(SimpleBulletApplication.java:261)

        at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:102)

        at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:147)

        at java.lang.Thread.run(Thread.java:619)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (WheelFrontLeft) attached to this node (Model)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (wheel_node) attached to this node (WheelFrontLeft)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (mesh3) attached to this node (wheel_node)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (model) attached to this node (null)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child () attached to this node (mesh3)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (mesh4) attached to this node (wheel_node)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (mesh5) attached to this node (wheel_node)

Aug 2, 2010 11:16:13 PM jme3dae.utilities.MatrixTransformer transform

SEVERE:

java.lang.NumberFormatException: empty String

        at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:994)

        at java.lang.Float.parseFloat(Float.java:422)

        at jme3dae.utilities.MatrixTransformer.transform(MatrixTransformer.java:42)

        at jme3dae.utilities.MatrixTransformer.transform(MatrixTransformer.java:13)

        at jme3dae.DAENode.getContent(DAENode.java:195)

        at jme3dae.collada14.transformers.TransformationElementTransformer.pushMatrix(TransformationElementTransformer.java:94)

        at jme3dae.collada14.transformers.TransformationElementTransformer.transform(TransformationElementTransformer.java:56)

        at jme3dae.collada14.transformers.SceneTransformer.parseNode(SceneTransformer.java:161)

        at jme3dae.collada14.transformers.SceneTransformer.parseNode(SceneTransformer.java:176)

        at jme3dae.collada14.transformers.SceneTransformer.parseVisualScene(SceneTransformer.java:131)

        at jme3dae.collada14.transformers.SceneTransformer.parseInstanceVisualScene(SceneTransformer.java:84)

        at jme3dae.collada14.transformers.SceneTransformer.transform(SceneTransformer.java:61)

        at jme3dae.collada14.ColladaDocumentV14.transform(ColladaDocumentV14.java:70)

        at jme3dae.collada14.ColladaDocumentV14.transform(ColladaDocumentV14.java:30)

        at jme3dae.ColladaLoader.load(ColladaLoader.java:41)

        at jme3dae.ColladaLoader.load(ColladaLoader.java:18)

        at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:162)

        at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:282)

        at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:292)

        at RayTest.TestFancyCar.buildPlayer(TestFancyCar.java:142)

        at RayTest.TestFancyCar.simpleInitApp(TestFancyCar.java:70)

        at com.jme3.app.SimpleBulletApplication.initialize(SimpleBulletApplication.java:261)

        at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:102)

        at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:147)

        at java.lang.Thread.run(Thread.java:619)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (WheelBackLeft) attached to this node (Model)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (wheel_node) attached to this node (WheelBackLeft)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (mesh3) attached to this node (wheel_node)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (model) attached to this node (null)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child () attached to this node (mesh3)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (mesh4) attached to this node (wheel_node)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (mesh5) attached to this node (wheel_node)

Aug 2, 2010 11:16:13 PM jme3dae.utilities.MatrixTransformer transform

SEVERE:

java.lang.NumberFormatException: empty String

        at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:994)

        at java.lang.Float.parseFloat(Float.java:422)

        at jme3dae.utilities.MatrixTransformer.transform(MatrixTransformer.java:42)

        at jme3dae.utilities.MatrixTransformer.transform(MatrixTransformer.java:13)

        at jme3dae.DAENode.getContent(DAENode.java:195)

        at jme3dae.collada14.transformers.TransformationElementTransformer.pushMatrix(TransformationElementTransformer.java:94)

        at jme3dae.collada14.transformers.TransformationElementTransformer.transform(TransformationElementTransformer.java:56)

        at jme3dae.collada14.transformers.SceneTransformer.parseNode(SceneTransformer.java:161)

        at jme3dae.collada14.transformers.SceneTransformer.parseNode(SceneTransformer.java:176)

        at jme3dae.collada14.transformers.SceneTransformer.parseVisualScene(SceneTransformer.java:131)

        at jme3dae.collada14.transformers.SceneTransformer.parseInstanceVisualScene(SceneTransformer.java:84)

        at jme3dae.collada14.transformers.SceneTransformer.transform(SceneTransformer.java:61)

        at jme3dae.collada14.ColladaDocumentV14.transform(ColladaDocumentV14.java:70)

        at jme3dae.collada14.ColladaDocumentV14.transform(ColladaDocumentV14.java:30)

        at jme3dae.ColladaLoader.load(ColladaLoader.java:41)

        at jme3dae.ColladaLoader.load(ColladaLoader.java:18)

        at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:162)

        at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:282)

        at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:292)

        at RayTest.TestFancyCar.buildPlayer(TestFancyCar.java:142)

        at RayTest.TestFancyCar.simpleInitApp(TestFancyCar.java:70)

        at com.jme3.app.SimpleBulletApplication.initialize(SimpleBulletApplication.java:261)

        at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:102)

        at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:147)

        at java.lang.Thread.run(Thread.java:619)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (WheelBackRight) attached to this node (Model)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (wheel_node) attached to this node (WheelBackRight)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (mesh3) attached to this node (wheel_node)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (model) attached to this node (null)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child () attached to this node (mesh3)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (mesh4) attached to this node (wheel_node)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (mesh5) attached to this node (wheel_node)

Aug 2, 2010 11:16:13 PM jme3dae.utilities.MatrixTransformer transform

SEVERE:

java.lang.NumberFormatException: empty String

        at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:994)

        at java.lang.Float.parseFloat(Float.java:422)

        at jme3dae.utilities.MatrixTransformer.transform(MatrixTransformer.java:42)

        at jme3dae.utilities.MatrixTransformer.transform(MatrixTransformer.java:13)

        at jme3dae.DAENode.getContent(DAENode.java:195)

        at jme3dae.collada14.transformers.TransformationElementTransformer.pushMatrix(TransformationElementTransformer.java:94)

        at jme3dae.collada14.transformers.TransformationElementTransformer.transform(TransformationElementTransformer.java:56)

        at jme3dae.collada14.transformers.SceneTransformer.parseNode(SceneTransformer.java:161)

        at jme3dae.collada14.transformers.SceneTransformer.parseNode(SceneTransformer.java:176)

        at jme3dae.collada14.transformers.SceneTransformer.parseVisualScene(SceneTransformer.java:131)

        at jme3dae.collada14.transformers.SceneTransformer.parseInstanceVisualScene(SceneTransformer.java:84)

        at jme3dae.collada14.transformers.SceneTransformer.transform(SceneTransformer.java:61)

        at jme3dae.collada14.ColladaDocumentV14.transform(ColladaDocumentV14.java:70)

        at jme3dae.collada14.ColladaDocumentV14.transform(ColladaDocumentV14.java:30)

        at jme3dae.ColladaLoader.load(ColladaLoader.java:41)

        at jme3dae.ColladaLoader.load(ColladaLoader.java:18)

        at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:162)

        at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:282)

        at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:292)

        at RayTest.TestFancyCar.buildPlayer(TestFancyCar.java:142)

        at RayTest.TestFancyCar.simpleInitApp(TestFancyCar.java:70)

        at com.jme3.app.SimpleBulletApplication.initialize(SimpleBulletApplication.java:261)

        at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:102)

        at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:147)

        at java.lang.Thread.run(Thread.java:619)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (WheelFrontRight) attached to this node (Model)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (wheel_node) attached to this node (WheelFrontRight)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (mesh3) attached to this node (wheel_node)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (model) attached to this node (null)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child () attached to this node (mesh3)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (mesh4) attached to this node (wheel_node)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (mesh5) attached to this node (wheel_node)

Aug 2, 2010 11:16:13 PM jme3dae.utilities.MatrixTransformer transform

SEVERE:

java.lang.NumberFormatException: empty String

        at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:994)

        at java.lang.Float.parseFloat(Float.java:422)

        at jme3dae.utilities.MatrixTransformer.transform(MatrixTransformer.java:42)

        at jme3dae.utilities.MatrixTransformer.transform(MatrixTransformer.java:13)

        at jme3dae.DAENode.getContent(DAENode.java:195)

        at jme3dae.collada14.transformers.TransformationElementTransformer.pushMatrix(TransformationElementTransformer.java:94)

        at jme3dae.collada14.transformers.TransformationElementTransformer.transform(TransformationElementTransformer.java:56)

        at jme3dae.collada14.transformers.SceneTransformer.parseNode(SceneTransformer.java:161)

        at jme3dae.collada14.transformers.SceneTransformer.parseVisualScene(SceneTransformer.java:131)

        at jme3dae.collada14.transformers.SceneTransformer.parseInstanceVisualScene(SceneTransformer.java:84)

        at jme3dae.collada14.transformers.SceneTransformer.transform(SceneTransformer.java:61)

        at jme3dae.collada14.ColladaDocumentV14.transform(ColladaDocumentV14.java:70)

        at jme3dae.collada14.ColladaDocumentV14.transform(ColladaDocumentV14.java:30)

        at jme3dae.ColladaLoader.load(ColladaLoader.java:41)

        at jme3dae.ColladaLoader.load(ColladaLoader.java:18)

        at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:162)

        at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:282)

        at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:292)

        at RayTest.TestFancyCar.buildPlayer(TestFancyCar.java:142)

        at RayTest.TestFancyCar.simpleInitApp(TestFancyCar.java:70)

        at com.jme3.app.SimpleBulletApplication.initialize(SimpleBulletApplication.java:261)

        at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:102)

        at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:147)

        at java.lang.Thread.run(Thread.java:619)

Aug 2, 2010 11:16:13 PM com.jme3.scene.Node attachChild

INFO: Child (Camera) attached to this node (COLLADA SCENE)

Aug 2, 2010 11:16:13 PM com.jme3.app.Application handleError

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.NullPointerException

        at RayTest.TestFancyCar.buildPlayer(TestFancyCar.java:152)

        at RayTest.TestFancyCar.simpleInitApp(TestFancyCar.java:70)

        at com.jme3.app.SimpleBulletApplication.initialize(SimpleBulletApplication.java:261)

        at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:102)

        at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:147)

        at java.lang.Thread.run(Thread.java:619)

BUILD SUCCESSFUL (total time: 4 seconds)





The line the error points to is the one where I load the file into the Spatial:

  /*
         * COLLADA file from sketchup 7
         */
        assetManager.registerLocator("../", FileLocator.class.getName());
        assetManager.registerLoader(ColladaLoader.class.getName(), "dae");
        Spatial carNode = assetManager.loadModel("dependencies/car.dae");
        final Geometry chasis = findGeom(carNode, "Car");
        BoundingBox box = (BoundingBox) chasis.getModelBound();

I imagine that means it can't find the file… are you sure it's looking in the right place for it?

I'm definitely finding the file because I can load the model alone in the visual world with no problem. The set-up in the physics world is the problem.



Now I've just tested a BUNCH of stuff and my results are below. Basically I'm using the physicsCar example, and replacing the Box stand-in alone with the model of my robot. I am keeping the wheels from the original code. Here are my tests and results:



–When loading a COLLADA model of my robot, I can't simply call findGeom with no String name, it only returns the first mesh it finds, which is a small component of the robot model. It still gives me the MATERIALS errors as in the last post, but doesn't fully crash.  When I do a  System.out.println(car.getChildren()); I get the following only: "[Model (Node), Camera (Node)]"





–I can load a .OBJ of the car directly as a Geometry, but I have to apply the materials myself and I still can't seem to get the physics of this working correctly. I have to Greatly reduce the scale of the model when I import it as a OBJ. I'll have to look into whether this is something I can change in the CAD program before exporting.  This seems to REALLY mess with the Collision shape. Even when I scale the Geometry of the model, it seems to only occur in the visual world, the physics model is not scaled. This is my code for that section:

       

Geometry car = (Geometry) assetManager.loadModel("dependencies/body_only.obj");

        car.setLocalScale(0.25f, 0.25f, 0.25f);

       // show normals as material

        car.setMaterial(mat);

        rootNode.attachChild(car);

        car.setModelBound(new BoundingBox());

        BoundingBox box = (BoundingBox) car.getModelBound();   //USE THIS WITH OBJ

         final Vector3f extent = box.getExtent(null);

        CompoundCollisionShape compoundShape = new CompoundCollisionShape();

        compoundShape.addChildShape(new BoxCollisionShape(extent), Vector3f.UNIT_Y);

        player = new PhysicsVehicleNode(car, compoundShape, 400);







–I tried to load an OGRE mesh XML of the robot model, but when I attempt to apply the physics using the findGeom with no name String, the entire model is SHOWN, however only that same small component (the first mesh in the file I suppose) is in the physics space.  It is the same problem as with the COLLADA file. When I do a  System.out.println(car.getChildren()); I get the following only: "[Flat_robot-geom-1 (Geometry), Flat_robot-geom-2 (Geometry)]"





====DebugShape Tests (Strange Problems)====



–When I attempt to attachDebugShape to a PhysicsNode built around the imported models, I get all kinds of problems. I simply added the following code to each of my tests, OBJ, OGREmesh and COLLADA imports. Here is that code:


player = new PhysicsVehicleNode(car, compoundShape, mass); //actual vehicle    
PhysicsNode lala = new PhysicsNode(chasis, compoundShape, mass);//tests node to see BoundingBox
lala.attachDebugShape(assetManager)
rootNode.attachChild(lala);



    *with the OBJ, and the code above, I get my model where it needs to be. But if I add ANY mass, the model shoots off the screen straight up incredibly fast. The debug shape is huge, the size of the original model (as mentioned above)
   
    *With this code in the COLLDAD test, only the small component mentioned earlier is shown. The debugShape is the same size as the part of the model, but again is translated up by about 1 world-unit. Attempting to drive the robot makes the robot flip over violently. I am supposing this is due to the physics only simulating that small component of the model mentioned earlier.

    *with the OGREmesh, the code above does soemthing funny. The main body of the robot (which was grouped together in the CAD program) is shown at the same size as the component mentioned in the COLLADA test. The wheels in the model (which were  grouped separately) are shown at the value in "car.setLocalScale(10)." The body itself no longer responds to setLocalScale.
The debugShape is the size of the BODY of the model only (wheels not included) which is again, very small and not responding to SetLocalScale methods. The debugShape is also localed about 1 world-unit ABOVE the model itself.It is exactly the same size, shape and location of the debugShape as from the COLLADA test.  I have a suspicion that the small OGRE mesh central model is due to some kind of OGRE loading error. Since the body of the model is actually the exact same size as the only component that loads in the Collada test.  Literally I think the entire grouped "body" of the model is being loaded into the size of the PART of the model.


====Terrain====
-- I can load a TERRAIN model as a OGRE Mesh XML, and then use findGeom to make a physics node of it if I simply don't pass a name String to the method as such:          final Geometry terrain = findGeom(TerrainNode, "");
Small success, YAY! However, when I do this, I loose the OGRE material involved and have to apply the image manually, which is not ideal.  Also my Vehicle stand-in slides sideways down the sides of the terrain, even on a very slight angle. I suppose I'll have to play with wheel friction?

I've exported the OBJ file again and chose different export options so now it seems to be more to scale.  When I do a debug shape, the shape still appears above the actual model as shown in the below (or attached) screenshot.



When I try to drive the car, it doesn't drive anywhere, but rather it just begins bucking  up and down like a wild horse. I'm not sure what to do about this. I added mass but it just dampens the bucking, the car still doesn't drive anywhere.



normen said:
It will never be a Geometry, its always a Node with Geometrys attached, load the Node, do getChildren(), iterate over the list and do what you have to do to the attached Geometrys.

I need the the following to be done:
[java]
//How can i extract the triangle data from this box
assetManager.loadModel("Models/mybox.j3o")
=>Geometry
geo.getMesh().getTriangle(..)
[/java]

EDIT my bad did not see this "No troubleshooting requests here please!!" :(
FranticFrettchen said:
I need the the following to be done:

Yeah, exactly, you quote the answer.

ok :slight_smile:



i will write my thoughts down step by step:


normen said:
... load the Node


i guess you mean
[java]assetManager.loadModel()[/java]
but the result is a Spatial, not a Node

i can get the Node by doing
[java]assetManager.loadModel().getParent()[/java]
but iterating over its childs gives me the same Spatial as before :(

And as a result of that I am confused

Node is a subclass of spatial. The spatial you load with loadModel is, more specifically, a node. Cast it and use getChildren

[java]



Spatial constructionGeo = new Geometry();

constructionGeo = assetManager.loadModel(“Models/World/World.mesh.j3o”);



for(Spatial aSpatial: ((Node)constructionGeo).getChildren()){

aSpatial :/= Geometry!

}

[/java]



thanks, but it’s still a Spatial :frowning:

Geometry is also a subclass of spatial…



I strongly suggest you read https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:scenegraph_for_dummies at the very least, and then familiarise yourself with controls, Without a good understanding of these you will not get the best out of JMonkey.



Matt