Ejemplo n.º 1
0
    def test_can_translate_colmesh(self):
        colmesh = modcolmesh.ColMesh()
        colmesh.load(self.path_colmesh)
        colmesh_old = copy.deepcopy(colmesh)
        path_write = os.path.join(*[
            'tests', 'generated', 'edit', 'evil_box_translate_mesh', 'meshes',
            'evil_box_translate_mesh.collisionmesh'
        ])

        colmesh = modcolmesh.ColMesh()
        colmesh.load(self.path_colmesh)

        offset = Vec3(1.0, 0.0, 0.0)
        colmesh.translate(offset)

        colmesh.save(path_write)

        self.assertEqual(len(colmesh.geoms), len(colmesh_old.geoms))
        for id_geom, geom in enumerate(colmesh.geoms):
            geom_old = colmesh_old.geoms[id_geom]
            self.assertEqual(len(geom.subgeoms), len(geom_old.subgeoms))
            for id_sub, subgeom in enumerate(geom.subgeoms):
                subgeom_old = geom_old.subgeoms[id_sub]
                self.assertEqual(len(subgeom.lods), len(subgeom_old.lods))
                for id_lod, lod in enumerate(subgeom.lods):
                    lod_old = subgeom_old.lods[id_lod]
                    self.assertEqual(len(lod.vertices), len(lod_old.vertices))
                    self.assertEqual(len(lod.faces), len(lod_old.faces))

                    for id_vert, vertex in enumerate(lod.vertices):
                        vertex_old = lod_old.vertices[id_vert]
                        print('[{}] {} : {}'.format(id_vert, vertex,
                                                    vertex_old))
                        self.assertEqual(vertex, (vertex_old + offset))
Ejemplo n.º 2
0
    def test_can_read_header(self):
        with open(self.path_colmesh, 'rb') as meshfile:
            colmesh = modcolmesh.ColMesh()
            colmesh._read_header(meshfile)

        self.assertTrue(colmesh.u1 == 0)
        self.assertTrue(colmesh.version == 10)
Ejemplo n.º 3
0
    def test_can_read_collisions_PR_REPO(self):
        counter = 0
        for dir, dirnames, filenames in os.walk(
                os.path.join(bf2.Mod().root, 'objects')):
            for filename in filenames:
                ext = filename.split('.')[-1].lower()
                if ext == 'collisionmesh' and 'test' not in dir:
                    counter += 1
                    filepath = os.path.join(bf2.Mod().root, dir, filename)
                    try:
                        colmesh = modcolmesh.ColMesh()
                        colmesh.load(filepath)

                        for geom in colmesh.geoms:
                            for sub in geom.subgeoms:
                                for lod in sub.lods:
                                    if lod.facenum > 10 and lod.facenum < 30:
                                        print(filepath)
                                        print(lod.facenum)
                                        for face in lod.faces:
                                            print(face)
                                        for zdata in lod.zdata:
                                            print(zdata)
                                        raise
                    except struct.error:
                        print('Failed to load {} struct'.format(filepath))
                        #raise
                    except Exception as e:
                        print('Failed to load {}'.format(filepath))
                        print(e)
                        raise
        print(counter)
        raise
Ejemplo n.º 4
0
    def test_can_create_colmesh_from_mock(self):
        path_write = os.path.join(*[
            'tests', 'generated', 'write', 'evil_box', 'meshes',
            'evil_box_mock.collisionmesh'
        ])

        colmesh = mocks.ColBox()
        colmesh.save(path_write)

        colmesh = modcolmesh.ColMesh()
        colmesh.load(path_write)
Ejemplo n.º 5
0
    def test_can_write_geoms(self):
        colmesh = modcolmesh.ColMesh()
        colmesh.load(self.path_colmesh)
        path_write = os.path.join(*[
            'tests', 'generated', 'write', 'evil_box', 'meshes',
            'evil_box_geoms.collisionmesh'
        ])

        dir = os.path.dirname(path_write)
        if not os.path.exists(dir): os.makedirs(dir)

        with open(path_write, 'wb') as fo:
            colmesh._write_geoms(fo)

        with open(path_write, 'rb') as fo:
            colmesh2 = modcolmesh.ColMesh()
            colmesh2._read_geoms(fo)

            self.assertEqual(colmesh2.geomnum, colmesh.geomnum)
            self.assertEqual(colmesh2.geoms, colmesh.geoms)
Ejemplo n.º 6
0
    def test_can_merge_geoms(self):
        colmesh = modcolmesh.ColMesh(self.path_colmesh)
        colmesh2 = copy.deepcopy(colmesh)
        path_write = os.path.join(*[
            self.path_write_folder, 'evil_box_merge_mesh', 'meshes',
            'evil_box_merge_mesh.collisionmesh'
        ])

        # translate 2nd mesh first
        colmesh2.translate(Vec3(1.0, 0.0, 0.0))

        colmesh.merge(colmesh2)
        colmesh.save(path_write)
