Example #1
0
File: base.py Project: j20232/bnp
def insert_keyframe(
        obj: bpy.types.Object,
        vec: np.ndarray,
        datapath: str,
        frame: int = bpy.context.scene.frame_current) -> np.ndarray:
    bpy.context.scene.frame_set(frame)
    if datapath == "rotation":
        if obj.rotation_mode == "AXIS_ANGLE":
            datapath = "rotation_axis_angle"
        elif obj.rotation_mode == "QUATERNION":
            datapath = "rotation_quaternion"
        else:
            datapath = "rotation_euler"

    if datapath == "location":
        obj.location = (vec[0], vec[1], vec[2])
    elif datapath == "rotation_euler":
        obj.rotation_mode = "XYZ"
        obj.rotation_euler = (vec[0], vec[1], vec[2])
    elif datapath == "rotation_quaternion":
        obj.rotation_mode = "QUATERNION"
        obj.rotation_quaternion = (vec[0], vec[1], vec[2], vec[3])
    elif datapath == "rotation_axis_angle":
        obj.rotation_mode = "AXIS_ANGLE"
        obj.rotation_axis_angle = (vec[0], vec[1], vec[2], vec[3])
    elif datapath == "scale":
        obj.scale = (vec[0], vec[1], vec[2])
    else:
        raise NotImplementedError("Illegal datapath!")
    obj.keyframe_insert(data_path=datapath, frame=frame)
Example #2
0
File: base.py Project: j20232/bnp
def remove_keyframe(obj: bpy.types.Object, frame: int):
    if obj.rotation_mode == "QUATERNION":
        obj.keyframe_insert(data_path="rotation_quaternion", frame=frame)
        obj.keyframe_delete(data_path="rotation_quaternion", frame=frame)
    elif obj.rotation_mode == "AXIS_ANGLE":
        obj.keyframe_insert(data_path="rotation_axis_angle", frame=frame)
        obj.keyframe_delete(data_path="rotation_axis_angle", frame=frame)
    else:
        obj.keyframe_insert(data_path="rotation_euler", frame=frame)
        obj.keyframe_delete(data_path="rotation_euler", frame=frame)
    obj.keyframe_insert(data_path="location", frame=frame)
    obj.keyframe_delete(data_path="location", frame=frame)
    obj.keyframe_insert(data_path="scale", frame=frame)
    obj.keyframe_delete(data_path="scale", frame=frame)
Example #3
0
def set_key(bl_obj: bpy.types.Object, frame: int, euler: Tuple[float, float,
                                                               float]):
    print('set_key', bl_obj, frame, euler)
    bl_obj.rotation_euler = euler
    bl_obj.keyframe_insert(data_path="rotation_euler", frame=frame)