blender:如何使用python导出形状键?

时间:2011-09-26 10:27:34

标签: python export blender

我想导出某些对象的形状键。如何才能访问形状键的网格? 我正在使用搅拌机2.59。感谢

1 个答案:

答案 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()