@loaders.gl/i3s 4.0.0-alpha.22 → 4.0.0-alpha.24

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 (165) hide show
  1. package/dist/dist.min.js +57 -55
  2. package/dist/es5/arcgis-webscene-loader.js +4 -4
  3. package/dist/es5/arcgis-webscene-loader.js.map +1 -1
  4. package/dist/es5/i3s-attribute-loader.js +1 -1
  5. package/dist/es5/i3s-attribute-loader.js.map +1 -1
  6. package/dist/es5/i3s-building-scene-layer-loader.js +1 -1
  7. package/dist/es5/i3s-building-scene-layer-loader.js.map +1 -1
  8. package/dist/es5/i3s-content-loader.js +1 -1
  9. package/dist/es5/i3s-content-loader.js.map +1 -1
  10. package/dist/es5/i3s-loader.js +1 -1
  11. package/dist/es5/i3s-loader.js.map +1 -1
  12. package/dist/es5/i3s-node-page-loader.js +14 -12
  13. package/dist/es5/i3s-node-page-loader.js.map +1 -1
  14. package/dist/es5/i3s-slpk-loader.js +3 -3
  15. package/dist/es5/i3s-slpk-loader.js.map +1 -1
  16. package/dist/es5/index.js +2 -2
  17. package/dist/es5/index.js.map +1 -1
  18. package/dist/es5/lib/parsers/parse-arcgis-webscene.js.map +1 -1
  19. package/dist/es5/lib/parsers/parse-i3s-tile-content.js.map +1 -1
  20. package/dist/es5/lib/parsers/parse-i3s.js.map +1 -1
  21. package/dist/es5/lib/parsers/parse-slpk/parse-slpk.js.map +1 -1
  22. package/dist/es5/lib/parsers/parse-slpk/slpk-archieve.js.map +1 -1
  23. package/dist/es5/types.js.map +1 -1
  24. package/dist/esm/arcgis-webscene-loader.js +2 -2
  25. package/dist/esm/arcgis-webscene-loader.js.map +1 -1
  26. package/dist/esm/i3s-attribute-loader.js +1 -1
  27. package/dist/esm/i3s-attribute-loader.js.map +1 -1
  28. package/dist/esm/i3s-building-scene-layer-loader.js +1 -1
  29. package/dist/esm/i3s-building-scene-layer-loader.js.map +1 -1
  30. package/dist/esm/i3s-content-loader.js +1 -1
  31. package/dist/esm/i3s-content-loader.js.map +1 -1
  32. package/dist/esm/i3s-loader.js +1 -1
  33. package/dist/esm/i3s-loader.js.map +1 -1
  34. package/dist/esm/i3s-node-page-loader.js +7 -5
  35. package/dist/esm/i3s-node-page-loader.js.map +1 -1
  36. package/dist/esm/i3s-slpk-loader.js +2 -2
  37. package/dist/esm/i3s-slpk-loader.js.map +1 -1
  38. package/dist/esm/index.js +1 -1
  39. package/dist/esm/index.js.map +1 -1
  40. package/dist/esm/lib/parsers/parse-arcgis-webscene.js.map +1 -1
  41. package/dist/esm/lib/parsers/parse-i3s-tile-content.js.map +1 -1
  42. package/dist/esm/lib/parsers/parse-i3s.js.map +1 -1
  43. package/dist/esm/lib/parsers/parse-slpk/parse-slpk.js.map +1 -1
  44. package/dist/esm/lib/parsers/parse-slpk/slpk-archieve.js.map +1 -1
  45. package/dist/esm/types.js.map +1 -1
  46. package/dist/i3s-content-worker-node.js +41 -41
  47. package/dist/i3s-content-worker-node.js.map +2 -2
  48. package/dist/i3s-content-worker.js +17 -17
  49. package/dist/src/arcgis-webscene-loader.d.ts +9 -0
  50. package/dist/src/arcgis-webscene-loader.d.ts.map +1 -0
  51. package/dist/src/bundle.d.ts.map +1 -0
  52. package/dist/{i3s-attribute-loader.d.ts → src/i3s-attribute-loader.d.ts} +3 -2
  53. package/dist/src/i3s-attribute-loader.d.ts.map +1 -0
  54. package/dist/src/i3s-building-scene-layer-loader.d.ts +8 -0
  55. package/dist/src/i3s-building-scene-layer-loader.d.ts.map +1 -0
  56. package/dist/src/i3s-content-loader.d.ts +8 -0
  57. package/dist/src/i3s-content-loader.d.ts.map +1 -0
  58. package/dist/{i3s-loader.d.ts → src/i3s-loader.d.ts} +2 -1
  59. package/dist/src/i3s-loader.d.ts.map +1 -0
  60. package/dist/src/i3s-node-page-loader.d.ts +8 -0
  61. package/dist/src/i3s-node-page-loader.d.ts.map +1 -0
  62. package/dist/{i3s-slpk-loader.d.ts → src/i3s-slpk-loader.d.ts} +2 -3
  63. package/dist/src/i3s-slpk-loader.d.ts.map +1 -0
  64. package/dist/{index.d.ts → src/index.d.ts} +1 -1
  65. package/dist/src/index.d.ts.map +1 -0
  66. package/dist/src/lib/helpers/i3s-nodepages-tiles.d.ts.map +1 -0
  67. package/dist/src/lib/parsers/constants.d.ts.map +1 -0
  68. package/dist/src/lib/parsers/parse-arcgis-webscene.d.ts +7 -0
  69. package/dist/src/lib/parsers/parse-arcgis-webscene.d.ts.map +1 -0
  70. package/dist/src/lib/parsers/parse-i3s-attribute.d.ts.map +1 -0
  71. package/dist/src/lib/parsers/parse-i3s-building-scene-layer.d.ts.map +1 -0
  72. package/dist/src/lib/parsers/parse-i3s-tile-content.d.ts.map +1 -0
  73. package/dist/{lib → src/lib}/parsers/parse-i3s.d.ts +1 -1
  74. package/dist/src/lib/parsers/parse-i3s.d.ts.map +1 -0
  75. package/dist/{lib → src/lib}/parsers/parse-slpk/parse-slpk.d.ts +1 -1
  76. package/dist/src/lib/parsers/parse-slpk/parse-slpk.d.ts.map +1 -0
  77. package/dist/{lib → src/lib}/parsers/parse-slpk/slpk-archieve.d.ts +2 -1
  78. package/dist/src/lib/parsers/parse-slpk/slpk-archieve.d.ts.map +1 -0
  79. package/dist/src/lib/utils/convert-i3s-obb-to-mbs.d.ts.map +1 -0
  80. package/dist/src/lib/utils/customize-/321/201olors.d.ts.map +1 -0
  81. package/dist/src/lib/utils/url-utils.d.ts.map +1 -0
  82. package/dist/{types.d.ts → src/types.d.ts} +16 -16
  83. package/dist/src/types.d.ts.map +1 -0
  84. package/dist/src/workers/i3s-content-worker-node.d.ts.map +1 -0
  85. package/dist/src/workers/i3s-content-worker.d.ts.map +1 -0
  86. package/dist/tsconfig.tsbuildinfo +1 -0
  87. package/package.json +9 -9
  88. package/src/arcgis-webscene-loader.ts +12 -6
  89. package/src/i3s-attribute-loader.ts +2 -1
  90. package/src/i3s-building-scene-layer-loader.ts +6 -1
  91. package/src/i3s-content-loader.ts +3 -2
  92. package/src/i3s-loader.ts +3 -2
  93. package/src/i3s-node-page-loader.ts +9 -6
  94. package/src/i3s-slpk-loader.ts +3 -3
  95. package/src/index.ts +1 -1
  96. package/src/lib/parsers/parse-arcgis-webscene.ts +2 -2
  97. package/src/lib/parsers/parse-i3s-tile-content.ts +1 -5
  98. package/src/lib/parsers/parse-i3s.ts +3 -2
  99. package/src/lib/parsers/parse-slpk/parse-slpk.ts +1 -1
  100. package/src/lib/parsers/parse-slpk/slpk-archieve.ts +2 -1
  101. package/src/types.ts +16 -16
  102. package/dist/arcgis-webscene-loader.d.ts +0 -7
  103. package/dist/arcgis-webscene-loader.d.ts.map +0 -1
  104. package/dist/arcgis-webscene-loader.js +0 -28
  105. package/dist/bundle.d.ts.map +0 -1
  106. package/dist/bundle.js +0 -5
  107. package/dist/i3s-attribute-loader.d.ts.map +0 -1
  108. package/dist/i3s-attribute-loader.js +0 -175
  109. package/dist/i3s-building-scene-layer-loader.d.ts +0 -6
  110. package/dist/i3s-building-scene-layer-loader.d.ts.map +0 -1
  111. package/dist/i3s-building-scene-layer-loader.js +0 -26
  112. package/dist/i3s-content-loader.d.ts +0 -6
  113. package/dist/i3s-content-loader.d.ts.map +0 -1
  114. package/dist/i3s-content-loader.js +0 -32
  115. package/dist/i3s-loader.d.ts.map +0 -1
  116. package/dist/i3s-loader.js +0 -100
  117. package/dist/i3s-node-page-loader.d.ts +0 -7
  118. package/dist/i3s-node-page-loader.d.ts.map +0 -1
  119. package/dist/i3s-node-page-loader.js +0 -22
  120. package/dist/i3s-slpk-loader.d.ts.map +0 -1
  121. package/dist/i3s-slpk-loader.js +0 -30
  122. package/dist/index.d.ts.map +0 -1
  123. package/dist/index.js +0 -23
  124. package/dist/lib/helpers/i3s-nodepages-tiles.d.ts.map +0 -1
  125. package/dist/lib/helpers/i3s-nodepages-tiles.js +0 -244
  126. package/dist/lib/parsers/constants.d.ts.map +0 -1
  127. package/dist/lib/parsers/constants.js +0 -88
  128. package/dist/lib/parsers/parse-arcgis-webscene.d.ts +0 -7
  129. package/dist/lib/parsers/parse-arcgis-webscene.d.ts.map +0 -1
  130. package/dist/lib/parsers/parse-arcgis-webscene.js +0 -88
  131. package/dist/lib/parsers/parse-i3s-attribute.d.ts.map +0 -1
  132. package/dist/lib/parsers/parse-i3s-attribute.js +0 -99
  133. package/dist/lib/parsers/parse-i3s-building-scene-layer.d.ts.map +0 -1
  134. package/dist/lib/parsers/parse-i3s-building-scene-layer.js +0 -46
  135. package/dist/lib/parsers/parse-i3s-tile-content.d.ts.map +0 -1
  136. package/dist/lib/parsers/parse-i3s-tile-content.js +0 -502
  137. package/dist/lib/parsers/parse-i3s.d.ts.map +0 -1
  138. package/dist/lib/parsers/parse-i3s.js +0 -105
  139. package/dist/lib/parsers/parse-slpk/parse-slpk.d.ts.map +0 -1
  140. package/dist/lib/parsers/parse-slpk/parse-slpk.js +0 -33
  141. package/dist/lib/parsers/parse-slpk/slpk-archieve.d.ts.map +0 -1
  142. package/dist/lib/parsers/parse-slpk/slpk-archieve.js +0 -131
  143. package/dist/lib/utils/convert-i3s-obb-to-mbs.d.ts.map +0 -1
  144. package/dist/lib/utils/convert-i3s-obb-to-mbs.js +0 -20
  145. package/dist/lib/utils/customize-/321/201olors.d.ts.map +0 -1
  146. package/dist/lib/utils/customize-/321/201olors.js +0 -104
  147. package/dist/lib/utils/url-utils.d.ts.map +0 -1
  148. package/dist/lib/utils/url-utils.js +0 -45
  149. package/dist/types.d.ts.map +0 -1
  150. package/dist/types.js +0 -8
  151. package/dist/workers/i3s-content-worker-node.d.ts.map +0 -1
  152. package/dist/workers/i3s-content-worker-node.js +0 -7
  153. package/dist/workers/i3s-content-worker.d.ts.map +0 -1
  154. package/dist/workers/i3s-content-worker.js +0 -5
  155. /package/dist/{bundle.d.ts → src/bundle.d.ts} +0 -0
  156. /package/dist/{lib → src/lib}/helpers/i3s-nodepages-tiles.d.ts +0 -0
  157. /package/dist/{lib → src/lib}/parsers/constants.d.ts +0 -0
  158. /package/dist/{lib → src/lib}/parsers/parse-i3s-attribute.d.ts +0 -0
  159. /package/dist/{lib → src/lib}/parsers/parse-i3s-building-scene-layer.d.ts +0 -0
  160. /package/dist/{lib → src/lib}/parsers/parse-i3s-tile-content.d.ts +0 -0
  161. /package/dist/{lib → src/lib}/utils/convert-i3s-obb-to-mbs.d.ts +0 -0
  162. /package/dist/{lib → src/lib}/utils/customize-/321/201olors.d.ts" +0 -0
  163. /package/dist/{lib → src/lib}/utils/url-utils.d.ts +0 -0
  164. /package/dist/{workers → src/workers}/i3s-content-worker-node.d.ts +0 -0
  165. /package/dist/{workers → src/workers}/i3s-content-worker.d.ts +0 -0
