@loaders.gl/tile-converter 4.0.0-alpha.9 → 4.0.0-beta.1
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/bin/i3s-server.js +4 -0
- package/bin/slpk-extractor.js +4 -0
- package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +5 -5
- package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
- package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +10 -5
- package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -1
- package/dist/3d-tiles-converter/helpers/load-i3s.d.ts +10 -0
- package/dist/3d-tiles-converter/helpers/load-i3s.d.ts.map +1 -0
- package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts +2 -1
- package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts.map +1 -1
- package/dist/converter.min.js +172 -103
- package/dist/deps-installer/deps-installer.d.ts +3 -2
- package/dist/deps-installer/deps-installer.d.ts.map +1 -1
- package/dist/dist.min.js +32715 -32567
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +97 -117
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +24 -22
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/load-i3s.js +63 -0
- package/dist/es5/3d-tiles-converter/helpers/load-i3s.js.map +1 -0
- package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
- package/dist/es5/converter-cli.js +25 -65
- package/dist/es5/converter-cli.js.map +1 -1
- package/dist/es5/deps-installer/deps-installer.js +113 -39
- package/dist/es5/deps-installer/deps-installer.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +45 -15
- package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/feature-attributes.js +8 -18
- package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js +83 -43
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-converter.js +100 -102
- package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/load-3d-tiles.js +70 -4
- package/dist/es5/i3s-converter/helpers/load-3d-tiles.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-index-document.js +3 -2
- package/dist/es5/i3s-converter/helpers/node-index-document.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/preprocess-3d-tiles.js +47 -12
- package/dist/es5/i3s-converter/helpers/preprocess-3d-tiles.js.map +1 -1
- package/dist/es5/i3s-converter/i3s-converter.js +187 -174
- package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/es5/i3s-converter/types.js +11 -11
- package/dist/es5/i3s-converter/types.js.map +1 -1
- package/dist/es5/i3s-server/README.md +46 -2
- package/dist/es5/i3s-server/app.js +23 -15
- package/dist/es5/i3s-server/app.js.map +1 -1
- package/dist/es5/i3s-server/bin/www.js +33 -0
- package/dist/es5/i3s-server/bin/www.js.map +1 -0
- package/dist/es5/i3s-server/controllers/index-controller.js +23 -22
- package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -1
- package/dist/es5/i3s-server/controllers/slpk-controller.js +35 -38
- package/dist/es5/i3s-server/controllers/slpk-controller.js.map +1 -1
- package/dist/es5/i3s-server/routes/index.js +2 -2
- package/dist/es5/i3s-server/routes/index.js.map +1 -1
- package/dist/es5/i3s-server/routes/slpk-router.js +14 -13
- package/dist/es5/i3s-server/routes/slpk-router.js.map +1 -1
- package/dist/es5/i3s-server/utils/create-scene-server.js +7 -4
- package/dist/es5/i3s-server/utils/create-scene-server.js.map +1 -1
- package/dist/es5/i3s-server/utils/server-utils.js +49 -0
- package/dist/es5/i3s-server/utils/server-utils.js.map +1 -0
- package/dist/es5/lib/utils/cli-utils.js +57 -0
- package/dist/es5/lib/utils/cli-utils.js.map +1 -0
- package/dist/es5/lib/utils/compress-util.js +1 -1
- package/dist/es5/lib/utils/compress-util.js.map +1 -1
- package/dist/es5/lib/utils/lod-conversion-utils.js +10 -4
- package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
- package/dist/es5/pgm-loader.js +11 -3
- package/dist/es5/pgm-loader.js.map +1 -1
- package/dist/es5/slpk-extractor/slpk-extractor.js +171 -0
- package/dist/es5/slpk-extractor/slpk-extractor.js.map +1 -0
- package/dist/es5/slpk-extractor-cli.js +117 -0
- package/dist/es5/slpk-extractor-cli.js.map +1 -0
- package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +51 -58
- package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +12 -11
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
- package/dist/esm/3d-tiles-converter/helpers/load-i3s.js +32 -0
- package/dist/esm/3d-tiles-converter/helpers/load-i3s.js.map +1 -0
- package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
- package/dist/esm/converter-cli.js +8 -48
- package/dist/esm/converter-cli.js.map +1 -1
- package/dist/esm/deps-installer/deps-installer.js +38 -12
- package/dist/esm/deps-installer/deps-installer.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js +28 -11
- package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/feature-attributes.js +10 -8
- package/dist/esm/i3s-converter/helpers/feature-attributes.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-attributes.js +77 -34
- package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-converter.js +60 -61
- package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/load-3d-tiles.js +33 -4
- package/dist/esm/i3s-converter/helpers/load-3d-tiles.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/node-index-document.js +2 -1
- package/dist/esm/i3s-converter/helpers/node-index-document.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/preprocess-3d-tiles.js +37 -12
- package/dist/esm/i3s-converter/helpers/preprocess-3d-tiles.js.map +1 -1
- package/dist/esm/i3s-converter/i3s-converter.js +101 -73
- package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/esm/i3s-converter/types.js +9 -9
- package/dist/esm/i3s-converter/types.js.map +1 -1
- package/dist/esm/i3s-server/README.md +46 -2
- package/dist/esm/i3s-server/app.js +13 -11
- package/dist/esm/i3s-server/app.js.map +1 -1
- package/dist/esm/i3s-server/bin/i3s-server.min.js +516 -0
- package/dist/esm/i3s-server/bin/www.js +30 -0
- package/dist/esm/i3s-server/bin/www.js.map +1 -0
- package/dist/esm/i3s-server/controllers/index-controller.js +4 -7
- package/dist/esm/i3s-server/controllers/index-controller.js.map +1 -1
- package/dist/esm/i3s-server/controllers/slpk-controller.js +9 -26
- package/dist/esm/i3s-server/controllers/slpk-controller.js.map +1 -1
- package/dist/esm/i3s-server/routes/index.js +1 -1
- package/dist/esm/i3s-server/routes/index.js.map +1 -1
- package/dist/esm/i3s-server/routes/slpk-router.js +5 -11
- package/dist/esm/i3s-server/routes/slpk-router.js.map +1 -1
- package/dist/esm/i3s-server/utils/create-scene-server.js +2 -5
- package/dist/esm/i3s-server/utils/create-scene-server.js.map +1 -1
- package/dist/esm/i3s-server/utils/server-utils.js +40 -0
- package/dist/esm/i3s-server/utils/server-utils.js.map +1 -0
- package/dist/esm/lib/utils/cli-utils.js +47 -0
- package/dist/esm/lib/utils/cli-utils.js.map +1 -0
- package/dist/esm/lib/utils/compress-util.js +1 -1
- package/dist/esm/lib/utils/compress-util.js.map +1 -1
- package/dist/esm/lib/utils/lod-conversion-utils.js +6 -4
- package/dist/esm/lib/utils/lod-conversion-utils.js.map +1 -1
- package/dist/esm/pgm-loader.js +7 -4
- package/dist/esm/pgm-loader.js.map +1 -1
- package/dist/esm/slpk-extractor/slpk-extractor.js +63 -0
- package/dist/esm/slpk-extractor/slpk-extractor.js.map +1 -0
- package/dist/esm/slpk-extractor-cli.js +74 -0
- package/dist/esm/slpk-extractor-cli.js.map +1 -0
- package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +15 -2
- package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/coordinate-converter.d.ts +1 -2
- package/dist/i3s-converter/helpers/coordinate-converter.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/feature-attributes.d.ts +8 -8
- package/dist/i3s-converter/helpers/feature-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/geometry-converter.d.ts +9 -9
- package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/gltf-attributes.d.ts +3 -3
- package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/load-3d-tiles.d.ts +15 -0
- package/dist/i3s-converter/helpers/load-3d-tiles.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts +4 -5
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts.map +1 -1
- package/dist/i3s-converter/i3s-converter.d.ts +3 -2
- package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
- package/dist/i3s-converter/types.d.ts +48 -7
- package/dist/i3s-converter/types.d.ts.map +1 -1
- package/dist/i3s-server/app.d.ts +1 -2
- package/dist/i3s-server/app.d.ts.map +1 -1
- package/dist/i3s-server/bin/www.d.ts +3 -0
- package/dist/i3s-server/bin/www.d.ts.map +1 -0
- package/dist/i3s-server/controllers/index-controller.d.ts +6 -1
- package/dist/i3s-server/controllers/index-controller.d.ts.map +1 -1
- package/dist/i3s-server/controllers/slpk-controller.d.ts +13 -2
- package/dist/i3s-server/controllers/slpk-controller.d.ts.map +1 -1
- package/dist/i3s-server/routes/index.d.ts +1 -2
- package/dist/i3s-server/routes/index.d.ts.map +1 -1
- package/dist/i3s-server/routes/slpk-router.d.ts +2 -2
- package/dist/i3s-server/routes/slpk-router.d.ts.map +1 -1
- package/dist/i3s-server/utils/create-scene-server.d.ts +11 -5
- package/dist/i3s-server/utils/create-scene-server.d.ts.map +1 -1
- package/dist/i3s-server/utils/server-utils.d.ts +24 -0
- package/dist/i3s-server/utils/server-utils.d.ts.map +1 -0
- package/dist/lib/utils/cli-utils.d.ts +34 -0
- package/dist/lib/utils/cli-utils.d.ts.map +1 -0
- package/dist/lib/utils/lod-conversion-utils.d.ts +2 -2
- package/dist/lib/utils/lod-conversion-utils.d.ts.map +1 -1
- package/dist/pgm-loader.d.ts +9 -2
- package/dist/pgm-loader.d.ts.map +1 -1
- package/dist/slpk-extractor/slpk-extractor.d.ts +23 -0
- package/dist/slpk-extractor/slpk-extractor.d.ts.map +1 -0
- package/dist/slpk-extractor-cli.d.ts +17 -0
- package/dist/slpk-extractor-cli.d.ts.map +1 -0
- package/dist/slpk-extractor.min.js +189 -0
- package/package.json +27 -21
- package/src/3d-tiles-converter/3d-tiles-converter.ts +65 -69
- package/src/3d-tiles-converter/helpers/b3dm-converter.ts +23 -19
- package/src/3d-tiles-converter/helpers/load-i3s.ts +52 -0
- package/src/3d-tiles-converter/helpers/texture-atlas.ts +6 -2
- package/src/converter-cli.ts +16 -74
- package/src/deps-installer/deps-installer.ts +56 -11
- package/src/i3s-converter/helpers/batch-ids-extensions.ts +77 -32
- package/src/i3s-converter/helpers/coordinate-converter.ts +1 -2
- package/src/i3s-converter/helpers/feature-attributes.ts +23 -18
- package/src/i3s-converter/helpers/geometry-attributes.ts +81 -44
- package/src/i3s-converter/helpers/geometry-converter.ts +149 -126
- package/src/i3s-converter/helpers/gltf-attributes.ts +9 -10
- package/src/i3s-converter/helpers/load-3d-tiles.ts +61 -5
- package/src/i3s-converter/helpers/node-index-document.ts +5 -1
- package/src/i3s-converter/helpers/preprocess-3d-tiles.ts +70 -21
- package/src/i3s-converter/i3s-converter.ts +145 -73
- package/src/i3s-converter/types.ts +49 -7
- package/src/i3s-server/README.md +46 -2
- package/src/i3s-server/{app.js → app.ts} +11 -9
- package/src/i3s-server/bin/www.ts +38 -0
- package/src/i3s-server/controllers/{index-controller.js → index-controller.ts} +10 -9
- package/src/i3s-server/controllers/slpk-controller.ts +32 -0
- package/src/i3s-server/routes/{index.js → index.ts} +2 -1
- package/src/i3s-server/routes/{slpk-router.js → slpk-router.ts} +5 -10
- package/src/i3s-server/utils/create-scene-server.ts +20 -0
- package/src/i3s-server/utils/server-utils.ts +70 -0
- package/src/lib/utils/cli-utils.ts +78 -0
- package/src/lib/utils/compress-util.ts +1 -1
- package/src/lib/utils/lod-conversion-utils.ts +10 -6
- package/src/pgm-loader.ts +15 -7
- package/src/slpk-extractor/slpk-extractor.ts +101 -0
- package/src/slpk-extractor-cli.ts +128 -0
- package/dist/3d-tiles-attributes-worker.d.ts +0 -28
- package/dist/3d-tiles-attributes-worker.d.ts.map +0 -1
- package/dist/3d-tiles-attributes-worker.js +0 -3
- package/dist/3d-tiles-attributes-worker.js.map +0 -7
- package/dist/3d-tiles-converter/3d-tiles-converter.js +0 -288
- package/dist/3d-tiles-converter/helpers/b3dm-converter.js +0 -269
- package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +0 -23
- package/dist/3d-tiles-converter/helpers/texture-atlas.js +0 -52
- package/dist/3d-tiles-converter/json-templates/tileset.js +0 -43
- package/dist/bundle.js +0 -5
- package/dist/constants.js +0 -4
- package/dist/converter-cli.js +0 -280
- package/dist/deps-installer/deps-installer.js +0 -63
- package/dist/es5/3d-tiles-attributes-worker.js +0 -25
- package/dist/es5/3d-tiles-attributes-worker.js.map +0 -1
- package/dist/es5/i3s-attributes-worker.js +0 -25
- package/dist/es5/i3s-attributes-worker.js.map +0 -1
- package/dist/es5/i3s-server/bin/www +0 -102
- package/dist/es5/workers/3d-tiles-attributes-worker.js +0 -28
- package/dist/es5/workers/3d-tiles-attributes-worker.js.map +0 -1
- package/dist/es5/workers/i3s-attributes-worker.js +0 -30
- package/dist/es5/workers/i3s-attributes-worker.js.map +0 -1
- package/dist/esm/3d-tiles-attributes-worker.js +0 -16
- package/dist/esm/3d-tiles-attributes-worker.js.map +0 -1
- package/dist/esm/i3s-attributes-worker.js +0 -16
- package/dist/esm/i3s-attributes-worker.js.map +0 -1
- package/dist/esm/i3s-server/bin/www +0 -102
- package/dist/esm/workers/3d-tiles-attributes-worker.js +0 -8
- package/dist/esm/workers/3d-tiles-attributes-worker.js.map +0 -1
- package/dist/esm/workers/i3s-attributes-worker.js +0 -7
- package/dist/esm/workers/i3s-attributes-worker.js.map +0 -1
- package/dist/i3s-attributes-worker.d.ts +0 -45
- package/dist/i3s-attributes-worker.d.ts.map +0 -1
- package/dist/i3s-attributes-worker.js +0 -9
- package/dist/i3s-attributes-worker.js.map +0 -7
- package/dist/i3s-converter/helpers/batch-ids-extensions.js +0 -138
- package/dist/i3s-converter/helpers/coordinate-converter.js +0 -123
- package/dist/i3s-converter/helpers/create-scene-server-path.js +0 -28
- package/dist/i3s-converter/helpers/feature-attributes.js +0 -216
- package/dist/i3s-converter/helpers/geometry-attributes.js +0 -202
- package/dist/i3s-converter/helpers/geometry-converter.js +0 -1225
- package/dist/i3s-converter/helpers/gltf-attributes.js +0 -128
- package/dist/i3s-converter/helpers/load-3d-tiles.js +0 -53
- package/dist/i3s-converter/helpers/node-debug.js +0 -120
- package/dist/i3s-converter/helpers/node-index-document.js +0 -268
- package/dist/i3s-converter/helpers/node-pages.js +0 -316
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.js +0 -76
- package/dist/i3s-converter/helpers/tileset-traversal.js +0 -29
- package/dist/i3s-converter/i3s-converter.js +0 -911
- package/dist/i3s-converter/json-templates/geometry-definitions.js +0 -87
- package/dist/i3s-converter/json-templates/layers.js +0 -139
- package/dist/i3s-converter/json-templates/metadata.js +0 -25
- package/dist/i3s-converter/json-templates/node.js +0 -89
- package/dist/i3s-converter/json-templates/scene-server.js +0 -31
- package/dist/i3s-converter/json-templates/shared-resources.js +0 -129
- package/dist/i3s-converter/json-templates/store.js +0 -103
- package/dist/i3s-converter/types.js +0 -17
- package/dist/i3s-server/app.js +0 -22
- package/dist/i3s-server/controllers/index-controller.js +0 -23
- package/dist/i3s-server/controllers/slpk-controller.js +0 -32
- package/dist/i3s-server/routes/index.js +0 -16
- package/dist/i3s-server/routes/slpk-router.js +0 -33
- package/dist/i3s-server/utils/create-scene-server.js +0 -14
- package/dist/index.js +0 -10
- package/dist/lib/utils/compress-util.js +0 -257
- package/dist/lib/utils/file-utils.js +0 -139
- package/dist/lib/utils/geometry-utils.js +0 -18
- package/dist/lib/utils/lod-conversion-utils.js +0 -76
- package/dist/lib/utils/queue.js +0 -18
- package/dist/lib/utils/statistic-utills.js +0 -64
- package/dist/lib/utils/write-queue.js +0 -80
- package/dist/pgm-loader.js +0 -24
- package/dist/workers/3d-tiles-attributes-worker.d.ts +0 -2
- package/dist/workers/3d-tiles-attributes-worker.d.ts.map +0 -1
- package/dist/workers/3d-tiles-attributes-worker.js +0 -9
- package/dist/workers/i3s-attributes-worker.d.ts +0 -2
- package/dist/workers/i3s-attributes-worker.d.ts.map +0 -1
- package/dist/workers/i3s-attributes-worker.js +0 -5
- package/src/3d-tiles-attributes-worker.ts +0 -43
- package/src/i3s-attributes-worker.ts +0 -59
- package/src/i3s-server/bin/www +0 -102
- package/src/i3s-server/controllers/slpk-controller.js +0 -38
- package/src/i3s-server/utils/create-scene-server.js +0 -15
- package/src/workers/3d-tiles-attributes-worker.ts +0 -6
- package/src/workers/i3s-attributes-worker.ts +0 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature-attributes.js","names":["flattenPropertyTableByFeatureIds","featureIds","propertyTable","resultPropertyTable","propertyName","properties","getPropertiesByFeatureIds","resultProperties","featureId","property","push","checkPropertiesLength","needFlatten","attribute","Object","values","length","STRING_TYPE","SHORT_INT_TYPE","DOUBLE_TYPE","OBJECT_ID_TYPE","getAttributeType","key","Number","isInteger","createdStorageAttribute","attributeIndex","attributeType","storageAttribute","concat","name","ordering","header","valueType","attributeValues","valuesPerElement","setupIdAttribute","setupStringAttribute","setupDoubleAttribute","getFieldAttributeType","createFieldAttribute","fieldAttributeType","type","alias","createPopupInfo","title","mediaInfos","fieldInfos","popupElements","expressionInfos","fieldName","visible","isEditable","label","unshift","encoding","attributeByteCounts"],"sources":["../../../../src/i3s-converter/helpers/feature-attributes.ts"],"sourcesContent":["import type {FeatureTableJson} from '@loaders.gl/3d-tiles';\nimport {\n Attribute,\n AttributeStorageInfo,\n ESRIField,\n Field,\n FieldInfo,\n PopupInfo\n} from '@loaders.gl/i3s';\n\n/**\n * Takes attributes from property table based on featureIds.\n * If there is no property value for particular featureId (index) the property will be null.\n * Example:\n * Initial data:\n * OBJECTID: [0, 1, 5]\n * component: ['Windows', 'Frames', 'Wall', 'Roof', 'Skylight']\n * Result:\n * OBJECTID: [0, 1, 5]\n * component: ['Windows', 'Frames', 'null']\n * @param featureIds\n * @param propertyTable\n */\nexport function flattenPropertyTableByFeatureIds(\n featureIds: number[],\n propertyTable: FeatureTableJson\n): FeatureTableJson {\n const resultPropertyTable: FeatureTableJson = {};\n for (const propertyName in propertyTable) {\n const properties = propertyTable[propertyName];\n resultPropertyTable[propertyName] = getPropertiesByFeatureIds(properties, featureIds);\n }\n\n return resultPropertyTable;\n}\n\n/**\n * Getting properties by featureId index\n * @param properties\n * @param featureIds\n */\nfunction getPropertiesByFeatureIds(properties: any[], featureIds: number[]): any[] {\n const resultProperties: any = [];\n\n for (const featureId of featureIds) {\n const property = properties[featureId] || null;\n resultProperties.push(property);\n }\n\n return resultProperties;\n}\n\n/**\n * Check that all attributes in propertyTable have the same length as FeatureIds.\n * If there are differencies between lengths we should flatten property table based on exiesting featureIds.\n * @param featureIds\n * @param propertyTable\n * @returns\n */\nexport function checkPropertiesLength(\n featureIds: number[],\n propertyTable: FeatureTableJson\n): boolean {\n let needFlatten = false;\n\n for (const attribute of Object.values(propertyTable)) {\n if (featureIds.length !== attribute.length) {\n needFlatten = true;\n }\n }\n\n return needFlatten;\n}\n\n/** String data type name for feature attributes */\nconst STRING_TYPE = 'string';\n/** Integer data type name for feature attributes */\nconst SHORT_INT_TYPE = 'Int32';\n/** Double data type name for feature attributes */\nconst DOUBLE_TYPE = 'double';\n/** Type of attribute that is linked with feature ids */\nconst OBJECT_ID_TYPE = 'OBJECTID';\n/**\n * Get the attribute type for attributeStorageInfo https://github.com/Esri/i3s-spec/blob/master/docs/1.7/attributeStorageInfo.cmn.md\n * @param key - attribute's key\n * @param attribute - attribute's type in propertyTable\n */\nexport function getAttributeType(key: string, attribute: string): string {\n if (key === OBJECT_ID_TYPE) {\n return OBJECT_ID_TYPE;\n }\n if (typeof attribute === STRING_TYPE) {\n return STRING_TYPE;\n } else if (typeof attribute === 'number') {\n return Number.isInteger(attribute) ? SHORT_INT_TYPE : DOUBLE_TYPE;\n }\n return STRING_TYPE;\n}\n\n/**\n * Generate storage attribute for map segmentation.\n * @param attributeIndex - order index of attribute (f_0, f_1 ...).\n * @param key - attribute key from propertyTable.\n * @param attributeType - attribute type.\n * @return Updated storageAttribute.\n */\nexport function createdStorageAttribute(\n attributeIndex: number,\n key: string,\n attributeType: Attribute\n): AttributeStorageInfo {\n const storageAttribute = {\n key: `f_${attributeIndex}`,\n name: key,\n ordering: ['attributeValues'],\n header: [{property: 'count', valueType: 'UInt32'}],\n attributeValues: {valueType: 'Int32', valuesPerElement: 1}\n };\n\n switch (attributeType) {\n case OBJECT_ID_TYPE:\n setupIdAttribute(storageAttribute);\n break;\n case STRING_TYPE:\n setupStringAttribute(storageAttribute);\n break;\n case DOUBLE_TYPE:\n setupDoubleAttribute(storageAttribute);\n break;\n case SHORT_INT_TYPE:\n break;\n default:\n setupStringAttribute(storageAttribute);\n }\n\n return storageAttribute;\n}\n\n/**\n * Find and return attribute type based on key form propertyTable.\n * @param attributeType\n */\nexport function getFieldAttributeType(attributeType: Attribute): ESRIField {\n switch (attributeType) {\n case OBJECT_ID_TYPE:\n return 'esriFieldTypeOID';\n case STRING_TYPE:\n return 'esriFieldTypeString';\n case SHORT_INT_TYPE:\n return 'esriFieldTypeInteger';\n case DOUBLE_TYPE:\n return 'esriFieldTypeDouble';\n default:\n return 'esriFieldTypeString';\n }\n}\n\n/**\n * Setup field attribute for map segmentation.\n * @param key - attribute for map segmentation.\n * @param fieldAttributeType - esri attribute type ('esriFieldTypeString' or 'esriFieldTypeOID').\n */\nexport function createFieldAttribute(key: string, fieldAttributeType: ESRIField): Field {\n return {\n name: key,\n type: fieldAttributeType,\n alias: key\n };\n}\n\n/**\n * Generate popup info to show metadata on the map.\n * @param propertyTable - table data with OBJECTID.\n * @return data for correct rendering of popup.\n */\nexport function createPopupInfo(propertyTable: FeatureTableJson): PopupInfo {\n const title = '{OBJECTID}';\n const mediaInfos = [];\n const fieldInfos: FieldInfo[] = [];\n const popupElements: {\n fieldInfos: FieldInfo[];\n type: string;\n }[] = [];\n const expressionInfos = [];\n\n for (const key in propertyTable) {\n fieldInfos.push({\n fieldName: key,\n visible: true,\n isEditable: false,\n label: key\n });\n }\n popupElements.push({\n fieldInfos,\n type: 'fields'\n });\n\n return {\n title,\n mediaInfos,\n popupElements,\n fieldInfos,\n expressionInfos\n };\n}\n\n/**\n * Setup storage attribute as string.\n * @param storageAttribute - attribute for map segmentation.\n */\nfunction setupStringAttribute(storageAttribute: AttributeStorageInfo): void {\n // @ts-expect-error\n storageAttribute.ordering.unshift('attributeByteCounts');\n storageAttribute.header.push({property: 'attributeValuesByteCount', valueType: 'UInt32'});\n storageAttribute.attributeValues = {\n valueType: 'String',\n encoding: 'UTF-8',\n valuesPerElement: 1\n };\n storageAttribute.attributeByteCounts = {\n valueType: 'UInt32',\n valuesPerElement: 1\n };\n}\n\n/**\n * Setup Id attribute for map segmentation.\n * @param storageAttribute - attribute for map segmentation .\n */\nfunction setupIdAttribute(storageAttribute: AttributeStorageInfo): void {\n storageAttribute.attributeValues = {\n valueType: 'Oid32',\n valuesPerElement: 1\n };\n}\n\n/**\n * Setup double attribute for map segmentation.\n * @param storageAttribute - attribute for map segmentation .\n */\nfunction setupDoubleAttribute(storageAttribute: AttributeStorageInfo): void {\n storageAttribute.attributeValues = {\n valueType: 'Float64',\n valuesPerElement: 1\n };\n}\n"],"mappings":"AAuBA,OAAO,SAASA,gCAAgCA,CAC9CC,UAAoB,EACpBC,aAA+B,EACb;EAClB,MAAMC,mBAAqC,GAAG,CAAC,CAAC;EAChD,KAAK,MAAMC,YAAY,IAAIF,aAAa,EAAE;IACxC,MAAMG,UAAU,GAAGH,aAAa,CAACE,YAAY,CAAC;IAC9CD,mBAAmB,CAACC,YAAY,CAAC,GAAGE,yBAAyB,CAACD,UAAU,EAAEJ,UAAU,CAAC;EACvF;EAEA,OAAOE,mBAAmB;AAC5B;AAOA,SAASG,yBAAyBA,CAACD,UAAiB,EAAEJ,UAAoB,EAAS;EACjF,MAAMM,gBAAqB,GAAG,EAAE;EAEhC,KAAK,MAAMC,SAAS,IAAIP,UAAU,EAAE;IAClC,MAAMQ,QAAQ,GAAGJ,UAAU,CAACG,SAAS,CAAC,IAAI,IAAI;IAC9CD,gBAAgB,CAACG,IAAI,CAACD,QAAQ,CAAC;EACjC;EAEA,OAAOF,gBAAgB;AACzB;AASA,OAAO,SAASI,qBAAqBA,CACnCV,UAAoB,EACpBC,aAA+B,EACtB;EACT,IAAI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ACG,QAAQ,CAACuB,OAAO,CAAC,qBAAqB,CAAC;EACxD1B,gBAAgB,CAACI,MAAM,CAACtB,IAAI,CAAC;IAACD,QAAQ,EAAE,0BAA0B;IAAEwB,SAAS,EAAE;EAAQ,CAAC,CAAC;EACzFL,gBAAgB,CAACM,eAAe,GAAG;IACjCD,SAAS,EAAE,QAAQ;IACnBsB,QAAQ,EAAE,OAAO;IACjBpB,gBAAgB,EAAE;EACpB,CAAC;EACDP,gBAAgB,CAAC4B,mBAAmB,GAAG;IACrCvB,SAAS,EAAE,QAAQ;IACnBE,gBAAgB,EAAE;EACpB,CAAC;AACH;AAMA,SAASC,gBAAgBA,CAACR,gBAAsC,EAAQ;EACtEA,gBAAgB,CAACM,eAAe,GAAG;IACjCD,SAAS,EAAE,OAAO;IAClBE,gBAAgB,EAAE;EACpB,CAAC;AACH;AAMA,SAASG,oBAAoBA,CAACV,gBAAsC,EAAQ;EAC1EA,gBAAgB,CAACM,eAAe,GAAG;IACjCD,SAAS,EAAE,SAAS;IACpBE,gBAAgB,EAAE;EACpB,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"feature-attributes.js","names":["flattenPropertyTableByFeatureIds","featureIdsMap","propertyTable","resultPropertyTable","propertyName","properties","getPropertiesByFeatureIds","resultProperties","featureIdKey","property","push","checkPropertiesLength","featureIds","needFlatten","attribute","Object","values","length","STRING_TYPE","SHORT_INT_TYPE","DOUBLE_TYPE","OBJECT_ID_TYPE","getAttributeType","key","Number","isInteger","createdStorageAttribute","attributeIndex","attributeType","storageAttribute","concat","name","ordering","header","valueType","attributeValues","valuesPerElement","setupIdAttribute","setupStringAttribute","setupDoubleAttribute","getFieldAttributeType","createFieldAttribute","fieldAttributeType","type","alias","createPopupInfo","title","mediaInfos","fieldInfos","popupElements","expressionInfos","fieldName","visible","isEditable","label","unshift","encoding","attributeByteCounts"],"sources":["../../../../src/i3s-converter/helpers/feature-attributes.ts"],"sourcesContent":["import type {FeatureTableJson} from '@loaders.gl/3d-tiles';\nimport {\n Attribute,\n AttributeStorageInfo,\n ESRIField,\n Field,\n FieldInfo,\n PopupInfo\n} from '@loaders.gl/i3s';\n\n/**\n * Takes attributes from property table based on featureIdsMap.\n * If there is no property value for particular featureId (index) the property will be null.\n * Example:\n * Initial data:\n * OBJECTID: {0: 0, 3: 33, 4: 333}\n * component: ['Windows', 'Frames', 'Wall', 'Roof', 'Skylight']\n * Result:\n * OBJECTID: [0, 33, 333]\n * component: ['Windows', 'Roof', 'Skylight']\n * @param featureIdsMap\n * @param propertyTable\n */\nexport function flattenPropertyTableByFeatureIds(\n featureIdsMap: Record<string, number>,\n propertyTable: FeatureTableJson\n): FeatureTableJson {\n const resultPropertyTable: FeatureTableJson = {};\n for (const propertyName in propertyTable) {\n const properties = propertyTable[propertyName];\n resultPropertyTable[propertyName] = getPropertiesByFeatureIds(properties, featureIdsMap);\n }\n\n return resultPropertyTable;\n}\n\n/**\n * Getting properties by featureId index\n * @param properties\n * @param featureIdsMap\n */\nfunction getPropertiesByFeatureIds(\n properties: unknown[],\n featureIdsMap: Record<string, number>\n): unknown[] {\n const resultProperties: unknown[] = [];\n\n if (properties) {\n for (const featureIdKey in featureIdsMap) {\n const property = properties[featureIdKey] || null;\n resultProperties.push(property);\n }\n }\n\n return resultProperties;\n}\n\n/**\n * Check that all attributes in propertyTable have the same length as FeatureIds.\n * If there are differencies between lengths we should flatten property table based on exiesting featureIds.\n * @param featureIds\n * @param propertyTable\n * @returns\n */\nexport function checkPropertiesLength(\n featureIds: number[],\n propertyTable: FeatureTableJson\n): boolean {\n let needFlatten = false;\n\n for (const attribute of Object.values(propertyTable)) {\n if (!featureIds || !attribute || featureIds.length !== attribute.length) {\n needFlatten = true;\n }\n }\n\n return needFlatten;\n}\n\n/** String data type name for feature attributes */\nconst STRING_TYPE = 'string';\n/** Integer data type name for feature attributes */\nconst SHORT_INT_TYPE = 'Int32';\n/** Double data type name for feature attributes */\nconst DOUBLE_TYPE = 'double';\n/** Type of attribute that is linked with feature ids */\nconst OBJECT_ID_TYPE = 'OBJECTID';\n/**\n * Get the attribute type for attributeStorageInfo https://github.com/Esri/i3s-spec/blob/master/docs/1.7/attributeStorageInfo.cmn.md\n * @param key - attribute's key\n * @param attribute - attribute taken from propertyTable\n */\nexport function getAttributeType(key: string, attribute: unknown): string {\n if (key === OBJECT_ID_TYPE) {\n return OBJECT_ID_TYPE;\n }\n if (typeof attribute === STRING_TYPE || typeof attribute === 'bigint') {\n return STRING_TYPE;\n } else if (typeof attribute === 'number') {\n return Number.isInteger(attribute) ? SHORT_INT_TYPE : DOUBLE_TYPE;\n }\n return STRING_TYPE;\n}\n\n/**\n * Generate storage attribute for map segmentation.\n * @param attributeIndex - order index of attribute (f_0, f_1 ...).\n * @param key - attribute key from propertyTable.\n * @param attributeType - attribute type.\n * @return Updated storageAttribute.\n */\nexport function createdStorageAttribute(\n attributeIndex: number,\n key: string,\n attributeType: Attribute\n): AttributeStorageInfo {\n const storageAttribute = {\n key: `f_${attributeIndex}`,\n name: key,\n ordering: ['attributeValues'],\n header: [{property: 'count', valueType: 'UInt32'}],\n attributeValues: {valueType: 'Int32', valuesPerElement: 1}\n };\n\n switch (attributeType) {\n case OBJECT_ID_TYPE:\n setupIdAttribute(storageAttribute);\n break;\n case STRING_TYPE:\n setupStringAttribute(storageAttribute);\n break;\n case DOUBLE_TYPE:\n setupDoubleAttribute(storageAttribute);\n break;\n case SHORT_INT_TYPE:\n break;\n default:\n setupStringAttribute(storageAttribute);\n }\n\n return storageAttribute;\n}\n\n/**\n * Find and return attribute type based on key form propertyTable.\n * @param attributeType\n */\nexport function getFieldAttributeType(attributeType: Attribute): ESRIField {\n switch (attributeType) {\n case OBJECT_ID_TYPE:\n return 'esriFieldTypeOID';\n case STRING_TYPE:\n return 'esriFieldTypeString';\n case SHORT_INT_TYPE:\n return 'esriFieldTypeInteger';\n case DOUBLE_TYPE:\n return 'esriFieldTypeDouble';\n default:\n return 'esriFieldTypeString';\n }\n}\n\n/**\n * Setup field attribute for map segmentation.\n * @param key - attribute for map segmentation.\n * @param fieldAttributeType - esri attribute type ('esriFieldTypeString' or 'esriFieldTypeOID').\n */\nexport function createFieldAttribute(key: string, fieldAttributeType: ESRIField): Field {\n return {\n name: key,\n type: fieldAttributeType,\n alias: key\n };\n}\n\n/**\n * Generate popup info to show metadata on the map.\n * @param propertyTable - table data with OBJECTID.\n * @return data for correct rendering of popup.\n */\nexport function createPopupInfo(propertyTable: FeatureTableJson): PopupInfo {\n const title = '{OBJECTID}';\n const mediaInfos = [];\n const fieldInfos: FieldInfo[] = [];\n const popupElements: {\n fieldInfos: FieldInfo[];\n type: string;\n }[] = [];\n const expressionInfos = [];\n\n for (const key in propertyTable) {\n fieldInfos.push({\n fieldName: key,\n visible: true,\n isEditable: false,\n label: key\n });\n }\n popupElements.push({\n fieldInfos,\n type: 'fields'\n });\n\n return {\n title,\n mediaInfos,\n popupElements,\n fieldInfos,\n expressionInfos\n };\n}\n\n/**\n * Setup storage attribute as string.\n * @param storageAttribute - attribute for map segmentation.\n */\nfunction setupStringAttribute(storageAttribute: AttributeStorageInfo): void {\n // @ts-expect-error\n storageAttribute.ordering.unshift('attributeByteCounts');\n storageAttribute.header.push({property: 'attributeValuesByteCount', valueType: 'UInt32'});\n storageAttribute.attributeValues = {\n valueType: 'String',\n encoding: 'UTF-8',\n valuesPerElement: 1\n };\n storageAttribute.attributeByteCounts = {\n valueType: 'UInt32',\n valuesPerElement: 1\n };\n}\n\n/**\n * Setup Id attribute for map segmentation.\n * @param storageAttribute - attribute for map segmentation .\n */\nfunction setupIdAttribute(storageAttribute: AttributeStorageInfo): void {\n storageAttribute.attributeValues = {\n valueType: 'Oid32',\n valuesPerElement: 1\n };\n}\n\n/**\n * Setup double attribute for map segmentation.\n * @param storageAttribute - attribute for map segmentation .\n */\nfunction setupDoubleAttribute(storageAttribute: AttributeStorageInfo): void {\n storageAttribute.attributeValues = {\n valueType: 'Float64',\n valuesPerElement: 1\n };\n}\n"],"mappings":"AAuBA,OAA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AAS,EAAE,OAAO;IAClBE,gBAAgB,EAAE;EACpB,CAAC;AACH;AAMA,SAASG,oBAAoBA,CAACV,gBAAsC,EAAQ;EAC1EA,gBAAgB,CAACM,eAAe,GAAG;IACjCD,SAAS,EAAE,SAAS;IACpBE,gBAAgB,EAAE;EACpB,CAAC;AACH"}
|
|
@@ -91,6 +91,11 @@ function makeAttributeObjects(attributes) {
|
|
|
91
91
|
let colorsList = new Uint8Array(colors);
|
|
92
92
|
let texCoordsList = new Float32Array(texCoords);
|
|
93
93
|
let uvRegionsList = new Uint16Array(uvRegions);
|
|
94
|
+
let positionsOffset = 0;
|
|
95
|
+
let normalsOffset = 0;
|
|
96
|
+
let colorsOffset = 0;
|
|
97
|
+
let uvRegionsOffset = 0;
|
|
98
|
+
let texCoordsOffset = 0;
|
|
94
99
|
for (let index = 0; index < featureIds.length; index++) {
|
|
95
100
|
const startIndex = faceRange[index * 2];
|
|
96
101
|
const endIndex = faceRange[index * 2 + 1];
|
|
@@ -101,19 +106,19 @@ function makeAttributeObjects(attributes) {
|
|
|
101
106
|
const texCoordsCount = getSliceAttributeCount('texCoords', startIndex, endIndex);
|
|
102
107
|
groupedData.push({
|
|
103
108
|
featureId: featureIds[index],
|
|
104
|
-
positions: positionsList.
|
|
105
|
-
normals: normalsList.
|
|
106
|
-
colors: colorsList.
|
|
107
|
-
uvRegions: uvRegionsList.
|
|
108
|
-
texCoords: texCoordsList.
|
|
109
|
+
positions: positionsList.subarray(positionsOffset, positionsOffset + positionsCount),
|
|
110
|
+
normals: normalsList.subarray(normalsOffset, normalsOffset + normalsCount),
|
|
111
|
+
colors: colorsList.subarray(colorsOffset, colorsOffset + colorsCount),
|
|
112
|
+
uvRegions: uvRegionsList.subarray(uvRegionsOffset, uvRegionsOffset + uvRegionsCount),
|
|
113
|
+
texCoords: texCoordsList.subarray(texCoordsOffset, texCoordsOffset + texCoordsCount)
|
|
109
114
|
});
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
+
positionsOffset += positionsCount;
|
|
116
|
+
normalsOffset += normalsCount;
|
|
117
|
+
colorsOffset += colorsCount;
|
|
118
|
+
uvRegionsOffset += uvRegionsCount;
|
|
119
|
+
texCoordsOffset += texCoordsCount;
|
|
115
120
|
}
|
|
116
|
-
return groupedData
|
|
121
|
+
return groupedData;
|
|
117
122
|
}
|
|
118
123
|
function getSliceAttributeCount(attributeName, startIndex, endIndex) {
|
|
119
124
|
const itemsPerVertex4 = 4;
|
|
@@ -134,57 +139,95 @@ function getSliceAttributeCount(attributeName, startIndex, endIndex) {
|
|
|
134
139
|
}
|
|
135
140
|
}
|
|
136
141
|
function unifyObjectsByFeatureId(sortedData) {
|
|
137
|
-
const
|
|
138
|
-
for (
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
existedObject.positions = concatenateTypedArrays(existedObject.positions, currentObject.positions);
|
|
143
|
-
existedObject.normals = concatenateTypedArrays(existedObject.normals, currentObject.normals);
|
|
144
|
-
existedObject.colors = concatenateTypedArrays(existedObject.colors, currentObject.colors);
|
|
145
|
-
existedObject.texCoords = concatenateTypedArrays(existedObject.texCoords, currentObject.texCoords);
|
|
142
|
+
const groupedMetadata = [];
|
|
143
|
+
for (const data of sortedData) {
|
|
144
|
+
const existingObject = groupedMetadata.find(obj => obj.featureId === data.featureId);
|
|
145
|
+
if (existingObject) {
|
|
146
|
+
existingObject.attributes.push(data);
|
|
146
147
|
} else {
|
|
147
|
-
|
|
148
|
+
groupedMetadata.push({
|
|
149
|
+
featureId: data.featureId,
|
|
150
|
+
attributes: [data]
|
|
151
|
+
});
|
|
148
152
|
}
|
|
149
153
|
}
|
|
154
|
+
const uniqueObjects = [];
|
|
155
|
+
for (const metatada of groupedMetadata) {
|
|
156
|
+
const attributes = concatenateAttributes(metatada.attributes);
|
|
157
|
+
uniqueObjects.push({
|
|
158
|
+
featureId: metatada.featureId,
|
|
159
|
+
...attributes
|
|
160
|
+
});
|
|
161
|
+
}
|
|
150
162
|
return uniqueObjects;
|
|
151
163
|
}
|
|
152
164
|
function groupAttributesAndRangesByFeatureId(unifiedObjects, featureCount) {
|
|
153
165
|
const firstAttributeObject = unifiedObjects[0];
|
|
154
166
|
const featureIds = [firstAttributeObject.featureId || 0];
|
|
155
|
-
let positions = new Float32Array(firstAttributeObject.positions);
|
|
156
|
-
let normals = new Float32Array(firstAttributeObject.normals);
|
|
157
|
-
let colors = new Uint8Array(firstAttributeObject.colors);
|
|
158
|
-
let uvRegions = new Uint16Array(firstAttributeObject.uvRegions);
|
|
159
|
-
let texCoords = new Float32Array(firstAttributeObject.texCoords);
|
|
160
167
|
const range = [0];
|
|
161
168
|
let objIndex = 0;
|
|
162
169
|
let sum = 0;
|
|
163
170
|
for (let index = 1; index < unifiedObjects.length; index++) {
|
|
164
171
|
const currentAttributesObject = unifiedObjects[index];
|
|
165
172
|
featureIds.push(currentAttributesObject.featureId || 0);
|
|
166
|
-
positions = concatenateTypedArrays(positions, currentAttributesObject.positions);
|
|
167
|
-
normals = concatenateTypedArrays(normals, currentAttributesObject.normals);
|
|
168
|
-
colors = concatenateTypedArrays(colors, currentAttributesObject.colors);
|
|
169
|
-
uvRegions = concatenateTypedArrays(uvRegions, currentAttributesObject.uvRegions);
|
|
170
|
-
texCoords = concatenateTypedArrays(texCoords, currentAttributesObject.texCoords);
|
|
171
173
|
const groupedObject = unifiedObjects[objIndex];
|
|
172
174
|
range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1 + sum);
|
|
173
175
|
range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE + sum);
|
|
174
176
|
sum += groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE;
|
|
175
177
|
objIndex += 1;
|
|
176
178
|
}
|
|
177
|
-
|
|
179
|
+
const attributes = concatenateAttributes(unifiedObjects);
|
|
180
|
+
range.push(attributes.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1);
|
|
178
181
|
const faceRange = new Uint32Array(range);
|
|
179
182
|
return {
|
|
180
183
|
faceRange,
|
|
181
184
|
featureIds,
|
|
185
|
+
featureCount,
|
|
186
|
+
...attributes
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function concatenateAttributes(attributes) {
|
|
190
|
+
const positionGroups = attributes.map(_ref => {
|
|
191
|
+
let {
|
|
192
|
+
positions
|
|
193
|
+
} = _ref;
|
|
194
|
+
return positions;
|
|
195
|
+
});
|
|
196
|
+
const positions = positionGroups.length > 1 ? concatenateTypedArrays(...positionGroups) : positionGroups[0];
|
|
197
|
+
const normalGroups = attributes.map(_ref2 => {
|
|
198
|
+
let {
|
|
199
|
+
normals
|
|
200
|
+
} = _ref2;
|
|
201
|
+
return normals;
|
|
202
|
+
});
|
|
203
|
+
const normals = normalGroups.length > 1 ? concatenateTypedArrays(...normalGroups) : normalGroups[0];
|
|
204
|
+
const colorGroups = attributes.map(_ref3 => {
|
|
205
|
+
let {
|
|
206
|
+
colors
|
|
207
|
+
} = _ref3;
|
|
208
|
+
return colors;
|
|
209
|
+
});
|
|
210
|
+
const colors = colorGroups.length > 1 ? concatenateTypedArrays(...colorGroups) : colorGroups[0];
|
|
211
|
+
const texCoordGroups = attributes.map(_ref4 => {
|
|
212
|
+
let {
|
|
213
|
+
texCoords
|
|
214
|
+
} = _ref4;
|
|
215
|
+
return texCoords;
|
|
216
|
+
});
|
|
217
|
+
const texCoords = texCoordGroups.length > 1 ? concatenateTypedArrays(...texCoordGroups) : texCoordGroups[0];
|
|
218
|
+
const uvRegionGroups = attributes.map(_ref5 => {
|
|
219
|
+
let {
|
|
220
|
+
uvRegions
|
|
221
|
+
} = _ref5;
|
|
222
|
+
return uvRegions;
|
|
223
|
+
});
|
|
224
|
+
const uvRegions = uvRegionGroups.length > 1 ? concatenateTypedArrays(...uvRegionGroups) : uvRegionGroups[0];
|
|
225
|
+
return {
|
|
182
226
|
positions,
|
|
183
227
|
normals,
|
|
184
228
|
colors,
|
|
185
|
-
uvRegions,
|
|
186
229
|
texCoords,
|
|
187
|
-
|
|
230
|
+
uvRegions
|
|
188
231
|
};
|
|
189
232
|
}
|
|
190
233
|
//# sourceMappingURL=geometry-attributes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geometry-attributes.js","names":["concatenateTypedArrays","VALUES_PER_VERTEX","POSITIONS_AND_NORMALS_PER_TRIANGLE","generateAttributes","attributes","positions","normals","texCoords","colors","uvRegions","featureIndices","triangleCount","length","faceRange","Uint32Array","featureIds","featureCount","data","calculateFaceRangesAndFeaturesCount","attributeObjects","makeAttributeObjects","unifiedAttributeObjectsByFeatureIds","unifyObjectsByFeatureId","groupedAttributes","groupAttributesAndRangesByFeatureId","rangeIndex","featureIndex","currentFeatureId","getFrequentValue","slice","faceRangeList","uniqueFeatureIds","index","newFeatureId","includes","push","values","map","mostFrequentValue","maxCount","value","groupedData","positionsList","Float32Array","normalsList","colorsList","Uint8Array","texCoordsList","uvRegionsList","Uint16Array","startIndex","endIndex","positionsCount","getSliceAttributeCount","normalsCount","colorsCount","uvRegionsCount","texCoordsCount","featureId","sort","first","second","attributeName","itemsPerVertex4","texCoordsPerVertex","trianglesCount","vertexCount","sortedData","uniqueObjects","currentObject","existedObject","find","obj","unifiedObjects","firstAttributeObject","range","objIndex","sum","currentAttributesObject","groupedObject"],"sources":["../../../../src/i3s-converter/helpers/geometry-attributes.ts"],"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, uvRegions, 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 uvRegions\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 = getFrequentValue(featureIndices.slice(0, VALUES_PER_VERTEX));\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 = VALUES_PER_VERTEX; index < featureIndices.length; index += VALUES_PER_VERTEX) {\n const newFeatureId = getFrequentValue(featureIndices.slice(index, index + VALUES_PER_VERTEX));\n if (currentFeatureId !== newFeatureId) {\n faceRangeList[rangeIndex] = index / VALUES_PER_VERTEX - 1;\n faceRangeList[rangeIndex + 1] = index / VALUES_PER_VERTEX;\n featureIds[featureIndex] = newFeatureId;\n\n if (!uniqueFeatureIds.includes(newFeatureId)) {\n uniqueFeatureIds.push(newFeatureId);\n }\n\n rangeIndex += 2;\n featureIndex += 1;\n }\n currentFeatureId = newFeatureId;\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 * Find most frequent value to avoid situation where one vertex can be part of multiple features (objects).\n * @param values\n */\nfunction getFrequentValue(values: number[]): number {\n const map: {[key: number]: number} = {};\n\n let mostFrequentValue = values[0];\n let maxCount = 1;\n\n for (const value of values) {\n // Save item and it's frequency count to the map.\n map[value] = (map[value] || 0) + 1;\n // Find max count of frequency.\n maxCount = maxCount > map[value] ? maxCount : map[value];\n // Find the most frequent value.\n mostFrequentValue = maxCount > map[value] ? mostFrequentValue : value;\n }\n\n return mostFrequentValue;\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 uvRegions,\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 let uvRegionsList = new Uint16Array(uvRegions);\n\n for (let index = 0; index < featureIds.length; index++) {\n const startIndex = faceRange[index * 2];\n const endIndex = faceRange[index * 2 + 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 uvRegionsCount = getSliceAttributeCount('uvRegions', 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 uvRegions: uvRegionsList.slice(0, uvRegionsCount),\n texCoords: texCoordsList.slice(0, texCoordsCount)\n });\n\n positionsList = positionsList.slice(positionsCount);\n normalsList = normalsList.slice(normalsCount);\n colorsList = colorsList.slice(colorsCount);\n uvRegionsList = uvRegionsList.slice(uvRegionsCount);\n texCoordsList = texCoordsList.slice(texCoordsCount);\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 itemsPerVertex4 = 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 case 'uvRegions':\n return vertexCount * itemsPerVertex4;\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 uvRegions = new Uint16Array(firstAttributeObject.uvRegions);\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 uvRegions = concatenateTypedArrays(uvRegions, currentAttributesObject.uvRegions);\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, uvRegions, texCoords, featureCount};\n}\n"],"mappings":"AACA,SAAQA,sBAAsB,QAAO,0BAA0B;AAE/D,MAAMC,iBAAiB,GAAG,CAAC;AAC3B,MAAMC,kCAAkC,GAAG,CAAC;AAO5C,OAAO,SAASC,kBAAkBA,CAACC,UAA+B,EAAsB;EACtF,MAAM;IAACC,SAAS;IAAEC,OAAO;IAAEC,SAAS;IAAEC,MAAM;IAAEC,SAAS;IAAEC;EAAc,CAAC,GAAGN,UAAU;EACrF,MAAMO,aAAa,GAAGN,SAAS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CAAC4C,aAAa,CAAC1E,SAAS,CAACO,MAAM,GAAGV,kCAAkC,GAAG,CAAC,GAAG2E,GAAG,CAAC;IACzFF,KAAK,CAACxC,IAAI,CAAC4C,aAAa,CAAC1E,SAAS,CAACO,MAAM,GAAGV,kCAAkC,GAAG2E,GAAG,CAAC;IAErFA,GAAG,IAAIE,aAAa,CAAC1E,SAAS,CAACO,MAAM,GAAGV,kCAAkC;IAC1E0E,QAAQ,IAAI,CAAC;EACf;EAEAD,KAAK,CAACxC,IAAI,CAAC9B,SAAS,CAACO,MAAM,GAAGV,kCAAkC,GAAG,CAAC,CAAC;EAErE,MAAMW,SAAS,GAAG,IAAIC,WAAW,CAAC6D,KAAK,CAAC;EACxC,OAAO;IAAC9D,SAAS;IAAEE,UAAU;IAAEV,SAAS;IAAEC,OAAO;IAAEE,MAAM;IAAEC,SAAS;IAAEF,SAAS;IAAES;EAAY,CAAC;AAChG"}
|
|
1
|
+
{"version":3,"file":"geometry-attributes.js","names":["concatenateTypedArrays","VALUES_PER_VERTEX","POSITIONS_AND_NORMALS_PER_TRIANGLE","generateAttributes","attributes","positions","normals","texCoords","colors","uvRegions","featureIndices","triangleCount","length","faceRange","Uint32Array","featureIds","featureCount","data","calculateFaceRangesAndFeaturesCount","attributeObjects","makeAttributeObjects","unifiedAttributeObjectsByFeatureIds","unifyObjectsByFeatureId","groupedAttributes","groupAttributesAndRangesByFeatureId","rangeIndex","featureIndex","currentFeatureId","getFrequentValue","slice","faceRangeList","uniqueFeatureIds","index","newFeatureId","includes","push","values","map","mostFrequentValue","maxCount","value","groupedData","positionsList","Float32Array","normalsList","colorsList","Uint8Array","texCoordsList","uvRegionsList","Uint16Array","positionsOffset","normalsOffset","colorsOffset","uvRegionsOffset","texCoordsOffset","startIndex","endIndex","positionsCount","getSliceAttributeCount","normalsCount","colorsCount","uvRegionsCount","texCoordsCount","featureId","subarray","attributeName","itemsPerVertex4","texCoordsPerVertex","trianglesCount","vertexCount","sortedData","groupedMetadata","existingObject","find","obj","uniqueObjects","metatada","concatenateAttributes","unifiedObjects","firstAttributeObject","range","objIndex","sum","currentAttributesObject","groupedObject","positionGroups","_ref","normalGroups","_ref2","colorGroups","_ref3","texCoordGroups","_ref4","uvRegionGroups","_ref5"],"sources":["../../../../src/i3s-converter/helpers/geometry-attributes.ts"],"sourcesContent":["import type {\n GeometryAttributes,\n ConvertedAttributes,\n GroupedByFeatureIdAttributes,\n GroupedAttributes\n} 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, uvRegions, 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 uvRegions\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 = getFrequentValue(featureIndices.slice(0, VALUES_PER_VERTEX));\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 = VALUES_PER_VERTEX; index < featureIndices.length; index += VALUES_PER_VERTEX) {\n const newFeatureId = getFrequentValue(featureIndices.slice(index, index + VALUES_PER_VERTEX));\n if (currentFeatureId !== newFeatureId) {\n faceRangeList[rangeIndex] = index / VALUES_PER_VERTEX - 1;\n faceRangeList[rangeIndex + 1] = index / VALUES_PER_VERTEX;\n featureIds[featureIndex] = newFeatureId;\n\n if (!uniqueFeatureIds.includes(newFeatureId)) {\n uniqueFeatureIds.push(newFeatureId);\n }\n\n rangeIndex += 2;\n featureIndex += 1;\n }\n currentFeatureId = newFeatureId;\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 * Find most frequent value to avoid situation where one vertex can be part of multiple features (objects).\n * @param values\n */\nfunction getFrequentValue(values: number[]): number {\n const map: {[key: number]: number} = {};\n\n let mostFrequentValue = values[0];\n let maxCount = 1;\n\n for (const value of values) {\n // Save item and it's frequency count to the map.\n map[value] = (map[value] || 0) + 1;\n // Find max count of frequency.\n maxCount = maxCount > map[value] ? maxCount : map[value];\n // Find the most frequent value.\n mostFrequentValue = maxCount > map[value] ? mostFrequentValue : value;\n }\n\n return mostFrequentValue;\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 uvRegions,\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 let uvRegionsList = new Uint16Array(uvRegions);\n let positionsOffset = 0;\n let normalsOffset = 0;\n let colorsOffset = 0;\n let uvRegionsOffset = 0;\n let texCoordsOffset = 0;\n\n for (let index = 0; index < featureIds.length; index++) {\n const startIndex = faceRange[index * 2];\n const endIndex = faceRange[index * 2 + 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 uvRegionsCount = getSliceAttributeCount('uvRegions', startIndex, endIndex);\n const texCoordsCount = getSliceAttributeCount('texCoords', startIndex, endIndex);\n\n groupedData.push({\n featureId: featureIds[index],\n positions: positionsList.subarray(positionsOffset, positionsOffset + positionsCount),\n normals: normalsList.subarray(normalsOffset, normalsOffset + normalsCount),\n colors: colorsList.subarray(colorsOffset, colorsOffset + colorsCount),\n uvRegions: uvRegionsList.subarray(uvRegionsOffset, uvRegionsOffset + uvRegionsCount),\n texCoords: texCoordsList.subarray(texCoordsOffset, texCoordsOffset + texCoordsCount)\n });\n\n positionsOffset += positionsCount;\n normalsOffset += normalsCount;\n colorsOffset += colorsCount;\n uvRegionsOffset += uvRegionsCount;\n texCoordsOffset += texCoordsCount;\n }\n\n return groupedData;\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 itemsPerVertex4 = 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 case 'uvRegions':\n return vertexCount * itemsPerVertex4;\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 groupedMetadata: {\n featureId: number;\n attributes: GroupedByFeatureIdAttributes[];\n }[] = [];\n for (const data of sortedData) {\n const existingObject = groupedMetadata.find((obj) => obj.featureId === data.featureId);\n if (existingObject) {\n existingObject.attributes.push(data);\n } else {\n groupedMetadata.push({\n featureId: data.featureId,\n attributes: [data]\n });\n }\n }\n\n const uniqueObjects: GroupedByFeatureIdAttributes[] = [];\n for (const metatada of groupedMetadata) {\n const attributes = concatenateAttributes(metatada.attributes);\n\n uniqueObjects.push({\n featureId: metatada.featureId,\n ...attributes\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 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 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 const attributes = concatenateAttributes(unifiedObjects);\n\n range.push(attributes.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1);\n\n const faceRange = new Uint32Array(range);\n return {faceRange, featureIds, featureCount, ...attributes};\n}\n\n/**\n * Concatenate attributes typed arrays\n * @param attributes - grouped by featureId typed arrays\n * @returns - concatenated typed array list\n */\nfunction concatenateAttributes(attributes: GroupedByFeatureIdAttributes[]): GroupedAttributes {\n const positionGroups = attributes.map(({positions}) => positions);\n const positions =\n positionGroups.length > 1 ? concatenateTypedArrays(...positionGroups) : positionGroups[0];\n\n const normalGroups = attributes.map(({normals}) => normals);\n const normals =\n normalGroups.length > 1 ? concatenateTypedArrays(...normalGroups) : normalGroups[0];\n\n const colorGroups = attributes.map(({colors}) => colors);\n const colors = colorGroups.length > 1 ? concatenateTypedArrays(...colorGroups) : colorGroups[0];\n\n const texCoordGroups = attributes.map(({texCoords}) => texCoords);\n const texCoords =\n texCoordGroups.length > 1 ? concatenateTypedArrays(...texCoordGroups) : texCoordGroups[0];\n\n const uvRegionGroups = attributes.map(({uvRegions}) => uvRegions);\n const uvRegions =\n uvRegionGroups.length > 1 ? concatenateTypedArrays(...uvRegionGroups) : uvRegionGroups[0];\n return {\n positions,\n normals,\n colors,\n texCoords,\n uvRegions\n };\n}\n"],"mappings":"AAMA,SAAQA,sBAAsB,QAAO,0BAA0B;AAE/D,MAAMC,iBAAiB,GAAG,CAAC;AAC3B,MAAMC,kCAAkC,GAAG,CAAC;AAO5C,OAAO,SAASC,kBAAkBA,CAACC,UAA+B,EAAsB;EACtF,MAAM;IAACC,SAAS;IAAEC,OAAO;IAAEC,SAAS;IAAEC,MAAM;IAAEC,SAAS;IAAEC;EAAc,CAAC,GAAGN,UAAU;EACrF,MAAMO,aAAa,GAAGN,SAAS,CAACO,MAAM,GAAGV,kCAAkC;EAE3E,IAAI,CAACQ,cAAc,CAACE,MAAM,EAAE;IAC1B,OAAO;MACLC,SAAS,EAAE,IAAIC,WAAW,CAAC,CAAC,CAAC,EAAEH,aAAa,GAAG,CAAC,CAAC,CAAC;MAClDI,UAAU,EAAE,CAAC,CAAC,CAAC;MACfC,YAAY,EAAE,CAAC;MACfX,SAAS;MACTC,OAAO;MACPC,SAAS;MACTC,MAAM;MACNC;IAC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GAAG,CAACqD,KAAA;IAAA,IAAC;MAAClF;IAAM,CAAC,GAAAkF,KAAA;IAAA,OAAKlF,MAAM;EAAA,EAAC;EACxD,MAAMA,MAAM,GAAGiF,WAAW,CAAC7E,MAAM,GAAG,CAAC,GAAGZ,sBAAsB,CAAC,GAAGyF,WAAW,CAAC,GAAGA,WAAW,CAAC,CAAC,CAAC;EAE/F,MAAME,cAAc,GAAGvF,UAAU,CAACiC,GAAG,CAACuD,KAAA;IAAA,IAAC;MAACrF;IAAS,CAAC,GAAAqF,KAAA;IAAA,OAAKrF,SAAS;EAAA,EAAC;EACjE,MAAMA,SAAS,GACboF,cAAc,CAAC/E,MAAM,GAAG,CAAC,GAAGZ,sBAAsB,CAAC,GAAG2F,cAAc,CAAC,GAAGA,cAAc,CAAC,CAAC,CAAC;EAE3F,MAAME,cAAc,GAAGzF,UAAU,CAACiC,GAAG,CAACyD,KAAA;IAAA,IAAC;MAACrF;IAAS,CAAC,GAAAqF,KAAA;IAAA,OAAKrF,SAAS;EAAA,EAAC;EACjE,MAAMA,SAAS,GACboF,cAAc,CAACjF,MAAM,GAAG,CAAC,GAAGZ,sBAAsB,CAAC,GAAG6F,cAAc,CAAC,GAAGA,cAAc,CAAC,CAAC,CAAC;EAC3F,OAAO;IACLxF,SAAS;IACTC,OAAO;IACPE,MAAM;IACND,SAAS;IACTE;EACF,CAAC;AACH"}
|
|
@@ -8,10 +8,11 @@ import { v4 as uuidv4 } from 'uuid';
|
|
|
8
8
|
import { generateAttributes } from './geometry-attributes';
|
|
9
9
|
import { createBoundingVolumesFromGeometry } from './coordinate-converter';
|
|
10
10
|
import { prepareDataForAttributesConversion } from './gltf-attributes';
|
|
11
|
-
import { handleBatchIdsExtensions } from './batch-ids-extensions';
|
|
11
|
+
import { getTextureByMetadataClass, handleBatchIdsExtensions } from './batch-ids-extensions';
|
|
12
12
|
import { checkPropertiesLength, flattenPropertyTableByFeatureIds } from './feature-attributes';
|
|
13
13
|
import { GL } from '@loaders.gl/math';
|
|
14
14
|
import { generateSyntheticIndices } from '../../lib/utils/geometry-utils';
|
|
15
|
+
import { EXT_FEATURE_METADATA, EXT_STRUCTURAL_METADATA, getPropertyTableFromExtFeatureMetadata, getPropertyTableFromExtStructuralMetadata } from '@loaders.gl/gltf';
|
|
15
16
|
const DEFAULT_ROUGHNESS_FACTOR = 1;
|
|
16
17
|
const DEFAULT_METALLIC_FACTOR = 1;
|
|
17
18
|
const VALUES_PER_VERTEX = 3;
|
|
@@ -22,15 +23,14 @@ const SHORT_INT_TYPE = 'Int32';
|
|
|
22
23
|
const DOUBLE_TYPE = 'Float64';
|
|
23
24
|
const OBJECT_ID_TYPE = 'Oid32';
|
|
24
25
|
const BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];
|
|
25
|
-
const EXT_FEATURE_METADATA = 'EXT_feature_metadata';
|
|
26
|
-
const EXT_MESH_FEATURES = 'EXT_mesh_features';
|
|
27
26
|
let scratchVector = new Vector3();
|
|
28
|
-
export default async function convertB3dmToI3sGeometry(tileContent, tileTransform, tileBoundingVolume, addNodeToNodePage, propertyTable, featuresHashArray, attributeStorageInfo, draco, generateBoundingVolumes, shouldMergeMaterials, geoidHeightModel,
|
|
27
|
+
export default async function convertB3dmToI3sGeometry(tileContent, tileTransform, tileBoundingVolume, addNodeToNodePage, propertyTable, featuresHashArray, attributeStorageInfo, draco, generateBoundingVolumes, shouldMergeMaterials, geoidHeightModel, libraries, metadataClass) {
|
|
29
28
|
var _tileContent$gltf;
|
|
30
29
|
const useCartesianPositions = generateBoundingVolumes;
|
|
31
30
|
const materialAndTextureList = await convertMaterials((_tileContent$gltf = tileContent.gltf) === null || _tileContent$gltf === void 0 ? void 0 : _tileContent$gltf.materials, shouldMergeMaterials);
|
|
32
31
|
const dataForAttributesConversion = prepareDataForAttributesConversion(tileContent, tileTransform, tileBoundingVolume);
|
|
33
|
-
const
|
|
32
|
+
const featureTexture = getTextureByMetadataClass(tileContent, metadataClass);
|
|
33
|
+
const convertedAttributesMap = await convertAttributes(dataForAttributesConversion, materialAndTextureList, useCartesianPositions, featureTexture);
|
|
34
34
|
if (generateBoundingVolumes) {
|
|
35
35
|
_generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel);
|
|
36
36
|
}
|
|
@@ -59,7 +59,7 @@ export default async function convertB3dmToI3sGeometry(tileContent, tileTransfor
|
|
|
59
59
|
propertyTable,
|
|
60
60
|
attributeStorageInfo,
|
|
61
61
|
draco,
|
|
62
|
-
|
|
62
|
+
libraries
|
|
63
63
|
}));
|
|
64
64
|
}
|
|
65
65
|
if (!result.length) {
|
|
@@ -93,7 +93,7 @@ async function _makeNodeResources(_ref) {
|
|
|
93
93
|
propertyTable,
|
|
94
94
|
attributeStorageInfo,
|
|
95
95
|
draco,
|
|
96
|
-
|
|
96
|
+
libraries
|
|
97
97
|
} = _ref;
|
|
98
98
|
const boundingVolumes = convertedAttributes.boundingVolumes;
|
|
99
99
|
const vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;
|
|
@@ -107,8 +107,9 @@ async function _makeNodeResources(_ref) {
|
|
|
107
107
|
texCoords,
|
|
108
108
|
featureCount
|
|
109
109
|
} = generateAttributes(convertedAttributes);
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
let featureIdsMap = {};
|
|
111
|
+
if (propertyTable) {
|
|
112
|
+
featureIdsMap = makeFeatureIdsUnique(featureIds, convertedAttributes.featureIndices, featuresHashArray, propertyTable);
|
|
112
113
|
}
|
|
113
114
|
const header = new Uint32Array(2);
|
|
114
115
|
const typedFeatureIds = generateBigUint64Array(featureIds);
|
|
@@ -122,10 +123,10 @@ async function _makeNodeResources(_ref) {
|
|
|
122
123
|
uvRegions,
|
|
123
124
|
featureIds,
|
|
124
125
|
faceRange
|
|
125
|
-
},
|
|
126
|
+
}, libraries) : null;
|
|
126
127
|
let attributes = [];
|
|
127
128
|
if (attributeStorageInfo && propertyTable) {
|
|
128
|
-
attributes = convertPropertyTableToAttributeBuffers(featureIds, propertyTable, attributeStorageInfo);
|
|
129
|
+
attributes = convertPropertyTableToAttributeBuffers(featureIds, featureIdsMap, propertyTable, attributeStorageInfo);
|
|
129
130
|
}
|
|
130
131
|
return {
|
|
131
132
|
nodeId,
|
|
@@ -141,7 +142,7 @@ async function _makeNodeResources(_ref) {
|
|
|
141
142
|
boundingVolumes
|
|
142
143
|
};
|
|
143
144
|
}
|
|
144
|
-
export async function convertAttributes(attributesData, materialAndTextureList, useCartesianPositions) {
|
|
145
|
+
export async function convertAttributes(attributesData, materialAndTextureList, useCartesianPositions, featureTexture) {
|
|
145
146
|
const {
|
|
146
147
|
nodes,
|
|
147
148
|
images,
|
|
@@ -165,7 +166,7 @@ export async function convertAttributes(attributesData, materialAndTextureList,
|
|
|
165
166
|
attributesMap.set(mergedMaterial.originalMaterialId, attributes);
|
|
166
167
|
}
|
|
167
168
|
}
|
|
168
|
-
convertNodes(nodes, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions);
|
|
169
|
+
convertNodes(nodes, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, undefined, featureTexture);
|
|
169
170
|
for (const attrKey of attributesMap.keys()) {
|
|
170
171
|
const attributes = attributesMap.get(attrKey);
|
|
171
172
|
if (!attributes) {
|
|
@@ -184,9 +185,10 @@ export async function convertAttributes(attributesData, materialAndTextureList,
|
|
|
184
185
|
}
|
|
185
186
|
function convertNodes(nodes, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions) {
|
|
186
187
|
let matrix = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
188
|
+
let featureTexture = arguments.length > 7 ? arguments[7] : undefined;
|
|
187
189
|
if (nodes) {
|
|
188
190
|
for (const node of nodes) {
|
|
189
|
-
convertNode(node, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix);
|
|
191
|
+
convertNode(node, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix, featureTexture);
|
|
190
192
|
}
|
|
191
193
|
}
|
|
192
194
|
}
|
|
@@ -214,16 +216,18 @@ function getCompositeTransformationMatrix(node, matrix) {
|
|
|
214
216
|
}
|
|
215
217
|
function convertNode(node, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions) {
|
|
216
218
|
let matrix = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
219
|
+
let featureTexture = arguments.length > 7 ? arguments[7] : undefined;
|
|
217
220
|
const transformationMatrix = getCompositeTransformationMatrix(node, matrix);
|
|
218
221
|
const mesh = node.mesh;
|
|
219
222
|
if (mesh) {
|
|
220
|
-
convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
|
|
223
|
+
convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix, featureTexture);
|
|
221
224
|
}
|
|
222
|
-
convertNodes(node.children || [], images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
|
|
225
|
+
convertNodes(node.children || [], images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix, featureTexture);
|
|
223
226
|
}
|
|
224
227
|
function convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, attributesMap) {
|
|
225
228
|
let useCartesianPositions = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
|
|
226
229
|
let matrix = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
230
|
+
let featureTexture = arguments.length > 7 ? arguments[7] : undefined;
|
|
227
231
|
for (const primitive of mesh.primitives) {
|
|
228
232
|
let outputAttributes = null;
|
|
229
233
|
let materialUvRegion;
|
|
@@ -271,7 +275,7 @@ function convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, att
|
|
|
271
275
|
outputAttributes.uvRegions = concatenateTypedArrays(outputAttributes.uvRegions, createUvRegion(materialUvRegion, indices));
|
|
272
276
|
}
|
|
273
277
|
outputAttributes.featureIndicesGroups = outputAttributes.featureIndicesGroups || [];
|
|
274
|
-
outputAttributes.featureIndicesGroups.push(flattenBatchIds(getBatchIds(attributes, primitive, images), indices));
|
|
278
|
+
outputAttributes.featureIndicesGroups.push(flattenBatchIds(getBatchIds(attributes, primitive, images, featureTexture), indices));
|
|
275
279
|
}
|
|
276
280
|
}
|
|
277
281
|
function normalizeIndices(primitive) {
|
|
@@ -401,8 +405,8 @@ function flattenBatchIds(batchedIds, indices) {
|
|
|
401
405
|
}
|
|
402
406
|
return newBatchIds;
|
|
403
407
|
}
|
|
404
|
-
function getBatchIds(attributes, primitive, images) {
|
|
405
|
-
const batchIds = handleBatchIdsExtensions(attributes, primitive, images);
|
|
408
|
+
function getBatchIds(attributes, primitive, images, featureTexture) {
|
|
409
|
+
const batchIds = handleBatchIdsExtensions(attributes, primitive, images, featureTexture);
|
|
406
410
|
if (batchIds.length) {
|
|
407
411
|
return batchIds;
|
|
408
412
|
}
|
|
@@ -660,6 +664,7 @@ function makeFeatureIdsUnique(featureIds, featureIndices, featuresHashArray, bat
|
|
|
660
664
|
const replaceMap = getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray);
|
|
661
665
|
replaceIndicesByUnique(featureIndices, replaceMap);
|
|
662
666
|
replaceIndicesByUnique(featureIds, replaceMap);
|
|
667
|
+
return replaceMap;
|
|
663
668
|
}
|
|
664
669
|
function getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray) {
|
|
665
670
|
const featureMap = {};
|
|
@@ -690,19 +695,21 @@ function replaceIndicesByUnique(indicesArray, featureMap) {
|
|
|
690
695
|
indicesArray[index] = featureMap[indicesArray[index]];
|
|
691
696
|
}
|
|
692
697
|
}
|
|
693
|
-
function convertPropertyTableToAttributeBuffers(featureIds, propertyTable, attributeStorageInfo) {
|
|
698
|
+
function convertPropertyTableToAttributeBuffers(featureIds, featureIdsMap, propertyTable, attributeStorageInfo) {
|
|
694
699
|
const attributeBuffers = [];
|
|
695
700
|
const needFlattenPropertyTable = checkPropertiesLength(featureIds, propertyTable);
|
|
696
|
-
const properties = needFlattenPropertyTable ? flattenPropertyTableByFeatureIds(
|
|
701
|
+
const properties = needFlattenPropertyTable ? flattenPropertyTableByFeatureIds(featureIdsMap, propertyTable) : propertyTable;
|
|
697
702
|
const propertyTableWithObjectIds = {
|
|
698
703
|
OBJECTID: featureIds,
|
|
699
704
|
...properties
|
|
700
705
|
};
|
|
701
706
|
for (const propertyName in propertyTableWithObjectIds) {
|
|
702
707
|
const type = getAttributeType(propertyName, attributeStorageInfo);
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
708
|
+
if (type) {
|
|
709
|
+
const value = propertyTableWithObjectIds[propertyName];
|
|
710
|
+
const attributeBuffer = generateAttributeBuffer(type, value);
|
|
711
|
+
attributeBuffers.push(attributeBuffer);
|
|
712
|
+
}
|
|
706
713
|
}
|
|
707
714
|
return attributeBuffers;
|
|
708
715
|
}
|
|
@@ -726,6 +733,14 @@ function generateAttributeBuffer(type, value) {
|
|
|
726
733
|
}
|
|
727
734
|
function getAttributeType(key, attributeStorageInfo) {
|
|
728
735
|
const attribute = attributeStorageInfo.find(attr => attr.name === key);
|
|
736
|
+
if (!attribute) {
|
|
737
|
+
console.error("attribute is null, key=".concat(key, ", attributeStorageInfo=").concat(JSON.stringify(attributeStorageInfo, null, 2)));
|
|
738
|
+
return '';
|
|
739
|
+
}
|
|
740
|
+
if (!attribute.attributeValues) {
|
|
741
|
+
console.error("attributeValues is null, attribute=".concat(attribute));
|
|
742
|
+
return '';
|
|
743
|
+
}
|
|
729
744
|
return attribute.attributeValues.valueType;
|
|
730
745
|
}
|
|
731
746
|
function generateShortIntegerAttributeBuffer(featureIds) {
|
|
@@ -762,7 +777,7 @@ function generateBigUint64Array(featureIds) {
|
|
|
762
777
|
}
|
|
763
778
|
return typedFeatureIds;
|
|
764
779
|
}
|
|
765
|
-
async function generateCompressedGeometry(vertexCount, convertedAttributes, attributes,
|
|
780
|
+
async function generateCompressedGeometry(vertexCount, convertedAttributes, attributes, libraries) {
|
|
766
781
|
const {
|
|
767
782
|
positions,
|
|
768
783
|
normals,
|
|
@@ -804,12 +819,16 @@ async function generateCompressedGeometry(vertexCount, convertedAttributes, attr
|
|
|
804
819
|
indices
|
|
805
820
|
}, DracoWriterWorker, {
|
|
806
821
|
...DracoWriterWorker.options,
|
|
807
|
-
source: dracoWorkerSoure,
|
|
808
822
|
reuseWorkers: true,
|
|
809
823
|
_nodeWorkers: true,
|
|
824
|
+
modules: libraries,
|
|
825
|
+
useLocalLibraries: true,
|
|
810
826
|
draco: {
|
|
811
827
|
method: 'MESH_SEQUENTIAL_ENCODING',
|
|
812
828
|
attributesMetadata
|
|
829
|
+
},
|
|
830
|
+
['draco-writer']: {
|
|
831
|
+
workerUrl: './modules/draco/dist/draco-writer-worker-node.js'
|
|
813
832
|
}
|
|
814
833
|
});
|
|
815
834
|
}
|
|
@@ -825,11 +844,12 @@ function generateFeatureIndexAttribute(featureIndex, faceRange) {
|
|
|
825
844
|
}
|
|
826
845
|
return orderedFeatureIndices;
|
|
827
846
|
}
|
|
828
|
-
export function getPropertyTable(tileContent) {
|
|
847
|
+
export function getPropertyTable(tileContent, metadataClass) {
|
|
829
848
|
if (!tileContent) {
|
|
830
849
|
return null;
|
|
831
850
|
}
|
|
832
|
-
|
|
851
|
+
let propertyTable;
|
|
852
|
+
const batchTableJson = tileContent.batchTableJson;
|
|
833
853
|
if (batchTableJson) {
|
|
834
854
|
return batchTableJson;
|
|
835
855
|
}
|
|
@@ -838,14 +858,15 @@ export function getPropertyTable(tileContent) {
|
|
|
838
858
|
extension
|
|
839
859
|
} = getPropertyTableExtension(tileContent);
|
|
840
860
|
switch (extensionName) {
|
|
841
|
-
case
|
|
861
|
+
case EXT_STRUCTURAL_METADATA:
|
|
842
862
|
{
|
|
843
|
-
|
|
844
|
-
return
|
|
863
|
+
propertyTable = getPropertyTableFromExtStructuralMetadata(extension, metadataClass);
|
|
864
|
+
return propertyTable;
|
|
845
865
|
}
|
|
846
866
|
case EXT_FEATURE_METADATA:
|
|
847
867
|
{
|
|
848
|
-
|
|
868
|
+
propertyTable = getPropertyTableFromExtFeatureMetadata(extension, metadataClass);
|
|
869
|
+
return propertyTable;
|
|
849
870
|
}
|
|
850
871
|
default:
|
|
851
872
|
return null;
|
|
@@ -853,7 +874,7 @@ export function getPropertyTable(tileContent) {
|
|
|
853
874
|
}
|
|
854
875
|
function getPropertyTableExtension(tileContent) {
|
|
855
876
|
var _tileContent$gltf3, _tileContent$gltf5, _tileContent$gltf5$ex;
|
|
856
|
-
const extensionsWithPropertyTables = [EXT_FEATURE_METADATA,
|
|
877
|
+
const extensionsWithPropertyTables = [EXT_FEATURE_METADATA, EXT_STRUCTURAL_METADATA];
|
|
857
878
|
const extensionsUsed = tileContent === null || tileContent === void 0 ? void 0 : (_tileContent$gltf3 = tileContent.gltf) === null || _tileContent$gltf3 === void 0 ? void 0 : _tileContent$gltf3.extensionsUsed;
|
|
858
879
|
if (!extensionsUsed) {
|
|
859
880
|
return {
|
|
@@ -869,38 +890,16 @@ function getPropertyTableExtension(tileContent) {
|
|
|
869
890
|
break;
|
|
870
891
|
}
|
|
871
892
|
}
|
|
893
|
+
if (!extensionName) {
|
|
894
|
+
return {
|
|
895
|
+
extensionName: null,
|
|
896
|
+
extension: null
|
|
897
|
+
};
|
|
898
|
+
}
|
|
872
899
|
const extension = tileContent === null || tileContent === void 0 ? void 0 : (_tileContent$gltf5 = tileContent.gltf) === null || _tileContent$gltf5 === void 0 ? void 0 : (_tileContent$gltf5$ex = _tileContent$gltf5.extensions) === null || _tileContent$gltf5$ex === void 0 ? void 0 : _tileContent$gltf5$ex[extensionName];
|
|
873
900
|
return {
|
|
874
901
|
extensionName,
|
|
875
902
|
extension
|
|
876
903
|
};
|
|
877
904
|
}
|
|
878
|
-
function getPropertyTableFromExtFeatureMetadata(extension) {
|
|
879
|
-
if (extension !== null && extension !== void 0 && extension.featureTables) {
|
|
880
|
-
var _Object$keys;
|
|
881
|
-
const firstFeatureTableName = (_Object$keys = Object.keys(extension.featureTables)) === null || _Object$keys === void 0 ? void 0 : _Object$keys[0];
|
|
882
|
-
if (firstFeatureTableName) {
|
|
883
|
-
const featureTable = extension === null || extension === void 0 ? void 0 : extension.featureTables[firstFeatureTableName];
|
|
884
|
-
const propertyTable = {};
|
|
885
|
-
for (const propertyName in featureTable.properties) {
|
|
886
|
-
propertyTable[propertyName] = featureTable.properties[propertyName].data;
|
|
887
|
-
}
|
|
888
|
-
return propertyTable;
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
if (extension !== null && extension !== void 0 && extension.featureTextures) {
|
|
892
|
-
var _Object$keys2;
|
|
893
|
-
const firstTextureName = (_Object$keys2 = Object.keys(extension.featureTextures)) === null || _Object$keys2 === void 0 ? void 0 : _Object$keys2[0];
|
|
894
|
-
if (firstTextureName) {
|
|
895
|
-
const featureTable = extension === null || extension === void 0 ? void 0 : extension.featureTextures[firstTextureName];
|
|
896
|
-
const propertyTable = {};
|
|
897
|
-
for (const propertyName in featureTable.properties) {
|
|
898
|
-
propertyTable[propertyName] = featureTable.properties[propertyName].data;
|
|
899
|
-
}
|
|
900
|
-
return propertyTable;
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
console.warn("The I3S converter couldn't handle EXT_feature_metadata extension: There is neither featureTables, no featureTextures in the extension.");
|
|
904
|
-
return null;
|
|
905
|
-
}
|
|
906
905
|
//# sourceMappingURL=geometry-converter.js.map
|