Last active
December 25, 2019 05:16
-
-
Save redglasses67/75adfc52c7de434b393c60d782b4a425 to your computer and use it in GitHub Desktop.
キーフレームを取得、変更する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import maya.api.OpenMaya as om2 | |
import maya.api.OpenMayaAnim as oma2 | |
selList = om2.MGlobal.getActiveSelectionList() | |
mObject = selList.getDependNode(0) | |
# findPlug を使って取得する場合 | |
dependencyNode = om2.MFnDependencyNode(mObject) | |
transXplug = dependencyNode.findPlug('tx', 0) | |
ctx = om2.MDGContext(om2.MTime(5.0)) # 5フレーム目の値が出力されます。 | |
transXval = transXplug.asDouble(ctx) | |
print("translate X = %s" %transXval) | |
# 現在のフレームを取得する方法 | |
currentTime = oma2.MAnimControl.currentTime() | |
# ちなみに現在のフレームを変更する方法 ( 現在のフレームを10フレーム目に変更 ) | |
oma2.MAnimControl.setCurrentTime(om2.MTime(10.0)) | |
# animCurve を取得してキーフレーム | |
animCurves = [] | |
mItDependencyGraph = om2.MItDependencyGraph( | |
mObject, | |
om2.MItDependencyGraph.kUpstream, | |
om2.MItDependencyGraph.kPlugLevel) | |
# mItDependencyGraph をまわす | |
while not mItDependencyGraph.isDone(): | |
currentNode = mItDependencyGraph.currentNode() | |
# animCurve かどうか判別 | |
if currentNode.hasFn(om2.MFn.kAnimCurve): | |
animCurve = oma2.MFnAnimCurve(currentNode) | |
animCurves.append(animCurve) | |
mItDependencyGraph.next() | |
if len(animCurves) == 0: | |
print("no animCurve...") | |
else: | |
for animCurve in animCurves: | |
# キーフレームを取得 | |
print("\nanimCurve key count = %s" %animCurve.numKeys) | |
for i in range(0, animCurve.numKeys): | |
time = animCurve.input(i) | |
val = animCurve.value(i) | |
print("time = %s : val = %s" %(time, val)) | |
print("animCurve = %s" %animCurve.animCurveType) | |
#print("animCurve timedAnimCurveTypeForPlug = %s" %animCurve.timedAnimCurveTypeForPlug) | |
# キーフレームを設定 | |
# addKey(Time, Value) | |
# kAnimCurveTA, kAnimCurveTL, kAnimCurveTT, kAnimCurveTU の場合 第1引数は MTime | |
# kAnimCurveUA, kAnimCurveUL, kAnimCurveUT, kAnimCurveUU の場合 第1引数は double | |
animCurve.addKey(om2.MTime(5.0), 10.0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment