|
@@ -1,109 +1,23 @@
|
|
|
-import Node, { addNodeClass } from '../core/Node.js';
|
|
|
import { attribute } from '../core/AttributeNode.js';
|
|
|
-import { temp } from '../core/VarNode.js';
|
|
|
import { varying } from '../core/VaryingNode.js';
|
|
|
-import { normalize } from '../math/MathNode.js';
|
|
|
import { cameraViewMatrix } from './CameraNode.js';
|
|
|
import { modelViewMatrix } from './ModelNode.js';
|
|
|
-import { nodeImmutable, vec4 } from '../shadernode/ShaderNode.js';
|
|
|
+import { tslFn, vec4 } from '../shadernode/ShaderNode.js';
|
|
|
|
|
|
-class TangentNode extends Node {
|
|
|
+export const tangentGeometry = /*#__PURE__*/ tslFn( ( stack, builder ) => {
|
|
|
|
|
|
- constructor( scope = TangentNode.LOCAL ) {
|
|
|
+ if ( builder.geometry.hasAttribute( 'tangent' ) === false ) {
|
|
|
|
|
|
- super();
|
|
|
-
|
|
|
- this.scope = scope;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- getHash( /*builder*/ ) {
|
|
|
-
|
|
|
- return `tangent-${this.scope}`;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- getNodeType() {
|
|
|
-
|
|
|
- const scope = this.scope;
|
|
|
-
|
|
|
- if ( scope === TangentNode.GEOMETRY ) {
|
|
|
-
|
|
|
- return 'vec4';
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- return 'vec3';
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- generate( builder ) {
|
|
|
-
|
|
|
- const scope = this.scope;
|
|
|
-
|
|
|
- let outputNode = null;
|
|
|
-
|
|
|
- if ( scope === TangentNode.GEOMETRY ) {
|
|
|
-
|
|
|
- outputNode = attribute( 'tangent', 'vec4' );
|
|
|
-
|
|
|
- if ( builder.geometry.hasAttribute( 'tangent' ) === false ) {
|
|
|
-
|
|
|
- builder.geometry.computeTangents();
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- } else if ( scope === TangentNode.LOCAL ) {
|
|
|
-
|
|
|
- outputNode = varying( tangentGeometry.xyz );
|
|
|
-
|
|
|
- } else if ( scope === TangentNode.VIEW ) {
|
|
|
-
|
|
|
- const vertexNode = modelViewMatrix.mul( vec4( tangentLocal, 0 ) ).xyz;
|
|
|
- outputNode = normalize( varying( vertexNode ) );
|
|
|
-
|
|
|
- } else if ( scope === TangentNode.WORLD ) {
|
|
|
-
|
|
|
- const vertexNode = tangentView.transformDirection( cameraViewMatrix );
|
|
|
- outputNode = normalize( varying( vertexNode ) );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- return outputNode.build( builder, this.getNodeType( builder ) );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- serialize( data ) {
|
|
|
-
|
|
|
- super.serialize( data );
|
|
|
-
|
|
|
- data.scope = this.scope;
|
|
|
+ builder.geometry.computeTangents();
|
|
|
|
|
|
}
|
|
|
|
|
|
- deserialize( data ) {
|
|
|
-
|
|
|
- super.deserialize( data );
|
|
|
-
|
|
|
- this.scope = data.scope;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-TangentNode.GEOMETRY = 'geometry';
|
|
|
-TangentNode.LOCAL = 'local';
|
|
|
-TangentNode.VIEW = 'view';
|
|
|
-TangentNode.WORLD = 'world';
|
|
|
-
|
|
|
-export default TangentNode;
|
|
|
+ return attribute( 'tangent', 'vec4' );
|
|
|
|
|
|
-export const tangentGeometry = nodeImmutable( TangentNode, TangentNode.GEOMETRY );
|
|
|
-export const tangentLocal = nodeImmutable( TangentNode, TangentNode.LOCAL );
|
|
|
-export const tangentView = nodeImmutable( TangentNode, TangentNode.VIEW );
|
|
|
-export const tangentWorld = nodeImmutable( TangentNode, TangentNode.WORLD );
|
|
|
-export const transformedTangentView = temp( tangentView, 'TransformedTangentView' );
|
|
|
-export const transformedTangentWorld = normalize( transformedTangentView.transformDirection( cameraViewMatrix ) );
|
|
|
+} )();
|
|
|
|
|
|
-addNodeClass( 'TangentNode', TangentNode );
|
|
|
+export const tangentLocal = /*#__PURE__*/ varying( tangentGeometry.xyz, 'tangentLocal' );
|
|
|
+export const tangentView = /*#__PURE__*/ varying( modelViewMatrix.mul( vec4( tangentLocal, 0 ) ).xyz, 'tangentView' ).normalize();
|
|
|
+export const tangentWorld = /*#__PURE__*/ varying( tangentView.transformDirection( cameraViewMatrix ), 'tangentWorld' ).normalize();
|
|
|
+export const transformedTangentView = /*#__PURE__*/ tangentView.toVar( 'transformedTangentView' );
|
|
|
+export const transformedTangentWorld = /*#__PURE__*/ transformedTangentView.transformDirection( cameraViewMatrix ).normalize();
|