I was wondering if anyone could help me. I'm hoping to come up with a simple Python script that exports data from an object in a scene.
I've written a little 3d renderer for fun, and my project relies on me manually setting vertices and triangles in script to set up objects. It would be a lot easier if I could just copy and paste from the python console into my script.
So far I've come across this script:
import bpy
current_obj = bpy.context.active_object
print("="*40) # printing marker
for face in current_obj.data.polygons:
verts_in_face = face.vertices[:]
print("face index", face.index)
print("normal", face.normal)
for vert in verts_in_face:
local_point = current_obj.data.vertices[vert].co
world_point = current_obj.matrix_world * local_point
print("vert", vert, " vert co", world_point)
However this outputs the vertices in no particular order, and in the format
face index 4
normal <Vector (0.0000, -1.0000, 0.0000)>
vert 8 vert co <Vector (0.0000, -0.0000, -3.0000)>
I'd really like to get it in a format like this:
vertices[0].SetVertex (-1.0, -1.0, -3.0); //vertex coordinates
vertices[1].SetVertex (1.0, -1.0, -3.0);
vertices[2].SetVertex (1.0, 1.0, -3.0);
and
mesh[0].SetTriangle (0, 3, 2); //vertex indices
It would make copy/pasting into my script a lot easier.
Is this possible? Can anyone help me? I've never used Python before and I don't know too much about Blender.