Exemplo n.º 1
0
    def test_from_obj_string05(self):
        content = """
        v 1 0 0
        v 16 3 2
        v 0 1 0
        v 0 0 1

        vt 0.5 0
        vt 0.5 0.5
        vt 0 0.5

        f 1/1 2/2 3/3 4/1
        f 2/1 3/2 4/3

        """
        res = geom_tools.from_obj_string(content, compute_normals=False)
        ans = geom_tools.Mesh(
            vertices=np.array([
                [1, 0, 0],
                [16, 3, 2],
                [0, 1, 0],
                [0, 0, 1],
            ]),
            polygon_vertex_indices=[
                [0, 1, 2, 3],
                [1, 2, 3]
            ],
            texture_vertices=np.array([
                [0.5, 0],
                [0.5, 0.5],
                [0, 0.5]
            ]),
            texture_polygon_vertex_indices=[
                [0, 1, 2, 0],
                [0, 1, 2],
            ],
            triangle_vertex_indices=np.array([
                [0, 1, 2],
                [0, 2, 3],
                [1, 2, 3],
            ]),
            triangle_texture_vertex_indices=np.array([
                [0, 1, 2],
                [0, 2, 0],
                [0, 1, 2],
            ]),
        )
        self.assertTrue(res == ans)
Exemplo n.º 2
0
 def test_from_obj_string01(self):
     content = """
     v 1 0 0
     v 0 1 0
     v 0 0 1
     
     f 1 2 3
     
     """
     res = geom_tools.from_obj_string(content, compute_normals=False)
     ans = geom_tools.Mesh(
         vertices=np.array([
             [1, 0, 0],
             [0, 1, 0],
             [0, 0, 1]
         ]),
         polygon_vertex_indices=[[0, 1, 2]],
         triangle_vertex_indices=np.array([[0, 1, 2]])
     )
     self.assertTrue(res == ans)
Exemplo n.º 3
0
    def test_mesh_obj_export04(self):
        mesh = geom_tools.Mesh(
            vertices=np.array([
                [1, 0, 0],
                [0, 1, 0],
                [0, 0, 1],
            ],
                              dtype=np.float32),
            polygon_vertex_indices=[[0, 1, 2], [2, 1, 0, 2], [1, 2, 0]],
            texture_vertices=np.array([
                [0, 1],
                [1, 0],
                [1, 0.5],
                [0.5, 0.5],
            ],
                                      dtype=np.float32),
            texture_polygon_vertex_indices=[
                [2, 0, 1],
                [3, 1, 0, 2],
                [0, 2, 3],
            ],
        )

        stream = io.StringIO()
        geom_tools.save_to_stream(mesh, stream)
        res = stream.getvalue()
        ans = """\
v 1.0 0.0 0.0
v 0.0 1.0 0.0
v 0.0 0.0 1.0

vt 0.0 1.0
vt 1.0 0.0
vt 1.0 0.5
vt 0.5 0.5

f 1/3 2/1 3/2
f 3/4 2/2 1/1 3/3
f 2/1 3/3 1/4
"""
        self.assertEqual(res, ans)
Exemplo n.º 4
0
    def test_mesh_obj_export01(self):
        mesh = geom_tools.Mesh(
            vertices=np.array([
                [1, 0, 0],
                [0, 1, 0],
                [0, 0, 1],
            ],
                              dtype=np.float32),
            polygon_vertex_indices=[[0, 1, 2]],
        )

        stream = io.StringIO()
        geom_tools.save_to_stream(mesh, stream)
        res = stream.getvalue()
        ans = """\
v 1.0 0.0 0.0
v 0.0 1.0 0.0
v 0.0 0.0 1.0

f 1 2 3
"""
        self.assertEqual(res, ans)
Exemplo n.º 5
0
    def test_from_obj_string11(self):
        content = """
        v 0 0 0
        v 1 0 0
        v 0 1 0                

        g Face
        f 1 2 3
        f 1 2 3  

        """
        res = geom_tools.from_obj_string(content, compute_normals=False, triangulate=False)
        ans = geom_tools.Mesh(
            vertices=np.array([
                [0, 0, 0],
                [1, 0, 0],
                [0, 1, 0],
            ]),
            polygon_vertex_indices=[[0, 1, 2], [0, 1, 2]],
            polygon_groups=[0, 0],
            group_names=["Face"]
        )
        self.assertTrue(res == ans)
Exemplo n.º 6
0
    def test_from_obj_string09(self):
        content = """
        v 0 0 0
        v 1 0 0
        v 0 1 0        

        vn 1 0 0

        f 1//1 2//1 3//1 

        """
        res = geom_tools.from_obj_string(content, compute_normals=True)
        ans = geom_tools.Mesh(
            vertices=np.array([
                [0, 0, 0],
                [1, 0, 0],
                [0, 1, 0],
            ]),
            polygon_vertex_indices=[[0, 1, 2]],
            triangle_vertex_indices=np.array([[0, 1, 2]]),
            normals=np.array([[0, 0, 1], [0, 0, 1], [0, 0, 1]], dtype=np.float32),
        )
        self.assertTrue(res == ans)
Exemplo n.º 7
0
    def test_from_obj_string03(self):
        content = """
        v 1 0 0
        v 0 1 0
        v 0 0 1
        v 16 3 2
        
        vn 1 0 0

        f 1//1 2//1 3//1 4//1

        """
        res = geom_tools.from_obj_string(content, compute_normals=False)
        ans = geom_tools.Mesh(
            vertices=np.array([
                [1, 0, 0],
                [0, 1, 0],
                [0, 0, 1],
                [16, 3, 2],
            ]),
            polygon_vertex_indices=[[0, 1, 2, 3]],
            triangle_vertex_indices=np.array([[0, 1, 2], [0, 2, 3]])
        )
        self.assertTrue(res == ans)
Exemplo n.º 8
0
    def test_from_obj_string10(self):
        content = """
        v 0 0 0
        v 1 0 0
        v 0 1 0                

        g Face
        f 1 2 3 

        """
        res = geom_tools.from_obj_string(content, compute_normals=True)
        ans = geom_tools.Mesh(
            vertices=np.array([
                [0, 0, 0],
                [1, 0, 0],
                [0, 1, 0],
            ]),
            polygon_vertex_indices=[[0, 1, 2]],
            triangle_vertex_indices=np.array([[0, 1, 2]]),
            normals=np.array([[0, 0, 1], [0, 0, 1], [0, 0, 1]], dtype=np.float32),
            polygon_groups=[0],
            group_names=["Face"]
        )
        self.assertTrue(res == ans)