@loaders.gl/tile-converter 3.4.0-alpha.3 → 3.4.0-alpha.4

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/3d-tiles-attributes-worker.js +1 -1
  2. package/dist/converter.min.js +90 -2875
  3. package/dist/dist.min.js +595 -18844
  4. package/dist/es5/3d-tiles-attributes-worker.js +1 -1
  5. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  6. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  7. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
  8. package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -1
  9. package/dist/es5/converter-cli.js.map +1 -1
  10. package/dist/es5/deps-installer/deps-installer.js +1 -1
  11. package/dist/es5/deps-installer/deps-installer.js.map +1 -1
  12. package/dist/es5/i3s-attributes-worker.js +1 -1
  13. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  14. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  15. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
  16. package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -1
  17. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  18. package/dist/es5/i3s-converter/helpers/geometry-converter.js +30 -8
  19. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  20. package/dist/es5/i3s-converter/helpers/node-debug.js +2 -4
  21. package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -1
  22. package/dist/es5/i3s-converter/helpers/node-index-document.js.map +1 -1
  23. package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
  24. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  25. package/dist/es5/i3s-converter/json-templates/geometry-definitions.js.map +1 -1
  26. package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -1
  27. package/dist/es5/i3s-converter/json-templates/node.js.map +1 -1
  28. package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -1
  29. package/dist/es5/i3s-converter/json-templates/store.js.map +1 -1
  30. package/dist/es5/i3s-converter/types.js.map +1 -1
  31. package/dist/es5/i3s-server/app.js.map +1 -1
  32. package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -1
  33. package/dist/es5/i3s-server/routes/index.js.map +1 -1
  34. package/dist/es5/lib/utils/compress-util.js.map +1 -1
  35. package/dist/es5/lib/utils/file-utils.js.map +1 -1
  36. package/dist/es5/lib/utils/queue.js.map +1 -1
  37. package/dist/es5/lib/utils/statistic-utills.js.map +1 -1
  38. package/dist/es5/lib/utils/write-queue.js.map +1 -1
  39. package/dist/es5/pgm-loader.js +1 -1
  40. package/dist/es5/workers/3d-tiles-attributes-worker.js.map +1 -1
  41. package/dist/es5/workers/i3s-attributes-worker.js.map +1 -1
  42. package/dist/esm/3d-tiles-attributes-worker.js +1 -1
  43. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  44. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  45. package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
  46. package/dist/esm/3d-tiles-converter/json-templates/tileset.js.map +1 -1
  47. package/dist/esm/converter-cli.js.map +1 -1
  48. package/dist/esm/deps-installer/deps-installer.js +1 -1
  49. package/dist/esm/deps-installer/deps-installer.js.map +1 -1
  50. package/dist/esm/i3s-attributes-worker.js +1 -1
  51. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  52. package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  53. package/dist/esm/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
  54. package/dist/esm/i3s-converter/helpers/feature-attributes.js.map +1 -1
  55. package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  56. package/dist/esm/i3s-converter/helpers/geometry-converter.js +30 -8
  57. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  58. package/dist/esm/i3s-converter/helpers/node-debug.js +2 -4
  59. package/dist/esm/i3s-converter/helpers/node-debug.js.map +1 -1
  60. package/dist/esm/i3s-converter/helpers/node-index-document.js.map +1 -1
  61. package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
  62. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  63. package/dist/esm/i3s-converter/json-templates/geometry-definitions.js.map +1 -1
  64. package/dist/esm/i3s-converter/json-templates/layers.js.map +1 -1
  65. package/dist/esm/i3s-converter/json-templates/node.js.map +1 -1
  66. package/dist/esm/i3s-converter/json-templates/shared-resources.js.map +1 -1
  67. package/dist/esm/i3s-converter/json-templates/store.js.map +1 -1
  68. package/dist/esm/i3s-converter/types.js.map +1 -1
  69. package/dist/esm/i3s-server/app.js.map +1 -1
  70. package/dist/esm/i3s-server/controllers/index-controller.js.map +1 -1
  71. package/dist/esm/i3s-server/routes/index.js.map +1 -1
  72. package/dist/esm/lib/utils/compress-util.js.map +1 -1
  73. package/dist/esm/lib/utils/file-utils.js.map +1 -1
  74. package/dist/esm/lib/utils/queue.js.map +1 -1
  75. package/dist/esm/lib/utils/statistic-utills.js.map +1 -1
  76. package/dist/esm/lib/utils/write-queue.js.map +1 -1
  77. package/dist/esm/pgm-loader.js +1 -1
  78. package/dist/esm/workers/3d-tiles-attributes-worker.js.map +1 -1
  79. package/dist/esm/workers/i3s-attributes-worker.js.map +1 -1
  80. package/dist/i3s-attributes-worker.js +2 -2
  81. package/dist/i3s-attributes-worker.js.map +3 -3
  82. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  83. package/dist/i3s-converter/helpers/geometry-converter.js +44 -6
  84. package/dist/i3s-converter/helpers/node-debug.d.ts.map +1 -1
  85. package/dist/i3s-converter/helpers/node-debug.js +10 -4
  86. package/dist/i3s-converter/types.d.ts +1 -0
  87. package/dist/i3s-converter/types.d.ts.map +1 -1
  88. package/package.json +15 -16
  89. package/src/i3s-converter/helpers/geometry-converter.ts +59 -14
  90. package/src/i3s-converter/helpers/node-debug.ts +11 -5
  91. package/src/i3s-converter/types.ts +10 -0
