Skip to content

Commit 7f7ad7c

Browse files
Fix: Re-ordering the UV maps to have the lightmap on slot 1 works correctly now. The UV map in the last slow now gets the correct name as well
1 parent c90e25d commit 7f7ad7c

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

addons/io_hubs_addon/components/operators.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -707,11 +707,17 @@ def create_uv_layouts(self, context, mesh_objs):
707707
# Check if object has a second UV layer. If it is named LIGHTMAP_LAYER_NAME, assume it is used for the lightmap.
708708
# Otherwise add a new UV layer LIGHTMAP_LAYER_NAME and place it second in the slot list.
709709
elif obj_uv_layers[1].name != LIGHTMAP_LAYER_NAME:
710-
print("The second UV layer in hubs should be named " + LIGHTMAP_LAYER_NAME + " and is reserved for the lightmap, all the layers >1 are ignored.")
711-
obj_uv_layers.new(name=LIGHTMAP_LAYER_NAME)
712-
# The new layer is the last in the list, swap it for position 1
713-
obj_uv_layers[1], obj_uv_layers[-1] = obj_uv_layers[-1], obj_uv_layers[1]
714-
710+
print("The second UV layer " + str(obj_uv_layers[1].name) + " of object " + str(obj.name) + " should be named " + LIGHTMAP_LAYER_NAME + " for Hubs and is reserved for the lightmap, all the layers >1 are ignored.")
711+
# The new layer is the last in the list and a full copy of the active one.
712+
# The changed order is no problem in Blender where UV layers are mostly indexed by name
713+
# Only when exporting to game engines the order matters, but most game engines have the lightmap on UV layer 1
714+
# Blender is creating the names of duplicated layers with a suffix .001
715+
# This needs to be avoided because otherwise existing setups cannot access it anymore
716+
second_layer_name = obj_uv_layers[1].name
717+
obj_uv_layers[1].name=LIGHTMAP_LAYER_NAME
718+
obj_uv_layers.active = obj_uv_layers[1]
719+
obj_uv_layers.new(name=second_layer_name)
720+
715721
# The layer for the lightmap needs to be the active one before lightmap packing
716722
obj_uv_layers.active = obj_uv_layers[LIGHTMAP_LAYER_NAME]
717723
# Set the object as selected in object mode

0 commit comments

Comments
 (0)