-
Notifications
You must be signed in to change notification settings - Fork 84
Tutorial 2: Triangle Mesh
This tutorial shows how to create a body represented by custom triangles. A
TriangleMeshShape should be a static body - but it's also possible to make
it dynamic - as shown in this tutorial.
First the vertices and indices have to be extracted from the model. This data
is then used to build a JOctree which is passed to the TriangleMeshShape
class. The octree makes it possible to use models containing several thousands
of vertices. This is very useful because you can build your map/level out of a
mesh and use it as a triangle mesh in the physics engine. Theoretically, Jitter
is able to handle triangle-triangle collision, but it would really make your
computer cry.

Figure 2: Tutorial 2 - Two boxed falling to the ground. The torus is a
TriangleMeshShape.
// Build an octree of it
JOctree octree = new JOctree(positions, indices);
octree.BuildOctree();
// Pass it to a new instance of the triangle mesh shape
TriangleMeshShape triangleMeshShape = new TriangleMeshShape(octree);
// Create a body, using the triangleMeshShape
RigidBody triangleBody = new RigidBody(triangleMeshShape);
triangleBody.Tag = Color.LightGray;
triangleBody.Position = new JVector(0, 3, 0);
// Add the mesh to the world.
world.AddBody(triangleBody);