Vector2Node.js 1.1 KB

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