def get(self): s = '#version 450\n' s += self.header defs = make_utils.def_strings_to_array( bpy.data.worlds['Arm'].world_defs) for a in defs: s += '#define {0}\n'.format(a) in_ext = '' out_ext = '' if self.shader_type == 'vert' and self.vertex_structure_as_vsinput: # Vertex structure as vertex shader input vs = self.context.data['vertex_structure'] for e in vs: self.add_in('vec' + str(e['size']) + ' ' + e['name']) elif self.shader_type == 'tesc': in_ext = '[]' out_ext = '[]' s += 'layout(vertices = 3) out;\n' # Gen outs for sin in self.ins: ar = sin.rsplit(' ', 1) # vec3 wnormal tc_s = 'tc_' + ar[1] self.add_out(ar[0] + ' ' + tc_s) # Pass data self.write( '{0}[gl_InvocationID] = {1}[gl_InvocationID];'.format( tc_s, ar[1])) elif self.shader_type == 'tese': in_ext = '[]' s += 'layout(triangles, equal_spacing, ccw) in;\n' elif self.shader_type == 'geom': in_ext = '[]' s += 'layout(triangles) in;\n' s += 'layout(triangle_strip, max_vertices = 3) out;\n' for a in self.includes: s += '#include "' + a + '"\n' for a in self.ins: s += 'in {0}{1};\n'.format(a, in_ext) for a in self.outs: s += 'out {0}{1};\n'.format(a, out_ext) for a in self.uniforms: s += 'uniform ' + a + ';\n' for f in self.functions: s += self.functions[f] s += 'void main() {\n' s += self.main_header s += self.main_pre s += self.main s += '}\n' return s
def export_data(fp, sdk_path, is_play=False, is_publish=False, in_viewport=False): global exporter wrd = bpy.data.worlds['Arm'] print('\nArmory v' + wrd.arm_version) print('OS: ' + arm.utils.get_os() + ', Target: ' + state.target + ', GAPI: ' + arm.utils.get_gapi()) # Clean compiled variants if cache is disabled build_dir = arm.utils.build_dir() if wrd.arm_cache_shaders == False: if os.path.isdir(build_dir + '/build/html5-resources'): shutil.rmtree(build_dir + '/build/html5-resources', onerror=remove_readonly) if os.path.isdir(build_dir + '/build/krom-resources'): shutil.rmtree(build_dir + '/build/krom-resources', onerror=remove_readonly) if os.path.isdir(build_dir + '/windowed/krom-resources'): shutil.rmtree(build_dir + '/windowed/krom-resources', onerror=remove_readonly) if os.path.isdir(build_dir + '/compiled/Shaders'): shutil.rmtree(build_dir + '/compiled/Shaders', onerror=remove_readonly) if os.path.isdir(build_dir + '/compiled/ShaderRaws'): shutil.rmtree(build_dir + '/compiled/ShaderRaws', onerror=remove_readonly) # Detect camera plane changes if len(bpy.data.cameras) > 0: cam = bpy.data.cameras[0] if state.last_clip_start == 0: state.last_clip_start = cam.clip_start state.last_clip_end = cam.clip_end elif cam.clip_start != state.last_clip_start or cam.clip_end != state.last_clip_end: if os.path.isdir(build_dir + '/compiled/Shaders'): shutil.rmtree(build_dir + '/compiled/Shaders', onerror=remove_readonly) state.last_clip_start = cam.clip_start state.last_clip_end = cam.clip_end 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 # TODO: cache make_logic.build_node_trees() active_worlds = set() for scene in bpy.data.scenes: if scene.arm_export and scene.world != None: active_worlds.add(scene.world) world_outputs = make_world.build_node_trees(active_worlds) make_renderpath.build_node_trees(assets_path) for wout in world_outputs: make_world.write_output(wout) # Export scene data assets.embedded_data = sorted(list(set(assets.embedded_data))) physics_found = False navigation_found = False ui_found = False ArmoryExporter.compress_enabled = is_publish and wrd.arm_asset_compression ArmoryExporter.in_viewport = in_viewport ArmoryExporter.import_traits = [] for scene in bpy.data.scenes: if scene.arm_export: ext = '.zip' if (scene.arm_compress and is_publish) else '.arm' asset_path = arm.utils.build_dir( ) + '/compiled/Assets/' + arm.utils.safestr(scene.name) + ext exporter.execute(bpy.context, asset_path, scene=scene, write_capture_info=state.is_render_anim, play_area=state.play_area) 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 export_physics: modules.append('physics') if export_navigation: modules.append('navigation') if export_ui: modules.append('ui') print('Exported modules: ' + str(modules)) # Write referenced shader variants for ref in assets.shader_datas: # Data does not exist yet if not os.path.isfile(fp + '/' + ref): shader_name = ref.split('/')[ 3] # Extract from 'build/compiled/...' defs = make_utils.def_strings_to_array(wrd.world_defs) if shader_name.startswith('compositor_pass'): defs += make_utils.def_strings_to_array(wrd.compo_defs) elif shader_name.startswith('grease_pencil'): defs = [] compile_shader(raw_shaders_path, shader_name, defs) # Reset path os.chdir(fp) # Copy std shaders if not os.path.isdir(arm.utils.build_dir() + '/compiled/Shaders/std'): shutil.copytree(raw_shaders_path + 'std', arm.utils.build_dir() + '/compiled/Shaders/std') # Write compiled.glsl write_data.write_compiledglsl() # Write khafile.js enable_dce = is_publish and wrd.arm_dce import_logic = not is_publish and arm.utils.logic_editor_space() != None write_data.write_khafilejs(is_play, export_physics, export_navigation, export_ui, is_publish, enable_dce, in_viewport, ArmoryExporter.import_traits, import_logic) # Write Main.hx - depends on write_khafilejs for writing number of assets resx, resy = arm.utils.get_render_resolution(arm.utils.get_active_scene()) # Import all logic nodes for patching if logic is being edited write_data.write_main(resx, resy, is_play, in_viewport, is_publish) if resx != state.last_resx or resy != state.last_resy: wrd.arm_recompile = True state.last_resx = resx state.last_resy = resy
def export_data(fp, sdk_path, is_play=False, is_publish=False, in_viewport=False): global exporter wrd = bpy.data.worlds['Arm'] print('\nArmory v' + wrd.arm_version) print('OS: ' + arm.utils.get_os() + ', Target: ' + state.target + ', GAPI: ' + arm.utils.get_gapi()) # Clean compiled variants if cache is disabled if wrd.arm_cache_shaders == False: build_dir = arm.utils.build_dir() if os.path.isdir(build_dir + '/build/html5-resources'): shutil.rmtree(build_dir + '/build/html5-resources') if os.path.isdir(build_dir + '/build/krom-resources'): shutil.rmtree(build_dir + '/build/krom-resources') if os.path.isdir(build_dir + '/window/krom-resources'): shutil.rmtree(build_dir + '/window/krom-resources') if os.path.isdir(build_dir + '/compiled/Shaders'): shutil.rmtree(build_dir + '/compiled/Shaders') if os.path.isdir(build_dir + '/compiled/ShaderRaws'): shutil.rmtree(build_dir + '/compiled/ShaderRaws') 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' assets.reset() # Build node trees # TODO: cache make_logic.build_node_trees() active_worlds = set() for scene in bpy.data.scenes: if scene.game_export and scene.world != None: active_worlds.add(scene.world) world_outputs = make_world.build_node_trees(active_worlds) make_renderpath.build_node_trees(assets_path) for wout in world_outputs: make_world.write_output(wout) # Export scene data assets.embedded_data = sorted(list(set(assets.embedded_data))) physics_found = False navigation_found = False ArmoryExporter.compress_enabled = is_publish ArmoryExporter.in_viewport = in_viewport for scene in bpy.data.scenes: if scene.game_export: ext = '.zip' if (scene.data_compressed and is_publish) else '.arm' asset_path = arm.utils.build_dir( ) + '/compiled/Assets/' + arm.utils.safestr(scene.name) + ext exporter.execute(bpy.context, asset_path, scene=scene) if physics_found == False and ArmoryExporter.export_physics: physics_found = True if navigation_found == False and ArmoryExporter.export_navigation: navigation_found = True assets.add(asset_path) if physics_found == False: # Disable physics anyway if no rigid body exported export_physics = False if navigation_found == False: export_navigation = False # Write referenced shader variants for ref in assets.shader_datas: # Data does not exist yet if not os.path.isfile(fp + '/' + ref): shader_name = ref.split('/')[ 3] # Extract from 'build/compiled/...' defs = make_utils.def_strings_to_array(wrd.world_defs + wrd.rp_defs) if shader_name.startswith('compositor_pass'): defs += make_utils.def_strings_to_array(wrd.compo_defs) elif shader_name.startswith('grease_pencil'): defs = [] compile_shader(raw_shaders_path, shader_name, defs) # Reset path os.chdir(fp) # Copy std shaders if not os.path.isdir(arm.utils.build_dir() + '/compiled/Shaders/std'): shutil.copytree(raw_shaders_path + 'std', arm.utils.build_dir() + '/compiled/Shaders/std') # Write compiled.glsl write_data.write_compiledglsl() # Write khafile.js write_data.write_khafilejs(is_play, export_physics, export_navigation, is_publish) # Write Main.hx - depends on write_khafilejs for writing number of assets resx, resy = arm.utils.get_render_resolution(arm.utils.get_active_scene()) write_data.write_main(resx, resy, is_play, in_viewport, is_publish) if resx != state.last_resx or resy != state.last_resy: wrd.arm_recompile = True state.last_resx = resx state.last_resy = resy