Hello,
I just started trying out this physics engine and have had no problem getting the built-in Box type to render. The problem for me comes when trying to load in a simple box model I have made in Blender. When I run the program I get an exception on the following line:
StaticTriangleGroup.StaticTriangleGroupVertex[] vertices;
int[] indices;
StaticTriangleGroup.GetVerticesAndIndicesFromModel(boxModel, out vertices, out indices);
var mesh = new TriangleMesh(vertices, indices);
mesh.WorldMatrix = Matrix.CreateTranslation(new Vector3(0, 0, 0));
var group = new StaticTriangleGroup(mesh);
game.gameSpace.Add(group);
game.modelDrawer.Add(mesh);
The exception is Unsupported vertex type in mesh. I'm not really sure what is happening. The cube model is about as simple as it gets! Any help would be appreciated so I can better understand loading custom models. Thanks!
Help with loading model files
Re: Help with loading model files
The GetVerticesAndIndicesFromModel method is just a convenience method that grabs an index and vertex buffer from a content pipeline-loaded model. It was recently changed to support only few vertex types uniformly across all platforms. The old system handled more formats, but didn't work properly on the WP7 hardware due a known bug in one of the XNA VertexBuffer.GetData methods.
The convenience method will probably be improved in the future, but it's not a high priority since it doesn't do anything special (and isn't really related to physics
). Usually, I just recommend using a custom content processor to extract vertices. An example of such a processor can be found in the Triangle Picking sample on the XNA website.
The mesh just wants a vertex and index list, it doesn't care where they come from
The convenience method will probably be improved in the future, but it's not a high priority since it doesn't do anything special (and isn't really related to physics

The mesh just wants a vertex and index list, it doesn't care where they come from

Re: Help with loading model files
Thanks for the reply. I will check out that example on the XNA site and see if I can get it working!
-
- Posts: 249
- Joined: Wed Nov 17, 2010 1:49 pm
Re: Help with loading model files
Extracting the indices from a model is as follows:
Hope that helps 
Code: Select all
// Load your model
Model model = Game.Content.Load<Model>(assetName);
// Loop through each mesh and mesh part
// MESH = model.Meshes[n];
// MESHPART = model.Meshes[n].MeshParts[n];
// Extract the indices
int index = meshPart.StartIndex;
int numTriangles = meshPart.PrimitiveCount;
modelExtractData.indices = new ushort[numTriangles * 3];
mesh.IndexBuffer.GetData<ushort>(
index * 2,
modelExtractData.indices,
0,
numTriangles * 3
);

Re: Help with loading model files
This helps a bit, but I'm still a little lost. Can you explain to me what your modelExtractData is? And how the indices are being stored in there? Thanks!
-
- Posts: 249
- Joined: Wed Nov 17, 2010 1:49 pm
Re: Help with loading model files
'ModelExtractData' is a simple class. It has a property called 'indices', which is an array:
This line sets the array size:
Which is the same as:
Only I'm accessing the indices array through the class as opposed to directly.
Code: Select all
ushort[] indices;
Code: Select all
modelExtractData.indices = new ushort[numTriangles * 3];
Code: Select all
ushort[] indices = new ushort[numTriangles * 3];