Issues with collision shapes

Hello, in the last days I’ve been doing some experiences and tutorials with the purpose of learning more about the engine, and stepped with some problems with some collision shapes in a scene.



I’ve done a simple test scene in blender with some simple meshes. You can see it here (wireframed):



http://dl.dropbox.com/u/918826/partilha/outros/jme%20collion%20stress/ground.blend



With the nightly JME3 version, I did the following (from what i’ve learn with the tutorials and wiki documentation):

[java]

this.bulletAppState = new BulletAppState();

this.stateManager.attach(bulletAppState);

Spatial landscapeModel = assetManager.loadModel(“Scenes/TestScene/SpheresTestScene.j3o”);



RigidBodyControl landscapePhy = new RigidBodyControl(0.0f);

landscapeModel.addControl(landscapePhy);



//make the collision shape visible

landscapePhy.attachDebugShape(assetManager);

this.bulletAppState.getPhysicsSpace().add(landscapePhy);

this.rootNode.attachChild(landscapeModel);



//camera location and light

this.cam.setLocation(new Vector3f(1.85f, 0.96f, 2.5f));

this.cam.setDirection(new Vector3f(-0.42f, -0.34f, -0.83f));

DirectionalLight lightSun = new DirectionalLight();

lightSun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));

this.rootNode.addLight(lightSun);

[/java]



I was expecting a nice colision mesh but something must got wrong and the generator had a seizure during the generation :stuck_out_tongue:







What am I doing wrong? :smiley:



PS: the xml meshes: http://dl.dropbox.com/u/918826/partilha/outros/jme%20collion%20stress/xml%20meshes.zip



Rewards.

Lol, are you sure this is not only the debug display? There were some problems lately with debug display but they are fixed in svn. Otherwise, are you sure your scene only consists of triangles?

Double checked the code and the scene. The only quad present in the scene was the plane but blender simply converted it for me to triangles. After this edit, same result as before. Tested with the individual meshes and the result shapes appeared bugged as well (same pattern).



Checked the code, but there is only one debug attachment in the whole code.



[java]package mygame;



//import com.bulletphysics.collision.shapes.CollisionShape;

import com.jme3.bullet.BulletAppState;

import com.jme3.bullet.control.RigidBodyControl;

import com.jme3.font.BitmapText;

import com.jme3.light.DirectionalLight;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.scene.Spatial;



/**

*

  • @author JGomes

    */

    public class ZeTest extends AbstractGameEngine // http://dl.dropbox.com/u/918826/partilha/outros/jme%20collion%20stress/AbstractGameEngine.java

    {



    protected BitmapText textCamDirection;

    protected BitmapText textCamPosition;

    protected BulletAppState bulletAppState;



    @Override

    public void simpleInitApp()

    {

    this.bulletAppState = new BulletAppState();

    this.stateManager.attach(bulletAppState);





    //Setting up the gui text for camera direction and position

    this.textCamDirection = new BitmapText(this.guiFont, false);

    this.textCamPosition = new BitmapText(this.guiFont, false);

    int guiFontSize = this.guiFont.getCharSet().getRenderedSize();

    textCamDirection.setSize(guiFontSize);

    textCamPosition.setSize(guiFontSize);

    textCamDirection.setText("Camera direction:");

    textCamPosition.setText("Camera position:");

    int windowHeight = this.settings.getHeight();

    textCamDirection.setLocalTranslation(0, windowHeight, 0);

    guiNode.attachChild(textCamDirection);

    textCamPosition.setLocalTranslation(0, windowHeight - textCamPosition.getLineHeight(), 0);

    guiNode.attachChild(textCamPosition);







    viewPort.setBackgroundColor(ColorRGBA.Black);



    Spatial landscapeNode = assetManager.loadModel("Scenes/TestScene/SpheresTestScene.j3o");





    RigidBodyControl landscapePhy = new RigidBodyControl(0.0f);

    landscapeNode.addControl(landscapePhy);

    landscapePhy.attachDebugShape(assetManager);

    this.bulletAppState.getPhysicsSpace().add(landscapePhy);

    this.rootNode.attachChild(landscapeNode);



    //camera and light

    this.cam.setLocation(new Vector3f(1.85f, 0.96f, 2.5f));

    this.cam.setDirection(new Vector3f(-0.42f, -0.34f, -0.83f));

    DirectionalLight lightSun = new DirectionalLight();

    lightSun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));

    this.rootNode.addLight(lightSun);

    }

    @Override

    public void simpleUpdate(float tpf)

    {

    this.textCamDirection.setText("Camera direction: " + this.cam.getDirection().toString());

    this.textCamPosition.setText("Camera position: " + this.cam.getLocation().toString());

    }



    public static void main(String[] args)

    {

    ZeTest test = new ZeTest();

    test.start();

    }

    }[/java]



    I just updated the SDK minutes before the first post (with same result).