@@ -1 +1 @@
1
- {"version":3,"file":"geometry-converter.d.ts","sourceRoot":"","sources":["../../../src/i3s-converter/helpers/geometry-converter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAE,gBAAgB,EAAC,MAAM,sBAAsB,CAAC;AAsBxE,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EAGvB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,oBAAoB,EAIrB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAC,KAAK,EAAC,MAAM,gBAAgB,CAAC;AACrC,+DAA+D;AAC/D,OAAO,EAAC,kBAAkB,EAAsC,MAAM,6BAA6B,CAAC;AA6BpG;;;;;;;;;;;;;;GAcG;AACH,wBAA8B,wBAAwB,CACpD,WAAW,EAAE,WAAW,EACxB,iBAAiB,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EACxC,aAAa,EAAE,gBAAgB,GAAG,IAAI,EACtC,iBAAiB,EAAE,MAAM,EAAE,EAC3B,oBAAoB,EAAE,oBAAoB,EAAE,GAAG,SAAS,EACxD,KAAK,EAAE,OAAO,EACd,uBAAuB,EAAE,OAAO,EAChC,oBAAoB,EAAE,OAAO,EAC7B,gBAAgB,EAAE,KAAK,EACvB,YAAY,EAAE;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAC,GACpC,OAAO,CAAC,qBAAqB,EAAE,GAAG,IAAI,CAAC,CA0DzC;AA6ID;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CACrC,cAAc,EAAE,kBAAkB,EAClC,sBAAsB,EAAE,sBAAsB,EAAE,EAChD,qBAAqB,EAAE,OAAO,GAC7B,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAgD3C;AA8lCD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,WAAW,GAAG,gBAAgB,GAAG,IAAI,CAoBlF"}
1
+ {"version":3,"file":"geometry-converter.d.ts","sourceRoot":"","sources":["../../../src/i3s-converter/helpers/geometry-converter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAE,gBAAgB,EAAC,MAAM,sBAAsB,CAAC;AAsBxE,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EAGvB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,oBAAoB,EAIrB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAC,KAAK,EAAC,MAAM,gBAAgB,CAAC;AACrC,+DAA+D;AAC/D,OAAO,EAAC,kBAAkB,EAAsC,MAAM,6BAA6B,CAAC;AAsCpG;;;;;;;;;;;;;;GAcG;AACH,wBAA8B,wBAAwB,CACpD,WAAW,EAAE,WAAW,EACxB,iBAAiB,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EACxC,aAAa,EAAE,gBAAgB,GAAG,IAAI,EACtC,iBAAiB,EAAE,MAAM,EAAE,EAC3B,oBAAoB,EAAE,oBAAoB,EAAE,GAAG,SAAS,EACxD,KAAK,EAAE,OAAO,EACd,uBAAuB,EAAE,OAAO,EAChC,oBAAoB,EAAE,OAAO,EAC7B,gBAAgB,EAAE,KAAK,EACvB,YAAY,EAAE;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAC,GACpC,OAAO,CAAC,qBAAqB,EAAE,GAAG,IAAI,CAAC,CA0DzC;AA6ID;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CACrC,cAAc,EAAE,kBAAkB,EAClC,sBAAsB,EAAE,sBAAsB,EAAE,EAChD,qBAAqB,EAAE,OAAO,GAC7B,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAgD3C;AAkoCD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,WAAW,GAAG,gBAAgB,GAAG,IAAI,CAoBlF"}
@@ -39,6 +39,7 @@ const coordinate_converter_1 = require("./coordinate-converter");
39
39
  const gltf_attributes_1 = require("./gltf-attributes");
40
40
  const batch_ids_extensions_1 = require("./batch-ids-extensions");
41
41
  const feature_attributes_1 = require("./feature-attributes");
42
+ const math_1 = require("@loaders.gl/math");
42
43
  // Spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.7/pbrMetallicRoughness.cmn.md
43
44
  const DEFAULT_ROUGHNESS_FACTOR = 1;
44
45
  const DEFAULT_METALLIC_FACTOR = 1;
@@ -334,12 +335,13 @@ function convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, att
334
335
  if (!outputAttributes) {
335
336
  continue;
336
337
  }
338
+ const indices = getIndices(primitive);
337
339
  outputAttributes.positions = (0, loader_utils_1.concatenateTypedArrays)(outputAttributes.positions, transformVertexArray({
338
340
  vertices: attributes.POSITION.value,
339
341
  cartographicOrigin,
340
342
  cartesianModelMatrix,
341
343
  nodeMatrix: matrix,
342
- indices: primitive.indices?.value,
344
+ indices,
343
345
  attributeSpecificTransformation: transformVertexPositions,
344
346
  useCartesianPositions
345
347
  }));
@@ -348,19 +350,55 @@ function convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, att
348
350
  cartographicOrigin,
349
351
  cartesianModelMatrix,
350
352
  nodeMatrix: matrix,
351
- indices: primitive.indices?.value,
353
+ indices,
352
354
  attributeSpecificTransformation: transformVertexNormals,
353
355
  useCartesianPositions: false
354
356
  }));
