gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 20:52:04 25 4
gpt4 key购买 nike

我想导出某些对象的形状键。我怎样才能访问形状键的网格?我正在使用 blender 2.59。谢谢

最佳答案

我做到了。这是脚本。也许对某人有帮助:

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

关于python - blender:如何使用 python 导出形状键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7553726/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com