TriangleMeshObject - Static terrain .fbx model

Feb 11, 2009 at 12:15 PM
Hi. I'm new to XNA, and I'm trying to add collisions to a terrain I made.

After searching for how to do this, I found a way to extract the data from de model, vertices and indices.

So now I'm trying to use the CreatePhysicsTriMesh method that is given as example on the JigLibX website to create the Triangle Mesh, but I'm having some trouble doing it.

This is the code I'm using:

        static Body CreatePhysicsTriMesh(Vector3 _Position, Model _Model, PhysicsSystem ps, List<TriangleVertexIndices> indexList, List<Vector3> vertexList)
            Body body;
            CollisionSkin collision;
            TriangleMesh triangleMesh;

            body = new Body();
            collision = new CollisionSkin(null);

            triangleMesh = new TriangleMesh();

            triangleMesh.CreateMesh(vertexList, indexList, 4, 1.0f);    --------> I get an Error on this line.
            collision.AddPrimitive(triangleMesh, 1, new MaterialProperties(0.8f, 0.7f, 0.6f));

            body.CollisionSkin = collision;
            body.Position = _Position;


            return body;

The error goes back to the method: octree.BuildOctree(4, 1.0f);

            for (int i = 0; i < tris.Length; i++)
                triBoxes[i].Min = Vector3.Min(positions[tris[i].I0], Vector3.Min(positions[tris[i].I1], positions[tris[i].I2]));
                triBoxes[i].Max = Vector3.Max(positions[tris[i].I0], Vector3.Max(positions[tris[i].I1], positions[tris[i].I2]));

                // get size of the root box
                rootNodeBox.Min = Vector3.Min(rootNodeBox.Min, triBoxes[i].Min);
                rootNodeBox.Max = Vector3.Max(rootNodeBox.Max, triBoxes[i].Max);

ERROR: Index was outside the bounds of the array.

Can someone give me hint? I'm completely clueless to why this is happening.
Feb 16, 2009 at 12:16 PM
looks like the indexList is not valid. Did you try to replace the staticMesh.x of the demo with your mesh. Does that work?
Feb 16, 2009 at 1:27 PM
Yes, I tried that and I got the following exception, when extracting the data from the model:

"Model uses 32-bit indices, which are not supported."

Feb 16, 2009 at 2:35 PM
> I'm new to XNA, and I'm trying to add collisions to a terrain I made.


1) did you try to export to another format? (I used blender with the x-exporter and everyting works fine)
2) the function which gets the vertices form your model doesn't support 32-bit indices. A while ago, we had a content processor for extracting vertices. maybe this works for yor (you have to get an old version from jiglibx, but thats not that easy for a beginner)
3) for a terrain you really should use a heightmap, not a model. But a model should work too.
Feb 16, 2009 at 3:50 PM

I will try your suggestions, and report back.

3) I am using a model for a terrain, because I didn't want a simple terrain. My terrain model contains some platforms and bridges, and stuff like that.
    Do you suggest that I use just a heightmap, and then add others objects (bridges, platforms, etc), with different collision bodies?

Feb 17, 2009 at 11:51 AM
The problem was indeed the terrain model. It had to do with invalid texture coordinates.

Thanks for the help.