Skip to content

Fix import for unused animation slice information. #95538

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GustJc
Copy link
Contributor

@GustJc GustJc commented Aug 15, 2024

Fixes #68936

Problem brief: The gltf importer would import 256 slice information for each animation if a single animation option was changed. Making the .import file unnecessarily big.

This makes the gltf importer only save slice data default values for slices created by the user.
This won't fix imported assets that have already been bloated. But it won't create bloat on new imported assets.


This is my first time with Godot source so I chose this simple approach first to see if it works. It did.

Maybe a better way to solve this is to avoid creating the 256 ImportOptions in the first place here

for (int i = 0; i < 256; i++) {
r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "slice_" + itos(i + 1) + "/name"), ""));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "slice_" + itos(i + 1) + "/start_frame"), 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "slice_" + itos(i + 1) + "/end_frame"), 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "slice_" + itos(i + 1) + "/loop_mode", PROPERTY_HINT_ENUM, "None,Linear,Pingpong"), 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "slice_" + itos(i + 1) + "/save_to_file/enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), false));
r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "slice_" + itos(i + 1) + "/save_to_file/path", PROPERTY_HINT_SAVE_FILE, ".res,*.tres"), ""));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "slice_" + itos(i + 1) + "/save_to_file/keep_custom_tracks"), false));
}

This is created when the import settings window is loaded, and it will always create those 256 slice default data.
But as they are all the same anyways, maybe its better to just load something like "slice_data" and use a similar strategy, where I checked for the slice_amount to decide if the slice default values needs to be filled or not.
Inside both the post_fix_node and post_fix_animation where we have that value.

@lyuma
Copy link
Contributor

lyuma commented Aug 15, 2024

Hmm I see what you're doing and it could work... basically it stops checking for slices (sets has_slices to false) at 1 + slice count.

It does feel a little hacky, and I would prefer if the underlying cause could somehow be addressed directly without having to make this loop kore complicated.

but honestly if it comes time for 4.4 or a 4.3 bugfix release and there isn't a better fix, I could go for this. I don't think it should cause any issues.

@AThousandShips AThousandShips changed the title Fix import for unused animation slice information. For #68936 Fix import for unused animation slice information. Aug 15, 2024
@AThousandShips AThousandShips added bug topic:import high priority topic:animation topic:3d performance cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release labels Aug 15, 2024
@AThousandShips AThousandShips added this to the 4.4 milestone Aug 15, 2024
@GustJc GustJc force-pushed the fix_import_unused_slide_data branch from 7f41c23 to 6959333 Compare August 15, 2024 15:59
@GustJc
Copy link
Contributor Author

GustJc commented Aug 15, 2024

It does feel a little hacky, and I would prefer if the underlying cause could somehow be addressed directly without having to make this loop kore complicated.

but honestly if it comes time for 4.4 or a 4.3 bugfix release and there isn't a better fix, I could go for this. I don't think it should cause any issues.

Glad to hear that. I'm still getting familiarized with Godot's code so I'm a bit unsure about bigger changes.
PS: I just got my clang-formater working and forced push the formatting changes.


I took a closer look how the import scene worked.
It uses those 256 default values to pass to its InspectorEditor with inspector->edit(scene_import_settings_data); at scene_import_settings.cpp:L952.
Which automatically creates the inspector for all the slice data values, and the resource_importer_scene.cpp uses their parameter paths and the slice_amount to check if they should be visible or not.
Essentially, the slice_data slots are all create only once when you select the animation node in the tree(at _select():L788).
And changing the slice_amount just changes its visibility.

To fix the root of this problem we'd need to change the behavior of creating all of the slice_data slots at once, and procedurally add or remove them only when the slice amount is changed.
But that's a big change for me right now, not really sure what breaks what yet.

I'll leave this PR open in case this can be accepted, but feel free to close it and implement a better solution if anyone wants to.

@GustJc GustJc marked this pull request as ready for review August 18, 2024 04:40
@GustJc GustJc requested a review from a team as a code owner August 18, 2024 04:40
Copy link
Contributor

@lyuma lyuma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do like how short this approach is, and it does solve an issue. That said, I'm a bit concerned that it is technically a hack. But seeing as the code immediately before this also has a bunch of special casing for animation slices, I guess it's okay.

What do others think?

@jitspoe
Copy link
Contributor

jitspoe commented Jan 23, 2025

Seems less hacky than having hundreds of unset settings stored in the .import file for every animation. :)

It'd be nice to get this in sooner rather than later to avoid file bloat.

@Repiteo Repiteo added the cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release label Feb 24, 2025
@Repiteo Repiteo modified the milestones: 4.4, 4.5 Feb 24, 2025
@akien-mga akien-mga removed the cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release label Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release high priority performance topic:animation topic:import topic:3d
Projects
Status: Ready for review
Development

Successfully merging this pull request may close these issues.

glTF .import files include slice information for 256 slices, if any animation options are set
6 participants