From 46a094057ff81806c65453e5676f7955890ac03b Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sun, 19 Jun 2016 21:22:55 -0400 Subject: [PATCH] Lightmap Mod: Don't expose tracebacks to the user Rather, inform the user in a standardized way when nothing was baked. Beats the heck out of seeing a random traceback! --- korman/exporter/etlight.py | 6 +++++- korman/operators/op_lightmap.py | 4 +++- korman/ui/modifiers/render.py | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/korman/exporter/etlight.py b/korman/exporter/etlight.py index 753b8de..bb829bb 100644 --- a/korman/exporter/etlight.py +++ b/korman/exporter/etlight.py @@ -69,11 +69,12 @@ class LightBaker: with GoodNeighbor() as toggle: try: # reduce the amount of indentation - self._bake_static_lighting(bake, toggle) + result = self._bake_static_lighting(bake, toggle) finally: # this stuff has been observed to be problematic with GoodNeighbor self._pop_lightgroups() self._restore_uvtexs() + return result def _bake_static_lighting(self, bake, toggle): # Step 0.9: Make all layers visible. @@ -112,6 +113,9 @@ class LightBaker: else: raise RuntimeError(key[0]) + # Return how many thingos we baked + return sum(map(sum, bake.values())) + def _generate_lightgroup(self, mesh, user_lg=None): """Makes a new light group for the baking process that excludes all Plasma RT lamps""" diff --git a/korman/operators/op_lightmap.py b/korman/operators/op_lightmap.py index 01d313c..5581718 100644 --- a/korman/operators/op_lightmap.py +++ b/korman/operators/op_lightmap.py @@ -42,7 +42,9 @@ class LightmapAutobakePreviewOperator(_LightingOperator, bpy.types.Operator): toggle.track(context.scene, "layers", tuple(context.scene.layers)) bake = LightBaker() - bake.bake_static_lighting([context.active_object,]) + if not bake.bake_static_lighting([context.active_object,]): + self.report({"INFO"}, "No valid lights found to bake.") + return {"FINISHED"} tex = bpy.data.textures.get("LIGHTMAPGEN_PREVIEW") if tex is None: diff --git a/korman/ui/modifiers/render.py b/korman/ui/modifiers/render.py index 0b46424..bfc4dde 100644 --- a/korman/ui/modifiers/render.py +++ b/korman/ui/modifiers/render.py @@ -59,7 +59,7 @@ def lightmap(modifier, layout, context): # the backing image name to see if it's for this lightmap. If so, you have a preview. If not, # well... It was nice knowing you! tex = bpy.data.textures.get("LIGHTMAPGEN_PREVIEW") - if tex is not None: + if tex is not None and tex.image is not None: im_name = "{}_LIGHTMAPGEN.png".format(context.active_object.name) if tex.image.name == im_name: layout.template_preview(tex, show_buttons=False)