@cesium/engine 25.0.0 → 26.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. package/Build/Workers/{chunk-3VDDRF2E.js → chunk-2EFYUSUY.js} +14 -14
  2. package/Build/Workers/{chunk-4GF4MVPY.js → chunk-5LSOO2KD.js} +7 -7
  3. package/Build/Workers/{chunk-I3A6DXYZ.js → chunk-6HK6IXK2.js} +4 -4
  4. package/Build/Workers/{chunk-CZ23Y3RM.js → chunk-6YR6JBMY.js} +2 -2
  5. package/Build/Workers/{chunk-J7KQEKPK.js → chunk-76FDC45O.js} +13 -13
  6. package/Build/Workers/{chunk-ZCCIIBZT.js → chunk-7D2HZKH7.js} +6 -6
  7. package/Build/Workers/{chunk-HSVQATK2.js → chunk-7KVKHY7O.js} +6 -6
  8. package/Build/Workers/{chunk-ITD2IN7N.js → chunk-A3O6EDBK.js} +2 -2
  9. package/Build/Workers/{chunk-ND3NTTOF.js → chunk-A6X24AZI.js} +6 -6
  10. package/Build/Workers/{chunk-DH26SNAB.js → chunk-AHWAZRBV.js} +6 -2
  11. package/Build/Workers/{chunk-3XY3MVPG.js → chunk-B4CQSLZJ.js} +4 -4
  12. package/Build/Workers/{chunk-DYT5NR6P.js → chunk-C7JQVRLM.js} +3 -3
  13. package/Build/Workers/{chunk-WC57YYBN.js → chunk-CDJDJ5LK.js} +2 -2
  14. package/Build/Workers/{chunk-VQKLRBIK.js → chunk-CEEZE3YZ.js} +7 -7
  15. package/Build/Workers/{chunk-4QQXGTCE.js → chunk-CLCTQVVL.js} +8 -8
  16. package/Build/Workers/{chunk-WNN5D4W3.js → chunk-DBD5WWG2.js} +10 -10
  17. package/Build/Workers/{chunk-URUCCIPS.js → chunk-DIGUUD6G.js} +6 -6
  18. package/Build/Workers/{chunk-BTX2NL3P.js → chunk-E7NZJOK7.js} +196 -22
  19. package/Build/Workers/{chunk-3LSD7OOA.js → chunk-EHTS2YPT.js} +16 -16
  20. package/Build/Workers/{chunk-35H3UBIO.js → chunk-ENNFMWDW.js} +11 -11
  21. package/Build/Workers/{chunk-GL7DNVUS.js → chunk-FCP2QY4G.js} +5 -5
  22. package/Build/Workers/{chunk-3RFFPH4M.js → chunk-FDK4K5IA.js} +1 -1
  23. package/Build/Workers/{chunk-WTQGE7Q6.js → chunk-FGQFQHN5.js} +17 -17
  24. package/Build/Workers/{chunk-WUBKZFF6.js → chunk-GSWMAFTE.js} +9 -9
  25. package/Build/Workers/{chunk-3TKLDHV3.js → chunk-GXWQZBAI.js} +2 -2
  26. package/Build/Workers/{chunk-A7A433MD.js → chunk-HHV3MCGV.js} +5 -5
  27. package/Build/Workers/{chunk-A7ZBMVFS.js → chunk-HS6AD4P2.js} +14 -14
  28. package/Build/Workers/{chunk-QXNQQYPV.js → chunk-IGAZBTFZ.js} +8 -8
  29. package/Build/Workers/{chunk-ZAPOS52G.js → chunk-ILME5BXA.js} +8 -8
  30. package/Build/Workers/{chunk-4MTRQFJP.js → chunk-JKXV6PG5.js} +1 -1
  31. package/Build/Workers/{chunk-FVLVVOBQ.js → chunk-JW6OZT4R.js} +10 -10
  32. package/Build/Workers/{chunk-EZARA5FJ.js → chunk-KGXSYGBG.js} +13 -13
  33. package/Build/Workers/{chunk-J3OFS2RD.js → chunk-LD64RPYV.js} +12 -12
  34. package/Build/Workers/{chunk-AWFZHD2B.js → chunk-LGNDTZVX.js} +4 -4
  35. package/Build/Workers/{chunk-AEAVLYPS.js → chunk-LNSQVXFH.js} +2 -2
  36. package/Build/Workers/{chunk-TA777BGS.js → chunk-N7CCOFLX.js} +1 -1
  37. package/Build/Workers/{chunk-7LSFAEWF.js → chunk-NIWITKQK.js} +10 -10
  38. package/Build/Workers/{chunk-4XXHJI6Y.js → chunk-OBEU25PI.js} +17 -17
  39. package/Build/Workers/{chunk-5T6QQAJW.js → chunk-QVLAFFJY.js} +1 -1
  40. package/Build/Workers/{chunk-J647NNZW.js → chunk-R4FPNAZ2.js} +6 -6
  41. package/Build/Workers/{chunk-HVMG6AG4.js → chunk-RG4F5R57.js} +9 -9
  42. package/Build/Workers/{chunk-ST2UWDUU.js → chunk-SF6K72D7.js} +5 -5
  43. package/Build/Workers/{chunk-H2A4USJR.js → chunk-SGRGNDOD.js} +10 -10
  44. package/Build/Workers/{chunk-DFEI5MAV.js → chunk-SM2CDCYF.js} +7 -7
  45. package/Build/Workers/{chunk-TAI4HLII.js → chunk-SS5ABQGY.js} +4 -4
  46. package/Build/Workers/{chunk-ACFFCHHZ.js → chunk-T5QBPLE3.js} +11 -11
  47. package/Build/Workers/{chunk-BVAIWR7O.js → chunk-TVZD72WJ.js} +12 -12
  48. package/Build/Workers/{chunk-6SDGQI27.js → chunk-UEY73NRN.js} +1 -1
  49. package/Build/Workers/{chunk-K6NFIRFB.js → chunk-UVO6COT2.js} +5 -5
  50. package/Build/Workers/{chunk-77RL3MBD.js → chunk-VAL7DYNR.js} +25 -4
  51. package/Build/Workers/{chunk-WN6P5UDH.js → chunk-WBSY7HDY.js} +12 -12
  52. package/Build/Workers/{chunk-FIBS5S7R.js → chunk-XDWCTQCZ.js} +2 -2
  53. package/Build/Workers/{chunk-CKQP3DSS.js → chunk-XLXSDIP5.js} +6 -6
  54. package/Build/Workers/{chunk-LH5SF3XV.js → chunk-XQ3SKCMM.js} +5 -5
  55. package/Build/Workers/{chunk-QSDY4NS7.js → chunk-YKU2Q3A2.js} +9 -9
  56. package/Build/Workers/{chunk-GPIGURCG.js → chunk-ZMBHFYOX.js} +7 -7
  57. package/Build/Workers/{chunk-QO2CGXMP.js → chunk-ZSGUV73H.js} +6 -6
  58. package/Build/Workers/combineGeometry.js +24 -24
  59. package/Build/Workers/createBoxGeometry.js +18 -18
  60. package/Build/Workers/createBoxOutlineGeometry.js +16 -16
  61. package/Build/Workers/createCircleGeometry.js +26 -26
  62. package/Build/Workers/createCircleOutlineGeometry.js +19 -19
  63. package/Build/Workers/createCoplanarPolygonGeometry.js +33 -33
  64. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +31 -31
  65. package/Build/Workers/createCorridorGeometry.js +29 -29
  66. package/Build/Workers/createCorridorOutlineGeometry.js +28 -28
  67. package/Build/Workers/createCylinderGeometry.js +20 -20
  68. package/Build/Workers/createCylinderOutlineGeometry.js +18 -18
  69. package/Build/Workers/createEllipseGeometry.js +26 -26
  70. package/Build/Workers/createEllipseOutlineGeometry.js +19 -19
  71. package/Build/Workers/createEllipsoidGeometry.js +19 -19
  72. package/Build/Workers/createEllipsoidOutlineGeometry.js +18 -18
  73. package/Build/Workers/createFrustumGeometry.js +18 -18
  74. package/Build/Workers/createFrustumOutlineGeometry.js +18 -18
  75. package/Build/Workers/createGeometry.js +24 -24
  76. package/Build/Workers/createGroundPolylineGeometry.js +22 -22
  77. package/Build/Workers/createPlaneGeometry.js +16 -16
  78. package/Build/Workers/createPlaneOutlineGeometry.js +15 -15
  79. package/Build/Workers/createPolygonGeometry.js +32 -32
  80. package/Build/Workers/createPolygonOutlineGeometry.js +30 -30
  81. package/Build/Workers/createPolylineGeometry.js +25 -25
  82. package/Build/Workers/createPolylineVolumeGeometry.js +31 -31
  83. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +27 -27
  84. package/Build/Workers/createRectangleGeometry.js +27 -27
  85. package/Build/Workers/createRectangleOutlineGeometry.js +20 -20
  86. package/Build/Workers/createSimplePolylineGeometry.js +23 -23
  87. package/Build/Workers/createSphereGeometry.js +19 -19
  88. package/Build/Workers/createSphereOutlineGeometry.js +18 -18
  89. package/Build/Workers/createTaskProcessorWorker.js +3 -3
  90. package/Build/Workers/createVectorTileClampedPolylines.js +14 -14
  91. package/Build/Workers/createVectorTileGeometries.js +24 -24
  92. package/Build/Workers/createVectorTilePoints.js +13 -13
  93. package/Build/Workers/createVectorTilePolygons.js +22 -22
  94. package/Build/Workers/createVectorTilePolylines.js +14 -14
  95. package/Build/Workers/createVerticesFromCesium3DTilesTerrain.js +25 -25
  96. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +22 -22
  97. package/Build/Workers/createVerticesFromHeightmap.js +22 -22
  98. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +20 -20
  99. package/Build/Workers/createWallGeometry.js +24 -24
  100. package/Build/Workers/createWallOutlineGeometry.js +23 -23
  101. package/Build/Workers/decodeDraco.js +10 -10
  102. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +987 -2320
  103. package/Build/Workers/decodeI3S.js +10 -10
  104. package/Build/Workers/gaussianSplatSorter.js +4 -4
  105. package/Build/Workers/gaussianSplatTextureGenerator.js +4 -4
  106. package/Build/Workers/incrementallyBuildTerrainPicker.js +10 -10
  107. package/Build/Workers/transcodeKTX2.js +6 -6
  108. package/Build/Workers/transferTypedArrayTest.js +1 -1
  109. package/Build/Workers/upsampleQuantizedTerrainMesh.js +22 -22
  110. package/Build/Workers/upsampleVerticesFromCesium3DTilesTerrain.js +25 -25
  111. package/Source/Core/BoundingRectangle.js +6 -8
  112. package/Source/Core/Cartesian2.js +1 -1
  113. package/Source/Core/Cartesian3.js +1 -1
  114. package/Source/Core/Cartesian4.js +1 -1
  115. package/Source/Core/Color.js +1 -0
  116. package/Source/Core/ComponentDatatype.js +35 -0
  117. package/Source/Core/InterpolationAlgorithm.js +57 -50
  118. package/Source/Core/Ion.js +1 -1
  119. package/Source/Core/MapProjection.js +1 -0
  120. package/Source/Core/Matrix2.js +1 -1
  121. package/Source/Core/Matrix3.js +1 -1
  122. package/Source/Core/Matrix4.js +1 -1
  123. package/Source/Core/Resource.js +1 -1
  124. package/Source/Core/ScreenSpaceEventHandler.js +51 -41
  125. package/Source/Core/TerrainMesh.js +3 -3
  126. package/Source/Core/TerrainPicker.js +1 -0
  127. package/Source/Core/createColorRamp.js +37 -0
  128. package/Source/Core/globalTypes.js +25 -0
  129. package/Source/Core/writeTextToCanvas.js +1 -0
  130. package/Source/DataSources/CzmlDataSource.js +12 -0
  131. package/Source/DataSources/KmlDataSource.js +528 -555
  132. package/Source/DataSources/PathGraphics.js +8 -1
  133. package/Source/DataSources/PathMode.js +27 -0
  134. package/Source/DataSources/PathVisualizer.js +298 -1
  135. package/Source/Renderer/Pass.js +3 -2
  136. package/Source/Renderer/Texture.js +1 -1
  137. package/Source/Renderer/VertexArray.js +1 -0
  138. package/Source/Renderer/createUniform.js +346 -239
  139. package/Source/Renderer/createUniformArray.js +494 -381
  140. package/Source/Scene/ArcGisMapService.js +1 -1
  141. package/Source/Scene/BillboardTexture.js +5 -3
  142. package/Source/Scene/BufferPoint.js +1 -0
  143. package/Source/Scene/BufferPointCollection.js +14 -1
  144. package/Source/Scene/BufferPolygon.js +3 -2
  145. package/Source/Scene/BufferPolygonCollection.js +10 -0
  146. package/Source/Scene/BufferPolyline.js +1 -0
  147. package/Source/Scene/BufferPolylineCollection.js +2 -0
  148. package/Source/Scene/BufferPrimitiveCollection.js +79 -28
  149. package/Source/Scene/CameraEventAggregator.js +30 -18
  150. package/Source/Scene/Cesium3DTile.js +54 -1
  151. package/Source/Scene/Cesium3DTileContent.js +195 -254
  152. package/Source/Scene/Cesium3DTileContentFactory.js +10 -2
  153. package/Source/Scene/Cesium3DTileOptimizations.js +4 -6
  154. package/Source/Scene/Cesium3DTileset.js +45 -5
  155. package/Source/Scene/ClippingPlaneCollection.js +2 -2
  156. package/Source/Scene/ClippingPolygon.js +2 -0
  157. package/Source/Scene/ClippingPolygonCollection.js +2 -2
  158. package/Source/Scene/Composite3DTileContent.js +254 -292
  159. package/Source/Scene/DerivedCommand.js +4 -0
  160. package/Source/Scene/EdgeDisplayMode.js +50 -0
  161. package/Source/Scene/Empty3DTileContent.js +100 -132
  162. package/Source/Scene/Expression.js +6 -8
  163. package/Source/Scene/GaussianSplat3DTileContent.js +436 -478
  164. package/Source/Scene/GeoJsonPrimitive.js +874 -0
  165. package/Source/Scene/Geometry3DTileContent.js +151 -185
  166. package/Source/Scene/GlobeSurfaceShaderSet.js +501 -409
  167. package/Source/Scene/GlobeSurfaceTile.js +540 -401
  168. package/Source/Scene/GlobeSurfaceTileProvider.js +1259 -1146
  169. package/Source/Scene/GltfBufferViewLoader.js +3 -3
  170. package/Source/Scene/GltfLoader.js +110 -0
  171. package/Source/Scene/GltfLoaderUtil.js +20 -4
  172. package/Source/Scene/GltfPipeline/forEachTextureInMaterial.js +10 -0
  173. package/Source/Scene/GltfPipeline/removeUnusedElements.js +21 -11
  174. package/Source/Scene/ImageryLayer.js +2 -2
  175. package/Source/Scene/ImageryLayerCollection.js +2 -2
  176. package/Source/Scene/Implicit3DTileContent.js +179 -214
  177. package/Source/Scene/MVTDataProvider.js +147 -0
  178. package/Source/Scene/Material.js +1 -0
  179. package/Source/Scene/Model/EdgeVisibilityPipelineStage.js +79 -311
  180. package/Source/Scene/Model/Extensions/Gpm/GltfGpmLoader.js +4 -0
  181. package/Source/Scene/Model/Model.js +37 -0
  182. package/Source/Scene/Model/Model3DTileContent.js +424 -458
  183. package/Source/Scene/Model/ModelDrawCommand.js +31 -3
  184. package/Source/Scene/Model/ModelUtility.js +5 -0
  185. package/Source/Scene/Model/createVectorTileBuffersFromModelComponents.js +466 -150
  186. package/Source/Scene/ModelComponents.js +39 -1
  187. package/Source/Scene/Multiple3DTileContent.js +291 -334
  188. package/Source/Scene/Picking.js +5 -0
  189. package/Source/Scene/PntsParser.js +1 -0
  190. package/Source/Scene/QuadtreePrimitive.js +3 -2
  191. package/Source/Scene/ResourceCacheKey.js +5 -5
  192. package/Source/Scene/Scene.js +27 -0
  193. package/Source/Scene/Tileset3DTileContent.js +113 -146
  194. package/Source/Scene/UrlTemplate3DTilesDataProvider.js +499 -0
  195. package/Source/Scene/Vector3DTileContent.js +205 -234
  196. package/Source/Scene/VectorGltf3DTileContent.js +85 -36
  197. package/Source/Scene/VoxelPrimitive.js +159 -175
  198. package/Source/Scene/VoxelProvider.js +64 -91
  199. package/Source/Scene/buildVectorGltfFromMVT.js +1059 -0
  200. package/Source/Scene/buildVoxelCustomShader.js +199 -0
  201. package/Source/Scene/decodeMVT.js +634 -0
  202. package/Source/Scene/findMeshoptExtension.js +23 -0
  203. package/Source/Scene/renderBufferPointCollection.js +113 -62
  204. package/Source/Scene/renderBufferPolygonCollection.js +98 -55
  205. package/Source/Scene/renderBufferPolylineCollection.js +270 -143
  206. package/Source/Shaders/BufferPointMaterialFS.glsl +1 -0
  207. package/Source/Shaders/BufferPointMaterialFS.js +1 -0
  208. package/Source/Shaders/BufferPointMaterialVS.glsl +19 -9
  209. package/Source/Shaders/BufferPointMaterialVS.js +20 -10
  210. package/Source/Shaders/BufferPolygonMaterialVS.glsl +13 -4
  211. package/Source/Shaders/BufferPolygonMaterialVS.js +14 -5
  212. package/Source/Shaders/BufferPolylineMaterialVS.glsl +16 -2
  213. package/Source/Shaders/BufferPolylineMaterialVS.js +17 -3
  214. package/Source/Shaders/Builtin/Constants/passCesium3DTileEdgesDirect.glsl +9 -0
  215. package/Source/Shaders/Builtin/Constants/passCesium3DTileEdgesDirect.js +11 -0
  216. package/Source/Shaders/Builtin/Constants/passOverlay.glsl +1 -1
  217. package/Source/Shaders/Builtin/Constants/passOverlay.js +1 -1
  218. package/Source/Shaders/Builtin/CzmBuiltins.js +2 -0
  219. package/Source/Shaders/Model/EdgeVisibilityStageVS.glsl +0 -1
  220. package/Source/Shaders/Model/EdgeVisibilityStageVS.js +0 -1
  221. package/Source/Workers/decodeGoogleEarthEnterprisePacket.js +2 -2
  222. package/Source/Workers/incrementallyBuildTerrainPicker.js +2 -0
  223. package/index.d.ts +311 -288
  224. package/index.js +103 -92
  225. package/package.json +4 -4
