3
$\begingroup$

I wrote a custom parser for .blend files using some of the info found here. I can read the structs inside the file, one of these is a Mesh and I would like to render that mesh in my application. I'm having trouble figuring out what to read from this Mesh struct.

I found two properties: mvert and medge, the first is a list of vertices and the second a list of edges (an edge is a pair of indices to the first list.)

Theoretically this is all I need, but turning a list of edges into triangles for rendering seems non-trivial, the brute force solution is slow and I couldn't find another solution on the internet.

I also found the mpoly property, it seems promising since its count is always the number of faces in the mesh, but I can't make sense of the properties (loopstart and totloop being the ones that seem more relevant.)

So my question is: which properties from the Mesh struct should I read and is any of them a closer representation to triangles than just a list of edges?

$\endgroup$
3
+50
$\begingroup$

For a basic engine you need to extract mvert which is an array of the vertices of the model. Within an item of this array the co attribute will contain the local vertex coordinate of a vertex. the no attribute contains the normal of that vertex.

The mpoly contains the face data as edge loops around the face. As a face within Blender can contain a finite amount of vertices you will need to triangulate the faces yourself. At forehand in blender, or later in your own code. An mpoly contains a loopstart as an index into mloop and a totloop as number of sequential entries that construct the face.

The mloop contains the data for the edge loops. It has a v for vertex index and a e as edge index.

$\endgroup$
  • $\begingroup$ To triangulate yourself, you can make a call to bpy.types.Mesh.update (calc_tessface=True), before exporting? $\endgroup$ – Robin Betts Apr 4 '18 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.