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. constructor( scope = BitangentNode.LOCAL ) {
  10. super( 'vec3' );
  11. this.scope = scope;
  12. }
  13. getHash( /*builder*/ ) {
  14. return `bitangent-${this.scope}`;
  15. }
  16. generate( builder ) {
  17. const scope = this.scope;
  18. const crossNormalTangent = new MathNode( MathNode.CROSS, new NormalNode( scope ), new TangentNode( scope ) );
  19. const tangentW = new SplitNode( new TangentNode( TangentNode.GEOMETRY ), 'w' );
  20. const vertexNode = new SplitNode( new OperatorNode( '*', crossNormalTangent, tangentW ), 'xyz' );
  21. const outputNode = new MathNode( MathNode.NORMALIZE, new VaryingNode( vertexNode ) );
  22. return outputNode.build( builder, this.getNodeType( builder ) );
  23. }
  24. serialize( data ) {
  25. super.serialize( data );
  26. data.scope = this.scope;
  27. }
  28. deserialize( data ) {
  29. super.deserialize( data );
  30. this.scope = data.scope;
  31. }
  32. }
  33. BitangentNode.GEOMETRY = 'geometry';
  34. BitangentNode.LOCAL = 'local';
  35. BitangentNode.VIEW = 'view';
  36. BitangentNode.WORLD = 'world';
  37. export default BitangentNode;