UVNode.js 1.1 KB

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