@loaders.gl/3d-tiles 4.2.0-alpha.4 → 4.2.0-alpha.5

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 (141) hide show
  1. package/dist/3d-tiles-archive/3d-tiles-archive-archive.js +66 -41
  2. package/dist/3d-tiles-archive/3d-tiles-archive-parser.d.ts +1 -1
  3. package/dist/3d-tiles-archive/3d-tiles-archive-parser.d.ts.map +1 -1
  4. package/dist/3d-tiles-archive/3d-tiles-archive-parser.js +26 -16
  5. package/dist/3d-tiles-archive-loader.js +25 -14
  6. package/dist/cesium-ion-loader.js +34 -30
  7. package/dist/dist.dev.js +1963 -1037
  8. package/dist/dist.min.js +32 -0
  9. package/dist/index.cjs +122 -337
  10. package/dist/index.cjs.map +7 -0
  11. package/dist/index.d.ts +13 -13
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +7 -1
  14. package/dist/lib/classes/helpers/tile-3d-accessor-utils.js +103 -87
  15. package/dist/lib/classes/tile-3d-batch-table-hierarchy.js +179 -155
  16. package/dist/lib/classes/tile-3d-batch-table.js +232 -217
  17. package/dist/lib/classes/tile-3d-feature-table.js +62 -59
  18. package/dist/lib/constants.js +19 -15
  19. package/dist/lib/encoders/encode-3d-tile-batched-model.js +40 -35
  20. package/dist/lib/encoders/encode-3d-tile-composite.js +19 -17
  21. package/dist/lib/encoders/encode-3d-tile-instanced-model.js +32 -31
  22. package/dist/lib/encoders/encode-3d-tile-point-cloud.js +31 -32
  23. package/dist/lib/encoders/encode-3d-tile.js +23 -19
  24. package/dist/lib/encoders/helpers/encode-3d-tile-header.js +23 -23
  25. package/dist/lib/ion/ion.js +55 -54
  26. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.d.ts +1 -1
  27. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.d.ts.map +1 -1
  28. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js +57 -51
  29. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.d.ts +1 -1
  30. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.d.ts.map +1 -1
  31. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js +21 -18
  32. package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js +35 -20
  33. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts +4 -4
  34. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts.map +1 -1
  35. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js +269 -234
  36. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts +2 -2
  37. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts.map +1 -1
  38. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js +83 -55
  39. package/dist/lib/parsers/helpers/parse-3d-tile-header.d.ts +1 -1
  40. package/dist/lib/parsers/helpers/parse-3d-tile-header.d.ts.map +1 -1
  41. package/dist/lib/parsers/helpers/parse-3d-tile-header.js +23 -14
  42. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts +1 -1
  43. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts.map +1 -1
  44. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js +82 -54
  45. package/dist/lib/parsers/helpers/parse-3d-tile-tables.d.ts +2 -2
  46. package/dist/lib/parsers/helpers/parse-3d-tile-tables.d.ts.map +1 -1
  47. package/dist/lib/parsers/helpers/parse-3d-tile-tables.js +79 -68
  48. package/dist/lib/parsers/helpers/parse-utils.js +19 -14
  49. package/dist/lib/parsers/parse-3d-tile-batched-model.d.ts +2 -2
  50. package/dist/lib/parsers/parse-3d-tile-batched-model.d.ts.map +1 -1
  51. package/dist/lib/parsers/parse-3d-tile-batched-model.js +21 -17
  52. package/dist/lib/parsers/parse-3d-tile-composite.d.ts +2 -2
  53. package/dist/lib/parsers/parse-3d-tile-composite.d.ts.map +1 -1
  54. package/dist/lib/parsers/parse-3d-tile-composite.js +18 -14
  55. package/dist/lib/parsers/parse-3d-tile-gltf.d.ts +2 -2
  56. package/dist/lib/parsers/parse-3d-tile-gltf.d.ts.map +1 -1
  57. package/dist/lib/parsers/parse-3d-tile-gltf.js +22 -14
  58. package/dist/lib/parsers/parse-3d-tile-header.d.ts +2 -2
  59. package/dist/lib/parsers/parse-3d-tile-header.d.ts.map +1 -1
  60. package/dist/lib/parsers/parse-3d-tile-header.js +168 -159
  61. package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts +2 -2
  62. package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts.map +1 -1
  63. package/dist/lib/parsers/parse-3d-tile-instanced-model.js +153 -123
  64. package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts +2 -2
  65. package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts.map +1 -1
  66. package/dist/lib/parsers/parse-3d-tile-point-cloud.js +380 -174
  67. package/dist/lib/parsers/parse-3d-tile.d.ts +2 -2
  68. package/dist/lib/parsers/parse-3d-tile.d.ts.map +1 -1
  69. package/dist/lib/parsers/parse-3d-tile.js +24 -24
  70. package/dist/lib/utils/obb/s2-corners-to-obb.js +29 -16
  71. package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts +1 -1
  72. package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts.map +1 -1
  73. package/dist/lib/utils/s2/converters/s2-to-boundary.js +55 -35
  74. package/dist/lib/utils/s2/converters/s2-to-obb-points.js +31 -20
  75. package/dist/lib/utils/s2/converters/s2-to-region.d.ts +1 -1
  76. package/dist/lib/utils/s2/converters/s2-to-region.d.ts.map +1 -1
  77. package/dist/lib/utils/s2/converters/s2-to-region.js +51 -35
  78. package/dist/lib/utils/s2/index.d.ts +7 -7
  79. package/dist/lib/utils/s2/index.d.ts.map +1 -1
  80. package/dist/lib/utils/s2/index.js +3 -1
  81. package/dist/lib/utils/s2/s2-geometry-functions.js +19 -5
  82. package/dist/lib/utils/s2/s2-token-functions.js +51 -22
  83. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts +1 -1
  84. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts.map +1 -1
  85. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js +23 -9
  86. package/dist/lib/utils/s2/s2geometry/s2-geometry.js +218 -157
  87. package/dist/lib/utils/version.js +3 -1
  88. package/dist/tile-3d-subtree-loader.d.ts +1 -1
  89. package/dist/tile-3d-subtree-loader.d.ts.map +1 -1
  90. package/dist/tile-3d-subtree-loader.js +15 -10
  91. package/dist/tile-3d-writer.js +19 -14
  92. package/dist/tiles-3d-loader.js +65 -55
  93. package/dist/types.js +3 -1
  94. package/package.json +11 -10
  95. package/dist/3d-tiles-archive/3d-tiles-archive-archive.js.map +0 -1
  96. package/dist/3d-tiles-archive/3d-tiles-archive-parser.js.map +0 -1
  97. package/dist/3d-tiles-archive-loader.js.map +0 -1
  98. package/dist/cesium-ion-loader.js.map +0 -1
  99. package/dist/index.js.map +0 -1
  100. package/dist/lib/classes/helpers/tile-3d-accessor-utils.js.map +0 -1
  101. package/dist/lib/classes/tile-3d-batch-table-hierarchy.js.map +0 -1
  102. package/dist/lib/classes/tile-3d-batch-table.js.map +0 -1
  103. package/dist/lib/classes/tile-3d-feature-table.js.map +0 -1
  104. package/dist/lib/constants.js.map +0 -1
  105. package/dist/lib/encoders/encode-3d-tile-batched-model.js.map +0 -1
  106. package/dist/lib/encoders/encode-3d-tile-composite.js.map +0 -1
  107. package/dist/lib/encoders/encode-3d-tile-instanced-model.js.map +0 -1
  108. package/dist/lib/encoders/encode-3d-tile-point-cloud.js.map +0 -1
  109. package/dist/lib/encoders/encode-3d-tile.js.map +0 -1
  110. package/dist/lib/encoders/helpers/encode-3d-tile-header.js.map +0 -1
  111. package/dist/lib/ion/ion.js.map +0 -1
  112. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js.map +0 -1
  113. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js.map +0 -1
  114. package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js.map +0 -1
  115. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +0 -1
  116. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +0 -1
  117. package/dist/lib/parsers/helpers/parse-3d-tile-header.js.map +0 -1
  118. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js.map +0 -1
  119. package/dist/lib/parsers/helpers/parse-3d-tile-tables.js.map +0 -1
  120. package/dist/lib/parsers/helpers/parse-utils.js.map +0 -1
  121. package/dist/lib/parsers/parse-3d-tile-batched-model.js.map +0 -1
  122. package/dist/lib/parsers/parse-3d-tile-composite.js.map +0 -1
  123. package/dist/lib/parsers/parse-3d-tile-gltf.js.map +0 -1
  124. package/dist/lib/parsers/parse-3d-tile-header.js.map +0 -1
  125. package/dist/lib/parsers/parse-3d-tile-instanced-model.js.map +0 -1
  126. package/dist/lib/parsers/parse-3d-tile-point-cloud.js.map +0 -1
  127. package/dist/lib/parsers/parse-3d-tile.js.map +0 -1
  128. package/dist/lib/utils/obb/s2-corners-to-obb.js.map +0 -1
  129. package/dist/lib/utils/s2/converters/s2-to-boundary.js.map +0 -1
  130. package/dist/lib/utils/s2/converters/s2-to-obb-points.js.map +0 -1
  131. package/dist/lib/utils/s2/converters/s2-to-region.js.map +0 -1
  132. package/dist/lib/utils/s2/index.js.map +0 -1
  133. package/dist/lib/utils/s2/s2-geometry-functions.js.map +0 -1
  134. package/dist/lib/utils/s2/s2-token-functions.js.map +0 -1
  135. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js.map +0 -1
  136. package/dist/lib/utils/s2/s2geometry/s2-geometry.js.map +0 -1
  137. package/dist/lib/utils/version.js.map +0 -1
  138. package/dist/tile-3d-subtree-loader.js.map +0 -1
  139. package/dist/tile-3d-writer.js.map +0 -1
  140. package/dist/tiles-3d-loader.js.map +0 -1
  141. package/dist/types.js.map +0 -1
