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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion scene/resources/importer_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,7 @@ Error ImporterMesh::lightmap_unwrap_cached(const Transform3D &p_base_transform,
for (int i = 0; i < lightmap_surfaces.size(); i++) {
Ref<SurfaceTool> st;
st.instantiate();
st->set_skin_weight_count((lightmap_surfaces[i].format & Mesh::ARRAY_FLAG_USE_8_BONE_WEIGHTS) ? SurfaceTool::SKIN_8_WEIGHTS : SurfaceTool::SKIN_4_WEIGHTS);
st->begin(Mesh::PRIMITIVE_TRIANGLES);
st->set_material(lightmap_surfaces[i].material);
st->set_meta("name", lightmap_surfaces[i].name);
Expand Down Expand Up @@ -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

if (tool->get_skin_weight_count() == SurfaceTool::SKIN_8_WEIGHTS) {
format |= RS::ARRAY_FLAG_USE_8_BONE_WEIGHTS;
} else {
format &= ~RS::ARRAY_FLAG_USE_8_BONE_WEIGHTS;
}

add_surface(tool->get_primitive_type(), arrays, Array(), Dictionary(), tool->get_material(), tool->get_meta("name"), format);
}

set_lightmap_size_hint(Size2(size_x, size_y));
Expand Down