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)
def apply_ob_props(ob: bpy.types.Object, new_name: str = name) -> bpy.types.Object: ob.name = new_name ob.location = [location[0] * 0.01, location[1] * -0.01, location[2] * 0.01] ob.rotation_mode = 'XYZ' ob.rotation_euler = [radians(rotation[2]), radians(-rotation[0]), radians(-rotation[1])] ob.scale = scale return ob