Vector2Node.js 1.2 KB

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