@loaders.gl/i3s 3.2.6 → 3.3.0-alpha.2

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 (57) hide show
  1. package/dist/dist.min.js +62 -55
  2. package/dist/es5/arcgis-webscene-loader.js +1 -1
  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 +19 -8
  9. package/dist/es5/i3s-content-loader.js.map +1 -1
  10. package/dist/es5/i3s-loader.js +36 -38
  11. package/dist/es5/i3s-loader.js.map +1 -1
  12. package/dist/es5/i3s-node-page-loader.js +1 -1
  13. package/dist/es5/i3s-node-page-loader.js.map +1 -1
  14. package/dist/es5/lib/parsers/parse-i3s-tile-content.js +76 -77
  15. package/dist/es5/lib/parsers/parse-i3s-tile-content.js.map +1 -1
  16. package/dist/es5/lib/parsers/parse-i3s.js +1 -1
  17. package/dist/es5/lib/parsers/parse-i3s.js.map +1 -1
  18. package/dist/es5/types.js.map +1 -1
  19. package/dist/esm/arcgis-webscene-loader.js +1 -1
  20. package/dist/esm/arcgis-webscene-loader.js.map +1 -1
  21. package/dist/esm/i3s-attribute-loader.js +1 -1
  22. package/dist/esm/i3s-attribute-loader.js.map +1 -1
  23. package/dist/esm/i3s-building-scene-layer-loader.js +1 -1
  24. package/dist/esm/i3s-building-scene-layer-loader.js.map +1 -1
  25. package/dist/esm/i3s-content-loader.js +12 -4
  26. package/dist/esm/i3s-content-loader.js.map +1 -1
  27. package/dist/esm/i3s-loader.js +8 -12
  28. package/dist/esm/i3s-loader.js.map +1 -1
  29. package/dist/esm/i3s-node-page-loader.js +1 -1
  30. package/dist/esm/i3s-node-page-loader.js.map +1 -1
  31. package/dist/esm/lib/parsers/parse-i3s-tile-content.js +37 -34
  32. package/dist/esm/lib/parsers/parse-i3s-tile-content.js.map +1 -1
  33. package/dist/esm/lib/parsers/parse-i3s.js +1 -1
  34. package/dist/esm/lib/parsers/parse-i3s.js.map +1 -1
  35. package/dist/esm/types.js.map +1 -1
  36. package/dist/i3s-building-scene-layer-loader.js +1 -1
  37. package/dist/i3s-content-loader.d.ts.map +1 -1
  38. package/dist/i3s-content-loader.js +8 -4
  39. package/dist/i3s-content-worker.js +56 -48
  40. package/dist/i3s-loader.d.ts +5 -0
  41. package/dist/i3s-loader.d.ts.map +1 -1
  42. package/dist/i3s-loader.js +6 -9
  43. package/dist/lib/parsers/parse-i3s-tile-content.d.ts +2 -2
  44. package/dist/lib/parsers/parse-i3s-tile-content.d.ts.map +1 -1
  45. package/dist/lib/parsers/parse-i3s-tile-content.js +36 -32
  46. package/dist/lib/parsers/parse-i3s.d.ts +1 -1
  47. package/dist/lib/parsers/parse-i3s.d.ts.map +1 -1
  48. package/dist/lib/parsers/parse-i3s.js +1 -1
  49. package/dist/types.d.ts +41 -0
  50. package/dist/types.d.ts.map +1 -1
  51. package/package.json +8 -8
  52. package/src/i3s-building-scene-layer-loader.ts +1 -1
  53. package/src/i3s-content-loader.ts +18 -6
  54. package/src/i3s-loader.ts +15 -12
  55. package/src/lib/parsers/parse-i3s-tile-content.ts +46 -41
  56. package/src/lib/parsers/parse-i3s.ts +1 -1
  57. package/src/types.ts +45 -0
@@ -8,15 +8,16 @@ import {DracoLoader, DracoMesh} from '@loaders.gl/draco';
8
8
  import {BasisLoader, CompressedTextureLoader} from '@loaders.gl/textures';
9
9
 
