From e63c64e256bc77618e4ea5ab13ecba6306ced0e6 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 3 Jul 2017 10:44:45 -0300 Subject: Clean up normalmapping, make sure tangents are imported correctly. --- editor/import/editor_import_collada.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'editor/import') diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp index e0a2ea624e..7948db3797 100644 --- a/editor/import/editor_import_collada.cpp +++ b/editor/import/editor_import_collada.cpp @@ -908,12 +908,20 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me #ifndef NO_UP_AXIS_SWAP if (collada.state.up_axis == Vector3::AXIS_Z) { + Vector3 bn = vertex.normal.cross(vertex.tangent.normal) * vertex.tangent.d; + SWAP(vertex.vertex.z, vertex.vertex.y); vertex.vertex.z = -vertex.vertex.z; SWAP(vertex.normal.z, vertex.normal.y); vertex.normal.z = -vertex.normal.z; SWAP(vertex.tangent.normal.z, vertex.tangent.normal.y); vertex.tangent.normal.z = -vertex.tangent.normal.z; + SWAP(bn.z, bn.y); + bn.z = -bn.z; + + vertex.tangent.d = vertex.normal.cross(vertex.tangent.normal).dot(bn) > 0 ? 1 : -1; + + print_line("Tangent " + itos(p_i) + ": " + vertex.tangent); } #endif -- cgit v1.2.3