@@ -0,0 +1,199 @@
1
+ // @ts-check
2
+
3
+ import Color from "../Core/Color.js";
4
+ import createColorRamp from "../Core/createColorRamp.js";
5
+ import CustomShader from "./Model/CustomShader.js";
6
+ import defined from "../Core/defined.js";
7
+ import MetadataComponentType from "./MetadataComponentType.js";
8
+ import MetadataType from "./MetadataType.js";
9
+ import TextureUniform from "./Model/TextureUniform.js";
10
+ import UniformType from "./Model/UniformType.js";
11
+
12
+ /** @import VoxelProvider from "./VoxelProvider.js"; */
13
+
14
+ /**
15
+ * Builds a custom shader for a voxel primitive based on information
16
+ * from the VoxelProvider about the metadata properties.
17
+ *
18
+ * Supports scalar float properties, or vec4 properties with float components.
19
+ *
20
+ * @function
21
+ *
22
+ * @param {VoxelProvider} provider The VoxelProvider for the primitive.
23
+ * @returns {CustomShader|undefined} A custom shader for the primitive, or undefined if a shader could not be constructed.
24
+ *
25
+ * @private
26
+ */
27
+ function buildVoxelCustomShader(provider) {
28
+ const { names, types, componentTypes, minimumValues, maximumValues } =
29
+ provider;
30
+
31
+ // Loop over metadata properties and build a shader for the first property
32
+ // that has a supported type and component type.
33
+ for (let i = 0; i < names.length; i++) {
34
+ if (!rangeIsValid(minimumValues?.[i], maximumValues?.[i])) {
35
+ continue;
36
+ }
37
+ const shader = constructMetadataShader(
38
+ names[i],
39
+ types[i],
40
+ componentTypes[i],
41
+ minimumValues[i],
42
+ maximumValues[i],
43
+ );
44
+ if (defined(shader)) {
45
+ return shader;
46
+ }
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Check if a range of values is valid for constructing a meaningful shader.
52
+ *
53
+ * @param {number[]} minimumValue The minimum value of the range.
54
+ * @param {number[]} maximumValue The maximum value of the range.
55
+ * @returns {boolean} True if the range is valid, false otherwise.
56
+ *
57
+ * @private
58
+ */
59
+ function rangeIsValid(minimumValue, maximumValue) {
60
+ if (!Array.isArray(minimumValue) || !Array.isArray(maximumValue)) {
61
+ return false;
62
+ }
63
+ const minimumComponent = Math.min(...minimumValue);
64
+ const maximumComponent = Math.max(...maximumValue);
65
+ return minimumComponent < maximumComponent;
66
+ }
67
+
68
+ /**
69
+ * Construct a metadata shader for a single metadata property.
70
+ *
71
+ * @param {string} name The name of the metadata property.
72
+ * @param {MetadataType} type The type of the metadata property.
73
+ * @param {MetadataComponentType} componentType The component type of the metadata property.
74
+ * @param {number[]} minimumValue The minimum value of the metadata property.
75
+ * @param {number[]} maximumValue The maximum value of the metadata property.
76
+ * @returns {CustomShader|undefined} A custom shader for the metadata property, or undefined if a shader could not be constructed.
77
+ *
78
+ * @private
79
+ */
80
+ function constructMetadataShader(
81
+ name,
82
+ type,
83
+ componentType,
84
+ minimumValue,
85
+ maximumValue,
86
+ ) {
87
+ if (
88
+ type === MetadataType.VEC4 &&
89
+ componentType === MetadataComponentType.FLOAT32
90
+ ) {
91
+ return buildColorShader(name, minimumValue, maximumValue);
92
+ } else if (
93
+ type === MetadataType.SCALAR &&
94
+ componentType === MetadataComponentType.FLOAT32
95
+ ) {
96
+ return buildColorMapShader(name, minimumValue, maximumValue);
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Build a color shader for a metadata property of type VEC4 and component type FLOAT32.
102
+ *
103
+ * @param {string} name The name of the metadata property.
104
+ * @param {number[]} minimumValue The minimum value of the metadata property.
105
+ * @param {number[]} maximumValue The maximum value of the metadata property.
106
+ * @returns {CustomShader|undefined} A custom shader for the metadata property, or undefined if a shader could not be constructed.
107
+ *
108
+ * @private
109
+ */
110
+ function buildColorShader(name, minimumValue, maximumValue) {
111
+ // Check if the values are in a range that would be meaningful to interpret as colors.
112
+ const minComponent = Math.min(...minimumValue);
113
+ const maxComponent = Math.max(...maximumValue);
114
+ if (minComponent < 0 || maxComponent > 1) {
115
+ // The data is out of the range expected for colors, so a color shader will be meaningless.
116
+ return;
117
+ }
118
+
119
+ return new CustomShader({
120
+ fragmentShaderText: `void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material)
121
+ {
122
+ material.diffuse = fsInput.metadata.${name}.rgb;
123
+ material.alpha = fsInput.metadata.${name}.a;
124
+ }`,
125
+ });
126
+ }
127
+
128
+ /**
129
+ * Build a color map shader for a metadata property of type SCALAR and component type FLOAT32.
130
+ *
131
+ * @param {string} name The name of the metadata property.
132
+ * @param {number[]} minimumValue The minimum value of the metadata property.
133
+ * @param {number[]} maximumValue The maximum value of the metadata property.
134
+ * @returns {CustomShader} A custom shader for the metadata property.
135
+ *
136
+ * @private
137
+ */
138
+ function buildColorMapShader(name, minimumValue, maximumValue) {
139
+ // Perceptually uniform color map similar to the "viridis" color map used in scientific visualization.
140
+ const colorMapWidth = 128;
141
+ const colorMap = createColorRamp(
142
+ [
143
+ new Color(0.267, 0.004, 0.329),
144
+ new Color(0.282, 0.14, 0.457),
145
+ new Color(0.254, 0.265, 0.53),
146
+ new Color(0.207, 0.372, 0.553),
147
+ new Color(0.164, 0.471, 0.558),
148
+ new Color(0.128, 0.567, 0.551),
149
+ new Color(0.135, 0.659, 0.518),
150
+ new Color(0.194, 0.741, 0.443),
151
+ new Color(0.282, 0.819, 0.369),
152
+ new Color(0.396, 0.898, 0.301),
153
+ new Color(0.538, 0.965, 0.236),
154
+ new Color(0.741, 0.998, 0.149),
155
+ new Color(0.993, 1.0, 0.144),
156
+ ],
157
+ colorMapWidth,
158
+ );
159
+
160
+ const textureUniform = new TextureUniform({
161
+ typedArray: colorMap,
162
+ width: colorMapWidth,
163
+ height: 1,
164
+ });
165
+
166
+ return new CustomShader({
167
+ uniforms: {
168
+ u_colorMap: {
169
+ type: UniformType.SAMPLER_2D,
170
+ value: textureUniform,
171
+ },
172
+ // The starting values are also available in the shader from the metadata statistics.
173
+ // But by using uniforms, we enable later dynamic changes to the range.
174
+ u_minimumValue: {
175
+ type: UniformType.FLOAT,
176
+ value: minimumValue[0],
177
+ },
178
+ u_maximumValue: {
179
+ type: UniformType.FLOAT,
180
+ value: maximumValue[0],
181
+ },
182
+ },
183
+ fragmentShaderText: `void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material)
184
+ {
185
+ float value = fsInput.metadata.${name};
186
+ vec3 voxelNormal = fsInput.attributes.normalEC;
187
+ float diffuse = max(0.0, dot(voxelNormal, czm_lightDirectionEC));
188
+ float lighting = 0.5 + 0.5 * diffuse;
189
+
190
+ if (value >= u_minimumValue && value <= u_maximumValue) {
191
+ float lerp = (value - u_minimumValue) / (u_maximumValue - u_minimumValue);
192
+ material.diffuse = texture(u_colorMap, vec2(lerp, 0.5)).rgb * lighting;
193
+ material.alpha = 1.0;
194
+ }
195
+ }`,
196
+ });
197
+ }
198
+
199
+ export default buildVoxelCustomShader;