Browse Source

Update LM preview to apply modifiers as well

pull/75/head
Adam Johnson 7 years ago
parent
commit
f6182b05b5
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 2
      korman/exporter/convert.py
  2. 11
      korman/exporter/etlight.py
  3. 22
      korman/exporter/mesh.py
  4. 8
      korman/operators/op_lightmap.py

2
korman/exporter/convert.py

@ -54,7 +54,7 @@ class Exporter:
self.sumfile = sumfile.SumFile()
# Step 0.8: Init the progress mgr
self.report.progress_add_step("Applying Blender Mods")
self.mesh.add_progress_presteps(self.report)
self.report.progress_add_step("Collecting Objects")
self.report.progress_add_step("Harvesting Actors")
if self._op.bake_lighting:

11
korman/exporter/etlight.py

@ -17,24 +17,25 @@ import bpy
from bpy.app.handlers import persistent
from .logger import ExportProgressLogger
from .mesh import _VERTEX_COLOR_LAYERS
from .mesh import _MeshManager, _VERTEX_COLOR_LAYERS
from ..helpers import *
_NUM_RENDER_LAYERS = 20
class LightBaker:
class LightBaker(_MeshManager):
"""ExportTime Lighting"""
def __init__(self, report=None):
self._lightgroups = {}
if report is None:
self._report = ExportProgressLogger()
self.add_progress_steps(self._report)
self.add_progress_steps(self._report, True)
self._report.progress_start("PREVIEWING LIGHTING")
self._own_report = True
else:
self._report = report
self._own_report = False
super().__init__(self._report)
self._uvtexs = {}
def __del__(self):
@ -42,7 +43,9 @@ class LightBaker:
self._report.progress_end()
@staticmethod
def add_progress_steps(report):
def add_progress_steps(report, add_base=False):
if add_base:
_MeshManager.add_progress_presteps(report)
report.progress_add_step("Searching for Bahro")
report.progress_add_step("Baking Static Lighting")

22
korman/exporter/mesh.py

@ -18,6 +18,7 @@ from PyHSPlasma import *
from math import fabs
import weakref
from ..exporter.logger import ExportProgressLogger
from . import explosions
from .. import helpers
from . import material
@ -113,14 +114,18 @@ class _GeoData:
class _MeshManager:
def __init__(self, exporter):
self._exporter = weakref.ref(exporter)
def __init__(self, report=None):
if report is not None:
self._report = report
self._mesh_overrides = {}
@staticmethod
def add_progress_presteps(report):
report.progress_add_step("Applying Blender Mods")
def __enter__(self):
report = self._exporter().report
report.progress_advance()
report.progress_range = len(bpy.data.objects)
self._report.progress_advance()
self._report.progress_range = len(bpy.data.objects)
# Some modifiers like "Array" will procedurally generate new geometry that will impact
# lightmap generation. The Blender Internal renderer does not seem to be smart enough to
@ -133,7 +138,7 @@ class _MeshManager:
# happen because Blender's memory management SUCKS!
self._mesh_overrides[i.name] = i.data.name
i.data = i.to_mesh(scene, True, "RENDER", calc_tessface=False)
report.progress_increment()
self._report.progress_increment()
return self
def __exit__(self, type, value, traceback):
@ -146,12 +151,15 @@ class _MeshManager:
class MeshConverter(_MeshManager):
def __init__(self, exporter):
super().__init__(exporter)
self._exporter = weakref.ref(exporter)
self.material = material.MaterialConverter(exporter)
self._dspans = {}
self._mesh_geospans = {}
# _report is a property on this subclass
super().__init__()
def _calc_num_uvchans(self, bo, mesh):
max_user_texs = plGeometrySpan.kUVCountMask
num_user_texs = len(mesh.tessface_uv_textures)

8
korman/operators/op_lightmap.py

@ -39,10 +39,10 @@ class LightmapAutobakePreviewOperator(_LightingOperator, bpy.types.Operator):
with GoodNeighbor() as toggle:
toggle.track(context.scene, "layers", tuple(context.scene.layers))
bake = LightBaker()
if not bake.bake_static_lighting([context.active_object,]):
self.report({"INFO"}, "No valid lights found to bake.")
return {"FINISHED"}
with LightBaker() as bake:
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:

Loading…
Cancel
Save