def apply_transform(obj:Object, location:bool=True, rotation:bool=True, scale:bool=True): loc, rot, scale = obj.matrix_world.decompose() obj.matrix_world = Matrix.Identity(4) m = obj.data s_mat_x = Matrix.Scale(scale.x, 4, Vector((1, 0, 0))) s_mat_y = Matrix.Scale(scale.y, 4, Vector((0, 1, 0))) s_mat_z = Matrix.Scale(scale.z, 4, Vector((0, 0, 1))) if scale: m.transform(s_mat_x * s_mat_y * s_mat_z) else: obj.scale = scale if rotation: m.transform(rot.to_matrix().to_4x4()) else: obj.rotation_euler = rot.to_euler() if location: m.transform(Matrix.Translation(loc)) else: obj.location = loc
def apply_transform(obj:Object, location:bool=True, rotation:bool=True, scale:bool=True): """ apply object transformation to mesh """ loc, rot, scale = obj.matrix_world.decompose() obj.matrix_world = Matrix.Identity(4) m = obj.data s_mat_x = Matrix.Scale(scale.x, 4, Vector((1, 0, 0))) s_mat_y = Matrix.Scale(scale.y, 4, Vector((0, 1, 0))) s_mat_z = Matrix.Scale(scale.z, 4, Vector((0, 0, 1))) if scale: m.transform(mathutils_mult(s_mat_x, s_mat_y, s_mat_z)) else: obj.scale = scale if rotation: m.transform(rot.to_matrix().to_4x4()) else: obj.rotation_euler = rot.to_euler() if location: m.transform(Matrix.Translation(loc)) else: obj.location = loc
def apply_transform(obj:Object, location:bool=True, rotation:bool=True, scale:bool=True): """ apply object transformation to mesh """ loc, rot, scl = obj.matrix_world.decompose() obj.matrix_world = Matrix.Identity(4) m = obj.data s_mat_x = Matrix.Scale(scl.x, 4, Vector((1, 0, 0))) s_mat_y = Matrix.Scale(scl.y, 4, Vector((0, 1, 0))) s_mat_z = Matrix.Scale(scl.z, 4, Vector((0, 0, 1))) if scale: m.transform(mathutils_mult(s_mat_x, s_mat_y, s_mat_z)) else: obj.scale = scl if rotation: m.transform(rot.to_matrix().to_4x4()) else: obj.rotation_euler = rot.to_euler() if location: m.transform(Matrix.Translation(loc)) else: obj.location = loc
def ob_copy_and_parent(ob: Object, parents: Iterable[Object]) -> None: is_orig = True space_data = bpy.context.space_data use_local_view = bool(space_data.local_view) for parent in parents: if is_orig: ob_copy = ob is_orig = False else: ob_copy = ob.copy() for coll in parent.users_collection: coll.objects.link(ob_copy) if use_local_view: ob_copy.local_view_set(space_data, True) ob_copy.select_set(True) ob.location = parent.location ob.rotation_euler = parent.rotation_euler ob.parent = parent ob.matrix_parent_inverse = parent.matrix_basis.inverted()
def test_create_anim_groups(self): obj = Object() obj.name = "obj" obj.data = Mesh() obj.location = [1.0, 2.0, 3.0] obj.rotation_euler = [4.0, 5.0, 6.0] obj.scale = [7.0, 8.0, 9.0] exporter = Exporter() exporter.create_anim_groups([obj]) self.assertEqual(exporter.anim_groups[0].anim_node.translate_x, 1.0) self.assertEqual(exporter.anim_groups[0].anim_node.translate_y, 2.0) self.assertEqual(exporter.anim_groups[0].anim_node.translate_z, 3.0) self.assertEqual(exporter.anim_groups[0].anim_node.rotate_axis_x, 4.0) self.assertEqual(exporter.anim_groups[0].anim_node.rotate_axis_y, 5.0) self.assertEqual(exporter.anim_groups[0].anim_node.rotate_axis_z, 6.0) self.assertEqual(exporter.anim_groups[0].anim_node.scale_x, 7.0) self.assertEqual(exporter.anim_groups[0].anim_node.scale_y, 8.0) self.assertEqual(exporter.anim_groups[0].anim_node.scale_z, 9.0) self.assertEqual(exporter.anim_group_by_mesh[obj.data], exporter.anim_groups[0])
def MoveCameraToOrientation(orientation: types.Object, productionCamera: types.Object): productionCamera.rotation_euler = __CorrectCameraOrientation( orientation.rotation_euler) productionCamera.location = __GetWorldLocation(orientation)
def test_create_objects(self): obj = Object() obj.name = "obj" mesh = Mesh() mesh.name = "mesh" obj.data = mesh obj.location = [1.0, 2.0, 3.0] obj.rotation_euler = [4.0, 5.0, 6.0] obj.scale = [7.0, 8.0, 9.0] mat_red = Material() mat_red.name = "red" mat_red.diffuse_color = [1.0, 0.0, 0.0, 1.0] mesh.materials = [mat_red] vertex = MeshVertex() vertex.co = [0.0, 0.0, 0.0] mesh.vertices = [vertex] * 3 uv_loop = MeshUVLoop() uv_loop.uv = [0.5, 0.5] uv_loop_layer = MeshUVLoopLayer() uv_loop_layer.data = [uv_loop] * 3 mesh.uv_layers = [uv_loop_layer] loop = MeshLoop() loop.normal = [1.0, 2.0, 3.0] mesh.loops = [loop] * 3 tri_red = MeshLoopTriangle() tri_red.vertices = [0, 1, 2] tri_red.loops = [0, 1, 2] tri_red.material_index = 0 mesh.loop_triangles = [tri_red] exporter = Exporter() exporter.create_materials([obj]) exporter.create_vertex_groups([obj]) exporter.create_vector_groups([obj]) exporter.create_st_groups([obj]) exporter.create_tri_groups([obj]) exporter.create_parts([obj]) exporter.create_shapes([obj]) exporter.create_anim_groups([obj]) exporter.create_objects([obj]) self.assertEqual(exporter.objs[0].obj_shape_link, exporter.shapes[0].this_shape_index) self.assertEqual(exporter.objs[0].obj_mat_link, exporter.materials[0].this_mat_index) self.assertEqual(exporter.objs[0].obj_anim_link, exporter.anim_groups[0].this_anim_group_index) self.assertEqual(exporter.objs[0].obj_shape_link, exporter.shape_by_mesh[mesh].this_shape_index) self.assertEqual(exporter.objs[0].obj_mat_link, exporter.get_default_material().this_mat_index) self.assertEqual( exporter.objs[0].obj_anim_link, exporter.anim_group_by_mesh[mesh].this_anim_group_index)