From b412e444dd7b50ed0935ebffda6e756548a16c23 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Tue, 23 Jun 2015 16:53:48 -0400 Subject: [PATCH] Don't die if LM'd object isn't on an active layer It appears that the mode set operator only works on active layers, so we have to make sure our lightmapped object's layers are active. *Sigh* --- korman/helpers.py | 11 +++++++++++ korman/operators/op_lightmap.py | 8 ++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/korman/helpers.py b/korman/helpers.py index c87680c..bb89fad 100644 --- a/korman/helpers.py +++ b/korman/helpers.py @@ -30,11 +30,22 @@ class GoodNeighbor: def __exit__(self, type, value, traceback): for (cls, attr), value in self._tracking.items(): setattr(cls, attr, value) + bpy.context.scene.update() +def enter_edit_mode(bo, toggle): + """Ensures an object is placed in edit mode""" + scene = bpy.context.scene + toggle.track(scene, "layers", bo.layers) + scene.update() + bpy.ops.object.mode_set(mode="EDIT") + def ensure_power_of_two(value): return pow(2, math.floor(math.log(value, 2))) +def exit_edit_mode(): + bpy.ops.object.mode_set(mode="OBJECT") + def make_active_selection(bo): """Selects a single Blender Object and makes it active""" for i in bpy.data.objects: diff --git a/korman/operators/op_lightmap.py b/korman/operators/op_lightmap.py index 70e0c80..64f200e 100644 --- a/korman/operators/op_lightmap.py +++ b/korman/operators/op_lightmap.py @@ -15,7 +15,7 @@ import bpy from bpy.props import * -from ..helpers import GoodNeighbor +from ..helpers import * def _fetch_lamp_objects(): for obj in bpy.data.objects: @@ -141,7 +141,7 @@ class LightmapAutobakeOperator(_LightingOperator, bpy.types.Operator): uv_textures.active = uvtex self._associate_image_with_uvtex(uvtex, im) # here we go... - bpy.ops.object.mode_set(mode="EDIT") + enter_edit_mode(obj, toggle) bpy.ops.mesh.select_all(action="SELECT") bpy.ops.uv.average_islands_scale() bpy.ops.uv.pack_islands() @@ -150,10 +150,10 @@ class LightmapAutobakeOperator(_LightingOperator, bpy.types.Operator): # results in my tests. it will be good enough for quick exports. uvtex = uv_textures.new("LIGHTMAPGEN") self._associate_image_with_uvtex(uvtex, im) - bpy.ops.object.mode_set(mode="EDIT") + enter_edit_mode(obj, toggle) bpy.ops.mesh.select_all(action="SELECT") bpy.ops.uv.smart_project() - bpy.ops.object.mode_set(mode="OBJECT") + exit_edit_mode() # Now, set the new LIGHTMAPGEN uv layer as what we want to render to... for i in uv_textures: