KhronosGroup / glTF-Blender-IO

Blender glTF 2.0 importer and exporter
https://docs.blender.org/manual/en/latest/addons/import_export/scene_gltf2.html
Apache License 2.0
1.48k stars 317 forks source link

Account for library when gathering image URI #2304

Closed etacarinaea closed 2 weeks ago

etacarinaea commented 1 month ago

When exporting a scene that has linked objects with materials that have relative paths to images, the absolute path of those images was being determined by taking that path relative to the current scene's path, instead of relative to the original path of the library, which would result in the images not being found if the current scene and the library weren't in the same directory. This PR fixes that.

julienduroure commented 1 month ago

Thanks for the PR I will have a look soon

julienduroure commented 1 month ago

Some files are now renamed in main branch. Can you please rebase your PR? Thanks :)

julienduroure commented 2 weeks ago

Hello, With this setup (photo.blend is linked into scene.blend), exporting scene.blend to scene.glb or scene.gltf => I am not able to reproduce the issue on main branch.

image

Can you please create a zip with right setup of directory that shows the issue?

etacarinaea commented 2 weeks ago

Here's the zip: gltf-blender-io_library-uri_test.zip

.
├── assets
│   ├── asset.bin
│   ├── asset.blend
│   └── asset.gltf
├── img
│   └── test.png
├── test.bin
├── test.blend
└── test.gltf

I think I forgot to mention that this only seems to happen when "keep original" is checked while exporting as a gltf. The zip includes the resulting gltf files from exporting the original scene (asset.blend) and the scene with the object linked (test.blend). The gltf of the original one correctly includes the image path, the one with the linked object doesn't.

Output from git diff -- test.gltf assets/asset.gltf:

@@ -44,6 +47,19 @@
                        ]
                }
        ],
+       "textures":[
+               {
+                       "sampler":0,
+                       "source":0
+               }
+       ],
+       "images":[
+               {
+                       "mimeType":"image/png",
+                       "name":"test.png",
+                       "uri":"../img/test.png"
+               }
+       ],
        "accessors":[
                {
                        "bufferView":0,
julienduroure commented 2 weeks ago

when "keep original" is checked

It was the missing part! Thanks :)

julienduroure commented 2 weeks ago

Merged, thanks!