355
- outputAttributes.texCoords = (0, loader_utils_1.concatenateTypedArrays)(outputAttributes.texCoords, flattenTexCoords(attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value, primitive.indices?.value));
356
- outputAttributes.colors = (0, loader_utils_1.concatenateTypedArrays)(outputAttributes.colors, flattenColors(attributes.COLOR_0, primitive.indices?.value));
357
+ outputAttributes.texCoords = (0, loader_utils_1.concatenateTypedArrays)(outputAttributes.texCoords, flattenTexCoords(attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value, indices));
358
+ outputAttributes.colors = (0, loader_utils_1.concatenateTypedArrays)(outputAttributes.colors, flattenColors(attributes.COLOR_0, indices));
357
359
  if (materialUvRegion) {
358
- outputAttributes.uvRegions = (0, loader_utils_1.concatenateTypedArrays)(outputAttributes.uvRegions, createUvRegion(materialUvRegion, primitive.indices?.value));
360
+ outputAttributes.uvRegions = (0, loader_utils_1.concatenateTypedArrays)(outputAttributes.uvRegions, createUvRegion(materialUvRegion, indices));
359
361
  }
360
362
  outputAttributes.featureIndicesGroups = outputAttributes.featureIndicesGroups || [];
361
- outputAttributes.featureIndicesGroups.push(flattenBatchIds(getBatchIds(attributes, primitive, images), primitive.indices?.value));
363
+ outputAttributes.featureIndicesGroups.push(flattenBatchIds(getBatchIds(attributes, primitive, images), indices));
362
364
  }
