Jump to content
  • Advertisement
Sign in to follow this  
zeppeldep

trianglelist from mesh

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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 ...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!