UVNode.js 978 B

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