在maya中为每个对象写入混合形状权重到文本文件
问题描述:
我是一个混合器新手,并且已经使用以下脚本将每个帧的所有混合形状权重转储为文本文件 - 每个新行都会带一个帧在动画序列中。在maya中为每个对象写入混合形状权重到文本文件
import bpy
sce = bpy.context.scene
ob = bpy.context.object
filepath = "blendshape_tracks.txt"
file = open(filepath, "w")
for f in range(sce.frame_start, sce.frame_end+1):
sce.frame_set(f)
vals = ""
for shapeKey in bpy.context.object.data.shape_keys.key_blocks:
if shapeKey.name != 'Basis':
v = str(round(shapeKey.value, 8)) + " "
vals += v
vals = vals[0:-2]
file.write(vals + "\n");
正如你可以看到这是在搅拌机超级容易,但现在我试图做同样的事情在Maya中。之前我试图以不同的格式将三维模型引入; DAE和FBX(尝试了ascii和bin以及不同的年份版本),但Blender不会导入它们(每次都会收到大量错误)。
所以基本上我问的是如何通过python或MEL在maya中做同样的事情?我检查了动画制作工具api,但没有线索从哪里开始。
提前欢呼。
编辑:好的,我想通了。令人惊讶的是,一旦你掌握了cmds库就很容易。
import maya.cmds as cmds
filepath = "blendshape_tracks.txt"
file = open(filepath, "w")
startFrame = cmds.playbackOptions(query=True,ast=True)
endFrame = cmds.playbackOptions(query=True,aet=True)
for i in range(int(startFrame), int(endFrame)):
vals = ""
cmds.currentTime(int(i), update=True)
weights = cmds.blendShape('blendshapeName',query=True,w=True)
vals = ""
for w in weights:
v = str(round(w, 8)) + " "
vals += v
vals = vals[0:-2]
file.write(vals + "\n")
答
回答自己的问题。
import maya.cmds as cmds
filepath = "blendshape_tracks.txt"
file = open(filepath, "w")
startFrame = cmds.playbackOptions(query=True,ast=True)
endFrame = cmds.playbackOptions(query=True,aet=True)
for i in range(int(startFrame), int(endFrame)):
vals = ""
cmds.currentTime(int(i), update=True)
weights = cmds.blendShape('blendshapeName',query=True,w=True)
vals = ""
for w in weights:
v = str(round(w, 8)) + " "
vals += v
vals = vals[0:-2]
file.write(vals + "\n")