-
-
Notifications
You must be signed in to change notification settings - Fork 22k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use UIDs in addition to paths for extracted meshes, materials and animations #100786
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure we are ok to merge this if the other parts are not implemented? There's also a call for all uid code contributors to meetup.
@fire if you think the change is good and just needs the missing pieces implemented, such as animation slices, I will implement the missing parts next week. I just wanted get approval for the overall concept before feature freeze. |
It makes sense that uid works everywhere. |
Thanks for the PR, I was having this exact issue. However, I noticed if I select an external material under mesh import in the UI, the res:// path is shown but the uid:// path is saved in the .import file. You mentioned that "the UID path isn't obvious and readable" and got confused when the engine deals with this issue |
Fixes #95637 The path import option can currently be set not only in What I'm thinking is that a user wouldn't really need to change the path after it was set, they would just move the extracted file in the filesystem instead. This could justify something like, instead of introducing a new uid import option, store the uid in the currently existing path import option and use |
I tested this with simple cube and somehow ended up with this which is related to this issue: #101256 I think it's caused by EditorPropertyPath automatically converting paths to UID. Not sure if there is a way to disable this behavior, but I think splitting between path and uid makes sense. It just has to work properly. |
Would be good to rebase and test again as #101256 was fixed. |
The path and uid are now stored correctly. |
Please check how this is done for the translations: Since the path can change, the most reliable way to do this is using the UID of the parent resource, which is supplied as argument on the ::import call. |
So from looking into this, my understanding is @reduz PRs #97912 and #97363 address a lot of the issues that this PR was designed for. Here are some of the things I am still thinking about: one of the things I am considering changing is to keep status quo with path = "uid://" (or res:// for compatibility) and put the file path into a property called "fallback_path" only to be used when the uid does not exist. That would make this PR smaller and less dangerous compared to beta, since it is only fixing the case where you have extracted files and the referenced file was deleted. the other question I had is when is it appropriate to modify the .import settings, for example if a referenced file is moved. If we call it fallback_path... let's say the user extracts a material to "res://models/materials/red.material" and then moves it to "res://global/red.material". Should the fallback_path be updated to the new path next time it is imported. Then if the user deletes global/red.material and the gltf is reimported, what should happen? Finally, we need to make sure all places that extract resources are updated to use uid:// at the time they perform the extraction (for example in the adv import dialog), and I should test if animation slices work) |
af4fba3
to
7264a77
Compare
I have changed the design and want to get consensus.
Pushed a new version of this change. I updated the original comment to explain what the PR is now doing, but I wanted to have this ready for the core meeting. My goal is to have a minimal change. This does not change anything to users who use res:// paths in .import, and it does not change anything for users who use valid uid:// paths in .import. During import, this PR should only impact cases when a uid:// path in .import is missing. This PR also implements UID paths when the user selects a new directory to extract meshes, textures and materials, so in other words, it means that this code may also affect newly imported assets. |
7264a77
to
8f95cec
Compare
I duplicated a GLB file and extracted mesh, but it saved as regular path for I think the general idea is fine. |
55b30de
to
bba2f1b
Compare
@KoBeWi I got this change working for meshes, materials and animations. I have been doing some tests on the fox gltf (which has animations, a mesh and a material) and so far I'm pretty satisfied with it. It feels nice and transparent to the user, since the file pickers only show the res:// path. I tested renames, even in cases where Godot doesn't update the res:// path, and it seems to be able to locate the file fine using the uid:// Some known issues:
a. it rewrites the file again, so it now means all meshes and animations are being written twice. b. the temporary uid is saved to uid_cache.bin first, which causes other places that reference the extracted meshes to use the temporary uid, even though the .tres file itself has a different UID. It's very confusing and while I haven't run into a bug with this, it feels wrong and jank. I think the fix requires modifying ResourceSaver to allow passing a UID into save(), which will turn into a bigger change. |
ERR_FAIL_COND_V_MSG(err != OK, anim, "Saving of animation failed: " + res_path); | ||
if (p_save_to_path.begins_with("uid://")) { | ||
// slow | ||
ResourceSaver::set_uid(res_path, ResourceUID::get_singleton()->text_to_id(p_save_to_path)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mentioned before, this is very undesired because if you move or rename the original scene, the uids for the external files will be changed.
Check the translation importer on how to generate uids for generated resources resulting from import.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have made the change for Mesh and Animation to use hash for UID generation.
(Note: The hash generation in CSV Translation had a bug that was causing uid conflicts and uid://, which I opted to fix in this PR. Let me know if the translation fixes should be a separate PR)
For Material, it is common for people to use other Material objects, switch to ShaderMaterial, or share materials between models. I think randomly generated UID makes more sense for this workflow because they are not overwritten on each import.
561f3c8
to
4f171de
Compare
4f171de
to
9947b36
Compare
9947b36
to
1af46e9
Compare
2ab19fd
to
4a0937e
Compare
4a0937e
to
c9f5084
Compare
I tested that it works (as much as I'm familiar with model import at least). |
c9f5084
to
423b693
Compare
When extracting meshes, materials and animations, always store the uid:// path as well as a res:// fallback. When validating import settings, load the fallback path if the uid:// path fails to load. Update save_to_file/fallback_path every import to keep the file path in sync with the uid. Use UID hashing for meshes and animations.
423b693
to
8997c99
Compare
Thanks! |
Related? #74612 |
Fixes #68672
edit 2025-02-12: rewrote this PR from scratch.
edit 2025-02-16: migrate existing UIDs, use hash function to derive consistent UIDs for meshes and animations.
This doesn't necessarily fix a bug, but this is trying to migrate more things to support UIDs. In this case, the extracted file paths for meshes and animations did not support UID, so if the paths were renamed it was possible for the import to fail.
Similarly, renaming materials could cause them to get lost between imports. This change will keep the uid updated so that the material can be referenced even after it is renamed.
This PR adds
use_external/fallback_path
andsave_to_file/fallback_path
to the existinguse_external/path
andsave_to_file/path
properties. These properties already use the ResourceUID::ensure_path() function which means they support UIDs already. The main change is to handle the case where the UID lookup fails (is_empty()) and to regenerate the UID from the fallback path.Additionally, refresh
fallback_path
properties on every import to ensure that the path is kept up to date.Finally, this changes Material, Mesh and Animation extraction buttons in the SceneImportSettings dialog to generate UIDs and assign the fallback_path initially.
Also, fix a bug in CSV translations related to UID hashing (as this was the only other place in the code which used a hash function to construct a UID, but did so incorrectly (allowing negative numbers) and without checking for collision.