0
$\begingroup$

I'm trying to write a mesh exporter, which would export vertex position, normal, tangent and texture coords. These would be used in my own engine. But I'm not fully understood the data organization in Blender's mesh.

In a GPU pipeline, primitives are usually limited to triangle lists/fans/stripes. However, it seems Blender meshes are organized in individual polygons, which don't have by-material large-sized triangle stripes? Is there any way to get the polygons by material?

I made a simple test geometry by subdividing twice on one surface of a cube, so this cube has 16 polygons on one face, and each one polygon on remaining 5 faces. When Auto Smooth is selected, vertex on different polygons should have different normals. However, the number of vertices is still 29 (by print C.object.data.vertices), which is not increased. So where are the polygon-specific vertices being stored?

$\endgroup$

1 Answer 1

2
$\begingroup$

Vertices are shared, no matter what material etc. the using polygons have.

Per-face vertex data is stored in loops (C.object.data.loops).

The elements of C.object.data.uv_layers[#].data[#] correspond to loop indexes. The first UV coordinate of the active UV map can be retrieved like .uv_layers.active.data[0].uv.

I'm not sure if triangle stripes and fans are still used nowadays. If a game-engine handles vertices like Blender and shares them among faces, there's no real difference in memory consumption...

You may wanna use the Separate P operator and split a mesh by material. Or create a lookup dictionary from material assignments to efficiently retrieve the right polygons.

Elements in C.object.data.uv_textures[#].data[#] correspond to face indexes, e.g. .uv_textures.active.data[0].image for polygons[0]. Note that the image attribute is set via UV / Image Editor, but that there's a second type of material assignment - the one from Material tab in Properties Editor, which sets polygons[#].material_index (just an interger, which is the index of the material in C.object.data.materials[#].

$\endgroup$
2
  • $\begingroup$ I'm writing my own engine using GLES, and I want to use Blender as content creator. OpenGL ES only have triangles, triangle fans and triangle strips. $\endgroup$ Commented Aug 4, 2015 at 2:39
  • 1
    $\begingroup$ Okay, then why not use triangles only? You can use the tessface data, or triangulate using bmesh module. Fans and stripes would make it unnecessarily complex. If needed, split edges to put different textures on adjacent faces. $\endgroup$
    – CodeManX
    Commented Aug 4, 2015 at 4:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .