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