def test_can_translate_mesh(self): vmesh = mocks.Box() vmesh_clone = mocks.Box() path_object_clone = os.path.join(*[ 'tests', 'generated', 'edit', 'evil_box_translate_mesh', 'meshes', 'evil_box_translate_mesh.staticmesh' ]) # using bf2 axis # x, y, z = red, green, blue lines in bfmeshview offset = (1.0, 0.0, 0.0) vmesh.translate(offset) vertices = [vertex for vertex in vmesh.get_vertices()] vertices_old = [vertex for vertex in vmesh_clone.get_vertices()] for id_vertex, vertex in enumerate(vertices): position = getattr(vertex, D3DDECLUSAGE.POSITION.name) position_old = getattr(vertices_old[id_vertex], D3DDECLUSAGE.POSITION.name) self.assertTrue(position == sum(i) for i in zip(position_old, offset)) # save for manual check vmesh.save(path_object_clone)
def test_can_rotate_mesh(self): vmesh = mocks.Box() vmesh_clone = mocks.Box() path_object_clone = os.path.join(*[ 'tests', 'generated', 'edit', 'evil_box_rotate_mesh', 'meshes', 'evil_box_rotate_mesh.staticmesh' ]) rotation = (45.0, 0.0, 0.0) vmesh.rotate(rotation) vmesh.save(path_object_clone)
def test_can_deserialize_materials_vertices(self): vmesh = mock_mesh.Box() vmesh_clone = mock_mesh.Box() vertices = [vertex for vertex in vmesh.get_vertices()] new_vertices = [] for id_geom, geom in enumerate(vmesh.geoms): for id_lod, lod in enumerate(geom.lods): for id_mat, material in enumerate(lod.materials): for vertex in vertices[material.vstart:material.vstart + material.vnum]: new_vertices.append(vertex) vmesh.update_vertices(vertices) self.assertEqual(vmesh.vertices, vmesh_clone.vertices)
def test_can_merge_simple_mesh(self): vmesh = mocks.Box() vmesh2 = mocks.Box() vmesh.isStaticMesh = True vmesh2.isStaticMesh = True path_object_clone = os.path.join(*[ 'tests', 'generated', 'edit', 'evil_box_merge_mesh', 'meshes', 'evil_box_merge_mesh.staticmesh' ]) offset = (1.0, 0.0, 0.0) vmesh2.translate(offset) vmesh.merge(vmesh2) vmesh.save(path_object_clone)
def test_can_serialize_vertices(self): vmesh = mock_mesh.Box() vertsize = int(vmesh.vertstride / vmesh.vertformat) #vmesh.save('./mockbox.staticmesh') v_id = 0 for vertex in vmesh.get_vertices(): for attrib in vmesh.vertattrib: flag = attrib.flag offset = int(attrib.offset / vmesh.vertformat) vartype = D3DDECLTYPE(attrib.vartype) usage = D3DDECLUSAGE(attrib.usage) self.assertTrue(hasattr(vertex, usage.name)) value = getattr(vertex, usage.name) self.assertTrue(len(value) == len(vartype)) vstart = v_id * vertsize datastart = vstart + offset datalenght = len(vartype) vdata = vmesh.vertices[datastart:datastart + datalenght] self.assertEqual(value, vdata) v_id += 1 self.assertEqual(v_id, vmesh.vertnum)
import os import modmesh import tests.mock_mesh as mocks pbox = mocks.Box() vbox = pbox.vmesh vbox.save('generated/generated_box/meshes/generated_box.staticmesh')