@loaders.gl/3d-tiles 4.0.0-alpha.23 → 4.0.0-alpha.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/dist/cesium-ion-loader.d.ts +2 -2
  2. package/dist/cesium-ion-loader.d.ts.map +1 -1
  3. package/dist/dist.min.js +421 -270
  4. package/dist/es5/3d-tiles-archive-loader.js +1 -1
  5. package/dist/es5/cesium-ion-loader.js.map +1 -1
  6. package/dist/es5/lib/utils/version.js +1 -1
  7. package/dist/es5/tile-3d-subtree-loader.js.map +1 -1
  8. package/dist/es5/tile-3d-writer.js.map +1 -1
  9. package/dist/es5/types.js.map +1 -1
  10. package/dist/esm/3d-tiles-archive-loader.js +1 -1
  11. package/dist/esm/cesium-ion-loader.js.map +1 -1
  12. package/dist/esm/lib/utils/version.js +1 -1
  13. package/dist/esm/tile-3d-subtree-loader.js.map +1 -1
  14. package/dist/esm/tile-3d-writer.js.map +1 -1
  15. package/dist/esm/types.js.map +1 -1
  16. package/dist/tile-3d-subtree-loader.d.ts +3 -3
  17. package/dist/tile-3d-subtree-loader.d.ts.map +1 -1
  18. package/dist/tile-3d-writer.d.ts +2 -2
  19. package/dist/tile-3d-writer.d.ts.map +1 -1
  20. package/dist/types.d.ts +2 -5
  21. package/dist/types.d.ts.map +1 -1
  22. package/package.json +8 -8
  23. package/src/cesium-ion-loader.ts +2 -2
  24. package/src/tile-3d-subtree-loader.ts +3 -3
  25. package/src/tile-3d-writer.ts +2 -2
  26. package/src/types.ts +3 -5
  27. package/dist/3d-tiles-archive/3d-tiles-archive-archive.js +0 -72
  28. package/dist/3d-tiles-archive/3d-tiles-archive-parser.js +0 -33
  29. package/dist/3d-tiles-archive-loader.js +0 -31
  30. package/dist/bundle.js +0 -5
  31. package/dist/cesium-ion-loader.js +0 -40
  32. package/dist/index.js +0 -30
  33. package/dist/lib/classes/helpers/tile-3d-accessor-utils.js +0 -113
  34. package/dist/lib/classes/tile-3d-batch-table-hierarchy.js +0 -197
  35. package/dist/lib/classes/tile-3d-batch-table.js +0 -245
  36. package/dist/lib/classes/tile-3d-feature-table.js +0 -72
  37. package/dist/lib/constants.js +0 -26
  38. package/dist/lib/encoders/encode-3d-tile-batched-model.js +0 -46
  39. package/dist/lib/encoders/encode-3d-tile-composite.js +0 -24
  40. package/dist/lib/encoders/encode-3d-tile-instanced-model.js +0 -38
  41. package/dist/lib/encoders/encode-3d-tile-point-cloud.js +0 -39
  42. package/dist/lib/encoders/encode-3d-tile.js +0 -33
  43. package/dist/lib/encoders/helpers/encode-3d-tile-header.js +0 -30
  44. package/dist/lib/filesystems/tiles-3d-archive-file-system.js +0 -75
  45. package/dist/lib/ion/ion.js +0 -68
  46. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js +0 -65
  47. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js +0 -30
  48. package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js +0 -42
  49. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js +0 -303
  50. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js +0 -96
  51. package/dist/lib/parsers/helpers/parse-3d-tile-header.js +0 -28
  52. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js +0 -87
  53. package/dist/lib/parsers/helpers/parse-3d-tile-tables.js +0 -93
  54. package/dist/lib/parsers/helpers/parse-utils.js +0 -32
  55. package/dist/lib/parsers/parse-3d-tile-batched-model.js +0 -33
  56. package/dist/lib/parsers/parse-3d-tile-composite.js +0 -24
  57. package/dist/lib/parsers/parse-3d-tile-gltf.js +0 -29
  58. package/dist/lib/parsers/parse-3d-tile-header.js +0 -194
  59. package/dist/lib/parsers/parse-3d-tile-instanced-model.js +0 -172
  60. package/dist/lib/parsers/parse-3d-tile-point-cloud.js +0 -441
  61. package/dist/lib/parsers/parse-3d-tile.js +0 -33
  62. package/dist/lib/utils/obb/s2-corners-to-obb.js +0 -37
  63. package/dist/lib/utils/s2/converters/s2-to-boundary.js +0 -61
  64. package/dist/lib/utils/s2/converters/s2-to-obb-points.js +0 -36
  65. package/dist/lib/utils/s2/converters/s2-to-region.js +0 -59
  66. package/dist/lib/utils/s2/index.js +0 -23
  67. package/dist/lib/utils/s2/s2-geometry-functions.js +0 -29
  68. package/dist/lib/utils/s2/s2-token-functions.js +0 -68
  69. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js +0 -32
  70. package/dist/lib/utils/s2/s2geometry/s2-geometry.js +0 -260
  71. package/dist/lib/utils/version.js +0 -7
  72. package/dist/tile-3d-subtree-loader.js +0 -23
  73. package/dist/tile-3d-writer.js +0 -27
  74. package/dist/tiles-3d-loader.js +0 -80
  75. package/dist/types.js +0 -2
