Created
October 17, 2020 11:50
-
-
Save kamera25/59aaec194293dc1fc9326b1e685bc0c8 to your computer and use it in GitHub Desktop.
Blenderで、頂点とメッシュデータをPython配列用に抽出するスクリプト
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 | |
# 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