Browse Source

Fix even more "no valid image" baking bugs...

pull/6/head
Adam Johnson 10 years ago
parent
commit
6318c3c40c
  1. 15
      korman/exporter/mesh.py
  2. 12
      korman/helpers.py
  3. 29
      korman/operators/op_export.py
  4. 19
      korman/operators/op_lightmap.py

15
korman/exporter/mesh.py

@ -18,6 +18,7 @@ from PyHSPlasma import *
import weakref import weakref
from . import explosions from . import explosions
from .. import helpers
from . import material from . import material
from . import utils from . import utils
@ -293,20 +294,12 @@ class MeshConverter:
return geospans return geospans
def _export_static_lighting(self, bo): def _export_static_lighting(self, bo):
context = {"active_object": bo, helpers.make_active_selection(bo)
"area": bpy.context.area,
"blend_data": bpy.context.blend_data,
"object": bo,
"region": bpy.context.region,
"scene": bpy.context.scene,
"screen": bpy.context.screen,
"window": bpy.context.window}
lm = bo.plasma_modifiers.lightmap lm = bo.plasma_modifiers.lightmap
if lm.enabled: if lm.enabled:
print(" Baking lightmap...") print(" Baking lightmap...")
print("====") print("====")
bpy.ops.object.plasma_lightmap_autobake(context, light_group=lm.light_group) bpy.ops.object.plasma_lightmap_autobake(light_group=lm.light_group)
print("====") print("====")
else: else:
for vcol_layer in bo.data.vertex_colors: for vcol_layer in bo.data.vertex_colors:
@ -315,7 +308,7 @@ class MeshConverter:
break break
else: else:
print(" Baking crappy vertex color lighting...") print(" Baking crappy vertex color lighting...")
bpy.ops.object.plasma_vertexlight_autobake(context) bpy.ops.object.plasma_vertexlight_autobake()
def _find_create_dspan(self, bo, hsgmat, pass_index): def _find_create_dspan(self, bo, hsgmat, pass_index):

12
korman/helpers.py

@ -13,6 +13,8 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Korman. If not, see <http://www.gnu.org/licenses/>. # along with Korman. If not, see <http://www.gnu.org/licenses/>.
import bpy
class GoodNeighbor: class GoodNeighbor:
"""Leave Things the Way You Found Them! (TM)""" """Leave Things the Way You Found Them! (TM)"""
@ -27,3 +29,13 @@ class GoodNeighbor:
def __exit__(self, type, value, traceback): def __exit__(self, type, value, traceback):
for (cls, attr), value in self._tracking.items(): for (cls, attr), value in self._tracking.items():
setattr(cls, attr, value) setattr(cls, attr, value)
def make_active_selection(bo):
"""Selects a single Blender Object and makes it active"""
for i in bpy.data.objects:
if i == bo:
bpy.context.scene.objects.active = i
i.select = True
else:
i.select = False

29
korman/operators/op_export.py

@ -92,14 +92,15 @@ class ExportOperator(bpy.types.Operator):
bpy.ops.object.mode_set(mode="OBJECT") bpy.ops.object.mode_set(mode="OBJECT")
# Separate blender operator and actual export logic for my sanity # Separate blender operator and actual export logic for my sanity
e = exporter.Exporter(self) with _UiHelper() as _ui:
try: e = exporter.Exporter(self)
e.run() try:
except exporter.ExportError as error: e.run()
self.report({"ERROR"}, str(error)) except exporter.ExportError as error:
return {"CANCELLED"} self.report({"ERROR"}, str(error))
else: return {"CANCELLED"}
return {"FINISHED"} else:
return {"FINISHED"}
def invoke(self, context, event): def invoke(self, context, event):
# Called when a user hits "export" from the menu # Called when a user hits "export" from the menu
@ -120,6 +121,18 @@ 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 __enter__(self):
self.active_object = bpy.context.object
self.selected_objects = bpy.context.selected_objects
def __exit__(self, type, value, traceback):
for i in bpy.data.objects:
i.select = (i in self.selected_objects)
bpy.context.scene.objects.active = self.active_object
# 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":

19
korman/operators/op_lightmap.py

@ -108,27 +108,26 @@ class LightmapAutobakeOperator(_LightingOperator, bpy.types.Operator):
# We want to ensure that we use the UV Layer "LIGHTMAPGEN" and fetch the size from # We want to ensure that we use the UV Layer "LIGHTMAPGEN" and fetch the size from
# the lightmap modifier. What fun... # the lightmap modifier. What fun...
mesh = context.active_object.data mesh = context.active_object.data
mesh.update()
# Search for LIGHTMAPGEN # Search for LIGHTMAPGEN
for uvtex in mesh.uv_textures: for i in mesh.uv_textures:
if uvtex.name == "LIGHTMAPGEN": if i.name == "LIGHTMAPGEN":
toggle.track(mesh.uv_textures, "active", uvtex) uvtex = i
toggle.track(uvtex, "active_render", True)
break break
else: else:
toggle.track(uvtex, "active_render", False) toggle.track(i, "active_render", False)
else: else:
# Gotta make it
uvtex = mesh.uv_textures.new("LIGHTMAPGEN") uvtex = mesh.uv_textures.new("LIGHTMAPGEN")
toggle.track(mesh.uv_textures, "active", uvtex) uvtex.active_render = False
toggle.track(uvtex, "active_render", True) toggle.track(mesh.uv_textures, "active", uvtex)
toggle.track(uvtex, "active_render", True)
# Now, enter edit mode on this mesh and unwrap. # Now, enter edit mode on this mesh and unwrap.
bpy.ops.object.mode_set(mode="EDIT") bpy.ops.object.mode_set(mode="EDIT")
bpy.ops.mesh.select_all(action="SELECT") bpy.ops.mesh.select_all(action="SELECT")
bpy.ops.uv.lightmap_pack(PREF_CONTEXT="ALL_FACES", PREF_IMG_PX_SIZE=size) bpy.ops.uv.lightmap_pack(PREF_CONTEXT="ALL_FACES", PREF_IMG_PX_SIZE=size)
bpy.ops.object.mode_set(mode="OBJECT") bpy.ops.object.mode_set(mode="OBJECT")
mesh.update()
# Associate the image with all the new UVs # Associate the image with all the new UVs
# NOTE: no toggle here because it's the artist's problem if they are looking at our # NOTE: no toggle here because it's the artist's problem if they are looking at our
@ -185,7 +184,6 @@ class VertexColorLightingOperator(_LightingOperator, bpy.types.Operator):
def execute(self, context): def execute(self, context):
with GoodNeighbor() as toggle: with GoodNeighbor() as toggle:
mesh = context.active_object.data mesh = context.active_object.data
mesh.update()
# Find the "autocolor" vertex color layer # Find the "autocolor" vertex color layer
autocolor = mesh.vertex_colors.get("autocolor") autocolor = mesh.vertex_colors.get("autocolor")
@ -197,6 +195,7 @@ class VertexColorLightingOperator(_LightingOperator, bpy.types.Operator):
for vcol_layer in mesh.vertex_colors: for vcol_layer in mesh.vertex_colors:
autocol = vcol_layer.name == "autocolor" autocol = vcol_layer.name == "autocolor"
toggle.track(vcol_layer, "active_render", autocol) toggle.track(vcol_layer, "active_render", autocol)
mesh.update()
# Bake settings # Bake settings
render = context.scene.render render = context.scene.render

Loading…
Cancel
Save