|
@@ -146,13 +146,14 @@ class SkinningNode extends Node {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Transforms the given vertex normal via skinning.
|
|
|
|
|
|
|
+ * Transforms the given vertex normal and tangent via skinning.
|
|
|
*
|
|
*
|
|
|
* @param {Node} [boneMatrices=this.boneMatricesNode] - The bone matrices
|
|
* @param {Node} [boneMatrices=this.boneMatricesNode] - The bone matrices
|
|
|
* @param {Node<vec3>} [normal=normalLocal] - The vertex normal in local space.
|
|
* @param {Node<vec3>} [normal=normalLocal] - The vertex normal in local space.
|
|
|
- * @return {Node<vec3>} The transformed vertex normal.
|
|
|
|
|
|
|
+ * @param {Node<vec3>} [tangent=tangentLocal] - The vertex tangent in local space.
|
|
|
|
|
+ * @return {{skinNormal: Node<vec3>, skinTangent:Node<vec3>}} The transformed vertex normal and tangent.
|
|
|
*/
|
|
*/
|
|
|
- getSkinnedNormal( boneMatrices = this.boneMatricesNode, normal = normalLocal ) {
|
|
|
|
|
|
|
+ getSkinnedNormalAndTangent( boneMatrices = this.boneMatricesNode, normal = normalLocal, tangent = tangentLocal ) {
|
|
|
|
|
|
|
|
const { skinIndexNode, skinWeightNode, bindMatrixNode, bindMatrixInverseNode } = this;
|
|
const { skinIndexNode, skinWeightNode, bindMatrixNode, bindMatrixInverseNode } = this;
|
|
|
|
|
|
|
@@ -161,7 +162,7 @@ class SkinningNode extends Node {
|
|
|
const boneMatZ = boneMatrices.element( skinIndexNode.z );
|
|
const boneMatZ = boneMatrices.element( skinIndexNode.z );
|
|
|
const boneMatW = boneMatrices.element( skinIndexNode.w );
|
|
const boneMatW = boneMatrices.element( skinIndexNode.w );
|
|
|
|
|
|
|
|
- // NORMAL
|
|
|
|
|
|
|
+ // NORMAL and TANGENT
|
|
|
|
|
|
|
|
let skinMatrix = add(
|
|
let skinMatrix = add(
|
|
|
skinWeightNode.x.mul( boneMatX ),
|
|
skinWeightNode.x.mul( boneMatX ),
|
|
@@ -172,7 +173,10 @@ class SkinningNode extends Node {
|
|
|
|
|
|
|
|
skinMatrix = bindMatrixInverseNode.mul( skinMatrix ).mul( bindMatrixNode );
|
|
skinMatrix = bindMatrixInverseNode.mul( skinMatrix ).mul( bindMatrixNode );
|
|
|
|
|
|
|
|
- return skinMatrix.transformDirection( normal ).xyz;
|
|
|
|
|
|
|
+ const skinNormal = skinMatrix.transformDirection( normal ).xyz;
|
|
|
|
|
+ const skinTangent = skinMatrix.transformDirection( tangent ).xyz;
|
|
|
|
|
+
|
|
|
|
|
+ return { skinNormal, skinTangent };
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -220,13 +224,13 @@ class SkinningNode extends Node {
|
|
|
|
|
|
|
|
if ( builder.hasGeometryAttribute( 'normal' ) ) {
|
|
if ( builder.hasGeometryAttribute( 'normal' ) ) {
|
|
|
|
|
|
|
|
- const skinNormal = this.getSkinnedNormal();
|
|
|
|
|
|
|
+ const { skinNormal, skinTangent } = this.getSkinnedNormalAndTangent();
|
|
|
|
|
|
|
|
normalLocal.assign( skinNormal );
|
|
normalLocal.assign( skinNormal );
|
|
|
|
|
|
|
|
if ( builder.hasGeometryAttribute( 'tangent' ) ) {
|
|
if ( builder.hasGeometryAttribute( 'tangent' ) ) {
|
|
|
|
|
|
|
|
- tangentLocal.assign( skinNormal );
|
|
|
|
|
|
|
+ tangentLocal.assign( skinTangent );
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|