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)