@cesium/engine 12.0.1 → 13.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 (161) hide show
  1. package/Build/Workers/{chunk-7D6T2WYT.js → chunk-2ONAV62A.js} +14 -47
  2. package/Build/Workers/{chunk-MV7YO647.js → chunk-2SRHVCFD.js} +6 -6
  3. package/Build/Workers/{chunk-ZPTNVB3S.js → chunk-3SCCWLZS.js} +34 -8
  4. package/Build/Workers/{chunk-7CKQ7PVJ.js → chunk-54I6VSRP.js} +6 -6
  5. package/Build/Workers/{chunk-XDJ7V4NZ.js → chunk-5I3LPAS7.js} +5 -5
  6. package/Build/Workers/{chunk-GSJ6LWIS.js → chunk-5ICYLS6B.js} +35 -21
  7. package/Build/Workers/{chunk-BH5M522L.js → chunk-5JY4LYO3.js} +7 -7
  8. package/Build/Workers/{chunk-DR56WFYZ.js → chunk-APCS5YJI.js} +7 -7
  9. package/Build/Workers/{chunk-COHL4R3G.js → chunk-AXYZUG4N.js} +1 -1
  10. package/Build/Workers/{chunk-2IJZVFHY.js → chunk-B34JXFHF.js} +5 -5
  11. package/Build/Workers/{chunk-54NYY4U4.js → chunk-B6IJY6AN.js} +7 -7
  12. package/Build/Workers/{chunk-H3RMGG7L.js → chunk-BMFWWTD7.js} +5 -5
  13. package/Build/Workers/{chunk-PJHRB4YJ.js → chunk-CBE4HRBH.js} +7 -7
  14. package/Build/Workers/{chunk-U7SH6OK7.js → chunk-CNPP6TQ2.js} +4 -4
  15. package/Build/Workers/{chunk-2XOUWNPN.js → chunk-DWIKWWEE.js} +5 -5
  16. package/Build/Workers/{chunk-PNA47CR7.js → chunk-EHGQQA7C.js} +1 -1
  17. package/Build/Workers/{chunk-7EBHNJTG.js → chunk-EJ5DT5BP.js} +1 -1
  18. package/Build/Workers/{chunk-3Y4UGAYI.js → chunk-EYZFEJX3.js} +6 -6
  19. package/Build/Workers/{chunk-EMCXAVSG.js → chunk-FNCXBBCF.js} +2 -2
  20. package/Build/Workers/{chunk-NL73INJS.js → chunk-GIOZHX7U.js} +2 -2
  21. package/Build/Workers/{chunk-VHGI7D3P.js → chunk-GSLKQJM2.js} +10 -10
  22. package/Build/Workers/{chunk-647NL6VU.js → chunk-HI73PIPQ.js} +2 -2
  23. package/Build/Workers/{chunk-GRQQHWMD.js → chunk-IP7F2MVW.js} +7 -7
  24. package/Build/Workers/{chunk-LBNGHEJY.js → chunk-IXNXKVOB.js} +4 -4
  25. package/Build/Workers/{chunk-2F42VIW6.js → chunk-J7BMSSY7.js} +13 -13
  26. package/Build/Workers/{chunk-PH3T7LNP.js → chunk-K62EHZFT.js} +15 -15
  27. package/Build/Workers/{chunk-GBPW65E3.js → chunk-K6SQV4IS.js} +6 -6
  28. package/Build/Workers/{chunk-WMHJAREU.js → chunk-KO232FLP.js} +2 -2
  29. package/Build/Workers/{chunk-AER5CLXD.js → chunk-KRVALCCI.js} +5 -5
  30. package/Build/Workers/{chunk-22FZ334F.js → chunk-LFUFGHL3.js} +10 -10
  31. package/Build/Workers/{chunk-AGYO4ZSF.js → chunk-LQT2ZK7D.js} +17 -17
  32. package/Build/Workers/{chunk-KJ65M35B.js → chunk-M2AA2ARJ.js} +11 -11
  33. package/Build/Workers/{chunk-YT5PQMSP.js → chunk-MGABCOOH.js} +6 -6
  34. package/Build/Workers/{chunk-JPNFQRN7.js → chunk-NQDKNE7V.js} +13 -13
  35. package/Build/Workers/{chunk-IJWXYSFC.js → chunk-OARMSJUU.js} +2 -2
  36. package/Build/Workers/{chunk-K7QC3WDT.js → chunk-OGRXNUR2.js} +1 -1
  37. package/Build/Workers/{chunk-KKMH4BKN.js → chunk-OZTFRHA2.js} +6 -6
  38. package/Build/Workers/{chunk-DJ7K7EYK.js → chunk-PBJQFLKS.js} +11 -11
  39. package/Build/Workers/{chunk-ETXXXGMP.js → chunk-PM76TX2X.js} +6 -6
  40. package/Build/Workers/{chunk-PISTPJXS.js → chunk-PTFIVVLX.js} +12 -12
  41. package/Build/Workers/{chunk-VXVQITFC.js → chunk-R2KGFZBA.js} +13 -13
  42. package/Build/Workers/{chunk-VO4SXJXT.js → chunk-S3UM4OKP.js} +7 -7
  43. package/Build/Workers/{chunk-NELAPOO6.js → chunk-SAKQO5NX.js} +2 -2
  44. package/Build/Workers/{chunk-ENARO52I.js → chunk-T34EOLFR.js} +14 -14
  45. package/Build/Workers/{chunk-X6YBZOOA.js → chunk-THDHWSEJ.js} +4 -4
  46. package/Build/Workers/{chunk-LVHHB5T6.js → chunk-TOHDFUJM.js} +4 -4
  47. package/Build/Workers/{chunk-Q7IIOKAT.js → chunk-UBAHTE4Q.js} +1 -1
  48. package/Build/Workers/{chunk-IAX6MIST.js → chunk-WAJNX74N.js} +17 -17
  49. package/Build/Workers/{chunk-76KRKKEF.js → chunk-WE4KF4AM.js} +9 -9
  50. package/Build/Workers/{chunk-JAKTB6CE.js → chunk-WUIDEXAN.js} +7 -7
  51. package/Build/Workers/{chunk-IVCFTVYW.js → chunk-YVGU235V.js} +4 -4
  52. package/Build/Workers/{chunk-ZCCI55EY.js → chunk-ZWSWJYJP.js} +13 -13
  53. package/Build/Workers/combineGeometry.js +22 -22
  54. package/Build/Workers/createBoxGeometry.js +16 -16
  55. package/Build/Workers/createBoxOutlineGeometry.js +14 -14
  56. package/Build/Workers/createCircleGeometry.js +24 -24
  57. package/Build/Workers/createCircleOutlineGeometry.js +17 -17
  58. package/Build/Workers/createCoplanarPolygonGeometry.js +31 -31
  59. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +29 -29
  60. package/Build/Workers/createCorridorGeometry.js +27 -27
  61. package/Build/Workers/createCorridorOutlineGeometry.js +26 -26
  62. package/Build/Workers/createCylinderGeometry.js +18 -18
  63. package/Build/Workers/createCylinderOutlineGeometry.js +16 -16
  64. package/Build/Workers/createEllipseGeometry.js +24 -24
  65. package/Build/Workers/createEllipseOutlineGeometry.js +17 -17
  66. package/Build/Workers/createEllipsoidGeometry.js +17 -17
  67. package/Build/Workers/createEllipsoidOutlineGeometry.js +16 -16
  68. package/Build/Workers/createFrustumGeometry.js +16 -16
  69. package/Build/Workers/createFrustumOutlineGeometry.js +16 -16
  70. package/Build/Workers/createGeometry.js +22 -22
  71. package/Build/Workers/createGroundPolylineGeometry.js +20 -20
  72. package/Build/Workers/createPlaneGeometry.js +14 -14
  73. package/Build/Workers/createPlaneOutlineGeometry.js +13 -13
  74. package/Build/Workers/createPolygonGeometry.js +30 -30
  75. package/Build/Workers/createPolygonOutlineGeometry.js +28 -28
  76. package/Build/Workers/createPolylineGeometry.js +23 -23
  77. package/Build/Workers/createPolylineVolumeGeometry.js +31 -32
  78. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +25 -25
  79. package/Build/Workers/createRectangleGeometry.js +25 -25
  80. package/Build/Workers/createRectangleOutlineGeometry.js +18 -18
  81. package/Build/Workers/createSimplePolylineGeometry.js +21 -21
  82. package/Build/Workers/createSphereGeometry.js +17 -17
  83. package/Build/Workers/createSphereOutlineGeometry.js +16 -16
  84. package/Build/Workers/createTaskProcessorWorker.js +3 -3
  85. package/Build/Workers/createVectorTileClampedPolylines.js +13 -13
  86. package/Build/Workers/createVectorTileGeometries.js +22 -22
  87. package/Build/Workers/createVectorTilePoints.js +12 -12
  88. package/Build/Workers/createVectorTilePolygons.js +20 -20
  89. package/Build/Workers/createVectorTilePolylines.js +13 -13
  90. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +20 -20
  91. package/Build/Workers/createVerticesFromHeightmap.js +20 -20
  92. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +17 -17
  93. package/Build/Workers/createWallGeometry.js +22 -22
  94. package/Build/Workers/createWallOutlineGeometry.js +21 -21
  95. package/Build/Workers/decodeDraco.js +11 -11
  96. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +5 -5
  97. package/Build/Workers/decodeI3S.js +10 -10
  98. package/Build/Workers/transcodeKTX2.js +7 -7
  99. package/Build/Workers/transferTypedArrayTest.js +1 -1
  100. package/Build/Workers/upsampleQuantizedTerrainMesh.js +20 -20
  101. package/Source/Core/BingMapsGeocoderService.js +2 -0
  102. package/Source/Core/Check.d.ts +2 -1
  103. package/Source/Core/GoogleGeocoderService.js +110 -0
  104. package/Source/Core/ITwinPlatform.js +324 -0
  105. package/Source/Core/Ion.js +1 -1
  106. package/Source/Core/IonGeocodeProviderType.js +33 -0
  107. package/Source/Core/IonGeocoderService.js +72 -0
  108. package/Source/Core/JulianDate.js +14 -7
  109. package/Source/Core/Rectangle.js +0 -20
  110. package/Source/Core/TrackingReferenceFrame.js +45 -0
  111. package/Source/Core/defined.d.ts +11 -0
  112. package/Source/DataSources/Entity.js +15 -1
  113. package/Source/DataSources/EntityView.js +55 -4
  114. package/Source/DataSources/ModelGraphics.js +23 -1
  115. package/Source/DataSources/ModelVisualizer.js +22 -1
  116. package/Source/DataSources/SampledProperty.js +24 -0
  117. package/Source/Renderer/ContextLimits.js +1 -1
  118. package/Source/Renderer/Texture.js +104 -92
  119. package/Source/Scene/ArcGisMapService.js +1 -1
  120. package/Source/Scene/Cesium3DTileset.js +1 -1
  121. package/Source/Scene/Cesium3DTilesetStatistics.js +109 -42
  122. package/Source/Scene/DerivedCommand.js +109 -16
  123. package/Source/Scene/DynamicEnvironmentMapManager.js +202 -65
  124. package/Source/Scene/GltfTextureLoader.js +16 -1
  125. package/Source/Scene/ITwinData.js +208 -0
  126. package/Source/Scene/Label.js +17 -3
  127. package/Source/Scene/MetadataClassProperty.js +26 -0
  128. package/Source/Scene/MetadataPicking.js +108 -17
  129. package/Source/Scene/MetadataType.js +20 -0
  130. package/Source/Scene/Model/Extensions/Gpm/GltfMeshPrimitiveGpmLoader.js +6 -11
  131. package/Source/Scene/Model/Model.js +1 -1
  132. package/Source/Scene/Model/Model3DTileContent.js +23 -1
  133. package/Source/Scene/Model/ModelStatistics.js +33 -5
  134. package/Source/Scene/Model/PointCloudStylingPipelineStage.js +2 -1
  135. package/Source/Scene/PickedMetadataInfo.js +21 -3
  136. package/Source/Scene/Picking.js +7 -1
  137. package/Source/Scene/PostProcessStage.js +14 -17
  138. package/Source/Scene/PostProcessStageCollection.js +4 -16
  139. package/Source/Scene/PostProcessStageLibrary.js +13 -51
  140. package/Source/Scene/PropertyAttributeProperty.js +15 -3
  141. package/Source/Scene/PropertyTextureProperty.js +12 -0
  142. package/Source/Scene/Scene.js +17 -2
  143. package/Source/Scene/SkyBox.js +23 -4
  144. package/Source/Scene/UrlTemplateImageryProvider.js +5 -5
  145. package/Source/Scene/createGooglePhotorealistic3DTileset.js +55 -16
  146. package/Source/Scene/getMetadataProperty.js +48 -0
  147. package/Source/Shaders/Builtin/Functions/reverseLogDepth.glsl +1 -1
  148. package/Source/Shaders/Builtin/Functions/reverseLogDepth.js +1 -1
  149. package/Source/Shaders/ConvolveSpecularMapFS.glsl +1 -1
  150. package/Source/Shaders/ConvolveSpecularMapFS.js +1 -1
  151. package/Source/Shaders/DepthPlaneVS.glsl +1 -1
  152. package/Source/Shaders/DepthPlaneVS.js +1 -1
  153. package/Source/Shaders/Model/ModelFS.glsl +7 -0
  154. package/Source/Shaders/Model/ModelFS.js +7 -0
  155. package/Source/Shaders/Model/ModelVS.glsl +9 -1
  156. package/Source/Shaders/Model/ModelVS.js +9 -1
  157. package/Source/Shaders/PostProcessStages/AmbientOcclusionGenerate.glsl +66 -37
  158. package/Source/Shaders/PostProcessStages/AmbientOcclusionGenerate.js +66 -37
  159. package/index.d.ts +295 -42
  160. package/index.js +67 -61
  161. package/package.json +1 -1