@@ -1,502 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseI3STileContent = void 0;
4
- const core_1 = require("@loaders.gl/core");
5
- const core_2 = require("@math.gl/core");
6
- const geospatial_1 = require("@math.gl/geospatial");
7
- const loader_utils_1 = require("@loaders.gl/loader-utils");
8
- const images_1 = require("@loaders.gl/images");
9
- const draco_1 = require("@loaders.gl/draco");
10
- const textures_1 = require("@loaders.gl/textures");
11
- const types_1 = require("../../types");
12
- const url_utils_1 = require("../utils/url-utils");
13
- const constants_1 = require("./constants");
14
- const customize__olors_1 = require("../utils/customize-\u0441olors");
15
- const scratchVector = new core_2.Vector3([0, 0, 0]);
16
- function getLoaderForTextureFormat(textureFormat) {
17
- switch (textureFormat) {
18
- case 'ktx-etc2':
19
- case 'dds':
20
- return textures_1.CompressedTextureLoader;
21
- case 'ktx2':
22
- return textures_1.BasisLoader;
23
- case 'jpg':
24
- case 'png':
25
- default:
26
- return images_1.ImageLoader;
27
- }
28
- }
29
- const I3S_ATTRIBUTE_TYPE = 'i3s-attribute-type';
30
- async function parseI3STileContent(arrayBuffer, tileOptions, tilesetOptions, options, context) {
31
- const content = {
32
- attributes: {},
33
- indices: null,
34
- featureIds: [],
35
- vertexCount: 0,
36
- modelMatrix: new core_2.Matrix4(),
37
- coordinateSystem: 0,
38
- byteLength: 0,
39
- texture: null
40
- };
41
- if (tileOptions.textureUrl) {
42
- // @ts-expect-error options is not properly typed
43
- const url = (0, url_utils_1.getUrlWithToken)(tileOptions.textureUrl, options?.i3s?.token);
44
- const loader = getLoaderForTextureFormat(tileOptions.textureFormat);
45
- const response = await fetch(url, options?.fetch);
46
- const arrayBuffer = await response.arrayBuffer();
47
- // @ts-expect-error options is not properly typed
48
- if (options?.i3s.decodeTextures) {
49
- if (loader === images_1.ImageLoader) {
50
- const options = { ...tileOptions.textureLoaderOptions, image: { type: 'data' } };
51
- try {
52
- // Image constructor is not supported in worker thread.
53
- // Do parsing image data on the main thread by using context to avoid worker issues.
54
- const texture = await (0, loader_utils_1.parseFromContext)(arrayBuffer, [], options, context);
55
- // @ts-expect-error
56
- content.texture = texture;
57
- }
58
- catch (e) {
59
- // context object is different between worker and node.js conversion script.
60
- // To prevent error we parse data in ordinary way if it is not parsed by using context.
61
- const texture = await (0, core_1.parse)(arrayBuffer, loader, options, context);
62
- // @ts-expect-error
63
- content.texture = texture;
64
- }
65
- }
66
- else if (loader === textures_1.CompressedTextureLoader || loader === textures_1.BasisLoader) {
67
- let texture = await (0, core_1.load)(arrayBuffer, loader, tileOptions.textureLoaderOptions);
68
- if (loader === textures_1.BasisLoader) {
69
- // @ts-expect-error
70
- texture = texture[0];
71
- }
72
- content.texture = {
73
- compressed: true,
74
- mipmaps: false,
75
- // @ts-expect-error
76
- width: texture[0].width,
77
- // @ts-expect-error
78
- height: texture[0].height,
79
- // @ts-expect-error
80
- data: texture
81
- };
82
- }
83
- }
84
- else {
85
- content.texture = arrayBuffer;
86
- }
87
- }
88
- content.material = makePbrMaterial(tileOptions.materialDefinition, content.texture);
89
- if (content.material) {
90
- content.texture = null;
91
- }
92
- return await parseI3SNodeGeometry(arrayBuffer, content, tileOptions, tilesetOptions, options);
93
- }
94
- exports.parseI3STileContent = parseI3STileContent;
95
- /* eslint-disable max-statements */
96
- async function parseI3SNodeGeometry(arrayBuffer, content, tileOptions, tilesetOptions, options) {
97
- const contentByteLength = arrayBuffer.byteLength;
98
- let attributes;
99
- let vertexCount;
100
- let byteOffset = 0;
101
- let featureCount = 0;
102
- let indices;
103
- if (tileOptions.isDracoGeometry) {
104
- const decompressedGeometry = await (0, core_1.parse)(arrayBuffer, draco_1.DracoLoader, {
105
- draco: {
106
- attributeNameEntry: I3S_ATTRIBUTE_TYPE
107
- }
108
- });
109
- // @ts-expect-error
110
- vertexCount = decompressedGeometry.header.vertexCount;
111
- indices = decompressedGeometry.indices?.value;
112
- const { POSITION, NORMAL, COLOR_0, TEXCOORD_0, ['feature-index']: featureIndex, ['uv-region']: uvRegion } = decompressedGeometry.attributes;
113
- attributes = {
114
- position: POSITION,
115
- normal: NORMAL,
116
- color: COLOR_0,
117
- uv0: TEXCOORD_0,
118
- uvRegion,
119
- id: featureIndex
120
- };
121
- updateAttributesMetadata(attributes, decompressedGeometry);
122
- const featureIds = getFeatureIdsFromFeatureIndexMetadata(featureIndex);
123
- if (featureIds) {
124
- flattenFeatureIdsByFeatureIndices(attributes, featureIds);
125
- }
126
- }
127
- else {
128
- const { vertexAttributes, ordering: attributesOrder, featureAttributes, featureAttributeOrder } = tilesetOptions.store.defaultGeometrySchema;
129
- // First 8 bytes reserved for header (vertexCount and featureCount)
130
- const headers = parseHeaders(arrayBuffer, tilesetOptions);
131
- byteOffset = headers.byteOffset;
132
- vertexCount = headers.vertexCount;
133
- featureCount = headers.featureCount;
134
- // Getting vertex attributes such as positions, normals, colors, etc...
135
- const { attributes: normalizedVertexAttributes, byteOffset: offset } = normalizeAttributes(arrayBuffer, byteOffset, vertexAttributes, vertexCount, attributesOrder);
136
- // Getting feature attributes such as featureIds and faceRange
137
- const { attributes: normalizedFeatureAttributes } = normalizeAttributes(arrayBuffer, offset, featureAttributes, featureCount, featureAttributeOrder);
138
- flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes);
139
- attributes = concatAttributes(normalizedVertexAttributes, normalizedFeatureAttributes);
140
- }
141
- if (!options?.i3s?.coordinateSystem ||
142
- options.i3s.coordinateSystem === constants_1.COORDINATE_SYSTEM.METER_OFFSETS) {
143
- const enuMatrix = parsePositions(attributes.position, tileOptions);
144
- content.modelMatrix = enuMatrix.invert();
145
- content.coordinateSystem = constants_1.COORDINATE_SYSTEM.METER_OFFSETS;
146
- }
147
- else {
148
- content.modelMatrix = getModelMatrix(attributes.position);
149
- content.coordinateSystem = constants_1.COORDINATE_SYSTEM.LNGLAT_OFFSETS;
150
- }
151
- attributes.color = await (0, customize__olors_1.customizeColors)(attributes.color, attributes.id, tileOptions, tilesetOptions, options);
152
- content.attributes = {
153
- positions: attributes.position,
154
- normals: attributes.normal,
155
- colors: normalizeAttribute(attributes.color),
156
- texCoords: attributes.uv0,
157
- uvRegions: normalizeAttribute(attributes.uvRegion || attributes.region) // Normalize from UInt16
158
- };
159
- content.indices = indices || null;
160
- if (attributes.id && attributes.id.value) {
161
- content.featureIds = attributes.id.value;
162
- }
163
- // Remove undefined attributes
164
- for (const attributeIndex in content.attributes) {
165
- if (!content.attributes[attributeIndex]) {
166
- delete content.attributes[attributeIndex];
167
- }
168
- }
169
- content.vertexCount = vertexCount;
170
- content.byteLength = contentByteLength;
171
- return content;
172
- }
173
- /**
174
- * Update attributes with metadata from decompressed geometry.
175
- * @param decompressedGeometry
176
- * @param attributes
177
- */
178
- function updateAttributesMetadata(attributes, decompressedGeometry) {
179
- for (const key in decompressedGeometry.loaderData.attributes) {
180
- const dracoAttribute = decompressedGeometry.loaderData.attributes[key];
181
- switch (dracoAttribute.name) {
182
- case 'POSITION':
183
- attributes.position.metadata = dracoAttribute.metadata;
184
- break;
185
- case 'feature-index':
186
- attributes.id.metadata = dracoAttribute.metadata;
187
- break;
188
- default:
189
- break;
190
- }
191
- }
192
- }
193
- /**
194
- * Do concatenation of attribute objects.
195
- * Done as separate fucntion to avoid ts errors.
196
- * @param normalizedVertexAttributes
197
- * @param normalizedFeatureAttributes
198
- * @returns - result of attributes concatenation.
199
- */
200
- function concatAttributes(normalizedVertexAttributes, normalizedFeatureAttributes) {
201
- return { ...normalizedVertexAttributes, ...normalizedFeatureAttributes };
202
- }
203
- /**
204
- * Normalize attribute to range [0..1] . Eg. convert colors buffer from [255,255,255,255] to [1,1,1,1]
205
- * @param attribute - geometry attribute
206
- * @returns - geometry attribute in right format
207
- */
208
- function normalizeAttribute(attribute) {
209
- if (!attribute) {
210
- return attribute;
211
- }
212
- attribute.normalized = true;
213
- return attribute;
214
- }
215
- function parseHeaders(arrayBuffer, options) {
216
- let byteOffset = 0;
217
- // First 8 bytes reserved for header (vertexCount and featurecount)
218
- let vertexCount = 0;
219
- let featureCount = 0;
220
- for (const { property, type } of options.store.defaultGeometrySchema.header) {
221
- const TypedArrayTypeHeader = (0, constants_1.getConstructorForDataFormat)(type);
222
- switch (property) {
223
- case types_1.HeaderAttributeProperty.vertexCount:
224
- vertexCount = new TypedArrayTypeHeader(arrayBuffer, 0, 4)[0];
225
- byteOffset += (0, constants_1.sizeOf)(type);
226
- break;
227
- case types_1.HeaderAttributeProperty.featureCount:
228
- featureCount = new TypedArrayTypeHeader(arrayBuffer, 4, 4)[0];
229
- byteOffset += (0, constants_1.sizeOf)(type);
230
- break;
231
- default:
232
- break;
233
- }
234
- }
235
- return {
236
- vertexCount,
237
- featureCount,
238
- byteOffset
239
- };
240
- }
241
- /* eslint-enable max-statements */
242
- function normalizeAttributes(arrayBuffer, byteOffset, vertexAttributes, attributeCount, attributesOrder) {
243
- const attributes = {};
244
- // the order of attributes depend on the order being added to the vertexAttributes object
245
- for (const attribute of attributesOrder) {
246
- if (vertexAttributes[attribute]) {
247
- const { valueType, valuesPerElement } = vertexAttributes[attribute];
248
- // protect from arrayBuffer read overunns by NOT assuming node has regions always even though its declared in defaultGeometrySchema.
249
- // In i3s 1.6: client is required to decide that based on ./shared resource of the node (materialDefinitions.[Mat_id].params.vertexRegions == true)
250
- // In i3s 1.7 the property has been rolled into the 3d scene layer json/node pages.
251
- // Code below does not account when the bytelength is actually bigger than
252
- // the calculated value (b\c the tile potentially could have mesh segmentation information).
253
- // In those cases tiles without regions could fail or have garbage values.
254
- if (byteOffset + attributeCount * valuesPerElement * (0, constants_1.sizeOf)(valueType) <=
255
- arrayBuffer.byteLength) {
256
- const buffer = arrayBuffer.slice(byteOffset);
257
- let value;
258
- if (valueType === 'UInt64') {
259
- value = parseUint64Values(buffer, attributeCount * valuesPerElement, (0, constants_1.sizeOf)(valueType));
260
- }
261
- else {
262
- const TypedArrayType = (0, constants_1.getConstructorForDataFormat)(valueType);
263
- value = new TypedArrayType(buffer, 0, attributeCount * valuesPerElement);
264
- }
265
- attributes[attribute] = {
266
- value,
267
- type: constants_1.GL_TYPE_MAP[valueType],
268
- size: valuesPerElement
269
- };
270
- switch (attribute) {
271
- case 'color':
272
- attributes.color.normalized = true;
273
- break;
274
- case 'position':
275
- case 'region':
276
- case 'normal':
277
- default:
278
- }
279
- byteOffset = byteOffset + attributeCount * valuesPerElement * (0, constants_1.sizeOf)(valueType);
280
- }
281
- else if (attribute !== 'uv0') {
282
- break;
283
- }
284
- }
285
- }
286
- return { attributes, byteOffset };
287
- }
288
- /**
289
- * Parse buffer to return array of uint64 values
290
- *
291
- * @param buffer
292
- * @param elementsCount
293
- * @returns 64-bit array of values until precision is lost after Number.MAX_SAFE_INTEGER
294
- */
295
- function parseUint64Values(buffer, elementsCount, attributeSize) {
296
- const values = [];
297
- const dataView = new DataView(buffer);
298
- let offset = 0;
299
- for (let index = 0; index < elementsCount; index++) {
300
- // split 64-bit number into two 32-bit parts
301
- const left = dataView.getUint32(offset, true);
302
- const right = dataView.getUint32(offset + 4, true);
303
- // combine the two 32-bit values
304
- const value = left + 2 ** 32 * right;
305
- values.push(value);
306
- offset += attributeSize;
307
- }
308
- return new Uint32Array(values);
309
- }
310
- function parsePositions(attribute, options) {
311
- const mbs = options.mbs;
312
- const value = attribute.value;
313
- const metadata = attribute.metadata;
314
- const enuMatrix = new core_2.Matrix4();
315
- const cartographicOrigin = new core_2.Vector3(mbs[0], mbs[1], mbs[2]);
316
- const cartesianOrigin = new core_2.Vector3();
317
- geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(cartographicOrigin, cartesianOrigin);
318
- geospatial_1.Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin, enuMatrix);
319
- attribute.value = offsetsToCartesians(value, metadata, cartographicOrigin);
320
- return enuMatrix;
321
- }
322
- /**
323
- * Converts position coordinates to absolute cartesian coordinates
324
- * @param vertices - "position" attribute data
325
- * @param metadata - When the geometry is DRACO compressed, contain position attribute's metadata
326
- * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/compressedAttributes.cmn.md
327
- * @param cartographicOrigin - Cartographic origin coordinates
328
- * @returns - converted "position" data
329
- */
330
- function offsetsToCartesians(vertices, metadata = {}, cartographicOrigin) {
331
- const positions = new Float64Array(vertices.length);
332
- const scaleX = (metadata['i3s-scale_x'] && metadata['i3s-scale_x'].double) || 1;
333
- const scaleY = (metadata['i3s-scale_y'] && metadata['i3s-scale_y'].double) || 1;
334
- for (let i = 0; i < positions.length; i += 3) {
335
- positions[i] = vertices[i] * scaleX + cartographicOrigin.x;
336
- positions[i + 1] = vertices[i + 1] * scaleY + cartographicOrigin.y;
337
- positions[i + 2] = vertices[i + 2] + cartographicOrigin.z;
338
- }
339
- for (let i = 0; i < positions.length; i += 3) {
340
- // @ts-ignore
341
- geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(positions.subarray(i, i + 3), scratchVector);
342
- positions[i] = scratchVector.x;
343
- positions[i + 1] = scratchVector.y;
344
- positions[i + 2] = scratchVector.z;
345
- }
346
- return positions;
347
- }
348
- /**
349
- * Get model matrix for loaded vertices
350
- * @param positions positions attribute
351
- * @returns Matrix4 - model matrix for geometry transformation
352
- */
353
- function getModelMatrix(positions) {
354
- const metadata = positions.metadata;
355
- const scaleX = metadata?.['i3s-scale_x']?.double || 1;
356
- const scaleY = metadata?.['i3s-scale_y']?.double || 1;
357
- const modelMatrix = new core_2.Matrix4();
358
- modelMatrix[0] = scaleX;
359
- modelMatrix[5] = scaleY;
360
- return modelMatrix;
361
- }
362
- /**
363
- * Makes a glTF-compatible PBR material from an I3S material definition
364
- * @param materialDefinition - i3s material definition
365
- * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/materialDefinitions.cmn.md
366
- * @param texture - texture image
367
- * @returns {object}
368
- */
369
- function makePbrMaterial(materialDefinition, texture) {
370
- let pbrMaterial;
371
- if (materialDefinition) {
372
- pbrMaterial = {
373
- ...materialDefinition,
374
- pbrMetallicRoughness: materialDefinition.pbrMetallicRoughness
375
- ? { ...materialDefinition.pbrMetallicRoughness }
376
- : { baseColorFactor: [255, 255, 255, 255] }
377
- };
378
- }
379
- else {
380
- pbrMaterial = {
381
- pbrMetallicRoughness: {}
382
- };
383
- if (texture) {
384
- pbrMaterial.pbrMetallicRoughness.baseColorTexture = { texCoord: 0 };
385
- }
386
- else {
387
- pbrMaterial.pbrMetallicRoughness.baseColorFactor = [255, 255, 255, 255];
388
- }
389
- }
390
- // Set default 0.25 per spec https://github.com/Esri/i3s-spec/blob/master/docs/1.7/materialDefinitions.cmn.md
391
- pbrMaterial.alphaCutoff = pbrMaterial.alphaCutoff || 0.25;
392
- if (pbrMaterial.alphaMode) {
393
- // I3S contain alphaMode in lowerCase
394
- pbrMaterial.alphaMode = pbrMaterial.alphaMode.toUpperCase();
395
- }
396
- // Convert colors from [255,255,255,255] to [1,1,1,1]
397
- if (pbrMaterial.emissiveFactor) {
398
- pbrMaterial.emissiveFactor = convertColorFormat(pbrMaterial.emissiveFactor);
399
- }
400
- if (pbrMaterial.pbrMetallicRoughness && pbrMaterial.pbrMetallicRoughness.baseColorFactor) {
401
- pbrMaterial.pbrMetallicRoughness.baseColorFactor = convertColorFormat(pbrMaterial.pbrMetallicRoughness.baseColorFactor);
402
- }
403
- if (texture) {
404
- setMaterialTexture(pbrMaterial, texture);
405
- }
406
- return pbrMaterial;
407
- }
408
- /**
409
- * Convert color from [255,255,255,255] to [1,1,1,1]
410
- * @param colorFactor - color array
411
- * @returns - new color array
412
- */
413
- function convertColorFormat(colorFactor) {
414
- const normalizedColor = [...colorFactor];
415
- for (let index = 0; index < colorFactor.length; index++) {
416
- normalizedColor[index] = colorFactor[index] / 255;
417
- }
418
- return normalizedColor;
419
- }
420
- /**
421
- * Set texture in PBR material
422
- * @param {object} material - i3s material definition
423
- * @param image - texture image
424
- * @returns
425
- */
426
- function setMaterialTexture(material, image) {
427
- const texture = { source: { image } };
428
- // I3SLoader now support loading only one texture. This elseif sequence will assign this texture to one of
429
- // properties defined in materialDefinition
430
- if (material.pbrMetallicRoughness && material.pbrMetallicRoughness.baseColorTexture) {
431
- material.pbrMetallicRoughness.baseColorTexture = {
432
- ...material.pbrMetallicRoughness.baseColorTexture,
433
- texture
434
- };
435
- }
436
- else if (material.emissiveTexture) {
437
- material.emissiveTexture = { ...material.emissiveTexture, texture };
438
- }
439
- else if (material.pbrMetallicRoughness &&
440
- material.pbrMetallicRoughness.metallicRoughnessTexture) {
441
- material.pbrMetallicRoughness.metallicRoughnessTexture = {
442
- ...material.pbrMetallicRoughness.metallicRoughnessTexture,
443
- texture
444
- };
445
- }
446
- else if (material.normalTexture) {
447
- material.normalTexture = { ...material.normalTexture, texture };
448
- }
449
- else if (material.occlusionTexture) {
450
- material.occlusionTexture = { ...material.occlusionTexture, texture };
451
- }
452
- }
453
- /**
454
- * Flatten feature ids using face ranges
455
- * @param normalizedFeatureAttributes
456
- * @returns
457
- */
458
- function flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes) {
459
- const { id, faceRange } = normalizedFeatureAttributes;
460
- if (!id || !faceRange) {
461
- return;
462
- }
463
- const featureIds = id.value;
464
- const range = faceRange.value;
465
- const featureIdsLength = range[range.length - 1] + 1;
466
- const orderedFeatureIndices = new Uint32Array(featureIdsLength * 3);
467
- let featureIndex = 0;
468
- let startIndex = 0;
469
- for (let index = 1; index < range.length; index += 2) {
470
- const fillId = Number(featureIds[featureIndex]);
471
- const endValue = range[index];
472
- const prevValue = range[index - 1];
473
- const trianglesCount = endValue - prevValue + 1;
474
- const endIndex = startIndex + trianglesCount * 3;
475
- orderedFeatureIndices.fill(fillId, startIndex, endIndex);
476
- featureIndex++;
477
- startIndex = endIndex;
478
- }
479
- normalizedFeatureAttributes.id.value = orderedFeatureIndices;
480
- }
481
- /**
482
- * Flatten feature ids using featureIndices
483
- * @param attributes
484
- * @param featureIds
485
- * @returns
486
- */
487
- function flattenFeatureIdsByFeatureIndices(attributes, featureIds) {
488
- const featureIndices = attributes.id.value;
489
- const result = new Float32Array(featureIndices.length);
490
- for (let index = 0; index < featureIndices.length; index++) {
491
- result[index] = featureIds[featureIndices[index]];
492
- }
493
- attributes.id.value = result;
494
- }
495
- /**
496
- * Flatten feature ids using featureIndices
497
- * @param featureIndex
498
- * @returns
499
- */
500
- function getFeatureIdsFromFeatureIndexMetadata(featureIndex) {
501
- return featureIndex?.metadata?.['i3s-feature-ids']?.intArray;
502
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"parse-i3s.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-i3s.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,gBAAgB,EAChB,aAAa,EAEb,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,EACb,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAC,aAAa,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAG3E,wBAAgB,iBAAiB,CAAC,IAAI,EAAG,mBAAmB,EAAE,OAAO,EAAE,aAAa,GAAG,aAAa,CA6BnG;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAG,kBAAkB,GAAG,aAAa,CAkChF;AAED,wBAAsB,oBAAoB,CAAC,OAAO,EAAG,YAAY,EAAE,OAAO,EAAG,aAAa,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA+B7I"}
@@ -1,105 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.normalizeTilesetData = exports.normalizeTileNonUrlData = exports.normalizeTileData = void 0;
7
- const culling_1 = require("@math.gl/culling");
8
- const geospatial_1 = require("@math.gl/geospatial");
9
- const core_1 = require("@loaders.gl/core");
10
- const tiles_1 = require("@loaders.gl/tiles");
11
- const i3s_nodepages_tiles_1 = __importDefault(require("../helpers/i3s-nodepages-tiles"));
12
- const url_utils_1 = require("../utils/url-utils");
13
- const i3s_loader_1 = require("../../i3s-loader");
14
- function normalizeTileData(tile, context) {
15
- const url = context.url || '';
16
- let contentUrl;
17
- if (tile.geometryData) {
18
- contentUrl = `${url}/${tile.geometryData[0].href}`;
19
- }
20
- let textureUrl;
21
- if (tile.textureData) {
22
- textureUrl = `${url}/${tile.textureData[0].href}`;
23
- }
24
- let attributeUrls;
25
- if (tile.attributeData) {
26
- attributeUrls = (0, url_utils_1.generateTileAttributeUrls)(url, tile);
27
- }
28
- const children = tile.children || [];
29
- return normalizeTileNonUrlData({
30
- ...tile,
31
- children,
32
- url,
33
- contentUrl,
34
- textureUrl,
35
- textureFormat: 'jpg',
36
- attributeUrls,
37
- isDracoGeometry: false
38
- });
39
- }
40
- exports.normalizeTileData = normalizeTileData;
41
- function normalizeTileNonUrlData(tile) {
42
- const boundingVolume = {};
43
- let mbs = [0, 0, 0, 1];
44
- if (tile.mbs) {
45
- mbs = tile.mbs;
46
- boundingVolume.sphere = [
47
- ...geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(tile.mbs.slice(0, 3)),
48
- tile.mbs[3] // radius of sphere
49
- ];
50
- }
51
- else if (tile.obb) {
52
- boundingVolume.box = [
53
- ...geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(tile.obb.center),
54
- ...tile.obb.halfSize,
55
- ...tile.obb.quaternion // quaternion
56
- ];
57
- const obb = new culling_1.OrientedBoundingBox().fromCenterHalfSizeQuaternion(boundingVolume.box.slice(0, 3), tile.obb.halfSize, tile.obb.quaternion);
58
- const boundingSphere = obb.getBoundingSphere();
59
- boundingVolume.sphere = [...boundingSphere.center, boundingSphere.radius];
60
- mbs = [...tile.obb.center, boundingSphere.radius];
61
- }
62
- const lodMetricType = tile.lodSelection?.[0].metricType;
63
- const lodMetricValue = tile.lodSelection?.[0].maxError;
64
- const type = tiles_1.TILE_TYPE.MESH;
65
- /**
66
- * I3S specification supports only REPLACE
67
- */
68
- const refine = tiles_1.TILE_REFINEMENT.REPLACE;
69
- return { ...tile, mbs, boundingVolume, lodMetricType, lodMetricValue, type, refine };
70
- }
71
- exports.normalizeTileNonUrlData = normalizeTileNonUrlData;
72
- async function normalizeTilesetData(tileset, options, context) {
73
- const url = context.url;
74
- let nodePagesTile;
75
- let root;
76
- if (tileset.nodePages) {
77
- nodePagesTile = new i3s_nodepages_tiles_1.default(tileset, url, options);
78
- root = await nodePagesTile.formTileFromNodePages(0);
79
- }
80
- else {
81
- // @ts-expect-error options is not properly typed
82
- const rootNodeUrl = (0, url_utils_1.getUrlWithToken)(`${tileset.url}/nodes/root`, options.i3s?.token);
83
- // eslint-disable-next-line no-use-before-define
84
- root = await (0, core_1.load)(rootNodeUrl, i3s_loader_1.I3SLoader, {
85
- ...options,
86
- i3s: {
87
- // @ts-expect-error options is not properly typed
88
- ...options.i3s,
89
- loadContent: false, isTileHeader: true, isTileset: false
90
- }
91
- });
92
- }
93
- return {
94
- ...tileset,
95
- loader: i3s_loader_1.I3SLoader,
96
- url,
97
- basePath: url,
98
- type: tiles_1.TILESET_TYPE.I3S,
99
- nodePagesTile,
100
- root,
101
- lodMetricType: root.lodMetricType,
102
- lodMetricValue: root.lodMetricValue
103
- };
104
- }
105
- exports.normalizeTilesetData = normalizeTilesetData;
@@ -1 +0,0 @@
1
- {"version":3,"file":"parse-slpk.d.ts","sourceRoot":"","sources":["../../../../src/lib/parsers/parse-slpk/parse-slpk.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EAMb,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAE5C;;;;;GAKG;AACH,eAAO,MAAM,SAAS,iBACN,YAAY,cACf,MAAM,KAAK,IAAI,kBACzB,QAAQ,WAAW,CA8BrB,CAAC"}
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseSLPK = void 0;
4
- const zip_1 = require("@loaders.gl/zip");
5
- const slpk_archieve_1 = require("./slpk-archieve");
6
- /**
7
- * Creates slpk file handler from raw file
8
- * @param fileProvider raw file data
9
- * @param cb is called with information message during parsing
10
- * @returns slpk file handler
11
- */
12
- const parseSLPK = async (fileProvider, cb) => {
13
- const hashCDOffset = await (0, zip_1.searchFromTheEnd)(fileProvider, zip_1.cdSignature);
14
- const cdFileHeader = await (0, zip_1.parseZipCDFileHeader)(hashCDOffset, fileProvider);
15
- let hashData;
16
- if (cdFileHeader?.fileName !== '@specialIndexFileHASH128@') {
17
- cb?.('SLPK doesnt contain hash file');
18
- hashData = await (0, zip_1.generateHashInfo)(fileProvider);
19
- cb?.('hash info has been composed according to central directory records');
20
- }
21
- else {
22
- cb?.('SLPK contains hash file');
23
- const localFileHeader = await (0, zip_1.parseZipLocalFileHeader)(cdFileHeader.localHeaderOffset, fileProvider);
24
- if (!localFileHeader) {
25
- throw new Error('corrupted SLPK');
26
- }
27
- const fileDataOffset = localFileHeader.fileDataOffset;
28
- const hashFile = await fileProvider.slice(fileDataOffset, fileDataOffset + localFileHeader.compressedSize);
29
- hashData = (0, zip_1.parseHashFile)(hashFile);
30
- }
31
- return new slpk_archieve_1.SLPKArchive(fileProvider, hashData);
32
- };
33
- exports.parseSLPK = parseSLPK;
@@ -1 +0,0 @@
1
- {"version":3,"file":"slpk-archieve.d.ts","sourceRoot":"","sources":["../../../../src/lib/parsers/parse-slpk/slpk-archieve.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,YAAY,EAA2B,WAAW,EAAU,MAAM,iBAAiB,CAAC;AAuC5F;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,WAAW,CAAe;IAClC,OAAO,CAAC,SAAS,CAAgB;gBACrB,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE;IAK9D;;;;;OAKG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,GAAG,KAAa,GAAG,OAAO,CAAC,MAAM,CAAC;IA8B1E;;;;OAIG;YACW,aAAa;IAmB3B;;;;OAIG;YACW,YAAY;IAmB1B,OAAO,CAAC,QAAQ,EAAE,MAAM;CAGzB"}