2
0

UVNode.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. import { TempNode } from '../core/TempNode.js';
  5. import { NodeLib } from '../core/NodeLib.js';
  6. var vertexDict = [ 'uv', 'uv2' ],
  7. fragmentDict = [ 'vUv', 'vUv2' ];
  8. function UVNode( index ) {
  9. TempNode.call( this, 'v2', { shared: false } );
  10. this.index = index || 0;
  11. }
  12. UVNode.prototype = Object.create( TempNode.prototype );
  13. UVNode.prototype.constructor = UVNode;
  14. UVNode.prototype.nodeType = "UV";
  15. UVNode.prototype.generate = function ( builder, output ) {
  16. builder.requires.uv[ this.index ] = true;
  17. var result = builder.isShader( 'vertex' ) ? vertexDict[ this.index ] : fragmentDict[ this.index ];
  18. return builder.format( result, this.getType( builder ), output );
  19. };
  20. UVNode.prototype.copy = function ( source ) {
  21. TempNode.prototype.copy.call( this, source );
  22. this.index = source.index;
  23. return this;
  24. };
  25. UVNode.prototype.toJSON = function ( meta ) {
  26. var data = this.getJSONNode( meta );
  27. if ( ! data ) {
  28. data = this.createJSONNode( meta );
  29. data.index = this.index;
  30. }
  31. return data;
  32. };
  33. NodeLib.addKeyword( 'uv', function () {
  34. return new UVNode();
  35. } );
  36. NodeLib.addKeyword( 'uv2', function () {
  37. return new UVNode( 1 );
  38. } );
  39. export { UVNode };