Vector2Node.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. };
  22. Vector2Node.prototype.toJSON = function ( meta ) {
  23. var data = this.getJSONNode( meta );
  24. if ( ! data ) {
  25. data = this.createJSONNode( meta );
  26. data.x = this.x;
  27. data.y = this.y;
  28. if ( this.readonly === true ) data.readonly = true;
  29. }
  30. return data;
  31. };
  32. export { Vector2Node };