2017-10-07 69 views
1

我是一個混合器新手,並且已經使用以下腳本將每個幀的所有混合形狀權重轉儲爲文本文件 - 每個新行都會帶一個幀在動畫序列中。在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") 

回答

0

回答自己的問題。

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") 
相關問題