• 11
• 27
• 9
• 20
• 31

# trianglelist from mesh

This topic is 1761 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

There is probably reference to code to do this action already, please point me in the right direction

I am trying to draw triangles from a mesh in directx x file

The directx x file is exported from blender .. I have not taken care of the mirrored part yet

the code I am trying (very badly put together by me) only draws every other triangle, what have I missed?

I am using .. C#, sharpdx and assimp net

ASI.Scene model = importer.ImportFile(fileName,
ASI.PostProcessPreset.TargetRealTimeMaximumQuality);

var vertices = new VertexBuffer(device,
Utilities.SizeOf() * 2 * model.Meshes[0].VertexCount, Usage.WriteOnly,
VertexFormat.None, Pool.Managed);

Vector4[] VSet = new Vector4[model.Meshes[0].VertexCount * 2];

foreach (ASI.Mesh AMesh in model.Meshes)
{
int i2 = -1;
for(int i1 = 0; i1 < AMesh.VertexCount * 2; i1++)
{
i2++;
VSet[i1] = new Vector4(AMesh.Vertices[i2][0], AMesh.Vertices[i2][1], AMesh.Vertices[ i2][2], 1.0f);
i1++;
VSet[i1] = new Vector4(AMesh.Normals[i2][0], AMesh.Normals[i2][1], AMesh.Normals[i2] [2], 1.0f);
}
break;
}
vertices.Lock(0, 0, LockFlags.None).WriteRange(VSet);


then draw with:

device.DrawPrimitives(PrimitiveType.TriangleList, 0, model.Meshes[0].VertexCount / 3);

##### Share on other sites

That mesh has quads. Use Assimp.PostProcessSteps.Triangulate.

Edit: Hmmm, that preset does include the triangulate flag already. I think you should iterate over the faces, not the vertices directly. Even better: use an index buffer and DrawIndexedPrimitive.

Edited by unbird

##### Share on other sites

oops! sorry now I see .. I am just throwing the vertices at the renderer without providing a the usage of each vertex in the faces .. doh!

*blush*

Thx unbird ... thx for putting me back on track and not calling me stooopid ...