Vector3Node.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. import { Vector3 } from '../../../../build/three.module.js';
  5. import { InputNode } from '../core/InputNode.js';
  6. import { NodeUtils } from '../core/NodeUtils.js';
  7. function Vector3Node( x, y, z ) {
  8. InputNode.call( this, 'v3' );
  9. this.value = x instanceof Vector3 ? x : new Vector3( x, y, z );
  10. }
  11. Vector3Node.prototype = Object.create( InputNode.prototype );
  12. Vector3Node.prototype.constructor = Vector3Node;
  13. Vector3Node.prototype.nodeType = "Vector3";
  14. NodeUtils.addShortcuts( Vector3Node.prototype, 'value', [ 'x', 'y', 'z' ] );
  15. Vector3Node.prototype.generateReadonly = function ( builder, output, uuid, type/*, ns, needsUpdate*/ ) {
  16. return builder.format( "vec3( " + this.x + ", " + this.y + ", " + this.z + " )", type, output );
  17. };
  18. Vector3Node.prototype.copy = function ( source ) {
  19. InputNode.prototype.copy.call( this, source );
  20. this.value.copy( source );
  21. };
  22. Vector3Node.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. data.z = this.z;
  29. if ( this.readonly === true ) data.readonly = true;
  30. }
  31. return data;
  32. };
  33. export { Vector3Node };