363
365
  }
366
+ /**
367
+ * Converts TRIANGLE-STRIPS to independent TRIANGLES
368
+ * @param {MeshPrimitive} primitive - the primitive to get the indices from
369
+ * @returns indices of vertices of the independent triangles
370
+ */
371
+ function getIndices(primitive) {
372
+ let indices = primitive.indices?.value;
373
+ if (indices && primitive.mode === math_1.GL.TRIANGLE_STRIP) {
374
+ /*
375
+ TRIANGLE_STRIP geometry contains n+2 vertices for n triangles;
376
+ TRIANGLE geometry contains n*3 vertices for n triangles.
377
+ The conversion from TRIANGLE_STRIP to TRIANGLE implies duplicating adjacent vertices.
378
+ */
379
+ const TypedArrayConstructor = indices.constructor;
380
+ const newIndices = new TypedArrayConstructor((indices.length - 2) * 3);
381
+ // Copy the first triangle indices with no modification like [i0, i1, i2, ...] -> [i0, i1, i2, ...]
382
+ let triangleIndex = 0;
383
+ let currentTriangle = indices.slice(0, 3);
384
+ newIndices.set(currentTriangle, 0);
385
+ // The rest triangle indices are being taken from strips using the following logic:
386
+ // [i1, i2, i3, i4, i5, i6, ...] -> [i3, i2, i1, i2, i3, i4, i5, i4, i3, i4, i5, i6, ...]
387
+ for (let i = 1; i + 2 < indices.length; i++) {
388
+ triangleIndex += 3;
389
+ currentTriangle = indices.slice(i, i + 3);
390
+ if (i % 2 === 0) {
391
+ newIndices.set(currentTriangle, triangleIndex);
392
+ }
393
+ else {
394
+ // The following "reverce" is necessary to calculate normals correctly
395
+ newIndices.set(currentTriangle.reverse(), triangleIndex);
396
+ }
397
+ }
398
+ indices = newIndices;
399
+ }
400
+ return indices;
401
+ }
364
402
  /**
365
403
  * Convert vertices attributes (POSITIONS or NORMALS) to i3s compatible format
366
404
  * @param args
@@ -1 +1 @@
1
- {"version":3,"file":"node-debug.d.ts","sourceRoot":"","sources":["../../../src/i3s-converter/helpers/node-debug.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAM,mBAAmB,EAAM,MAAM,iBAAiB,CAAC;AASnE;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,mBAAmB,GAAG,MAAM,EAAE,CAW/E"}
1
+ {"version":3,"file":"node-debug.d.ts","sourceRoot":"","sources":["../../../src/i3s-converter/helpers/node-debug.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAM,mBAAmB,EAAM,MAAM,iBAAiB,CAAC;AAiBnE;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,mBAAmB,GAAG,MAAM,EAAE,CAW/E"}
@@ -2,9 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateNodeBoundingVolumes = void 0;
4
4
  const culling_1 = require("@math.gl/culling");
5
- const engine_1 = require("@luma.gl/engine");
6
5
  const core_1 = require("@math.gl/core");
7
6
  const geospatial_1 = require("@math.gl/geospatial");
7
+ // prettier-ignore
8
+ const CUBE_POSITIONS = new Float32Array([
9
+ -1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1,
10
+ -1, -1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1,
11
+ -1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, -1,
12
+ -1, -1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1,
13
+ 1, -1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1,
14
+ -1, -1, -1, -1, -1, 1, -1, 1, 1, -1, 1, -1
15
+ ]);
8
16
  // TODO Unite Tile validation logic in i3s-17-and-debug with this code.
9
17
  /**
10
18
  * Do validation of bounding volumes for particular node.
@@ -75,11 +83,9 @@ function createBoundingBoxFromTileObb(obb) {
75
83
  * @param node
76
84
  */
