@loaders.gl/i3s 3.1.3 → 4.0.0-alpha.5
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/bundle.js +2 -2
- package/dist/bundle.js.map +1 -0
- package/dist/dist.min.js +28 -25
- package/dist/i3s-attribute-loader.js +130 -155
- package/dist/i3s-attribute-loader.js.map +1 -0
- package/dist/i3s-building-scene-layer-loader.js +18 -23
- package/dist/i3s-building-scene-layer-loader.js.map +1 -0
- package/dist/i3s-content-loader.js +22 -25
- package/dist/i3s-content-loader.js.map +1 -0
- package/dist/i3s-content-worker.js +23 -21
- package/dist/i3s-loader.js +81 -84
- package/dist/i3s-loader.js.map +1 -0
- package/dist/i3s-node-page-loader.js +17 -21
- package/dist/i3s-node-page-loader.js.map +1 -0
- package/dist/index.js +6 -14
- package/dist/index.js.map +1 -0
- package/dist/lib/helpers/i3s-nodepages-tiles.js +228 -221
- package/dist/lib/helpers/i3s-nodepages-tiles.js.map +1 -0
- package/dist/lib/parsers/constants.js +63 -85
- package/dist/lib/parsers/constants.js.map +1 -0
- package/dist/lib/parsers/parse-i3s-attribute.js +62 -86
- package/dist/lib/parsers/parse-i3s-attribute.js.map +1 -0
- package/dist/lib/parsers/parse-i3s-building-scene-layer.js +40 -41
- package/dist/lib/parsers/parse-i3s-building-scene-layer.js.map +1 -0
- package/dist/lib/parsers/parse-i3s-tile-content.d.ts.map +1 -1
- package/dist/lib/parsers/parse-i3s-tile-content.js +458 -441
- package/dist/lib/parsers/parse-i3s-tile-content.js.map +1 -0
- package/dist/lib/parsers/parse-i3s.js +88 -86
- package/dist/lib/parsers/parse-i3s.js.map +1 -0
- package/dist/lib/utils/convert-i3s-obb-to-mbs.js +8 -19
- package/dist/lib/utils/convert-i3s-obb-to-mbs.js.map +1 -0
- package/dist/lib/utils/url-utils.js +28 -41
- package/dist/lib/utils/url-utils.js.map +1 -0
- package/dist/types.d.ts +2 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +19 -18
- package/dist/types.js.map +1 -0
- package/dist/workers/i3s-content-worker.js +4 -5
- package/dist/workers/i3s-content-worker.js.map +1 -0
- package/package.json +12 -12
- package/src/i3s-building-scene-layer-loader.ts +1 -1
- package/src/i3s-content-loader.ts +1 -1
- package/src/lib/parsers/parse-i3s-tile-content.ts +4 -1
- package/src/types.ts +2 -3
- package/dist/es5/bundle.js +0 -7
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/i3s-attribute-loader.js +0 -249
- package/dist/es5/i3s-attribute-loader.js.map +0 -1
- package/dist/es5/i3s-building-scene-layer-loader.js +0 -58
- package/dist/es5/i3s-building-scene-layer-loader.js.map +0 -1
- package/dist/es5/i3s-content-loader.js +0 -60
- package/dist/es5/i3s-content-loader.js.map +0 -1
- package/dist/es5/i3s-loader.js +0 -233
- package/dist/es5/i3s-loader.js.map +0 -1
- package/dist/es5/i3s-node-page-loader.js +0 -72
- package/dist/es5/i3s-node-page-loader.js.map +0 -1
- package/dist/es5/index.js +0 -52
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/helpers/i3s-nodepages-tiles.js +0 -393
- package/dist/es5/lib/helpers/i3s-nodepages-tiles.js.map +0 -1
- package/dist/es5/lib/parsers/constants.js +0 -89
- package/dist/es5/lib/parsers/constants.js.map +0 -1
- package/dist/es5/lib/parsers/parse-i3s-attribute.js +0 -124
- package/dist/es5/lib/parsers/parse-i3s-attribute.js.map +0 -1
- package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js +0 -86
- package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js.map +0 -1
- package/dist/es5/lib/parsers/parse-i3s-tile-content.js +0 -635
- package/dist/es5/lib/parsers/parse-i3s-tile-content.js.map +0 -1
- package/dist/es5/lib/parsers/parse-i3s.js +0 -155
- package/dist/es5/lib/parsers/parse-i3s.js.map +0 -1
- package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js +0 -24
- package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js.map +0 -1
- package/dist/es5/lib/utils/url-utils.js +0 -40
- package/dist/es5/lib/utils/url-utils.js.map +0 -1
- package/dist/es5/types.js +0 -29
- package/dist/es5/types.js.map +0 -1
- package/dist/es5/workers/i3s-content-worker.js +0 -8
- package/dist/es5/workers/i3s-content-worker.js.map +0 -1
- package/dist/esm/bundle.js +0 -5
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/i3s-attribute-loader.js +0 -152
- package/dist/esm/i3s-attribute-loader.js.map +0 -1
- package/dist/esm/i3s-building-scene-layer-loader.js +0 -21
- package/dist/esm/i3s-building-scene-layer-loader.js.map +0 -1
- package/dist/esm/i3s-content-loader.js +0 -25
- package/dist/esm/i3s-content-loader.js.map +0 -1
- package/dist/esm/i3s-loader.js +0 -97
- package/dist/esm/i3s-loader.js.map +0 -1
- package/dist/esm/i3s-node-page-loader.js +0 -22
- package/dist/esm/i3s-node-page-loader.js.map +0 -1
- package/dist/esm/index.js +0 -6
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/helpers/i3s-nodepages-tiles.js +0 -239
- package/dist/esm/lib/helpers/i3s-nodepages-tiles.js.map +0 -1
- package/dist/esm/lib/parsers/constants.js +0 -67
- package/dist/esm/lib/parsers/constants.js.map +0 -1
- package/dist/esm/lib/parsers/parse-i3s-attribute.js +0 -74
- package/dist/esm/lib/parsers/parse-i3s-attribute.js.map +0 -1
- package/dist/esm/lib/parsers/parse-i3s-building-scene-layer.js +0 -45
- package/dist/esm/lib/parsers/parse-i3s-building-scene-layer.js.map +0 -1
- package/dist/esm/lib/parsers/parse-i3s-tile-content.js +0 -494
- package/dist/esm/lib/parsers/parse-i3s-tile-content.js.map +0 -1
- package/dist/esm/lib/parsers/parse-i3s.js +0 -91
- package/dist/esm/lib/parsers/parse-i3s.js.map +0 -1
- package/dist/esm/lib/utils/convert-i3s-obb-to-mbs.js +0 -9
- package/dist/esm/lib/utils/convert-i3s-obb-to-mbs.js.map +0 -1
- package/dist/esm/lib/utils/url-utils.js +0 -31
- package/dist/esm/lib/utils/url-utils.js.map +0 -1
- package/dist/esm/types.js +0 -21
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/workers/i3s-content-worker.js +0 -4
- package/dist/esm/workers/i3s-content-worker.js.map +0 -1
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { STRING_ATTRIBUTE_TYPE, OBJECT_ID_ATTRIBUTE_TYPE, FLOAT_64_TYPE, INT_16_ATTRIBUTE_TYPE } from './constants';
|
|
2
|
-
export async function parseI3STileAttribute(arrayBuffer, options) {
|
|
3
|
-
const {
|
|
4
|
-
attributeName,
|
|
5
|
-
attributeType
|
|
6
|
-
} = options;
|
|
7
|
-
|
|
8
|
-
if (!attributeName) {
|
|
9
|
-
return {};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return {
|
|
13
|
-
[attributeName]: attributeType ? parseAttribute(attributeType, arrayBuffer) : null
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function parseAttribute(attributeType, arrayBuffer) {
|
|
18
|
-
switch (attributeType) {
|
|
19
|
-
case STRING_ATTRIBUTE_TYPE:
|
|
20
|
-
return parseStringsAttribute(arrayBuffer);
|
|
21
|
-
|
|
22
|
-
case OBJECT_ID_ATTRIBUTE_TYPE:
|
|
23
|
-
return parseShortNumberAttribute(arrayBuffer);
|
|
24
|
-
|
|
25
|
-
case FLOAT_64_TYPE:
|
|
26
|
-
return parseFloatAttribute(arrayBuffer);
|
|
27
|
-
|
|
28
|
-
case INT_16_ATTRIBUTE_TYPE:
|
|
29
|
-
return parseInt16ShortNumberAttribute(arrayBuffer);
|
|
30
|
-
|
|
31
|
-
default:
|
|
32
|
-
return parseShortNumberAttribute(arrayBuffer);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function parseShortNumberAttribute(arrayBuffer) {
|
|
37
|
-
const countOffset = 4;
|
|
38
|
-
return new Uint32Array(arrayBuffer, countOffset);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function parseInt16ShortNumberAttribute(arrayBuffer) {
|
|
42
|
-
const countOffset = 4;
|
|
43
|
-
return new Int16Array(arrayBuffer, countOffset);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function parseFloatAttribute(arrayBuffer) {
|
|
47
|
-
const countOffset = 8;
|
|
48
|
-
return new Float64Array(arrayBuffer, countOffset);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function parseStringsAttribute(arrayBuffer) {
|
|
52
|
-
const stringsCountOffset = 0;
|
|
53
|
-
const dataOffset = 8;
|
|
54
|
-
const bytesPerStringSize = 4;
|
|
55
|
-
const stringsArray = [];
|
|
56
|
-
|
|
57
|
-
try {
|
|
58
|
-
const stringsCount = new DataView(arrayBuffer, stringsCountOffset, bytesPerStringSize).getUint32(stringsCountOffset, true);
|
|
59
|
-
const stringSizes = new Uint32Array(arrayBuffer, dataOffset, stringsCount);
|
|
60
|
-
let stringOffset = dataOffset + stringsCount * bytesPerStringSize;
|
|
61
|
-
|
|
62
|
-
for (const stringByteSize of stringSizes) {
|
|
63
|
-
const textDecoder = new TextDecoder('utf-8');
|
|
64
|
-
const stringAttribute = new Uint8Array(arrayBuffer, stringOffset, stringByteSize);
|
|
65
|
-
stringsArray.push(textDecoder.decode(stringAttribute));
|
|
66
|
-
stringOffset += stringByteSize;
|
|
67
|
-
}
|
|
68
|
-
} catch (error) {
|
|
69
|
-
console.error('Parse string attribute error: ', error.message);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return stringsArray;
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=parse-i3s-attribute.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/parsers/parse-i3s-attribute.ts"],"names":["STRING_ATTRIBUTE_TYPE","OBJECT_ID_ATTRIBUTE_TYPE","FLOAT_64_TYPE","INT_16_ATTRIBUTE_TYPE","parseI3STileAttribute","arrayBuffer","options","attributeName","attributeType","parseAttribute","parseStringsAttribute","parseShortNumberAttribute","parseFloatAttribute","parseInt16ShortNumberAttribute","countOffset","Uint32Array","Int16Array","Float64Array","stringsCountOffset","dataOffset","bytesPerStringSize","stringsArray","stringsCount","DataView","getUint32","stringSizes","stringOffset","stringByteSize","textDecoder","TextDecoder","stringAttribute","Uint8Array","push","decode","error","console","message"],"mappings":"AAAA,SACEA,qBADF,EAEEC,wBAFF,EAGEC,aAHF,EAIEC,qBAJF,QAKO,aALP;AAaA,OAAO,eAAeC,qBAAf,CAAqCC,WAArC,EAAkDC,OAAlD,EAA2D;AAChE,QAAM;AAACC,IAAAA,aAAD;AAAgBC,IAAAA;AAAhB,MAAiCF,OAAvC;;AAEA,MAAI,CAACC,aAAL,EAAoB;AAClB,WAAO,EAAP;AACD;;AACD,SAAO;AACL,KAACA,aAAD,GAAiBC,aAAa,GAAGC,cAAc,CAACD,aAAD,EAAgBH,WAAhB,CAAjB,GAAgD;AADzE,GAAP;AAGD;;AAQD,SAASI,cAAT,CAAwBD,aAAxB,EAAuCH,WAAvC,EAAoD;AAClD,UAAQG,aAAR;AACE,SAAKR,qBAAL;AACE,aAAOU,qBAAqB,CAACL,WAAD,CAA5B;;AACF,SAAKJ,wBAAL;AACE,aAAOU,yBAAyB,CAACN,WAAD,CAAhC;;AACF,SAAKH,aAAL;AACE,aAAOU,mBAAmB,CAACP,WAAD,CAA1B;;AACF,SAAKF,qBAAL;AACE,aAAOU,8BAA8B,CAACR,WAAD,CAArC;;AACF;AACE,aAAOM,yBAAyB,CAACN,WAAD,CAAhC;AAVJ;AAYD;;AAQD,SAASM,yBAAT,CAAmCN,WAAnC,EAAgD;AAC9C,QAAMS,WAAW,GAAG,CAApB;AACA,SAAO,IAAIC,WAAJ,CAAgBV,WAAhB,EAA6BS,WAA7B,CAAP;AACD;;AAQD,SAASD,8BAAT,CAAwCR,WAAxC,EAAqD;AACnD,QAAMS,WAAW,GAAG,CAApB;AACA,SAAO,IAAIE,UAAJ,CAAeX,WAAf,EAA4BS,WAA5B,CAAP;AACD;;AAQD,SAASF,mBAAT,CAA6BP,WAA7B,EAA0C;AACxC,QAAMS,WAAW,GAAG,CAApB;AACA,SAAO,IAAIG,YAAJ,CAAiBZ,WAAjB,EAA8BS,WAA9B,CAAP;AACD;;AAQD,SAASJ,qBAAT,CAA+BL,WAA/B,EAAmE;AACjE,QAAMa,kBAAkB,GAAG,CAA3B;AACA,QAAMC,UAAU,GAAG,CAAnB;AACA,QAAMC,kBAAkB,GAAG,CAA3B;AACA,QAAMC,YAAsB,GAAG,EAA/B;;AAEA,MAAI;AAEF,UAAMC,YAAY,GAAG,IAAIC,QAAJ,CACnBlB,WADmB,EAEnBa,kBAFmB,EAGnBE,kBAHmB,EAInBI,SAJmB,CAITN,kBAJS,EAIW,IAJX,CAArB;AAKA,UAAMO,WAAW,GAAG,IAAIV,WAAJ,CAAgBV,WAAhB,EAA6Bc,UAA7B,EAAyCG,YAAzC,CAApB;AACA,QAAII,YAAY,GAAGP,UAAU,GAAGG,YAAY,GAAGF,kBAA/C;;AAEA,SAAK,MAAMO,cAAX,IAA6BF,WAA7B,EAA0C;AACxC,YAAMG,WAAW,GAAG,IAAIC,WAAJ,CAAgB,OAAhB,CAApB;AACA,YAAMC,eAAe,GAAG,IAAIC,UAAJ,CAAe1B,WAAf,EAA4BqB,YAA5B,EAA0CC,cAA1C,CAAxB;AACAN,MAAAA,YAAY,CAACW,IAAb,CAAkBJ,WAAW,CAACK,MAAZ,CAAmBH,eAAnB,CAAlB;AACAJ,MAAAA,YAAY,IAAIC,cAAhB;AACD;AACF,GAhBD,CAgBE,OAAOO,KAAP,EAAc;AACdC,IAAAA,OAAO,CAACD,KAAR,CAAc,gCAAd,EAAiDA,KAAD,CAAiBE,OAAjE;AACD;;AAED,SAAOf,YAAP;AACD","sourcesContent":["import {\n STRING_ATTRIBUTE_TYPE,\n OBJECT_ID_ATTRIBUTE_TYPE,\n FLOAT_64_TYPE,\n INT_16_ATTRIBUTE_TYPE\n} from './constants';\n\n/**\n * Get particular tile and creates attribute object inside.\n * @param {ArrayBuffer} arrayBuffer\n * @param {Object} options\n * @returns {Promise<object>}\n */\nexport async function parseI3STileAttribute(arrayBuffer, options) {\n const {attributeName, attributeType} = options;\n\n if (!attributeName) {\n return {};\n }\n return {\n [attributeName]: attributeType ? parseAttribute(attributeType, arrayBuffer) : null\n };\n}\n\n/**\n * Parse attributes based on attribute type.\n * @param {String} attributeType\n * @param {ArrayBuffer} arrayBuffer\n * @returns {any}\n */\nfunction parseAttribute(attributeType, arrayBuffer) {\n switch (attributeType) {\n case STRING_ATTRIBUTE_TYPE:\n return parseStringsAttribute(arrayBuffer);\n case OBJECT_ID_ATTRIBUTE_TYPE:\n return parseShortNumberAttribute(arrayBuffer);\n case FLOAT_64_TYPE:\n return parseFloatAttribute(arrayBuffer);\n case INT_16_ATTRIBUTE_TYPE:\n return parseInt16ShortNumberAttribute(arrayBuffer);\n default:\n return parseShortNumberAttribute(arrayBuffer);\n }\n}\n\n/**\n * Parse short number attribute.\n * Short Integer spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.7/attributeStorageInfo.cmn.md\n * @param {ArrayBuffer} arrayBuffer\n * @returns {Uint32Array}\n */\nfunction parseShortNumberAttribute(arrayBuffer) {\n const countOffset = 4;\n return new Uint32Array(arrayBuffer, countOffset);\n}\n\n/**\n * Parse Int16 short number attribute.\n * Parsing of such data is not documented. Added to handle Building Scene Layer Tileset attributes data.\n * @param {ArrayBuffer} arrayBuffer\n * @returns {Int16Array}\n */\nfunction parseInt16ShortNumberAttribute(arrayBuffer) {\n const countOffset = 4;\n return new Int16Array(arrayBuffer, countOffset);\n}\n\n/**\n * Parse float attribute.\n * Double Spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.7/attributeStorageInfo.cmn.md\n * @param {ArrayBuffer} arrayBuffer\n * @returns {Float64Array}\n */\nfunction parseFloatAttribute(arrayBuffer) {\n const countOffset = 8;\n return new Float64Array(arrayBuffer, countOffset);\n}\n\n/**\n * Parse string attribute.\n * String spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.7/attributeStorageInfo.cmn.md\n * @param arrayBuffer\n * @returns list of strings\n */\nfunction parseStringsAttribute(arrayBuffer: ArrayBuffer): string[] {\n const stringsCountOffset = 0;\n const dataOffset = 8;\n const bytesPerStringSize = 4;\n const stringsArray: string[] = [];\n\n try {\n // Use DataView to avoid multiple of 4 error on Uint32Array constructor\n const stringsCount = new DataView(\n arrayBuffer,\n stringsCountOffset,\n bytesPerStringSize\n ).getUint32(stringsCountOffset, true);\n const stringSizes = new Uint32Array(arrayBuffer, dataOffset, stringsCount);\n let stringOffset = dataOffset + stringsCount * bytesPerStringSize;\n\n for (const stringByteSize of stringSizes) {\n const textDecoder = new TextDecoder('utf-8');\n const stringAttribute = new Uint8Array(arrayBuffer, stringOffset, stringByteSize);\n stringsArray.push(textDecoder.decode(stringAttribute));\n stringOffset += stringByteSize;\n }\n } catch (error) {\n console.error('Parse string attribute error: ', (error as Error).message); // eslint-disable-line\n }\n\n return stringsArray;\n}\n"],"file":"parse-i3s-attribute.js"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
const OBJECT_3D_LAYER_TYPE = '3DObject';
|
|
2
|
-
export async function parseBuildingSceneLayer(data, url) {
|
|
3
|
-
const layer0 = JSON.parse(new TextDecoder().decode(data));
|
|
4
|
-
const {
|
|
5
|
-
sublayers
|
|
6
|
-
} = layer0;
|
|
7
|
-
return {
|
|
8
|
-
header: layer0,
|
|
9
|
-
sublayers: parseSublayersTree(sublayers, url)
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function parseSublayersTree(sublayers, url) {
|
|
14
|
-
let layers = [];
|
|
15
|
-
|
|
16
|
-
for (let index = 0; index < sublayers.length; index++) {
|
|
17
|
-
var _subLayer$sublayers;
|
|
18
|
-
|
|
19
|
-
const subLayer = sublayers[index];
|
|
20
|
-
const {
|
|
21
|
-
id,
|
|
22
|
-
layerType,
|
|
23
|
-
visibility = true,
|
|
24
|
-
...rest
|
|
25
|
-
} = subLayer;
|
|
26
|
-
|
|
27
|
-
if (layerType === OBJECT_3D_LAYER_TYPE) {
|
|
28
|
-
const sublayerUrl = "".concat(url, "/sublayers/").concat(id);
|
|
29
|
-
layers.push({
|
|
30
|
-
url: sublayerUrl,
|
|
31
|
-
id,
|
|
32
|
-
layerType,
|
|
33
|
-
visibility,
|
|
34
|
-
...rest
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (subLayer !== null && subLayer !== void 0 && (_subLayer$sublayers = subLayer.sublayers) !== null && _subLayer$sublayers !== void 0 && _subLayer$sublayers.length) {
|
|
39
|
-
layers = [...layers, ...parseSublayersTree(subLayer.sublayers, url)];
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return layers;
|
|
44
|
-
}
|
|
45
|
-
//# sourceMappingURL=parse-i3s-building-scene-layer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/parsers/parse-i3s-building-scene-layer.ts"],"names":["OBJECT_3D_LAYER_TYPE","parseBuildingSceneLayer","data","url","layer0","JSON","parse","TextDecoder","decode","sublayers","header","parseSublayersTree","layers","index","length","subLayer","id","layerType","visibility","rest","sublayerUrl","push"],"mappings":"AAEA,MAAMA,oBAAoB,GAAG,UAA7B;AAQA,OAAO,eAAeC,uBAAf,CACLC,IADK,EAELC,GAFK,EAG+B;AACpC,QAAMC,MAAM,GAAGC,IAAI,CAACC,KAAL,CAAW,IAAIC,WAAJ,GAAkBC,MAAlB,CAAyBN,IAAzB,CAAX,CAAf;AACA,QAAM;AAACO,IAAAA;AAAD,MAAcL,MAApB;AAEA,SAAO;AACLM,IAAAA,MAAM,EAAEN,MADH;AAELK,IAAAA,SAAS,EAAEE,kBAAkB,CAACF,SAAD,EAAYN,GAAZ;AAFxB,GAAP;AAID;;AAOD,SAASQ,kBAAT,CACEF,SADF,EAEEN,GAFF,EAG2B;AACzB,MAAIS,MAA+B,GAAG,EAAtC;;AAEA,OAAK,IAAIC,KAAK,GAAG,CAAjB,EAAoBA,KAAK,GAAGJ,SAAS,CAACK,MAAtC,EAA8CD,KAAK,EAAnD,EAAuD;AAAA;;AACrD,UAAME,QAAQ,GAAGN,SAAS,CAACI,KAAD,CAA1B;AACA,UAAM;AAACG,MAAAA,EAAD;AAAKC,MAAAA,SAAL;AAAgBC,MAAAA,UAAU,GAAG,IAA7B;AAAmC,SAAGC;AAAtC,QAA8CJ,QAApD;;AAGA,QAAIE,SAAS,KAAKjB,oBAAlB,EAAwC;AACtC,YAAMoB,WAAW,aAAMjB,GAAN,wBAAuBa,EAAvB,CAAjB;AAEAJ,MAAAA,MAAM,CAACS,IAAP,CAAY;AACVlB,QAAAA,GAAG,EAAEiB,WADK;AAEVJ,QAAAA,EAFU;AAGVC,QAAAA,SAHU;AAIVC,QAAAA,UAJU;AAKV,WAAGC;AALO,OAAZ;AAOD;;AAED,QAAIJ,QAAJ,aAAIA,QAAJ,sCAAIA,QAAQ,CAAEN,SAAd,gDAAI,oBAAqBK,MAAzB,EAAiC;AAC/BF,MAAAA,MAAM,GAAG,CAAC,GAAGA,MAAJ,EAAY,GAAGD,kBAAkB,CAACI,QAAQ,CAACN,SAAV,EAAqBN,GAArB,CAAjC,CAAT;AACD;AACF;;AAED,SAAOS,MAAP;AACD","sourcesContent":["import type {BuildingSceneLayerTileset, BuildingSceneSublayer} from '../../types';\n\nconst OBJECT_3D_LAYER_TYPE = '3DObject';\n\n/**\n * Parses Builiding Scene Layer and creates tileset\n * @param data\n * @param options\n * @param context\n */\nexport async function parseBuildingSceneLayer(\n data: ArrayBuffer,\n url: string\n): Promise<BuildingSceneLayerTileset> {\n const layer0 = JSON.parse(new TextDecoder().decode(data));\n const {sublayers} = layer0;\n\n return {\n header: layer0,\n sublayers: parseSublayersTree(sublayers, url)\n };\n}\n\n/**\n * Recursively parses Building Scene Layer sublayers.\n * @param sublayers\n * @param url\n */\nfunction parseSublayersTree(\n sublayers: BuildingSceneSublayer[],\n url: string\n): BuildingSceneSublayer[] {\n let layers: BuildingSceneSublayer[] = [];\n\n for (let index = 0; index < sublayers.length; index++) {\n const subLayer = sublayers[index];\n const {id, layerType, visibility = true, ...rest} = subLayer;\n\n // Add support only for 3DObject layer type for I3S purposes.\n if (layerType === OBJECT_3D_LAYER_TYPE) {\n const sublayerUrl = `${url}/sublayers/${id}`;\n\n layers.push({\n url: sublayerUrl,\n id,\n layerType,\n visibility,\n ...rest\n });\n }\n\n if (subLayer?.sublayers?.length) {\n layers = [...layers, ...parseSublayersTree(subLayer.sublayers, url)];\n }\n }\n\n return layers;\n}\n"],"file":"parse-i3s-building-scene-layer.js"}
|
|
@@ -1,494 +0,0 @@
|
|
|
1
|
-
import { load, parse } from '@loaders.gl/core';
|
|
2
|
-
import { Vector3, Matrix4 } from '@math.gl/core';
|
|
3
|
-
import { Ellipsoid } from '@math.gl/geospatial';
|
|
4
|
-
import { ImageLoader } from '@loaders.gl/images';
|
|
5
|
-
import { DracoLoader } from '@loaders.gl/draco';
|
|
6
|
-
import { BasisLoader, CompressedTextureLoader } from '@loaders.gl/textures';
|
|
7
|
-
import { HeaderAttributeProperty } from '../../types';
|
|
8
|
-
import { getUrlWithToken } from '../utils/url-utils';
|
|
9
|
-
import { GL_TYPE_MAP, getConstructorForDataFormat, sizeOf, COORDINATE_SYSTEM } from './constants';
|
|
10
|
-
const scratchVector = new Vector3([0, 0, 0]);
|
|
11
|
-
|
|
12
|
-
function getLoaderForTextureFormat(textureFormat) {
|
|
13
|
-
switch (textureFormat) {
|
|
14
|
-
case 'ktx-etc2':
|
|
15
|
-
case 'dds':
|
|
16
|
-
return CompressedTextureLoader;
|
|
17
|
-
|
|
18
|
-
case 'ktx2':
|
|
19
|
-
return BasisLoader;
|
|
20
|
-
|
|
21
|
-
case 'jpg':
|
|
22
|
-
case 'png':
|
|
23
|
-
default:
|
|
24
|
-
return ImageLoader;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const I3S_ATTRIBUTE_TYPE = 'i3s-attribute-type';
|
|
29
|
-
export async function parseI3STileContent(arrayBuffer, tile, tileset, options, context) {
|
|
30
|
-
tile.content = tile.content || {};
|
|
31
|
-
tile.content.featureIds = tile.content.featureIds || null;
|
|
32
|
-
tile.content.attributes = {};
|
|
33
|
-
|
|
34
|
-
if (tile.textureUrl) {
|
|
35
|
-
var _options$i3s;
|
|
36
|
-
|
|
37
|
-
const url = getUrlWithToken(tile.textureUrl, options === null || options === void 0 ? void 0 : (_options$i3s = options.i3s) === null || _options$i3s === void 0 ? void 0 : _options$i3s.token);
|
|
38
|
-
const loader = getLoaderForTextureFormat(tile.textureFormat);
|
|
39
|
-
const response = await fetch(url);
|
|
40
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
41
|
-
|
|
42
|
-
if (options !== null && options !== void 0 && options.i3s.decodeTextures) {
|
|
43
|
-
if (loader === ImageLoader) {
|
|
44
|
-
const options = { ...tile.textureLoaderOptions,
|
|
45
|
-
image: {
|
|
46
|
-
type: 'data'
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
try {
|
|
51
|
-
tile.content.texture = await context.parse(arrayBuffer, options);
|
|
52
|
-
} catch (e) {
|
|
53
|
-
tile.content.texture = await parse(arrayBuffer, loader, options);
|
|
54
|
-
}
|
|
55
|
-
} else if (loader === CompressedTextureLoader || loader === BasisLoader) {
|
|
56
|
-
const texture = await load(arrayBuffer, loader, tile.textureLoaderOptions);
|
|
57
|
-
tile.content.texture = {
|
|
58
|
-
compressed: true,
|
|
59
|
-
mipmaps: false,
|
|
60
|
-
width: texture[0].width,
|
|
61
|
-
height: texture[0].height,
|
|
62
|
-
data: texture
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
} else {
|
|
66
|
-
tile.content.texture = arrayBuffer;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
tile.content.material = makePbrMaterial(tile.materialDefinition, tile.content.texture);
|
|
71
|
-
|
|
72
|
-
if (tile.content.material) {
|
|
73
|
-
tile.content.texture = null;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return await parseI3SNodeGeometry(arrayBuffer, tile, tileset, options);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
async function parseI3SNodeGeometry(arrayBuffer, tile, tileset, options) {
|
|
80
|
-
var _options$i3s2;
|
|
81
|
-
|
|
82
|
-
if (!tile.content) {
|
|
83
|
-
return tile;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const content = tile.content;
|
|
87
|
-
let attributes;
|
|
88
|
-
let vertexCount;
|
|
89
|
-
let byteOffset = 0;
|
|
90
|
-
let featureCount = 0;
|
|
91
|
-
let indices;
|
|
92
|
-
|
|
93
|
-
if (tile.isDracoGeometry) {
|
|
94
|
-
var _decompressedGeometry;
|
|
95
|
-
|
|
96
|
-
const decompressedGeometry = await parse(arrayBuffer, DracoLoader, {
|
|
97
|
-
draco: {
|
|
98
|
-
attributeNameEntry: I3S_ATTRIBUTE_TYPE
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
vertexCount = decompressedGeometry.header.vertexCount;
|
|
102
|
-
indices = (_decompressedGeometry = decompressedGeometry.indices) === null || _decompressedGeometry === void 0 ? void 0 : _decompressedGeometry.value;
|
|
103
|
-
const {
|
|
104
|
-
POSITION,
|
|
105
|
-
NORMAL,
|
|
106
|
-
COLOR_0,
|
|
107
|
-
TEXCOORD_0,
|
|
108
|
-
['feature-index']: featureIndex,
|
|
109
|
-
['uv-region']: uvRegion
|
|
110
|
-
} = decompressedGeometry.attributes;
|
|
111
|
-
attributes = {
|
|
112
|
-
position: POSITION,
|
|
113
|
-
normal: NORMAL,
|
|
114
|
-
color: COLOR_0,
|
|
115
|
-
uv0: TEXCOORD_0,
|
|
116
|
-
uvRegion,
|
|
117
|
-
id: featureIndex
|
|
118
|
-
};
|
|
119
|
-
updateAttributesMetadata(attributes, decompressedGeometry);
|
|
120
|
-
const featureIds = getFeatureIdsFromFeatureIndexMetadata(featureIndex);
|
|
121
|
-
|
|
122
|
-
if (featureIds) {
|
|
123
|
-
flattenFeatureIdsByFeatureIndices(attributes, featureIds);
|
|
124
|
-
}
|
|
125
|
-
} else {
|
|
126
|
-
const {
|
|
127
|
-
vertexAttributes,
|
|
128
|
-
ordering: attributesOrder,
|
|
129
|
-
featureAttributes,
|
|
130
|
-
featureAttributeOrder
|
|
131
|
-
} = tileset.store.defaultGeometrySchema;
|
|
132
|
-
const headers = parseHeaders(tileset, arrayBuffer);
|
|
133
|
-
byteOffset = headers.byteOffset;
|
|
134
|
-
vertexCount = headers.vertexCount;
|
|
135
|
-
featureCount = headers.featureCount;
|
|
136
|
-
const {
|
|
137
|
-
attributes: normalizedVertexAttributes,
|
|
138
|
-
byteOffset: offset
|
|
139
|
-
} = normalizeAttributes(arrayBuffer, byteOffset, vertexAttributes, vertexCount, attributesOrder);
|
|
140
|
-
const {
|
|
141
|
-
attributes: normalizedFeatureAttributes
|
|
142
|
-
} = normalizeAttributes(arrayBuffer, offset, featureAttributes, featureCount, featureAttributeOrder);
|
|
143
|
-
flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes);
|
|
144
|
-
attributes = concatAttributes(normalizedVertexAttributes, normalizedFeatureAttributes);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (!(options !== null && options !== void 0 && (_options$i3s2 = options.i3s) !== null && _options$i3s2 !== void 0 && _options$i3s2.coordinateSystem) || options.i3s.coordinateSystem === COORDINATE_SYSTEM.METER_OFFSETS) {
|
|
148
|
-
const enuMatrix = parsePositions(attributes.position, tile);
|
|
149
|
-
content.modelMatrix = enuMatrix.invert();
|
|
150
|
-
content.coordinateSystem = COORDINATE_SYSTEM.METER_OFFSETS;
|
|
151
|
-
} else {
|
|
152
|
-
content.modelMatrix = getModelMatrix(attributes.position);
|
|
153
|
-
content.coordinateSystem = COORDINATE_SYSTEM.LNGLAT_OFFSETS;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
content.attributes = {
|
|
157
|
-
positions: attributes.position,
|
|
158
|
-
normals: attributes.normal,
|
|
159
|
-
colors: normalizeAttribute(attributes.color),
|
|
160
|
-
texCoords: attributes.uv0,
|
|
161
|
-
uvRegions: normalizeAttribute(attributes.uvRegion)
|
|
162
|
-
};
|
|
163
|
-
content.indices = indices || null;
|
|
164
|
-
|
|
165
|
-
if (attributes.id && attributes.id.value) {
|
|
166
|
-
tile.content.featureIds = attributes.id.value;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
for (const attributeIndex in content.attributes) {
|
|
170
|
-
if (!content.attributes[attributeIndex]) {
|
|
171
|
-
delete content.attributes[attributeIndex];
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
content.vertexCount = vertexCount;
|
|
176
|
-
content.byteLength = arrayBuffer.byteLength;
|
|
177
|
-
return tile;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function updateAttributesMetadata(attributes, decompressedGeometry) {
|
|
181
|
-
for (const key in decompressedGeometry.loaderData.attributes) {
|
|
182
|
-
const dracoAttribute = decompressedGeometry.loaderData.attributes[key];
|
|
183
|
-
|
|
184
|
-
switch (dracoAttribute.name) {
|
|
185
|
-
case 'POSITION':
|
|
186
|
-
attributes.position.metadata = dracoAttribute.metadata;
|
|
187
|
-
break;
|
|
188
|
-
|
|
189
|
-
case 'feature-index':
|
|
190
|
-
attributes.id.metadata = dracoAttribute.metadata;
|
|
191
|
-
break;
|
|
192
|
-
|
|
193
|
-
default:
|
|
194
|
-
break;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function concatAttributes(normalizedVertexAttributes, normalizedFeatureAttributes) {
|
|
200
|
-
return { ...normalizedVertexAttributes,
|
|
201
|
-
...normalizedFeatureAttributes
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function normalizeAttribute(attribute) {
|
|
206
|
-
if (!attribute) {
|
|
207
|
-
return attribute;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
attribute.normalized = true;
|
|
211
|
-
return attribute;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function parseHeaders(tileset, arrayBuffer) {
|
|
215
|
-
let byteOffset = 0;
|
|
216
|
-
let vertexCount = 0;
|
|
217
|
-
let featureCount = 0;
|
|
218
|
-
|
|
219
|
-
for (const {
|
|
220
|
-
property,
|
|
221
|
-
type
|
|
222
|
-
} of tileset.store.defaultGeometrySchema.header) {
|
|
223
|
-
const TypedArrayTypeHeader = getConstructorForDataFormat(type);
|
|
224
|
-
|
|
225
|
-
switch (property) {
|
|
226
|
-
case HeaderAttributeProperty.vertexCount:
|
|
227
|
-
vertexCount = new TypedArrayTypeHeader(arrayBuffer, 0, 4)[0];
|
|
228
|
-
byteOffset += sizeOf(type);
|
|
229
|
-
break;
|
|
230
|
-
|
|
231
|
-
case HeaderAttributeProperty.featureCount:
|
|
232
|
-
featureCount = new TypedArrayTypeHeader(arrayBuffer, 4, 4)[0];
|
|
233
|
-
byteOffset += sizeOf(type);
|
|
234
|
-
break;
|
|
235
|
-
|
|
236
|
-
default:
|
|
237
|
-
break;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
return {
|
|
242
|
-
vertexCount,
|
|
243
|
-
featureCount,
|
|
244
|
-
byteOffset
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
function normalizeAttributes(arrayBuffer, byteOffset, vertexAttributes, vertexCount, attributesOrder) {
|
|
249
|
-
const attributes = {};
|
|
250
|
-
|
|
251
|
-
for (const attribute of attributesOrder) {
|
|
252
|
-
if (vertexAttributes[attribute]) {
|
|
253
|
-
const {
|
|
254
|
-
valueType,
|
|
255
|
-
valuesPerElement
|
|
256
|
-
} = vertexAttributes[attribute];
|
|
257
|
-
const count = vertexCount;
|
|
258
|
-
|
|
259
|
-
if (byteOffset + count * valuesPerElement > arrayBuffer.byteLength) {
|
|
260
|
-
break;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
const buffer = arrayBuffer.slice(byteOffset);
|
|
264
|
-
let value;
|
|
265
|
-
|
|
266
|
-
if (valueType === 'UInt64') {
|
|
267
|
-
value = parseUint64Values(buffer, count * valuesPerElement, sizeOf(valueType));
|
|
268
|
-
} else {
|
|
269
|
-
const TypedArrayType = getConstructorForDataFormat(valueType);
|
|
270
|
-
value = new TypedArrayType(buffer, 0, count * valuesPerElement);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
attributes[attribute] = {
|
|
274
|
-
value,
|
|
275
|
-
type: GL_TYPE_MAP[valueType],
|
|
276
|
-
size: valuesPerElement
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
switch (attribute) {
|
|
280
|
-
case 'color':
|
|
281
|
-
attributes.color.normalized = true;
|
|
282
|
-
break;
|
|
283
|
-
|
|
284
|
-
case 'position':
|
|
285
|
-
case 'region':
|
|
286
|
-
case 'normal':
|
|
287
|
-
default:
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
byteOffset = byteOffset + count * valuesPerElement * sizeOf(valueType);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
return {
|
|
295
|
-
attributes,
|
|
296
|
-
byteOffset
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
function parseUint64Values(buffer, elementsCount, attributeSize) {
|
|
301
|
-
const values = [];
|
|
302
|
-
const dataView = new DataView(buffer);
|
|
303
|
-
let offset = 0;
|
|
304
|
-
|
|
305
|
-
for (let index = 0; index < elementsCount; index++) {
|
|
306
|
-
const left = dataView.getUint32(offset, true);
|
|
307
|
-
const right = dataView.getUint32(offset + 4, true);
|
|
308
|
-
const value = left + 2 ** 32 * right;
|
|
309
|
-
values.push(value);
|
|
310
|
-
offset += attributeSize;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
return new Uint32Array(values);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
function parsePositions(attribute, tile) {
|
|
317
|
-
const mbs = tile.mbs;
|
|
318
|
-
const value = attribute.value;
|
|
319
|
-
const metadata = attribute.metadata;
|
|
320
|
-
const enuMatrix = new Matrix4();
|
|
321
|
-
const cartographicOrigin = new Vector3(mbs[0], mbs[1], mbs[2]);
|
|
322
|
-
const cartesianOrigin = new Vector3();
|
|
323
|
-
Ellipsoid.WGS84.cartographicToCartesian(cartographicOrigin, cartesianOrigin);
|
|
324
|
-
Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin, enuMatrix);
|
|
325
|
-
attribute.value = offsetsToCartesians(value, metadata, cartographicOrigin);
|
|
326
|
-
return enuMatrix;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
function offsetsToCartesians(vertices, metadata = {}, cartographicOrigin) {
|
|
330
|
-
const positions = new Float64Array(vertices.length);
|
|
331
|
-
const scaleX = metadata['i3s-scale_x'] && metadata['i3s-scale_x'].double || 1;
|
|
332
|
-
const scaleY = metadata['i3s-scale_y'] && metadata['i3s-scale_y'].double || 1;
|
|
333
|
-
|
|
334
|
-
for (let i = 0; i < positions.length; i += 3) {
|
|
335
|
-
positions[i] = vertices[i] * scaleX + cartographicOrigin.x;
|
|
336
|
-
positions[i + 1] = vertices[i + 1] * scaleY + cartographicOrigin.y;
|
|
337
|
-
positions[i + 2] = vertices[i + 2] + cartographicOrigin.z;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
for (let i = 0; i < positions.length; i += 3) {
|
|
341
|
-
Ellipsoid.WGS84.cartographicToCartesian(positions.subarray(i, i + 3), scratchVector);
|
|
342
|
-
positions[i] = scratchVector.x;
|
|
343
|
-
positions[i + 1] = scratchVector.y;
|
|
344
|
-
positions[i + 2] = scratchVector.z;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
return positions;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
function getModelMatrix(positions) {
|
|
351
|
-
var _metadata$i3sScale_x, _metadata$i3sScale_y;
|
|
352
|
-
|
|
353
|
-
const metadata = positions.metadata;
|
|
354
|
-
const scaleX = (metadata === null || metadata === void 0 ? void 0 : (_metadata$i3sScale_x = metadata['i3s-scale_x']) === null || _metadata$i3sScale_x === void 0 ? void 0 : _metadata$i3sScale_x.double) || 1;
|
|
355
|
-
const scaleY = (metadata === null || metadata === void 0 ? void 0 : (_metadata$i3sScale_y = metadata['i3s-scale_y']) === null || _metadata$i3sScale_y === void 0 ? void 0 : _metadata$i3sScale_y.double) || 1;
|
|
356
|
-
const modelMatrix = new Matrix4();
|
|
357
|
-
modelMatrix[0] = scaleX;
|
|
358
|
-
modelMatrix[5] = scaleY;
|
|
359
|
-
return modelMatrix;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
function makePbrMaterial(materialDefinition, texture) {
|
|
363
|
-
let pbrMaterial;
|
|
364
|
-
|
|
365
|
-
if (materialDefinition) {
|
|
366
|
-
pbrMaterial = { ...materialDefinition,
|
|
367
|
-
pbrMetallicRoughness: materialDefinition.pbrMetallicRoughness ? { ...materialDefinition.pbrMetallicRoughness
|
|
368
|
-
} : {
|
|
369
|
-
baseColorFactor: [255, 255, 255, 255]
|
|
370
|
-
}
|
|
371
|
-
};
|
|
372
|
-
} else {
|
|
373
|
-
pbrMaterial = {
|
|
374
|
-
pbrMetallicRoughness: {}
|
|
375
|
-
};
|
|
376
|
-
|
|
377
|
-
if (texture) {
|
|
378
|
-
pbrMaterial.pbrMetallicRoughness.baseColorTexture = {
|
|
379
|
-
texCoord: 0
|
|
380
|
-
};
|
|
381
|
-
} else {
|
|
382
|
-
pbrMaterial.pbrMetallicRoughness.baseColorFactor = [255, 255, 255, 255];
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
pbrMaterial.alphaCutoff = pbrMaterial.alphaCutoff || 0.25;
|
|
387
|
-
|
|
388
|
-
if (pbrMaterial.alphaMode) {
|
|
389
|
-
pbrMaterial.alphaMode = pbrMaterial.alphaMode.toUpperCase();
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
if (pbrMaterial.emissiveFactor) {
|
|
393
|
-
pbrMaterial.emissiveFactor = convertColorFormat(pbrMaterial.emissiveFactor);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
if (pbrMaterial.pbrMetallicRoughness && pbrMaterial.pbrMetallicRoughness.baseColorFactor) {
|
|
397
|
-
pbrMaterial.pbrMetallicRoughness.baseColorFactor = convertColorFormat(pbrMaterial.pbrMetallicRoughness.baseColorFactor);
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
if (texture) {
|
|
401
|
-
setMaterialTexture(pbrMaterial, texture);
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
return pbrMaterial;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
function convertColorFormat(colorFactor) {
|
|
408
|
-
const normalizedColor = [...colorFactor];
|
|
409
|
-
|
|
410
|
-
for (let index = 0; index < colorFactor.length; index++) {
|
|
411
|
-
normalizedColor[index] = colorFactor[index] / 255;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
return normalizedColor;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
function setMaterialTexture(material, image) {
|
|
418
|
-
const texture = {
|
|
419
|
-
source: {
|
|
420
|
-
image
|
|
421
|
-
}
|
|
422
|
-
};
|
|
423
|
-
|
|
424
|
-
if (material.pbrMetallicRoughness && material.pbrMetallicRoughness.baseColorTexture) {
|
|
425
|
-
material.pbrMetallicRoughness.baseColorTexture = { ...material.pbrMetallicRoughness.baseColorTexture,
|
|
426
|
-
texture
|
|
427
|
-
};
|
|
428
|
-
} else if (material.emissiveTexture) {
|
|
429
|
-
material.emissiveTexture = { ...material.emissiveTexture,
|
|
430
|
-
texture
|
|
431
|
-
};
|
|
432
|
-
} else if (material.pbrMetallicRoughness && material.pbrMetallicRoughness.metallicRoughnessTexture) {
|
|
433
|
-
material.pbrMetallicRoughness.metallicRoughnessTexture = { ...material.pbrMetallicRoughness.metallicRoughnessTexture,
|
|
434
|
-
texture
|
|
435
|
-
};
|
|
436
|
-
} else if (material.normalTexture) {
|
|
437
|
-
material.normalTexture = { ...material.normalTexture,
|
|
438
|
-
texture
|
|
439
|
-
};
|
|
440
|
-
} else if (material.occlusionTexture) {
|
|
441
|
-
material.occlusionTexture = { ...material.occlusionTexture,
|
|
442
|
-
texture
|
|
443
|
-
};
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
function flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes) {
|
|
448
|
-
const {
|
|
449
|
-
id,
|
|
450
|
-
faceRange
|
|
451
|
-
} = normalizedFeatureAttributes;
|
|
452
|
-
|
|
453
|
-
if (!id || !faceRange) {
|
|
454
|
-
return;
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
const featureIds = id.value;
|
|
458
|
-
const range = faceRange.value;
|
|
459
|
-
const featureIdsLength = range[range.length - 1] + 1;
|
|
460
|
-
const orderedFeatureIndices = new Uint32Array(featureIdsLength * 3);
|
|
461
|
-
let featureIndex = 0;
|
|
462
|
-
let startIndex = 0;
|
|
463
|
-
|
|
464
|
-
for (let index = 1; index < range.length; index += 2) {
|
|
465
|
-
const fillId = Number(featureIds[featureIndex]);
|
|
466
|
-
const endValue = range[index];
|
|
467
|
-
const prevValue = range[index - 1];
|
|
468
|
-
const trianglesCount = endValue - prevValue + 1;
|
|
469
|
-
const endIndex = startIndex + trianglesCount * 3;
|
|
470
|
-
orderedFeatureIndices.fill(fillId, startIndex, endIndex);
|
|
471
|
-
featureIndex++;
|
|
472
|
-
startIndex = endIndex;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
normalizedFeatureAttributes.id.value = orderedFeatureIndices;
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
function flattenFeatureIdsByFeatureIndices(attributes, featureIds) {
|
|
479
|
-
const featureIndices = attributes.id.value;
|
|
480
|
-
const result = new Float32Array(featureIndices.length);
|
|
481
|
-
|
|
482
|
-
for (let index = 0; index < featureIndices.length; index++) {
|
|
483
|
-
result[index] = featureIds[featureIndices[index]];
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
attributes.id.value = result;
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
function getFeatureIdsFromFeatureIndexMetadata(featureIndex) {
|
|
490
|
-
var _featureIndex$metadat, _featureIndex$metadat2;
|
|
491
|
-
|
|
492
|
-
return featureIndex === null || featureIndex === void 0 ? void 0 : (_featureIndex$metadat = featureIndex.metadata) === null || _featureIndex$metadat === void 0 ? void 0 : (_featureIndex$metadat2 = _featureIndex$metadat['i3s-feature-ids']) === null || _featureIndex$metadat2 === void 0 ? void 0 : _featureIndex$metadat2.intArray;
|
|
493
|
-
}
|
|
494
|
-
//# sourceMappingURL=parse-i3s-tile-content.js.map
|