在MAYA 2009中,是否可以捕获立方体旋转事件?
我需要根据立方体的旋转角度(rotationX)来调用一个函数(Maya-Python)。为此,我需要以编程的方式捕捉这个事件。
我尝试使用循环,但这样会导致程序卡在循环里,这段时间内什么都不能做。
我也尝试了线程(python),结果还是一样。
这样做可以吗?或者有没有其他方法?如果可以的话,怎么做呢?
使用的是Maya 2009,操作系统是Windows XP
一些失败的代码示例:
import maya.cmds as cmds
while (count < 90):
lock = cmds.getAttr('pCube1.rotateX',lock=False)
print lock
count = count + 1
这里是Python相关的:
#!/usr/bin/python
import thread
import time
# Define a function for the thread
def cubeRotateX( threadName, delay):
count = 0
while count < 5:
time.sleep(delay)
count += 1
try:
thread.start_new_thread( cubeRotateX, ("Thread-1", 2, ) )
except:
print "Error: unable to start thread"
while 1:
pass
1 个回答
1
听起来你可能需要用到scriptJob。下面是一个简单的例子。不过在这个例子中,回调函数只会在你松开鼠标后才会被调用,也就是在你停止旋转的时候。
import maya.cmds
def myRotateCallback():
print 'do something'
maya.cmds.scriptJob( attributeChange=['pCube1.rotateX', myRotateCallback] )
如果你想在旋转立方体的时候持续接收到回调,可以通过maya的API来实现,使用MNodeMessage::addNodeDirtyPlugCallback这个方法。