@@ -1,3 +1,8 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT AND Apache-2.0
3
+ // Copyright vis.gl contributors
4
+ // This file is derived from the Cesium code base under Apache 2 license
5
+ // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
1
6
  import { DracoLoader } from '@loaders.gl/draco';
2
7
  import { parseFromContext } from '@loaders.gl/loader-utils';
3
8
  import { GL } from '@loaders.gl/math';
@@ -10,221 +15,422 @@ import { normalize3DTileColorAttribute } from "./helpers/normalize-3d-tile-color
10
15
  import { normalize3DTileNormalAttribute } from "./helpers/normalize-3d-tile-normals.js";
11
16
  import { normalize3DTilePositionAttribute } from "./helpers/normalize-3d-tile-positions.js";
12
17
  export async function parsePointCloud3DTile(tile, arrayBuffer, byteOffset, options, context) {
13
- byteOffset = parse3DTileHeaderSync(tile, arrayBuffer, byteOffset);
14
- byteOffset = parse3DTileTablesHeaderSync(tile, arrayBuffer, byteOffset);
15
- byteOffset = parse3DTileTablesSync(tile, arrayBuffer, byteOffset, options);
16
- initializeTile(tile);
17
- const {
18
- featureTable,
19
- batchTable
20
- } = parsePointCloudTables(tile);
21
- await parseDraco(tile, featureTable, batchTable, options, context);
22
- parsePositions(tile, featureTable, options);
23
- parseColors(tile, featureTable, batchTable);
24
- parseNormals(tile, featureTable);
25
- return byteOffset;
18
+ byteOffset = parse3DTileHeaderSync(tile, arrayBuffer, byteOffset);
19
+ byteOffset = parse3DTileTablesHeaderSync(tile, arrayBuffer, byteOffset);
20
+ byteOffset = parse3DTileTablesSync(tile, arrayBuffer, byteOffset, options);
21
+ initializeTile(tile);
22
+ const { featureTable, batchTable } = parsePointCloudTables(tile);
23
+ await parseDraco(tile, featureTable, batchTable, options, context);
24
+ parsePositions(tile, featureTable, options);
25
+ // @ts-expect-error TODO - do we need to assert on the batch table?
26
+ parseColors(tile, featureTable, batchTable);
27
+ parseNormals(tile, featureTable);
28
+ return byteOffset;
26
29
  }
