예제 #1
0
    def test_create_shapes(self):
        obj = Object()

        mesh = Mesh()
        mesh.name = "mesh"
        obj.data = mesh

        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])

        self.assertEqual(exporter.shapes[0].shape_tri_link,
                         exporter.tri_groups[0].this_tri_group_index)
        self.assertEqual(exporter.shapes[0].shape_mat_link,
                         exporter.get_default_material().this_mat_index)
        self.assertEqual(exporter.shapes[0].shape_part_num, 1)
        self.assertEqual(exporter.shape_by_mesh[mesh], exporter.shapes[0])
예제 #2
0
    def test_create_vertex_groups(self):
        not_a_mesh = Object()
        mesh = Object()

        mesh.data = Mesh()
        mesh.data.name = "mesh"

        vertex = MeshVertex()
        vertex.co = [0.0, 0.0, 0.0]

        mesh.data.vertices = [vertex] * 10

        exporter = Exporter()
        exporter.create_vertex_groups([not_a_mesh, mesh])

        self.assertEqual(len(exporter.names), 1)
        self.assertEqual(len(exporter.vtx_groups), 1)
        self.assertEqual(not_a_mesh.data in exporter.vtx_group_by_mesh, False)
        self.assertEqual(exporter.vtx_group_by_mesh[mesh.data],
                         exporter.vtx_groups[0])
예제 #3
0
    def test_create_tri_groups(self):
        not_a_mesh = Object()
        mesh = Object()

        mesh.data = Mesh()
        mesh.data.name = "mesh"

        vertex = MeshVertex()
        vertex.co = [0.0, 0.0, 0.0]

        mesh.data.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.data.uv_layers = [uv_loop_layer]

        loop = MeshLoop()
        loop.normal = [1.0, 2.0, 3.0]
        mesh.data.loops = [loop] * 3

        tri = MeshLoopTriangle()
        tri.vertices = [0, 1, 2]
        tri.loops = [0, 1, 2]
        mesh.data.loop_triangles = [tri]

        exporter = Exporter()
        exporter.create_vertex_groups([not_a_mesh, mesh])
        exporter.create_vector_groups([not_a_mesh, mesh])
        exporter.create_st_groups([not_a_mesh, mesh])
        exporter.create_tri_groups([not_a_mesh, mesh])

        self.assertEqual(len(exporter.tri_groups), 1)
        self.assertEqual(not_a_mesh.data in exporter.tri_group_by_mesh, False)
        self.assertEqual(exporter.tri_group_by_mesh[mesh.data],
                         exporter.tri_groups[0])
예제 #4
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)
예제 #5
0
    def test_create_parts(self):
        obj = Object()

        mesh = Mesh()
        mesh.name = "mesh"
        obj.data = mesh

        mat_red = Material()
        mat_red.name = "red"
        mat_red.diffuse_color = [1.0, 0.0, 0.0, 1.0]

        mat_green = Material()
        mat_green.name = "green"
        mat_green.diffuse_color = [0.0, 1.0, 0.0, 1.0]

        mat_blue = Material()
        mat_blue.name = "blue"
        mat_blue.diffuse_color = [0.0, 0.0, 1.0, 1.0]

        mesh.materials = [mat_red, mat_green, mat_blue]

        vertex = MeshVertex()
        vertex.co = [0.0, 0.0, 0.0]

        mesh.vertices = [vertex] * 9

        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

        tri_green = MeshLoopTriangle()
        tri_green.vertices = [3, 4, 5]
        tri_green.loops = [0, 1, 2]
        tri_green.material_index = 1

        tri_blue = MeshLoopTriangle()
        tri_blue.vertices = [6, 7, 8]
        tri_blue.loops = [0, 1, 2]
        tri_blue.material_index = 2

        mesh.loop_triangles = [tri_red, tri_green, tri_blue]

        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])

        self.assertEqual(exporter.parts[0].mat_index,
                         exporter.materials[1].this_mat_index)
        self.assertEqual(exporter.parts[1].mat_index,
                         exporter.materials[2].this_mat_index)
        self.assertEqual(exporter.parts[2].mat_index,
                         exporter.materials[3].this_mat_index)
        self.assertEqual(exporter.parts[0].tri_indices,
                         [exporter.tri_groups[0].tris[0].this_tri_index])
        self.assertEqual(exporter.parts[1].tri_indices,
                         [exporter.tri_groups[0].tris[1].this_tri_index])
        self.assertEqual(exporter.parts[2].tri_indices,
                         [exporter.tri_groups[0].tris[2].this_tri_index])
        self.assertEqual(exporter.parts_by_mesh[mesh], exporter.parts)