Vector3Node.js 999 B

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