27
30
  function initializeTile(tile) {
28
- tile.attributes = {
29
- positions: null,
30
- colors: null,
31
- normals: null,
32
- batchIds: null
33
- };
34
- tile.isQuantized = false;
35
- tile.isTranslucent = false;
36
- tile.isRGB565 = false;
37
- tile.isOctEncoded16P = false;
31
+ // Initialize point cloud tile defaults
32
+ tile.attributes = {
33
+ positions: null,
34
+ colors: null,
35
+ normals: null,
36
+ batchIds: null
37
+ };
38
+ tile.isQuantized = false;
39
+ tile.isTranslucent = false;
40
+ tile.isRGB565 = false;
41
+ tile.isOctEncoded16P = false;
38
42
  }
39
43
  function parsePointCloudTables(tile) {
40
- const featureTable = new Tile3DFeatureTable(tile.featureTableJson, tile.featureTableBinary);
41
- const pointsLength = featureTable.getGlobalProperty('POINTS_LENGTH');
42
- if (!Number.isFinite(pointsLength)) {
43
- throw new Error('POINTS_LENGTH must be defined');
44
- }
45
- featureTable.featuresLength = pointsLength;
46
- tile.featuresLength = pointsLength;
47
- tile.pointsLength = pointsLength;
48
- tile.pointCount = pointsLength;
49
- tile.rtcCenter = featureTable.getGlobalProperty('RTC_CENTER', GL.FLOAT, 3);
50
- const batchTable = parseBatchIds(tile, featureTable);
51
- return {
52
- featureTable,
53
- batchTable
54
- };
44
+ const featureTable = new Tile3DFeatureTable(tile.featureTableJson, tile.featureTableBinary);
45
+ const pointsLength = featureTable.getGlobalProperty('POINTS_LENGTH');
46
+ if (!Number.isFinite(pointsLength)) {
47
+ throw new Error('POINTS_LENGTH must be defined');
48
+ }
49
+ featureTable.featuresLength = pointsLength;
50
+ tile.featuresLength = pointsLength;
51
+ tile.pointsLength = pointsLength;
52
+ tile.pointCount = pointsLength;
53
+ tile.rtcCenter = featureTable.getGlobalProperty('RTC_CENTER', GL.FLOAT, 3);
54
+ const batchTable = parseBatchIds(tile, featureTable);
55
+ return { featureTable, batchTable };
55
56
  }
