|
|
@ -15,7 +15,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
import bpy |
|
|
|
import bpy |
|
|
|
|
|
|
|
|
|
|
|
from contextlib import ExitStack |
|
|
|
from contextlib import contextmanager |
|
|
|
import itertools |
|
|
|
import itertools |
|
|
|
|
|
|
|
|
|
|
|
from .explosions import * |
|
|
|
from .explosions import * |
|
|
@ -375,6 +375,8 @@ class LightBaker(_MeshManager): |
|
|
|
# this tended to create sharp edges. There was already a discussion about this on the |
|
|
|
# this tended to create sharp edges. There was already a discussion about this on the |
|
|
|
# Guild of Writers forum, so I'm implementing a code version of dendwaler's process, |
|
|
|
# Guild of Writers forum, so I'm implementing a code version of dendwaler's process, |
|
|
|
# as detailed here: https://forum.guildofwriters.org/viewtopic.php?p=62572#p62572 |
|
|
|
# as detailed here: https://forum.guildofwriters.org/viewtopic.php?p=62572#p62572 |
|
|
|
|
|
|
|
# This has been amended with Sirius's observations in GH-265 about forced uv map |
|
|
|
|
|
|
|
# packing. Namely, don't do it unless modifiers make us. |
|
|
|
uv_base = self._get_lightmap_uvtex(mesh, modifier) |
|
|
|
uv_base = self._get_lightmap_uvtex(mesh, modifier) |
|
|
|
if uv_base is not None: |
|
|
|
if uv_base is not None: |
|
|
|
uv_textures.active = uv_base |
|
|
|
uv_textures.active = uv_base |
|
|
@ -384,25 +386,25 @@ class LightBaker(_MeshManager): |
|
|
|
uv_textures.active = uvtex |
|
|
|
uv_textures.active = uvtex |
|
|
|
|
|
|
|
|
|
|
|
# if the artist hid any UVs, they will not be baked to... fix this now |
|
|
|
# if the artist hid any UVs, they will not be baked to... fix this now |
|
|
|
bpy.ops.object.mode_set(mode="EDIT") |
|
|
|
with self._set_mode("EDIT"): |
|
|
|
bpy.ops.uv.reveal() |
|
|
|
bpy.ops.uv.reveal() |
|
|
|
bpy.ops.object.mode_set(mode="OBJECT") |
|
|
|
|
|
|
|
self._associate_image_with_uvtex(uv_textures.active, im) |
|
|
|
self._associate_image_with_uvtex(uv_textures.active, im) |
|
|
|
bpy.ops.object.mode_set(mode="EDIT") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# prep the uvtex for lightmapping |
|
|
|
# Meshes with modifiers need to have islands packed to prevent generated vertices |
|
|
|
|
|
|
|
# from sharing UVs. Sigh. |
|
|
|
|
|
|
|
if self.is_collapsed(bo): |
|
|
|
|
|
|
|
self._report.warn("'{}': packing islands in UV Texture '{}' due to modifier collapse", bo.name, uv_base.name) |
|
|
|
|
|
|
|
with self._set_mode("EDIT"): |
|
|
|
bpy.ops.mesh.select_all(action="SELECT") |
|
|
|
bpy.ops.mesh.select_all(action="SELECT") |
|
|
|
bpy.ops.uv.average_islands_scale() |
|
|
|
|
|
|
|
bpy.ops.uv.pack_islands() |
|
|
|
bpy.ops.uv.pack_islands() |
|
|
|
else: |
|
|
|
else: |
|
|
|
# same thread, see Sirius's suggestion RE smart unwrap. this seems to yield good |
|
|
|
# same thread, see Sirius's suggestion RE smart unwrap. this seems to yield good |
|
|
|
# results in my tests. it will be good enough for quick exports. |
|
|
|
# results in my tests. it will be good enough for quick exports. |
|
|
|
uvtex = uv_textures.new(self.lightmap_uvtex_name) |
|
|
|
uvtex = uv_textures.new(self.lightmap_uvtex_name) |
|
|
|
self._associate_image_with_uvtex(uvtex, im) |
|
|
|
self._associate_image_with_uvtex(uvtex, im) |
|
|
|
bpy.ops.object.mode_set(mode="EDIT") |
|
|
|
with self._set_mode("EDIT"): |
|
|
|
bpy.ops.mesh.select_all(action="SELECT") |
|
|
|
bpy.ops.mesh.select_all(action="SELECT") |
|
|
|
bpy.ops.uv.smart_project() |
|
|
|
bpy.ops.uv.smart_project(island_margin=0.05) |
|
|
|
bpy.ops.object.mode_set(mode="OBJECT") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Now, set the new LIGHTMAPGEN uv layer as what we want to render to... |
|
|
|
# Now, set the new LIGHTMAPGEN uv layer as what we want to render to... |
|
|
|
# NOTE that this will need to be reset by us to what the user had previously |
|
|
|
# NOTE that this will need to be reset by us to what the user had previously |
|
|
@ -490,3 +492,11 @@ class LightBaker(_MeshManager): |
|
|
|
elif isinstance(i.data, bpy.types.Mesh) and not self._has_valid_material(i): |
|
|
|
elif isinstance(i.data, bpy.types.Mesh) and not self._has_valid_material(i): |
|
|
|
toggle.track(i, "hide_render", True) |
|
|
|
toggle.track(i, "hide_render", True) |
|
|
|
i.select = value |
|
|
|
i.select = value |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@contextmanager |
|
|
|
|
|
|
|
def _set_mode(self, mode): |
|
|
|
|
|
|
|
bpy.ops.object.mode_set(mode=mode) |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
yield |
|
|
|
|
|
|
|
finally: |
|
|
|
|
|
|
|
bpy.ops.object.mode_set(mode="OBJECT") |
|
|
|