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. 29
      korman/operators/op_lightmap.py

15
korman/exporter/mesh.py

@ -18,6 +18,7 @@ from PyHSPlasma import *
import weakref
from . import explosions
from .. import helpers
from . import material
from . import utils
@ -293,20 +294,12 @@ class MeshConverter:
return geospans
def _export_static_lighting(self, bo):
context = {"active_object": 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}
helpers.make_active_selection(bo)
lm = bo.plasma_modifiers.lightmap
if lm.enabled:
print(" Baking lightmap...")
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("====")
else:
for vcol_layer in bo.data.vertex_colors:
@ -315,7 +308,7 @@ class MeshConverter:
break
else:
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):

12
korman/helpers.py

@ -13,6 +13,8 @@
# You should have received a copy of the GNU General Public License
# along with Korman. If not, see <http://www.gnu.org/licenses/>.
import bpy
class GoodNeighbor:
"""Leave Things the Way You Found Them! (TM)"""
@ -27,3 +29,13 @@ class GoodNeighbor:
def __exit__(self, type, value, traceback):
for (cls, attr), value in self._tracking.items():
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")
# Separate blender operator and actual export logic for my sanity
e = exporter.Exporter(self)
try:
e.run()
except exporter.ExportError as error:
self.report({"ERROR"}, str(error))
return {"CANCELLED"}
else:
return {"FINISHED"}
with _UiHelper() as _ui:
e = exporter.Exporter(self)
try:
e.run()
except exporter.ExportError as error:
self.report({"ERROR"}, str(error))
return {"CANCELLED"}
else:
return {"FINISHED"}
def invoke(self, context, event):
# Called when a user hits "export" from the menu
@ -120,6 +121,18 @@ class ExportOperator(bpy.types.Operator):
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 :)
def menu_cb(self, context):
if context.scene.render.engine == "PLASMA_GAME":

29
korman/operators/op_lightmap.py

@ -103,39 +103,38 @@ class LightmapAutobakeOperator(_LightingOperator, bpy.types.Operator):
im.user_clear()
data_images.remove(im)
im = data_images.new(im_name, width=size, height=size)
# This just wraps Blender's internal lightmap UV whatchacallit...
# We want to ensure that we use the UV Layer "LIGHTMAPGEN" and fetch the size from
# the lightmap modifier. What fun...
mesh = context.active_object.data
mesh.update()
# Search for LIGHTMAPGEN
for uvtex in mesh.uv_textures:
if uvtex.name == "LIGHTMAPGEN":
toggle.track(mesh.uv_textures, "active", uvtex)
toggle.track(uvtex, "active_render", True)
for i in mesh.uv_textures:
if i.name == "LIGHTMAPGEN":
uvtex = i
break
else:
toggle.track(uvtex, "active_render", False)
toggle.track(i, "active_render", False)
else:
# Gotta make it
uvtex = mesh.uv_textures.new("LIGHTMAPGEN")
toggle.track(mesh.uv_textures, "active", uvtex)
toggle.track(uvtex, "active_render", True)
uvtex.active_render = False
toggle.track(mesh.uv_textures, "active", uvtex)
toggle.track(uvtex, "active_render", True)
# Now, enter edit mode on this mesh and unwrap.
bpy.ops.object.mode_set(mode="EDIT")
bpy.ops.mesh.select_all(action="SELECT")
bpy.ops.uv.lightmap_pack(PREF_CONTEXT="ALL_FACES", PREF_IMG_PX_SIZE=size)
bpy.ops.object.mode_set(mode="OBJECT")
mesh.update()
# 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
# super swagalicious LIGHTMAPGEN uvtexture...
for i in mesh.uv_textures.active.data:
i.image = im
# Bake settings
render = context.scene.render
toggle.track(render, "use_bake_to_vertex_color", False)
@ -185,7 +184,6 @@ class VertexColorLightingOperator(_LightingOperator, bpy.types.Operator):
def execute(self, context):
with GoodNeighbor() as toggle:
mesh = context.active_object.data
mesh.update()
# Find the "autocolor" vertex color layer
autocolor = mesh.vertex_colors.get("autocolor")
@ -197,6 +195,7 @@ class VertexColorLightingOperator(_LightingOperator, bpy.types.Operator):
for vcol_layer in mesh.vertex_colors:
autocol = vcol_layer.name == "autocolor"
toggle.track(vcol_layer, "active_render", autocol)
mesh.update()
# Bake settings
render = context.scene.render

Loading…
Cancel
Save