I have only two variable dimensions - width=length and deep. I think only one way to create this form - load a mesh, created in an external editor, scale it, and create the RigidBodyControl using this Spatial, but after that - unbind the RigidBodyControl from the mesh (to use the Spatial for the creation of another triangle prisms). This method corrupts my code architecture, but if it is the only one way for me - OK, but how to implement this correct to avoid unused linking of the mesh and RigidBodyControl?
What can you advise me? Are there classes to create this prism so simple as a BoxCollisionShape?
The simplest way to go is use MeshCollisionShape and use a jme3utilities.mesh.Prism class. But first you need to understand some basics: JMonkeyEngine uses Bullet physics engine. In order for the JME engine to interact with Bullet, there needs to be a ‘binding’ for the Bullet library. There are two binding currently:
One built-in with the engine that comes by default and you are probably using this one. It’s called jme3-bullet.
One written by @stephengold called Minie. Minie comes with a Prism Mesh shape. Minie is an improved binding and compatible with the default engine binding meaning that you don’t need to rewrite anything, you just need to update a dependency.
Minie has a built-in prism class. You need to change your dependencies to use Minie instead of jme3-bullet. For example I use maven so for me it’s this:
Some last words regarding rigidbodies: If you have 10 prisms in your game, you will have 10 spatials with 10 RigidBodyControl attached to them. Don’t unbind the RigidBodyControl to create other Prisms.
The prism, that you have created, is not the same as I need. I need a prism which has a right triangle as the cross section. You have created a equilateral triangle as the cross section.
Oh you are right, I missed that part. In that case you have to implement one Prism class yourself. Without changing any dependencies or anything: Create a Prism class by extending the com.jme3.scene.Mesh class and assemble the vertices and indices yourself. You need to fill a Position and Indices vertex buffers with appropriate floats. You can calculate the sizes by passing in floats in the Prism class constructor for width, height and depth. You can see examples how the com.jme3.scene.shape.Box class does it for a Box and then implement your own version for the Prism. Then use this Prism mesh with a MeshCollisionShape and you’re done.