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 Aug 6, 2024
1 parent 93db353 commit 15ebcb1
Showing 1 changed file with 7 additions and 3 deletions.
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 15ebcb1

Please sign in to comment.