10
10
  import {
11
- I3STilesetHeader,
12
- I3STileHeader,
13
11
  FeatureAttribute,
14
12
  VertexAttribute,
15
13
  I3SMeshAttributes,
16
14
  I3SMeshAttribute,
17
15
  TileContentTexture,
18
16
  HeaderAttributeProperty,
19
- I3SMaterialDefinition
17
+ I3SMaterialDefinition,
18
+ I3STileContent,
19
+ I3STileOptions,
20
+ I3STilesetOptions
20
21
  } from '../../types';
21
22
  import {getUrlWithToken} from '../utils/url-utils';
22
23
 
@@ -40,43 +41,51 @@ function getLoaderForTextureFormat(textureFormat?: 'jpg' | 'png' | 'ktx-etc2' |
40
41
 
41
42
  const I3S_ATTRIBUTE_TYPE = 'i3s-attribute-type';
42
43
 
44
+ const defaultContent: I3STileContent = {
45
+ attributes: {},
46
+ indices: null,
47
+ featureIds: [],
48
+ vertexCount: 0,
49
+ modelMatrix: new Matrix4(),
50
+ coordinateSystem: 0,
51
+ byteLength: 0,
52
+ texture: null
53
+ };
54
+
43
55
  export async function parseI3STileContent(
44
56
  arrayBuffer: ArrayBuffer,
45
- tile: I3STileHeader,
46
- tileset: I3STilesetHeader,
57
+ tileOptions: I3STileOptions,
58
+ tilesetOptions: I3STilesetOptions,
47
59
  options?: LoaderOptions,
48
60
  context?: LoaderContext
49
- ) {
50
- tile.content = tile.content || {};
51
- tile.content.featureIds = tile.content.featureIds || null;
52
-
53
- tile.content.attributes = {};
61
+ ): Promise<I3STileContent> {
62
+ const content: I3STileContent = defaultContent;
54
63
 
55
- if (tile.textureUrl) {
56
- const url = getUrlWithToken(tile.textureUrl, options?.i3s?.token);
57
- const loader = getLoaderForTextureFormat(tile.textureFormat);
64
+ if (tileOptions.textureUrl) {
65
+ const url = getUrlWithToken(tileOptions.textureUrl, options?.i3s?.token);
66
+ const loader = getLoaderForTextureFormat(tileOptions.textureFormat);
58
67
  const response = await fetch(url, options?.fetch as RequestInit);
59
68
  const arrayBuffer = await response.arrayBuffer();
60
69
 
61
70
  if (options?.i3s.decodeTextures) {
62
71
  if (loader === ImageLoader) {
63
- const options = {...tile.textureLoaderOptions, image: {type: 'data'}};
72
+ const options = {...tileOptions.textureLoaderOptions, image: {type: 'data'}};
64
73
  try {
65
74
  // @ts-ignore context must be defined
66
75
  // Image constructor is not supported in worker thread.
67
76
  // Do parsing image data on the main thread by using context to avoid worker issues.
68
- tile.content.texture = await context.parse(arrayBuffer, options);
77
+ content.texture = await context.parse(arrayBuffer, options);
69
78
  } catch (e) {
70
79
  // context object is different between worker and node.js conversion script.
71
80
  // To prevent error we parse data in ordinary way if it is not parsed by using context.
72
- tile.content.texture = await parse(arrayBuffer, loader, options);
81
+ content.texture = await parse(arrayBuffer, loader, options);
73
82
  }
74
83
  } else if (loader === CompressedTextureLoader || loader === BasisLoader) {
75
- let texture = await load(arrayBuffer, loader, tile.textureLoaderOptions);
84
+ let texture = await load(arrayBuffer, loader, tileOptions.textureLoaderOptions);
76
85
  if (loader === BasisLoader) {
77
86
  texture = texture[0];
78
87
  }
79
- tile.content.texture = {
88
+ content.texture = {
80
89
  compressed: true,
81
90
  mipmaps: false,
82
91
  width: texture[0].width,
@@ -85,30 +94,26 @@ export async function parseI3STileContent(
85
94
  };
86
95
  }
87
96
  } else {
88
- tile.content.texture = arrayBuffer;
97
+ content.texture = arrayBuffer;
89
98
  }
90
99
  }
91
100
 
92
- tile.content.material = makePbrMaterial(tile.materialDefinition, tile.content.texture);
93
- if (tile.content.material) {
94
- tile.content.texture = null;
101
+ content.material = makePbrMaterial(tileOptions.materialDefinition, content.texture);
102
+ if (content.material) {
103
+ content.texture = null;
95
104
  }
96
105
 
97
- return await parseI3SNodeGeometry(arrayBuffer, tile, tileset, options);
106
+ return await parseI3SNodeGeometry(arrayBuffer, content, tileOptions, tilesetOptions, options);
98
107
  }
99
108
 
100
109
  /* eslint-disable max-statements */
101
110
  async function parseI3SNodeGeometry(
102
111
  arrayBuffer: ArrayBuffer,
103
- tile: I3STileHeader,
104
- tileset: I3STilesetHeader,
112
+ content: I3STileContent,
113
+ tileOptions: I3STileOptions,
114
+ tilesetOptions: I3STilesetOptions,
105
115
  options?: LoaderOptions
106
- ) {
107
- if (!tile.content) {
108
- return tile;
109
- }
110
-
111
- const content = tile.content;
116
+ ): Promise<I3STileContent> {
112
117
  const contentByteLength = arrayBuffer.byteLength;
113
118
  let attributes: I3SMeshAttributes;
114
119
  let vertexCount: number;
@@ -116,7 +121,7 @@ async function parseI3SNodeGeometry(
116
121
  let featureCount: number = 0;
117
122
  let indices: TypedArray | undefined;
118
123
 
119
- if (tile.isDracoGeometry) {
124
+ if (tileOptions.isDracoGeometry) {
120
125
  const decompressedGeometry: DracoMesh = await parse(arrayBuffer, DracoLoader, {
121
126
  draco: {
122
127
  attributeNameEntry: I3S_ATTRIBUTE_TYPE
@@ -156,9 +161,9 @@ async function parseI3SNodeGeometry(
156
161
  ordering: attributesOrder,
157
162
  featureAttributes,
158
163
  featureAttributeOrder
159
- } = tileset.store.defaultGeometrySchema;
164
+ } = tilesetOptions.store.defaultGeometrySchema;
160
165
  // First 8 bytes reserved for header (vertexCount and featureCount)
161
- const headers = parseHeaders(tileset, arrayBuffer);
166
+ const headers = parseHeaders(arrayBuffer, tilesetOptions);
162
167
  byteOffset = headers.byteOffset;
163
168
  vertexCount = headers.vertexCount;
164
169
  featureCount = headers.featureCount;
@@ -188,7 +193,7 @@ async function parseI3SNodeGeometry(
188
193
  !options?.i3s?.coordinateSystem ||
189
194
  options.i3s.coordinateSystem === COORDINATE_SYSTEM.METER_OFFSETS
190
195
  ) {
191
- const enuMatrix = parsePositions(attributes.position, tile);
196
+ const enuMatrix = parsePositions(attributes.position, tileOptions);
192
197
  content.modelMatrix = enuMatrix.invert();
193
198
  content.coordinateSystem = COORDINATE_SYSTEM.METER_OFFSETS;
194
199
  } else {
@@ -206,7 +211,7 @@ async function parseI3SNodeGeometry(
206
211
  content.indices = indices || null;
207
212
 
208
213
  if (attributes.id && attributes.id.value) {
209
- tile.content.featureIds = attributes.id.value;
214
+ content.featureIds = attributes.id.value;
210
215
  }
211
216
 
212
217
  // Remove undefined attributes
@@ -219,7 +224,7 @@ async function parseI3SNodeGeometry(
219
224
  content.vertexCount = vertexCount;
220
225
  content.byteLength = contentByteLength;
221
226
 
222
- return tile;
227
+ return content;
223
228
  }
224
229
 
225
230
  /**
@@ -274,12 +279,12 @@ function normalizeAttribute(attribute: I3SMeshAttribute): I3SMeshAttribute {
274
279
  return attribute;
275
280
  }
276
281
 
277
- function parseHeaders(tileset: I3STilesetHeader, arrayBuffer: ArrayBuffer) {
282
+ function parseHeaders(arrayBuffer: ArrayBuffer, options: I3STilesetOptions) {
278
283
  let byteOffset = 0;
279
284
  // First 8 bytes reserved for header (vertexCount and featurecount)
280
285
  let vertexCount = 0;
281
286
  let featureCount = 0;
282
- for (const {property, type} of tileset.store.defaultGeometrySchema.header) {
287
+ for (const {property, type} of options.store.defaultGeometrySchema.header) {
283
288
  const TypedArrayTypeHeader = getConstructorForDataFormat(type);
284
289
  switch (property) {
285
290
  case HeaderAttributeProperty.vertexCount:
@@ -394,8 +399,8 @@ function parseUint64Values(
394
399
  return new Uint32Array(values);
395
400
  }
396
401
 
397
- function parsePositions(attribute: I3SMeshAttribute, tile: I3STileHeader): Matrix4 {
398
- const mbs = tile.mbs;
402
+ function parsePositions(attribute: I3SMeshAttribute, options: I3STileOptions): Matrix4 {
403
+ const mbs = options.mbs;
399
404
  const value = attribute.value;
400
405
  const metadata = attribute.metadata;
401
406
  const enuMatrix = new Matrix4();
@@ -13,7 +13,7 @@ import {
13
13
  } from '../../types';
14
14
  import type {LoaderOptions, LoaderContext} from '@loaders.gl/loader-utils';
15
15
 
16
- export function normalizeTileData(tile : Node3DIndexDocument, options : LoaderOptions, context: LoaderContext): I3STileHeader {
16
+ export function normalizeTileData(tile : Node3DIndexDocument, context: LoaderContext): I3STileHeader {
17
17
  const url: string = context.url || '';
18
18
  let contentUrl: string | undefined;
19
19
  if (tile.geometryData) {
package/src/types.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type {Matrix4, Quaternion, Vector3} from '@math.gl/core';
2
2
  import type {TypedArray, MeshAttribute, TextureLevel} from '@loaders.gl/schema';
3
+ import {Tile3D, Tileset3D} from '@loaders.gl/tiles';
3
4
 
4
5
  export enum DATA_TYPE {
5
6
  UInt8 = 'UInt8',
@@ -80,6 +81,50 @@ export type I3STileHeader = {
80
81
  lodSelection?: LodSelection[];
81
82
  [key: string]: any;
82
83
  };
84
+
85
+ export type I3SParseOptions = {
86
+ /** ArcGIS access token */
87
+ token?: string;
88
+ /** Is 3DSceneLayer json expected in response */
89
+ isTileset?: string;
90
+ /** Is 3DNodeIndexDocument json expected in response */
91
+ isTileHeader?: string;
92
+ /** Tile3D instance. This property used only to load tile content */
93
+ /** @deprecated */
94
+ tile?: Tile3D | I3STileOptions;
95
+ /** Tileset3D instance. This property used only to load tile content */
96
+ /** @deprecated */
97
+ tileset?: Tileset3D | I3STilesetOptions;
98
+ /** Tile-specific options */
99
+ _tileOptions?: I3STileOptions;
100
+ /** Tileset-specific options */
101
+ _tilesetOptions?: I3STilesetOptions;
102
+ /** Load Draco Compressed geometry if available */
103
+ useDracoGeometry?: boolean;
104
+ /** Load compressed textures if available */
105
+ useCompressedTextures?: boolean;
106
+ /** Set false if don't need to parse textures */
107
+ decodeTextures?: boolean;
108
+ /** deck.gl compatible coordinate system.
109
+ * https://github.com/visgl/deck.gl/blob/master/docs/developer-guide/coordinate-systems.md
110
+ * Supported coordinate systems: METER_OFFSETS, LNGLAT_OFFSETS
111
+ */
112
+ coordinateSystem?: number;
113
+ };
114
+
115
+ export type I3STileOptions = {
116
+ isDracoGeometry: boolean;
117
+ textureUrl?: string;
118
+ textureFormat?: I3STextureFormat;
119
+ textureLoaderOptions?: any;
120
+ materialDefinition?: I3SMaterialDefinition;
121
+ mbs: Mbs;
122
+ };
123
+
124
+ export type I3STilesetOptions = {
125
+ store: Store;
126
+ };
127
+
83
128
  // TODO Replace "[key: string]: any" with actual defenition
84
129
  export type I3STileContent = {
85
130
  attributes: I3SMeshAttributes;