예제 #1
0
def process_file(base_dir, f):
    current_process().daemon = False

    base_name = decode(f['base_name'])
    full_path = decode(f['full_path'])
    zip_hash = decode(f['metadata']['types']['original']['zip'])

    f_dir = full_path.replace('/', '_')
    f_dir = os.path.join(base_dir, f_dir)
    if not os.path.isdir(f_dir):
        os.mkdir(f_dir)

    orig_zip = os.path.join(f_dir, base_name + '.orig.zip')
    if not os.path.isfile(orig_zip):
        f_data = urllib2.urlopen(DOWNLOAD + '/' + zip_hash).read()
        orig_zip_file = open(orig_zip, 'wb')
        orig_zip_file.write(f_data)
        orig_zip_file.close()

    optimizations = factory.getInstance('full_optimizations')
    save = factory.getInstance('save_collada_zip')

    orig_ss = orig_zip + '.png'
    opt_zip = os.path.join(f_dir, base_name + '.opt.zip')
    opt_ss = opt_zip + '.png'

    mesh = collada.Collada(orig_zip, zip_filename=base_name)
    orig_render_info = getRenderInfo(mesh)

    if not os.path.isfile(orig_ss):
        p = Process(target=save_screenshot,
                    args=(orig_zip, orig_ss),
                    kwargs={'zip_filename': base_name})
        p.start()
        p.join()

    if not os.path.isfile(opt_zip):
        optimizations.apply(mesh)
        save.apply(mesh, opt_zip)
        mesh = None

    optmesh = collada.Collada(opt_zip)
    opt_render_info = getRenderInfo(optmesh)
    optmesh = None

    if not os.path.isfile(opt_ss):
        p = Process(target=save_screenshot, args=(opt_zip, opt_ss))
        p.start()
        p.join()

    orig_ss_copy = f_dir + '.orig.png'
    opt_ss_copy = f_dir + '.opt.png'
    if not os.path.isfile(orig_ss_copy):
        shutil.copy2(orig_ss, orig_ss_copy)
    if not os.path.isfile(opt_ss_copy):
        shutil.copy2(opt_ss, opt_ss_copy)

    orig_size = os.stat(orig_zip)[6]
    opt_size = os.stat(opt_zip)[6]
    return (f_dir, orig_size, opt_size, orig_render_info, opt_render_info)
예제 #2
0
def process_file(base_dir, f):
    current_process().daemon = False
    
    base_name = decode(f['base_name'])
    full_path = decode(f['full_path'])
    zip_hash = decode(f['metadata']['types']['original']['zip'])
    
    f_dir = full_path.replace('/','_')
    f_dir = os.path.join(base_dir, f_dir)
    if not os.path.isdir(f_dir):
        os.mkdir(f_dir)
    
    orig_zip = os.path.join(f_dir, base_name + '.orig.zip')
    if not os.path.isfile(orig_zip):
        f_data = urllib2.urlopen(DOWNLOAD + '/' + zip_hash).read()
        orig_zip_file = open(orig_zip, 'wb')
        orig_zip_file.write(f_data)
        orig_zip_file.close()
        
    optimizations = factory.getInstance('full_optimizations')
    save = factory.getInstance('save_collada_zip')
    
    orig_ss = orig_zip + '.png'
    opt_zip = os.path.join(f_dir, base_name + '.opt.zip')
    opt_ss = opt_zip + '.png'
    
    mesh = collada.Collada(orig_zip, zip_filename=base_name)
    orig_render_info = getRenderInfo(mesh)

    if not os.path.isfile(orig_ss):
        p = Process(target=save_screenshot, args=(orig_zip, orig_ss), kwargs={'zip_filename':base_name})
        p.start()
        p.join()
    
    if not os.path.isfile(opt_zip):
        optimizations.apply(mesh)
        save.apply(mesh, opt_zip)
        mesh = None
    
    optmesh = collada.Collada(opt_zip)
    opt_render_info = getRenderInfo(optmesh)
    optmesh = None
    
    if not os.path.isfile(opt_ss):
        p = Process(target=save_screenshot, args=(opt_zip, opt_ss))
        p.start()
        p.join()
        
    orig_ss_copy = f_dir + '.orig.png'
    opt_ss_copy = f_dir + '.opt.png'
    if not os.path.isfile(orig_ss_copy):
        shutil.copy2(orig_ss, orig_ss_copy)
    if not os.path.isfile(opt_ss_copy):
        shutil.copy2(opt_ss, opt_ss_copy)
        
    orig_size = os.stat(orig_zip)[6]
    opt_size = os.stat(opt_zip)[6]
    return (f_dir, orig_size, opt_size, orig_render_info, opt_render_info)
