是否可以从Maya外部运行Maya Python脚本并同时在Maya中查看结果?
如果没有,关闭文本输入弹出窗口后,如何使我的跳跃动作代码在Maya中工作而不会终止?
我正在开发一个项目,我使用Leap Motion Device操作Maya Objects,Maya不断询问我输入文本,一旦关闭它,就会终止跳跃动作代码。
任何帮助?
您可以在下面找到我的代码:
from os.path import join
import maya.standalone; maya.standalone.initialize()
import maya.cmds as cmds
import Leap, sys, thread, time
from Leap import CircleGesture, KeyTapGesture, ScreenTapGesture, SwipeGesture
class LeapMotionListener(Leap.Listener) :
# Naming the fingers and bones and states
finger_names = ['Thumb', 'Index', 'Middle', 'Ring', 'Pinky']
bone_names = ['Metacarpal', 'Proximal', 'Intermediate', 'Distal']
state_names = ['STATE_INVALID', 'STATE_START', 'STATE_UPDATE', 'STATE_END']
# Determines what happens when Initialized
def on_init(self, controller):
print("Initialized")
# Determines what happens when connected
def on_connect(self, controller):
print ("Motion Sensor Connected!")
controller.enable_gesture(Leap.Gesture.TYPE_CIRCLE);
controller.enable_gesture(Leap.Gesture.TYPE_KEY_TAP);
controller.enable_gesture(Leap.Gesture.TYPE_SCREEN_TAP);
controller.enable_gesture(Leap.Gesture.TYPE_SWIPE);
def on_disconnect(self, controller):
print("Motion Sensor Disconnected")
def on_exit(self, controller):
print("Exited")
def on_frame(self, controller):
frame = controller.frame()
for gesture in frame.gestures():
if gesture.type is Leap.Gesture.TYPE_CIRCLE:
circle = CircleGesture(gesture)
if circle.pointable.direction.angle_to(circle.normal) <= Leap.PI/2: #If Clockwise
clockwiseness = "clockwise"
else:
clockwiseness = "counter-clockwise"
swept_angle = 0
if circle.state != Leap.Gesture.STATE_START:
#We create a new Circle gesture, with the id of the gesture created by the previous frame
previous = CircleGesture(controller.frame(1).gesture(circle.id))
#We get the angle rotated from the previous frame till the current one
swept_angle = (circle.progress - previous.progress) * 2 * Leap.PI
print "ID: " + str(circle.id) + ", progress: " + str(circle.progress) + ", Radius (mm): " + str(circle.radius) \
+ ", Swept Angle: " + str(swept_angle * Leap.RAD_TO_DEG) + ", Direction: " + clockwiseness
#Create a polyCube when I do a circle gesture
result = cmds.polyCube(w = 9, h = 9 , d = 9, name ='myCube#')
def main():
listener = LeapMotionListener()
controller = Leap.Controller()
controller.add_listener(listener)
print("Press Enter to quit.")
try:
sys.stdin.readline()
except KeyboardInterrupt:
pass
finally:
controller.remove_listener(listener)
if __name__ == "__main__":
main()
答案 0 :(得分:0)
您正在向maya询问行
中的文本框
try:
sys.stdin.readline()
except KeyboardInterrupt:
pass
finally:
controller.remove_listener(listener)
但输入会阻止访问场景。您可能应该添加一个手势来触发断开连接,这样您就不必担心从文本框中出现任何问题。没有SDK就不容易测试,但是这样的话:
class LeapMotionListener(Leap.Listener) :
#... other code here
def on_frame(self, controller):
frame = controller.frame()
for gesture in frame.gestures():
#.... other code here....
if gesture.type is Leap.Gesture.TYPE_SWIPE:
controller.remove_listener(this)
listener = LeapMotionListener()
controller = Leap.Controller()
controller.add_listener(listener)