def build_project(is_play=False, is_publish=False, in_viewport=False, target=None): wrd = bpy.data.worlds['Arm'] # Set target if target == None: state.target = wrd.arm_project_target.lower() # Clear flag state.in_viewport = False # Save blend if arm.utils.get_save_on_build(): bpy.ops.wm.save_mainfile() log.clear() # Set camera in active scene active_scene = bpy.context.screen.scene if wrd.arm_play_active_scene else bpy.data.scenes[ wrd.arm_project_scene] if active_scene.camera == None: for o in active_scene.objects: if o.type == 'CAMERA': active_scene.camera = o break # Get paths sdk_path = arm.utils.get_sdk_path() raw_shaders_path = sdk_path + '/armory/Shaders/' # Set dir fp = arm.utils.get_fp() os.chdir(fp) # Create directories sources_path = 'Sources/' + arm.utils.safestr(wrd.arm_project_package) if not os.path.exists(sources_path): os.makedirs(sources_path) # Compile path tracer shaders # if len(bpy.data.cameras) > 0 and bpy.data.cameras[0].renderpath_path == 'pathtrace_path': # path_tracer.compile(raw_shaders_path + 'pt_trace_pass/pt_trace_pass.frag.glsl') # Save external scripts edited inside Blender write_texts = False for text in bpy.data.texts: if text.filepath != '' and text.is_dirty: write_texts = True break if write_texts: area = bpy.context.area old_type = area.type area.type = 'TEXT_EDITOR' for text in bpy.data.texts: if text.filepath != '' and text.is_dirty and os.path.isfile( text.filepath): area.spaces[0].text = text bpy.ops.text.save() area.type = old_type # Save internal Haxe scripts for text in bpy.data.texts: if text.filepath == '' and text.name[-3:] == '.hx': with open( 'Sources/' + arm.utils.safestr(wrd.arm_project_package) + '/' + text.name, 'w') as f: f.write(text.as_string()) # Export data export_data(fp, sdk_path, is_play=is_play, is_publish=is_publish, in_viewport=in_viewport) if state.target == 'html5': w, h = arm.utils.get_render_resolution(arm.utils.get_active_scene()) write_data.write_indexhtml(w, h) # Bundle files from include dir if os.path.isdir('include'): for fn in glob.iglob(os.path.join('include', '**'), recursive=False): shutil.copy( fn, arm.utils.build_dir() + '/html5/' + os.path.basename(fn)) if state.playproc == None: log.print_progress(50)
def build(target, is_play=False, is_publish=False, is_export=False): global profile_time profile_time = time.time() state.target = target state.is_play = is_play state.is_publish = is_publish state.is_export = is_export # Save blend if arm.utils.get_save_on_build(): bpy.ops.wm.save_mainfile() log.clear() # Set camera in active scene active_scene = arm.utils.get_active_scene() if active_scene.camera == None: for o in active_scene.objects: if o.type == 'CAMERA': active_scene.camera = o break # Get paths sdk_path = arm.utils.get_sdk_path() raw_shaders_path = sdk_path + '/armory/Shaders/' # Set dir fp = arm.utils.get_fp() os.chdir(fp) # Create directories wrd = bpy.data.worlds['Arm'] sources_path = 'Sources/' + arm.utils.safestr(wrd.arm_project_package) if not os.path.exists(sources_path): os.makedirs(sources_path) # Save external scripts edited inside Blender write_texts = False for text in bpy.data.texts: if text.filepath != '' and text.is_dirty: write_texts = True break if write_texts: area = bpy.context.area old_type = area.type area.type = 'TEXT_EDITOR' for text in bpy.data.texts: if text.filepath != '' and text.is_dirty and os.path.isfile( text.filepath): area.spaces[0].text = text bpy.ops.text.save() area.type = old_type # Save internal Haxe scripts for text in bpy.data.texts: if text.filepath == '' and text.name[-3:] == '.hx': with open( 'Sources/' + arm.utils.safestr(wrd.arm_project_package) + '/' + text.name, 'w') as f: f.write(text.as_string()) # Export data export_data(fp, sdk_path) if state.target == 'html5': w, h = arm.utils.get_render_resolution(arm.utils.get_active_scene()) write_data.write_indexhtml(w, h, is_publish) # Bundle files from include dir if os.path.isdir('include'): dest = '/html5/' if is_publish else '/debug/html5/' for fn in glob.iglob(os.path.join('include', '**'), recursive=False): shutil.copy( fn, arm.utils.build_dir() + dest + os.path.basename(fn))
def play_project(in_viewport): global scripts_mtime wrd = bpy.data.worlds['Arm'] log.clear() # Store area if arm.utils.with_krom() and in_viewport and bpy.context.area != None and bpy.context.area.type == 'VIEW_3D': state.play_area = bpy.context.area state.target = runtime_to_target(in_viewport) # Build data build_project(is_play=True, in_viewport=in_viewport, target=state.target) state.in_viewport = in_viewport khajs_path = get_khajs_path(in_viewport, state.target) if wrd.arm_recompile or \ wrd.arm_recompile_trigger or \ not wrd.arm_cache_compiler or \ not wrd.arm_cache_shaders or \ not os.path.isfile(khajs_path) or \ state.last_target != state.target or \ state.last_in_viewport != state.in_viewport: wrd.arm_recompile = True wrd.arm_recompile_trigger = False state.last_target = state.target state.last_in_viewport = state.in_viewport # Trait sources modified script_path = arm.utils.get_fp() + '/Sources/' + wrd.arm_project_package if os.path.isdir(script_path): for fn in glob.iglob(os.path.join(script_path, '**', '*.hx'), recursive=True): mtime = os.path.getmtime(fn) if scripts_mtime < mtime: scripts_mtime = mtime wrd.arm_recompile = True # New compile requred - traits or materials changed if wrd.arm_recompile or state.target == 'native': # Unable to live-patch, stop player if state.krom_running: bpy.ops.arm.space_stop('EXEC_DEFAULT') # play_project(in_viewport=True) # Restart return mode = 'play' if state.target == 'native': state.compileproc = compile_project(target_name='--run') elif state.target == 'krom': if in_viewport: mode = 'play_viewport' state.compileproc = compile_project(target_name='krom') else: # Electron, Browser w, h = arm.utils.get_render_resolution(arm.utils.get_active_scene()) write_data.write_electronjs(w, h) write_data.write_indexhtml(w, h) state.compileproc = compile_project(target_name='html5') threading.Timer(0.1, watch_compile, [mode]).start() else: # kha.js up to date compile_project(target_name=state.target, patch=True)