glTF: Fix tangent generation for non-blend shapes
PR #30877 was bogus as it made a blend shape-specific code block apply
to everything but blend shapes (as it seemed not to work properly *for*
blend shapes).
The proper fix should thus be to simply remove the problematic
block (and thus cleanup unnecessary logic).
Fixes #32712.
(cherry picked from commit 0034c88c57
)
This commit is contained in:
parent
48bc3fd297
commit
5f5ef98832
|
@ -1070,24 +1070,15 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) {
|
||||||
array[Mesh::ARRAY_INDEX] = indices;
|
array[Mesh::ARRAY_INDEX] = indices;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool generated_tangents = false;
|
bool generate_tangents = (primitive == Mesh::PRIMITIVE_TRIANGLES && !a.has("TANGENT") && a.has("TEXCOORD_0") && a.has("NORMAL"));
|
||||||
Variant erased_indices;
|
|
||||||
|
|
||||||
if (primitive == Mesh::PRIMITIVE_TRIANGLES && !a.has("TANGENT") && a.has("TEXCOORD_0") && a.has("NORMAL")) {
|
if (generate_tangents) {
|
||||||
//must generate mikktspace tangents.. ergh..
|
//must generate mikktspace tangents.. ergh..
|
||||||
Ref<SurfaceTool> st;
|
Ref<SurfaceTool> st;
|
||||||
st.instance();
|
st.instance();
|
||||||
st->create_from_triangle_arrays(array);
|
st->create_from_triangle_arrays(array);
|
||||||
if (!p.has("targets")) {
|
|
||||||
//morph targets should not be reindexed, as array size might differ
|
|
||||||
//removing indices is the best bet here
|
|
||||||
st->deindex();
|
|
||||||
erased_indices = a[Mesh::ARRAY_INDEX];
|
|
||||||
a[Mesh::ARRAY_INDEX] = Variant();
|
|
||||||
}
|
|
||||||
st->generate_tangents();
|
st->generate_tangents();
|
||||||
array = st->commit_to_arrays();
|
array = st->commit_to_arrays();
|
||||||
generated_tangents = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Array morphs;
|
Array morphs;
|
||||||
|
@ -1202,10 +1193,9 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) {
|
||||||
array_copy[Mesh::ARRAY_TANGENT] = tangents_v4;
|
array_copy[Mesh::ARRAY_TANGENT] = tangents_v4;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (generated_tangents) {
|
if (generate_tangents) {
|
||||||
Ref<SurfaceTool> st;
|
Ref<SurfaceTool> st;
|
||||||
st.instance();
|
st.instance();
|
||||||
array_copy[Mesh::ARRAY_INDEX] = erased_indices; //needed for tangent generation, erased by deindex
|
|
||||||
st->create_from_triangle_arrays(array_copy);
|
st->create_from_triangle_arrays(array_copy);
|
||||||
st->deindex();
|
st->deindex();
|
||||||
st->generate_tangents();
|
st->generate_tangents();
|
||||||
|
|
Loading…
Reference in New Issue