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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import buildModuleUrl from "../Core/buildModuleUrl.js";
  2. import Cartesian3 from "../Core/Cartesian3.js";
  3. import Frozen from "../Core/Frozen.js";
  4. import defined from "../Core/defined.js";
  5. import destroyObject from "../Core/destroyObject.js";
  6. import Ellipsoid from "../Core/Ellipsoid.js";
  7. import IauOrientationAxes from "../Core/IauOrientationAxes.js";
  8. import Matrix3 from "../Core/Matrix3.js";
  9. import Matrix4 from "../Core/Matrix4.js";
  10. import Simon1994PlanetaryPositions from "../Core/Simon1994PlanetaryPositions.js";
  11. import Transforms from "../Core/Transforms.js";
  12. import EllipsoidPrimitive from "./EllipsoidPrimitive.js";
  13. import Material from "./Material.js";
  14. /**
  15. * Draws the Moon in 3D.
  16. * @alias Moon
  17. * @constructor
  18. *
  19. * @param {object} [options] Object with the following properties:
  20. * @param {boolean} [options.show=true] Determines whether the moon will be rendered.
  21. * @param {string} [options.textureUrl=buildModuleUrl('Assets/Textures/moonSmall.jpg')] The moon texture.
  22. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.MOON] The moon ellipsoid.
  23. * @param {boolean} [options.onlySunLighting=true] Use the sun as the only light source.
  24. *
  25. *
  26. * @example
  27. * scene.moon = new Cesium.Moon();
  28. *
  29. * @see Scene#moon
  30. */
  31. function Moon(options) {
  32. options = options ?? Frozen.EMPTY_OBJECT;
  33. let url = options.textureUrl;
  34. if (!defined(url)) {
  35. url = buildModuleUrl("Assets/Textures/moonSmall.jpg");
  36. }
  37. /**
  38. * Determines if the moon will be shown.
  39. *
  40. * @type {boolean}
  41. * @default true
  42. */
  43. this.show = options.show ?? true;
  44. /**
  45. * The moon texture.
  46. * @type {string}
  47. * @default buildModuleUrl('Assets/Textures/moonSmall.jpg')
  48. */
  49. this.textureUrl = url;
  50. this._ellipsoid = options.ellipsoid ?? Ellipsoid.MOON;
  51. /**
  52. * Use the sun as the only light source.
  53. * @type {boolean}
  54. * @default true
  55. */
  56. this.onlySunLighting = options.onlySunLighting ?? true;
  57. this._ellipsoidPrimitive = new EllipsoidPrimitive({
  58. radii: this.ellipsoid.radii,
  59. material: Material.fromType(Material.ImageType),
  60. depthTestEnabled: false,
  61. _owner: this,
  62. });
  63. this._ellipsoidPrimitive.material.translucent = false;
  64. this._axes = new IauOrientationAxes();
  65. }
  66. Object.defineProperties(Moon.prototype, {
  67. /**
  68. * Get the ellipsoid that defines the shape of the moon.
  69. *
  70. * @memberof Moon.prototype
  71. *
  72. * @type {Ellipsoid}
  73. * @readonly
  74. *
  75. * @default {@link Ellipsoid.MOON}
  76. */
  77. ellipsoid: {
  78. get: function () {
  79. return this._ellipsoid;
  80. },
  81. },
  82. });
  83. const icrfToFixed = new Matrix3();
  84. const rotationScratch = new Matrix3();
  85. const translationScratch = new Cartesian3();
  86. const scratchCommandList = [];
  87. /**
  88. * @private
  89. */
  90. Moon.prototype.update = function (frameState) {
  91. if (!this.show) {
  92. return;
  93. }
  94. const ellipsoidPrimitive = this._ellipsoidPrimitive;
  95. ellipsoidPrimitive.material.uniforms.image = this.textureUrl;
  96. ellipsoidPrimitive.onlySunLighting = this.onlySunLighting;
  97. const date = frameState.time;
  98. if (!defined(Transforms.computeIcrfToFixedMatrix(date, icrfToFixed))) {
  99. Transforms.computeTemeToPseudoFixedMatrix(date, icrfToFixed);
  100. }
  101. const rotation = this._axes.evaluate(date, rotationScratch);
  102. Matrix3.transpose(rotation, rotation);
  103. Matrix3.multiply(icrfToFixed, rotation, rotation);
  104. const translation =
  105. Simon1994PlanetaryPositions.computeMoonPositionInEarthInertialFrame(
  106. date,
  107. translationScratch,
  108. );
  109. Matrix3.multiplyByVector(icrfToFixed, translation, translation);
  110. Matrix4.fromRotationTranslation(
  111. rotation,
  112. translation,
  113. ellipsoidPrimitive.modelMatrix,
  114. );
  115. const savedCommandList = frameState.commandList;
  116. frameState.commandList = scratchCommandList;
  117. scratchCommandList.length = 0;
  118. ellipsoidPrimitive.update(frameState);
  119. frameState.commandList = savedCommandList;
  120. return scratchCommandList.length === 1 ? scratchCommandList[0] : undefined;
  121. };
  122. /**
  123. * Returns true if this object was destroyed; otherwise, false.
  124. * <br /><br />
  125. * If this object was destroyed, it should not be used; calling any function other than
  126. * <code>isDestroyed</code> will result in a {@link DeveloperError} exception.
  127. *
  128. * @returns {boolean} <code>true</code> if this object was destroyed; otherwise, <code>false</code>.
  129. *
  130. * @see Moon#destroy
  131. */
  132. Moon.prototype.isDestroyed = function () {
  133. return false;
  134. };
  135. /**
  136. * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic
  137. * release of WebGL resources, instead of relying on the garbage collector to destroy this object.
  138. * <br /><br />
  139. * Once an object is destroyed, it should not be used; calling any function other than
  140. * <code>isDestroyed</code> will result in a {@link DeveloperError} exception. Therefore,
  141. * assign the return value (<code>undefined</code>) to the object as done in the example.
  142. *
  143. * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.
  144. *
  145. *
  146. * @example
  147. * moon = moon && moon.destroy();
  148. *
  149. * @see Moon#isDestroyed
  150. */
  151. Moon.prototype.destroy = function () {
  152. this._ellipsoidPrimitive =
  153. this._ellipsoidPrimitive && this._ellipsoidPrimitive.destroy();
  154. return destroyObject(this);
  155. };
  156. export default Moon;