Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kamera25
Created October 17, 2020 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamera25/59aaec194293dc1fc9326b1e685bc0c8 to your computer and use it in GitHub Desktop.
Save kamera25/59aaec194293dc1fc9326b1e685bc0c8 to your computer and use it in GitHub Desktop.
Blenderで、頂点とメッシュデータをPython配列用に抽出するスクリプト
import bpy
# Get Variables.
obj = bpy.context.active_object
mesh = obj.data
print ( f"# Convert vertexs and face from \"{obj.name}\".")
# Print Vertexs.
vertNum = len(mesh.vertices)
print( f"# of vertices={vertNum}")
vertFirstStr = '\t( '
print( "_vertexsData = [")
for vert in mesh.vertices:
print( f"{vertFirstStr} {vert.co.x}, {vert.co.y}, {vert.co.z} )")
vertFirstStr = "\t, ("
print( "]")
# Print faces.
faceNum = len(mesh.polygons)
print( f"# of faces={faceNum}")
faceFirstStr = '\t('
print( "_facesData = [")
for face in mesh.polygons:
strVerts = faceFirstStr
for vert in face.vertices:
strVerts += f" {vert} ,"
strVerts = strVerts.rstrip(',')
strVerts += ')'
print(strVerts)
faceFirstStr = '\t, ('
print( "]")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment