Created
February 29, 2012 17:38
-
-
Save emersonmoretto/1942825 to your computer and use it in GitHub Desktop.
Blender python script to generate 3D model by vertex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
# Output file | |
file = open(os.path.expanduser("~/Desktop/model3d.mdl"), "w") | |
model_object = None | |
model_mesh = None | |
# Search for the first object of type mesh | |
for obj in bpy.context.scene.objects: | |
if obj.type == 'MESH': | |
model_object = obj | |
model_mesh = obj.data | |
# Triangulate | |
model_object.select = True | |
bpy.ops.object.mode_set(mode='EDIT') | |
bpy.ops.mesh.select_all(action='SELECT') | |
bpy.ops.mesh.quads_convert_to_tris() | |
# Write each vertex per line with x,y,z separated by a tab | |
for face in model_mesh.faces: | |
for vertex_index in face.vertices: | |
vertex = model_mesh.vertices[vertex_index] | |
file.write(str(vertex.co[0])) | |
file.write('\t') | |
file.write(str(vertex.co[1])) | |
file.write('\t') | |
file.write(str(vertex.co[2])) | |
file.write('\n') | |
file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment