예제 #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_textures(self):
        image = Image()
        image.filepath = "//test/image/path.png"
        image.library = "//test/image/library"

        node = ShaderNodeTexImage()
        node.image = image

        material = Material()
        material.name = "material"
        material.diffuse_color = [1.0, 1.0, 1.0, 1.0]
        material.use_nodes = True
        material.node_tree = NodeTree()
        material.node_tree.nodes = [node]

        mesh = Mesh()
        mesh.materials = [material]

        obj = Object()
        obj.data = mesh

        bpy.path.abspath = Mock(return_value=image.filepath)
        bpy.path.display_name_from_filepath = Mock(return_value="texture")

        reader = Mock()
        reader.read = Mock(return_value=[12, 34, [[0x05, 0x06], [0x07, 0x08]]])
        png.Reader = Mock(return_value=reader)

        exporter = Exporter()
        exporter.create_textures([obj])

        bpy.path.abspath.assert_called_once_with(
            "//test/image/path.png", library="//test/image/library")
        bpy.path.display_name_from_filepath.assert_called_once_with(
            "//test/image/path.png")
        png.Reader.assert_called_once_with("//test/image/path.png")
        reader.read.assert_called_once()

        self.assertEqual(exporter.names[0].node_name, "texture.tex")
        self.assertEqual(exporter.tex_images[0].tex_img_data, [5, 6, 7, 8])
        self.assertEqual(exporter.textures[0].tex_img_width, 12)
        self.assertEqual(exporter.textures[0].tex_img_height, 34)
예제 #3
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)
예제 #4
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)