【发布时间】:2019-04-18 19:53:15
【问题描述】:
在 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'}
例如,在它插入所有关键帧之前,并且只有在您可以用鼠标移动立方体之后才会发生这种情况。我想移动立方体并同时“记录”它的运动。有解决办法吗?
【问题讨论】:
标签: python modal-dialog operator-keyword blender