So, did you try doing any collision? Is it equivalent to the debug display?

I’m newbie with the engine. :stuck_out_tongue: Is there any way for slowing down a falling object (or the simulation)? I’m testing the collisions with a small cube but the action happens too fast that the only thing i see is the cube disappearing and looking down to watch it falling in a circular motion (the appears to be circular to the y axis).



Sometimes i can see the cube following a random direction before falling down in the same motion described before.



Here is my code now :



[java]public void simpleInitApp()

{

this.bulletAppState = new BulletAppState();

this.stateManager.attach(bulletAppState);





//Setting up the gui text for camera direction and position

this.textCamDirection = new BitmapText(this.guiFont, false);

this.textCamPosition = new BitmapText(this.guiFont, false);

int guiFontSize = this.guiFont.getCharSet().getRenderedSize();

textCamDirection.setSize(guiFontSize);

textCamPosition.setSize(guiFontSize);

textCamDirection.setText(“Camera direction:”);

textCamPosition.setText(“Camera position:”);

int windowHeight = this.settings.getHeight();

textCamDirection.setLocalTranslation(0, windowHeight, 0);

guiNode.attachChild(textCamDirection);

textCamPosition.setLocalTranslation(0, windowHeight - textCamPosition.getLineHeight(), 0);

guiNode.attachChild(textCamPosition);







viewPort.setBackgroundColor(ColorRGBA.Black);



Spatial landscapeNode = assetManager.loadModel(“Scenes/TestScene/SpheresTestScene.j3o”);





RigidBodyControl landscapePhy = new RigidBodyControl(0.0f);

landscapeNode.addControl(landscapePhy);

landscapePhy.attachDebugShape(assetManager);

this.bulletAppState.getPhysicsSpace().add(landscapePhy);

this.rootNode.attachChild(landscapeNode);





Material cubeOrangeMat = new Material(assetManager, “Common/MatDefs/Misc/SolidColor.j3md”);

cubeOrangeMat.setColor(“m_Color”, ColorRGBA.Orange);



//center (right in the midle of the balls), where one of the collision shapes goes to infinity (in y axis)

//Vector3f cubeStartPosition = new Vector3f(0.0f, 5.0f, 0.0f);



//Above the plane

//Vector3f cubeStartPosition = new Vector3f(3f, 5f, 2.6f);

//Vector3f cubeStartPosition = new Vector3f(3f, 1f, 2.6f);



//Above one ball

Vector3f cubeStartPosition = new Vector3f(-0.16f, 5.0f, 1.58f);



Geometry cubeGeo = new Geometry(“Simple Cube”, new Box(cubeStartPosition, 0.2f, 0.2f, 0.2f));

cubeGeo.setMaterial(cubeOrangeMat);



RigidBodyControl cubePhy = new RigidBodyControl(3.0f);





cubeGeo.addControl(cubePhy);

this.bulletAppState.getPhysicsSpace().add(cubePhy);

this.rootNode.attachChild(cubeGeo);



//camera and light

this.cam.setLocation(new Vector3f(5f, 7f, 11f));

this.cam.setDirection(new Vector3f(-0.42f, -0.34f, -0.83f));

DirectionalLight lightSun = new DirectionalLight();

lightSun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));

this.rootNode.addLight(lightSun);

}[/java]

add this line:

[java]speed = 0.2f;[/java]

But anyway, sound like the collision shape is indeed messes up… Could you please loop through your model and convert the single meshes to MeshCollisionShapes and see how that looks?

normen said:
add this line:
[java]speed = 0.2f;[/java]

Thx, much better now.

o.O' The cube seems to ignore collisions, he starts in a constant descent circular motion around the y axis...

normen said:
But anyway, sound like the collision shape is indeed messes up.. Could you please loop through your model and convert the single meshes to MeshCollisionShapes and see how that looks?


Sorry, i didn't understand, what you mean by that?

I tested the meshes alone before:


Btw, when debugging i noticed that the node of the (scene) model loaded by the assetManager have childrens, but its strange that each children have a node as a children that have again a node as child with one of the geometries when in the xml file these childrens do not exists. Check the image and compare against the xml.


