Skip to content

Instantly share code, notes, and snippets.

@vigonotion
Created June 25, 2019 17:31
Show Gist options
  • Save vigonotion/9b8001c656a6246cf8e1a3455fb7da37 to your computer and use it in GitHub Desktop.
Save vigonotion/9b8001c656a6246cf8e1a3455fb7da37 to your computer and use it in GitHub Desktop.
Blender script to export as a geometry for three.js
import bpy, os
result = ""
obdata = bpy.context.object.data
result += 'Vertices: \n'
for v in obdata.vertices:
result += ('{}, {}, {}, '.format(v.co.x, v.co.z, v.co.y)) + '\n'
result += 'Edges: \n'
for e in obdata.edges:
result += ('{}, {}, '.format(e.vertices[0], e.vertices[1])) + '\n'
result += 'Faces: \n'
for f in obdata.polygons:
result += ('{}, {}, {}, '.format(f.vertices[2], f.vertices[1], f.vertices[0]))
result += '\n'
# get path to render output (usually /tmp\)
tempFolder = os.path.abspath (bpy.context.scene.render.filepath)
# make a filename
filename = os.path.join (tempFolder, "vertices.txt")
# open a file to write to
file = open(filename, "w")
# write the data to file
file.write(result)
# close the file
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment