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

gltf: Allow more than 4 joints but warn and ignore them. #61912

Merged
merged 1 commit into from
Jun 11, 2022
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
13 changes: 9 additions & 4 deletions modules/gltf/gltf_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2620,6 +2620,7 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> state) {
return OK;
}

bool has_warned = false;
Array meshes = state->json["meshes"];
for (GLTFMeshIndex i = 0; i < meshes.size(); i++) {
print_verbose("glTF: Parsing mesh: " + itos(i));
Expand Down Expand Up @@ -2692,11 +2693,16 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> state) {
array[Mesh::ARRAY_COLOR] = _decode_accessor_as_color(state, a["COLOR_0"], true);
has_vertex_color = true;
}
if (a.has("JOINTS_0") && !a.has("JOINTS_1")) {
if (a.has("JOINTS_0")) {
array[Mesh::ARRAY_BONES] = _decode_accessor_as_ints(state, a["JOINTS_0"], true);
}
ERR_CONTINUE(a.has("JOINTS_0") && a.has("JOINTS_1"));
if (a.has("WEIGHTS_0") && !a.has("WEIGHTS_1")) {
if (a.has("WEIGHTS_1") && a.has("JOINTS_1")) {
if (!has_warned) {
WARN_PRINT("glTF: Meshes use more than 4 bone joints");
Copy link
Member

Choose a reason for hiding this comment

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

Need testing, but WARN_PRINT_ONCE should do what you're reimplementing with the bool.

Copy link
Member

Choose a reason for hiding this comment

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

It might not work as "once per file" though, so this approach might be best.

has_warned = true;
}
}
if (a.has("WEIGHTS_0")) {
Vector<float> weights = _decode_accessor_as_floats(state, a["WEIGHTS_0"], true);
{ //gltf does not seem to normalize the weights for some reason..
int wc = weights.size();
Expand All @@ -2718,7 +2724,6 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> state) {
}
array[Mesh::ARRAY_WEIGHTS] = weights;
}
ERR_CONTINUE(a.has("WEIGHTS_0") && a.has("WEIGHTS_1"));

if (p.has("indices")) {
Vector<int> indices = _decode_accessor_as_ints(state, p["indices"], false);
Expand Down