1 node list, so I would expect 3 node levels. Maybe this is not important.
[xml]<scene formatVersion="1.0.0">
<nodes>
<node name="Icosphere">
<position x="0.209953" y="1.000000" z="-0.262442"/>
<quaternion x="0.000000" y="0.000000" z="-0.000000" w="1.000000"/>
<scale x="1.000000" y="1.000000" z="1.000000"/>
<entity name="Icosphere" meshFile="Icosphere.mesh"/>
</node>
<node name="Plane">
<position x="-0.014824" y="0.000234" z="0.015727"/>
<quaternion x="0.000000" y="0.000000" z="-0.000000" w="1.000000"/>
<scale x="5.000000" y="5.000000" z="5.000000"/>
<entity name="Plane" meshFile="Plane.mesh"/>
</node>
<node name="Cone">
<position x="-2.367324" y="1.000000" z="-0.000000"/>
<quaternion x="0.000000" y="0.000000" z="-0.000000" w="1.000000"/>
<scale x="1.000000" y="1.000000" z="1.000000"/>
<entity name="Cone" meshFile="Cone.mesh"/>
</node>
<node name="Icosphere.002">
<position x="-0.283435" y="1.000000" z="1.543145"/>
<quaternion x="0.000000" y="0.000000" z="-0.000000" w="1.000000"/>
<scale x="1.000000" y="1.000000" z="1.000000"/>
<entity name="Icosphere.002" meshFile="Icosphere.002.mesh"/>
</node>
<node name="Icosphere.001">
<position x="1.432920" y="1.000000" z="1.117993"/>
<quaternion x="0.000000" y="0.000000" z="-0.000000" w="1.000000"/>
<scale x="1.000000" y="1.000000" z="1.000000"/>
<entity name="Icosphere.001" meshFile="Icosphere.001.mesh"/>
</node>
</nodes>
<externals>
<item type="material">
<file name="SpheresTestScene.material"/>
</item>
</externals>
<environment>
<colourAmbient r="0.000000" g="0.000000" b="0.000000"/>
<colourBackground r="0.050876" g="0.050876" b="0.050876"/>
</environment>
</scene>[/xml]

Load the model and look at the structure in the SceneComposer, theres meshes which are the leaf objects. These need to be converted to a mesh shape, the CollisionShapeFactory does nothing else than looping through your node and finding all meshes. The difference in structure is because of the difference in what the tree structure means in blender an jME. In jME a Geometry defines one object with a mesh and a material, thats why one object in blender might become two objects in jME (one per material).

Ok.



The SceneComposer is a bit odd and crashs the sdk a lot when doing certain actions.

Well, i edited the scene and for each ogre mesh “inside” the scene entities I generated a collision mesh by adding a physics control by first selecting the ogre mesh → move the cursor to the selection location → click “create/update collision shape” button (the editor move the object to the center X=Y=Z=0), → translate the object back to cursor and then save.



When I reopen the scene in the editor or viewer, every object is now in the center, the editor didn’t save up the position that I have set before… -_-



After undoing everything and start again with a j3o fresh converted scene, I noticed that the ogre meshes aren’t in the same place of the geometry. For example, the plane ogremesh have twice the size of the plane, the cone ogremesh is a cube and is not in the same place of the cone but standing a little away from it. And both translations values are the same.







Well, now its lunch time! :smiley:

The location off is due to the local translation of the objects, select the super node to generate a collisionshape for all objects. Anyway, the shape now generated seems to be correct, no?

one question, in the code we still need to add a physics control to the model after adding in the editor?



about the locations, cannot move one without moving the other, and manual positioning is hard atm.

No, its saved in the j3o file, just do

[java]Spatial myModel=assetManager.loadModel("Models/MyModel.j3o");

physicsSpace.addAll(myModel);[/java]

Ty for the info :smiley:



Is there any fast way for attaching a debug shape to every control? I had to take a peek in the addAll code to copy to create a small method for adding debug shapes to the RigidBodyControls and look out for children.



But well, tried a lot of ways for getting the thing right, including your suggestions, but the collisions are still f*** up. :frowning:

Even with a new simple model, the problem still happens… And the small testing cube that I release in the scene also continues to go crazy.



After rewriting some of the code, the crazy cube problems stop and collisions seems to be working fine now, but the debugger shape still seems to have some visual issues.







Is it normal to not be able to translate an spatial correctly after adding the RigidBodyControl?



[java] Material cubeOrangeMat = new Material(assetManager, “Common/MatDefs/Misc/SolidColor.j3md”)

cubeOrangeMat.setColor(“Color”, ColorRGBA.Orange);

Geometry cubeGeo = new Geometry(“Simple Cube”, new Box(Vector3f.ZERO, 0.2f, 0.2f, 0.2f));

cubeGeo.setMaterial(cubeOrangeMat);

cubeGeo.setShadowMode(ShadowMode.CastAndReceive);

cubeGeo.setLocalTranslation(loc); //fine

RigidBodyControl cubePhy = new RigidBodyControl(1f);

cubeGeo.addControl(cubePhy);

//cubeGeo.setLocalTranslation(loc); //the cube (and collision box) stays in ZERO)

cubePhy.attachDebugShape(assetManager);

this.bulletAppState.getPhysicsSpace().add(cubePhy);

this.rootNode.attachChild(cubeGeo);[/java]

Yes thats normal, if you want to move it set it to kinematic mode or move the RigidBody.