在Blender中,我使用模态操作符模板来移动对象并将其位置记录为关键帧。在
我在做这样的事情:
import bpy
from bpy.props import IntProperty, FloatProperty
class ModalOperator(bpy.types.Operator):
"""Move an object with the mouse, example"""
bl_idname = "object.modal_operator"
bl_label = "Simple Modal Operator"
first_mouse_x = IntProperty()
first_value = FloatProperty()
current_frame = 1
endframe = bpy.data.scenes["Scene"].frame_end
def modal(self, context, event):
if event.type == 'MOUSEMOVE':
if self.current_frame < self.endframe:
delta = self.first_mouse_x - event.mouse_x
context.object.location.x = self.first_value + delta * 0.01
context.scene.frame_set(self.current_frame)
bpy.ops.anim.keyframe_insert_menu(type="Rotation")
bpy.ops.anim.keyframe_insert_menu(type="Location")
self.current_frame+=1
elif event.type == 'LEFTMOUSE':
return {'FINISHED'}
elif event.type in {'RIGHTMOUSE', 'ESC'}:
context.object.location.x = self.first_value
return {'CANCELLED'}
return {'RUNNING_MODAL'}
例如,在它插入所有关键帧之前,并且只有在你可以用鼠标移动立方体之后才会发生这种情况。我想移动立方体,同时“记录”它的运动。有解决办法吗?在
好吧,我解决了这个问题。在
我给错误的对象调用了keyframe_insert(动画,而不是立方体本身)
这是正确的插入方式,例如当对象是摄影机时:
以这种方式,关键帧在播放时插入。在
简单的解决方案是启用搅拌机Auto Keyframing。在
如果您仍然想让您的运算符工作,我希望您不需要调用其他运算符直接处理数据,尤其是在模态运算符中。在
相关问题 更多 >
编程相关推荐