From 109d10a6fdadeb5735bb4186bd570c2e4ad754c2 Mon Sep 17 00:00:00 2001 From: Mathias Kanzler Date: Mon, 29 Jan 2024 18:00:50 +0100 Subject: [PATCH] Fix handedness of MikkTSpace tangent output --- source/gltf/primitive.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/gltf/primitive.js b/source/gltf/primitive.js index ab093fa2..44fc11fe 100644 --- a/source/gltf/primitive.js +++ b/source/gltf/primitive.js @@ -828,6 +828,11 @@ class gltfPrimitive extends GltfObject const tangents = generateTangents(positions, normals, texcoords); + // convert coordinate system handedness to respect output format of MikkTSpace + for (let idx = 0; idx < tangents.length; idx += 4) { + tangents[idx+3] = -tangents[idx+3] // Flip w-channel + } + // Create a new buffer and buffer view for the tangents: const tangentBuffer = new gltfBuffer(); tangentBuffer.byteLength = tangents.byteLength;