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

FrameState.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. import SceneMode from "./SceneMode.js";
  2. /**
  3. * State information about the current frame. An instance of this class
  4. * is provided to update functions.
  5. *
  6. * @param {Context} context The rendering context
  7. * @param {CreditDisplay} creditDisplay Handles adding and removing credits from an HTML element
  8. * @param {JobScheduler} jobScheduler The job scheduler
  9. *
  10. * @alias FrameState
  11. * @constructor
  12. *
  13. * @private
  14. */
  15. function FrameState(context, creditDisplay, jobScheduler) {
  16. /**
  17. * The rendering context.
  18. *
  19. * @type {Context}
  20. */
  21. this.context = context;
  22. /**
  23. * An array of rendering commands.
  24. *
  25. * @type {DrawCommand[]}
  26. */
  27. this.commandList = [];
  28. /**
  29. * An array of panorama rendering commands.
  30. *
  31. * @type {DrawCommand[]}
  32. */
  33. this.panoramaCommandList = [];
  34. /**
  35. * An array of shadow maps.
  36. * @type {ShadowMap[]}
  37. */
  38. this.shadowMaps = [];
  39. /**
  40. * The BRDF look up texture generator used for image-based lighting for PBR models
  41. * @type {BrdfLutGenerator}
  42. */
  43. this.brdfLutGenerator = undefined;
  44. /**
  45. * The environment map used for image-based lighting for PBR models
  46. * @type {CubeMap}
  47. */
  48. this.environmentMap = undefined;
  49. /**
  50. * The spherical harmonic coefficients used for image-based lighting for PBR models.
  51. * @type {Cartesian3[]}
  52. */
  53. this.sphericalHarmonicCoefficients = undefined;
  54. /**
  55. * The specular environment atlas used for image-based lighting for PBR models.
  56. * @type {Texture}
  57. */
  58. this.specularEnvironmentMaps = undefined;
  59. /**
  60. * The maximum level-of-detail of the specular environment atlas used for image-based lighting for PBR models.
  61. * @type {number}
  62. */
  63. this.specularEnvironmentMapsMaximumLOD = undefined;
  64. /**
  65. * The current mode of the scene.
  66. *
  67. * @type {SceneMode}
  68. * @default {@link SceneMode.SCENE3D}
  69. */
  70. this.mode = SceneMode.SCENE3D;
  71. /**
  72. * The current morph transition time between 2D/Columbus View and 3D,
  73. * with 0.0 being 2D or Columbus View and 1.0 being 3D.
  74. *
  75. * @type {number}
  76. */
  77. this.morphTime = SceneMode.getMorphTime(SceneMode.SCENE3D);
  78. /**
  79. * The current frame number.
  80. *
  81. * @type {number}
  82. * @default 0
  83. */
  84. this.frameNumber = 0;
  85. /**
  86. * <code>true</code> if a new frame has been issued and the frame number has been updated.
  87. *
  88. * @type {boolean}
  89. * @default false
  90. */
  91. this.newFrame = false;
  92. /**
  93. * The scene's current time.
  94. *
  95. * @type {JulianDate}
  96. * @default undefined
  97. */
  98. this.time = undefined;
  99. /**
  100. * The job scheduler.
  101. *
  102. * @type {JobScheduler}
  103. */
  104. this.jobScheduler = jobScheduler;
  105. /**
  106. * The map projection to use in 2D and Columbus View modes.
  107. *
  108. * @type {MapProjection}
  109. * @default undefined
  110. */
  111. this.mapProjection = undefined;
  112. /**
  113. * The current camera.
  114. *
  115. * @type {Camera}
  116. * @default undefined
  117. */
  118. this.camera = undefined;
  119. /**
  120. * Whether the camera is underground.
  121. *
  122. * @type {boolean}
  123. * @default false
  124. */
  125. this.cameraUnderground = false;
  126. /**
  127. * The {@link GlobeTranslucencyState} object used by the scene.
  128. *
  129. * @type {GlobeTranslucencyState}
  130. * @default undefined
  131. */
  132. this.globeTranslucencyState = undefined;
  133. /**
  134. * The culling volume.
  135. *
  136. * @type {CullingVolume}
  137. * @default undefined
  138. */
  139. this.cullingVolume = undefined;
  140. /**
  141. * The current occluder.
  142. *
  143. * @type {Occluder}
  144. * @default undefined
  145. */
  146. this.occluder = undefined;
  147. /**
  148. * The maximum screen-space error used to drive level-of-detail refinement. Higher
  149. * values will provide better performance but lower visual quality.
  150. *
  151. * @type {number}
  152. * @default 2
  153. */
  154. this.maximumScreenSpaceError = undefined;
  155. /**
  156. * Ratio between a pixel and a density-independent pixel. Provides a standard unit of
  157. * measure for real pixel measurements appropriate to a particular device.
  158. *
  159. * @type {number}
  160. * @default 1.0
  161. */
  162. this.pixelRatio = 1.0;
  163. /**
  164. * @typedef FrameState.Passes
  165. * @type {object}
  166. * @property {boolean} render <code>true</code> if the primitive should update for a render pass, <code>false</code> otherwise.
  167. * @property {boolean} pick <code>true</code> if the primitive should update for a picking pass, <code>false</code> otherwise.
  168. * @property {boolean} pickVoxel <code>true</code> if the primitive should update for a voxel picking pass, <code>false</code> otherwise.
  169. * @property {boolean} depth <code>true</code> if the primitive should update for a depth only pass, <code>false</code> otherwise.
  170. * @property {boolean} postProcess <code>true</code> if the primitive should update for a per-feature post-process pass, <code>false</code> otherwise.
  171. * @property {boolean} offscreen <code>true</code> if the primitive should update for an offscreen pass, <code>false</code> otherwise.
  172. */
  173. /**
  174. * @type {FrameState.Passes}
  175. */
  176. this.passes = {
  177. /**
  178. * @default false
  179. */
  180. render: false,
  181. /**
  182. * @default false
  183. */
  184. pick: false,
  185. /**
  186. * @default false
  187. */
  188. pickVoxel: false,
  189. /**
  190. * @default false
  191. */
  192. depth: false,
  193. /**
  194. * @default false
  195. */
  196. postProcess: false,
  197. /**
  198. * @default false
  199. */
  200. offscreen: false,
  201. };
  202. /**
  203. * The credit display.
  204. *
  205. * @type {CreditDisplay}
  206. */
  207. this.creditDisplay = creditDisplay;
  208. /**
  209. * An array of functions to be called at the end of the frame. This array
  210. * will be cleared after each frame.
  211. * <p>
  212. * This allows queueing up events in <code>update</code> functions and
  213. * firing them at a time when the subscribers are free to change the
  214. * scene state, e.g., manipulate the camera, instead of firing events
  215. * directly in <code>update</code> functions.
  216. * </p>
  217. * <p>
  218. * If any function in the array returns <code>true</code>, in request render mode
  219. * another frame will be rendered.
  220. * </p>
  221. *
  222. * @type {FrameState.AfterRenderCallback[]}
  223. *
  224. * @example
  225. * frameState.afterRender.push(function() {
  226. * // take some action, raise an event, etc.
  227. * });
  228. */
  229. this.afterRender = [];
  230. /**
  231. * Gets whether or not to optimize for 3D only.
  232. *
  233. * @type {boolean}
  234. * @default false
  235. */
  236. this.scene3DOnly = false;
  237. /**
  238. * @typedef FrameState.Fog
  239. * @type {object}
  240. * @property {boolean} enabled <code>true</code> if fog is enabled, <code>false</code> otherwise. This affects both fog culling and rendering.
  241. * @property {boolean} renderable <code>true</code> if fog should be rendered, <code>false</code> if not. This flag should be checked in combination with fog.enabled.
  242. * @property {number | undefined} density A positive number used to mix the color and fog color based on camera distance.
  243. * @property {number | undefined} visualDensityScalar A positive number to modify how impactful the fog is based off the density
  244. * @property {number | undefined} sse A scalar used to modify the screen space error of geometry partially in fog.
  245. * @property {number | undefined} minimumBrightness The minimum brightness of terrain with fog applied.
  246. */
  247. /**
  248. * @type {FrameState.Fog}
  249. */
  250. this.fog = {
  251. /**
  252. * @default false
  253. */
  254. enabled: false,
  255. renderable: false,
  256. density: undefined,
  257. visualDensityScalar: undefined,
  258. sse: undefined,
  259. minimumBrightness: undefined,
  260. };
  261. /**
  262. * The current Atmosphere
  263. * @type {Atmosphere}
  264. */
  265. this.atmosphere = undefined;
  266. /**
  267. * A scalar used to vertically exaggerate the scene
  268. * @type {number}
  269. * @default 1.0
  270. */
  271. this.verticalExaggeration = 1.0;
  272. /**
  273. * The height relative to which the scene is vertically exaggerated.
  274. * @type {number}
  275. * @default 0.0
  276. */
  277. this.verticalExaggerationRelativeHeight = 0.0;
  278. /**
  279. * @typedef FrameState.ShadowState
  280. * @type {object}
  281. * @property {boolean} shadowsEnabled Whether there are any active shadow maps this frame.
  282. * @property {boolean} lightShadowsEnabled Whether there are any active shadow maps that originate from light sources. Does not include shadow maps that are used for analytical purposes.
  283. * @property {ShadowMap[]} shadowMaps All shadow maps that are enabled this frame.
  284. * @property {ShadowMap[]} lightShadowMaps Shadow maps that originate from light sources. Does not include shadow maps that are used for analytical purposes. Only these shadow maps will be used to generate receive shadows shaders.
  285. * @property {number} nearPlane The near plane of the scene's frustum commands. Used for fitting cascaded shadow maps.
  286. * @property {number} farPlane The far plane of the scene's frustum commands. Used for fitting cascaded shadow maps.
  287. * @property {number} closestObjectSize The size of the bounding volume that is closest to the camera. This is used to place more shadow detail near the object.
  288. * @property {number} lastDirtyTime The time when a shadow map was last dirty
  289. * @property {boolean} outOfView Whether the shadows maps are out of view this frame
  290. */
  291. /**
  292. * @type {FrameState.ShadowState}
  293. */
  294. this.shadowState = {
  295. /**
  296. * @default true
  297. */
  298. shadowsEnabled: true,
  299. shadowMaps: [],
  300. lightShadowMaps: [],
  301. /**
  302. * @default 1.0
  303. */
  304. nearPlane: 1.0,
  305. /**
  306. * @default 5000.0
  307. */
  308. farPlane: 5000.0,
  309. /**
  310. * @default 1000.0
  311. */
  312. closestObjectSize: 1000.0,
  313. /**
  314. * @default 0
  315. */
  316. lastDirtyTime: 0,
  317. /**
  318. * @default true
  319. */
  320. outOfView: true,
  321. };
  322. /**
  323. * The position of the splitter to use when rendering different things on either side of a splitter.
  324. * This value should be between 0.0 and 1.0 with 0 being the far left of the viewport and 1 being the far right of the viewport.
  325. * @type {number}
  326. * @default 0.0
  327. */
  328. this.splitPosition = 0.0;
  329. /**
  330. * Distances to the near and far planes of the camera frustums
  331. * @type {number[]}
  332. * @default []
  333. */
  334. this.frustumSplits = [];
  335. /**
  336. * The current scene background color
  337. *
  338. * @type {Color}
  339. */
  340. this.backgroundColor = undefined;
  341. /**
  342. * The light used to shade the scene.
  343. *
  344. * @type {Light}
  345. */
  346. this.light = undefined;
  347. /**
  348. * The distance from the camera at which to disable the depth test of billboards, labels and points
  349. * to, for example, prevent clipping against terrain. When set to zero, the depth test should always
  350. * be applied. When less than zero, the depth test should never be applied.
  351. * @type {number}
  352. */
  353. this.minimumDisableDepthTestDistance = undefined;
  354. /**
  355. * When <code>false</code>, 3D Tiles will render normally. When <code>true</code>, classified 3D Tile geometry will render normally and
  356. * unclassified 3D Tile geometry will render with the color multiplied with {@link FrameState#invertClassificationColor}.
  357. * @type {boolean}
  358. * @default false
  359. */
  360. this.invertClassification = false;
  361. /**
  362. * The highlight color of unclassified 3D Tile geometry when {@link FrameState#invertClassification} is <code>true</code>.
  363. * @type {Color}
  364. */
  365. this.invertClassificationColor = undefined;
  366. /**
  367. * Whether or not the scene uses a logarithmic depth buffer.
  368. *
  369. * @type {boolean}
  370. * @default false
  371. */
  372. this.useLogDepth = false;
  373. /**
  374. * Additional state used to update 3D Tilesets.
  375. *
  376. * @type {Cesium3DTilePassState}
  377. */
  378. this.tilesetPassState = undefined;
  379. /**
  380. * The minimum terrain height out of all rendered terrain tiles. Used to improve culling for objects underneath the ellipsoid but above terrain.
  381. *
  382. * @type {number}
  383. * @default 0.0
  384. */
  385. this.minimumTerrainHeight = 0.0;
  386. /**
  387. * Whether metadata picking is currently in progress.
  388. *
  389. * This is set to `true` in the `Picking.pickMetadata` function,
  390. * immediately before updating and executing the draw commands,
  391. * and set back to `false` immediately afterwards. It will be
  392. * used to determine whether the metadata picking draw commands
  393. * should be executed, in the `Scene.executeCommand` function.
  394. *
  395. * @type {boolean}
  396. * @default false
  397. */
  398. this.pickingMetadata = false;
  399. /**
  400. * Metadata picking information.
  401. *
  402. * This describes the metadata property that is supposed to be picked
  403. * in a `Picking.pickMetadata` call.
  404. *
  405. * This is stored in the frame state and in the metadata picking draw
  406. * commands. In the `Scene.updateDerivedCommands` call, it will be
  407. * checked whether the instance that is stored in the frame state
  408. * is different from the one in the draw command, and if necessary,
  409. * the derived commands for metadata picking will be updated based
  410. * on this information.
  411. *
  412. * @type {PickedMetadataInfo|undefined}
  413. */
  414. this.pickedMetadataInfo = undefined;
  415. /**
  416. * Internal toggle indicating that at least one primitive for this frame requested
  417. * edge visibility rendering (EXT_mesh_primitive_edge_visibility). This allows
  418. * lazy allocation/activation of the edge MRT without storing a Scene reference
  419. * on the frame state (avoids passing entire Scene through internal APIs).
  420. * Set by model pipeline stages when they encounter edge visibility data.
  421. * Consumed by Scene to flip its _enableEdgeVisibility flag.
  422. * @type {boolean}
  423. * @private
  424. */
  425. this.edgeVisibilityRequested = false;
  426. }
  427. /**
  428. * A function that will be called at the end of the frame.
  429. *
  430. * @callback FrameState.AfterRenderCallback
  431. * @returns {boolean} true if another render should be requested in request render mode
  432. */
  433. export default FrameState;