Skip to content

Commit

Permalink
Fix: Re-ordering the UV maps to have the lightmap on slot 1 works cor…
Browse files Browse the repository at this point in the history
…rectly now. The UV map in the last slow now gets the correct name as well
  • Loading branch information
GottfriedHofmann committed Jan 29, 2025
1 parent c90e25d commit 7f7ad7c
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions addons/io_hubs_addon/components/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,11 +707,17 @@ def create_uv_layouts(self, context, mesh_objs):
# Check if object has a second UV layer. If it is named LIGHTMAP_LAYER_NAME, assume it is used for the lightmap.
# Otherwise add a new UV layer LIGHTMAP_LAYER_NAME and place it second in the slot list.
elif obj_uv_layers[1].name != LIGHTMAP_LAYER_NAME:
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.")
obj_uv_layers.new(name=LIGHTMAP_LAYER_NAME)
# The new layer is the last in the list, swap it for position 1
obj_uv_layers[1], obj_uv_layers[-1] = obj_uv_layers[-1], obj_uv_layers[1]

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.")
# The new layer is the last in the list and a full copy of the active one.
# The changed order is no problem in Blender where UV layers are mostly indexed by name
# Only when exporting to game engines the order matters, but most game engines have the lightmap on UV layer 1
# Blender is creating the names of duplicated layers with a suffix .001
# This needs to be avoided because otherwise existing setups cannot access it anymore
second_layer_name = obj_uv_layers[1].name
obj_uv_layers[1].name=LIGHTMAP_LAYER_NAME
obj_uv_layers.active = obj_uv_layers[1]
obj_uv_layers.new(name=second_layer_name)

# The layer for the lightmap needs to be the active one before lightmap packing
obj_uv_layers.active = obj_uv_layers[LIGHTMAP_LAYER_NAME]
# Set the object as selected in object mode
Expand Down

1 comment on commit 7f7ad7c

@DougReeder
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I haven't worked with the exporter.

Please sign in to comment.