I have a script that duplicates a sourceobject N times, one for each entry in a array, and then scales the UV for that object to 1/n the height, and moves it vertically in the UV map to not have overlapping UVs before joining all duplicated objects.
This have worked great before 3.6, but now all instances get the UV Offset of the last object in the list for some reason. Both 3.6 and 4.0 show the same issue. Can't find anything in the changelog.
Logging the "offset" value shows that each instance gets it's correct offset but it does not seem to apply to the actual object.
Can anyone see any issues or know of why this may not work in 3.6 and above?
for idx, ((x, y, z), (rx, ry, rz)) in enumerate(instance_data_list):
# Duplicate the original source object
bpy.ops.object.duplicate(linked=False)
# The duplicated object becomes the active object
instance = bpy.context.active_object
# Move and rotate the instance
instance.location = (x, y, z)
instance.rotation_euler = (math.radians(rx), math.radians(ry), math.radians(rz))
# Adjust the UV map
uv_layer = instance.data.uv_layers.active
scale_factor = 1.0 / len(instance_data_list)
offset = scale_factor * (len(instance_data_list) - idx - 1)
# Find current min and max UV values for vertical adjustment
min_uv_y = min([uv_data.uv[1] for uv_data in uv_layer.data])
max_uv_y = max([uv_data.uv[1] for uv_data in uv_layer.data])
# Print the results to the console
print("")
print("Minimum UV Y:", min_uv_y)
print("Maximum UV Y:", max_uv_y)
print("Offset: ", offset)
# Adjust the UVs
for uv_data in uv_layer.data:
original_uv_y = uv_data.uv[1] # Store original value for printing
# Normalize the UVs
uv_data.uv[1] = (uv_data.uv[1] - min_uv_y) / (max_uv_y - min_uv_y)
normalized_uv_y = uv_data.uv[1] # Store normalized value for printing
# Apply scale and offset
uv_data.uv[1] = uv_data.uv[1] * scale_factor + offset
# Print before and after values
print(f"Original UV Y: {original_uv_y}, Normalized UV Y: {normalized_uv_y}, Adjusted UV Y: {uv_data.uv[1]}")
instances.append(instance)
instance_data = [
((28.046864, -7.994648, 18.856857), (0, 90, 180)),
((28.046864, -8.994648, 18.856857), (0, 90, 180)),
((28.046864, -9.994648, 18.856857), (0, 90, 180)),
((28.046864, -10.994648, 18.856857), (0, 90, 180)),
((28.046864, -11.994648, 18.856857), (0, 90, 180)),
((28.046864, -12.994648, 18.856857), (0, 90, 180)),
]