[SOLVED]Problem with mesh CollisionShape from OgreMax

Hello, i’m new in jme, maybe my problem is simple, but i’m cant figure it out.

So, i run example from wiki - TestFancyCar . Everything works great.

Then i try to change car to my model from 3d max.
I use OgreMax to export .scene from .max file.
When i’m making CollisionShape from body without wheels mesh (like in example), CollisionShape is shifted.

My code:
assetManager.registerLocator(“files/models/btr”, FileLocator.class); //Регистрируем путь
carNode = (Node)assetManager.loadModel(“btr.scene”);
Texture tex = assetManager.loadTexture(“BTR80.PNG”);
Material mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
mat.setTexture(“ColorMap”, tex);
carNode.setMaterial(mat);
carNode.setShadowMode(ShadowMode.Cast);

Geometry chasis = findGeom(carNode, “body”);
BoundingBox box = (BoundingBox) chasis.getModelBound();
//Create a hull collision shape for the chassis
CollisionShape carHull = CollisionShapeFactory.createDynamicMeshShape(chasis);

//Create a vehicle control
player = new VehicleControl(carHull, mass);
carNode.addControl(player);

Result (ball is behind not below):

Any suggestions?

Thank you in advance

Model

First of all I recommend using a Hullcollision shape, expecially for vehicles I had great resuls with them.

Anyway: You create a shape directly from the body (the offset of the body however is probably done via the parent) that is why your collision has not the offset. Easy solution would be to create a Compoundshape and offset the hullshape when adding it to the compound shape.

1 Like

createDynamicMeshShape does create a hull shape, or multiple in a compound shape if needed. But yeah, the geometry you create the hull shape from is offset so the hull shape is created without that offset if you use the geometry directly. You could either create it from the base node which would include the wheels though or create it manually and offset it yourself.

1 Like

Thanks for reply,
i created from base node

carNode = assetManager.loadModel(“btr.scene”);
CollisionShape carHull = CollisionShapeFactory.createDynamicMeshShape(carNode);

it works great for me.
Now, when i add wheels, vehicle doesnt accelerate, but front vehicles steer normal.

Geometry wheel_firstRight = findGeom(carNode, "Object002");
    wheel_firstRight.center();
    box = (BoundingBox) wheel_firstRight.getModelBound();
    wheelRadius = box.getYExtent();
    player.addWheel(wheel_firstRight.getParent(),  box.getCenter().add(0f, wheelRadius+0.2f, -2.5f), wheelDirection, wheelAxle, 0.2f, wheelRadius, true);

    Geometry wheel_firstLeft = findGeom(carNode, "Object007");
    wheel_firstLeft.center();
    box = (BoundingBox) wheel_firstLeft.getModelBound();
    player.addWheel(wheel_firstLeft.getParent(), box.getCenter().add(0f, wheelRadius+0.2f, -2.5f), wheelDirection, wheelAxle, 0.2f, wheelRadius, true);

  	... here another 4 vehicles
    
    Geometry wheel_br = findGeom(carNode, "Object006");
    wheel_br.center();
    box = (BoundingBox) wheel_br.getModelBound();
    player.addWheel(wheel_br.getParent(), box.getCenter().add(0, wheelRadius+0.2f, 2f),
            wheelDirection, wheelAxle, 0.2f, wheelRadius, false);

    Geometry wheel_bl = findGeom(carNode, "Object010");
    wheel_bl.center();
    box = (BoundingBox) wheel_bl.getModelBound();
    player.addWheel(wheel_bl.getParent(), box.getCenter().add(0, wheelRadius+0.2f, 2f),
            wheelDirection, wheelAxle, 0.2f, wheelRadius, false);

I think it’s because vehicles is part of car shape to which they connected, but front vehicles seems work properly.

little help?

thanks

Sorry, I found problem
I put wheelRadius+0.2f in

player.addWheel(wheel_firstRight.getParent(), box.getCenter().add(0f, wheelRadius+0.2f, -2.5f), wheelDirection, wheelAxle, 0.2f, wheelRadius, true);

wheels doesnt touch ground, after change to wheelRadius everything works fine.