Ejemplo n.º 7
0
    def test_can_read_geoms(self):
        with open(self.path_colmesh, 'rb') as meshfile:
            colmesh = modcolmesh.ColMesh()
            colmesh._read_geoms(meshfile)
            self.assertTrue(meshfile.tell() == 1511)

        self.assertTrue(len(colmesh.geoms) == colmesh.geomnum == 1)

        geom0 = colmesh.geoms[0]
        self.assertTrue(geom0.subgeomnum == 1)

        subgeom0 = geom0.subgeoms[0]
        self.assertTrue(subgeom0.lodnum == 3)

        lod0 = subgeom0.lods[0]
        lod1 = subgeom0.lods[1]
        lod2 = subgeom0.lods[2]
        self.assertTrue(lod0.coltype == 0)
        self.assertTrue(lod0.facenum == 12)
        self.assertTrue(lod0.u7 == 49)
        self.assertTrue(lod0.ynum == 3)
        self.assertTrue(lod0.znum == 12)
        self.assertTrue(lod0.anum == 36)
Ejemplo n.º 8
0
def main():
    colpath = os.path.join(bf2.Mod().root, 'objects', 'staticobjects', 'pr',
                           'citybuildings', 'pavement', 'divider', '24m_1',
                           'Meshes', '24m_1.collisionmesh')
    colmesh = modcolmesh.ColMesh(colpath)
    colmesh2 = copy.deepcopy(colmesh)

    # from fallujah
    position1 = Vec3(491.567, 24.653, 495.454)
    rotation1 = (0.2, 0.0, 0.0)

    position2 = Vec3(491.416, 24.653, 443.974)
    rotation2 = (0.2, 0.0, 0.0)

    diff = position2 - position1

    print(diff)
    raise

    colmesh2.translate(diff)
    colmesh.merge(colmesh2)

    col0 = colmesh.geoms[0].subgeoms[0].lods[0]
    min, max = Vec3(*col0.min), Vec3(*col0.max)
    center_offset = (min + max) / 2
    #print(min)
    #print(max)
    #print(center_offset)
    #print(position1 + center_offset)
    colmesh.translate(-center_offset)

    path_save = os.path.join(bf2.Mod().root, 'objects', 'staticobjects', 'pr',
                             'citybuildings', 'pavement', 'divider',
                             '24m_1_merge', 'meshes',
                             '24m_1_merge.collisionmesh')
    colmesh.save(path_save)
Ejemplo n.º 9
0
    def test_for_data(self):
        def __copy_from_export(copy_from, copy_to, objects):
            mod_path = bf2.Mod().root
            export_path = os.path.join(*copy_from)
            samples_path = os.path.join(*copy_to)

            for object_name in objects:
                exported_object_path = os.path.join(
                    mod_path, export_path, object_name, 'meshes',
                    object_name + '.collisionmesh')
                samples_object_path = os.path.join(
                    mod_path, samples_path, object_name, 'meshes',
                    object_name + '.collisionmesh')

                # raise the
                shutil.copy(exported_object_path, samples_object_path)

        objects = [
            'evil_box',
            'evil_tri',
            'evil_plane',
            'evil_plane_90',
        ]
        __copy_from_export(['objects', 'staticobjects', 'test'], [
            'readme', 'assets', 'apps', 'python3', 'mesher', 'tests', 'samples'
        ], objects)
        object_name = objects[2]
        path_samples = os.path.join('tests', 'samples')
        path_colmesh = os.path.join(path_samples, object_name, 'meshes',
                                    object_name + '.collisionmesh')

        colmesh = modcolmesh.ColMesh()
        colmesh.load(path_colmesh)
        print(path_colmesh)

        geom0 = colmesh.geoms[0]
        subgeom0 = geom0.subgeoms[0]
        lod0 = subgeom0.lods[0]

        for i in range(lod0.vertnum):
            print('vertex[{}]: {}'.format(i, lod0.vertices[i]))
            pass
        print('vertices({})\n'.format(lod0.vertnum))

        for i in range(lod0.facenum):
            print('face[{}]: {}'.format(i, lod0.faces[i]))
            pass
        print('facenum({})\n'.format(lod0.facenum))

        for i in range(lod0.ynum):
            print('ydata[{}]: {}'.format(i, lod0.ydata[i]))
            pass
        print('ynum({})\n'.format(lod0.ynum))

        for i in range(lod0.znum):
            value = lod0.zdata[i]
            face = lod0.faces[value]
            print('zdata[{}]: {}'.format(i, value))
            pass
        print('znum({})\n'.format(lod0.znum))

        for i in range(lod0.anum):
            vertex = lod0.vertices

            value = lod0.adata[i]
            face = lod0.faces[value]
            print('adata[{}]: {}'.format(i, value))
            pass
        print('anum({})\n'.format(lod0.anum))
        raise
Ejemplo n.º 10
0
 def test_can_read_colmesh(self):
     colmesh = modcolmesh.ColMesh()
     colmesh.load(self.path_colmesh)