@loaders.gl/tile-converter 3.1.7 → 3.2.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.
- package/dist/3d-tiles-attributes-worker.d.ts +28 -0
- package/dist/3d-tiles-attributes-worker.d.ts.map +1 -0
- package/dist/3d-tiles-attributes-worker.js +4 -0
- package/dist/3d-tiles-attributes-worker.js.map +7 -0
- package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +82 -0
- package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -0
- package/dist/3d-tiles-converter/3d-tiles-converter.js +268 -0
- package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +84 -0
- package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -0
- package/dist/3d-tiles-converter/helpers/b3dm-converter.js +278 -0
- package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +13 -0
- package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts.map +1 -0
- package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +23 -0
- package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts +9 -0
- package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts.map +1 -0
- package/dist/3d-tiles-converter/helpers/texture-atlas.js +52 -0
- package/dist/3d-tiles-converter/json-templates/tileset.d.ts +15 -0
- package/dist/3d-tiles-converter/json-templates/tileset.d.ts.map +1 -0
- package/dist/3d-tiles-converter/json-templates/tileset.js +43 -0
- package/dist/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +5 -0
- package/dist/converter.min.js +20 -20
- package/dist/deps-installer/deps-installer.d.ts +4 -0
- package/dist/deps-installer/deps-installer.d.ts.map +1 -0
- package/dist/deps-installer/deps-installer.js +21 -0
- package/dist/dist.min.js +1082 -1131
- package/dist/es5/3d-tiles-attributes-worker.js +29 -0
- package/dist/es5/3d-tiles-attributes-worker.js.map +1 -0
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +104 -44
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +34 -43
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
- package/dist/es5/i3s-attributes-worker.js +29 -0
- package/dist/es5/i3s-attributes-worker.js.map +1 -0
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js +19 -11
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js +2 -2
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-converter.js +267 -178
- package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/gltf-attributes.js +71 -0
- package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -0
- package/dist/es5/i3s-converter/helpers/node-pages.js +43 -52
- package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/es5/i3s-converter/i3s-converter.js +264 -219
- package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/es5/index.js +8 -0
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/utils/compress-util.js +14 -17
- package/dist/es5/lib/utils/compress-util.js.map +1 -1
- package/dist/es5/lib/utils/file-utils.js +39 -14
- package/dist/es5/lib/utils/file-utils.js.map +1 -1
- package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
- package/dist/es5/lib/utils/queue.js +61 -0
- package/dist/es5/lib/utils/queue.js.map +1 -0
- package/dist/es5/lib/utils/statistic-utills.js.map +1 -1
- package/dist/es5/lib/utils/write-queue.js +225 -0
- package/dist/es5/lib/utils/write-queue.js.map +1 -0
- package/dist/es5/pgm-loader.js +1 -1
- package/dist/es5/pgm-loader.js.map +1 -1
- package/dist/es5/workers/3d-tiles-attributes-worker.js +37 -0
- package/dist/es5/workers/3d-tiles-attributes-worker.js.map +1 -0
- package/dist/es5/workers/i3s-attributes-worker.js +40 -0
- package/dist/es5/workers/i3s-attributes-worker.js.map +1 -0
- package/dist/esm/3d-tiles-attributes-worker.js +16 -0
- package/dist/esm/3d-tiles-attributes-worker.js.map +1 -0
- package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +32 -5
- package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +23 -23
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
- package/dist/esm/i3s-attributes-worker.js +16 -0
- package/dist/esm/i3s-attributes-worker.js.map +1 -0
- package/dist/esm/i3s-converter/helpers/coordinate-converter.js +19 -11
- package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-attributes.js +2 -2
- package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-converter.js +117 -58
- package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/gltf-attributes.js +54 -0
- package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -0
- package/dist/esm/i3s-converter/helpers/node-pages.js +12 -9
- package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/esm/i3s-converter/i3s-converter.js +115 -28
- package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/utils/compress-util.js +6 -8
- package/dist/esm/lib/utils/compress-util.js.map +1 -1
- package/dist/esm/lib/utils/file-utils.js +11 -1
- package/dist/esm/lib/utils/file-utils.js.map +1 -1
- package/dist/esm/lib/utils/lod-conversion-utils.js.map +1 -1
- package/dist/esm/lib/utils/queue.js +19 -0
- package/dist/esm/lib/utils/queue.js.map +1 -0
- package/dist/esm/lib/utils/statistic-utills.js.map +1 -1
- package/dist/esm/lib/utils/write-queue.js +88 -0
- package/dist/esm/lib/utils/write-queue.js.map +1 -0
- package/dist/esm/pgm-loader.js +1 -1
- package/dist/esm/pgm-loader.js.map +1 -1
- package/dist/esm/workers/3d-tiles-attributes-worker.js +5 -0
- package/dist/esm/workers/3d-tiles-attributes-worker.js.map +1 -0
- package/dist/esm/workers/i3s-attributes-worker.js +4 -0
- package/dist/esm/workers/i3s-attributes-worker.js.map +1 -0
- package/dist/i3s-attributes-worker.d.ts +33 -0
- package/dist/i3s-attributes-worker.d.ts.map +1 -0
- package/dist/i3s-attributes-worker.js +10 -0
- package/dist/i3s-attributes-worker.js.map +7 -0
- package/dist/i3s-converter/helpers/coordinate-converter.d.ts +41 -0
- package/dist/i3s-converter/helpers/coordinate-converter.d.ts.map +1 -0
- package/dist/i3s-converter/helpers/coordinate-converter.js +122 -0
- package/dist/i3s-converter/helpers/create-scene-server-path.d.ts +9 -0
- package/dist/i3s-converter/helpers/create-scene-server-path.d.ts.map +1 -0
- package/dist/i3s-converter/helpers/create-scene-server-path.js +28 -0
- package/dist/i3s-converter/helpers/geometry-attributes.d.ts +8 -0
- package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -0
- package/dist/i3s-converter/helpers/geometry-attributes.js +177 -0
- package/dist/i3s-converter/helpers/geometry-converter.d.ts +29 -0
- package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -0
- package/dist/i3s-converter/helpers/geometry-converter.js +901 -0
- package/dist/i3s-converter/helpers/gltf-attributes.d.ts +9 -0
- package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -0
- package/dist/i3s-converter/helpers/gltf-attributes.js +56 -0
- package/dist/i3s-converter/helpers/node-debug.d.ts +8 -0
- package/dist/i3s-converter/helpers/node-debug.d.ts.map +1 -0
- package/dist/i3s-converter/helpers/node-debug.js +114 -0
- package/dist/i3s-converter/helpers/node-pages.d.ts +117 -0
- package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -0
- package/dist/i3s-converter/helpers/node-pages.js +208 -0
- package/dist/i3s-converter/i3s-converter.d.ts +325 -0
- package/dist/i3s-converter/i3s-converter.d.ts.map +1 -0
- package/dist/i3s-converter/i3s-converter.js +1056 -0
- package/dist/i3s-converter/json-templates/layers.d.ts +95 -0
- package/dist/i3s-converter/json-templates/layers.d.ts.map +1 -0
- package/dist/i3s-converter/json-templates/layers.js +199 -0
- package/dist/i3s-converter/json-templates/metadata.d.ts +22 -0
- package/dist/i3s-converter/json-templates/metadata.d.ts.map +1 -0
- package/dist/i3s-converter/json-templates/metadata.js +25 -0
- package/dist/i3s-converter/json-templates/node.d.ts +61 -0
- package/dist/i3s-converter/json-templates/node.d.ts.map +1 -0
- package/dist/i3s-converter/json-templates/node.js +89 -0
- package/dist/i3s-converter/json-templates/scene-server.d.ts +28 -0
- package/dist/i3s-converter/json-templates/scene-server.d.ts.map +1 -0
- package/dist/i3s-converter/json-templates/scene-server.js +31 -0
- package/dist/i3s-converter/json-templates/shared-resources.d.ts +14 -0
- package/dist/i3s-converter/json-templates/shared-resources.d.ts.map +1 -0
- package/dist/i3s-converter/json-templates/shared-resources.js +129 -0
- package/dist/i3s-converter/json-templates/store.d.ts +95 -0
- package/dist/i3s-converter/json-templates/store.d.ts.map +1 -0
- package/dist/i3s-converter/json-templates/store.js +103 -0
- package/dist/i3s-converter/types.d.ts +114 -0
- package/dist/i3s-converter/types.d.ts.map +1 -0
- package/dist/i3s-converter/types.js +2 -0
- package/dist/i3s-server/app.d.ts +3 -0
- package/dist/i3s-server/app.d.ts.map +1 -0
- package/dist/i3s-server/app.js +14 -0
- package/dist/i3s-server/controllers/index-controller.d.ts +2 -0
- package/dist/i3s-server/controllers/index-controller.d.ts.map +1 -0
- package/dist/i3s-server/controllers/index-controller.js +23 -0
- package/dist/i3s-server/routes/index.d.ts +3 -0
- package/dist/i3s-server/routes/index.d.ts.map +1 -0
- package/dist/i3s-server/routes/index.js +16 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/lib/utils/compress-util.d.ts +45 -0
- package/dist/lib/utils/compress-util.d.ts.map +1 -0
- package/dist/lib/utils/compress-util.js +257 -0
- package/{src → dist}/lib/utils/file-utils.d.ts +6 -14
- package/dist/lib/utils/file-utils.d.ts.map +1 -0
- package/dist/lib/utils/file-utils.js +81 -0
- package/dist/lib/utils/lod-conversion-utils.d.ts +41 -0
- package/dist/lib/utils/lod-conversion-utils.d.ts.map +1 -0
- package/dist/lib/utils/lod-conversion-utils.js +76 -0
- package/dist/lib/utils/queue.d.ts +7 -0
- package/dist/lib/utils/queue.d.ts.map +1 -0
- package/dist/lib/utils/queue.js +18 -0
- package/dist/lib/utils/statistic-utills.d.ts +3 -0
- package/dist/lib/utils/statistic-utills.d.ts.map +1 -0
- package/dist/lib/utils/statistic-utills.js +64 -0
- package/dist/lib/utils/write-queue.d.ts +22 -0
- package/dist/lib/utils/write-queue.d.ts.map +1 -0
- package/dist/lib/utils/write-queue.js +62 -0
- package/dist/pgm-loader.d.ts +6 -0
- package/dist/pgm-loader.d.ts.map +1 -0
- package/dist/pgm-loader.js +23 -0
- package/dist/workers/3d-tiles-attributes-worker.d.ts +2 -0
- package/dist/workers/3d-tiles-attributes-worker.d.ts.map +1 -0
- package/dist/workers/3d-tiles-attributes-worker.js +9 -0
- package/dist/workers/i3s-attributes-worker.d.ts +2 -0
- package/dist/workers/i3s-attributes-worker.d.ts.map +1 -0
- package/dist/workers/i3s-attributes-worker.js +5 -0
- package/package.json +20 -18
- package/src/3d-tiles-attributes-worker.ts +43 -0
- package/src/3d-tiles-converter/3d-tiles-converter.ts +48 -5
- package/src/3d-tiles-converter/helpers/b3dm-converter.ts +21 -18
- package/src/i3s-attributes-worker.ts +46 -0
- package/src/i3s-converter/helpers/coordinate-converter.ts +29 -24
- package/src/i3s-converter/helpers/geometry-attributes.ts +4 -3
- package/src/i3s-converter/helpers/{geometry-converter.js → geometry-converter.ts} +421 -175
- package/src/i3s-converter/helpers/gltf-attributes.ts +68 -0
- package/src/i3s-converter/helpers/node-pages.ts +25 -17
- package/src/i3s-converter/i3s-converter.ts +124 -69
- package/src/i3s-converter/types.ts +90 -8
- package/src/index.ts +1 -0
- package/src/lib/utils/{compress-util.js → compress-util.ts} +105 -18
- package/src/lib/utils/file-utils.ts +84 -0
- package/src/lib/utils/{lod-conversion-utils.js → lod-conversion-utils.ts} +27 -5
- package/src/lib/utils/queue.ts +17 -0
- package/src/lib/utils/{statistic-utills.js → statistic-utills.ts} +0 -0
- package/src/lib/utils/write-queue.ts +75 -0
- package/src/workers/3d-tiles-attributes-worker.ts +6 -0
- package/src/workers/i3s-attributes-worker.ts +6 -0
- package/dist/es5/i3s-converter/helpers/geometry-converter.d.ts +0 -44
- package/dist/es5/lib/utils/compress-util.d.ts +0 -53
- package/dist/es5/lib/utils/file-utils.d.ts +0 -43
- package/dist/es5/lib/utils/lod-conversion-utils.d.ts +0 -32
- package/dist/esm/i3s-converter/helpers/geometry-converter.d.ts +0 -44
- package/dist/esm/lib/utils/compress-util.d.ts +0 -53
- package/dist/esm/lib/utils/file-utils.d.ts +0 -43
- package/dist/esm/lib/utils/lod-conversion-utils.d.ts +0 -32
- package/src/i3s-converter/helpers/geometry-converter.d.ts +0 -44
- package/src/lib/utils/compress-util.d.ts +0 -53
- package/src/lib/utils/file-utils.js +0 -38
- package/src/lib/utils/lod-conversion-utils.d.ts +0 -32
|
@@ -7,9 +7,9 @@ export function generateAttributes(attributes) {
|
|
|
7
7
|
normals,
|
|
8
8
|
texCoords,
|
|
9
9
|
colors,
|
|
10
|
-
featureIndices
|
|
11
|
-
triangleCount
|
|
10
|
+
featureIndices
|
|
12
11
|
} = attributes;
|
|
12
|
+
const triangleCount = positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE;
|
|
13
13
|
|
|
14
14
|
if (!featureIndices.length) {
|
|
15
15
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/i3s-converter/helpers/geometry-attributes.ts"],"names":["concatenateTypedArrays","VALUES_PER_VERTEX","POSITIONS_AND_NORMALS_PER_TRIANGLE","generateAttributes","attributes","positions","normals","texCoords","colors","featureIndices","triangleCount","length","faceRange","Uint32Array","featureIds","featureCount","data","calculateFaceRangesAndFeaturesCount","attributeObjects","makeAttributeObjects","unifiedAttributeObjectsByFeatureIds","unifyObjectsByFeatureId","groupedAttributes","groupAttributesAndRangesByFeatureId","rangeIndex","featureIndex","currentFeatureId","faceRangeList","uniqueFeatureIds","index","includes","push","groupedData","positionsList","Float32Array","normalsList","colorsList","Uint8Array","texCoordsList","faceRangeIndex","startIndex","endIndex","positionsCount","getSliceAttributeCount","normalsCount","colorsCount","texCoordsCount","featureId","slice","sort","first","second","attributeName","colorsPerVertex","texCoordsPerVertex","trianglesCount","vertexCount","sortedData","uniqueObjects","currentObject","existedObject","find","obj","unifiedObjects","firstAttributeObject","range","objIndex","sum","currentAttributesObject","groupedObject"],"mappings":"AACA,SAAQA,sBAAR,QAAqC,0BAArC;AAEA,MAAMC,iBAAiB,GAAG,CAA1B;AACA,MAAMC,kCAAkC,GAAG,CAA3C;AAOA,OAAO,SAASC,kBAAT,CAA4BC,UAA5B,EAA4E;AACjF,QAAM;AAACC,IAAAA,SAAD;AAAYC,IAAAA,OAAZ;AAAqBC,IAAAA,SAArB;AAAgCC,IAAAA,MAAhC;AAAwCC,IAAAA,cAAxC;AAAwDC,IAAAA;AAAxD,MAAyEN,UAA/E;;AAEA,MAAI,CAACK,cAAc,CAACE,MAApB,EAA4B;AAC1B,WAAO;AACLC,MAAAA,SAAS,EAAE,IAAIC,WAAJ,CAAgB,CAAC,CAAD,EAAIH,aAAa,GAAG,CAApB,CAAhB,CADN;AAELI,MAAAA,UAAU,EAAE,CAAC,CAAD,CAFP;AAGLC,MAAAA,YAAY,EAAE,CAHT;AAILV,MAAAA,SAJK;AAKLC,MAAA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O,GAAGN,sBAAsB,CAACM,OAAD,EAAU8D,uBAAuB,CAAC9D,OAAlC,CAAhC;AACAE,IAAAA,MAAM,GAAGR,sBAAsB,CAACQ,MAAD,EAAS4D,uBAAuB,CAAC5D,MAAjC,CAA/B;AACAD,IAAAA,SAAS,GAAGP,sBAAsB,CAACO,SAAD,EAAY6D,uBAAuB,CAAC7D,SAApC,CAAlC;AAEA,UAAM8D,aAAa,GAAGN,cAAc,CAACG,QAAD,CAApC;AACAD,IAAAA,KAAK,CAAClC,IAAN,CAAWsC,aAAa,CAAChE,SAAd,CAAwBM,MAAxB,GAAiCT,kCAAjC,GAAsE,CAAtE,GAA0EiE,GAArF;AACAF,IAAAA,KAAK,CAAClC,IAAN,CAAWsC,aAAa,CAAChE,SAAd,CAAwBM,MAAxB,GAAiCT,kCAAjC,GAAsEiE,GAAjF;AAEAA,IAAAA,GAAG,IAAIE,aAAa,CAAChE,SAAd,CAAwBM,MAAxB,GAAiCT,kCAAxC;AACAgE,IAAAA,QAAQ,IAAI,CAAZ;AACD;;AAEDD,EAAAA,KAAK,CAAClC,IAAN,CAAW1B,SAAS,CAACM,MAAV,GAAmBT,kCAAnB,GAAwD,CAAnE;AAEA,QAAMU,SAAS,GAAG,IAAIC,WAAJ,CAAgBoD,KAAhB,CAAlB;AACA,SAAO;AAACrD,IAAAA,SAAD;AAAYE,IAAAA,UAAZ;AAAwBT,IAAAA,SAAxB;AAAmCC,IAAAA,OAAnC;AAA4CE,IAAAA,MAA5C;AAAoDD,IAAAA,SAApD;AAA+DQ,IAAAA;AAA/D,GAAP;AACD","sourcesContent":["import type {GeometryAttributes, AttributesData, GroupedByFeatureIdAttributes} from '../types';\nimport {concatenateTypedArrays} from '@loaders.gl/loader-utils';\n\nconst VALUES_PER_VERTEX = 3;\nconst POSITIONS_AND_NORMALS_PER_TRIANGLE = 9;\n\n/**\n * Generate geometry attributes with faceRange and featureCount\n * @param attributes\n * @returns attirbutes with featureCount, featureIds and changed faceRange.\n */\nexport function generateAttributes(attributes: AttributesData): GeometryAttributes {\n const {positions, normals, texCoords, colors, featureIndices, triangleCount} = attributes;\n\n if (!featureIndices.length) {\n return {\n faceRange: new Uint32Array([0, triangleCount - 1]),\n featureIds: [0],\n featureCount: 1,\n positions,\n normals,\n texCoords,\n colors\n };\n }\n\n const data = calculateFaceRangesAndFeaturesCount(featureIndices);\n const attributeObjects = makeAttributeObjects({...data, ...attributes});\n const unifiedAttributeObjectsByFeatureIds = unifyObjectsByFeatureId(attributeObjects);\n const groupedAttributes = groupAttributesAndRangesByFeatureId(\n unifiedAttributeObjectsByFeatureIds,\n data.featureCount\n );\n return groupedAttributes;\n}\n\n/**\n * Calculates face Ranges and feature count based on featureIndices.\n * @param featureIndices\n * @returns Object with featureCount, reordered attributes and changed faceRange.\n */\nfunction calculateFaceRangesAndFeaturesCount(featureIndices: number[]): {\n faceRange: Uint32Array;\n featureCount: number;\n featureIds: number[];\n} {\n let rangeIndex = 1;\n let featureIndex = 1;\n let currentFeatureId = featureIndices[0];\n const faceRangeList: any[] = [];\n const featureIds: any[] = [];\n const uniqueFeatureIds = [currentFeatureId];\n\n faceRangeList[0] = 0;\n featureIds[0] = currentFeatureId;\n\n for (let index = 1; index < featureIndices.length; index++) {\n if (currentFeatureId !== featureIndices[index]) {\n faceRangeList[rangeIndex] = index / VALUES_PER_VERTEX - 1;\n faceRangeList[rangeIndex + 1] = index / VALUES_PER_VERTEX;\n featureIds[featureIndex] = featureIndices[index];\n\n if (!uniqueFeatureIds.includes(featureIndices[index])) {\n uniqueFeatureIds.push(featureIndices[index]);\n }\n\n rangeIndex += 2;\n featureIndex += 1;\n }\n currentFeatureId = featureIndices[index];\n }\n\n faceRangeList[rangeIndex] = featureIndices.length / VALUES_PER_VERTEX - 1;\n\n const faceRange = new Uint32Array(faceRangeList);\n const featureCount = uniqueFeatureIds.length;\n\n return {faceRange, featureCount, featureIds};\n}\n\n/**\n * Generate list of attribute object grouped by feature ids.\n * @param attributes\n * @returns sorted list of attribute objects.\n */\nfunction makeAttributeObjects(attributes: GeometryAttributes): GroupedByFeatureIdAttributes[] {\n const {\n featureIds,\n positions,\n normals,\n colors,\n texCoords,\n faceRange = new Uint32Array(0)\n } = attributes;\n const groupedData: GroupedByFeatureIdAttributes[] = [];\n\n let positionsList = new Float32Array(positions);\n let normalsList = new Float32Array(normals);\n let colorsList = new Uint8Array(colors);\n let texCoordsList = new Float32Array(texCoords);\n\n let faceRangeIndex = 0;\n\n for (let index = 0; index < featureIds.length; index++) {\n const startIndex = faceRange[index + faceRangeIndex];\n const endIndex = faceRange[index + faceRangeIndex + 1];\n\n const positionsCount = getSliceAttributeCount('positions', startIndex, endIndex);\n const normalsCount = getSliceAttributeCount('normals', startIndex, endIndex);\n const colorsCount = getSliceAttributeCount('colors', startIndex, endIndex);\n const texCoordsCount = getSliceAttributeCount('texCoords', startIndex, endIndex);\n\n groupedData.push({\n featureId: featureIds[index],\n positions: positionsList.slice(0, positionsCount),\n normals: normalsList.slice(0, normalsCount),\n colors: colorsList.slice(0, colorsCount),\n texCoords: texCoordsList.slice(0, texCoordsCount)\n });\n\n positionsList = positionsList.slice(positionsCount);\n normalsList = normalsList.slice(normalsCount);\n colorsList = colorsList.slice(colorsCount);\n texCoordsList = texCoordsList.slice(texCoordsCount);\n\n faceRangeIndex += 1;\n }\n\n return groupedData.sort((first, second) => first.featureId - second.featureId);\n}\n\n/**\n * Generate sliced count for generating attribute objects depends on attribute name and range.\n * @param attributeName\n * @param startIndex\n * @param endIndex\n * @returns sliced count\n */\nfunction getSliceAttributeCount(\n attributeName: string,\n startIndex: number,\n endIndex: number\n): number {\n const colorsPerVertex = 4;\n const texCoordsPerVertex = 2;\n\n const trianglesCount = endIndex - startIndex + 1;\n const vertexCount = trianglesCount * 3;\n\n switch (attributeName) {\n case 'positions':\n case 'normals':\n return trianglesCount * POSITIONS_AND_NORMALS_PER_TRIANGLE;\n case 'colors':\n return vertexCount * colorsPerVertex;\n case 'texCoords':\n return vertexCount * texCoordsPerVertex;\n default:\n return 0;\n }\n}\n\n/**\n * Generates unique object list depends on feature ids and concantenate their attributes.\n * @param sortedData\n * @returns unique list of objects\n */\nfunction unifyObjectsByFeatureId(\n sortedData: GroupedByFeatureIdAttributes[]\n): GroupedByFeatureIdAttributes[] {\n const uniqueObjects: GroupedByFeatureIdAttributes[] = [];\n\n for (let index = 0; index < sortedData.length; index++) {\n const currentObject = sortedData[index];\n const existedObject = uniqueObjects.find((obj) => obj.featureId === currentObject.featureId);\n\n if (existedObject) {\n existedObject.positions = concatenateTypedArrays(\n existedObject.positions,\n currentObject.positions\n );\n existedObject.normals = concatenateTypedArrays(existedObject.normals, currentObject.normals);\n existedObject.colors = concatenateTypedArrays(existedObject.colors, currentObject.colors);\n existedObject.texCoords = concatenateTypedArrays(\n existedObject.texCoords,\n currentObject.texCoords\n );\n } else {\n uniqueObjects.push(currentObject);\n }\n }\n\n return uniqueObjects;\n}\n\n/**\n * Generates attribute objects with new faceRange and reordered attributes.\n * @param unifiedObjects\n * @returns generated attributes with new faceRange.\n */\nfunction groupAttributesAndRangesByFeatureId(\n unifiedObjects: GroupedByFeatureIdAttributes[],\n featureCount: number\n): GeometryAttributes {\n const firstAttributeObject = unifiedObjects[0];\n const featureIds = [firstAttributeObject.featureId || 0];\n\n let positions = new Float32Array(firstAttributeObject.positions);\n let normals = new Float32Array(firstAttributeObject.normals);\n let colors = new Uint8Array(firstAttributeObject.colors);\n let texCoords = new Float32Array(firstAttributeObject.texCoords);\n const range = [0];\n\n let objIndex = 0;\n let sum = 0;\n\n for (let index = 1; index < unifiedObjects.length; index++) {\n const currentAttributesObject = unifiedObjects[index];\n featureIds.push(currentAttributesObject.featureId || 0);\n\n positions = concatenateTypedArrays(positions, currentAttributesObject.positions);\n normals = concatenateTypedArrays(normals, currentAttributesObject.normals);\n colors = concatenateTypedArrays(colors, currentAttributesObject.colors);\n texCoords = concatenateTypedArrays(texCoords, currentAttributesObject.texCoords);\n\n const groupedObject = unifiedObjects[objIndex];\n range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1 + sum);\n range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE + sum);\n\n sum += groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE;\n objIndex += 1;\n }\n\n range.push(positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1);\n\n const faceRange = new Uint32Array(range);\n return {faceRange, featureIds, positions, normals, colors, texCoords, featureCount};\n}\n"],"file":"geometry-attributes.js"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/i3s-converter/helpers/geometry-attributes.ts"],"names":["concatenateTypedArrays","VALUES_PER_VERTEX","POSITIONS_AND_NORMALS_PER_TRIANGLE","generateAttributes","attributes","positions","normals","texCoords","colors","featureIndices","triangleCount","length","faceRange","Uint32Array","featureIds","featureCount","data","calculateFaceRangesAndFeaturesCount","attributeObjects","makeAttributeObjects","unifiedAttributeObjectsByFeatureIds","unifyObjectsByFeatureId","groupedAttributes","groupAttributesAndRangesByFeatureId","rangeIndex","featureIndex","currentFeatureId","faceRangeList","uniqueFeatureIds","index","includes","push","groupedData","positionsList","Float32Array","normalsList","colorsList","Uint8Array","texCoordsList","faceRangeIndex","startIndex","endIndex","positionsCount","getSliceAttributeCount","normalsCount","colorsCount","texCoordsCount","featureId","slice","sort","first","second","attributeName","colorsPerVertex","texCoordsPerVertex","trianglesCount","vertexCount","sortedData","uniqueObjects","currentObject","existedObject","find","obj","unifiedObjects","firstAttributeObject","range","objIndex","sum","currentAttributesObject","groupedObject"],"mappings":"AACA,SAAQA,sBAAR,QAAqC,0BAArC;AAEA,MAAMC,iBAAiB,GAAG,CAA1B;AACA,MAAMC,kCAAkC,GAAG,CAA3C;AAOA,OAAO,SAASC,kBAAT,CAA4BC,UAA5B,EAAiF;AACtF,QAAM;AAACC,IAAAA,SAAD;AAAYC,IAAAA,OAAZ;AAAqBC,IAAAA,SAArB;AAAgCC,IAAAA,MAAhC;AAAwCC,IAA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C,IAAAA,OAAnC;AAA4CE,IAAAA,MAA5C;AAAoDD,IAAAA,SAApD;AAA+DQ,IAAAA;AAA/D,GAAP;AACD","sourcesContent":["import type {GeometryAttributes, ConvertedAttributes, GroupedByFeatureIdAttributes} from '../types';\nimport {concatenateTypedArrays} from '@loaders.gl/loader-utils';\n\nconst VALUES_PER_VERTEX = 3;\nconst POSITIONS_AND_NORMALS_PER_TRIANGLE = 9;\n\n/**\n * Generate geometry attributes with faceRange and featureCount\n * @param attributes\n * @returns attirbutes with featureCount, featureIds and changed faceRange.\n */\nexport function generateAttributes(attributes: ConvertedAttributes): GeometryAttributes {\n const {positions, normals, texCoords, colors, featureIndices} = attributes;\n const triangleCount = positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE;\n\n if (!featureIndices.length) {\n return {\n faceRange: new Uint32Array([0, triangleCount - 1]),\n featureIds: [0],\n featureCount: 1,\n positions,\n normals,\n texCoords,\n colors\n };\n }\n\n const data = calculateFaceRangesAndFeaturesCount(featureIndices);\n const attributeObjects = makeAttributeObjects({...data, ...attributes});\n const unifiedAttributeObjectsByFeatureIds = unifyObjectsByFeatureId(attributeObjects);\n const groupedAttributes = groupAttributesAndRangesByFeatureId(\n unifiedAttributeObjectsByFeatureIds,\n data.featureCount\n );\n return groupedAttributes;\n}\n\n/**\n * Calculates face Ranges and feature count based on featureIndices.\n * @param featureIndices\n * @returns Object with featureCount, reordered attributes and changed faceRange.\n */\nfunction calculateFaceRangesAndFeaturesCount(featureIndices: number[]): {\n faceRange: Uint32Array;\n featureCount: number;\n featureIds: number[];\n} {\n let rangeIndex = 1;\n let featureIndex = 1;\n let currentFeatureId = featureIndices[0];\n const faceRangeList: any[] = [];\n const featureIds: any[] = [];\n const uniqueFeatureIds = [currentFeatureId];\n\n faceRangeList[0] = 0;\n featureIds[0] = currentFeatureId;\n\n for (let index = 1; index < featureIndices.length; index++) {\n if (currentFeatureId !== featureIndices[index]) {\n faceRangeList[rangeIndex] = index / VALUES_PER_VERTEX - 1;\n faceRangeList[rangeIndex + 1] = index / VALUES_PER_VERTEX;\n featureIds[featureIndex] = featureIndices[index];\n\n if (!uniqueFeatureIds.includes(featureIndices[index])) {\n uniqueFeatureIds.push(featureIndices[index]);\n }\n\n rangeIndex += 2;\n featureIndex += 1;\n }\n currentFeatureId = featureIndices[index];\n }\n\n faceRangeList[rangeIndex] = featureIndices.length / VALUES_PER_VERTEX - 1;\n\n const faceRange = new Uint32Array(faceRangeList);\n const featureCount = uniqueFeatureIds.length;\n\n return {faceRange, featureCount, featureIds};\n}\n\n/**\n * Generate list of attribute object grouped by feature ids.\n * @param attributes\n * @returns sorted list of attribute objects.\n */\nfunction makeAttributeObjects(attributes: GeometryAttributes): GroupedByFeatureIdAttributes[] {\n const {\n featureIds,\n positions,\n normals,\n colors,\n texCoords,\n faceRange = new Uint32Array(0)\n } = attributes;\n const groupedData: GroupedByFeatureIdAttributes[] = [];\n\n let positionsList = new Float32Array(positions);\n let normalsList = new Float32Array(normals);\n let colorsList = new Uint8Array(colors);\n let texCoordsList = new Float32Array(texCoords);\n\n let faceRangeIndex = 0;\n\n for (let index = 0; index < featureIds.length; index++) {\n const startIndex = faceRange[index + faceRangeIndex];\n const endIndex = faceRange[index + faceRangeIndex + 1];\n\n const positionsCount = getSliceAttributeCount('positions', startIndex, endIndex);\n const normalsCount = getSliceAttributeCount('normals', startIndex, endIndex);\n const colorsCount = getSliceAttributeCount('colors', startIndex, endIndex);\n const texCoordsCount = getSliceAttributeCount('texCoords', startIndex, endIndex);\n\n groupedData.push({\n featureId: featureIds[index],\n positions: positionsList.slice(0, positionsCount),\n normals: normalsList.slice(0, normalsCount),\n colors: colorsList.slice(0, colorsCount),\n texCoords: texCoordsList.slice(0, texCoordsCount)\n });\n\n positionsList = positionsList.slice(positionsCount);\n normalsList = normalsList.slice(normalsCount);\n colorsList = colorsList.slice(colorsCount);\n texCoordsList = texCoordsList.slice(texCoordsCount);\n\n faceRangeIndex += 1;\n }\n\n return groupedData.sort((first, second) => first.featureId - second.featureId);\n}\n\n/**\n * Generate sliced count for generating attribute objects depends on attribute name and range.\n * @param attributeName\n * @param startIndex\n * @param endIndex\n * @returns sliced count\n */\nfunction getSliceAttributeCount(\n attributeName: string,\n startIndex: number,\n endIndex: number\n): number {\n const colorsPerVertex = 4;\n const texCoordsPerVertex = 2;\n\n const trianglesCount = endIndex - startIndex + 1;\n const vertexCount = trianglesCount * 3;\n\n switch (attributeName) {\n case 'positions':\n case 'normals':\n return trianglesCount * POSITIONS_AND_NORMALS_PER_TRIANGLE;\n case 'colors':\n return vertexCount * colorsPerVertex;\n case 'texCoords':\n return vertexCount * texCoordsPerVertex;\n default:\n return 0;\n }\n}\n\n/**\n * Generates unique object list depends on feature ids and concantenate their attributes.\n * @param sortedData\n * @returns unique list of objects\n */\nfunction unifyObjectsByFeatureId(\n sortedData: GroupedByFeatureIdAttributes[]\n): GroupedByFeatureIdAttributes[] {\n const uniqueObjects: GroupedByFeatureIdAttributes[] = [];\n\n for (let index = 0; index < sortedData.length; index++) {\n const currentObject = sortedData[index];\n const existedObject = uniqueObjects.find((obj) => obj.featureId === currentObject.featureId);\n\n if (existedObject) {\n existedObject.positions = concatenateTypedArrays(\n existedObject.positions,\n currentObject.positions\n );\n existedObject.normals = concatenateTypedArrays(existedObject.normals, currentObject.normals);\n existedObject.colors = concatenateTypedArrays(existedObject.colors, currentObject.colors);\n existedObject.texCoords = concatenateTypedArrays(\n existedObject.texCoords,\n currentObject.texCoords\n );\n } else {\n uniqueObjects.push(currentObject);\n }\n }\n\n return uniqueObjects;\n}\n\n/**\n * Generates attribute objects with new faceRange and reordered attributes.\n * @param unifiedObjects\n * @returns generated attributes with new faceRange.\n */\nfunction groupAttributesAndRangesByFeatureId(\n unifiedObjects: GroupedByFeatureIdAttributes[],\n featureCount: number\n): GeometryAttributes {\n const firstAttributeObject = unifiedObjects[0];\n const featureIds = [firstAttributeObject.featureId || 0];\n\n let positions = new Float32Array(firstAttributeObject.positions);\n let normals = new Float32Array(firstAttributeObject.normals);\n let colors = new Uint8Array(firstAttributeObject.colors);\n let texCoords = new Float32Array(firstAttributeObject.texCoords);\n const range = [0];\n\n let objIndex = 0;\n let sum = 0;\n\n for (let index = 1; index < unifiedObjects.length; index++) {\n const currentAttributesObject = unifiedObjects[index];\n featureIds.push(currentAttributesObject.featureId || 0);\n\n positions = concatenateTypedArrays(positions, currentAttributesObject.positions);\n normals = concatenateTypedArrays(normals, currentAttributesObject.normals);\n colors = concatenateTypedArrays(colors, currentAttributesObject.colors);\n texCoords = concatenateTypedArrays(texCoords, currentAttributesObject.texCoords);\n\n const groupedObject = unifiedObjects[objIndex];\n range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1 + sum);\n range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE + sum);\n\n sum += groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE;\n objIndex += 1;\n }\n\n range.push(positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1);\n\n const faceRange = new Uint32Array(range);\n return {faceRange, featureIds, positions, normals, colors, texCoords, featureCount};\n}\n"],"file":"geometry-attributes.js"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Vector3, Matrix4, Vector4 } from '@math.gl/core';
|
|
2
2
|
import { Ellipsoid } from '@math.gl/geospatial';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { DracoWriterWorker } from '@loaders.gl/draco';
|
|
4
|
+
import { assert, encode } from '@loaders.gl/core';
|
|
5
5
|
import { concatenateArrayBuffers, concatenateTypedArrays } from '@loaders.gl/loader-utils';
|
|
6
6
|
import md5 from 'md5';
|
|
7
7
|
import { generateAttributes } from './geometry-attributes';
|
|
8
8
|
import { createBoundingVolumesFromGeometry } from './coordinate-converter';
|
|
9
|
+
import { prepareDataForAttributesConversion } from './gltf-attributes';
|
|
9
10
|
const DEFAULT_ROUGHNESS_FACTOR = 1;
|
|
10
11
|
const DEFAULT_METALLIC_FACTOR = 1;
|
|
11
12
|
const VALUES_PER_VERTEX = 3;
|
|
@@ -17,10 +18,13 @@ const DOUBLE_TYPE = 'Float64';
|
|
|
17
18
|
const OBJECT_ID_TYPE = 'Oid32';
|
|
18
19
|
const BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];
|
|
19
20
|
let scratchVector = new Vector3();
|
|
20
|
-
export default async function convertB3dmToI3sGeometry(tileContent, nodeId, featuresHashArray, attributeStorageInfo, draco, generateBoundingVolumes, geoidHeightModel) {
|
|
21
|
+
export default async function convertB3dmToI3sGeometry(tileContent, nodeId, featuresHashArray, attributeStorageInfo, draco, generateBoundingVolumes, geoidHeightModel, workerSource) {
|
|
22
|
+
var _tileContent$gltf;
|
|
23
|
+
|
|
21
24
|
const useCartesianPositions = generateBoundingVolumes;
|
|
22
|
-
const materialAndTextureList = convertMaterials(tileContent);
|
|
23
|
-
const
|
|
25
|
+
const materialAndTextureList = convertMaterials((_tileContent$gltf = tileContent.gltf) === null || _tileContent$gltf === void 0 ? void 0 : _tileContent$gltf.materials);
|
|
26
|
+
const dataForAttributesConversion = prepareDataForAttributesConversion(tileContent);
|
|
27
|
+
const convertedAttributesMap = await convertAttributes(dataForAttributesConversion, useCartesianPositions);
|
|
24
28
|
|
|
25
29
|
if (generateBoundingVolumes) {
|
|
26
30
|
_generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel);
|
|
@@ -36,7 +40,9 @@ export default async function convertB3dmToI3sGeometry(tileContent, nodeId, feat
|
|
|
36
40
|
let nodesCounter = nodeId;
|
|
37
41
|
let {
|
|
38
42
|
materials = []
|
|
39
|
-
} = tileContent.gltf
|
|
43
|
+
} = tileContent.gltf || {
|
|
44
|
+
materials: []
|
|
45
|
+
};
|
|
40
46
|
|
|
41
47
|
if (!(materials !== null && materials !== void 0 && materials.length)) {
|
|
42
48
|
materials.push({
|
|
@@ -52,6 +58,11 @@ export default async function convertB3dmToI3sGeometry(tileContent, nodeId, feat
|
|
|
52
58
|
}
|
|
53
59
|
|
|
54
60
|
const convertedAttributes = convertedAttributesMap.get(sourceMaterial.id);
|
|
61
|
+
|
|
62
|
+
if (!convertedAttributes) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
|
|
55
66
|
const {
|
|
56
67
|
material,
|
|
57
68
|
texture
|
|
@@ -64,7 +75,8 @@ export default async function convertB3dmToI3sGeometry(tileContent, nodeId, feat
|
|
|
64
75
|
nodeId: nodesCounter,
|
|
65
76
|
featuresHashArray,
|
|
66
77
|
attributeStorageInfo,
|
|
67
|
-
draco
|
|
78
|
+
draco,
|
|
79
|
+
workerSource
|
|
68
80
|
}));
|
|
69
81
|
nodesCounter++;
|
|
70
82
|
}
|
|
@@ -100,11 +112,13 @@ async function _makeNodeResources({
|
|
|
100
112
|
nodeId,
|
|
101
113
|
featuresHashArray,
|
|
102
114
|
attributeStorageInfo,
|
|
103
|
-
draco
|
|
115
|
+
draco,
|
|
116
|
+
workerSource
|
|
104
117
|
}) {
|
|
118
|
+
var _tileContent$gltf2;
|
|
119
|
+
|
|
105
120
|
const boundingVolumes = convertedAttributes.boundingVolumes;
|
|
106
121
|
const vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;
|
|
107
|
-
const triangleCount = vertexCount / 3;
|
|
108
122
|
const {
|
|
109
123
|
faceRange,
|
|
110
124
|
featureIds,
|
|
@@ -113,10 +127,7 @@ async function _makeNodeResources({
|
|
|
113
127
|
colors,
|
|
114
128
|
texCoords,
|
|
115
129
|
featureCount
|
|
116
|
-
} = generateAttributes(
|
|
117
|
-
triangleCount,
|
|
118
|
-
...convertedAttributes
|
|
119
|
-
});
|
|
130
|
+
} = generateAttributes(convertedAttributes);
|
|
120
131
|
|
|
121
132
|
if (tileContent.batchTableJson) {
|
|
122
133
|
makeFeatureIdsUnique(featureIds, convertedAttributes.featureIndices, featuresHashArray, tileContent.batchTableJson);
|
|
@@ -126,20 +137,20 @@ async function _makeNodeResources({
|
|
|
126
137
|
const typedFeatureIds = generateBigUint64Array(featureIds);
|
|
127
138
|
header.set([vertexCount, featureCount], 0);
|
|
128
139
|
const fileBuffer = new Uint8Array(concatenateArrayBuffers(header.buffer, positions.buffer, normals.buffer, texture ? texCoords.buffer : new ArrayBuffer(0), colors.buffer, typedFeatureIds.buffer, faceRange.buffer));
|
|
129
|
-
const compressedGeometry = draco ?
|
|
140
|
+
const compressedGeometry = draco ? generateCompressedGeometry(vertexCount, convertedAttributes, {
|
|
130
141
|
positions,
|
|
131
142
|
normals,
|
|
132
143
|
texCoords: texture ? texCoords : new Float32Array(0),
|
|
133
144
|
colors,
|
|
134
145
|
featureIds,
|
|
135
146
|
faceRange
|
|
136
|
-
}) : null;
|
|
147
|
+
}, workerSource.draco) : null;
|
|
137
148
|
const attributes = convertBatchTableToAttributeBuffers(tileContent.batchTableJson, featureIds, attributeStorageInfo);
|
|
138
149
|
return {
|
|
139
150
|
geometry: fileBuffer,
|
|
140
151
|
compressedGeometry,
|
|
141
152
|
texture,
|
|
142
|
-
sharedResources: getSharedResources(tileContent, nodeId),
|
|
153
|
+
sharedResources: getSharedResources(((_tileContent$gltf2 = tileContent.gltf) === null || _tileContent$gltf2 === void 0 ? void 0 : _tileContent$gltf2.materials) || [], nodeId),
|
|
143
154
|
meshMaterial: material,
|
|
144
155
|
vertexCount,
|
|
145
156
|
attributes,
|
|
@@ -148,12 +159,16 @@ async function _makeNodeResources({
|
|
|
148
159
|
};
|
|
149
160
|
}
|
|
150
161
|
|
|
151
|
-
function convertAttributes(
|
|
152
|
-
|
|
153
|
-
|
|
162
|
+
export async function convertAttributes(attributesData, useCartesianPositions) {
|
|
163
|
+
const {
|
|
164
|
+
gltfMaterials,
|
|
165
|
+
nodes,
|
|
166
|
+
cartographicOrigin,
|
|
167
|
+
cartesianModelMatrix
|
|
168
|
+
} = attributesData;
|
|
154
169
|
const attributesMap = new Map();
|
|
155
170
|
|
|
156
|
-
for (const material of
|
|
171
|
+
for (const material of gltfMaterials || [{
|
|
157
172
|
id: 'default'
|
|
158
173
|
}]) {
|
|
159
174
|
attributesMap.set(material.id, {
|
|
@@ -161,32 +176,39 @@ function convertAttributes(tileContent, useCartesianPositions) {
|
|
|
161
176
|
normals: new Float32Array(0),
|
|
162
177
|
texCoords: new Float32Array(0),
|
|
163
178
|
colors: new Uint8Array(0),
|
|
179
|
+
featureIndicesGroups: [],
|
|
164
180
|
featureIndices: [],
|
|
165
181
|
boundingVolumes: null
|
|
166
182
|
});
|
|
167
183
|
}
|
|
168
184
|
|
|
169
|
-
|
|
170
|
-
convertNodes(nodes, tileContent, attributesMap, useCartesianPositions);
|
|
185
|
+
convertNodes(nodes, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions);
|
|
171
186
|
|
|
172
187
|
for (const attrKey of attributesMap.keys()) {
|
|
173
188
|
const attributes = attributesMap.get(attrKey);
|
|
174
189
|
|
|
190
|
+
if (!attributes) {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
|
|
175
194
|
if (attributes.positions.length === 0) {
|
|
176
195
|
attributesMap.delete(attrKey);
|
|
177
196
|
continue;
|
|
178
197
|
}
|
|
179
198
|
|
|
180
|
-
|
|
199
|
+
if (attributes.featureIndicesGroups) {
|
|
200
|
+
attributes.featureIndices = attributes.featureIndicesGroups.reduce((acc, value) => acc.concat(value));
|
|
201
|
+
delete attributes.featureIndicesGroups;
|
|
202
|
+
}
|
|
181
203
|
}
|
|
182
204
|
|
|
183
205
|
return attributesMap;
|
|
184
206
|
}
|
|
185
207
|
|
|
186
|
-
function convertNodes(nodes,
|
|
208
|
+
function convertNodes(nodes, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
|
|
187
209
|
if (nodes) {
|
|
188
210
|
for (const node of nodes) {
|
|
189
|
-
convertNode(node,
|
|
211
|
+
convertNode(node, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix);
|
|
190
212
|
}
|
|
191
213
|
}
|
|
192
214
|
}
|
|
@@ -219,19 +241,21 @@ function getCompositeTransformationMatrix(node, matrix) {
|
|
|
219
241
|
return transformationMatrix;
|
|
220
242
|
}
|
|
221
243
|
|
|
222
|
-
function convertNode(node,
|
|
244
|
+
function convertNode(node, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
|
|
223
245
|
const transformationMatrix = getCompositeTransformationMatrix(node, matrix);
|
|
224
246
|
const mesh = node.mesh;
|
|
225
247
|
|
|
226
248
|
if (mesh) {
|
|
227
|
-
convertMesh(mesh,
|
|
249
|
+
convertMesh(mesh, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
|
|
228
250
|
}
|
|
229
251
|
|
|
230
|
-
convertNodes(node.children,
|
|
252
|
+
convertNodes(node.children || [], cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
|
|
231
253
|
}
|
|
232
254
|
|
|
233
|
-
function convertMesh(mesh,
|
|
255
|
+
function convertMesh(mesh, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions = false, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
|
|
234
256
|
for (const primitive of mesh.primitives) {
|
|
257
|
+
var _primitive$indices, _primitive$indices2, _primitive$indices3, _primitive$indices4, _primitive$indices5;
|
|
258
|
+
|
|
235
259
|
let outputAttributes = null;
|
|
236
260
|
|
|
237
261
|
if (primitive.material) {
|
|
@@ -242,27 +266,33 @@ function convertMesh(mesh, content, attributesMap, useCartesianPositions = false
|
|
|
242
266
|
|
|
243
267
|
assert(outputAttributes !== null, 'Primitive - material mapping failed');
|
|
244
268
|
const attributes = primitive.attributes;
|
|
269
|
+
|
|
270
|
+
if (!outputAttributes) {
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
|
|
245
274
|
outputAttributes.positions = concatenateTypedArrays(outputAttributes.positions, transformVertexArray({
|
|
246
275
|
vertices: attributes.POSITION.value,
|
|
247
|
-
cartographicOrigin
|
|
248
|
-
cartesianModelMatrix
|
|
276
|
+
cartographicOrigin,
|
|
277
|
+
cartesianModelMatrix,
|
|
249
278
|
nodeMatrix: matrix,
|
|
250
|
-
indices: primitive.indices.value,
|
|
279
|
+
indices: (_primitive$indices = primitive.indices) === null || _primitive$indices === void 0 ? void 0 : _primitive$indices.value,
|
|
251
280
|
attributeSpecificTransformation: transformVertexPositions,
|
|
252
281
|
useCartesianPositions
|
|
253
282
|
}));
|
|
254
283
|
outputAttributes.normals = concatenateTypedArrays(outputAttributes.normals, transformVertexArray({
|
|
255
284
|
vertices: attributes.NORMAL && attributes.NORMAL.value,
|
|
256
|
-
cartographicOrigin
|
|
257
|
-
cartesianModelMatrix
|
|
285
|
+
cartographicOrigin,
|
|
286
|
+
cartesianModelMatrix,
|
|
258
287
|
nodeMatrix: matrix,
|
|
259
|
-
indices: primitive.indices.value,
|
|
288
|
+
indices: (_primitive$indices2 = primitive.indices) === null || _primitive$indices2 === void 0 ? void 0 : _primitive$indices2.value,
|
|
260
289
|
attributeSpecificTransformation: transformVertexNormals,
|
|
261
290
|
useCartesianPositions: false
|
|
262
291
|
}));
|
|
263
|
-
outputAttributes.texCoords = concatenateTypedArrays(outputAttributes.texCoords, flattenTexCoords(attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value, primitive.indices.value));
|
|
264
|
-
outputAttributes.colors = concatenateTypedArrays(outputAttributes.colors, flattenColors(attributes.COLOR_0, primitive.indices.value));
|
|
265
|
-
outputAttributes.
|
|
292
|
+
outputAttributes.texCoords = concatenateTypedArrays(outputAttributes.texCoords, flattenTexCoords(attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value, (_primitive$indices3 = primitive.indices) === null || _primitive$indices3 === void 0 ? void 0 : _primitive$indices3.value));
|
|
293
|
+
outputAttributes.colors = concatenateTypedArrays(outputAttributes.colors, flattenColors(attributes.COLOR_0, (_primitive$indices4 = primitive.indices) === null || _primitive$indices4 === void 0 ? void 0 : _primitive$indices4.value));
|
|
294
|
+
outputAttributes.featureIndicesGroups = outputAttributes.featureIndicesGroups || [];
|
|
295
|
+
outputAttributes.featureIndicesGroups.push(flattenBatchIds(getBatchIdsByAttributeName(attributes), (_primitive$indices5 = primitive.indices) === null || _primitive$indices5 === void 0 ? void 0 : _primitive$indices5.value));
|
|
266
296
|
}
|
|
267
297
|
}
|
|
268
298
|
|
|
@@ -402,9 +432,8 @@ function getBatchIdsByAttributeName(attributes) {
|
|
|
402
432
|
return batchIds;
|
|
403
433
|
}
|
|
404
434
|
|
|
405
|
-
function convertMaterials(
|
|
435
|
+
function convertMaterials(sourceMaterials = []) {
|
|
406
436
|
const result = [];
|
|
407
|
-
const sourceMaterials = tileContent.gltf.materials || [];
|
|
408
437
|
|
|
409
438
|
for (const sourceMaterial of sourceMaterials) {
|
|
410
439
|
result.push(convertMaterial(sourceMaterial));
|
|
@@ -414,12 +443,12 @@ function convertMaterials(tileContent) {
|
|
|
414
443
|
}
|
|
415
444
|
|
|
416
445
|
function convertMaterial(sourceMaterial) {
|
|
417
|
-
var _sourceMaterial$pbrMe, _sourceMaterial$pbrMe2, _sourceMaterial$pbrMe3;
|
|
446
|
+
var _sourceMaterial$emiss, _sourceMaterial$pbrMe, _sourceMaterial$pbrMe2, _sourceMaterial$pbrMe3;
|
|
418
447
|
|
|
419
448
|
const material = {
|
|
420
449
|
doubleSided: sourceMaterial.doubleSided,
|
|
421
|
-
emissiveFactor: sourceMaterial.emissiveFactor.map(c => Math.round(c * 255)),
|
|
422
|
-
alphaMode: (sourceMaterial.alphaMode
|
|
450
|
+
emissiveFactor: (_sourceMaterial$emiss = sourceMaterial.emissiveFactor) === null || _sourceMaterial$emiss === void 0 ? void 0 : _sourceMaterial$emiss.map(c => Math.round(c * 255)),
|
|
451
|
+
alphaMode: convertAlphaMode(sourceMaterial.alphaMode),
|
|
423
452
|
pbrMetallicRoughness: {
|
|
424
453
|
roughnessFactor: (sourceMaterial === null || sourceMaterial === void 0 ? void 0 : (_sourceMaterial$pbrMe = sourceMaterial.pbrMetallicRoughness) === null || _sourceMaterial$pbrMe === void 0 ? void 0 : _sourceMaterial$pbrMe.roughnessFactor) || DEFAULT_ROUGHNESS_FACTOR,
|
|
425
454
|
metallicFactor: (sourceMaterial === null || sourceMaterial === void 0 ? void 0 : (_sourceMaterial$pbrMe2 = sourceMaterial.pbrMetallicRoughness) === null || _sourceMaterial$pbrMe2 === void 0 ? void 0 : _sourceMaterial$pbrMe2.metallicFactor) || DEFAULT_METALLIC_FACTOR
|
|
@@ -452,15 +481,33 @@ function convertMaterial(sourceMaterial) {
|
|
|
452
481
|
};
|
|
453
482
|
}
|
|
454
483
|
|
|
484
|
+
function convertAlphaMode(gltfAlphaMode) {
|
|
485
|
+
switch (gltfAlphaMode) {
|
|
486
|
+
case 'OPAQUE':
|
|
487
|
+
return 'opaque';
|
|
488
|
+
|
|
489
|
+
case 'MASK':
|
|
490
|
+
return 'mask';
|
|
491
|
+
|
|
492
|
+
case 'BLEND':
|
|
493
|
+
return 'blend';
|
|
494
|
+
|
|
495
|
+
default:
|
|
496
|
+
return 'opaque';
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
455
500
|
function getDefaultMaterial() {
|
|
456
501
|
return {
|
|
457
502
|
alphaMode: 'opaque',
|
|
458
|
-
pbrMetallicRoughness: {
|
|
503
|
+
pbrMetallicRoughness: {
|
|
504
|
+
metallicFactor: 1,
|
|
505
|
+
roughnessFactor: 1
|
|
506
|
+
}
|
|
459
507
|
};
|
|
460
508
|
}
|
|
461
509
|
|
|
462
|
-
function getSharedResources(
|
|
463
|
-
const gltfMaterials = tileContent.gltf.materials;
|
|
510
|
+
function getSharedResources(gltfMaterials, nodeId) {
|
|
464
511
|
const i3sResources = {};
|
|
465
512
|
|
|
466
513
|
if (!gltfMaterials || !gltfMaterials.length) {
|
|
@@ -507,7 +554,7 @@ function convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId) {
|
|
|
507
554
|
}
|
|
508
555
|
|
|
509
556
|
return {
|
|
510
|
-
materialDefinitionInfo: extractSharedResourcesMaterialInfo(colorFactor, metallicFactor),
|
|
557
|
+
materialDefinitionInfo: extractSharedResourcesMaterialInfo(colorFactor || [1, 1, 1, 1], metallicFactor),
|
|
511
558
|
textureDefinitionInfo
|
|
512
559
|
};
|
|
513
560
|
}
|
|
@@ -523,27 +570,34 @@ function extractSharedResourcesMaterialInfo(baseColorFactor, metallicFactor = 1)
|
|
|
523
570
|
dielectricSpecular[3] = 1;
|
|
524
571
|
const specular = dielectricSpecular.lerp(dielectricSpecular, baseColorVector, metallicFactor);
|
|
525
572
|
return {
|
|
526
|
-
|
|
527
|
-
|
|
573
|
+
params: {
|
|
574
|
+
diffuse: diffuse.toArray(),
|
|
575
|
+
specular: specular.toArray(),
|
|
576
|
+
renderMode: 'solid'
|
|
577
|
+
}
|
|
528
578
|
};
|
|
529
579
|
}
|
|
530
580
|
|
|
531
581
|
function extractSharedResourcesTextureInfo(texture, nodeId) {
|
|
582
|
+
var _texture$source, _texture$source2, _texture$source3;
|
|
583
|
+
|
|
532
584
|
return {
|
|
533
|
-
encoding: [texture.source.mimeType],
|
|
585
|
+
encoding: texture !== null && texture !== void 0 && (_texture$source = texture.source) !== null && _texture$source !== void 0 && _texture$source.mimeType ? [texture.source.mimeType] : undefined,
|
|
534
586
|
images: [{
|
|
535
587
|
id: generateImageId(texture, nodeId),
|
|
536
|
-
size: texture.source.image.width,
|
|
537
|
-
length: [texture.source.image.data.length]
|
|
588
|
+
size: (_texture$source2 = texture.source) === null || _texture$source2 === void 0 ? void 0 : _texture$source2.image.width,
|
|
589
|
+
length: [(_texture$source3 = texture.source) === null || _texture$source3 === void 0 ? void 0 : _texture$source3.image.data.length]
|
|
538
590
|
}]
|
|
539
591
|
};
|
|
540
592
|
}
|
|
541
593
|
|
|
542
594
|
function generateImageId(texture, nodeId) {
|
|
595
|
+
var _texture$source4;
|
|
596
|
+
|
|
543
597
|
const {
|
|
544
598
|
width,
|
|
545
599
|
height
|
|
546
|
-
} = texture.source.image;
|
|
600
|
+
} = (_texture$source4 = texture.source) === null || _texture$source4 === void 0 ? void 0 : _texture$source4.image;
|
|
547
601
|
const levelCountOfTexture = 1;
|
|
548
602
|
const indexOfLevel = 0;
|
|
549
603
|
const indexOfTextureInStore = nodeId + 1;
|
|
@@ -634,7 +688,9 @@ function convertBatchTableToAttributeBuffers(batchTable, featureIds, attributeSt
|
|
|
634
688
|
attributeBuffer = generateStringAttributeBuffer(batchTableWithFeatureIds[key]);
|
|
635
689
|
}
|
|
636
690
|
|
|
637
|
-
|
|
691
|
+
if (attributeBuffer) {
|
|
692
|
+
attributeBuffers.push(attributeBuffer);
|
|
693
|
+
}
|
|
638
694
|
}
|
|
639
695
|
}
|
|
640
696
|
|
|
@@ -688,7 +744,7 @@ function generateBigUint64Array(featureIds) {
|
|
|
688
744
|
return typedFeatureIds;
|
|
689
745
|
}
|
|
690
746
|
|
|
691
|
-
async function generateCompressedGeometry(vertexCount, convertedAttributes, attributes) {
|
|
747
|
+
async function generateCompressedGeometry(vertexCount, convertedAttributes, attributes, dracoWorkerSoure) {
|
|
692
748
|
const {
|
|
693
749
|
positions,
|
|
694
750
|
normals,
|
|
@@ -722,15 +778,18 @@ async function generateCompressedGeometry(vertexCount, convertedAttributes, attr
|
|
|
722
778
|
'i3s-feature-ids': new Int32Array(featureIds)
|
|
723
779
|
}
|
|
724
780
|
};
|
|
725
|
-
return
|
|
781
|
+
return encode({
|
|
726
782
|
attributes: compressedAttributes,
|
|
727
783
|
indices
|
|
728
|
-
},
|
|
784
|
+
}, DracoWriterWorker, { ...DracoWriterWorker.options,
|
|
785
|
+
source: dracoWorkerSoure,
|
|
786
|
+
reuseWorkers: true,
|
|
787
|
+
_nodeWorkers: true,
|
|
729
788
|
draco: {
|
|
730
789
|
method: 'MESH_SEQUENTIAL_ENCODING',
|
|
731
790
|
attributesMetadata
|
|
732
791
|
}
|
|
733
|
-
})
|
|
792
|
+
});
|
|
734
793
|
}
|
|
735
794
|
|
|
736
795
|
function generateFeatureIndexAttribute(featureIndex, faceRange) {
|