HullCollisionShape for custom Cone model

I am trying to do some physics tests. I created and exported a simple Cone model from Blender and now I am trying to create a collision shape for it. The cone should be a moving object that can also collide with other Cone objects in the world. Currently I have the following code:


public void makeTri(Vector3f loc) {

Spatial tri = assetManager.loadModel(“Models/Cone.mesh.xml”);

tri.scale(1f, 1f, 1f);


//Create a CollisionShape

HullCollisionShape shape = new HullCollisionShape( tri ); // how to get geometry ?

// spatial.addControl(new PhysicsRigidBodyControl(mass));

//Create a PhysicsControl by supplying the CollisionShape and mass. E.g. com.jme3.bullet.control.RigidBodyControl

tri_phy = new RigidBodyControl(shape, 2f);

//Add the PhysicsControl to the Spatial.


//Add the PhysicsControl to the physicsSpace object.


//Attach the Spatial to the rootNode, as usual.




I have read the tutorials about physics and did some searching. I cant seem to get how to get from Spatial to a Geometry object which seems to be needed when creating a HullCollisionShape this way. Of course just casting the Spatial to Geometry isn’t the answer and gets a java.lang.ClassCastException :slight_smile:

In another post I picked up on someone saying this code is an easy way to create HullCollisionShape or return Meshes but I couldn’t follow how.


spatial.addControl(new PhysicsRigidBodyControl(mass))


Or am I going about it the wrong way? Maybe I need to convert to a Mesh object first somehow and do some vertices calc before getting to a Shape like the following topic does?

What would be the proper way to get a HullCollisionShape or GImpactCollisionShape for my custom Cone model ?

The latest svn has RigidBodyControl which creates the hull automatically, alpha-3 only has the CollisionShapeFactory. Generally you would create a new HullCollisionShape like any object supplying the mesh in the constructor new HullCollisionShape(mesh);. But there is a cone collision shape in the bullet library, just use that one.

It is a bit late for me and I’m going to bed right now but here is an example for you, I got this in a map loader class I created for a test game a while ago:

[java] Node collisionModel = (Node) assetManager.loadModel(“Models/”.concat(name));

CollisionShape modelShape = CollisionShapeFactory.createMeshShape(collisionModel);

RigidBodyControl rigidControl = new RigidBodyControl(modelShape, 0);


If I recall correctly, this should give you a geometry correct collision shape and add it to the physics space (rigid), been a while tho. Can’t think straight now anyway, hope it helps :wink:

Edit: Darn, normen got his post before I was even able to look up my snippet, oh well… Guess it could be of use to someone later on

I forget to mention which jme I was using. Im using a jme3 branche from svn I downloaded this week. I am still unsure how the code should look when RigidBodyControl is supposed to create the hull but I solved my problem by using the ConeCollisionShape. Maybe the shape can be added on this page ?


public void makeTri(Vector3f loc) {

// load model and set material

Spatial cone = assetManager.loadModel("Models/Cone.mesh.xml");


// set scale and location

cone.scale(0.5f, 0.5f, 0.5f);


// create a CollisionShape

ConeCollisionShape shape = new ConeCollisionShape(0.5f, 0.5f);

// create a PhysicsControl

tri_phy = new RigidBodyControl(shape, 2f);

// add the control to the Spatial.


// add the control to the physicsSpace object.


// attach the Spatial to the rootNode




You have to supply a mass in the RigidBodyControl constructor, then it will generate a collision shape when its attached to the spatial.