UVNode.js 718 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { addNodeClass } from '../core/Node.js';
  2. import AttributeNode from '../core/AttributeNode.js';
  3. import { nodeObject } from '../shadernode/ShaderNode.js';
  4. class UVNode extends AttributeNode {
  5. constructor( index = 0 ) {
  6. super( null, 'vec2' );
  7. this.isUVNode = true;
  8. this.index = index;
  9. }
  10. getAttributeName( /*builder*/ ) {
  11. const index = this.index;
  12. return 'uv' + ( index > 0 ? index + 1 : '' );
  13. }
  14. serialize( data ) {
  15. super.serialize( data );
  16. data.index = this.index;
  17. }
  18. deserialize( data ) {
  19. super.deserialize( data );
  20. this.index = data.index;
  21. }
  22. }
  23. export default UVNode;
  24. export const uv = ( ...params ) => nodeObject( new UVNode( ...params ) );
  25. addNodeClass( UVNode );