Example #1
0
def gen_thumb(check_exists=True, scenes=None, db=None):
    model_files = walk_files('.pbb')
    model_file_count = len(model_files)
    for i, (p, fn) in enumerate(model_files, start=1):
        pfn = '%s/%s' % (p,fn)

        dbships = None
        if scenes and db:
            scene0 = pfn[11:-4].lower()
            scene = scene0[:-6] if scene0.endswith('_scene') else scene0

            ids = scenes.get(scene, '')
            if ids:
                dbships = tuple(db.ships.find({'_id': {'$in': ids}, 'size':{'$exists': False}}))

        if not dbships:
            continue

        f, e =fn.rsplit('.', 1)
        t = 'ships' if 'ships' in p else 'stations'
        fno = ('thumb/%s/%s.gif' % (t, f)).lower()

        if check_exists and os.path.exists(fno):
            print 'Exists %d/%d %s' % (i,model_file_count, fno)
            continue

        print 'Processing %d/%d %s' % (i,model_file_count, fn)
        try:
            with open(pfn) as f:
                lods = get_lods(f.read(), max_lod=1)
            xt = lods[0].thumb(fno)
            if xt and dbships:
                for ship in dbships:
                    ship['size'] = size = dict(w=xt[0], h=xt[1], l=xt[2])
                    db.ships.save(ship)
                    print '\tsetting size: {} to {}\n'.format(ship['_id'], size)
            else:
                print 'NO XT'

        except Exception, e:
            print 'Error processing %s\n%s' % (pfn, e)
            raise
Example #2
0
def gen_obj():
    model_files = walk_files('.pbb')
    model_file_count = len(model_files)
    for i, (p, fn) in enumerate(model_files, start=1):
        pfn = '%s/%s' % (p,fn)
        f,e =fn.rsplit('.', 1)
        fno = ('obj/%s.obj' % (f)).lower()

        if os.path.exists(fno):
            print 'Exists %d/%d %s' % (i,model_file_count, fno)
            continue

        print 'Processing %d/%d %s' % (i,model_file_count, fn)
        try:
            #export(pfn, fno)

            with open(pfn) as f:
                lods = get_lods(f.read())
            lods[0].save_obj(fno)

        except Exception, e:
            print 'Error processing %s\n%s' % (pfn, e)
            raise
Example #3
0
def get_info(scenes):

    scene_ships = {s.lower():s for s in scenes.keys()}
#    print '\n'.join(sorted(scene_ships))
#    return
#    model_files = [f for f in walk_files('.pbb') if 'ships' in f[1].lower()]
    model_files = walk_files('.pbb')
    model_file_count = len(model_files)
    ships = []
    for i, (p, fn) in enumerate(model_files, start=1):
        pfn = '%s/%s' % (p,fn)
        f, e =fn.rsplit('.', 1)
#        print pfn
        #print 'Processing %d/%d %s' % (i,model_file_count, fn)
        try:
            with open(pfn) as f:
                lods = get_lods(f.read(), max_lod=1, load_mesh=False)

            scene = pfn[11:-4].lower()
            scene = scene[:-6] if scene.endswith('_scene') else scene
            id = scenes.get(scene, '')
            # TODO: use the _scene.pbd file to determine the pbb file names
            if not id and not scene.startswith('stations'):
                found = False
                for ship_key in scene_ships:
                    if ship_key in pfn.lower():
                        ship = scene_ships[ship_key]
                        id = scenes.get(ship, '??')
                        print 'PARTIAL | {:60} | {:20} | {}'.format(pfn, ship, id)
                        found = True
                if not found:
                    print "NOT FOUND", scene
            ships.append((65536.0*lods[0].scale/500.0*2, scene, pfn))
        except Exception, e:
            print 'X', str(e), pfn
            pass