77
85
  function getTileObbVertices(node) {
78
- const geometry = new engine_1.CubeGeometry();
79
86
  // @ts-expect-error
80
87
  const halfSize = node.obb.halfSize;
81
- const attributes = geometry.getAttributes();
82
- const positions = new Float32Array(attributes.POSITION.value);
88
+ const positions = CUBE_POSITIONS;
83
89
  // @ts-expect-error
84
90
  const obbCenterCartesian = geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(node.obb.center);
85
91
  let vertices = [];
@@ -141,4 +141,5 @@ export type MergedMaterial = {
141
141
  /** Uint16Array of 4 elements https://github.com/Esri/i3s-spec/blob/master/docs/1.7/geometryUVRegion.cmn.md */
142
142
  uvRegion?: Uint16Array;
143
143
  };
144
+ export type TypedArrayConstructor = Uint8ArrayConstructor | Int8ArrayConstructor | Uint16ArrayConstructor | Int16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor;
144
145
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/i3s-converter/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,sBAAsB,EAAC,MAAM,kBAAkB,CAAC;AACxD,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,iBAAiB,CAAC;AAEzB,4CAA4C;AAC5C,MAAM,MAAM,qBAAqB,GAAG;IAClC;;OAEG;IACH,MAAM,CAAC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AC;IACjD,gDAAgD;IAChD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,2EAA2E;AAC3E,MAAM,MAAM,sBAAsB,GAAG;IACnC,2GAA2G;IAC3G,QAAQ,EAAE,qBAAqB,CAAC;IAChC,8BAA8B;IAC9B,OAAO,CAAC,EAAE,sBAAsB,CAAC;IACjC,uCAAuC;IACvC,eAAe,EAAE,cAAc,EAAE,CAAC;CACnC,CAAC;AAEF,wCAAwC;AACxC,MAAM,MAAM,cAAc,GAAG;IAC3B,uBAAuB;IACvB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,4BAA4B;IAC5B,WAAW,CAAC,EAAE;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,8GAA8G;IAC9G,QAAQ,CAAC,EAAE,WAAW,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAC7B,qBAAqB,GACrB,oBAAoB,GACpB,sBAAsB,GACtB,qBAAqB,GACrB,qBAAqB,GACrB,sBAAsB,GACtB,uBAAuB,GACvB,uBAAuB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/tile-converter",
3
- "version": "3.4.0-alpha.3",
3
+ "version": "3.4.0-alpha.4",
4
4
  "description": "Converter",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -44,20 +44,19 @@
44
44
  "build-3d-tiles-attributes-worker": "esbuild src/workers/3d-tiles-attributes-worker.ts --outfile=dist/3d-tiles-attributes-worker.js --platform=node --target=esnext,node14 --external:join-images --minify --bundle --sourcemap --define:__VERSION__=\\\"$npm_package_version\\\""
45
45
  },
46
46
  "dependencies": {
47
- "@loaders.gl/3d-tiles": "3.4.0-alpha.3",
48
- "@loaders.gl/crypto": "3.4.0-alpha.3",
49
- "@loaders.gl/draco": "3.4.0-alpha.3",
50
- "@loaders.gl/gltf": "3.4.0-alpha.3",
51
- "@loaders.gl/i3s": "3.4.0-alpha.3",
52
- "@loaders.gl/images": "3.4.0-alpha.3",
53
- "@loaders.gl/loader-utils": "3.4.0-alpha.3",
54
- "@loaders.gl/polyfills": "3.4.0-alpha.3",
55
- "@loaders.gl/schema": "3.4.0-alpha.3",
56
- "@loaders.gl/textures": "3.4.0-alpha.3",
57
- "@loaders.gl/tiles": "3.4.0-alpha.3",
58
- "@loaders.gl/worker-utils": "3.4.0-alpha.3",
59
- "@loaders.gl/zip": "3.4.0-alpha.3",
60
- "@luma.gl/engine": "^8.5.19",
47
+ "@loaders.gl/3d-tiles": "3.4.0-alpha.4",
48
+ "@loaders.gl/crypto": "3.4.0-alpha.4",
49
+ "@loaders.gl/draco": "3.4.0-alpha.4",
50
+ "@loaders.gl/gltf": "3.4.0-alpha.4",
51
+ "@loaders.gl/i3s": "3.4.0-alpha.4",
52
+ "@loaders.gl/images": "3.4.0-alpha.4",
53
+ "@loaders.gl/loader-utils": "3.4.0-alpha.4",
54
+ "@loaders.gl/polyfills": "3.4.0-alpha.4",
55
+ "@loaders.gl/schema": "3.4.0-alpha.4",
56
+ "@loaders.gl/textures": "3.4.0-alpha.4",
57
+ "@loaders.gl/tiles": "3.4.0-alpha.4",
58
+ "@loaders.gl/worker-utils": "3.4.0-alpha.4",
59
+ "@loaders.gl/zip": "3.4.0-alpha.4",
61
60
  "@math.gl/core": "^3.5.1",
62
61
  "@math.gl/culling": "^3.5.1",
63
62
  "@math.gl/geoid": "^3.5.1",
@@ -80,5 +79,5 @@
80
79
  "join-images": "^1.1.3",
81
80
  "sharp": "^0.31.3"
82
81
  },
