Vector3Node.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 Vector3Node( x, y, z ) {
  7. InputNode.call( this, 'v3' );
  8. this.value = x instanceof THREE.Vector3 ? x : new THREE.Vector3( x, y, z );
  9. };
  10. Vector3Node.prototype = Object.create( InputNode.prototype );
  11. Vector3Node.prototype.constructor = Vector3Node;
  12. Vector3Node.prototype.nodeType = "Vector3";
  13. NodeUtils.addShortcuts( Vector3Node.prototype, 'value', [ 'x', 'y', 'z' ] );
  14. Vector3Node.prototype.generateReadonly = function ( builder, output, uuid, type, ns, needsUpdate ) {
  15. return builder.format( "vec3( " + this.x + ", " + this.y + ", " + this.z + " )", type, output );
  16. };
  17. Vector3Node.prototype.copy = function ( source ) {
  18. InputNode.prototype.copy.call( this, source );
  19. this.value.copy( source );
  20. };
  21. Vector3Node.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. data.z = this.z;
  28. if ( this.readonly === true ) data.readonly = true;
  29. }
  30. return data;
  31. };
  32. export { Vector3Node };