From 009545d71634216da1c65a890c317c79c73f767a Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Thu, 17 Sep 2015 09:50:01 -1000 Subject: [PATCH] Patching and lightmap updates --- hecl/blender/BlenderConnection.cpp | 6 +++ hecl/blender/hecl/Patching.py | 69 +++++++++++++++++++----------- hecl/blender/hecl/__init__.py | 1 + hecl/blender/hecl/srea/__init__.py | 5 ++- hecl/blender/hecl_blendershell.py | 9 +++- 5 files changed, 62 insertions(+), 28 deletions(-) diff --git a/hecl/blender/BlenderConnection.cpp b/hecl/blender/BlenderConnection.cpp index dee945e7a..753710e62 100644 --- a/hecl/blender/BlenderConnection.cpp +++ b/hecl/blender/BlenderConnection.cpp @@ -317,6 +317,12 @@ BlenderConnection::BlenderConnection(bool silenceBlender) BlenderLog.report(LogVisor::FatalError, "unable to install blender addon using '%s'", blenderAddonPath.c_str()); continue; } + else if (!strcmp(lineBuf, "ADDONINSTALLED")) + { + _closePipe(); + blenderAddonPath = _S("SKIPINSTALL"); + continue; + } else if (strcmp(lineBuf, "READY")) { _closePipe(); diff --git a/hecl/blender/hecl/Patching.py b/hecl/blender/hecl/Patching.py index 490b47eee..f5c8deb3d 100644 --- a/hecl/blender/hecl/Patching.py +++ b/hecl/blender/hecl/Patching.py @@ -29,30 +29,30 @@ def find_project_root(): return path[0] return None -def get_patching_dir(make_dirs=False): +def get_patching_dirs(make_dirs=False): proj_root = find_project_root() if not proj_root: - return None + return None, None rel_to_blend = os.path.relpath(bpy.data.filepath, start=proj_root) rel_to_blend_comps = path_components(rel_to_blend) trace_dir = os.path.join(proj_root, '.hecl', 'patches') + global_out = trace_dir if not make_dirs and not os.path.exists(trace_dir): - return None + return None, global_out _mkdir(trace_dir) for comp in rel_to_blend_comps: ext_pair = os.path.splitext(comp) if ext_pair[1] == '.blend': trace_dir = os.path.join(trace_dir, ext_pair[0]) if not make_dirs and not os.path.exists(trace_dir): - return None + return None, global_out _mkdir(trace_dir) - return trace_dir + return trace_dir, global_out trace_dir = os.path.join(trace_dir, comp) if not make_dirs and not os.path.exists(trace_dir): - return None + return None, global_out _mkdir(trace_dir) - class FILE_OT_hecl_patching_save(bpy.types.Operator): '''Save text datablocks to hecl patching directory''' bl_idname = "file.hecl_patching_save" @@ -60,13 +60,13 @@ class FILE_OT_hecl_patching_save(bpy.types.Operator): bl_options = {'REGISTER'} def execute(self, context): - patching_dir = get_patching_dir(make_dirs=True) + patching_dir, global_dir = get_patching_dirs(make_dirs=True) if not patching_dir: - self.report({'ERROR'}, 'Unable to save patches for ' + bpy.data.filepath) + self.report({'WARNING'}, 'Unable to save patches for ' + bpy.data.filepath) return {'CANCELLED'} count = 0 for text in bpy.data.texts: - if not text.name.endswith('.py'): + if not text.name.endswith('.py') or text.name.startswith('g_'): continue text_abspath = os.path.join(patching_dir, text.name) text_file = open(text_abspath, 'w') @@ -86,23 +86,40 @@ class FILE_OT_hecl_patching_load(bpy.types.Operator): bl_options = {'REGISTER'} def execute(self, context): - patching_dir = get_patching_dir() - if not patching_dir: - self.report({'ERROR'}, 'Unable to load patches for ' + bpy.data.filepath) - return {'CANCELLED'} - p = Path(patching_dir) + patching_dir, global_dir = get_patching_dirs() count = 0 - for path in p.glob('*.py'): - path = path.name - text_abspath = os.path.join(patching_dir, path) - text_file = open(text_abspath, 'r') - if path in bpy.data.texts: - text = bpy.data.texts[path] - else: - text = bpy.data.texts.new(path) - text.from_string(text_file.read()) - text_file.close() - count += 1 + + # Locals + if patching_dir: + p = Path(patching_dir) + for path in p.glob('*.py'): + path = path.name + text_abspath = os.path.join(patching_dir, path) + text_file = open(text_abspath, 'r') + if path in bpy.data.texts: + text = bpy.data.texts[path] + else: + text = bpy.data.texts.new(path) + text.from_string(text_file.read()) + text_file.close() + count += 1 + + # Globals + if global_dir: + p = Path(global_dir) + print('CHECKING', global_dir) + for path in p.glob('g_*.py'): + path = path.name + text_abspath = os.path.join(global_dir, path) + text_file = open(text_abspath, 'r') + if path in bpy.data.texts: + text = bpy.data.texts[path] + else: + text = bpy.data.texts.new(path) + text.from_string(text_file.read()) + text_file.close() + count += 1 + if count == 1: self.report({'INFO'}, 'loaded 1 patch') else: diff --git a/hecl/blender/hecl/__init__.py b/hecl/blender/hecl/__init__.py index b7a89a676..95acdd38c 100644 --- a/hecl/blender/hecl/__init__.py +++ b/hecl/blender/hecl/__init__.py @@ -18,6 +18,7 @@ Nodegrid = Nodegrid.Nodegrid import bpy, os, sys from bpy.app.handlers import persistent + # Appendable list allowing external addons to register additional resource types hecl_typeS = [ ('NONE', "None", "Active scene not using HECL", None, None), diff --git a/hecl/blender/hecl/srea/__init__.py b/hecl/blender/hecl/srea/__init__.py index 08348a920..e16ab6188 100644 --- a/hecl/blender/hecl/srea/__init__.py +++ b/hecl/blender/hecl/srea/__init__.py @@ -324,6 +324,9 @@ class SREAInitializeCycles(bpy.types.Operator): initialize_nodetree_cycles(mat, pixel_size) return {'FINISHED'} + def invoke(self, context, event): + return context.window_manager.invoke_confirm(self, event) + # Lightmap render operator class SREARenderLightmaps(bpy.types.Operator): bl_idname = "scene.hecl_area_render_lightmaps" @@ -347,7 +350,7 @@ class SREARenderLightmaps(bpy.types.Operator): # Mmm Cycles context.scene.render.engine = 'CYCLES' - context.scene.render.bake.margin = pixel_size // 128 + context.scene.render.bake.margin = pixel_size // 256 # Iterate materials and setup cycles for mat in bpy.data.materials: diff --git a/hecl/blender/hecl_blendershell.py b/hecl/blender/hecl_blendershell.py index b3b94d30d..d1023d073 100644 --- a/hecl/blender/hecl_blendershell.py +++ b/hecl/blender/hecl_blendershell.py @@ -34,9 +34,11 @@ def quitblender(): bpy.ops.wm.quit_blender() # If there's a third argument, use it as the .zip path containing the addon -if len(args) >= 3: +did_install = False +if len(args) >= 3 and args[2] != 'SKIPINSTALL': bpy.ops.wm.addon_install(overwrite=True, target='DEFAULT', filepath=args[2]) bpy.ops.wm.addon_refresh() + did_install = True # Make addon available to commands if bpy.context.user_preferences.addons.find('hecl') == -1: @@ -51,6 +53,11 @@ except: writepipeline(b'NOADDON') bpy.ops.wm.quit_blender() +# Quit if just installed +if did_install: + writepipeline(b'ADDONINSTALLED') + bpy.ops.wm.quit_blender() + # Intro handshake writepipeline(b'READY') ackbytes = readpipeline()