Skip to content

Instantly share code, notes, and snippets.

@takumikinjo
Created September 17, 2011 00:27
Show Gist options
  • Save takumikinjo/1223452 to your computer and use it in GitHub Desktop.
Save takumikinjo/1223452 to your computer and use it in GitHub Desktop.
import bpy
mesh = bpy.context.active_object.data
uv_coord_list = []
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
bpy.ops.mesh.quads_convert_to_tris()
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
uvtex = mesh.uv_textures.active
f = open('/Users/kinjo/foo', 'w')
f.write('private float vertices[] = {')
for face in mesh.faces:
for v in face.vertices:
co = mesh.vertices[v].co
f.write(str(co.x) + 'f, ' + str(co.y) + 'f, ' + str(co.z) + 'f, \n')
f.write('};\n')
f.write('private float normals[] = {')
for face in mesh.faces:
for v in face.vertices:
norm = mesh.vertices[v].normal
f.write(str(norm.x) + 'f, ' + str(norm.y) + 'f, ' + str(norm.z) + 'f, \n')
f.write('};\n')
f.write('private float texture[] = {')
for i, uv in enumerate(uvtex.data):
uvs = uv.uv1, uv.uv2, uv.uv3, uv.uv4
for j, v in enumerate(mesh.faces[i].vertices):
vertex = mesh.vertices[v]
uv_coord_list.append(uvs[j])
f.write(str(uv_coord_list[-1][0]) + 'f, ' + str(uv_coord_list[-1][1]) + 'f, \n')
f.write('};\n')
f.write('private short indices[] = {')
i = 0
for face in mesh.faces:
for v in range(len(face.vertices)):
f.write('%d, ' % i)
i += 1
f.write('\n};\n')
f.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment