summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2020-04-28 20:32:37 +0200
committerGitHub <noreply@github.com>2020-04-28 20:32:37 +0200
commit2497740a4eb70683639f9225e9ac9ecb5e7da52a (patch)
tree8dcc9f0534a43b605fb4e5a11da2f3e07d193c75 /editor
parentabf5132a32bec9d80ce711b22476170fd18edfdc (diff)
parent0034c88c579dc736a6366a957b4107d62e85468b (diff)
Merge pull request #37273 from akien-mga/gltf-tangent-fix-32712
glTF: Fix tangent generation for non-blend shapes
Diffstat (limited to 'editor')
-rw-r--r--editor/import/editor_scene_importer_gltf.cpp16
1 files changed, 3 insertions, 13 deletions
diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp
index 6ad2aa4142..45e376a2aa 100644
--- a/editor/import/editor_scene_importer_gltf.cpp
+++ b/editor/import/editor_scene_importer_gltf.cpp
@@ -1075,24 +1075,15 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) {
array[Mesh::ARRAY_INDEX] = indices;
}
- bool generated_tangents = false;
- Variant erased_indices;
+ bool generate_tangents = (primitive == Mesh::PRIMITIVE_TRIANGLES && !a.has("TANGENT") && a.has("TEXCOORD_0") && a.has("NORMAL"));
- if (primitive == Mesh::PRIMITIVE_TRIANGLES && !a.has("TANGENT") && a.has("TEXCOORD_0") && a.has("NORMAL")) {
+ if (generate_tangents) {
//must generate mikktspace tangents.. ergh..
Ref<SurfaceTool> st;
st.instance();
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();
array = st->commit_to_arrays();
- generated_tangents = true;
}
Array morphs;
@@ -1207,10 +1198,9 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) {
array_copy[Mesh::ARRAY_TANGENT] = tangents_v4;
}
- if (generated_tangents) {
+ if (generate_tangents) {
Ref<SurfaceTool> st;
st.instance();
- array_copy[Mesh::ARRAY_INDEX] = erased_indices; //needed for tangent generation, erased by deindex
st->create_from_triangle_arrays(array_copy);
st->deindex();
st->generate_tangents();