将 maya 中每帧对象的混合变形权重写入文本文件

Write blendshape weights for object per frame in maya to text file

我是一名 Blender 新手,一直在使用以下脚本将对象每帧的所有 blendshape 权重转储到一个文本文件中 - 每一个新行都会在动画序列中带来一个帧。

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");

如您所见,这在 Blender 中非常容易,但现在我正尝试在 Maya 中做同样的事情。之前我试图以不同的格式将 3d 模型带过来; 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")