Vector2Node.js 952 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { Vector2 } from '../../../../build/three.module.js';
  2. import { InputNode } from '../core/InputNode.js';
  3. import { NodeUtils } from '../core/NodeUtils.js';
  4. class Vector2Node extends InputNode {
  5. constructor( x, y ) {
  6. super( 'v2' );
  7. this.value = x instanceof Vector2 ? x : new Vector2( x, y );
  8. }
  9. generateReadonly( builder, output, uuid, type/*, ns, needsUpdate*/ ) {
  10. return builder.format( 'vec2( ' + this.x + ', ' + this.y + ' )', type, output );
  11. }
  12. copy( source ) {
  13. super.copy( source );
  14. this.value.copy( source );
  15. return this;
  16. }
  17. toJSON( meta ) {
  18. let data = this.getJSONNode( meta );
  19. if ( ! data ) {
  20. data = this.createJSONNode( meta );
  21. data.x = this.x;
  22. data.y = this.y;
  23. if ( this.readonly === true ) data.readonly = true;
  24. }
  25. return data;
  26. }
  27. }
  28. Vector2Node.prototype.nodeType = 'Vector2';
  29. NodeUtils.addShortcuts( Vector2Node.prototype, 'value', [ 'x', 'y' ] );
  30. export { Vector2Node };