Last active
October 12, 2015 09:48
-
-
Save zeffii/0de692af99c18499d205 to your computer and use it in GitHub Desktop.
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 bpy | |
scene = bpy.context.scene | |
file_name = 'massive.tkg' | |
file_location = '/home/zeffii/Desktop/sw/' | |
with open(file_location + file_name, 'w') as ofile: | |
array_contenders = [] | |
for obj in bpy.context.selected_objects: | |
scene.objects.active = obj | |
bpy.ops.object.mode_set(mode='EDIT', toggle=False) | |
bpy.ops.mesh.select_all(action='SELECT') | |
bpy.ops.mesh.quads_convert_to_tris(quad_method='BEAUTY', ngon_method='BEAUTY') | |
bpy.ops.object.mode_set(mode='OBJECT', toggle=False) | |
# verts | |
objname = obj.name.replace('.', '_') | |
array_contenders.append(objname) | |
ofile.write('var %s = {\n' % objname) | |
ofile.write(' verts: [') | |
verts = obj.data.vertices | |
for v in verts[:-1]: | |
ofile.write("%.4f, %.4f, %.4f, " % v.co[:]) | |
ofile.write("%.4f, %.4f, %.4f],\n" % verts[-1].co[:]) | |
# faces | |
ofile.write(' faces: [') | |
polygons = obj.data.polygons | |
for face in polygons[:-1]: | |
ofile.write('%i, %i, %i, ' % face.vertices[:]) | |
ofile.write('%i, %i, %i],\n' % polygons[-1].vertices[:]) | |
# edges | |
edges_subset = [e for e in obj.data.edges if e.crease == 1.0] | |
ofile.write(' edges: [') | |
for edge in edges_subset[:-1]: | |
ofile.write('%i, %i, ' % edge.vertices[:]) | |
ofile.write('%i, %i]\n' % edges_subset[-1].vertices[:]) | |
ofile.write('};\n') | |
ofile.write('var master_array = [') | |
for o in array_contenders: | |
ofile.write(o + ',') | |
ofile.write(']\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment