Beispiel #1
0
    def test_set_vertices_and_compute_normals03(self):
        mesh = Mesh(
            vertices=np.array([
                [0, 0, 0],
                [0, 0, 0],
                [0, 0, 0],
            ]),
            polygon_vertex_indices=[[0, 1, 2]],
            triangle_vertex_indices=np.array([[0, 1, 2]]),
        )
        new_vertices = np.array([
            [0, 0, 0],
            [1, 0, 0],
            [0, 1, 0],
        ])
        ans = np.array([
            [0, 0, 1],
            [0, 0, 1],
            [0, 0, 1],
        ], dtype=np.float32)
        self.assertFalse(mesh.has_normals())
        mesh2 = mesh.set_vertices_and_compute_normals(new_vertices)

        res = mesh2.normals
        self.assertEqual(ans.shape, res.shape)
        self.assertTrue(np.allclose(ans, res))
Beispiel #2
0
    def test_set_vertices_and_compute_normals02(self):
        new_vertices = np.array([
            [0.1, 0, 0],
            [0, 50, 0],
            [1, 0, 0],
            [0, 0, 1],
            [0, 0, 0],
        ],
                                dtype=np.float32)

        mesh = Mesh(
            vertices=np.zeros_like(new_vertices),
            polygon_vertex_indices=[
                [1, 0, 4],
                [4, 2, 3],
            ],
            triangle_vertex_indices=np.array([
                [1, 0, 4],
                [4, 2, 3],
            ],
                                             dtype=np.int32),
        )
        ans = np.array([
            [0, 0, -1],
            [0, 0, -1],
            [0, -1, 0],
            [0, -1, 0],
            [0, -0.70710678, -0.70710678],
        ],
                       dtype=np.float32)
        self.assertFalse(mesh.has_normals())
        mesh.set_vertices_and_compute_normals(new_vertices)

        res = mesh.normals
        self.assertEqual(ans.shape, res.shape)
        self.assertTrue(np.allclose(ans, res))
Beispiel #3
0
 def test_mesh_has_normals02(self):
     mesh1 = Mesh(vertices=np.arange(3),
                  polygon_vertex_indices=[[0, 1, 2]],
                  normals=np.array([1, 2, 3]))
     self.assertTrue(mesh1.has_normals())
Beispiel #4
0
 def test_mesh_has_normals01(self):
     mesh1 = Mesh(vertices=np.arange(3), polygon_vertex_indices=[[0, 1, 2]])
     self.assertFalse(mesh1.has_normals())