@@ -1,4 +1,5 @@
1
1
  import defined from "../Core/defined.js";
2
+ import Model3DTileContent from "./Model/Model3DTileContent.js";
2
3
 
3
4
  /**
4
5
  * @private
@@ -29,6 +30,7 @@ function Cesium3DTilesetStatistics() {
29
30
  // Memory statistics
30
31
  this.geometryByteLength = 0;
31
32
  this.texturesByteLength = 0;
33
+ this.texturesReferenceCounterById = {};
32
34
  this.batchTableByteLength = 0; // batch textures and any binary metadata properties not otherwise accounted for
33
35
  }
34
36
 
@@ -45,61 +47,123 @@ Cesium3DTilesetStatistics.prototype.clear = function () {
45
47
  this.numberOfTilesCulledWithChildrenUnion = 0;
46
48
  };
47
49
 
48
- function updatePointAndFeatureCounts(statistics, content, decrement, load) {
50
+ /**
51
+ * Increment the counters for the points, triangles, and features
52
+ * that are currently selected for rendering.
53
+ *
54
+ * This will be called recursively for the given content and
55
+ * all its inner contents
56
+ *
57
+ * @param {Cesium3DTileContent} content
58
+ */
59
+ Cesium3DTilesetStatistics.prototype.incrementSelectionCounts = function (
60
+ content,
61
+ ) {
62
+ this.numberOfFeaturesSelected += content.featuresLength;
63
+ this.numberOfPointsSelected += content.pointsLength;
64
+ this.numberOfTrianglesSelected += content.trianglesLength;
65
+
66
+ // Recursive calls on all inner contents
49
67
  const contents = content.innerContents;
50
- const pointsLength = content.pointsLength;
51
- const trianglesLength = content.trianglesLength;
52
- const featuresLength = content.featuresLength;
53
- const geometryByteLength = content.geometryByteLength;
54
- const texturesByteLength = content.texturesByteLength;
55
- const batchTableByteLength = content.batchTableByteLength;
68
+ if (defined(contents)) {
69
+ const length = contents.length;
70
+ for (let i = 0; i < length; ++i) {
71
+ this.incrementSelectionCounts(contents[i]);
72
+ }
73
+ }
74
+ };
56
75
 
