Maya脚本:在Maya viewport视图中,模型显示为白色怎么去修复?

snipaste_2023-10-22_02-16-44

在Maya viewport视图中,模型显示为白色怎么去修复?通常针对这样的模型,重新指定材质是完全没用的。这里我们可以选择模型,执行这段修复代码就可以解决这个问题。

string $select_dd[] = `ls -shapes -sl`;
setAttr ($select_dd[0] + ".displayColors") 1;
setAttr ($select_dd[0] + ".displayColors") 0;

现在我们也能够给模型正常指定材质了那么目前,我也只知道这种修复方法。如果你有更好的解决方案,欢迎与大家分享!

原作者:视口中的白色表面错误 – Denes Dankhazi’s Blogfolio (ddankhazi.com)

Maya脚本:Maya动画滑步修复工具,适用于常规绑定的人和动物模型

bilib8_17-17-47

Python代码


import maya.cmds as cmds

def updateInfo(*args):
    selected_objects = cmds.ls(selection=True)
    if selected_objects:
        selected_object = selected_objects[0]
        
        current_frame = cmds.currentTime(query=True)
        translate_z = cmds.getAttr(selected_object + ".translateZ")
        
        cmds.floatField(currentFrameField, edit=True, value=current_frame)
        cmds.floatField(translateZField, edit=True, value=translate_z)
    else:
        cmds.confirmDialog(title="警告", message="请选择一个对象。", button="好")

def updateInfo1(*args):
    selected_objects = cmds.ls(selection=True)
    if selected_objects:
        selected_object = selected_objects[0]
        
        current_frame = cmds.currentTime(query=True)
        translate_z = cmds.getAttr(selected_object + ".translateZ")
        
        cmds.floatField(currentFrameField1, edit=True, value=current_frame)
        cmds.floatField(translateZField1, edit=True, value=translate_z)
    else:
        cmds.confirmDialog(title="警告", message="请选择一个对象。", button="好")

def calculateDifference(*args):
    translate_z1 = cmds.floatField(translateZField1, query=True, value=True)
    translate_z = cmds.floatField(translateZField, query=True, value=True)
    current_frame1 = cmds.floatField(currentFrameField1, query=True, value=True)
    current_frame = cmds.floatField(currentFrameField, query=True, value=True)
    
    result = (translate_z1 - translate_z) / (current_frame1 - current_frame)
    cmds.floatField(resultField, edit=True, value=result)

def applyNewTranslateZ(*args):
    selected_objects = cmds.ls(selection=True)
    if selected_objects:
        selected_object = selected_objects[0]
        
        new_translate_z = cmds.getAttr(selected_object + ".translateZ") + cmds.floatField(resultField, query=True, value=True)
        current_frame = cmds.currentTime(query=True)
        
        original_translate_z = cmds.getAttr(selected_object + ".translateZ", time=current_frame)
        
        cmds.currentTime(current_frame + 1, edit=True)
        
        cmds.setAttr(selected_object + ".translateZ", new_translate_z)
        
        cmds.setKeyframe(selected_object, attribute="translateZ", t=current_frame + 1, v=new_translate_z)

if cmds.window("myWindow", exists=True):
    cmds.deleteUI("myWindow")

window = cmds.window("myWindow", title="滑步修复工具@喵喵动画屋", widthHeight=(250, 350))
main_layout = cmds.columnLayout()

cmds.text(label="选定一个对象并点击下面的按钮来获取信息。")

cmds.rowLayout(numberOfColumns=2, columnWidth2=(120, 70))
cmds.text(label="当前关键帧:")
currentFrameField = cmds.floatField(value=0, precision=0, editable=False)
cmds.setParent("..")

cmds.rowLayout(numberOfColumns=2, columnWidth2=(120, 70))
cmds.text(label="位移Z:")
translateZField = cmds.floatField(value=0, precision=4, editable=False)
cmds.setParent("..")

cmds.button(label="获取起始帧信息", command=updateInfo)

cmds.separator(height=20, style="none")

cmds.rowLayout(numberOfColumns=2, columnWidth2=(120, 70))
cmds.text(label="当前关键帧:")
currentFrameField1 = cmds.floatField(value=0, precision=0, editable=False)
cmds.setParent("..")

cmds.rowLayout(numberOfColumns=2, columnWidth2=(120, 70))
cmds.text(label="位移Z:")
translateZField1 = cmds.floatField(value=0, precision=4, editable=False)
cmds.setParent("..")

cmds.button(label="获取结束帧信息", command=updateInfo1)

cmds.separator(height=20, style="none")

cmds.rowLayout(numberOfColumns=2, columnWidth2=(120, 70))
cmds.button(label="计算差值", command=calculateDifference)
resultField = cmds.floatField(value=0, precision=4, editable=False)
cmds.setParent("..")

cmds.separator(height=20, style="none")

cmds.rowLayout(numberOfColumns=2, columnWidth2=(120, 70))
cmds.button(label="开始修复滑步", command=applyNewTranslateZ)
cmds.setParent("..")

cmds.text(label="从“脚踩地”的这一帧开始修复,直到“脚离地”前一帧!", align="left")

cmds.showWindow(window)

Python code (English interface)


import maya.cmds as cmds

def updateInfo(*args):
    selected_objects = cmds.ls(selection=True)
    if selected_objects:
        selected_object = selected_objects[0]
        
        current_frame = cmds.currentTime(query=True)
        translate_z = cmds.getAttr(selected_object + ".translateZ")
        
        cmds.floatField(currentFrameField, edit=True, value=current_frame)
        cmds.floatField(translateZField, edit=True, value=translate_z)
    else:
        cmds.confirmDialog(title="Warning", message="Please select an object.", button="OK")