56
57
  function parsePositions(tile, featureTable, options) {
57
- tile.attributes = tile.attributes || {
58
- positions: null,
59
- colors: null,
60
- normals: null,
61
- batchIds: null
62
- };
63
- if (!tile.attributes.positions) {
64
- if (featureTable.hasProperty('POSITION')) {
65
- tile.attributes.positions = featureTable.getPropertyArray('POSITION', GL.FLOAT, 3);
66
- } else if (featureTable.hasProperty('POSITION_QUANTIZED')) {
67
- const positions = featureTable.getPropertyArray('POSITION_QUANTIZED', GL.UNSIGNED_SHORT, 3);
68
- tile.isQuantized = true;
69
- tile.quantizedRange = (1 << 16) - 1;
70
- tile.quantizedVolumeScale = featureTable.getGlobalProperty('QUANTIZED_VOLUME_SCALE', GL.FLOAT, 3);
71
- if (!tile.quantizedVolumeScale) {
72
- throw new Error('QUANTIZED_VOLUME_SCALE must be defined for quantized positions.');
73
- }
74
- tile.quantizedVolumeOffset = featureTable.getGlobalProperty('QUANTIZED_VOLUME_OFFSET', GL.FLOAT, 3);
75
- if (!tile.quantizedVolumeOffset) {
76
- throw new Error('QUANTIZED_VOLUME_OFFSET must be defined for quantized positions.');
77
- }
78
- tile.attributes.positions = normalize3DTilePositionAttribute(tile, positions, options);
58
+ tile.attributes = tile.attributes || {
59
+ positions: null,
60
+ colors: null,
61
+ normals: null,
62
+ batchIds: null
63
+ };
64
+ if (!tile.attributes.positions) {
65
+ if (featureTable.hasProperty('POSITION')) {
66
+ tile.attributes.positions = featureTable.getPropertyArray('POSITION', GL.FLOAT, 3);
67
+ }
68
+ else if (featureTable.hasProperty('POSITION_QUANTIZED')) {
69
+ const positions = featureTable.getPropertyArray('POSITION_QUANTIZED', GL.UNSIGNED_SHORT, 3);
70
+ tile.isQuantized = true;
71
+ tile.quantizedRange = (1 << 16) - 1;
72
+ tile.quantizedVolumeScale = featureTable.getGlobalProperty('QUANTIZED_VOLUME_SCALE', GL.FLOAT, 3);
73
+ if (!tile.quantizedVolumeScale) {
74
+ throw new Error('QUANTIZED_VOLUME_SCALE must be defined for quantized positions.');
75
+ }
76
+ tile.quantizedVolumeOffset = featureTable.getGlobalProperty('QUANTIZED_VOLUME_OFFSET', GL.FLOAT, 3);
77
+ if (!tile.quantizedVolumeOffset) {
78
+ throw new Error('QUANTIZED_VOLUME_OFFSET must be defined for quantized positions.');
79
+ }
80
+ tile.attributes.positions = normalize3DTilePositionAttribute(tile, positions, options);
81
+ }
79
82
  }
80
- }
83
+ if (!tile.attributes.positions) {
84
+ throw new Error('Either POSITION or POSITION_QUANTIZED must be defined.');
85
+ }
86
+ }
87
+ function parseColors(tile, featureTable, batchTable) {
88
+ tile.attributes = tile.attributes || {
89
+ positions: null,
90
+ colors: null,
91
+ normals: null,
92
+ batchIds: null
93
+ };
94
+ if (!tile.attributes.colors) {
95
+ let colors = null;
96
+ if (featureTable.hasProperty('RGBA')) {
97
+ colors = featureTable.getPropertyArray('RGBA', GL.UNSIGNED_BYTE, 4);
98
+ tile.isTranslucent = true;
99
+ }
100
+ else if (featureTable.hasProperty('RGB')) {
101
+ colors = featureTable.getPropertyArray('RGB', GL.UNSIGNED_BYTE, 3);
102
+ }
103
+ else if (featureTable.hasProperty('RGB565')) {
104
+ colors = featureTable.getPropertyArray('RGB565', GL.UNSIGNED_SHORT, 1);
105
+ tile.isRGB565 = true;
106
+ }
107
+ tile.attributes.colors = normalize3DTileColorAttribute(tile, colors, batchTable);
108
+ }
109
+ if (featureTable.hasProperty('CONSTANT_RGBA')) {
110
+ tile.constantRGBA = featureTable.getGlobalProperty('CONSTANT_RGBA', GL.UNSIGNED_BYTE, 4);
111
+ }
112
+ }
113
+ function parseNormals(tile, featureTable) {
114
+ tile.attributes = tile.attributes || {
115
+ positions: null,
116
+ colors: null,
117
+ normals: null,
118
+ batchIds: null
119
+ };
120
+ if (!tile.attributes.normals) {
121
+ let normals = null;
122
+ if (featureTable.hasProperty('NORMAL')) {
123
+ normals = featureTable.getPropertyArray('NORMAL', GL.FLOAT, 3);
124
+ }
125
+ else if (featureTable.hasProperty('NORMAL_OCT16P')) {
126
+ normals = featureTable.getPropertyArray('NORMAL_OCT16P', GL.UNSIGNED_BYTE, 2);
127
+ tile.isOctEncoded16P = true;
128
+ }
129
+ tile.attributes.normals = normalize3DTileNormalAttribute(tile, normals);
130
+ }
131
+ }
132
+ function parseBatchIds(tile, featureTable) {
133
+ let batchTable = null;
134
+ if (!tile.batchIds && featureTable.hasProperty('BATCH_ID')) {
135
+ tile.batchIds = featureTable.getPropertyArray('BATCH_ID', GL.UNSIGNED_SHORT, 1);
136
+ if (tile.batchIds) {
137
+ const batchFeatureLength = featureTable.getGlobalProperty('BATCH_LENGTH');
138
+ if (!batchFeatureLength) {
139
+ throw new Error('Global property: BATCH_LENGTH must be defined when BATCH_ID is defined.');
140
+ }
141
+ const { batchTableJson, batchTableBinary } = tile;
142
+ batchTable = new Tile3DBatchTable(batchTableJson, batchTableBinary, batchFeatureLength);
143
+ }
144
+ }
145
+ return batchTable;
146
+ }
147
+ // eslint-disable-next-line complexity
148
+ async function parseDraco(tile, featureTable, batchTable, options, context) {
149
+ let dracoBuffer;
150
+ let dracoFeatureTableProperties;
151
+ let dracoBatchTableProperties;
152
+ const batchTableDraco = tile.batchTableJson &&
153
+ tile.batchTableJson.extensions &&
154
+ tile.batchTableJson.extensions['3DTILES_draco_point_compression'];
155
+ if (batchTableDraco) {
156
+ dracoBatchTableProperties = batchTableDraco.properties;
157
+ }
158
+ const featureTableDraco = featureTable.getExtension('3DTILES_draco_point_compression');
159
+ if (featureTableDraco) {
160
+ dracoFeatureTableProperties = featureTableDraco.properties;
161
+ const dracoByteOffset = featureTableDraco.byteOffset;
162
+ const dracoByteLength = featureTableDraco.byteLength;
163
+ if (!dracoFeatureTableProperties || !Number.isFinite(dracoByteOffset) || !dracoByteLength) {
164
+ throw new Error('Draco properties, byteOffset, and byteLength must be defined');
165
+ }
166
+ dracoBuffer = (tile.featureTableBinary || []).slice(dracoByteOffset, dracoByteOffset + dracoByteLength);
167
+ tile.hasPositions = Number.isFinite(dracoFeatureTableProperties.POSITION);
168
+ tile.hasColors =
169
+ Number.isFinite(dracoFeatureTableProperties.RGB) ||
170
+ Number.isFinite(dracoFeatureTableProperties.RGBA);
171
+ tile.hasNormals = Number.isFinite(dracoFeatureTableProperties.NORMAL);
172
+ tile.hasBatchIds = Number.isFinite(dracoFeatureTableProperties.BATCH_ID);
173
+ tile.isTranslucent = Number.isFinite(dracoFeatureTableProperties.RGBA);
174
+ }
175
+ if (!dracoBuffer) {
176
+ return true;
177
+ }
178
+ const dracoData = {
179
+ buffer: dracoBuffer,
180
+ properties: { ...dracoFeatureTableProperties, ...dracoBatchTableProperties },
181
+ featureTableProperties: dracoFeatureTableProperties,
182
+ batchTableProperties: dracoBatchTableProperties,
183
+ dequantizeInShader: false
184
+ };
185
+ return await loadDraco(tile, dracoData, options, context);
186
+ }
187
+ // eslint-disable-next-line complexity, max-statements
188
+ export async function loadDraco(tile, dracoData, options, context) {
189
+ if (!context) {
190
+ return;
191
+ }
192
+ const dracoOptions = {
193
+ ...options,
194
+ draco: {
195
+ ...options?.draco,
196
+ extraAttributes: dracoData.batchTableProperties || {}
197
+ }
198
+ };
199
+ // The entire tileset might be included, too expensive to serialize
200
+ delete dracoOptions['3d-tiles'];
201
+ const data = await parseFromContext(dracoData.buffer, DracoLoader, dracoOptions, context);
202
+ const decodedPositions = data.attributes.POSITION && data.attributes.POSITION.value;
203
+ const decodedColors = data.attributes.COLOR_0 && data.attributes.COLOR_0.value;
204
+ const decodedNormals = data.attributes.NORMAL && data.attributes.NORMAL.value;
205
+ const decodedBatchIds = data.attributes.BATCH_ID && data.attributes.BATCH_ID.value;
206
+ // @ts-expect-error
207
+ const isQuantizedDraco = decodedPositions && data.attributes.POSITION.value.quantization;
208
+ // @ts-expect-error
209
+ const isOctEncodedDraco = decodedNormals && data.attributes.NORMAL.value.quantization;
210
+ if (isQuantizedDraco) {
211
+ // Draco quantization range == quantized volume scale - size in meters of the quantized volume
212
+ // Internal quantized range is the range of values of the quantized data, e.g. 255 for 8-bit, 1023 for 10-bit, etc
213
+ // @ts-expect-error This doesn't look right
214
+ const quantization = data.POSITION.data.quantization;
215
+ const range = quantization.range;
216
+ tile.quantizedVolumeScale = new Vector3(range, range, range);
217
+ tile.quantizedVolumeOffset = new Vector3(quantization.minValues);
218
+ tile.quantizedRange = (1 << quantization.quantizationBits) - 1.0;
219
+ tile.isQuantizedDraco = true;
220
+ }
221
+ if (isOctEncodedDraco) {
222
+ // @ts-expect-error This doesn't look right
223
+ tile.octEncodedRange = (1 << data.NORMAL.data.quantization.quantizationBits) - 1.0;
224
+ tile.isOctEncodedDraco = true;
225
+ }
226
+ // Extra batch table attributes
227
+ const batchTableAttributes = {};
228
+ if (dracoData.batchTableProperties) {
229
+ for (const attributeName of Object.keys(dracoData.batchTableProperties)) {
230
+ if (data.attributes[attributeName] && data.attributes[attributeName].value) {
231
+ batchTableAttributes[attributeName.toLowerCase()] = data.attributes[attributeName].value;
232
+ }
233
+ }
234
+ }
235
+ tile.attributes = {
236
+ // @ts-expect-error
237
+ positions: decodedPositions,
238
+ // @ts-expect-error
239
+ colors: normalize3DTileColorAttribute(tile, decodedColors, undefined),
240
+ // @ts-expect-error
241
+ normals: decodedNormals,
242
+ // @ts-expect-error
243
+ batchIds: decodedBatchIds,
244
+ ...batchTableAttributes
245
+ };
246
+ }
247
+ // TODO - this is the remaining code from Cesium's parser
248
+ /*
249
+ const batchTable = new Tile3DBatchTable(tile);
250
+
251
+ // parseDracoBuffer(tile, featureTable, batchTable);
252
+
81
253
  if (!tile.attributes.positions) {
82
254
  throw new Error('Either POSITION or POSITION_QUANTIZED must be defined.');
83
255
  }
84
256
  }
85
- function parseColors(tile, featureTable, batchTable) {
86
- tile.attributes = tile.attributes || {
87
- positions: null,
88
- colors: null,
89
- normals: null,
90
- batchIds: null
91
- };
92
- if (!tile.attributes.colors) {
93
- let colors = null;
257
+ /*
258
+
259
+ if (!tile.attributes.positions) {
260
+ if (featureTable.hasProperty('POSITION')) {
261
+ tile.attributes.positions = featureTable.getPropertyArray('POSITION', GL.FLOAT, 3);
262
+ } else if (featureTable.hasProperty('POSITION_QUANTIZED')) {
263
+ tile.attributes.positions = featureTable.getPropertyArray('POSITION_QUANTIZED', GL.UNSIGNED_SHORT, 3);
264
+
265
+
266
+ if (!tile.colors) {
94
267
  if (featureTable.hasProperty('RGBA')) {
95
- colors = featureTable.getPropertyArray('RGBA', GL.UNSIGNED_BYTE, 4);
268
+ tile.colors = featureTable.getPropertyArray('RGBA', GL.UNSIGNED_BYTE, 4);
96
269
  tile.isTranslucent = true;
97
270
  } else if (featureTable.hasProperty('RGB')) {
98
- colors = featureTable.getPropertyArray('RGB', GL.UNSIGNED_BYTE, 3);
99
- } else if (featureTable.hasProperty('RGB565')) {
100
- colors = featureTable.getPropertyArray('RGB565', GL.UNSIGNED_SHORT, 1);
271
+ tile.colors = featureTable.getPropertyArray('RGB', GL.UNSIGNED_BYTE, 3);
272
+ } else if (featureTable.hasPropertry('RGB565')) {
273
+ tile.colors = featureTable.getPropertyArray('RGB565', GL.UNSIGNED_SHORT, 1);
101
274
  tile.isRGB565 = true;
102
275
  }
103
- tile.attributes.colors = normalize3DTileColorAttribute(tile, colors, batchTable);
104
276
  }
105
- if (featureTable.hasProperty('CONSTANT_RGBA')) {
106
- tile.constantRGBA = featureTable.getGlobalProperty('CONSTANT_RGBA', GL.UNSIGNED_BYTE, 4);
107
- }
108
- }
109
- function parseNormals(tile, featureTable) {
110
- tile.attributes = tile.attributes || {
111
- positions: null,
112
- colors: null,
113
- normals: null,
114
- batchIds: null
115
- };
277
+
116
278
  if (!tile.attributes.normals) {
117
- let normals = null;
118
- if (featureTable.hasProperty('NORMAL')) {
119
- normals = featureTable.getPropertyArray('NORMAL', GL.FLOAT, 3);
120
- } else if (featureTable.hasProperty('NORMAL_OCT16P')) {
121
- normals = featureTable.getPropertyArray('NORMAL_OCT16P', GL.UNSIGNED_BYTE, 2);
279
+ if (featureTable.getPropertry('NORMAL')) {
280
+ tile.attributes.normals = featureTable.getPropertyArray('NORMAL', GL.FLOAT, 3);
281
+ } else if (featureTable.getProperty('NORMAL_OCT16P')) {
282
+ tile.attributes.normals = featureTable.getPropertyArray('NORMAL_OCT16P', GL.UNSIGNED_BYTE, 2);
122
283
  tile.isOctEncoded16P = true;
123
284
  }
124
- tile.attributes.normals = normalize3DTileNormalAttribute(tile, normals);
125
285
  }
126
- }
127
- function parseBatchIds(tile, featureTable) {
128
- let batchTable = null;
129
- if (!tile.batchIds && featureTable.hasProperty('BATCH_ID')) {
130
- tile.batchIds = featureTable.getPropertyArray('BATCH_ID', GL.UNSIGNED_SHORT, 1);
131
- if (tile.batchIds) {
132
- const batchFeatureLength = featureTable.getGlobalProperty('BATCH_LENGTH');
133
- if (!batchFeatureLength) {
134
- throw new Error('Global property: BATCH_LENGTH must be defined when BATCH_ID is defined.');
135
- }
136
- const {
137
- batchTableJson,
138
- batchTableBinary
139
- } = tile;
140
- batchTable = new Tile3DBatchTable(batchTableJson, batchTableBinary, batchFeatureLength);
286
+
287
+ if (!tile.batchIds) {
288
+ if (featureTable.hasProperty('BATCH_ID')) {
289
+ tile.batchIds = featureTable.getPropertyArray('BATCH_ID', GL.UNSIGNED_SHORT, 1);
141
290
  }
142
291
  }
143
- return batchTable;
292
+
293
+ if (!tile.attributes.positions) {
294
+ throw new Error('Either POSITION or POSITION_QUANTIZED must be defined.');
295
+ }
296
+
297
+ if (featureTable.getPropertry('CONSTANT_RGBA')) {
298
+ tile.constantRGBA = featureTable.getGlobalProperty('CONSTANT_RGBA', GL.UNSIGNED_BYTE, 4);
299
+ }
300
+
301
+ if (tile.batchIds) {
302
+ const batchLength = featureTable.getGlobalProperty('BATCH_LENGTH');
303
+ if (!defined(batchLength)) {
304
+ throw new Error('Global property: BATCH_LENGTH must be defined when BATCH_ID is defined.');
305
+ }
306
+
307
+ if (defined(batchTableBinary)) {
308
+ // Copy the batchTableBinary section and let the underlying ArrayBuffer be freed
309
+ batchTableBinary = new Uint8Array(batchTableBinary);
310
+ }
311
+
312
+ if (defined(pointCloud._batchTableLoaded)) {
313
+ pointCloud._batchTableLoaded(batchLength, batchTableJson, batchTableBinary);
314
+ }
315
+ }
316
+
317
+ // If points are not batched and there are per-point properties, use these properties for styling purposes
318
+ var styleableProperties;
319
+ if (!hasBatchIds && defined(batchTableBinary)) {
320
+ tile.styleableProperties = Cesium3DTileBatchTable.getBinaryProperties(
321
+ pointsLength,
322
+ batchTableJson,
323
+ batchTableBinary
324
+ );
325
+ }
326
+
327
+ tile.draco = draco;
144
328
  }
145
- async function parseDraco(tile, featureTable, batchTable, options, context) {
329
+
330
+ // Separate parsing and decoding of Draco
331
+ export function parseDracoBuffer(tile, featureTable, batchTable) {
146
332
  let dracoBuffer;
147
333
  let dracoFeatureTableProperties;
148
334
  let dracoBatchTableProperties;
149
- const batchTableDraco = tile.batchTableJson && tile.batchTableJson.extensions && tile.batchTableJson.extensions['3DTILES_draco_point_compression'];
335
+
336
+ const batchTableDraco = batchTable.getExtension('3DTILES_draco_point_compression');
150
337
  if (batchTableDraco) {
151
338
  dracoBatchTableProperties = batchTableDraco.properties;
152
339
  }
340
+
153
341
  const featureTableDraco = featureTable.getExtension('3DTILES_draco_point_compression');
154
342
  if (featureTableDraco) {
155
343
  dracoFeatureTableProperties = featureTableDraco.properties;
156
344
  const dracoByteOffset = featureTableDraco.byteOffset;
157
345
  const dracoByteLength = featureTableDraco.byteLength;
158
- if (!dracoFeatureTableProperties || !Number.isFinite(dracoByteOffset) || !dracoByteLength) {
346
+ if (!dracoFeatureTableProperties || !dracoByteOffset || !dracoByteLength) {
159
347
  throw new Error('Draco properties, byteOffset, and byteLength must be defined');
160
348
  }
161
- dracoBuffer = (tile.featureTableBinary || []).slice(dracoByteOffset, dracoByteOffset + dracoByteLength);
162
- tile.hasPositions = Number.isFinite(dracoFeatureTableProperties.POSITION);
163
- tile.hasColors = Number.isFinite(dracoFeatureTableProperties.RGB) || Number.isFinite(dracoFeatureTableProperties.RGBA);
164
- tile.hasNormals = Number.isFinite(dracoFeatureTableProperties.NORMAL);
165
- tile.hasBatchIds = Number.isFinite(dracoFeatureTableProperties.BATCH_ID);
166
- tile.isTranslucent = Number.isFinite(dracoFeatureTableProperties.RGBA);
349
+
350
+ dracoBuffer = arraySlice(
351
+ featureTableBinary,
352
+ dracoByteOffset,
353
+ dracoByteOffset + dracoByteLength
354
+ );
355
+ tile.hasPositions = dracoFeatureTableProperties.POSITION;
356
+ tile.hasColors = dracoFeatureTableProperties.RGB || dracoFeatureTableProperties.RGBA;
357
+ tile.hasNormals = dracoFeatureTableProperties.NORMAL;
358
+ tile.hasBatchIds = dracoFeatureTableProperties.BATCH_ID;
359
+ tile.isTranslucent = dracoFeatureTableProperties.RGBA;
167
360
  }
168
- if (!dracoBuffer) {
169
- return true;
361
+
362
+ if (dracoBuffer) {
363
+ tile.draco = {
364
+ buffer: dracoBuffer,
365
+ properties: {...dracoFeatureTableProperties, ...dracoBatchTableProperties},
366
+ featureTableProperties: dracoFeatureTableProperties,
367
+ batchTableProperties: dracoBatchTableProperties,
368
+ dequantizeInShader: false
369
+ };
370
+
371
+ tile.decodingState = DECODING_STATE.NEEDS_DECODE;
170
372
  }
171
- const dracoData = {
172
- buffer: dracoBuffer,
173
- properties: {
174
- ...dracoFeatureTableProperties,
175
- ...dracoBatchTableProperties
176
- },
177
- featureTableProperties: dracoFeatureTableProperties,
178
- batchTableProperties: dracoBatchTableProperties,
179
- dequantizeInShader: false
180
- };
181
- return await loadDraco(tile, dracoData, options, context);
182
373
  }
183
- export async function loadDraco(tile, dracoData, options, context) {
184
- if (!context) {
185
- return;
186
- }
187
- const dracoOptions = {
188
- ...options,
189
- draco: {
190
- ...(options === null || options === void 0 ? void 0 : options.draco),
191
- extraAttributes: dracoData.batchTableProperties || {}
192
- }
193
- };
194
- delete dracoOptions['3d-tiles'];
195
- const data = await parseFromContext(dracoData.buffer, DracoLoader, dracoOptions, context);
196
- const decodedPositions = data.attributes.POSITION && data.attributes.POSITION.value;
197
- const decodedColors = data.attributes.COLOR_0 && data.attributes.COLOR_0.value;
198
- const decodedNormals = data.attributes.NORMAL && data.attributes.NORMAL.value;
199
- const decodedBatchIds = data.attributes.BATCH_ID && data.attributes.BATCH_ID.value;
200
- const isQuantizedDraco = decodedPositions && data.attributes.POSITION.value.quantization;
201
- const isOctEncodedDraco = decodedNormals && data.attributes.NORMAL.value.quantization;
202
- if (isQuantizedDraco) {
203
- const quantization = data.POSITION.data.quantization;
204
- const range = quantization.range;
205
- tile.quantizedVolumeScale = new Vector3(range, range, range);
206
- tile.quantizedVolumeOffset = new Vector3(quantization.minValues);
207
- tile.quantizedRange = (1 << quantization.quantizationBits) - 1.0;
208
- tile.isQuantizedDraco = true;
209
- }
210
- if (isOctEncodedDraco) {
211
- tile.octEncodedRange = (1 << data.NORMAL.data.quantization.quantizationBits) - 1.0;
212
- tile.isOctEncodedDraco = true;
374
+
375
+ /*
376
+ function decodeDraco(tile, context) {
377
+ if (tile.decodingState === DECODING_STATE.READY) {
378
+ return false;
213
379
  }
214
- const batchTableAttributes = {};
215
- if (dracoData.batchTableProperties) {
216
- for (const attributeName of Object.keys(dracoData.batchTableProperties)) {
217
- if (data.attributes[attributeName] && data.attributes[attributeName].value) {
218
- batchTableAttributes[attributeName.toLowerCase()] = data.attributes[attributeName].value;
219
- }
380
+ if (tile.decodingState === DECODING_STATE.NEEDS_DECODE) {
381
+ var parsedContent = tile._parsedContent;
382
+ var draco = parsedContent.draco;
383
+ var decodePromise = DracoLoader.decodePointCloud(draco, context);
384
+ if (defined(decodePromise)) {
385
+ tile.decodingState = DECODING_STATE.DECODING;
386
+ decodePromise.then(function(result) {
387
+ tile.decodingState = DECODING_STATE.READY;
388
+ var decodedPositions = defined(result.POSITION) ? result.POSITION.array : undefined;
389
+ var decodedRgb = defined(result.RGB) ? result.RGB.array : undefined;
390
+ var decodedRgba = defined(result.RGBA) ? result.RGBA.array : undefined;
391
+ var decodedNormals = defined(result.NORMAL) ? result.NORMAL.array : undefined;
392
+ var decodedBatchIds = defined(result.BATCH_ID) ? result.BATCH_ID.array : undefined;
393
+ var isQuantizedDraco = defined(decodedPositions) && defined(result.POSITION.data.quantization);
394
+ var isOctEncodedDraco = defined(decodedNormals) && defined(result.NORMAL.data.quantization);
395
+ if (isQuantizedDraco) {
396
+ // Draco quantization range == quantized volume scale - size in meters of the quantized volume
397
+ // Internal quantized range is the range of values of the quantized data, e.g. 255 for 8-bit, 1023 for 10-bit, etc
398
+ var quantization = result.POSITION.data.quantization;
399
+ var range = quantization.range;
400
+ tile._quantizedVolumeScale = Cartesian3.fromElements(range, range, range);
401
+ tile._quantizedVolumeOffset = Cartesian3.unpack(quantization.minValues);
402
+ tile._quantizedRange = (1 << quantization.quantizationBits) - 1.0;
403
+ tile._isQuantizedDraco = true;
404
+ }
405
+ if (isOctEncodedDraco) {
406
+ tile._octEncodedRange = (1 << result.NORMAL.data.quantization.quantizationBits) - 1.0;
407
+ tile._isOctEncodedDraco = true;
408
+ }
409
+ var styleableProperties = parsedContent.styleableProperties;
410
+ var batchTableProperties = draco.batchTableProperties;
411
+ for (var name in batchTableProperties) {
412
+ if (batchTableProperties.hasOwnProperty(name)) {
413
+ var property = result[name];
414
+ if (!defined(styleableProperties)) {
415
+ styleableProperties = {};
416
+ }
417
+ styleableProperties[name] = {
418
+ typedArray : property.array,
419
+ componentCount : property.data.componentsPerAttribute
420
+ };
421
+ }
422
+ }
423
+ parsedContent.positions = defaultValue(decodedPositions, parsedContent.positions);
424
+ parsedContent.colors = defaultValue(defaultValue(decodedRgba, decodedRgb), parsedContent.colors);
425
+ parsedContent.normals = defaultValue(decodedNormals, parsedContent.normals);
426
+ parsedContent.batchIds = defaultValue(decodedBatchIds, parsedContent.batchIds);
427
+ parsedContent.styleableProperties = styleableProperties;
428
+ }).otherwise(function(error) {
429
+ tile.decodingState = DECODING_STATE.FAILED;
430
+ tile._readyPromise.reject(error);
431
+ });
220
432
  }
221
433
  }
222
- tile.attributes = {
223
- positions: decodedPositions,
224
- colors: normalize3DTileColorAttribute(tile, decodedColors, undefined),
225
- normals: decodedNormals,
226
- batchIds: decodedBatchIds,
227
- ...batchTableAttributes
228
- };
434
+ return true;
229
435
  }
230
- //# sourceMappingURL=parse-3d-tile-point-cloud.js.map
436
+ */
@@ -1,5 +1,5 @@
1
1
  import { LoaderContext } from '@loaders.gl/loader-utils';
2
- import { Tiles3DLoaderOptions } from '../../tiles-3d-loader';
3
- import { Tiles3DTileContent } from '../../types';
2
+ import { Tiles3DLoaderOptions } from "../../tiles-3d-loader.js";
3
+ import { Tiles3DTileContent } from "../../types.js";
4
4
  export declare function parse3DTile(arrayBuffer: ArrayBuffer, byteOffset: number | undefined, options: Tiles3DLoaderOptions | undefined, context: LoaderContext | undefined, tile?: Tiles3DTileContent): Promise<number>;
5
5
  //# sourceMappingURL=parse-3d-tile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-3d-tile.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-3d-tile.ts"],"names":[],"mappings":"AAeA,OAAO,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAC,oBAAoB,EAAC,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAC,kBAAkB,EAAC,MAAM,aAAa,CAAC;AAG/C,wBAAsB,WAAW,CAC/B,WAAW,EAAE,WAAW,EACxB,UAAU,oBAAI,EACd,OAAO,EAAE,oBAAoB,GAAG,SAAS,EACzC,OAAO,EAAE,aAAa,GAAG,SAAS,EAClC,IAAI,GAAE,kBAAsC,GAC3C,OAAO,CAAC,MAAM,CAAC,CA+BjB"}
1
+ {"version":3,"file":"parse-3d-tile.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-3d-tile.ts"],"names":[],"mappings":"AAeA,OAAO,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAC,oBAAoB,EAAC,iCAA8B;AAC3D,OAAO,EAAC,kBAAkB,EAAC,uBAAoB;AAG/C,wBAAsB,WAAW,CAC/B,WAAW,EAAE,WAAW,EACxB,UAAU,oBAAI,EACd,OAAO,EAAE,oBAAoB,GAAG,SAAS,EACzC,OAAO,EAAE,aAAa,GAAG,SAAS,EAClC,IAAI,GAAE,kBAAsC,GAC3C,OAAO,CAAC,MAAM,CAAC,CA+BjB"}