Skip to content

Commit ff2d509

Browse files
authored
SkinningNode: Fix tangent transformation. (#32718)
1 parent b3bdd22 commit ff2d509

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/nodes/accessors/SkinningNode.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,14 @@ class SkinningNode extends Node {
146146
}
147147

148148
/**
149-
* Transforms the given vertex normal via skinning.
149+
* Transforms the given vertex normal and tangent via skinning.
150150
*
151151
* @param {Node} [boneMatrices=this.boneMatricesNode] - The bone matrices
152152
* @param {Node<vec3>} [normal=normalLocal] - The vertex normal in local space.
153-
* @return {Node<vec3>} The transformed vertex normal.
153+
* @param {Node<vec3>} [tangent=tangentLocal] - The vertex tangent in local space.
154+
* @return {{skinNormal: Node<vec3>, skinTangent:Node<vec3>}} The transformed vertex normal and tangent.
154155
*/
155-
getSkinnedNormal( boneMatrices = this.boneMatricesNode, normal = normalLocal ) {
156+
getSkinnedNormalAndTangent( boneMatrices = this.boneMatricesNode, normal = normalLocal, tangent = tangentLocal ) {
156157

157158
const { skinIndexNode, skinWeightNode, bindMatrixNode, bindMatrixInverseNode } = this;
158159

@@ -161,7 +162,7 @@ class SkinningNode extends Node {
161162
const boneMatZ = boneMatrices.element( skinIndexNode.z );
162163
const boneMatW = boneMatrices.element( skinIndexNode.w );
163164

164-
// NORMAL
165+
// NORMAL and TANGENT
165166

166167
let skinMatrix = add(
167168
skinWeightNode.x.mul( boneMatX ),
@@ -172,7 +173,10 @@ class SkinningNode extends Node {
172173

173174
skinMatrix = bindMatrixInverseNode.mul( skinMatrix ).mul( bindMatrixNode );
174175

175-
return skinMatrix.transformDirection( normal ).xyz;
176+
const skinNormal = skinMatrix.transformDirection( normal ).xyz;
177+
const skinTangent = skinMatrix.transformDirection( tangent ).xyz;
178+
179+
return { skinNormal, skinTangent };
176180

177181
}
178182

@@ -220,13 +224,13 @@ class SkinningNode extends Node {
220224

221225
if ( builder.hasGeometryAttribute( 'normal' ) ) {
222226

223-
const skinNormal = this.getSkinnedNormal();
227+
const { skinNormal, skinTangent } = this.getSkinnedNormalAndTangent();
224228

225229
normalLocal.assign( skinNormal );
226230

227231
if ( builder.hasGeometryAttribute( 'tangent' ) ) {
228232

229-
tangentLocal.assign( skinNormal );
233+
tangentLocal.assign( skinTangent );
230234

231235
}
232236

0 commit comments

Comments
 (0)