В 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'}
Бывает, что перед этимвставляет все ключевые кадры и только после того, как вы можете перемещать куб с помощью мыши, например.Я бы хотел переместить куб и одновременно «записать» его движение.Есть ли решение для этого?