Vector2Node.js 1.1 KB

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