@loaders.gl/i3s 3.1.0-beta.7 → 3.1.3

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 (91) hide show
  1. package/dist/bundle.js +5 -10364
  2. package/dist/dist.min.js +10371 -0
  3. package/dist/es5/bundle.js +1 -1
  4. package/dist/es5/bundle.js.map +1 -1
  5. package/dist/es5/i3s-attribute-loader.js +147 -62
  6. package/dist/es5/i3s-attribute-loader.js.map +1 -1
  7. package/dist/es5/i3s-building-scene-layer-loader.js +36 -8
  8. package/dist/es5/i3s-building-scene-layer-loader.js.map +1 -1
  9. package/dist/es5/i3s-content-loader.js +36 -10
  10. package/dist/es5/i3s-content-loader.js.map +1 -1
  11. package/dist/es5/i3s-loader.js +175 -51
  12. package/dist/es5/i3s-loader.js.map +1 -1
  13. package/dist/es5/i3s-node-page-loader.js +51 -8
  14. package/dist/es5/i3s-node-page-loader.js.map +1 -1
  15. package/dist/es5/index.js +6 -6
  16. package/dist/es5/index.js.map +1 -1
  17. package/dist/es5/lib/helpers/i3s-nodepages-tiles.js +328 -173
  18. package/dist/es5/lib/helpers/i3s-nodepages-tiles.js.map +1 -1
  19. package/dist/es5/lib/parsers/constants.js +9 -28
  20. package/dist/es5/lib/parsers/constants.js.map +1 -1
  21. package/dist/es5/lib/parsers/parse-i3s-attribute.js +69 -27
  22. package/dist/es5/lib/parsers/parse-i3s-attribute.js.map +1 -1
  23. package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js +62 -28
  24. package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js.map +1 -1
  25. package/dist/es5/lib/parsers/parse-i3s-tile-content.js +416 -314
  26. package/dist/es5/lib/parsers/parse-i3s-tile-content.js.map +1 -1
  27. package/dist/es5/lib/parsers/parse-i3s.js +109 -49
  28. package/dist/es5/lib/parsers/parse-i3s.js.map +1 -1
  29. package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js +8 -4
  30. package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js.map +1 -1
  31. package/dist/es5/lib/utils/url-utils.js +14 -17
  32. package/dist/es5/lib/utils/url-utils.js.map +1 -1
  33. package/dist/es5/types.js +10 -2
  34. package/dist/es5/types.js.map +1 -1
  35. package/dist/esm/i3s-attribute-loader.js +1 -1
  36. package/dist/esm/i3s-attribute-loader.js.map +1 -1
  37. package/dist/esm/i3s-building-scene-layer-loader.js +1 -1
  38. package/dist/esm/i3s-building-scene-layer-loader.js.map +1 -1
  39. package/dist/esm/i3s-content-loader.js +1 -1
  40. package/dist/esm/i3s-content-loader.js.map +1 -1
  41. package/dist/esm/i3s-loader.js +1 -1
  42. package/dist/esm/i3s-loader.js.map +1 -1
  43. package/dist/esm/i3s-node-page-loader.js +1 -1
  44. package/dist/esm/i3s-node-page-loader.js.map +1 -1
  45. package/dist/esm/index.js.map +1 -1
  46. package/dist/esm/lib/helpers/i3s-nodepages-tiles.js +33 -23
  47. package/dist/esm/lib/helpers/i3s-nodepages-tiles.js.map +1 -1
  48. package/dist/esm/lib/parsers/constants.js +2 -18
  49. package/dist/esm/lib/parsers/constants.js.map +1 -1
  50. package/dist/esm/lib/parsers/parse-i3s-tile-content.js +44 -61
  51. package/dist/esm/lib/parsers/parse-i3s-tile-content.js.map +1 -1
  52. package/dist/esm/lib/parsers/parse-i3s.js +40 -25
  53. package/dist/esm/lib/parsers/parse-i3s.js.map +1 -1
  54. package/dist/esm/lib/utils/url-utils.js +2 -3
  55. package/dist/esm/lib/utils/url-utils.js.map +1 -1
  56. package/dist/esm/types.js +7 -0
  57. package/dist/esm/types.js.map +1 -1
  58. package/dist/i3s-building-scene-layer-loader.js +1 -1
  59. package/dist/i3s-content-loader.js +1 -1
  60. package/dist/i3s-content-worker.js +106 -95
  61. package/dist/index.d.ts +1 -1
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/lib/helpers/i3s-nodepages-tiles.d.ts +20 -20
  64. package/dist/lib/helpers/i3s-nodepages-tiles.d.ts.map +1 -1
  65. package/dist/lib/helpers/i3s-nodepages-tiles.js +33 -32
  66. package/dist/lib/parsers/constants.d.ts +1 -17
  67. package/dist/lib/parsers/constants.d.ts.map +1 -1
  68. package/dist/lib/parsers/constants.js +3 -21
  69. package/dist/lib/parsers/parse-i3s-attribute.d.ts +1 -1
  70. package/dist/lib/parsers/parse-i3s-tile-content.d.ts +2 -2
  71. package/dist/lib/parsers/parse-i3s-tile-content.d.ts.map +1 -1
  72. package/dist/lib/parsers/parse-i3s-tile-content.js +35 -61
  73. package/dist/lib/parsers/parse-i3s.d.ts +5 -3
  74. package/dist/lib/parsers/parse-i3s.d.ts.map +1 -1
  75. package/dist/lib/parsers/parse-i3s.js +37 -32
  76. package/dist/lib/utils/url-utils.d.ts +6 -6
  77. package/dist/lib/utils/url-utils.d.ts.map +1 -1
  78. package/dist/lib/utils/url-utils.js +5 -5
  79. package/dist/types.d.ts +289 -74
  80. package/dist/types.d.ts.map +1 -1
  81. package/dist/types.js +6 -1
  82. package/package.json +10 -10
  83. package/src/i3s-building-scene-layer-loader.ts +1 -1
  84. package/src/i3s-content-loader.ts +1 -1
  85. package/src/index.ts +3 -3
  86. package/src/lib/helpers/i3s-nodepages-tiles.ts +71 -55
  87. package/src/lib/parsers/constants.ts +2 -22
  88. package/src/lib/parsers/parse-i3s-tile-content.ts +74 -103
  89. package/src/lib/parsers/parse-i3s.ts +48 -37
  90. package/src/lib/utils/url-utils.ts +7 -7
  91. package/src/types.ts +302 -93
