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)
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)
def progressive_screenshot(prog_dae, prog_pdae, percentage, screenshot_file, full_path): mesh = collada.Collada(prog_dae) if os.path.isfile(prog_pdae): add_pm = factory.getInstance('add_back_pm') try: mesh = add_pm.apply(mesh, prog_pdae, percentage) except collada.DaeError: print 'FAILED', full_path return screenshot = factory.getInstance('save_screenshot') screenshot.apply(mesh, screenshot_file)
def fullOptimizations(mesh): optimize_filters = [ 'triangulate', 'generate_normals', 'combine_effects', 'combine_materials', 'combine_primitives', 'adjust_texcoords', 'optimize_textures', 'split_triangle_texcoords', 'normalize_indices', 'make_atlases', 'combine_effects', 'combine_materials', 'combine_primitives', 'optimize_sources', 'strip_unused_sources', 'optimize_textures' ] for f in optimize_filters: inst = factory.getInstance(f) mesh = inst.apply(mesh) return mesh
def mediumOptimizations(mesh): optimize_filters = [ "triangulate", "generate_normals", "combine_effects", "combine_materials", "combine_primitives", "optimize_sources", "strip_unused_sources", "optimize_textures", ] for f in optimize_filters: inst = factory.getInstance(f) mesh = inst.apply(mesh) return mesh
def process(meshPath): mesh = collada.Collada(meshPath) # 'triangulate', optimize_filters = [ 'combine_primitives', 'optimize_sources', 'strip_unused_sources', 'normalize_indices' ] for f in optimize_filters: inst = factory.getInstance(f) mesh = inst.apply(mesh) # f = 'sander_simplify' # pmout = open('pm_file', 'w') # inst = factory.getInstance(f) # mesh = inst.apply(mesh, pmout) # s = meshtool.filters.simplify_filters.sander_simplify.SanderSimplify(mesh, pmout) # meshsimple = s.simplify() return mesh
def save_screenshot(mesh_file, screenshot_file, zip_filename=None): screenshot = factory.getInstance('save_screenshot') mesh = collada.Collada(mesh_file, zip_filename=zip_filename) screenshot.apply(mesh, screenshot_file)
def save_screenshot(mesh_file, screenshot_file, zip_filename=None): mesh = collada.Collada(mesh_file, zip_filename=zip_filename) strip_lines = factory.getInstance('strip_lines') mesh = strip_lines.apply(mesh) screenshot = factory.getInstance('save_screenshot') screenshot.apply(mesh, screenshot_file)