我想导出某些对象的形状键。如何才能访问形状键的网格? 我正在使用搅拌机2.59。感谢
答案 0 :(得分:7)
import bpy
import xml.dom.minidom
path = "/Users/x/Documents/y/game_projects/test.xml"
dom = xml.dom.minidom.getDOMImplementation()
tree = dom.createDocument(None, "document", None)
root = tree.documentElement
root.setAttribute("version", "0.1")
for object in bpy.data.objects:
if object.type == 'MESH' and object.data.shape_keys:
objectElement = tree.createElement("object")
objectElement.setAttribute("name", object.name)
root.appendChild(objectElement)
keysElement = tree.createElement("shape_keys")
objectElement.appendChild(keysElement)
keyBlocks = object.data.shape_keys.key_blocks
for block in keyBlocks:
keyElement = tree.createElement("key")
keyElement.setAttribute("name", block.name)
keysElement.appendChild(keyElement)
for data in block.data:
vertex = data.co
element = tree.createElement("vertex")
element.setAttribute("x", str(vertex.x))
element.setAttribute("y", str(vertex.y))
element.setAttribute("z", str(vertex.z))
keyElement.appendChild(element)
file = open(path, "w", encoding="utf8")
tree.writexml(file, encoding = "UTF-8", indent = "\n", addindent = "\t")
file.close()