83
- "gitHead": "a954528dd1d78a1f128d8f6b07e4baeb7a296924"
82
+ "gitHead": "f039a523df8b908a91f26c5ba8c4cfc1924b6140"
84
83
  }
@@ -40,6 +40,15 @@ import {B3DMAttributesData /*, transformI3SAttributesOnWorker*/} from '../../i3s
40
40
  import {prepareDataForAttributesConversion} from './gltf-attributes';
41
41
  import {handleBatchIdsExtensions} from './batch-ids-extensions';
42
42
  import {checkPropertiesLength, flattenPropertyTableByFeatureIds} from './feature-attributes';
43
+ import {MeshPrimitive} from 'modules/gltf/src/lib/types/gltf-postprocessed-schema';
44
+ import {GL} from '@loaders.gl/math';
45
+
46
+ /*
47
+ At the moment of writing the type TypedArrayConstructor is not exported in '@math.gl/types'.
48
+ So the following import is replaced with the local import
49
+ import type {TypedArrayConstructor} from '@math.gl/types';
50
+ */
51
+ import type {TypedArrayConstructor} from '../types';
43
52
 
44
53
  // Spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.7/pbrMetallicRoughness.cmn.md
45
54
  const DEFAULT_ROUGHNESS_FACTOR = 1;
@@ -507,6 +516,8 @@ function convertMesh(
507
516
  if (!outputAttributes) {
508
517
  continue;
509
518
  }
519
+
520
+ const indices = getIndices(primitive);
510
521
  outputAttributes.positions = concatenateTypedArrays(
511
522
  outputAttributes.positions,
512
523
  transformVertexArray({
@@ -514,7 +525,7 @@ function convertMesh(
514
525
  cartographicOrigin,
515
526
  cartesianModelMatrix,
516
527
  nodeMatrix: matrix,
517
- indices: primitive.indices?.value,
528
+ indices,
518
529
  attributeSpecificTransformation: transformVertexPositions,
519
530
  useCartesianPositions
520
531
  })
@@ -526,37 +537,71 @@ function convertMesh(
526
537
  cartographicOrigin,
527
538
  cartesianModelMatrix,
528
539
  nodeMatrix: matrix,
529
- indices: primitive.indices?.value,
540
+ indices,
530
541
  attributeSpecificTransformation: transformVertexNormals,
531
542
  useCartesianPositions: false
532
543
  })
533
544
  );
534
545
  outputAttributes.texCoords = concatenateTypedArrays(
535
546
  outputAttributes.texCoords,
536
- flattenTexCoords(
537
- attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value,
538
- primitive.indices?.value
539
- )
547
+ flattenTexCoords(attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value, indices)
540
548
  );
541
549
 
542
550
  outputAttributes.colors = concatenateTypedArrays(
543
551
  outputAttributes.colors,
544
- flattenColors(attributes.COLOR_0, primitive.indices?.value)
552
+ flattenColors(attributes.COLOR_0, indices)
545
553
  );
546
554
 
547
555
  if (materialUvRegion) {
548
556
  outputAttributes.uvRegions = concatenateTypedArrays(
549
557
  outputAttributes.uvRegions,
550
- createUvRegion(materialUvRegion, primitive.indices?.value)
558
+ createUvRegion(materialUvRegion, indices)
551
559
  );
552
560
  }
553
561
 
554
562
  outputAttributes.featureIndicesGroups = outputAttributes.featureIndicesGroups || [];
555
563
  outputAttributes.featureIndicesGroups.push(
556
- flattenBatchIds(getBatchIds(attributes, primitive, images), primitive.indices?.value)
564
+ flattenBatchIds(getBatchIds(attributes, primitive, images), indices)
557
565
  );
558
566
  }
