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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import buildModuleUrl from "../Core/buildModuleUrl.js";
  2. import CubeMapPanorama from "./CubeMapPanorama.js";
  3. import SceneMode from "./SceneMode.js";
  4. import destroyObject from "../Core/destroyObject.js";
  5. /**
  6. * A sky box around the scene to draw stars. The sky box is defined using the True Equator Mean Equinox (TEME) axes.
  7. * <p>
  8. * This is only supported in 3D. The sky box is faded out when morphing to 2D or Columbus view. The size of
  9. * the sky box must not exceed {@link Scene#maximumCubeMapSize}.
  10. * </p>
  11. *
  12. * @alias SkyBox
  13. * @constructor
  14. *
  15. * @param {object} options Object with the following properties:
  16. * @param {object} [options.sources] The source URL or <code>Image</code> object for each of the six cube map faces. See the example below.
  17. * @param {boolean} [options.show=true] Determines if this primitive will be shown.
  18. *
  19. *
  20. * @example
  21. * scene.skyBox = new Cesium.SkyBox({
  22. * sources : {
  23. * positiveX : 'skybox_px.png',
  24. * negativeX : 'skybox_nx.png',
  25. * positiveY : 'skybox_py.png',
  26. * negativeY : 'skybox_ny.png',
  27. * positiveZ : 'skybox_pz.png',
  28. * negativeZ : 'skybox_nz.png'
  29. * }
  30. * });
  31. *
  32. * @see Scene#skyBox
  33. * @see Transforms.computeTemeToPseudoFixedMatrix
  34. */
  35. function SkyBox(options) {
  36. this._sources = options.sources;
  37. this._show = options.show ?? true;
  38. this._panorama = new CubeMapPanorama({
  39. sources: this._sources,
  40. show: this._show,
  41. returnCommand: true,
  42. });
  43. }
  44. Object.defineProperties(SkyBox.prototype, {
  45. /**
  46. * Gets or sets the the primitive object.
  47. * @memberof SkyBox.prototype
  48. * @type {object}
  49. */
  50. sources: {
  51. get: function () {
  52. return this._panorama.sources;
  53. },
  54. set: function (value) {
  55. this._panorama.sources = value;
  56. },
  57. },
  58. /**
  59. * Determines if the sky box will be shown.
  60. * @memberof SkyBox.prototype
  61. * @type {boolean}
  62. * @default true
  63. */
  64. show: {
  65. get: function () {
  66. return this._panorama.show;
  67. },
  68. set: function (value) {
  69. this._panorama.show = value;
  70. },
  71. },
  72. });
  73. /**
  74. * Called when {@link Viewer} or {@link CesiumWidget} render the scene to
  75. * get the draw commands needed to render this primitive.
  76. * <p>
  77. * Do not call this function directly. This is documented just to
  78. * list the exceptions that may be propagated when the scene is rendered:
  79. * </p>
  80. *
  81. * @exception {DeveloperError} this.sources is required and must have positiveX, negativeX, positiveY, negativeY, positiveZ, and negativeZ properties.
  82. * @exception {DeveloperError} this.sources properties must all be the same type.
  83. */
  84. SkyBox.prototype.update = function (frameState, useHdr) {
  85. const { mode, passes } = frameState;
  86. if (mode !== SceneMode.SCENE3D && mode !== SceneMode.MORPHING) {
  87. return;
  88. }
  89. if (!passes.render) {
  90. return;
  91. }
  92. // Delegate completely
  93. return this._panorama.update(frameState, useHdr);
  94. };
  95. /**
  96. * Returns true if this object was destroyed; otherwise, false.
  97. * <br /><br />
  98. * If this object was destroyed, it should not be used; calling any function other than
  99. * <code>isDestroyed</code> will result in a {@link DeveloperError} exception.
  100. *
  101. * @returns {boolean} <code>true</code> if this object was destroyed; otherwise, <code>false</code>.
  102. *
  103. * @see SkyBox#destroy
  104. */
  105. SkyBox.prototype.isDestroyed = function () {
  106. return false;
  107. };
  108. /**
  109. * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic
  110. * release of WebGL resources, instead of relying on the garbage collector to destroy this object.
  111. * <br /><br />
  112. * Once an object is destroyed, it should not be used; calling any function other than
  113. * <code>isDestroyed</code> will result in a {@link DeveloperError} exception. Therefore,
  114. * assign the return value (<code>undefined</code>) to the object as done in the example.
  115. *
  116. * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.
  117. *
  118. *
  119. * @example
  120. * skyBox = skyBox && skyBox.destroy();
  121. *
  122. * @see SkyBox#isDestroyed
  123. */
  124. SkyBox.prototype.destroy = function () {
  125. this._panorama = this._panorama && this._panorama.destroy();
  126. return destroyObject(this);
  127. };
  128. function getDefaultSkyBoxUrl(suffix) {
  129. return buildModuleUrl(`Assets/Textures/SkyBox/tycho2t3_80_${suffix}.jpg`);
  130. }
  131. /**
  132. * Creates a skybox instance with the default starmap for the Earth.
  133. * @return {SkyBox} The default skybox for the Earth
  134. *
  135. * @example
  136. * viewer.scene.skyBox = Cesium.SkyBox.createEarthSkyBox();
  137. */
  138. SkyBox.createEarthSkyBox = function () {
  139. return new SkyBox({
  140. sources: {
  141. positiveX: getDefaultSkyBoxUrl("px"),
  142. negativeX: getDefaultSkyBoxUrl("mx"),
  143. positiveY: getDefaultSkyBoxUrl("py"),
  144. negativeY: getDefaultSkyBoxUrl("my"),
  145. positiveZ: getDefaultSkyBoxUrl("pz"),
  146. negativeZ: getDefaultSkyBoxUrl("mz"),
  147. },
  148. });
  149. };
  150. export default SkyBox;