blender: how to export shape keys using python?
I want to export shape keys for some object. How can i get access to a shape key's mesh ? I'm using blender 2.59. Th开发者_开发问答anks
i did it. Here is the script. maybe it would be helpful for someone:
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()
精彩评论