559
567
  }
568
+ /**
569
+ * Converts TRIANGLE-STRIPS to independent TRIANGLES
570
+ * @param {MeshPrimitive} primitive - the primitive to get the indices from
571
+ * @returns indices of vertices of the independent triangles
572
+ */
573
+ function getIndices(primitive: MeshPrimitive): TypedArray {
574
+ let indices: TypedArray = primitive.indices?.value;
575
+ if (indices && primitive.mode === GL.TRIANGLE_STRIP) {
576
+ /*
577
+ TRIANGLE_STRIP geometry contains n+2 vertices for n triangles;
578
+ TRIANGLE geometry contains n*3 vertices for n triangles.
579
+ The conversion from TRIANGLE_STRIP to TRIANGLE implies duplicating adjacent vertices.
580
+ */
581
+ const TypedArrayConstructor = indices.constructor as TypedArrayConstructor;
582
+ const newIndices = new TypedArrayConstructor((indices.length - 2) * 3);
583
+
584
+ // Copy the first triangle indices with no modification like [i0, i1, i2, ...] -> [i0, i1, i2, ...]
585
+ let triangleIndex = 0;
586
+ let currentTriangle = indices.slice(0, 3);
587
+ newIndices.set(currentTriangle, 0);
588
+
589
+ // The rest triangle indices are being taken from strips using the following logic:
590
+ // [i1, i2, i3, i4, i5, i6, ...] -> [i3, i2, i1, i2, i3, i4, i5, i4, i3, i4, i5, i6, ...]
591
+ for (let i = 1; i + 2 < indices.length; i++) {
592
+ triangleIndex += 3;
593
+ currentTriangle = indices.slice(i, i + 3);
594
+ if (i % 2 === 0) {
595
+ newIndices.set(currentTriangle, triangleIndex);
596
+ } else {
597
+ // The following "reverce" is necessary to calculate normals correctly
598
+ newIndices.set(currentTriangle.reverse(), triangleIndex);
599
+ }
600
+ }
601
+ indices = newIndices;
602
+ }
603
+ return indices;
604
+ }
560
605
 
561
606
  /**
562
607
  * Convert vertices attributes (POSITIONS or NORMALS) to i3s compatible format
@@ -575,7 +620,7 @@ function transformVertexArray(args: {
575
620
  cartographicOrigin: number[];
576
621
  cartesianModelMatrix: number[];
577
622
  nodeMatrix: Matrix4;
578
- indices: Uint8Array;
623
+ indices: TypedArray;
579
624
  attributeSpecificTransformation: Function;
580
625
  useCartesianPositions: boolean;
581
626
  }) {
@@ -654,7 +699,7 @@ function transformVertexNormals(vertexVector, calleeArgs): number[] {
654
699
  * @param indices - gltf primitive indices
655
700
  * @returns flattened texture coordinates
656
701
  */
