def set_transformation(obj: bpy.types.Object, transf: Dict[str, str]) -> None: """set the transformation of an object""" trans = transf['translation'] rot = transf['rotation'] obj.location = trans # blender.point_at(cam, root_obj, 'TRACK_NEGATIVE_Z', 'UP_Y') if isinstance(rot, dict): point_at_obj = blender.get_obj_by_name(rot['point_at']) blender.point_at(obj, point_at_obj, blender.TRACK_AXIS[rot.get('track_axis', '-z')], blender.UP_AXIS[rot.get('up_axis', 'y')]) else: if len(rot) == 3: # I think Panda3D's HPR is intrinsic # If Blender is extrinsic, the order can just be reversed, LOL # rot is in HPR form # H -> Z # P -> X # R -> Y obj.rotation_mode = 'ZXY' obj.rotation_euler = ( math.radians(rot[1]), # X == (ZXY)[1] math.radians(rot[2]), # Y == (ZXY)[2] math.radians(rot[0]), # Z == (ZXY)[0] ) else: obj.rotation_mode = 'QUATERNION' obj.rotation_quaternion = rot
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
def _add_object(self, obj: bpy.types.Object): """Add a scene object""" if obj.data.artnet_universe is None: return if not obj.data.artnet_universe in self._fixture_universes: self._fixture_universes[obj.data.artnet_universe] = {} universe = self._fixture_universes[obj.data.artnet_universe] fixture = {} fixture["object"] = obj fixture["fixture_type"] = obj.data.artnet_fixture_type # base address is 1-based so subtract 1 from it fixture["base_address"] = obj.data.artnet_base_address - 1 universe[obj.name] = fixture obj.rotation_mode = "XYZ"
def change_rotation_mode(obj: bpy.types.Object, rotation_mode: str, normalized: bool = True): if rotation_mode == "rotation_axis_angle": rotation_mode = "AXIS_ANGLE" elif rotation_mode == "rotation_quaternion": rotation_mode = "QUATERNION" elif rotation_mode == "rotation_euler": rotation_mode = "XYZ" obj.rotation_mode = rotation_mode if normalized and obj.rotation_mode == "AXIS_ANGLE": axis_angle = normalize_axis_angle(vec2np(obj.rotation_axis_angle))[0] obj.rotation_axis_angle = (axis_angle[0], axis_angle[1], axis_angle[2], axis_angle[3]) elif normalized and obj.rotation_mode == "QUATERNION": quat = normalize_quaternion(vec2np(obj.rotation_quaternion))[0] obj.rotation_quaternion = (quat[0], quat[1], quat[2], quat[3])
def set_object_rotation(context, position_properties: WorkpiecePosition, scene_object: bpy.types.Object): rotations = WorkpieceOperator.visible_surface_rotation( position_properties.visible_surface) rotations.extend(WorkpieceOperator.view_rotation( context, position_properties.view)) rotations.extend(WorkpieceOperator.orientation_rotation( context, position_properties.orientation, position_properties.view)) scene_object.rotation_mode = 'QUATERNION' object_rotations = scene_object.rotation_quaternion.copy() for rotation in rotations: object_rotations = WorkpieceOperator.quaternion_rotation( rotation, object_rotations) scene_object.rotation_quaternion = object_rotations
def setObjQuaternionRotation(obj: bpy.types.Object, rotation: Vector3f): obj.rotation_mode = 'QUATERNION' obj.rotation_quaternion = makeQuaternionRotation(rotation)
def setObjEulerRotation(obj: bpy.types.Object, rotation: Vector3f): obj.rotation_mode = kImEulerOrder obj.rotation_euler = makeEulerRotation(rotation)
def create_ls3d_object(bl_obj: bpy.types.Object, ls3d_parent: Optional[LS3DObject]) -> None: props = bl_obj.ls3d_props print(f"Exporting {bl_obj.name}") def get_obj_and_visual_type() -> Tuple[ObjectType, Optional[VisualType]]: if bl_obj.type == 'MESH': mesh_type = props.mesh_type if mesh_type == 'STANDARD': return ObjectType.VISUAL, VisualType.STANDARD_MESH elif mesh_type == 'SECTOR': return ObjectType.SECTOR, None elif mesh_type == 'OCCLUDER': return ObjectType.OCCLUDER, None elif mesh_type == 'BILLBOARD': return ObjectType.VISUAL, VisualType.BILLBOARD elif mesh_type == 'SINGLE': return ObjectType.VISUAL, VisualType.SINGLE_MESH elif mesh_type == 'SINGLE_MORPH': return ObjectType.VISUAL, VisualType.SINGLE_MORPH elif mesh_type == 'MORPH': return ObjectType.VISUAL, VisualType.MORPH elif mesh_type == 'MIRROR': return ObjectType.VISUAL, VisualType.MIRROR elif bl_obj.type == 'LIGHT': return ObjectType.VISUAL, VisualType.LENS elif bl_obj.type == 'EMPTY' and props.helper_type == 'TARGET': return ObjectType.TARGET, None else: return ObjectType.DUMMY, None obj_type, visual_type = get_obj_and_visual_type() parent_index = 0 if ls3d_parent: parent_index = Libraries.Objects.index(ls3d_parent) + 1 visual_flags = 0 # Extracting visual flags if props.visual_flag_a: visual_flags |= VisualFlags.DEPTH_BIAS if props.visual_flag_b: visual_flags |= VisualFlags.DYNAMIC_SHADOWS if props.visual_flag_c: visual_flags |= VisualFlags.UNKNOWN0 if props.visual_flag_d: visual_flags |= VisualFlags.UNKNOWN1 if props.visual_flag_e: visual_flags |= VisualFlags.UNKNOWN2 if props.visual_flag_f: visual_flags |= VisualFlags.DECALS if props.visual_flag_g: visual_flags |= VisualFlags.NO_FOG culling_flags = 0 # Extracting culling flags if props.culling_flag_a: culling_flags |= CullingFlags.ENABLED if props.culling_flag_b: culling_flags |= CullingFlags.UNKNOWN1 if props.culling_flag_c: culling_flags |= CullingFlags.UNKNOWN2 if props.culling_flag_d: culling_flags |= CullingFlags.UNKNOWN3 if props.culling_flag_e: culling_flags |= CullingFlags.UNKNOWN4 properties = "" for prop in props.user_defined_properties: if properties != "": properties += '\r\n' properties += prop.content rotation_mode = bl_obj.rotation_mode bl_obj.rotation_mode = 'QUATERNION' ls3d_obj = LS3DObject(obj_type, visual_type, visual_flags, parent_index, bl_obj.matrix_local.to_translation(), bl_obj.matrix_local.to_quaternion(), bl_obj.matrix_local.to_scale(), 0, culling_flags, bl_obj.name.replace(".", "_"), properties) bl_obj.rotation_mode = rotation_mode ls3d_obj.bl_obj = bl_obj # Create ls3d meshes depending on the object type and visual type if obj_type == ObjectType.VISUAL: if (visual_type == VisualType.STANDARD_MESH or visual_type == VisualType.BILLBOARD or visual_type == VisualType.SINGLE_MESH or visual_type == VisualType.MORPH or visual_type == VisualType.SINGLE_MORPH): create_ls3d_standard_mesh(ls3d_obj, visual_type) elif visual_type == VisualType.LENS: create_ls3d_lens(ls3d_obj) elif visual_type == VisualType.MIRROR: create_ls3d_mirror(ls3d_obj) elif obj_type == ObjectType.DUMMY: ls3d_obj.mesh = Dummy() ls3d_obj.children = bl_obj.children elif obj_type == ObjectType.SECTOR: create_ls3d_sector(ls3d_obj) elif obj_type == ObjectType.OCCLUDER: ls3d_obj.mesh = Occluder() ls3d_obj.children = bl_obj.children elif obj_type == ObjectType.TARGET: ls3d_obj.mesh = Target() ls3d_obj.children = bl_obj.children return ls3d_obj