@@ -21,8 +21,8 @@ class I3SNodePagesTiles {
21
21
  this.textureDefinitionsSelectedFormats = [];
22
22
  this.textureLoaderOptions = {};
23
23
  this.tileset = { ...tileset }; // spread the tileset to avoid circular reference
24
- this.nodesPerPage = tileset.nodePages.nodesPerPage;
25
- this.lodSelectionMetricType = tileset.nodePages.lodSelectionMetricType;
24
+ this.nodesPerPage = tileset.nodePages?.nodesPerPage || 64;
25
+ this.lodSelectionMetricType = tileset.nodePages?.lodSelectionMetricType;
26
26
  this.options = options;
27
27
  this.initSelectedFormatsForTextureDefinitions(tileset);
28
28
  }
@@ -58,23 +58,23 @@ class I3SNodePagesTiles {
58
58
  for (const child of node.children || []) {
59
59
  const childNode = await this.getNodeById(child);
60
60
  children.push({
61
- id: child,
61
+ id: child.toString(),
62
62
  obb: childNode.obb
63
63
  });
64
64
  }
65
- let contentUrl = null;
66
- let textureUrl = null;
67
- let materialDefinition = null;
68
- let textureFormat = 'jpeg';
65
+ let contentUrl;
66
+ let textureUrl;
67
+ let materialDefinition;
68
+ let textureFormat = 'jpg';
69
69
  let attributeUrls = [];
70
70
  let isDracoGeometry = false;
71
71
  if (node && node.mesh) {
72
72
  // Get geometry resource URL and type (compressed / non-compressed)
73
73
  const { url, isDracoGeometry: isDracoGeometryResult } = (node.mesh.geometry &&
74
- this.getContentUrl(node.mesh.geometry)) || { url: null, isDracoGeometry: null };
74
+ this.getContentUrl(node.mesh.geometry)) || { isDracoGeometry: false };
75
75
  contentUrl = url;
76
76
  isDracoGeometry = isDracoGeometryResult;
77
- const [textureData, nodeMaterialDefinition] = this.getInformationFromMaterial(node.mesh.material);
77
+ const { textureData, materialDefinition: nodeMaterialDefinition } = this.getInformationFromMaterial(node.mesh.material);
78
78
  materialDefinition = nodeMaterialDefinition;
79
79
  textureFormat = textureData.format || textureFormat;
80
80
  if (textureData.name) {
@@ -86,7 +86,7 @@ class I3SNodePagesTiles {
86
86
  }
87
87
  const lodSelection = this.getLodSelection(node);
88
88
  return (0, parse_i3s_1.normalizeTileNonUrlData)({
89
- id,
89
+ id: id.toString(),
90
90
  lodSelection,
91
91
  obb: node.obb,
92
92
  contentUrl,
@@ -101,13 +101,14 @@ class I3SNodePagesTiles {
101
101
  }
102
102
  /**
103
103
  * Forms url and type of geometry resource by nodepage's data and `geometryDefinitions` in the tileset
104
- * @param {Object} meshGeometryData - data about the node's mesh from the nodepage
105
- * @returns {Object} -
104
+ * @param - data about the node's mesh from the nodepage
105
+ * @returns -
106
106
  * {string} url - url to the geometry resource
107
107
  * {boolean} isDracoGeometry - whether the geometry resource contain DRACO compressed geometry
108
108
  */
109
109
  getContentUrl(meshGeometryData) {
110
- let result = {};
110
+ let result = null;
111
+ // @ts-ignore
111
112
  const geometryDefinition = this.tileset.geometryDefinitions[meshGeometryData.definition];
112
113
  let geometryIndex = -1;
113
114
  // Try to find DRACO geometryDefinition of `useDracoGeometry` option is set
@@ -129,53 +130,53 @@ class I3SNodePagesTiles {
129
130
  }
130
131
  /**
131
132
  * Forms 1.6 compatible LOD selection object from a nodepage's node data
132
- * @param {Object} node - a node from nodepage
133
- * @returns {Object[]} - Array of object of following properties:
134
- * {string} metricType - the label of the LOD metric
135
- * {number} maxError - the value of the metric
133
+ * @param node - a node from nodepage
134
+ * @returns- Array of LodSelection
136
135
  */
137
136
  getLodSelection(node) {
138
137
  const lodSelection = [];
139
138
  if (this.lodSelectionMetricType === 'maxScreenThresholdSQ') {
140
139
  lodSelection.push({
141
140
  metricType: 'maxScreenThreshold',
141
+ // @ts-ignore
142
142
  maxError: Math.sqrt(node.lodThreshold / (Math.PI * 0.25))
143
143
  });
144
144
  }
145
145
  lodSelection.push({
146
146
  metricType: this.lodSelectionMetricType,
147
+ // @ts-ignore
147
148
  maxError: node.lodThreshold
148
149
  });
149
150
  return lodSelection;
150
151
  }
151
152
  /**
152
153
  * Returns information about texture and material from `materialDefinitions`
153
- * @param {Object} material - material data from nodepage
154
- * @returns {Object[]} - Couple [textureData, materialDefinition]
154
+ * @param material - material data from nodepage
155
+ * @returns - Couple {textureData, materialDefinition}
155
156
  * {string} textureData.name - path name of the texture
156
157
  * {string} textureData.format - format of the texture
157
158
  * materialDefinition - PBR-like material definition from `materialDefinitions`
158
159
  */
159
160
  getInformationFromMaterial(material) {
160
- const textureDataDefault = { name: null, format: null };
161
+ const informationFromMaterial = { textureData: { name: null } };
161
162
  if (material) {
162
- const materialDefinition = this.tileset.materialDefinitions[material.definition];
163
- const textureSetDefinitionIndex = materialDefinition &&
164
- materialDefinition.pbrMetallicRoughness &&
165
- materialDefinition.pbrMetallicRoughness.baseColorTexture &&
166
- materialDefinition.pbrMetallicRoughness.baseColorTexture.textureSetDefinitionId;
167
- if (textureSetDefinitionIndex || textureSetDefinitionIndex === 0) {
168
- const textureData = this.textureDefinitionsSelectedFormats[textureSetDefinitionIndex] || textureDataDefault;
169
- return [textureData, materialDefinition];
163
+ const materialDefinition = this.tileset.materialDefinitions?.[material.definition];
164
+ if (materialDefinition) {
165
+ informationFromMaterial.materialDefinition = materialDefinition;
166
+ const textureSetDefinitionIndex = materialDefinition?.pbrMetallicRoughness?.baseColorTexture?.textureSetDefinitionId;
167
+ if (typeof textureSetDefinitionIndex === 'number') {
168
+ informationFromMaterial.textureData =
169
+ this.textureDefinitionsSelectedFormats[textureSetDefinitionIndex] ||
170
+ informationFromMaterial.textureData;
171
+ }
170
172
  }
171
- return [textureDataDefault, materialDefinition];
172
173
  }
173
- return [textureDataDefault, null];
174
+ return informationFromMaterial;
174
175
  }
175
176
  /**
176
177
  * Sets preferable and supported format for each textureDefinition of the tileset
177
- * @param {Object} tileset - I3S layer data
178
- * @returns {void}
178
+ * @param tileset - I3S layer data
179
+ * @returns
179
180
  */
180
181
  initSelectedFormatsForTextureDefinitions(tileset) {
181
182
  this.textureDefinitionsSelectedFormats = [];
@@ -1,23 +1,7 @@
1
- export declare function getConstructorForDataFormat(dataType: string): Uint8ArrayConstructor | Uint16ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor | null;
1
+ export declare function getConstructorForDataFormat(dataType: string): Uint8ArrayConstructor | Uint16ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor;
2
2
  export declare const GL_TYPE_MAP: {
3
3
  [key: string]: number;
4
4
  };
5
- export declare const I3S_NAMED_VERTEX_ATTRIBUTES: {
6
- position: string;
7
- normal: string;
8
- uv0: string;
9
- color: string;
10
- region: string;
11
- };
12
- export declare const I3S_NAMED_GEOMETRY_ATTRIBUTES: {
13
- vertexAttributes: string;
14
- featureAttributeOrder: string;
15
- featureAttributes: string;
16
- };
17
- export declare const I3S_NAMED_HEADER_ATTRIBUTES: {
18
- vertexCount: string;
19
- featureCount: string;
20
- };
21
5
  /**
22
6
  * Returns how many bytes a type occupies
23
7
  * @param dataType
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/constants.ts"],"names":[],"mappings":"AAGA,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,MAAM,sIAe3D;AAED,eAAO,MAAM,WAAW,EAAE;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAM/C,CAAC;AAEF,eAAO,MAAM,2BAA2B;;;;;;CAMvC,CAAC;AAEF,eAAO,MAAM,6BAA6B;;;;CAIzC,CAAC;AAEF,eAAO,MAAM,2BAA2B;;;CAIvC,CAAC;AACF;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAkB/C;AAED,eAAO,MAAM,qBAAqB,WAAW,CAAC;AAC9C,eAAO,MAAM,wBAAwB,UAAU,CAAC;AAChD,eAAO,MAAM,aAAa,YAAY,CAAC;AACvC,eAAO,MAAM,qBAAqB,UAAU,CAAC;AAI7C,oBAAY,iBAAiB;IAC3B;;OAEG;IACH,OAAO,KAAK;IACZ;;;OAGG;IACH,MAAM,IAAI;IACV;;OAEG;IACH,aAAa,IAAI;IACjB;;;;OAIG;IACH,cAAc,IAAI;IAClB;;OAEG;IACH,SAAS,IAAI;CACd"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/constants.ts"],"names":[],"mappings":"AAGA,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,MAAM,+HAe3D;AAED,eAAO,MAAM,WAAW,EAAE;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAM/C,CAAC;AACF;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAkB/C;AAED,eAAO,MAAM,qBAAqB,WAAW,CAAC;AAC9C,eAAO,MAAM,wBAAwB,UAAU,CAAC;AAChD,eAAO,MAAM,aAAa,YAAY,CAAC;AACvC,eAAO,MAAM,qBAAqB,UAAU,CAAC;AAI7C,oBAAY,iBAAiB;IAC3B;;OAEG;IACH,OAAO,KAAK;IACZ;;;OAGG;IACH,MAAM,IAAI;IACV;;OAEG;IACH,aAAa,IAAI;IACjB;;;;OAIG;IACH,cAAc,IAAI;IAClB;;OAEG;IACH,SAAS,IAAI;CACd"}
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.COORDINATE_SYSTEM = exports.INT_16_ATTRIBUTE_TYPE = exports.FLOAT_64_TYPE = exports.OBJECT_ID_ATTRIBUTE_TYPE = exports.STRING_ATTRIBUTE_TYPE = exports.sizeOf = exports.I3S_NAMED_HEADER_ATTRIBUTES = exports.I3S_NAMED_GEOMETRY_ATTRIBUTES = exports.I3S_NAMED_VERTEX_ATTRIBUTES = exports.GL_TYPE_MAP = exports.getConstructorForDataFormat = void 0;
6
+ exports.COORDINATE_SYSTEM = exports.INT_16_ATTRIBUTE_TYPE = exports.FLOAT_64_TYPE = exports.OBJECT_ID_ATTRIBUTE_TYPE = exports.STRING_ATTRIBUTE_TYPE = exports.sizeOf = exports.GL_TYPE_MAP = exports.getConstructorForDataFormat = void 0;
7
7
  const constants_1 = __importDefault(require("@luma.gl/constants"));
8
8
  const types_1 = require("../../types");
9
9
  function getConstructorForDataFormat(dataType) {
@@ -19,7 +19,7 @@ function getConstructorForDataFormat(dataType) {
19
19
  case types_1.DATA_TYPE.UInt64:
20
20
  return Float64Array;
21
21
  default:
22
- return null;
22
+ throw new Error(`parse i3s tile content: unknown type of data: ${dataType}`);
23
23
  }
24
24
  }
25
25
  exports.getConstructorForDataFormat = getConstructorForDataFormat;
@@ -30,24 +30,6 @@ exports.GL_TYPE_MAP = {
30
30
  UInt32: constants_1.default.UNSIGNED_INT,
31
31
  UInt64: constants_1.default.DOUBLE
32
32
  };
33
- exports.I3S_NAMED_VERTEX_ATTRIBUTES = {
34
- position: 'position',
35
- normal: 'normal',
36
- uv0: 'uv0',
37
- color: 'color',
38
- region: 'region'
39
- };
40
- exports.I3S_NAMED_GEOMETRY_ATTRIBUTES = {
41
- vertexAttributes: 'vertexAttributes',
42
- featureAttributeOrder: 'featureAttributeOrder',
43
- featureAttributes: 'featureAttributes'
44
- };
45
- // TODO Remove Named Attributes and replase with Typescipt types
46
- exports.I3S_NAMED_HEADER_ATTRIBUTES = {
47
- // header: 'header',
48
- vertexCount: 'vertexCount',
49
- featureCount: 'featureCount'
50
- };
51
33
  /**
52
34
  * Returns how many bytes a type occupies
53
35
  * @param dataType
@@ -69,7 +51,7 @@ function sizeOf(dataType) {
69
51
  case types_1.DATA_TYPE.Float64:
70
52
  return 8;
71
53
  default:
72
- return NaN;
54
+ throw new Error(`parse i3s tile content: unknown size of data: ${dataType}`);
73
55
  }
74
56
  }
75
57
  exports.sizeOf = sizeOf;
@@ -5,6 +5,6 @@
5
5
  * @returns {Promise<object>}
6
6
  */
7
7
  export declare function parseI3STileAttribute(arrayBuffer: any, options: any): Promise<{
8
- [x: number]: Int16Array | Uint32Array | Float64Array | string[] | null;
8
+ [x: number]: string[] | Int16Array | Uint32Array | Float64Array | null;
9
9
  }>;
10
10
  //# sourceMappingURL=parse-i3s-attribute.d.ts.map
@@ -1,4 +1,4 @@
1
1
  import type { LoaderOptions, LoaderContext } from '@loaders.gl/loader-utils';
2
- import type { Tileset, Tile } from '../../types';
3
- export declare function parseI3STileContent(arrayBuffer: ArrayBuffer, tile: Tile, tileset: Tileset, options?: LoaderOptions, context?: LoaderContext): Promise<Tile>;
2
+ import { I3STilesetHeader, I3STileHeader } from '../../types';
3
+ export declare function parseI3STileContent(arrayBuffer: ArrayBuffer, tile: I3STileHeader, tileset: I3STilesetHeader, options?: LoaderOptions, context?: LoaderContext): Promise<I3STileHeader>;
4
4
  //# sourceMappingURL=parse-i3s-tile-content.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-i3s-tile-content.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-i3s-tile-content.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAC,aAAa,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAK3E,OAAO,KAAK,EACV,OAAO,EACP,IAAI,EAOL,MAAM,aAAa,CAAC;AAgCrB,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,aAAa,iBAkDxB"}
1
+ {"version":3,"file":"parse-i3s-tile-content.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-i3s-tile-content.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,aAAa,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAK3E,OAAO,EACL,gBAAgB,EAChB,aAAa,EAQd,MAAM,aAAa,CAAC;AAuBrB,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,aAAa,EACnB,OAAO,EAAE,gBAAgB,EACzB,OAAO,CAAC,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,aAAa,0BA+CxB"}
@@ -7,34 +7,31 @@ const geospatial_1 = require("@math.gl/geospatial");
7
7
  const images_1 = require("@loaders.gl/images");
8
8
  const draco_1 = require("@loaders.gl/draco");
9
9
  const textures_1 = require("@loaders.gl/textures");
10
+ const types_1 = require("../../types");
10
11
  const url_utils_1 = require("../utils/url-utils");
11
12
  const constants_1 = require("./constants");
12
13
  const scratchVector = new core_2.Vector3([0, 0, 0]);
13
14
  function getLoaderForTextureFormat(textureFormat) {
14
15
  switch (textureFormat) {
15
- case 'jpeg':
16
- case 'png':
17
- return images_1.ImageLoader;
18
16
  case 'ktx-etc2':
19
17
  case 'dds':
20
18
  return textures_1.CompressedTextureLoader;
21
19
  case 'ktx2':
22
20
  return textures_1.BasisLoader;
21
+ case 'jpg':
22
+ case 'png':
23
23
  default:
24
- return null;
24
+ return images_1.ImageLoader;
25
25
  }
26
26
  }
27
27
  const I3S_ATTRIBUTE_TYPE = 'i3s-attribute-type';
28
28
  async function parseI3STileContent(arrayBuffer, tile, tileset, options, context) {
29
29
  tile.content = tile.content || {};
30
30
  tile.content.featureIds = tile.content.featureIds || null;
31
- // construct featureData from defaultGeometrySchema;
32
- tile.content.featureData = constructFeatureDataStruct(tileset);
33
31
  tile.content.attributes = {};
34
32
  if (tile.textureUrl) {
35
33
  const url = (0, url_utils_1.getUrlWithToken)(tile.textureUrl, options?.i3s?.token);
36
- const loader = getLoaderForTextureFormat(tile.textureFormat) || images_1.ImageLoader;
37
- // @ts-ignore context must be defined
34
+ const loader = getLoaderForTextureFormat(tile.textureFormat);
38
35
  const response = await fetch(url);
39
36
  const arrayBuffer = await response.arrayBuffer();
40
37
  if (options?.i3s.decodeTextures) {
@@ -71,11 +68,11 @@ async function parseI3STileContent(arrayBuffer, tile, tileset, options, context)
71
68
  if (tile.content.material) {
72
69
  tile.content.texture = null;
73
70
  }
74
- return await parseI3SNodeGeometry(arrayBuffer, tile, options);
71
+ return await parseI3SNodeGeometry(arrayBuffer, tile, tileset, options);
75
72
  }
76
73
  exports.parseI3STileContent = parseI3STileContent;
77
74
  /* eslint-disable max-statements */
78
- async function parseI3SNodeGeometry(arrayBuffer, tile, options) {
75
+ async function parseI3SNodeGeometry(arrayBuffer, tile, tileset, options) {
79
76
  if (!tile.content) {
80
77
  return tile;
81
78
  }
@@ -84,14 +81,16 @@ async function parseI3SNodeGeometry(arrayBuffer, tile, options) {
84
81
  let vertexCount;
85
82
  let byteOffset = 0;
86
83
  let featureCount = 0;
84
+ let indices;
87
85
  if (tile.isDracoGeometry) {
88
86
  const decompressedGeometry = await (0, core_1.parse)(arrayBuffer, draco_1.DracoLoader, {
89
87
  draco: {
90
88
  attributeNameEntry: I3S_ATTRIBUTE_TYPE
91
89
  }
92
90
  });
91
+ // @ts-expect-error
93
92
  vertexCount = decompressedGeometry.header.vertexCount;
94
- const indices = decompressedGeometry.indices.value;
93
+ indices = decompressedGeometry.indices?.value;
95
94
  const { POSITION, NORMAL, COLOR_0, TEXCOORD_0, ['feature-index']: featureIndex, ['uv-region']: uvRegion } = decompressedGeometry.attributes;
96
95
  attributes = {
97
96
  position: POSITION,
@@ -99,8 +98,7 @@ async function parseI3SNodeGeometry(arrayBuffer, tile, options) {
99
98
  color: COLOR_0,
100
99
  uv0: TEXCOORD_0,
101
100
  uvRegion,
102
- id: featureIndex,
103
- indices
101
+ id: featureIndex
104
102
  };
105
103
  updateAttributesMetadata(attributes, decompressedGeometry);
106
104
  const featureIds = getFeatureIdsFromFeatureIndexMetadata(featureIndex);
@@ -109,16 +107,14 @@ async function parseI3SNodeGeometry(arrayBuffer, tile, options) {
109
107
  }
110
108
  }
111
109
  else {
112
- const { vertexAttributes, attributesOrder, featureAttributes, featureAttributeOrder } = content.featureData;
110
+ const { vertexAttributes, ordering: attributesOrder, featureAttributes, featureAttributeOrder } = tileset.store.defaultGeometrySchema;
113
111
  // First 8 bytes reserved for header (vertexCount and featureCount)
114
- const headers = parseHeaders(content, arrayBuffer);
112
+ const headers = parseHeaders(tileset, arrayBuffer);
115
113
  byteOffset = headers.byteOffset;
116
114
  vertexCount = headers.vertexCount;
117
115
  featureCount = headers.featureCount;
118
116
  // Getting vertex attributes such as positions, normals, colors, etc...
119
- const { attributes: normalizedVertexAttributes, byteOffset: offset } = normalizeAttributes(arrayBuffer, byteOffset, vertexAttributes, vertexCount,
120
- // @ts-expect-error
121
- attributesOrder);
117
+ const { attributes: normalizedVertexAttributes, byteOffset: offset } = normalizeAttributes(arrayBuffer, byteOffset, vertexAttributes, vertexCount, attributesOrder);
122
118
  // Getting feature attributes such as featureIds and faceRange
123
119
  const { attributes: normalizedFeatureAttributes } = normalizeAttributes(arrayBuffer, offset, featureAttributes, featureCount, featureAttributeOrder);
124
120
  flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes);
@@ -141,7 +137,7 @@ async function parseI3SNodeGeometry(arrayBuffer, tile, options) {
141
137
  texCoords: attributes.uv0,
142
138
  uvRegions: normalizeAttribute(attributes.uvRegion) // Normalize from UInt16
143
139
  };
144
- content.indices = attributes.indices || null;
140
+ content.indices = indices || null;
145
141
  if (attributes.id && attributes.id.value) {
146
142
  tile.content.featureIds = attributes.id.value;
147
143
  }
@@ -197,46 +193,26 @@ function normalizeAttribute(attribute) {
197
193
  attribute.normalized = true;
198
194
  return attribute;
199
195
  }
200
- function constructFeatureDataStruct(tileset) {
201
- // seed featureData from defaultGeometrySchema
202
- const defaultGeometrySchema = tileset.store.defaultGeometrySchema;
203
- const featureData = defaultGeometrySchema;
204
- // populate the vertex attributes value types and values per element
205
- for (const geometryAttribute in constants_1.I3S_NAMED_GEOMETRY_ATTRIBUTES) {
206
- for (const namedAttribute in constants_1.I3S_NAMED_VERTEX_ATTRIBUTES) {
207
- const attribute = defaultGeometrySchema[geometryAttribute][namedAttribute];
208
- if (attribute) {
209
- const { byteOffset = 0, count = 0, valueType, valuesPerElement } = attribute;
210
- featureData[geometryAttribute][namedAttribute] = {
211
- valueType,
212
- valuesPerElement,
213
- byteOffset,
214
- count
215
- };
216
- }
217
- }
218
- }
219
- featureData.attributesOrder = defaultGeometrySchema.ordering;
220
- return featureData;
221
- }
222
- function parseHeaders(content, arrayBuffer) {
196
+ function parseHeaders(tileset, arrayBuffer) {
223
197
  let byteOffset = 0;
224
198
  // First 8 bytes reserved for header (vertexCount and featurecount)
225
199
  let vertexCount = 0;
226
200
  let featureCount = 0;
227
- content.featureData.header.forEach(({ property, type }) => {
201
+ for (const { property, type } of tileset.store.defaultGeometrySchema.header) {
228
202
  const TypedArrayTypeHeader = (0, constants_1.getConstructorForDataFormat)(type);
229
- if (property === constants_1.I3S_NAMED_HEADER_ATTRIBUTES.vertexCount) {
230
- // @ts-expect-error
231
- vertexCount = new TypedArrayTypeHeader(arrayBuffer, 0, 4)[0];
232
- byteOffset += (0, constants_1.sizeOf)(type);
233
- }
234
- if (property === constants_1.I3S_NAMED_HEADER_ATTRIBUTES.featureCount) {
235
- // @ts-expect-error
236
- featureCount = new TypedArrayTypeHeader(arrayBuffer, 4, 4)[0];
237
- byteOffset += (0, constants_1.sizeOf)(type);
203
+ switch (property) {
204
+ case types_1.HeaderAttributeProperty.vertexCount:
205
+ vertexCount = new TypedArrayTypeHeader(arrayBuffer, 0, 4)[0];
206
+ byteOffset += (0, constants_1.sizeOf)(type);
207
+ break;
208
+ case types_1.HeaderAttributeProperty.featureCount:
209
+ featureCount = new TypedArrayTypeHeader(arrayBuffer, 4, 4)[0];
210
+ byteOffset += (0, constants_1.sizeOf)(type);
211
+ break;
212
+ default:
213
+ break;
238
214
  }
239
- });
215
+ }
240
216
  return {
241
217
  vertexCount,
242
218
  featureCount,
@@ -262,13 +238,12 @@ function normalizeAttributes(arrayBuffer, byteOffset, vertexAttributes, vertexCo
262
238
  break;
263
239
  }
264
240
  const buffer = arrayBuffer.slice(byteOffset);
265
- let value = [];
241
+ let value;
266
242
  if (valueType === 'UInt64') {
267
243
  value = parseUint64Values(buffer, count * valuesPerElement, (0, constants_1.sizeOf)(valueType));
268
244
  }
269
245
  else {
270
246
  const TypedArrayType = (0, constants_1.getConstructorForDataFormat)(valueType);
271
- // @ts-expect-error
272
247
  value = new TypedArrayType(buffer, 0, count * valuesPerElement);
273
248
  }
274
249
  attributes[attribute] = {
@@ -310,7 +285,7 @@ function parseUint64Values(buffer, elementsCount, attributeSize) {
310
285
  values.push(value);
311
286
  offset += attributeSize;
312
287
  }
313
- return values;
288
+ return new Uint32Array(values);
314
289
  }
315
290
  function parsePositions(attribute, tile) {
316
291
  const mbs = tile.mbs;
@@ -405,7 +380,9 @@ function makePbrMaterial(materialDefinition, texture) {
405
380
  if (pbrMaterial.pbrMetallicRoughness && pbrMaterial.pbrMetallicRoughness.baseColorFactor) {
406
381
  pbrMaterial.pbrMetallicRoughness.baseColorFactor = convertColorFormat(pbrMaterial.pbrMetallicRoughness.baseColorFactor);
407
382
  }
408
- setMaterialTexture(pbrMaterial, texture);
383
+ if (texture) {
384
+ setMaterialTexture(pbrMaterial, texture);
385
+ }
409
386
  return pbrMaterial;
410
387
  }
411
388
  /**
@@ -501,8 +478,5 @@ function flattenFeatureIdsByFeatureIndices(attributes, featureIds) {
501
478
  * @returns
502
479
  */
503
480
  function getFeatureIdsFromFeatureIndexMetadata(featureIndex) {
504
- return (featureIndex &&
505
- featureIndex.metadata &&
506
- featureIndex.metadata['i3s-feature-ids'] &&
507
- featureIndex.metadata['i3s-feature-ids'].intArray);
481
+ return featureIndex?.metadata?.['i3s-feature-ids']?.intArray;
508
482
  }
@@ -1,4 +1,6 @@
1
- export declare function normalizeTileData(tile: any, options: any, context: any): any;
2
- export declare function normalizeTileNonUrlData(tile: any): any;
3
- export declare function normalizeTilesetData(tileset: any, options: any, context: any): Promise<void>;
1
+ import { I3STilesetHeader, I3STileHeader, I3SMinimalNodeData, Node3DIndexDocument } from '../../types';
2
+ import type { LoaderOptions, LoaderContext } from '@loaders.gl/loader-utils';
3
+ export declare function normalizeTileData(tile: Node3DIndexDocument, options: LoaderOptions, context: LoaderContext): I3STileHeader;
4
+ export declare function normalizeTileNonUrlData(tile: I3SMinimalNodeData): I3STileHeader;
5
+ export declare function normalizeTilesetData(tileset: I3STilesetHeader, options: LoaderOptions, context: LoaderContext): Promise<void>;
4
6
  //# sourceMappingURL=parse-i3s.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-i3s.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-i3s.ts"],"names":[],"mappings":"AAOA,wBAAgB,iBAAiB,CAAC,IAAI,KAAA,EAAE,OAAO,KAAA,EAAE,OAAO,KAAA,OAoBvD;AAED,wBAAgB,uBAAuB,CAAC,IAAI,KAAA,OAqC3C;AAED,wBAAsB,oBAAoB,CAAC,OAAO,KAAA,EAAE,OAAO,KAAA,EAAE,OAAO,KAAA,iBAqBnE"}
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,EACpB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAC,aAAa,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAE3E,wBAAgB,iBAAiB,CAAC,IAAI,EAAG,mBAAmB,EAAE,OAAO,EAAG,aAAa,EAAE,OAAO,EAAE,aAAa,GAAG,aAAa,CAyB5H;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAG,kBAAkB,GAAG,aAAa,CAmChF;AAED,wBAAsB,oBAAoB,CAAC,OAAO,EAAG,gBAAgB,EAAE,OAAO,EAAG,aAAa,EAAE,OAAO,EAAE,aAAa,iBAqBrH"}
@@ -11,54 +11,59 @@ const tiles_1 = require("@loaders.gl/tiles");
11
11
  const i3s_nodepages_tiles_1 = __importDefault(require("../helpers/i3s-nodepages-tiles"));
12
12
  const url_utils_1 = require("../utils/url-utils");
13
13
  function normalizeTileData(tile, options, context) {
14
- tile.url = context.url;
15
- if (tile.featureData) {
16
- tile.featureUrl = `${tile.url}/${tile.featureData[0].href}`;
17
- }
14
+ const url = context.url || '';
15
+ let contentUrl;
18
16
  if (tile.geometryData) {
19
- tile.contentUrl = `${tile.url}/${tile.geometryData[0].href}`;
17
+ contentUrl = `${url}/${tile.geometryData[0].href}`;
20
18
  }
19
+ let textureUrl;
21
20
  if (tile.textureData) {
22
- tile.textureUrl = `${tile.url}/${tile.textureData[0].href}`;
21
+ textureUrl = `${url}/${tile.textureData[0].href}`;
23
22
  }
23
+ let attributeUrls;
24
24
  if (tile.attributeData) {
25
- tile.attributeUrls = (0, url_utils_1.generateTileAttributeUrls)(tile);
25
+ attributeUrls = (0, url_utils_1.generateTileAttributeUrls)(url, tile);
26
26
  }
27
- return normalizeTileNonUrlData(tile);
27
+ return normalizeTileNonUrlData({
28
+ ...tile,
29
+ url,
30
+ contentUrl,
31
+ textureUrl,
32
+ attributeUrls,
33
+ isDracoGeometry: false
34
+ });
28
35
  }
29
36
  exports.normalizeTileData = normalizeTileData;
30
37
  function normalizeTileNonUrlData(tile) {
31
- const box = tile.obb
32
- ? [
33
- ...geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(tile.obb.center),
34
- ...tile.obb.halfSize,
35
- ...tile.obb.quaternion // quaternion
36
- ]
37
- : undefined;
38
- let sphere;
38
+ const boundingVolume = {};
39
+ let mbs = [0, 0, 0, 1];
39
40
  if (tile.mbs) {
40
- sphere = [
41
+ mbs = tile.mbs;
42
+ boundingVolume.sphere = [
41
43
  ...geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(tile.mbs.slice(0, 3)),
42
44
  tile.mbs[3] // radius of sphere
43
45
  ];
44
46
  }
45
- else if (box) {
46
- const obb = new culling_1.OrientedBoundingBox().fromCenterHalfSizeQuaternion(box.slice(0, 3), tile.obb.halfSize, tile.obb.quaternion);
47
+ else if (tile.obb) {
48
+ boundingVolume.box = [
49
+ ...geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(tile.obb.center),
50
+ ...tile.obb.halfSize,
51
+ ...tile.obb.quaternion // quaternion
52
+ ];
53
+ const obb = new culling_1.OrientedBoundingBox().fromCenterHalfSizeQuaternion(boundingVolume.box.slice(0, 3), tile.obb.halfSize, tile.obb.quaternion);
47
54
  const boundingSphere = obb.getBoundingSphere();
48
- sphere = [...boundingSphere.center, boundingSphere.radius];
49
- tile.mbs = [...tile.obb.center, boundingSphere.radius];
55
+ boundingVolume.sphere = [...boundingSphere.center, boundingSphere.radius];
56
+ mbs = [...tile.obb.center, boundingSphere.radius];
50
57
  }
51
- tile.boundingVolume = {
52
- sphere,
53
- box
54
- };
55
- tile.lodMetricType = tile.lodSelection[0].metricType;
56
- tile.lodMetricValue = tile.lodSelection[0].maxError;
57
- tile.transformMatrix = tile.transform;
58
- tile.type = tiles_1.TILE_TYPE.MESH;
59
- // TODO only support replacement for now
60
- tile.refine = tiles_1.TILE_REFINEMENT.REPLACE;
61
- return tile;
58
+ const lodMetricType = tile.lodSelection?.[0].metricType;
59
+ const lodMetricValue = tile.lodSelection?.[0].maxError;
60
+ const transformMatrix = tile.transform;
61
+ const type = tiles_1.TILE_TYPE.MESH;
62
+ /**
63
+ * I3S specification supports only REPLACE
64
+ */
65
+ const refine = tiles_1.TILE_REFINEMENT.REPLACE;
66
+ return { ...tile, mbs, boundingVolume, lodMetricType, lodMetricValue, transformMatrix, type, refine };
62
67
  }
63
68
  exports.normalizeTileNonUrlData = normalizeTileNonUrlData;
64
69
  async function normalizeTilesetData(tileset, options, context) {
@@ -1,17 +1,17 @@
1
- import { Tile } from '../../types';
1
+ import { Node3DIndexDocument } from '../../types';
2
2
  /**
3
3
  * Generates url with token if it is exists.
4
- * @param {String} url
5
- * @param {any} token
6
- * @returns {string}
4
+ * @param url
5
+ * @param token
6
+ * @returns
7
7
  */
8
- export declare function getUrlWithToken(url: string, token?: null): string;
8
+ export declare function getUrlWithToken(url: string, token?: string | null): string;
9
9
  /**
10
10
  * Generates attribute urls for tile.
11
11
  * @param tile
12
12
  * @returns list of attribute urls
13
13
  */
14
- export declare function generateTileAttributeUrls(tile: Tile): string[];
14
+ export declare function generateTileAttributeUrls(url: string, tile: Node3DIndexDocument): string[];
15
15
  /**
16
16
  * Generates attribute urls for tileset based on tileset and resource
17
17
  * @param {Object} tileset
@@ -1 +1 @@
1
- {"version":3,"file":"url-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/url-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,aAAa,CAAC;AAEjC;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,OAAO,GAAG,MAAM,CAEjE;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,EAAE,CAU9D;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,KAAA,EAAE,QAAQ,KAAA,YAU7D"}
1
+ {"version":3,"file":"url-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/url-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,aAAa,CAAC;AAEhD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,GAAE,MAAM,GAAG,IAAW,GAAG,MAAM,CAEhF;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,GAAG,MAAM,EAAE,CAU1F;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,KAAA,EAAE,QAAQ,KAAA,YAU7D"}
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateTilesetAttributeUrls = exports.generateTileAttributeUrls = exports.getUrlWithToken = void 0;
4
4
  /**
5
5
  * Generates url with token if it is exists.
6
- * @param {String} url
7
- * @param {any} token
8
- * @returns {string}
6
+ * @param url
7
+ * @param token
8
+ * @returns
9
9
  */
10
10
  function getUrlWithToken(url, token = null) {
11
11
  return token ? `${url}?token=${token}` : url;
@@ -16,8 +16,8 @@ exports.getUrlWithToken = getUrlWithToken;
16
16
  * @param tile
17
17
  * @returns list of attribute urls
18
18
  */
19
- function generateTileAttributeUrls(tile) {
20
- const { url, attributeData } = tile;
19
+ function generateTileAttributeUrls(url, tile) {
20
+ const { attributeData = [] } = tile;
21
21
  const attributeUrls = [];
22
22
  for (let index = 0; index < attributeData.length; index++) {
23
23
  const attributeUrl = attributeData[index].href.replace('./', '');