657
- function flattenTexCoords(texCoords: Float32Array, indices: Uint8Array): Float32Array {
702
+ function flattenTexCoords(texCoords: Float32Array, indices: TypedArray): Float32Array {
658
703
  const newTexCoords = new Float32Array(indices.length * VALUES_PER_TEX_COORD);
659
704
  if (!texCoords) {
660
705
  // We need dummy UV0s because it is required in 1.6
@@ -679,7 +724,7 @@ function flattenTexCoords(texCoords: Float32Array, indices: Uint8Array): Float32
679
724
  */
680
725
  function flattenColors(
681
726
  colorsAttribute: GLTFAccessorPostprocessed,
682
- indices: Uint8Array
727
+ indices: TypedArray
683
728
  ): Uint8Array {
684
729
  const components = colorsAttribute?.components || VALUES_PER_COLOR_ELEMENT;
685
730
  const newColors = new Uint8Array(indices.length * components);
@@ -707,7 +752,7 @@ function flattenColors(
707
752
  * @param indices - geometry indices data
708
753
  * @returns - uv-region array
709
754
  */
710
- function createUvRegion(materialUvRegion: Uint16Array, indices: Uint8Array): Uint16Array {
755
+ function createUvRegion(materialUvRegion: Uint16Array, indices: TypedArray): Uint16Array {
711
756
  const result = new Uint16Array(indices.length * 4);
712
757
  for (let i = 0; i < result.length; i += 4) {
713
758
  result.set(materialUvRegion, i);
@@ -721,7 +766,7 @@ function createUvRegion(materialUvRegion: Uint16Array, indices: Uint8Array): Uin
721
766
  * @param indices - gltf primitive indices
722
767
  * @returns flattened batch ids
723
768
  */
724
- function flattenBatchIds(batchedIds: number[], indices: Uint8Array): number[] {
769
+ function flattenBatchIds(batchedIds: number[], indices: TypedArray): number[] {
725
770
  if (!batchedIds.length || !indices.length) {
726
771
  return [];
727
772
  }
@@ -1,10 +1,18 @@
1
1
  import type {Mbs, Node3DIndexDocument, Obb} from '@loaders.gl/i3s';
2
-
3
2
  import {OrientedBoundingBox, BoundingSphere} from '@math.gl/culling';
4
- import {CubeGeometry} from '@luma.gl/engine';
5
3
  import {Vector3} from '@math.gl/core';
6
4
  import {Ellipsoid} from '@math.gl/geospatial';
7
5
 
6
+ // prettier-ignore
7
+ const CUBE_POSITIONS = new Float32Array([
8
+ -1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1,
9
+ -1, -1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1,
10
+ -1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, -1,
11
+ -1, -1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1,
12
+ 1, -1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1,
13
+ -1, -1, -1, -1, -1, 1, -1, 1, 1, -1, 1, -1
14
+ ]);
15
+
8
16
  // TODO Unite Tile validation logic in i3s-17-and-debug with this code.
9
17
 
10
18
  /**
@@ -86,11 +94,9 @@ function createBoundingBoxFromTileObb(obb: Obb): OrientedBoundingBox {
86
94
  * @param node
87
95
  */
88
96
  function getTileObbVertices(node: Node3DIndexDocument): number[] {
89
- const geometry = new CubeGeometry();
90
97
  // @ts-expect-error
91
98
  const halfSize = node.obb.halfSize;
92
- const attributes = geometry.getAttributes();
93
- const positions = new Float32Array(attributes.POSITION.value);
99
+ const positions = CUBE_POSITIONS;
94
100
  // @ts-expect-error
95
101
  const obbCenterCartesian = Ellipsoid.WGS84.cartographicToCartesian(node.obb.center);
96
102
 
@@ -153,3 +153,13 @@ export type MergedMaterial = {
153
153
  /** Uint16Array of 4 elements https://github.com/Esri/i3s-spec/blob/master/docs/1.7/geometryUVRegion.cmn.md */
154
154
  uvRegion?: Uint16Array;
155
155
  };
156
+
157
+ export type TypedArrayConstructor =
158
+ | Uint8ArrayConstructor
159
+ | Int8ArrayConstructor
160
+ | Uint16ArrayConstructor
161
+ | Int16ArrayConstructor
162
+ | Int32ArrayConstructor
163
+ | Uint32ArrayConstructor
164
+ | Float32ArrayConstructor
165
+ | Float64ArrayConstructor;