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. function UVNode( index ) {
  7. TempNode.call( this, 'v2', { shared: false } );
  8. this.index = index || 0;
  9. }
  10. UVNode.prototype = Object.create( TempNode.prototype );
  11. UVNode.prototype.constructor = UVNode;
  12. UVNode.prototype.nodeType = "UV";
  13. UVNode.prototype.generate = function ( builder, output ) {
  14. builder.requires.uv[ this.index ] = true;
  15. var uvIndex = this.index > 0 ? this.index + 1 : '';
  16. var result = builder.isShader( 'vertex' ) ? 'uv' + uvIndex : 'vUv' + uvIndex;
  17. return builder.format( result, this.getType( builder ), output );
  18. };
  19. UVNode.prototype.copy = function ( source ) {
  20. TempNode.prototype.copy.call( this, source );
  21. this.index = source.index;
  22. return this;
  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 };