Created
June 25, 2019 17:31
-
-
Save vigonotion/9b8001c656a6246cf8e1a3455fb7da37 to your computer and use it in GitHub Desktop.
Blender script to export as a geometry for three.js
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, 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