コード例 #1
0
ファイル: common.py プロジェクト: yazici/assemblme
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
コード例 #2
0
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
コード例 #3
0
ファイル: transform.py プロジェクト: bblanimation/assemblme
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
コード例 #4
0
    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])
コード例 #5
0
ファイル: asset.py プロジェクト: truenote/jewelcraft
def apply_scale(ob: Object) -> None:
    mat = Matrix.Diagonal(ob.scale).to_4x4()
    ob.data.transform(mat)
    ob.scale = (1.0, 1.0, 1.0)
コード例 #6
0
    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)