Browse Source

Fix lightmap preview operator devilry

The "Preview Lightmap" operator no longer changes the active selected
objects or the active layer selection.
pull/123/head
Adam Johnson 6 years ago
parent
commit
3e90ac4727
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 30
      korman/helpers.py
  2. 33
      korman/operators/op_export.py
  3. 6
      korman/operators/op_lightmap.py

30
korman/helpers.py

@ -48,6 +48,36 @@ class TemporaryObject:
return getattr(self._obj, attr) return getattr(self._obj, attr)
class UiHelper:
"""This fun little helper makes sure that we don't wreck the UI"""
def __init__(self, context):
self.active_object = context.active_object
self.selected_objects = context.selected_objects
def __enter__(self):
scene = bpy.context.scene
self.layers = tuple(scene.layers)
self.frame_num = scene.frame_current
scene.frame_set(scene.frame_start)
scene.update()
# Some operators require there be an active_object even though they
# don't actually use it...
if scene.objects.active is None:
scene.objects.active = scene.objects[0]
return self
def __exit__(self, type, value, traceback):
for i in bpy.data.objects:
i.select = (i in self.selected_objects)
scene = bpy.context.scene
scene.objects.active = self.active_object
scene.layers = self.layers
scene.frame_set(self.frame_num)
scene.update()
def ensure_power_of_two(value): def ensure_power_of_two(value):
return pow(2, math.floor(math.log(value, 2))) return pow(2, math.floor(math.log(value, 2)))

33
korman/operators/op_export.py

@ -20,6 +20,7 @@ from pathlib import Path
import pstats import pstats
from .. import exporter from .. import exporter
from ..helpers import UiHelper
from ..properties.prop_world import PlasmaAge, game_versions from ..properties.prop_world import PlasmaAge, game_versions
from ..korlib import ConsoleToggler from ..korlib import ConsoleToggler
@ -131,7 +132,7 @@ class ExportOperator(bpy.types.Operator):
# Separate blender operator and actual export logic for my sanity # Separate blender operator and actual export logic for my sanity
ageName = path.stem ageName = path.stem
with _UiHelper(context) as _ui: with UiHelper(context) as _ui:
e = exporter.Exporter(self) e = exporter.Exporter(self)
try: try:
self.export_active = True self.export_active = True
@ -181,36 +182,6 @@ class ExportOperator(bpy.types.Operator):
setattr(PlasmaAge, name, prop(**age_options)) setattr(PlasmaAge, name, prop(**age_options))
class _UiHelper:
"""This fun little helper makes sure that we don't wreck the UI"""
def __init__(self, context):
self.active_object = context.active_object
self.selected_objects = context.selected_objects
def __enter__(self):
scene = bpy.context.scene
self.layers = tuple(scene.layers)
self.frame_num = scene.frame_current
scene.frame_set(scene.frame_start)
scene.update()
# Some operators require there be an active_object even though they
# don't actually use it...
if scene.objects.active is None:
scene.objects.active = scene.objects[0]
return self
def __exit__(self, type, value, traceback):
for i in bpy.data.objects:
i.select = (i in self.selected_objects)
scene = bpy.context.scene
scene.objects.active = self.active_object
scene.layers = self.layers
scene.frame_set(self.frame_num)
scene.update()
# Add the export operator to the Export menu :) # Add the export operator to the Export menu :)
def menu_cb(self, context): def menu_cb(self, context):
if context.scene.render.engine == "PLASMA_GAME": if context.scene.render.engine == "PLASMA_GAME":

6
korman/operators/op_lightmap.py

@ -17,7 +17,7 @@ import bpy
from bpy.props import * from bpy.props import *
from ..exporter.etlight import LightBaker from ..exporter.etlight import LightBaker
from ..helpers import GoodNeighbor from ..helpers import UiHelper
class _LightingOperator: class _LightingOperator:
@ -38,9 +38,7 @@ class LightmapAutobakePreviewOperator(_LightingOperator, bpy.types.Operator):
super().__init__() super().__init__()
def execute(self, context): def execute(self, context):
with GoodNeighbor() as toggle: with UiHelper(context):
toggle.track(context.scene, "layers", tuple(context.scene.layers))
with LightBaker() as bake: with LightBaker() as bake:
if not 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.") self.report({"INFO"}, "No valid lights found to bake.")

Loading…
Cancel
Save