I have a set of Blender objects that I want to export as a single object.

I process each object, adding vertices, triangles for the exported object.

Dealing with materials for the processed objects is not mentionned here.

Is the following processing principle correct? (I'm asking, as I don't quite get what I expect: The export works.

I have all the expected objects but objects are not properly positioned in the exported world).

Thanks in advance for advices and help.

Code: Select all

```
# obj : object being processed
# data : its mesh data
# For the first object, the following is stored (first 2 instructions because of axis changes):
first_obj_transform = Matrix.Rotation(radians(90), 4, 'X')
first_obj_transform *= Matrix.Scale(-1, 4, Vector((0, 0, 1)))
first_obj_matrix = obj.matrix_world.copy()
Then,
for each object (obj) and its mesh (data):
obj_matrix = obj.matrix_world.copy()
data.calc_tessface() # Compute and update the list of tessellated faces (faces of 3 or 4 vertices)
...
# Take into account the axis changes:
obj_matrix = obj_matrix * first_obj_transform
# Pivot in world coordinates
pivot = Vector([obj.matrix_world.translation[0], obj.matrix_world.translation[1], obj.matrix_world.translation[2]])
# Update pivot applying the axis transformation
new_pivot = first_obj_transform * pivot
obj_matrix.translation = new_pivot[0], new_pivot[1], new_pivot[2]
# Get vertices, normals and UVs from the faces
for face_num, face in enumerate(data.tessfaces):
...
# Process triangle or quad
for face_num, face in enumerate(data.tessfaces):
f_v = face.vertices
...
# Process each vertex for the found triangles
# convert local object coordinates to local coordinates of first object
local_vertex = data.vertices[f_v[vert_num]].co * obj_matrix * first_obj_matrix.inverted()
local_vertex.x += first_obj_matrix.translation[0] - obj_matrix.translation[0]
local_vertex.y += first_obj_matrix.translation[1] - obj_matrix.translation[1]
local_vertex.z += first_obj_matrix.translation[2] - obj_matrix.translation[2]
# Add the converted vertices in the export
...
```