BitangentNode.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import Node from '../core/Node.js';
  2. import VaryingNode from '../core/VaryingNode.js';
  3. import OperatorNode from '../math/OperatorNode.js';
  4. import MathNode from '../math/MathNode.js';
  5. import SplitNode from '../utils/SplitNode.js';
  6. import NormalNode from './NormalNode.js';
  7. import TangentNode from './TangentNode.js';
  8. class BitangentNode extends Node {
  9. static GEOMETRY = 'geometry';
  10. static LOCAL = 'local';
  11. static VIEW = 'view';
  12. static WORLD = 'world';
  13. constructor( scope = BitangentNode.LOCAL ) {
  14. super( 'vec3' );
  15. this.scope = scope;
  16. }
  17. getHash( /*builder*/ ) {
  18. return `bitangent-${this.scope}`;
  19. }
  20. generate( builder ) {
  21. const scope = this.scope;
  22. const crossNormalTangent = new MathNode( MathNode.CROSS, new NormalNode( scope ), new TangentNode( scope ) );
  23. const tangentW = new SplitNode( new TangentNode( TangentNode.GEOMETRY ), 'w' );
  24. const vertexNode = new SplitNode( new OperatorNode( '*', crossNormalTangent, tangentW ), 'xyz' );
  25. const outputNode = new MathNode( MathNode.NORMALIZE, new VaryingNode( vertexNode ) );
  26. return outputNode.build( builder, this.getNodeType( builder ) );
  27. }
  28. serialize( data ) {
  29. super.serialize( data );
  30. data.scope = this.scope;
  31. }
  32. deserialize( data ) {
  33. super.deserialize( data );
  34. this.scope = data.scope;
  35. }
  36. }
  37. export default BitangentNode;