57
- if (load) {
58
- statistics.numberOfFeaturesLoaded += decrement
59
- ? -featuresLength
60
- : featuresLength;
61
- statistics.numberOfPointsLoaded += decrement ? -pointsLength : pointsLength;
62
- statistics.geometryByteLength += decrement
63
- ? -geometryByteLength
64
- : geometryByteLength;
65
- statistics.texturesByteLength += decrement
66
- ? -texturesByteLength
67
- : texturesByteLength;
68
- statistics.batchTableByteLength += decrement
69
- ? -batchTableByteLength
70
- : batchTableByteLength;
76
+ /**
77
+ * Increment the counters for the number of features and points that
78
+ * are currently loaded, and the lengths (size in bytes) of the
79
+ * occupied memory.
80
+ *
81
+ * This will be called recursively for the given content and
82
+ * all its inner contents
83
+ *
84
+ * @param {Cesium3DTileContent} content
85
+ */
86
+ Cesium3DTilesetStatistics.prototype.incrementLoadCounts = function (content) {
87
+ this.numberOfFeaturesLoaded += content.featuresLength;
88
+ this.numberOfPointsLoaded += content.pointsLength;
89
+ this.geometryByteLength += content.geometryByteLength;
90
+ this.batchTableByteLength += content.batchTableByteLength;
91
+
92
+ // When the content is not a `Model3DTileContent`, then its
93
+ // textures byte length is added directly
94
+ if (!(content instanceof Model3DTileContent)) {
95
+ this.texturesByteLength += content.texturesByteLength;
71
96
  } else {
72
- statistics.numberOfFeaturesSelected += decrement
73
- ? -featuresLength
74
- : featuresLength;
75
- statistics.numberOfPointsSelected += decrement
76
- ? -pointsLength
77
- : pointsLength;
78
- statistics.numberOfTrianglesSelected += decrement
79
- ? -trianglesLength
80
- : trianglesLength;
97
+ // When the content is a `Model3DTileContent`, then increment the
98
+ // reference counter for all its textures. The byte length of any
99
+ // newly tracked texture to the total textures byte length
100
+ const textureIds = content.getTextureIds();
101
+ for (const textureId of textureIds) {
102
+ const referenceCounter =
103
+ this.texturesReferenceCounterById[textureId] ?? 0;
104
+ if (referenceCounter === 0) {
105
+ const textureByteLength = content.getTextureByteLengthById(textureId);
106
+ this.texturesByteLength += textureByteLength;
107
+ }
108
+ this.texturesReferenceCounterById[textureId] = referenceCounter + 1;
109
+ }
81
110
  }
82
111
 
112
+ // Recursive calls on all inner contents
113
+ const contents = content.innerContents;
83
114
  if (defined(contents)) {
84
115
  const length = contents.length;
85
116
  for (let i = 0; i < length; ++i) {
86
- updatePointAndFeatureCounts(statistics, contents[i], decrement, load);
117
+ this.incrementLoadCounts(contents[i]);
87
118
  }
88
119
  }
89
- }
90
-
91
- Cesium3DTilesetStatistics.prototype.incrementSelectionCounts = function (
92
- content,
93
- ) {
94
- updatePointAndFeatureCounts(this, content, false, false);
95
- };
96
-
97
- Cesium3DTilesetStatistics.prototype.incrementLoadCounts = function (content) {
98
- updatePointAndFeatureCounts(this, content, false, true);
99
120
  };
100
121
 
122
+ /**
123
+ * Decrement the counters for the number of features and points that
124
+ * are currently loaded, and the lengths (size in bytes) of the
125
+ * occupied memory.
126
+ *
127
+ * This will be called recursively for the given content and
128
+ * all its inner contents
129
+ *
130
+ * @param {Cesium3DTileContent} content
131
+ */
101
132
  Cesium3DTilesetStatistics.prototype.decrementLoadCounts = function (content) {
102
- updatePointAndFeatureCounts(this, content, true, true);
133
+ this.numberOfFeaturesLoaded -= content.featuresLength;
134
+ this.numberOfPointsLoaded -= content.pointsLength;
135
+ this.geometryByteLength -= content.geometryByteLength;
136
+ this.batchTableByteLength -= content.batchTableByteLength;
137
+
138
+ // When the content is not a `Model3DTileContent`, then its
139
+ // textures byte length is subtracted directly
140
+ if (!(content instanceof Model3DTileContent)) {
141
+ this.texturesByteLength -= content.texturesByteLength;
142
+ } else {
143
+ // When the content is a `Model3DTileContent`, then decrement the
144
+ // reference counter for all its textures. The byte length of any
145
+ // texture that is no longer references is subtracted from the
146
+ // total textures byte length
147
+ const textureIds = content.getTextureIds();
148
+ for (const textureId of textureIds) {
149
+ const referenceCounter = this.texturesReferenceCounterById[textureId];
150
+ if (referenceCounter === 1) {
151
+ delete this.texturesReferenceCounterById[textureId];
152
+ const textureByteLength = content.getTextureByteLengthById(textureId);
153
+ this.texturesByteLength -= textureByteLength;
154
+ } else {
155
+ this.texturesReferenceCounterById[textureId] = referenceCounter - 1;
156
+ }
157
+ }
158
+ }
159
+ // Recursive calls on all inner contents
160
+ const contents = content.innerContents;
161
+ if (defined(contents)) {
162
+ const length = contents.length;
163
+ for (let i = 0; i < length; ++i) {
164
+ this.decrementLoadCounts(contents[i]);
165
+ }
166
+ }
103
167
  };
104
168
 
105
169
  Cesium3DTilesetStatistics.clone = function (statistics, result) {
@@ -124,6 +188,9 @@ Cesium3DTilesetStatistics.clone = function (statistics, result) {
124
188
  statistics.numberOfTilesCulledWithChildrenUnion;
125
189
  result.geometryByteLength = statistics.geometryByteLength;
126
190
  result.texturesByteLength = statistics.texturesByteLength;
191
+ result.texturesReferenceCounterById = {
192
+ ...statistics.texturesReferenceCounterById,
193
+ };
127
194
  result.batchTableByteLength = statistics.batchTableByteLength;
128
195
  };
129
196
  export default Cesium3DTilesetStatistics;
@@ -1,3 +1,4 @@
1
+ import { MetadataComponentType } from "@cesium/engine";
1
2
  import defined from "../Core/defined.js";
2
3
  import DrawCommand from "../Renderer/DrawCommand.js";
3
4
  import RenderState from "../Renderer/RenderState.js";
@@ -416,6 +417,98 @@ function getGlslType(classProperty) {
416
417
  return `ivec${componentCount}`;
417
418
  }
418
419
 
420
+ /**
421
+ * Returns a shader statement that applies the inverse of the
422
+ * value transform to the given value, based on the given offset
423
+ * and scale.
424
+ *
425
+ * @param {string} input The input value
426
+ * @param {string} offset The offset
427
+ * @param {string} scale The scale
428
+ * @returns {string} The statement
429
+ */
430
+ function unapplyValueTransform(input, offset, scale) {
431
+ return `((${input} - float(${offset})) / float(${scale}))`;
432
+ }
433
+
434
+ /**
435
+ * Returns a shader statement that applies the inverse of the
436
+ * normalization, based on the given component type
437
+ *
438
+ * @param {string} input The input value
439
+ * @param {string} componentType The component type
440
+ * @returns {string} The statement
441
+ */
442
+ function unnormalize(input, componentType) {
443
+ const max = MetadataComponentType.getMaximum(componentType);
444
+ return `(${input}) / float(${max})`;
445
+ }
446
+
447
+ /**
448
+ * Creates a shader statement that returns the value of the specified
449
+ * property, normalized to the range [0, 1].
450
+ *
451
+ * @param {MetadataClassProperty} classProperty The class property
452
+ * @param {object} metadataProperty The metadata property, either
453
+ * a `PropertyTextureProperty` or a `PropertyAttributeProperty`
454
+ * @returns {string} The string
455
+ */
456
+ function getSourceValueStringScalar(classProperty, metadataProperty) {
457
+ let result = `float(value)`;
458
+
459
+ // The 'hasValueTransform' indicates whether the property
460
+ // (or its class property) did define an 'offset' or 'scale'.
461
+ // Even when they had not been defined in the JSON, they are
462
+ // defined in the object, with default values.
463
+ if (metadataProperty.hasValueTransform) {
464
+ const offset = metadataProperty.offset;
465
+ const scale = metadataProperty.scale;
466
+ result = unapplyValueTransform(result, offset, scale);
467
+ }
468
+ if (!classProperty.normalized) {
469
+ result = unnormalize(result, classProperty.componentType);
470
+ }
471
+ return result;
472
+ }
473
+
474
+ /**
475
+ * Creates a shader statement that returns the value of the specified
476
+ * component of the given property, normalized to the range [0, 1].
477
+ *
478
+ * @param {MetadataClassProperty} classProperty The class property
479
+ * @param {object} metadataProperty The metadata property, either
480
+ * a `PropertyTextureProperty` or a `PropertyAttributeProperty`
481
+ * @param {string} componentName The name, in ["x", "y", "z", "w"]
482
+ * @returns {string} The string
483
+ */
484
+ function getSourceValueStringComponent(
485
+ classProperty,
486
+ metadataProperty,
487
+ componentName,
488
+ ) {
489
+ const valueString = `value.${componentName}`;
490
+ let result = `float(${valueString})`;
491
+
492
+ // The 'hasValueTransform' indicates whether the property
493
+ // (or its class property) did define an 'offset' or 'scale'.
494
+ // Even when they had not been defined in the JSON, they are
495
+ // defined in the object, with default values
496
+ // Note that in the 'PropertyTextureProperty' and the
497
+ // 'PropertyAttributeProperty', these values are
498
+ // stored as "object types" (like 'Cartesian2'), whereas
499
+ // in the 'MetadataClassProperty', they are stored as
500
+ // "array types", e.g. a `[number, number]`
501
+ if (metadataProperty.hasValueTransform) {
502
+ const offset = metadataProperty.offset[componentName];
503
+ const scale = metadataProperty.scale[componentName];
504
+ result = unapplyValueTransform(result, offset, scale);
505
+ }
506
+ if (!classProperty.normalized) {
507
+ result = unnormalize(result, classProperty.componentType);
508
+ }
509
+ return result;
510
+ }
511
+
419
512
  /**
420
513
  * Creates a new `ShaderProgram` from the given input that renders metadata
421
514
  * values into the frame buffer, according to the given picked metadata info.
@@ -452,34 +545,34 @@ function getPickMetadataShaderProgram(
452
545
  return shader;
453
546
  }
454
547
 
548
+ const metadataProperty = pickedMetadataInfo.metadataProperty;
455
549
  const classProperty = pickedMetadataInfo.classProperty;
456
550
  const glslType = getGlslType(classProperty);
457
551
 
458
552
  // Define the components that will go into the output `metadataValues`.
553
+ // This will be the 'color' that is written into the frame buffer,
554
+ // meaning that the values should be in [0.0, 1.0], and will become
555
+ // values in [0, 255] in the frame buffer.
459
556
  // By default, all of them are 0.0.
460
557
  const sourceValueStrings = ["0.0", "0.0", "0.0", "0.0"];
461
558
  const componentCount = getComponentCount(classProperty);
462
559
  if (componentCount === 1) {
463
- // When the property is a scalar, store its value directly
464
- // in `metadataValues.x`
465
- sourceValueStrings[0] = `float(value)`;
560
+ // When the property is a scalar, store the source value
561
+ // string directly in `metadataValues.x`
562
+ sourceValueStrings[0] = getSourceValueStringScalar(
563
+ classProperty,
564
+ metadataProperty,
565
+ );
466
566
  } else {
467
567
  // When the property is an array, store the array elements
468
568
  // in `metadataValues.x/y/z/w`
469
- const components = ["x", "y", "z", "w"];
470
- for (let i = 0; i < componentCount; i++) {
471
- const component = components[i];
472
- const valueString = `value.${component}`;
473
- sourceValueStrings[i] = `float(${valueString})`;
474
- }
475
- }
476
-
477
- // Make sure that the `metadataValues` components are all in
478
- // the range [0, 1] (which will result in RGBA components
479
- // in [0, 255] during rendering)
480
- if (!classProperty.normalized) {
569
+ const componentNames = ["x", "y", "z", "w"];
481
570
  for (let i = 0; i < componentCount; i++) {
482
- sourceValueStrings[i] += " / 255.0";
571
+ sourceValueStrings[i] = getSourceValueStringComponent(
572
+ classProperty,
573
+ metadataProperty,
574
+ componentNames[i],
575
+ );
483
576
  }
484
577
  }
485
578