class TestMesh(unittest.TestCase): """ Run tests from main project folder. """ def setUp(self): self.reader = WavefrontReader(resources.obj_primitives) self.mesh = self.reader.get_mesh("Cube") def tearDown(self): pass def test_position_update_to_modelmatrix(self): for pos in [(4, 5, 6), (5, 4, 1)]: mesh = self.reader.get_mesh("Cube", position=pos) self.assertTrue(np.isclose(mesh.position.xyz, pos).all()) self.assertTrue( np.isclose(mesh.uniforms['model_matrix'][:3, 3], pos).all()) for pos in [(4, 5, 6), (5, 4, 1)]: mesh = self.mesh mesh.position.xyz = pos self.assertTrue(np.isclose(mesh.position.xyz, pos).all()) self.assertTrue( np.isclose(mesh.uniforms['model_matrix'][:3, 3], pos).all()) def test_position_update(self): mesh = self.mesh for pos in [(4, 5, 6), (5, 4, 1)]: mesh.position.x, mesh.position.y, mesh.position.z = pos self.assertTrue(np.isclose(mesh.position.xyz, pos).all()) def test_rotation_update(self): mesh = self.mesh for rot in [(4, 5, 6), (5, 4, 1)]: mesh.rotation.x, mesh.rotation.y, mesh.rotation.z = rot self.assertTrue(np.isclose(mesh.rotation.xyz, rot).all()) def test_scale_update(self): mesh = self.mesh for rot in [(4, 5, 6), (5, 4, 1)]: mesh.scale.x, mesh.scale.y, mesh.scale.z = rot self.assertTrue(np.isclose(mesh.scale.xyz, rot).all()) for rot in [4, 5]: mesh.scale.xyz = rot self.assertTrue(np.isclose(mesh.scale.xyz, (rot, rot, rot)).all())
class TestMesh(unittest.TestCase): """ Run tests from main project folder. """ def setUp(self): self.reader = WavefrontReader(resources.obj_primitives) self.mesh = self.reader.get_mesh("Cube") def tearDown(self): pass def test_position_update(self): mesh = self.mesh for pos in [(4,5, 6), (5, 4, 1)]: mesh.x, mesh.y, mesh.z = pos self.assertEqual(mesh.position, pos) def test_rotation_update(self): mesh = self.mesh for rot in [(4, 5, 6), (5, 4, 1)]: mesh.rot_x, mesh.rot_y, mesh.rot_z = rot self.assertEqual(mesh.rotation, rot)
def test_dynamic_mode_reflects_array_writability(): reader = WavefrontReader(resources.obj_primitives) cube = reader.get_mesh("Cube") old_vert = cube.vertices[0, 0] cube.vertices[:] += 1. assert np.isclose(cube.vertices[0, 0], old_vert + 1) cube.vertices[:] += 1. assert np.isclose(cube.vertices[0][0], old_vert + 2)
def test_dynamic_mode_reflects_array_writability(): reader = WavefrontReader(resources.obj_primitives) cube = reader.get_mesh("Cube", dynamic=True) old_vert = cube.vertices[0, 0] cube.vertices[:] += 1. assert cube.vertices[0, 0] == old_vert + 1 assert cube.dynamic cube.dynamic = False assert not cube.dynamic with pytest.raises(ValueError): cube.vertices[:] += 1. cube.dynamic = True cube.vertices[:] += 1. assert cube.vertices[0][0] == old_vert + 2
class TestMesh(unittest.TestCase): """ Run tests from main project folder. """ def setUp(self): self.reader = WavefrontReader(resources.obj_primitives) self.mesh = self.reader.get_mesh("Cube") def tearDown(self): pass def test_position_update(self): mesh = self.mesh for pos in [(4, 5, 6), (5, 4, 1)]: mesh.position.x, mesh.position.y, mesh.position.z = pos self.assertEqual(mesh.position.xyz, pos) def test_rotation_update(self): mesh = self.mesh for rot in [(4, 5, 6), (5, 4, 1)]: mesh.rotation.x, mesh.rotation.y, mesh.rotation.z = rot self.assertEqual(mesh.rotation.xyz, rot) def test_scale_update(self): mesh = self.mesh for rot in [(4, 5, 6), (5, 4, 1)]: mesh.scale.x, mesh.scale.y, mesh.scale.z = rot self.assertEqual(mesh.scale.xyz, rot) for rot in [4, 5]: mesh.scale.xyz = rot self.assertEqual(mesh.scale.xyz, (rot, rot, rot))
def cube(): reader = WavefrontReader(resources.obj_primitives) return reader.get_mesh("Cube")
def test_wavefront_objects_get_name(): reader = WavefrontReader(resources.obj_primitives) cube = reader.get_mesh('Cube', name='CoolCube') assert hasattr(cube, 'name') assert cube.name == 'CoolCube'