Skip to main content
GameDev.net gamedev.net
🔒 Locked

trianglelist from mesh

Started by zeppeldep May 19, 2013 at 11:52 AM 2 replies 1.6k views
Original Post
zeppeldep
zeppeldep

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);

unbird
unbird

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.

zeppeldep
zeppeldep

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 ...

unbird
unbird
laugh.png. Well that would violate both netiquette and forum rules. I also don't think there are stupid questions per se: We all started "from zero" somewhere you know. One can ask stupidly though - or lazily.

Also: My own experience with assimp is no more than a couple of weeks, so I might well miss something here. I recommend playing around with the assimp_view.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.