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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import Check from "../Core/Check.js";
  2. import defined from "../Core/defined.js";
  3. import DeveloperError from "../Core/DeveloperError.js";
  4. import Resource from "../Core/Resource.js";
  5. import CubeMap from "./CubeMap.js";
  6. /**
  7. * Asynchronously loads six images and creates a cube map. Returns a promise that
  8. * will resolve to a {@link CubeMap} once loaded, or reject if any image fails to load.
  9. *
  10. * @function loadCubeMap
  11. *
  12. * @param {Context} context The context to use to create the cube map.
  13. * @param {object} urls The source URL of each image. See the example below.
  14. * @param {boolean} [skipColorSpaceConversion=false] If true, any custom gamma or color profiles in the images will be ignored.
  15. * @returns {Promise<CubeMap>} a promise that will resolve to the requested {@link CubeMap} when loaded.
  16. *
  17. * @exception {DeveloperError} context is required.
  18. * @exception {DeveloperError} urls is required and must have positiveX, negativeX, positiveY, negativeY, positiveZ, and negativeZ properties.
  19. *
  20. *
  21. * @example
  22. * Cesium.loadCubeMap(context, {
  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. * }).then(function(cubeMap) {
  30. * // use the cubemap
  31. * }).catch(function(error) {
  32. * // an error occurred
  33. * });
  34. *
  35. * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}
  36. * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}
  37. *
  38. * @private
  39. */
  40. function loadCubeMap(context, urls, skipColorSpaceConversion) {
  41. //>>includeStart('debug', pragmas.debug);
  42. Check.defined("context", context);
  43. Check.defined("urls", urls);
  44. if (
  45. Object.values(CubeMap.FaceName).some((faceName) => !defined(urls[faceName]))
  46. ) {
  47. throw new DeveloperError(
  48. "urls must have positiveX, negativeX, positiveY, negativeY, positiveZ, and negativeZ properties.",
  49. );
  50. }
  51. //>>includeEnd('debug');
  52. // PERFORMANCE_IDEA: Given the size of some cube maps, we should consider tiling them, which
  53. // would prevent hiccups when uploading, for example, six 4096x4096 textures to the GPU.
  54. //
  55. // Also, it is perhaps acceptable to use the context here in the callbacks, but
  56. // ideally, we would do it in the primitive's update function.
  57. const flipOptions = {
  58. flipY: true,
  59. skipColorSpaceConversion: skipColorSpaceConversion,
  60. preferImageBitmap: true,
  61. };
  62. const facePromises = [
  63. Resource.createIfNeeded(urls.positiveX).fetchImage(flipOptions),
  64. Resource.createIfNeeded(urls.negativeX).fetchImage(flipOptions),
  65. Resource.createIfNeeded(urls.positiveY).fetchImage(flipOptions),
  66. Resource.createIfNeeded(urls.negativeY).fetchImage(flipOptions),
  67. Resource.createIfNeeded(urls.positiveZ).fetchImage(flipOptions),
  68. Resource.createIfNeeded(urls.negativeZ).fetchImage(flipOptions),
  69. ];
  70. return Promise.all(facePromises).then(function (images) {
  71. return new CubeMap({
  72. context: context,
  73. source: {
  74. positiveX: images[0],
  75. negativeX: images[1],
  76. positiveY: images[2],
  77. negativeY: images[3],
  78. positiveZ: images[4],
  79. negativeZ: images[5],
  80. },
  81. });
  82. });
  83. }
  84. export default loadCubeMap;