def patch(): if state.proc_build != None: return assets.invalidate_enabled = False fp = arm.utils.get_fp() os.chdir(fp) asset_path = arm.utils.get_fp_build( ) + '/compiled/Assets/' + arm.utils.safestr( bpy.context.scene.name) + '.arm' ArmoryExporter.export_scene(bpy.context, asset_path, scene=bpy.context.scene) if not os.path.isdir(arm.utils.build_dir() + '/compiled/Shaders/std'): raw_shaders_path = arm.utils.get_sdk_path() + '/armory/Shaders/' shutil.copytree(raw_shaders_path + 'std', arm.utils.build_dir() + '/compiled/Shaders/std') node_path = arm.utils.get_node_path() khamake_path = arm.utils.get_khamake_path() cmd = [node_path, khamake_path, 'krom'] cmd.extend( ('--shaderversion', '330', '--parallelAssetConversion', '4', '--to', arm.utils.build_dir() + '/debug', '--nohaxe', '--noproject')) assets.invalidate_enabled = True state.proc_build = run_proc(cmd, patch_done)
def patch_export(): """Re-export the current scene and update the game accordingly.""" if not __running or state.proc_build is not None: return arm.assets.invalidate_enabled = False with arm.utils.WorkingDir(arm.utils.get_fp()): asset_path = arm.utils.get_fp_build( ) + '/compiled/Assets/' + arm.utils.safestr( bpy.context.scene.name) + '.arm' ArmoryExporter.export_scene(bpy.context, asset_path, scene=bpy.context.scene) dir_std_shaders_dst = os.path.join(arm.utils.build_dir(), 'compiled', 'Shaders', 'std') if not os.path.isdir(dir_std_shaders_dst): dir_std_shaders_src = os.path.join(arm.utils.get_sdk_path(), 'armory', 'Shaders', 'std') shutil.copytree(dir_std_shaders_src, dir_std_shaders_dst) node_path = arm.utils.get_node_path() khamake_path = arm.utils.get_khamake_path() cmd = [ node_path, khamake_path, 'krom', '--shaderversion', '330', '--parallelAssetConversion', '4', '--to', arm.utils.build_dir() + '/debug', '--nohaxe', '--noproject' ] arm.assets.invalidate_enabled = True state.proc_build = make.run_proc(cmd, patch_done)
def export_data(fp, sdk_path): wrd = bpy.data.worlds['Arm'] print('Armory v{0} ({1})'.format(wrd.arm_version, wrd.arm_commit)) if wrd.arm_verbose_output: print( f'Blender: {bpy.app.version_string}, Target: {state.target}, GAPI: {arm.utils.get_gapi()}' ) # Clean compiled variants if cache is disabled build_dir = arm.utils.get_fp_build() if not wrd.arm_cache_build: if os.path.isdir(build_dir + '/debug/html5-resources'): shutil.rmtree(build_dir + '/debug/html5-resources', onerror=remove_readonly) if os.path.isdir(build_dir + '/krom-resources'): shutil.rmtree(build_dir + '/krom-resources', onerror=remove_readonly) if os.path.isdir(build_dir + '/debug/krom-resources'): shutil.rmtree(build_dir + '/debug/krom-resources', onerror=remove_readonly) if os.path.isdir(build_dir + '/windows-resources'): shutil.rmtree(build_dir + '/windows-resources', onerror=remove_readonly) if os.path.isdir(build_dir + '/linux-resources'): shutil.rmtree(build_dir + '/linux-resources', onerror=remove_readonly) if os.path.isdir(build_dir + '/osx-resources'): shutil.rmtree(build_dir + '/osx-resources', onerror=remove_readonly) if os.path.isdir(build_dir + '/compiled/Shaders'): shutil.rmtree(build_dir + '/compiled/Shaders', onerror=remove_readonly) raw_shaders_path = sdk_path + '/armory/Shaders/' assets_path = sdk_path + '/armory/Assets/' export_physics = bpy.data.worlds['Arm'].arm_physics != 'Disabled' export_navigation = bpy.data.worlds['Arm'].arm_navigation != 'Disabled' export_ui = bpy.data.worlds['Arm'].arm_ui != 'Disabled' assets.reset() # Build node trees ArmoryExporter.import_traits = [] make_logic.build() make_world.build() make_renderpath.build() # Export scene data assets.embedded_data = sorted(list(set(assets.embedded_data))) physics_found = False navigation_found = False ui_found = False ArmoryExporter.compress_enabled = state.is_publish and wrd.arm_asset_compression ArmoryExporter.optimize_enabled = state.is_publish and wrd.arm_optimize_data if not os.path.exists(build_dir + '/compiled/Assets'): os.makedirs(build_dir + '/compiled/Assets') # have a "zoo" collection in the current scene export_coll = bpy.data.collections.new("export_coll") bpy.context.scene.collection.children.link(export_coll) for scene in bpy.data.scenes: if scene == bpy.context.scene: continue for o in scene.collection.all_objects: if o.type == "MESH" or o.type == "EMPTY": if o.name not in export_coll.all_objects.keys(): export_coll.objects.link(o) depsgraph = bpy.context.evaluated_depsgraph_get() bpy.data.collections.remove(export_coll) # destroy "zoo" collection for scene in bpy.data.scenes: if scene.arm_export: ext = '.lz4' if ArmoryExporter.compress_enabled else '.arm' asset_path = build_dir + '/compiled/Assets/' + arm.utils.safestr( scene.name) + ext ArmoryExporter.export_scene(bpy.context, asset_path, scene=scene, depsgraph=depsgraph) if ArmoryExporter.export_physics: physics_found = True if ArmoryExporter.export_navigation: navigation_found = True if ArmoryExporter.export_ui: ui_found = True assets.add(asset_path) if physics_found == False: # Disable physics if no rigid body is exported export_physics = False if navigation_found == False: export_navigation = False if ui_found == False: export_ui = False if wrd.arm_ui == 'Enabled': export_ui = True modules = [] if wrd.arm_audio == 'Enabled': modules.append('audio') if export_physics: modules.append('physics') if export_navigation: modules.append('navigation') if export_ui: modules.append('ui') defs = arm.utils.def_strings_to_array(wrd.world_defs) cdefs = arm.utils.def_strings_to_array(wrd.compo_defs) if wrd.arm_verbose_output: print('Exported modules:', ', '.join(modules)) print('Shader flags:', ' '.join(defs)) print('Compositor flags:', ' '.join(cdefs)) print('Khafile flags:', ' '.join(assets.khafile_defs)) # Render path is configurable at runtime has_config = wrd.arm_write_config or os.path.exists(arm.utils.get_fp() + '/Bundled/config.arm') # Write compiled.inc shaders_path = build_dir + '/compiled/Shaders' if not os.path.exists(shaders_path): os.makedirs(shaders_path) write_data.write_compiledglsl(defs + cdefs, make_variants=has_config) # Write referenced shader passes if not os.path.isfile(build_dir + '/compiled/Shaders/shader_datas.arm' ) or state.last_world_defs != wrd.world_defs: res = {'shader_datas': []} for ref in assets.shader_passes: # Ensure shader pass source exists if not os.path.exists(raw_shaders_path + '/' + ref): continue assets.shader_passes_assets[ref] = [] if ref.startswith('compositor_pass'): compile_shader_pass(res, raw_shaders_path, ref, defs + cdefs, make_variants=has_config) else: compile_shader_pass(res, raw_shaders_path, ref, defs, make_variants=has_config) # Workaround to also export non-material world shaders res['shader_datas'] += make_world.shader_datas arm.utils.write_arm(shaders_path + '/shader_datas.arm', res) for ref in assets.shader_passes: for s in assets.shader_passes_assets[ref]: assets.add_shader(shaders_path + '/' + s + '.glsl') for file in assets.shaders_external: name = file.split('/')[-1].split('\\')[-1] target = build_dir + '/compiled/Shaders/' + name if not os.path.exists(target): shutil.copy(file, target) state.last_world_defs = wrd.world_defs # Reset path os.chdir(fp) # Copy std shaders if not os.path.isdir(build_dir + '/compiled/Shaders/std'): shutil.copytree(raw_shaders_path + 'std', build_dir + '/compiled/Shaders/std') # Write config.arm resx, resy = arm.utils.get_render_resolution(arm.utils.get_active_scene()) if wrd.arm_write_config: write_data.write_config(resx, resy) # Change project version (Build, Publish) if (not state.is_play) and (wrd.arm_project_version_autoinc): wrd.arm_project_version = arm.utils.arm.utils.change_version_project( wrd.arm_project_version) # Write khafile.js enable_dce = state.is_publish and wrd.arm_dce import_logic = not state.is_publish and arm.utils.logic_editor_space( ) != None write_data.write_khafilejs(state.is_play, export_physics, export_navigation, export_ui, state.is_publish, enable_dce, ArmoryExporter.import_traits, import_logic) # Write Main.hx - depends on write_khafilejs for writing number of assets scene_name = arm.utils.get_project_scene_name() write_data.write_mainhx(scene_name, resx, resy, state.is_play, state.is_publish) if scene_name != state.last_scene or resx != state.last_resx or resy != state.last_resy: wrd.arm_recompile = True state.last_resx = resx state.last_resy = resy state.last_scene = scene_name
import subprocess import threading import webbrowser import arm.utils import arm.write_data as write_data import arm.make_logic as make_logic import arm.make_renderpath as make_renderpath import arm.make_world as make_world import arm.make_state as state import arm.assets as assets import arm.log as log import arm.lib.make_datas import arm.lib.server from arm.exporter import ArmoryExporter exporter = ArmoryExporter() scripts_mtime = 0 # Monitor source changes profile_time = 0 def run_proc(cmd, done): def fn(p, done): p.wait() if done != None: done() p = subprocess.Popen(cmd) threading.Thread(target=fn, args=(p, done)).start() return p