def updateInfo1(*args):
    selected_objects = cmds.ls(selection=True)
    if selected_objects:
        selected_object = selected_objects[0]
        
        current_frame = cmds.currentTime(query=True)
        translate_z = cmds.getAttr(selected_object + ".translateZ")
        
        cmds.floatField(currentFrameField1, edit=True, value=current_frame)
        cmds.floatField(translateZField1, edit=True, value=translate_z)
    else:
        cmds.confirmDialog(title="Warning", message="Please select an object.", button="OK")

def calculateDifference(*args):
    translate_z1 = cmds.floatField(translateZField1, query=True, value=True)
    translate_z = cmds.floatField(translateZField, query=True, value=True)
    current_frame1 = cmds.floatField(currentFrameField1, query=True, value=True)
    current_frame = cmds.floatField(currentFrameField, query=True, value=True)
    
    result = (translate_z1 - translate_z) / (current_frame1 - current_frame)
    cmds.floatField(resultField, edit=True, value=result)

def applyNewTranslateZ(*args):
    selected_objects = cmds.ls(selection=True)
    if selected_objects:
        selected_object = selected_objects[0]
        
        new_translate_z = cmds.getAttr(selected_object + ".translateZ") + cmds.floatField(resultField, query=True, value=True)
        current_frame = cmds.currentTime(query=True)
        
        original_translate_z = cmds.getAttr(selected_object + ".translateZ", time=current_frame)
        
        cmds.currentTime(current_frame + 1, edit=True)
        
        cmds.setAttr(selected_object + ".translateZ", new_translate_z)
        
        cmds.setKeyframe(selected_object, attribute="translateZ", t=current_frame + 1, v=new_translate_z)

if cmds.window("myWindow", exists=True):
    cmds.deleteUI("myWindow")

window = cmds.window("myWindow", title="Slide Fix Tool @ Meow Animation Studio", widthHeight=(250, 350))
main_layout = cmds.columnLayout()

cmds.text(label="Select an object and click the buttons below to get information.")

cmds.rowLayout(numberOfColumns=2, columnWidth2=(120, 70))
cmds.text(label="Current Frame:")
currentFrameField = cmds.floatField(value=0, precision=0, editable=False)
cmds.setParent("..")

cmds.rowLayout(numberOfColumns=2, columnWidth2=(120, 70))
cmds.text(label="Translate Z:")
translateZField = cmds.floatField(value=0, precision=4, editable=False)
cmds.setParent("..")

cmds.button(label="Get Start Frame Info", command=updateInfo)

cmds.separator(height=20, style="none")

cmds.rowLayout(numberOfColumns=2, columnWidth2=(120, 70))
cmds.text(label="Current Frame:")
currentFrameField1 = cmds.floatField(value=0, precision=0, editable=False)
cmds.setParent("..")

cmds.rowLayout(numberOfColumns=2, columnWidth2=(120, 70))
cmds.text(label="Translate Z:")
translateZField1 = cmds.floatField(value=0, precision=4, editable=False)
cmds.setParent("..")

cmds.button(label="Get End Frame Info", command=updateInfo1)

cmds.separator(height=20, style="none")

cmds.rowLayout(numberOfColumns=2, columnWidth2=(120, 70))
cmds.button(label="Calculate Difference", command=calculateDifference)
resultField = cmds.floatField(value=0, precision=4, editable=False)
cmds.setParent("..")

cmds.separator(height=20, style="none")

cmds.rowLayout(numberOfColumns=2, columnWidth2=(120, 70))
cmds.button(label="Start Slide Fix", command=applyNewTranslateZ)
cmds.setParent("..")

cmds.text(label="Start fixing from the frame where the foot touches the ground, until the frame just before the foot leaves the ground!", align="left")

cmds.showWindow(window)

Maya脚本:平移旋转自动归零

mel14
//by 喵喵动画屋  旋转归零

string $lanzi[] = `ls -sl`;
int $shuliang = size($lanzi);
print($shuliang+"\n");

for($i=0;$i<$shuliang;$i++)
{
    print($lanzi[$i]+"\n");
    
   int $rotate_ret = `getAttr -se ($lanzi[$i]+".rotateX")`; 
   if($rotate_ret==1)
   {
        setAttr ($lanzi[$i]+".rotateX") 0;  
   }
   
   $rotate_ret = `getAttr -se ($lanzi[$i]+".rotateY")`; 
   if($rotate_ret==1)
   {
        setAttr ($lanzi[$i]+".rotateY") 0;  
   }
   
   $rotate_ret = `getAttr -se ($lanzi[$i]+".rotateZ")`; 
   if($rotate_ret==1)
   {
        setAttr ($lanzi[$i]+".rotateZ") 0;  

   }
   
   

     print($rotate_ret+"\n"); 

}


//by 喵喵动画屋  平移归零

string $lanzi[] = `ls -sl`;
int $shuliang = size($lanzi);
print($shuliang+"\n");

for($i=0;$i<$shuliang;$i++)
{
    print($lanzi[$i]+"\n");
    
   int $translate_ret = `getAttr -se ($lanzi[$i]+".translateX")`; 
   if($translate_ret==1)
   {
        setAttr ($lanzi[$i]+".translateX") 0;  
   }
   
   $translate_ret = `getAttr -se ($lanzi[$i]+".translateY")`; 
   if($translate_ret==1)
   {
        setAttr ($lanzi[$i]+".translateY") 0;  
   }
   
   $translate_ret = `getAttr -se ($lanzi[$i]+".translateZ")`; 
   if($translate_ret==1)
   {
        setAttr ($lanzi[$i]+".translateZ") 0;  

   }
   
   

     print($translate_ret+"\n"); 

}