|
@@ -1,6 +1,6 @@
|
|
|
import Node, { addNodeClass } from '../core/Node.js';
|
|
|
import { NodeUpdateType } from '../core/constants.js';
|
|
|
-import { ShaderNode, nodeProxy } from '../shadernode/ShaderNode.js';
|
|
|
+import { nodeProxy } from '../shadernode/ShaderNode.js';
|
|
|
import { attribute } from '../core/AttributeNode.js';
|
|
|
import { uniform } from '../core/UniformNode.js';
|
|
|
import { add } from '../math/OperatorNode.js';
|
|
@@ -9,91 +9,72 @@ import { normalLocal } from './NormalNode.js';
|
|
|
import { positionLocal } from './PositionNode.js';
|
|
|
import { tangentLocal } from './TangentNode.js';
|
|
|
|
|
|
-const Skinning = new ShaderNode( ( inputs, {}, builder ) => {
|
|
|
+class SkinningNode extends Node {
|
|
|
|
|
|
- const { index, weight, bindMatrix, bindMatrixInverse, boneMatrices } = inputs;
|
|
|
+ constructor( skinnedMesh ) {
|
|
|
|
|
|
- const boneMatX = boneMatrices.element( index.x );
|
|
|
- const boneMatY = boneMatrices.element( index.y );
|
|
|
- const boneMatZ = boneMatrices.element( index.z );
|
|
|
- const boneMatW = boneMatrices.element( index.w );
|
|
|
+ super( 'void' );
|
|
|
|
|
|
- // POSITION
|
|
|
+ this.skinnedMesh = skinnedMesh;
|
|
|
|
|
|
- const skinVertex = bindMatrix.mul( positionLocal );
|
|
|
+ this.updateType = NodeUpdateType.OBJECT;
|
|
|
|
|
|
- const skinned = add(
|
|
|
- boneMatX.mul( weight.x ).mul( skinVertex ),
|
|
|
- boneMatY.mul( weight.y ).mul( skinVertex ),
|
|
|
- boneMatZ.mul( weight.z ).mul( skinVertex ),
|
|
|
- boneMatW.mul( weight.w ).mul( skinVertex )
|
|
|
- );
|
|
|
+ //
|
|
|
|
|
|
- const skinPosition = bindMatrixInverse.mul( skinned ).xyz;
|
|
|
+ this.skinIndexNode = attribute( 'skinIndex', 'uvec4' );
|
|
|
+ this.skinWeightNode = attribute( 'skinWeight', 'vec4' );
|
|
|
|
|
|
- // NORMAL
|
|
|
+ this.bindMatrixNode = uniform( skinnedMesh.bindMatrix, 'mat4' );
|
|
|
+ this.bindMatrixInverseNode = uniform( skinnedMesh.bindMatrixInverse, 'mat4' );
|
|
|
+ this.boneMatricesNode = buffer( skinnedMesh.skeleton.boneMatrices, 'mat4', skinnedMesh.skeleton.bones.length );
|
|
|
|
|
|
- let skinMatrix = add(
|
|
|
- weight.x.mul( boneMatX ),
|
|
|
- weight.y.mul( boneMatY ),
|
|
|
- weight.z.mul( boneMatZ ),
|
|
|
- weight.w.mul( boneMatW )
|
|
|
- );
|
|
|
+ }
|
|
|
|
|
|
- skinMatrix = bindMatrixInverse.mul( skinMatrix ).mul( bindMatrix );
|
|
|
+ construct( builder ) {
|
|
|
|
|
|
- const skinNormal = skinMatrix.transformDirection( normalLocal ).xyz;
|
|
|
+ const { skinIndexNode, skinWeightNode, bindMatrixNode, bindMatrixInverseNode, boneMatricesNode } = this;
|
|
|
|
|
|
- // ASSIGNS
|
|
|
+ const boneMatX = boneMatricesNode.element( skinIndexNode.x );
|
|
|
+ const boneMatY = boneMatricesNode.element( skinIndexNode.y );
|
|
|
+ const boneMatZ = boneMatricesNode.element( skinIndexNode.z );
|
|
|
+ const boneMatW = boneMatricesNode.element( skinIndexNode.w );
|
|
|
|
|
|
- positionLocal.assign( skinPosition ).build( builder ); // @TODO: For some reason this doesn't work as stack.assign( positionLocal, skinPosition )?
|
|
|
- normalLocal.assign( skinNormal ).build( builder );
|
|
|
+ // POSITION
|
|
|
|
|
|
- if ( builder.hasGeometryAttribute( 'tangent' ) ) {
|
|
|
+ const skinVertex = bindMatrixNode.mul( positionLocal );
|
|
|
|
|
|
- tangentLocal.assign( skinNormal ).build( builder );
|
|
|
+ const skinned = add(
|
|
|
+ boneMatX.mul( skinWeightNode.x ).mul( skinVertex ),
|
|
|
+ boneMatY.mul( skinWeightNode.y ).mul( skinVertex ),
|
|
|
+ boneMatZ.mul( skinWeightNode.z ).mul( skinVertex ),
|
|
|
+ boneMatW.mul( skinWeightNode.w ).mul( skinVertex )
|
|
|
+ );
|
|
|
|
|
|
- }
|
|
|
+ const skinPosition = bindMatrixInverseNode.mul( skinned ).xyz;
|
|
|
|
|
|
-} );
|
|
|
+ // NORMAL
|
|
|
|
|
|
-class SkinningNode extends Node {
|
|
|
+ let skinMatrix = add(
|
|
|
+ skinWeightNode.x.mul( boneMatX ),
|
|
|
+ skinWeightNode.y.mul( boneMatY ),
|
|
|
+ skinWeightNode.z.mul( boneMatZ ),
|
|
|
+ skinWeightNode.w.mul( boneMatW )
|
|
|
+ );
|
|
|
|
|
|
- constructor( skinnedMesh ) {
|
|
|
+ skinMatrix = bindMatrixInverseNode.mul( skinMatrix ).mul( bindMatrixNode );
|
|
|
|
|
|
- super( 'void' );
|
|
|
+ const skinNormal = skinMatrix.transformDirection( normalLocal ).xyz;
|
|
|
|
|
|
- this.skinnedMesh = skinnedMesh;
|
|
|
+ // ASSIGNS
|
|
|
|
|
|
- this.updateType = NodeUpdateType.OBJECT;
|
|
|
+ builder.stack.assign( positionLocal, skinPosition );
|
|
|
+ builder.stack.assign( normalLocal, skinNormal );
|
|
|
|
|
|
- //
|
|
|
+ if ( builder.hasGeometryAttribute( 'tangent' ) ) {
|
|
|
|
|
|
- this.skinIndexNode = attribute( 'skinIndex', 'uvec4' );
|
|
|
- this.skinWeightNode = attribute( 'skinWeight', 'vec4' );
|
|
|
-
|
|
|
- this.bindMatrixNode = uniform( skinnedMesh.bindMatrix, 'mat4' );
|
|
|
- this.bindMatrixInverseNode = uniform( skinnedMesh.bindMatrixInverse, 'mat4' );
|
|
|
- this.boneMatricesNode = buffer( skinnedMesh.skeleton.boneMatrices, 'mat4', skinnedMesh.skeleton.bones.length );
|
|
|
-
|
|
|
- }
|
|
|
+ builder.stack.assign( tangentLocal, skinNormal );
|
|
|
|
|
|
- generate( builder ) {
|
|
|
-
|
|
|
- /*return new ShaderNode( ( {}, stack, builder ) => Skinning.call( {
|
|
|
- index: this.skinIndexNode,
|
|
|
- weight: this.skinWeightNode,
|
|
|
- bindMatrix: this.bindMatrixNode,
|
|
|
- bindMatrixInverse: this.bindMatrixInverseNode,
|
|
|
- boneMatrices: this.boneMatricesNode
|
|
|
- }, stack, builder ) ).build( builder );*/
|
|
|
- Skinning.call( {
|
|
|
- index: this.skinIndexNode,
|
|
|
- weight: this.skinWeightNode,
|
|
|
- bindMatrix: this.bindMatrixNode,
|
|
|
- bindMatrixInverse: this.bindMatrixInverseNode,
|
|
|
- boneMatrices: this.boneMatricesNode
|
|
|
- }, {}, builder );
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|