Skip to content

Commit

Permalink
Account for library when gathering image URI
Browse files Browse the repository at this point in the history
When a material with a relative path to an image is linked from another
.blend file, that path should be relative to that .blend file instead of
relative to the current file.
  • Loading branch information
etacarinaea committed Sep 1, 2024
1 parent 295bbf7 commit 136d910
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions addons/io_scene_gltf2/blender/exp/material/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ def gather_image(
uri, factor_uri = __gather_uri(image_data, mime_type, name, export_settings)
else:
# Retrieve URI relative to exported glTF files
uri = __gather_original_uri(image_data.original.filepath, export_settings)
uri = __gather_original_uri(
image_data.original.filepath,
blender_shader_sockets[0].socket.id_data.library,
export_settings
)
# In case we can't retrieve image (for example packed images, with original moved)
# We don't create invalid image without uri
factor_uri = None
Expand All @@ -81,9 +85,9 @@ def gather_image(
# We also return image_data, as it can be used to generate same file with another extension for WebP management
return image, image_data, factor, None

def __gather_original_uri(original_uri, export_settings):
def __gather_original_uri(original_uri, library, export_settings):
path_to_image = bpy.path.abspath(original_uri, library=library)

path_to_image = bpy.path.abspath(original_uri)
if not os.path.exists(path_to_image): return None
try:
rel_path = os.path.relpath(
Expand Down

0 comments on commit 136d910

Please sign in to comment.