예제 #3
0
def getJSON(mesh):
    cameras = []
    for cam in mesh.cameras:
        cameras.append({'id':cam.id})
        
    lights = []
    for light in mesh.lights:
        lights.append({'id':light.id, 'type': type(light).__name__})
        
    materials = []
    for material in mesh.materials:
        materials.append({'id':material.id, 'effect':material.effect.id})
        
    effects = []
    for effect in mesh.effects:
        effects.append({'id':effect.id, 'type':effect.shadingtype})
        
    images = []
    for image in mesh.images:
        images.append({'id':image.id, 'name':image.path})
        
    primitives = []
    for geom in mesh.geometries:
        for i, prim in enumerate(geom.primitives):
            primitives.append({'id':"%s%d" % (geom.id, i),
                               'type':type(prim).__name__,
                               'vertices':len(prim.vertex_index) if prim.vertex_index is not None else 0,
                               'normals': prim.normal_index is not None,
                               'texcoords': len(prim.texcoord_indexset) > 0})
        
    json_ret = {'cameras': cameras,
                'lights': lights,
                'materials': materials,
                'effects': effects,
                'images': images,
                'primitives': primitives}
    
    json_ret.update(getRenderInfo(mesh))
    
    boundsInfo = getBoundsInfo(mesh)
    boundsInfo = {'bounds': [boundsInfo['bounds'][0].tolist(), boundsInfo['bounds'][1].tolist()],
                  'center': boundsInfo['center'].tolist(),
                  'center_farthest': boundsInfo['center_farthest'].tolist(),
                  'center_farthest_distance': float(boundsInfo['center_farthest_distance'])}
    json_ret['bounds_info'] = boundsInfo
    
    return json.dumps(json_ret)
예제 #4
0
def getJSON(mesh):
    cameras = []
    for cam in mesh.cameras:
        cameras.append({'id': cam.id})

    lights = []
    for light in mesh.lights:
        lights.append({'id': light.id, 'type': type(light).__name__})

    materials = []
    for material in mesh.materials:
        materials.append({'id': material.id, 'effect': material.effect.id})

    effects = []
    for effect in mesh.effects:
        effects.append({'id': effect.id, 'type': effect.shadingtype})

    images = []
    for image in mesh.images:
        images.append({'id': image.id, 'name': image.path})

    primitives = []
    for geom in mesh.geometries:
        for i, prim in enumerate(geom.primitives):
            primitives.append({
                'id':
                "%s%d" % (geom.id, i),
                'type':
                type(prim).__name__,
                'vertices':
                len(prim.vertex_index) if prim.vertex_index is not None else 0,
                'normals':
                prim.normal_index is not None,
                'texcoords':
                len(prim.texcoord_indexset) > 0
            })

    json_ret = {
        'cameras': cameras,
        'lights': lights,
        'materials': materials,
        'effects': effects,
        'images': images,
        'primitives': primitives
    }

    json_ret.update(getRenderInfo(mesh))

    boundsInfo = getBoundsInfo(mesh)
    boundsInfo = {
        'bounds':
        [boundsInfo['bounds'][0].tolist(), boundsInfo['bounds'][1].tolist()],
        'center':
        boundsInfo['center'].tolist(),
        'center_farthest':
        boundsInfo['center_farthest'].tolist(),
        'center_farthest_distance':
        float(boundsInfo['center_farthest_distance'])
    }
    json_ret['bounds_info'] = boundsInfo

    return json.dumps(json_ret)