【问题标题】:Write blendshape weights for object per frame in maya to text file将maya中每帧对象的混合形状权重写入文本文件
【发布时间】:2017-10-08 08:51:23
【问题描述】:

我是搅拌机新手,一直在使用以下脚本将对象每帧的所有 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")

【问题讨论】:

    标签: python blender maya


    【解决方案1】:

    回答自己的问题。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-08
      • 2017-11-06
      • 2016-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-20
      相关资源
      最近更新 更多