Browse Source

Be more careful about toggling renderability

pull/35/head
Adam Johnson 9 years ago
parent
commit
ffd0e6ed8a
  1. 51
      korman/exporter/etlight.py

51
korman/exporter/etlight.py

@ -28,7 +28,7 @@ class LightBaker:
self._lightgroups = {} self._lightgroups = {}
self._uvtexs = {} self._uvtexs = {}
def _apply_render_settings(self, toggle): def _apply_render_settings(self, toggle, vcols):
render = bpy.context.scene.render render = bpy.context.scene.render
toggle.track(render, "use_textures", False) toggle.track(render, "use_textures", False)
toggle.track(render, "use_shadows", True) toggle.track(render, "use_shadows", True)
@ -36,6 +36,7 @@ class LightBaker:
toggle.track(render, "use_raytrace", True) toggle.track(render, "use_raytrace", True)
toggle.track(render, "bake_type", "FULL") toggle.track(render, "bake_type", "FULL")
toggle.track(render, "use_bake_clear", True) toggle.track(render, "use_bake_clear", True)
toggle.track(render, "use_bake_to_vertex_color", vcols)
def _associate_image_with_uvtex(self, uvtex, im): def _associate_image_with_uvtex(self, uvtex, im):
# Associate the image with all the new UVs # Associate the image with all the new UVs
@ -44,18 +45,20 @@ class LightBaker:
for i in uvtex.data: for i in uvtex.data:
i.image = im i.image = im
def _bake_lightmaps(self, objs, layers, toggle): def _bake_lightmaps(self, objs, layers):
scene = bpy.context.scene with GoodNeighbor() as toggle:
scene.layers = layers scene = bpy.context.scene
toggle.track(scene.render, "use_bake_to_vertex_color", False) scene.layers = layers
self._select_only(objs) self._apply_render_settings(toggle, False)
bpy.ops.object.bake_image() self._select_only(objs, toggle)
bpy.ops.object.bake_image()
def _bake_vcols(self, objs, toggle): def _bake_vcols(self, objs):
bpy.context.scene.layers = (True,) * _NUM_RENDER_LAYERS with GoodNeighbor() as toggle:
toggle.track(bpy.context.scene.render, "use_bake_to_vertex_color", True) bpy.context.scene.layers = (True,) * _NUM_RENDER_LAYERS
self._select_only(objs) self._apply_render_settings(toggle, True)
bpy.ops.object.bake_image() self._select_only(objs, toggle)
bpy.ops.object.bake_image()
def bake_static_lighting(self, objs): def bake_static_lighting(self, objs):
"""Bakes all static lighting for Plasma geometry""" """Bakes all static lighting for Plasma geometry"""
@ -96,17 +99,16 @@ class LightBaker:
print(" ...") print(" ...")
# Step 2: BAKE! # Step 2: BAKE!
self._apply_render_settings(toggle)
for key, value in bake.items(): for key, value in bake.items():
if not value: if not value:
continue continue
if key[0] == "lightmap": if key[0] == "lightmap":
print(" {} Lightmap(s) [H:{:X}]".format(len(value), hash(key))) print(" {} Lightmap(s) [H:{:X}]".format(len(value), hash(key)))
self._bake_lightmaps(value, key[1:], toggle) self._bake_lightmaps(value, key[1:])
elif key[0] == "vcol": elif key[0] == "vcol":
print(" {} Crap Light(s)".format(len(value))) print(" {} Crap Light(s)".format(len(value)))
self._bake_vcols(value, toggle) self._bake_vcols(value)
else: else:
raise RuntimeError(key[0]) raise RuntimeError(key[0])
@ -228,11 +230,8 @@ class LightBaker:
if uvtex is not None: if uvtex is not None:
uv_textures.remove(uvtex) uv_textures.remove(uvtex)
# Make sure the object can be baked to. NOTE this also makes sure we can enter edit mode # Make sure we can enter Edit Mode(TM)
# TROLLING LOL LOL LOL
toggle.track(bo, "hide", False) toggle.track(bo, "hide", False)
toggle.track(bo, "hide_render", False)
toggle.track(bo, "hide_select", False)
# Because the way Blender tracks active UV layers is massively stupid... # Because the way Blender tracks active UV layers is massively stupid...
self._uvtexs[mesh.name] = uv_textures.active.name self._uvtexs[mesh.name] = uv_textures.active.name
@ -285,12 +284,6 @@ class LightBaker:
if not self._generate_lightgroup(mesh): if not self._generate_lightgroup(mesh):
return False return False
# Make sure the object can be baked to. NOTE this also makes sure we can enter edit mode
# TROLLING LOL LOL LOL
toggle.track(bo, "hide", False)
toggle.track(bo, "hide_render", False)
toggle.track(bo, "hide_select", False)
# I have heard tale of some moar "No valid image to bake to" boogs if there is a really # I have heard tale of some moar "No valid image to bake to" boogs if there is a really
# old copy of the autocolor layer on the mesh. Nuke it. # old copy of the autocolor layer on the mesh. Nuke it.
autocolor = vcols.get("autocolor") autocolor = vcols.get("autocolor")
@ -316,13 +309,17 @@ class LightBaker:
i.active = uvtex_name == i.name i.active = uvtex_name == i.name
mesh.uv_textures.active = mesh.uv_textures[uvtex_name] mesh.uv_textures.active = mesh.uv_textures[uvtex_name]
def _select_only(self, objs): def _select_only(self, objs, toggle):
if isinstance(objs, bpy.types.Object): if isinstance(objs, bpy.types.Object):
toggle.track(objs, "hide_render", False)
for i in bpy.data.objects: for i in bpy.data.objects:
i.select = i == objs i.select = i == objs
else: else:
for i in bpy.data.objects: for i in bpy.data.objects:
i.select = i in objs value = i in objs
if value:
toggle.track(i, "hide_render", False)
i.select = value
@persistent @persistent
def _toss_garbage(scene): def _toss_garbage(scene):

Loading…
Cancel
Save