Generating Collision Shape

Hi,
I made car, picture bellow, and when a try to make collision shape of it I found a problem.

The car is made in Blender then exported in ogre and imported to jME, in jME automaticaly converted to .j3o and then loaded it in game using Spatial car = assetManager.loadModel("Models/Car.j3o");

Collision is made by CollisionShape carShape = CollisionShapeFactory.createDynamicMeshShape(car);

But how you can see in the picture Collision Shape Factory jump some vertices and doesn’t create the collision shape that I want (the pink lines on top of car).

I haven’t got any more idea how to fix it, I tried some methods but it doesn’t work. Do anybody know how can I fix it?
Thanks

Hi
Actually you can have 3 types of collision shape: (please correct me if I am wrong)
1- Use the car mesh itself as collision shape : (it is precise but adds a lot of load on cpu and not recommended for non-simple meshes) so forget this one ! :stuck_out_tongue_winking_eye:

2-Use that collisionshapefactory to create simple mesh from the main mesh which you used in your example. It uses some algorithm to create a simple mesh and may not be as you wish!
3-You can create your own collision mesh in blender for your car model. and one way would be to use blender Decimate modifier: (It has a lot of improvement in blender 2.77 )


1 Like

Okay, so, let’s look at it:

car is only how the car looks, spatial, let’s say it’s only body of the car, the red things in the picture

carShape is DYNAMIC MeshShape collision which shape is created from car, the pink lines,

vehicle is new VehicleControl made from carShape and mass,

vehicleNode is node where are everything attached, wheels…

then here are
vehicleNode.addControl(vehicle) and vehicleNode.addWheel(...)

So, car is only spatial from Blender 2.77 and carShape take only some of it’s vertices to create DynamicMeshShape then I create vehicleNode, after that vehicle is created from carShape and some mass. Then wheels are added to vehicleNode and finally

rootNode.attachChild(vehicleNode);
        getPhysicsSpace().add(vehicle);

That’s how I have created the car.
But today I find out, that I need to say to CollisionShapeFactory I don’t want a DYNAMIC MeshShape collision but I want only MeshShape collision, I don’t know how you name it, it’s MeshShape I’m looking for. BUT if the code be

CollisionShape carShape = CollisionShapeFactory.createMeshShape(car);

not

CollisionShape carShape = CollisionShapeFactory.createDynamicMeshShape(car);

then the error appear when I’m going to hit something (wall, pillar, etc…)

java.lang.NullPointerException
	at com.bulletphysics.collision.dispatch.CollisionDispatcher.freeCollisionAlgorithm(CollisionDispatcher.java:119)
	at com.bulletphysics.collision.dispatch.CompoundCollisionAlgorithm.destroy(CompoundCollisionAlgorithm.java:76)
	at com.bulletphysics.collision.dispatch.CollisionDispatcher.freeCollisionAlgorithm(CollisionDispatcher.java:120)
	at com.bulletphysics.collision.dispatch.CompoundCollisionAlgorithm.destroy(CompoundCollisionAlgorithm.java:76)
	at com.bulletphysics.collision.dispatch.CollisionDispatcher.freeCollisionAlgorithm(CollisionDispatcher.java:120)
	at com.bulletphysics.collision.broadphase.HashedOverlappingPairCache.cleanOverlappingPair(HashedOverlappingPairCache.java:219)
	at com.bulletphysics.collision.broadphase.HashedOverlappingPairCache.removeOverlappingPair(HashedOverlappingPairCache.java:91)
	at com.bulletphysics.collision.broadphase.DbvtBroadphase.collide(DbvtBroadphase.java:145)
	at com.bulletphysics.collision.broadphase.DbvtBroadphase.calculateOverlappingPairs(DbvtBroadphase.java:235)
	at com.bulletphysics.collision.dispatch.CollisionWorld.performDiscreteCollisionDetection(CollisionWorld.java:139)
	at com.bulletphysics.dynamics.DiscreteDynamicsWorld.internalSingleStepSimulation(DiscreteDynamicsWorld.java:378)
	at com.bulletphysics.dynamics.DiscreteDynamicsWorld.stepSimulation(DiscreteDynamicsWorld.java:339)
	at com.jme3.bullet.PhysicsSpace.update(PhysicsSpace.java:349)
	at com.jme3.bullet.PhysicsSpace.update(PhysicsSpace.java:336)
	at com.jme3.bullet.BulletAppState.render(BulletAppState.java:247)
	at com.jme3.app.state.AppStateManager.render(AppStateManager.java:300)
	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:257)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:152)
	at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:192)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:233)
	at java.lang.Thread.run(Thread.java:745)

AL lib: (EE) alc_cleanup: 1 device not closed

Exception: java.lang.NullPointerException thrown from the UncaughtExceptionHandler in thread "jME3 Main"
BUILD SUCCESSFUL (total time: 17 seconds)

How can I catch or fix this?
Sorry for that but I still haven’t got any idea.

do not use this (like ever for games)

createMeshShape
is not for moving objects, do not move them ever.

The thing you need to understand is that you can only really move convex shapes in real time, concave shapes cause too much overhead. So a “dynamic mesh” is a convex hull shape which is probably what you don’t like. You could make for example the top and bottom of your car two separate hull shapes and combine them in a compound shape to model the car more closely while still having only two convex shape checks.