Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.