智慧水务管理系统 - 精河县供水工程综合管理平台

BoxEmitter.js 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import Cartesian3 from "../Core/Cartesian3.js";
  2. import Check from "../Core/Check.js";
  3. import CesiumMath from "../Core/Math.js";
  4. const defaultDimensions = new Cartesian3(1.0, 1.0, 1.0);
  5. /**
  6. * A ParticleEmitter that emits particles within a box.
  7. * Particles will be positioned randomly within the box and have initial velocities emanating from the center of the box.
  8. *
  9. * @alias BoxEmitter
  10. * @constructor
  11. *
  12. * @param {Cartesian3} dimensions The width, height and depth dimensions of the box.
  13. */
  14. function BoxEmitter(dimensions) {
  15. dimensions = dimensions ?? defaultDimensions;
  16. //>>includeStart('debug', pragmas.debug);
  17. Check.defined("dimensions", dimensions);
  18. Check.typeOf.number.greaterThanOrEquals("dimensions.x", dimensions.x, 0.0);
  19. Check.typeOf.number.greaterThanOrEquals("dimensions.y", dimensions.y, 0.0);
  20. Check.typeOf.number.greaterThanOrEquals("dimensions.z", dimensions.z, 0.0);
  21. //>>includeEnd('debug');
  22. this._dimensions = Cartesian3.clone(dimensions);
  23. }
  24. Object.defineProperties(BoxEmitter.prototype, {
  25. /**
  26. * The width, height and depth dimensions of the box in meters.
  27. * @memberof BoxEmitter.prototype
  28. * @type {Cartesian3}
  29. * @default new Cartesian3(1.0, 1.0, 1.0)
  30. */
  31. dimensions: {
  32. get: function () {
  33. return this._dimensions;
  34. },
  35. set: function (value) {
  36. //>>includeStart('debug', pragmas.debug);
  37. Check.defined("value", value);
  38. Check.typeOf.number.greaterThanOrEquals("value.x", value.x, 0.0);
  39. Check.typeOf.number.greaterThanOrEquals("value.y", value.y, 0.0);
  40. Check.typeOf.number.greaterThanOrEquals("value.z", value.z, 0.0);
  41. //>>includeEnd('debug');
  42. Cartesian3.clone(value, this._dimensions);
  43. },
  44. },
  45. });
  46. const scratchHalfDim = new Cartesian3();
  47. /**
  48. * Initializes the given {Particle} by setting it's position and velocity.
  49. *
  50. * @private
  51. * @param {Particle} particle The particle to initialize.
  52. */
  53. BoxEmitter.prototype.emit = function (particle) {
  54. const dim = this._dimensions;
  55. const halfDim = Cartesian3.multiplyByScalar(dim, 0.5, scratchHalfDim);
  56. const x = CesiumMath.randomBetween(-halfDim.x, halfDim.x);
  57. const y = CesiumMath.randomBetween(-halfDim.y, halfDim.y);
  58. const z = CesiumMath.randomBetween(-halfDim.z, halfDim.z);
  59. particle.position = Cartesian3.fromElements(x, y, z, particle.position);
  60. particle.velocity = Cartesian3.normalize(
  61. particle.position,
  62. particle.velocity,
  63. );
  64. };
  65. export default BoxEmitter;