Skip to content
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

Fix ImporterMesh bone weight handling during lightmap unwrap #81854

Merged
merged 1 commit into from
Sep 21, 2023

Conversation

bitsawer
Copy link
Member

@bitsawer bitsawer commented Sep 18, 2023

When unwrapping surfaces for lightmaps we need to update the format flag depending on if we use 0, 4 or 8 influences. Previously this was not done and afterwards the code read invalid memory in some cases (for example seeing invalid bone indices like 545021568 in the bug report).

After this patch, the cube import works. The cube does look pretty busted, but as it is just a test model it might be intentional and bones still seem to affect it correctly when moved. And removing the skeleton influence makes it look like a normal cube. I don't have access to the original model, so @QbieShay might be able to test this more.

Also, I spotted another weird thing with the test project. Simply repeatedly selecting between the Cube mesh node and then another node causes errors and the top UI toolbar keeps growing and adds what looks like a vertical separator every time you do this:

Attempt to disconnect a nonexistent connection from 'test2:<Node3D#1869871115769>'. Signal: 'replacing_by', callable: 'EditorNode::set_edited_scene'.
editor\plugins\node_3d_editor_plugin.cpp:7693 - Condition "p_control->get_parent() != context_toolbar_hbox" is true.
editor\plugins\node_3d_editor_plugin.cpp:7693 - Condition "p_control->get_parent() != context_toolbar_hbox" is true.
editor\plugins\node_3d_editor_plugin.cpp:7693 - Condition "p_control->get_parent() != context_toolbar_hbox" is true.

bug

@bitsawer bitsawer added this to the 4.2 milestone Sep 18, 2023
@@ -1292,7 +1293,15 @@ Error ImporterMesh::lightmap_unwrap_cached(const Transform3D &p_base_transform,
Ref<SurfaceTool> &tool = surfaces_tools[i];
tool->index();
Array arrays = tool->commit_to_arrays();
add_surface(tool->get_primitive_type(), arrays, Array(), Dictionary(), tool->get_material(), tool->get_meta("name"), lightmap_surfaces[i].format);

uint64_t format = lightmap_surfaces[i].format;
Copy link
Member Author

Choose a reason for hiding this comment

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

I made this uint64_t instead of uint32_t as future proofing for #81138

@bitsawer bitsawer requested a review from a team September 18, 2023 16:13
Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

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

Looks great! Tested locally and it appears to work.

I get the same janky cube that you get, but when moving bones around it deforms in a way that seems right.

@clayjohn clayjohn added the cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release label Sep 21, 2023
@akien-mga akien-mga merged commit 44ea5f9 into godotengine:master Sep 21, 2023
15 checks passed
@akien-mga
Copy link
Member

Thanks!

@bitsawer bitsawer deleted the fix_importer_mesh_bones branch September 21, 2023 17:57
@YuriSizov
Copy link
Contributor

Cherry-picked for 4.1.3.

@YuriSizov YuriSizov removed the cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release label Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lightmap UV generation on rigged FBX files causes the mesh to disappear
4 participants