@@ -1,24 +0,0 @@
1
- "use strict";
2
- // This file is derived from the Cesium code base under Apache 2 license
3
- // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.parseComposite3DTile = void 0;
6
- const parse_3d_tile_header_1 = require("./helpers/parse-3d-tile-header");
7
- // eslint-disable-next-line max-params
8
- async function parseComposite3DTile(tile, arrayBuffer, byteOffset, options, context, parse3DTile) {
9
- byteOffset = (0, parse_3d_tile_header_1.parse3DTileHeaderSync)(tile, arrayBuffer, byteOffset);
10
- const view = new DataView(arrayBuffer);
11
- // Extract number of tiles
12
- tile.tilesLength = view.getUint32(byteOffset, true);
13
- byteOffset += 4;
14
- // extract each tile from the byte stream
15
- tile.tiles = [];
16
- while (tile.tiles.length < tile.tilesLength && (tile.byteLength || 0) - byteOffset > 12) {
17
- const subtile = { shape: 'tile3d' };
18
- tile.tiles.push(subtile);
19
- byteOffset = await parse3DTile(arrayBuffer, byteOffset, options, context, subtile);
20
- // TODO - do we need to add any padding in between tiles?
21
- }
22
- return byteOffset;
23
- }
24
- exports.parseComposite3DTile = parseComposite3DTile;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.parseGltf3DTile = void 0;
5
- const loader_utils_1 = require("@loaders.gl/loader-utils");
6
- const gltf_1 = require("@loaders.gl/gltf");
7
- async function parseGltf3DTile(tile, arrayBuffer, options, context) {
8
- // Set flags
9
- // glTF models need to be rotated from Y to Z up
10
- // https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification#y-up-to-z-up
11
- tile.rotateYtoZ = true;
12
- // Save gltf up axis
13
- tile.gltfUpAxis = options?.['3d-tiles']?.assetGltfUpAxis
14
- ? options['3d-tiles'].assetGltfUpAxis
15
- : 'Y';
16
- if (options?.['3d-tiles']?.loadGLTF) {
17
- if (!context) {
18
- return arrayBuffer.byteLength;
19
- }
20
- const gltfWithBuffers = await (0, loader_utils_1.parseFromContext)(arrayBuffer, gltf_1.GLTFLoader, options, context);
21
- tile.gltf = (0, gltf_1.postProcessGLTF)(gltfWithBuffers);
22
- tile.gpuMemoryUsageInBytes = (0, gltf_1._getMemoryUsageGLTF)(tile.gltf);
23
- }
24
- else {
25
- tile.gltfArrayBuffer = arrayBuffer;
26
- }
27
- return arrayBuffer.byteLength;
28
- }
29
- exports.parseGltf3DTile = parseGltf3DTile;
@@ -1,194 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeImplicitTileData = exports.normalizeImplicitTileHeaders = exports.normalizeTileHeaders = exports.normalizeTileData = void 0;
4
- const loader_utils_1 = require("@loaders.gl/loader-utils");
5
- const tile_3d_subtree_loader_1 = require("../../tile-3d-subtree-loader");
6
- const core_1 = require("@loaders.gl/core");
7
- const tiles_1 = require("@loaders.gl/tiles");
8
- const parse_3d_implicit_tiles_1 = require("./helpers/parse-3d-implicit-tiles");
9
- const s2_corners_to_obb_1 = require("../utils/obb/s2-corners-to-obb");
10
- function getTileType(tile, tileContentUrl = '') {
11
- if (!tileContentUrl) {
12
- return tiles_1.TILE_TYPE.EMPTY;
13
- }
14
- const contentUrl = tileContentUrl.split('?')[0]; // Discard query string
15
- const fileExtension = contentUrl.split('.').pop();
16
- switch (fileExtension) {
17
- case 'pnts':
18
- return tiles_1.TILE_TYPE.POINTCLOUD;
19
- case 'i3dm':
20
- case 'b3dm':
21
- case 'glb':
22
- case 'gltf':
23
- return tiles_1.TILE_TYPE.SCENEGRAPH;
24
- default:
25
- return fileExtension || tiles_1.TILE_TYPE.EMPTY;
26
- }
27
- }
28
- function getRefine(refine) {
29
- switch (refine) {
30
- case 'REPLACE':
31
- case 'replace':
32
- return tiles_1.TILE_REFINEMENT.REPLACE;
33
- case 'ADD':
34
- case 'add':
35
- return tiles_1.TILE_REFINEMENT.ADD;
36
- default:
37
- return refine;
38
- }
39
- }
40
- function resolveUri(uri = '', basePath) {
41
- // url scheme per RFC3986
42
- const urlSchemeRegex = /^[a-z][0-9a-z+.-]*:/i;
43
- if (urlSchemeRegex.test(basePath)) {
44
- const url = new URL(uri, `${basePath}/`);
45
- return decodeURI(url.toString());
46
- }
47
- else if (uri.startsWith('/')) {
48
- return uri;
49
- }
50
- return loader_utils_1.path.resolve(basePath, uri);
51
- }
52
- function normalizeTileData(tile, basePath) {
53
- if (!tile) {
54
- return null;
55
- }
56
- let tileContentUrl;
57
- if (tile.content) {
58
- const contentUri = tile.content.uri || tile.content?.url;
59
- tileContentUrl = resolveUri(contentUri, basePath);
60
- }
61
- const tilePostprocessed = {
62
- ...tile,
63
- id: tileContentUrl,
64
- contentUrl: tileContentUrl,
65
- lodMetricType: tiles_1.LOD_METRIC_TYPE.GEOMETRIC_ERROR,
66
- lodMetricValue: tile.geometricError,
67
- transformMatrix: tile.transform,
68
- type: getTileType(tile, tileContentUrl),
69
- refine: getRefine(tile.refine)
70
- };
71
- return tilePostprocessed;
72
- }
73
- exports.normalizeTileData = normalizeTileData;
74
- // normalize tile headers
75
- async function normalizeTileHeaders(tileset, basePath, options) {
76
- let root = null;
77
- const rootImplicitTilingExtension = getImplicitTilingExtensionData(tileset.root);
78
- if (rootImplicitTilingExtension && tileset.root) {
79
- root = await normalizeImplicitTileHeaders(tileset.root, tileset, basePath, rootImplicitTilingExtension, options);
80
- }
81
- else {
82
- root = normalizeTileData(tileset.root, basePath);
83
- }
84
- const stack = [];
85
- stack.push(root);
86
- while (stack.length > 0) {
87
- const tile = stack.pop() || {};
88
- const children = tile.children || [];
89
- const childrenPostprocessed = [];
90
- for (const childHeader of children) {
91
- const childImplicitTilingExtension = getImplicitTilingExtensionData(childHeader);
92
- let childHeaderPostprocessed;
93
- if (childImplicitTilingExtension) {
94
- childHeaderPostprocessed = await normalizeImplicitTileHeaders(childHeader, tileset, basePath, childImplicitTilingExtension, options);
95
- }
96
- else {
97
- childHeaderPostprocessed = normalizeTileData(childHeader, basePath);
98
- }
99
- if (childHeaderPostprocessed) {
100
- childrenPostprocessed.push(childHeaderPostprocessed);
101
- stack.push(childHeaderPostprocessed);
102
- }
103
- }
104
- tile.children = childrenPostprocessed;
105
- }
106
- return root;
107
- }
108
- exports.normalizeTileHeaders = normalizeTileHeaders;
109
- /**
110
- * Do normalisation of implicit tile headers
111
- * TODO Check if Tile3D class can be a return type here.
112
- * @param tileset
113
- */
114
- async function normalizeImplicitTileHeaders(tile, tileset, basePath, implicitTilingExtension, options) {
115
- const { subdivisionScheme, maximumLevel, availableLevels, subtreeLevels, subtrees: { uri: subtreesUriTemplate } } = implicitTilingExtension;
116
- const replacedUrlTemplate = (0, parse_3d_implicit_tiles_1.replaceContentUrlTemplate)(subtreesUriTemplate, 0, 0, 0, 0);
117
- const subtreeUrl = resolveUri(replacedUrlTemplate, basePath);
118
- const subtree = await (0, core_1.load)(subtreeUrl, tile_3d_subtree_loader_1.Tile3DSubtreeLoader, options);
119
- const contentUrlTemplate = resolveUri(tile.content?.uri, basePath);
120
- const refine = tileset?.root?.refine;
121
- // @ts-ignore
122
- const rootLodMetricValue = tile.geometricError;
123
- // Replace tile.boundingVolume with the the bounding volume specified by the extensions['3DTILES_bounding_volume_S2']
124
- const s2VolumeInfo = tile.boundingVolume.extensions?.['3DTILES_bounding_volume_S2'];
125
- if (s2VolumeInfo) {
126
- const box = (0, s2_corners_to_obb_1.convertS2BoundingVolumetoOBB)(s2VolumeInfo);
127
- const s2VolumeBox = { box, s2VolumeInfo };
128
- tile.boundingVolume = s2VolumeBox;
129
- }
130
- const rootBoundingVolume = tile.boundingVolume;
131
- const implicitOptions = {
132
- contentUrlTemplate,
133
- subtreesUriTemplate,
134
- subdivisionScheme,
135
- subtreeLevels,
136
- maximumLevel: Number.isFinite(availableLevels) ? availableLevels - 1 : maximumLevel,
137
- refine,
138
- basePath,
139
- lodMetricType: tiles_1.LOD_METRIC_TYPE.GEOMETRIC_ERROR,
140
- rootLodMetricValue,
141
- rootBoundingVolume,
142
- getTileType,
143
- getRefine
144
- };
145
- return await normalizeImplicitTileData(tile, basePath, subtree, implicitOptions, options);
146
- }
147
- exports.normalizeImplicitTileHeaders = normalizeImplicitTileHeaders;
148
- /**
149
- * Do implicit data normalisation to create hierarchical tile structure
150
- * @param tile
151
- * @param rootSubtree
152
- * @param options
153
- * @returns
154
- */
155
- async function normalizeImplicitTileData(tile, basePath, rootSubtree, implicitOptions, loaderOptions) {
156
- if (!tile) {
157
- return null;
158
- }
159
- const { children, contentUrl } = await (0, parse_3d_implicit_tiles_1.parseImplicitTiles)({
160
- subtree: rootSubtree,
161
- implicitOptions,
162
- loaderOptions
163
- });
164
- let tileContentUrl;
165
- let tileContent = null;
166
- if (contentUrl) {
167
- tileContentUrl = contentUrl;
168
- tileContent = { uri: contentUrl.replace(`${basePath}/`, '') };
169
- }
170
- const tilePostprocessed = {
171
- ...tile,
172
- id: tileContentUrl,
173
- contentUrl: tileContentUrl,
174
- lodMetricType: tiles_1.LOD_METRIC_TYPE.GEOMETRIC_ERROR,
175
- lodMetricValue: tile.geometricError,
176
- transformMatrix: tile.transform,
177
- type: getTileType(tile, tileContentUrl),
178
- refine: getRefine(tile.refine),
179
- content: tileContent || tile.content,
180
- children
181
- };
182
- return tilePostprocessed;
183
- }
184
- exports.normalizeImplicitTileData = normalizeImplicitTileData;
185
- /**
186
- * Implicit Tiling data can be in 3DTILES_implicit_tiling for 3DTiles v.Next or directly in implicitTiling object for 3DTiles v1.1.
187
- * Spec 3DTiles v.Next - https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_implicit_tiling
188
- * Spec 3DTiles v.1.1 - https://github.com/CesiumGS/3d-tiles/tree/draft-1.1/specification/ImplicitTiling
189
- * @param tile
190
- * @returns
191
- */
192
- function getImplicitTilingExtensionData(tile) {
193
- return tile?.extensions?.['3DTILES_implicit_tiling'] || tile?.implicitTiling;
194
- }
@@ -1,172 +0,0 @@
1
- "use strict";
2
- // This file is derived from the Cesium code base under Apache 2 license
3
- // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
4
- var __importDefault = (this && this.__importDefault) || function (mod) {
5
- return (mod && mod.__esModule) ? mod : { "default": mod };
6
- };
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.parseInstancedModel3DTile = void 0;
9
- const core_1 = require("@math.gl/core");
10
- const geospatial_1 = require("@math.gl/geospatial");
11
- const math_1 = require("@loaders.gl/math"); // 'math.gl/geometry';
12
- const tile_3d_feature_table_1 = __importDefault(require("../classes/tile-3d-feature-table"));
13
- const tile_3d_batch_table_1 = __importDefault(require("../classes/tile-3d-batch-table"));
14
- const parse_3d_tile_header_1 = require("./helpers/parse-3d-tile-header");
15
- const parse_3d_tile_tables_1 = require("./helpers/parse-3d-tile-tables");
16
- const parse_3d_tile_gltf_view_1 = require("./helpers/parse-3d-tile-gltf-view");
17
- async function parseInstancedModel3DTile(tile, arrayBuffer, byteOffset, options, context) {
18
- byteOffset = parseInstancedModel(tile, arrayBuffer, byteOffset, options, context);
19
- await (0, parse_3d_tile_gltf_view_1.extractGLTF)(tile, tile.gltfFormat || 0, options, context);
20
- return byteOffset;
21
- }
22
- exports.parseInstancedModel3DTile = parseInstancedModel3DTile;
23
- function parseInstancedModel(tile, arrayBuffer, byteOffset, options, context) {
24
- byteOffset = (0, parse_3d_tile_header_1.parse3DTileHeaderSync)(tile, arrayBuffer, byteOffset);
25
- if (tile.version !== 1) {
26
- throw new Error(`Instanced 3D Model version ${tile.version} is not supported`);
27
- }
28
- byteOffset = (0, parse_3d_tile_tables_1.parse3DTileTablesHeaderSync)(tile, arrayBuffer, byteOffset);
29
- const view = new DataView(arrayBuffer);
30
- tile.gltfFormat = view.getUint32(byteOffset, true);
31
- byteOffset += 4;
32
- // PARSE FEATURE TABLE
33
- byteOffset = (0, parse_3d_tile_tables_1.parse3DTileTablesSync)(tile, arrayBuffer, byteOffset, options);
34
- byteOffset = (0, parse_3d_tile_gltf_view_1.parse3DTileGLTFViewSync)(tile, arrayBuffer, byteOffset, options);
35
- // TODO - Is the feature table sometimes optional or can check be moved into table header parser?
36
- if (!tile?.header?.featureTableJsonByteLength || tile.header.featureTableJsonByteLength === 0) {
37
- throw new Error('i3dm parser: featureTableJsonByteLength is zero.');
38
- }
39
- const featureTable = new tile_3d_feature_table_1.default(tile.featureTableJson, tile.featureTableBinary);
40
- const instancesLength = featureTable.getGlobalProperty('INSTANCES_LENGTH');
41
- featureTable.featuresLength = instancesLength;
42
- if (!Number.isFinite(instancesLength)) {
43
- throw new Error('i3dm parser: INSTANCES_LENGTH must be defined');
44
- }
45
- tile.eastNorthUp = featureTable.getGlobalProperty('EAST_NORTH_UP');
46
- tile.rtcCenter = featureTable.getGlobalProperty('RTC_CENTER', math_1.GL.FLOAT, 3);
47
- const batchTable = new tile_3d_batch_table_1.default(tile.batchTableJson, tile.batchTableBinary, instancesLength);
48
- extractInstancedAttributes(tile, featureTable, batchTable, instancesLength);
49
- return byteOffset;
50
- }
51
- // eslint-disable-next-line max-statements, complexity
52
- function extractInstancedAttributes(tile, featureTable, batchTable, instancesLength) {
53
- const instances = new Array(instancesLength);
54
- const instancePosition = new core_1.Vector3();
55
- const instanceNormalRight = new core_1.Vector3();
56
- const instanceNormalUp = new core_1.Vector3();
57
- const instanceNormalForward = new core_1.Vector3();
58
- const instanceRotation = new core_1.Matrix3();
59
- const instanceQuaternion = new core_1.Quaternion();
60
- const instanceScale = new core_1.Vector3();
61
- const instanceTranslationRotationScale = {};
62
- const instanceTransform = new core_1.Matrix4();
63
- const scratch1 = [];
64
- const scratch2 = [];
65
- const scratch3 = [];
66
- const scratch4 = [];
67
- for (let i = 0; i < instancesLength; i++) {
68
- let position;
69
- // Get the instance position
70
- if (featureTable.hasProperty('POSITION')) {
71
- position = featureTable.getProperty('POSITION', math_1.GL.FLOAT, 3, i, instancePosition);
72
- }
73
- else if (featureTable.hasProperty('POSITION_QUANTIZED')) {
74
- position = featureTable.getProperty('POSITION_QUANTIZED', math_1.GL.UNSIGNED_SHORT, 3, i, instancePosition);
75
- const quantizedVolumeOffset = featureTable.getGlobalProperty('QUANTIZED_VOLUME_OFFSET', math_1.GL.FLOAT, 3);
76
- if (!quantizedVolumeOffset) {
77
- throw new Error('i3dm parser: QUANTIZED_VOLUME_OFFSET must be defined for quantized positions.');
78
- }
79
- const quantizedVolumeScale = featureTable.getGlobalProperty('QUANTIZED_VOLUME_SCALE', math_1.GL.FLOAT, 3);
80
- if (!quantizedVolumeScale) {
81
- throw new Error('i3dm parser: QUANTIZED_VOLUME_SCALE must be defined for quantized positions.');
82
- }
83
- const MAX_UNSIGNED_SHORT = 65535.0;
84
- for (let j = 0; j < 3; j++) {
85
- position[j] =
86
- (position[j] / MAX_UNSIGNED_SHORT) * quantizedVolumeScale[j] + quantizedVolumeOffset[j];
87
- }
88
- }
89
- if (!position) {
90
- throw new Error('i3dm: POSITION or POSITION_QUANTIZED must be defined for each instance.');
91
- }
92
- instancePosition.copy(position);
93
- // @ts-expect-error
94
- instanceTranslationRotationScale.translation = instancePosition;
95
- // Get the instance rotation
96
- tile.normalUp = featureTable.getProperty('NORMAL_UP', math_1.GL.FLOAT, 3, i, scratch1);
97
- tile.normalRight = featureTable.getProperty('NORMAL_RIGHT', math_1.GL.FLOAT, 3, i, scratch2);
98
- const hasCustomOrientation = false;
99
- if (tile.normalUp) {
100
- if (!tile.normalRight) {
101
- throw new Error('i3dm: Custom orientation requires both NORMAL_UP and NORMAL_RIGHT.');
102
- }
103
- // Vector3.unpack(normalUp, 0, instanceNormalUp);
104
- // Vector3.unpack(normalRight, 0, instanceNormalRight);
105
- tile.hasCustomOrientation = true;
106
- }
107
- else {
108
- tile.octNormalUp = featureTable.getProperty('NORMAL_UP_OCT32P', math_1.GL.UNSIGNED_SHORT, 2, i, scratch1);
109
- tile.octNormalRight = featureTable.getProperty('NORMAL_RIGHT_OCT32P', math_1.GL.UNSIGNED_SHORT, 2, i, scratch2);
110
- if (tile.octNormalUp) {
111
- if (!tile.octNormalRight) {
112
- throw new Error('i3dm: oct-encoded orientation requires NORMAL_UP_OCT32P and NORMAL_RIGHT_OCT32P');
113
- }
114
- throw new Error('i3dm: oct-encoded orientation not implemented');
115
- /*
116
- AttributeCompression.octDecodeInRange(octNormalUp[0], octNormalUp[1], 65535, instanceNormalUp);
117
- AttributeCompression.octDecodeInRange(octNormalRight[0], octNormalRight[1], 65535, instanceNormalRight);
118
- hasCustomOrientation = true;
119
- */
120
- }
121
- else if (tile.eastNorthUp) {
122
- geospatial_1.Ellipsoid.WGS84.eastNorthUpToFixedFrame(instancePosition, instanceTransform);
123
- instanceTransform.getRotationMatrix3(instanceRotation);
124
- }
125
- else {
126
- instanceRotation.identity();
127
- }
128
- }
129
- if (hasCustomOrientation) {
130
- instanceNormalForward.copy(instanceNormalRight).cross(instanceNormalUp).normalize();
131
- instanceRotation.setColumn(0, instanceNormalRight);
132
- instanceRotation.setColumn(1, instanceNormalUp);
133
- instanceRotation.setColumn(2, instanceNormalForward);
134
- }
135
- instanceQuaternion.fromMatrix3(instanceRotation);
136
- // @ts-expect-error
137
- instanceTranslationRotationScale.rotation = instanceQuaternion;
138
- // Get the instance scale
139
- instanceScale.set(1.0, 1.0, 1.0);
140
- const scale = featureTable.getProperty('SCALE', math_1.GL.FLOAT, 1, i, scratch3);
141
- if (Number.isFinite(scale)) {
142
- instanceScale.multiplyByScalar(scale);
143
- }
144
- const nonUniformScale = featureTable.getProperty('SCALE_NON_UNIFORM', math_1.GL.FLOAT, 3, i, scratch1);
145
- if (nonUniformScale) {
146
- instanceScale.scale(nonUniformScale);
147
- }
148
- // @ts-expect-error
149
- instanceTranslationRotationScale.scale = instanceScale;
150
- // Get the batchId
151
- let batchId = featureTable.getProperty('BATCH_ID', math_1.GL.UNSIGNED_SHORT, 1, i, scratch4);
152
- if (batchId === undefined) {
153
- // If BATCH_ID semantic is undefined, batchId is just the instance number
154
- batchId = i;
155
- }
156
- // @ts-expect-error
157
- const rotationMatrix = new core_1.Matrix4().fromQuaternion(instanceTranslationRotationScale.rotation);
158
- // Create the model matrix and the instance
159
- instanceTransform.identity();
160
- // @ts-expect-error
161
- instanceTransform.translate(instanceTranslationRotationScale.translation);
162
- instanceTransform.multiplyRight(rotationMatrix);
163
- // @ts-expect-error
164
- instanceTransform.scale(instanceTranslationRotationScale.scale);
165
- const modelMatrix = instanceTransform.clone();
166
- instances[i] = {
167
- modelMatrix,
168
- batchId
169
- };
170
- }
171
- tile.instances = instances;
172
- }