Browse Source

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*
pull/8/head
Adam Johnson 10 years ago
parent
commit
b412e444dd
  1. 11
      korman/helpers.py
  2. 8
      korman/operators/op_lightmap.py

11
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:

8
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:

Loading…
Cancel
Save