Vector3Node.js 1.2 KB

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