UVNode.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. };
  24. UVNode.prototype.toJSON = function ( meta ) {
  25. var data = this.getJSONNode( meta );
  26. if ( ! data ) {
  27. data = this.createJSONNode( meta );
  28. data.index = this.index;
  29. }
  30. return data;
  31. };
  32. NodeLib.addKeyword( 'uv', function () {
  33. return new UVNode();
  34. } );
  35. NodeLib.addKeyword( 'uv2', function () {
  36. return new UVNode( 1 );
  37. } );
  38. export { UVNode };