@loaders.gl/3d-tiles 4.2.0-alpha.3 → 4.2.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/3d-tiles-archive/3d-tiles-archive-archive.js +66 -41
- package/dist/3d-tiles-archive/3d-tiles-archive-parser.d.ts +1 -1
- package/dist/3d-tiles-archive/3d-tiles-archive-parser.d.ts.map +1 -1
- package/dist/3d-tiles-archive/3d-tiles-archive-parser.js +26 -16
- package/dist/3d-tiles-archive-loader.js +26 -15
- package/dist/cesium-ion-loader.js +34 -30
- package/dist/dist.dev.js +1963 -1037
- package/dist/dist.min.js +32 -0
- package/dist/index.cjs +122 -337
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +13 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/lib/classes/helpers/tile-3d-accessor-utils.js +103 -87
- package/dist/lib/classes/tile-3d-batch-table-hierarchy.js +179 -155
- package/dist/lib/classes/tile-3d-batch-table.js +232 -217
- package/dist/lib/classes/tile-3d-feature-table.js +62 -59
- package/dist/lib/constants.js +19 -15
- package/dist/lib/encoders/encode-3d-tile-batched-model.js +40 -35
- package/dist/lib/encoders/encode-3d-tile-composite.js +19 -17
- package/dist/lib/encoders/encode-3d-tile-instanced-model.js +32 -31
- package/dist/lib/encoders/encode-3d-tile-point-cloud.js +31 -32
- package/dist/lib/encoders/encode-3d-tile.js +23 -19
- package/dist/lib/encoders/helpers/encode-3d-tile-header.js +23 -23
- package/dist/lib/ion/ion.js +55 -54
- package/dist/lib/parsers/helpers/normalize-3d-tile-colors.d.ts +1 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-colors.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js +57 -51
- package/dist/lib/parsers/helpers/normalize-3d-tile-normals.d.ts +1 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-normals.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js +21 -18
- package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js +35 -20
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts +4 -4
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js +269 -234
- package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts +2 -2
- package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js +83 -55
- package/dist/lib/parsers/helpers/parse-3d-tile-header.d.ts +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-header.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-header.js +23 -14
- package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js +82 -54
- package/dist/lib/parsers/helpers/parse-3d-tile-tables.d.ts +2 -2
- package/dist/lib/parsers/helpers/parse-3d-tile-tables.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-tables.js +79 -68
- package/dist/lib/parsers/helpers/parse-utils.js +19 -14
- package/dist/lib/parsers/parse-3d-tile-batched-model.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-batched-model.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-batched-model.js +21 -17
- package/dist/lib/parsers/parse-3d-tile-composite.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-composite.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-composite.js +18 -14
- package/dist/lib/parsers/parse-3d-tile-gltf.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-gltf.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-gltf.js +22 -14
- package/dist/lib/parsers/parse-3d-tile-header.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-header.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-header.js +168 -159
- package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-instanced-model.js +153 -123
- package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-point-cloud.js +380 -174
- package/dist/lib/parsers/parse-3d-tile.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile.js +24 -24
- package/dist/lib/utils/obb/s2-corners-to-obb.js +29 -16
- package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts +1 -1
- package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts.map +1 -1
- package/dist/lib/utils/s2/converters/s2-to-boundary.js +55 -35
- package/dist/lib/utils/s2/converters/s2-to-obb-points.js +31 -20
- package/dist/lib/utils/s2/converters/s2-to-region.d.ts +1 -1
- package/dist/lib/utils/s2/converters/s2-to-region.d.ts.map +1 -1
- package/dist/lib/utils/s2/converters/s2-to-region.js +51 -35
- package/dist/lib/utils/s2/index.d.ts +7 -7
- package/dist/lib/utils/s2/index.d.ts.map +1 -1
- package/dist/lib/utils/s2/index.js +3 -1
- package/dist/lib/utils/s2/s2-geometry-functions.js +19 -5
- package/dist/lib/utils/s2/s2-token-functions.js +51 -22
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts +1 -1
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts.map +1 -1
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js +23 -9
- package/dist/lib/utils/s2/s2geometry/s2-geometry.js +218 -157
- package/dist/lib/utils/version.js +4 -2
- package/dist/tile-3d-subtree-loader.d.ts +1 -1
- package/dist/tile-3d-subtree-loader.d.ts.map +1 -1
- package/dist/tile-3d-subtree-loader.js +15 -10
- package/dist/tile-3d-writer.js +19 -14
- package/dist/tiles-3d-loader.js +65 -55
- package/dist/types.js +3 -1
- package/package.json +11 -10
- package/dist/3d-tiles-archive/3d-tiles-archive-archive.js.map +0 -1
- package/dist/3d-tiles-archive/3d-tiles-archive-parser.js.map +0 -1
- package/dist/3d-tiles-archive-loader.js.map +0 -1
- package/dist/cesium-ion-loader.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/classes/helpers/tile-3d-accessor-utils.js.map +0 -1
- package/dist/lib/classes/tile-3d-batch-table-hierarchy.js.map +0 -1
- package/dist/lib/classes/tile-3d-batch-table.js.map +0 -1
- package/dist/lib/classes/tile-3d-feature-table.js.map +0 -1
- package/dist/lib/constants.js.map +0 -1
- package/dist/lib/encoders/encode-3d-tile-batched-model.js.map +0 -1
- package/dist/lib/encoders/encode-3d-tile-composite.js.map +0 -1
- package/dist/lib/encoders/encode-3d-tile-instanced-model.js.map +0 -1
- package/dist/lib/encoders/encode-3d-tile-point-cloud.js.map +0 -1
- package/dist/lib/encoders/encode-3d-tile.js.map +0 -1
- package/dist/lib/encoders/helpers/encode-3d-tile-header.js.map +0 -1
- package/dist/lib/ion/ion.js.map +0 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js.map +0 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js.map +0 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-header.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-tables.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-utils.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-batched-model.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-composite.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-gltf.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-header.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-instanced-model.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-point-cloud.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile.js.map +0 -1
- package/dist/lib/utils/obb/s2-corners-to-obb.js.map +0 -1
- package/dist/lib/utils/s2/converters/s2-to-boundary.js.map +0 -1
- package/dist/lib/utils/s2/converters/s2-to-obb-points.js.map +0 -1
- package/dist/lib/utils/s2/converters/s2-to-region.js.map +0 -1
- package/dist/lib/utils/s2/index.js.map +0 -1
- package/dist/lib/utils/s2/s2-geometry-functions.js.map +0 -1
- package/dist/lib/utils/s2/s2-token-functions.js.map +0 -1
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js.map +0 -1
- package/dist/lib/utils/s2/s2geometry/s2-geometry.js.map +0 -1
- package/dist/lib/utils/version.js.map +0 -1
- package/dist/tile-3d-subtree-loader.js.map +0 -1
- package/dist/tile-3d-writer.js.map +0 -1
- package/dist/tiles-3d-loader.js.map +0 -1
- package/dist/types.js.map +0 -1
|
@@ -1,230 +1,245 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT AND Apache-2.0
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
// This file is derived from the Cesium code base under Apache 2 license
|
|
5
|
+
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
1
6
|
import { assert } from '@loaders.gl/loader-utils';
|
|
2
7
|
import { createTypedArrayFromAccessor } from "./helpers/tile-3d-accessor-utils.js";
|
|
3
8
|
import { initializeHierarchy, traverseHierarchy } from "./tile-3d-batch-table-hierarchy.js";
|
|
4
9
|
function defined(x) {
|
|
5
|
-
|
|
10
|
+
return x !== undefined && x !== null;
|
|
6
11
|
}
|
|
7
12
|
const clone = (x, y) => x;
|
|
13
|
+
// These top level fields in the batch table json are not properties
|
|
8
14
|
const IGNORED_PROPERTY_FIELDS = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
HIERARCHY: true, // Deprecated HIERARCHY property
|
|
16
|
+
extensions: true,
|
|
17
|
+
extras: true
|
|
12
18
|
};
|
|
19
|
+
// The size of this array equals the maximum instance count among all loaded tiles, which has the potential to be large.
|
|
13
20
|
export default class Tile3DBatchTableParser {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
this.binary = binary;
|
|
27
|
-
this.featureCount = featureCount;
|
|
28
|
-
this._extensions = ((_this$json = this.json) === null || _this$json === void 0 ? void 0 : _this$json.extensions) || {};
|
|
29
|
-
this._properties = {};
|
|
30
|
-
for (const propertyName in this.json) {
|
|
31
|
-
if (!IGNORED_PROPERTY_FIELDS[propertyName]) {
|
|
32
|
-
this._properties[propertyName] = this.json[propertyName];
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
this._binaryProperties = this._initializeBinaryProperties();
|
|
36
|
-
if (options['3DTILES_batch_table_hierarchy']) {
|
|
37
|
-
this._hierarchy = initializeHierarchy(this, this.json, this.binary);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
getExtension(extensionName) {
|
|
41
|
-
return this.json && this.json.extensions && this.json.extensions[extensionName];
|
|
42
|
-
}
|
|
43
|
-
memorySizeInBytes() {
|
|
44
|
-
return 0;
|
|
45
|
-
}
|
|
46
|
-
isClass(batchId, className) {
|
|
47
|
-
this._checkBatchId(batchId);
|
|
48
|
-
assert(typeof className === 'string', className);
|
|
49
|
-
if (this._hierarchy) {
|
|
50
|
-
const result = traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
|
|
51
|
-
const classId = hierarchy.classIds[instanceIndex];
|
|
52
|
-
const instanceClass = hierarchy.classes[classId];
|
|
53
|
-
return instanceClass.name === className;
|
|
54
|
-
});
|
|
55
|
-
return defined(result);
|
|
56
|
-
}
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
isExactClass(batchId, className) {
|
|
60
|
-
assert(typeof className === 'string', className);
|
|
61
|
-
return this.getExactClassName(batchId) === className;
|
|
62
|
-
}
|
|
63
|
-
getExactClassName(batchId) {
|
|
64
|
-
this._checkBatchId(batchId);
|
|
65
|
-
if (this._hierarchy) {
|
|
66
|
-
const classId = this._hierarchy.classIds[batchId];
|
|
67
|
-
const instanceClass = this._hierarchy.classes[classId];
|
|
68
|
-
return instanceClass.name;
|
|
69
|
-
}
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
hasProperty(batchId, name) {
|
|
73
|
-
this._checkBatchId(batchId);
|
|
74
|
-
assert(typeof name === 'string', name);
|
|
75
|
-
return defined(this._properties[name]) || this._hasPropertyInHierarchy(batchId, name);
|
|
76
|
-
}
|
|
77
|
-
getPropertyNames(batchId, results) {
|
|
78
|
-
this._checkBatchId(batchId);
|
|
79
|
-
results = defined(results) ? results : [];
|
|
80
|
-
results.length = 0;
|
|
81
|
-
const propertyNames = Object.keys(this._properties);
|
|
82
|
-
results.push(...propertyNames);
|
|
83
|
-
if (this._hierarchy) {
|
|
84
|
-
this._getPropertyNamesInHierarchy(batchId, results);
|
|
85
|
-
}
|
|
86
|
-
return results;
|
|
87
|
-
}
|
|
88
|
-
getProperty(batchId, name) {
|
|
89
|
-
this._checkBatchId(batchId);
|
|
90
|
-
assert(typeof name === 'string', name);
|
|
91
|
-
if (this._binaryProperties) {
|
|
92
|
-
const binaryProperty = this._binaryProperties[name];
|
|
93
|
-
if (defined(binaryProperty)) {
|
|
94
|
-
return this._getBinaryProperty(binaryProperty, batchId);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
const propertyValues = this._properties[name];
|
|
98
|
-
if (defined(propertyValues)) {
|
|
99
|
-
return clone(propertyValues[batchId], true);
|
|
100
|
-
}
|
|
101
|
-
if (this._hierarchy) {
|
|
102
|
-
const hierarchyProperty = this._getHierarchyProperty(batchId, name);
|
|
103
|
-
if (defined(hierarchyProperty)) {
|
|
104
|
-
return hierarchyProperty;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return undefined;
|
|
108
|
-
}
|
|
109
|
-
setProperty(batchId, name, value) {
|
|
110
|
-
const featureCount = this.featureCount;
|
|
111
|
-
this._checkBatchId(batchId);
|
|
112
|
-
assert(typeof name === 'string', name);
|
|
113
|
-
if (this._binaryProperties) {
|
|
114
|
-
const binaryProperty = this._binaryProperties[name];
|
|
115
|
-
if (binaryProperty) {
|
|
116
|
-
this._setBinaryProperty(binaryProperty, batchId, value);
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
if (this._hierarchy) {
|
|
121
|
-
if (this._setHierarchyProperty(this, batchId, name, value)) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
let propertyValues = this._properties[name];
|
|
126
|
-
if (!defined(propertyValues)) {
|
|
127
|
-
this._properties[name] = new Array(featureCount);
|
|
128
|
-
propertyValues = this._properties[name];
|
|
129
|
-
}
|
|
130
|
-
propertyValues[batchId] = clone(value, true);
|
|
131
|
-
}
|
|
132
|
-
_checkBatchId(batchId) {
|
|
133
|
-
const valid = batchId >= 0 && batchId < this.featureCount;
|
|
134
|
-
if (!valid) {
|
|
135
|
-
throw new Error('batchId not in range [0, featureCount - 1].');
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
_getBinaryProperty(binaryProperty, index) {
|
|
139
|
-
return binaryProperty.unpack(binaryProperty.typedArray, index);
|
|
140
|
-
}
|
|
141
|
-
_setBinaryProperty(binaryProperty, index, value) {
|
|
142
|
-
binaryProperty.pack(value, binaryProperty.typedArray, index);
|
|
143
|
-
}
|
|
144
|
-
_initializeBinaryProperties() {
|
|
145
|
-
let binaryProperties = null;
|
|
146
|
-
for (const name in this._properties) {
|
|
147
|
-
const property = this._properties[name];
|
|
148
|
-
const binaryProperty = this._initializeBinaryProperty(name, property);
|
|
149
|
-
if (binaryProperty) {
|
|
150
|
-
binaryProperties = binaryProperties || {};
|
|
151
|
-
binaryProperties[name] = binaryProperty;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return binaryProperties;
|
|
155
|
-
}
|
|
156
|
-
_initializeBinaryProperty(name, property) {
|
|
157
|
-
if ('byteOffset' in property) {
|
|
158
|
-
const tile3DAccessor = property;
|
|
159
|
-
assert(this.binary, `Property ${name} requires a batch table binary.`);
|
|
160
|
-
assert(tile3DAccessor.type, `Property ${name} requires a type.`);
|
|
161
|
-
const accessor = createTypedArrayFromAccessor(tile3DAccessor, this.binary.buffer, this.binary.byteOffset | 0, this.featureCount);
|
|
162
|
-
return {
|
|
163
|
-
typedArray: accessor.values,
|
|
164
|
-
componentCount: accessor.size,
|
|
165
|
-
unpack: accessor.unpacker,
|
|
166
|
-
pack: accessor.packer
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
return null;
|
|
170
|
-
}
|
|
171
|
-
_hasPropertyInHierarchy(batchId, name) {
|
|
172
|
-
if (!this._hierarchy) {
|
|
173
|
-
return false;
|
|
174
|
-
}
|
|
175
|
-
const result = traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
|
|
176
|
-
const classId = hierarchy.classIds[instanceIndex];
|
|
177
|
-
const instances = hierarchy.classes[classId].instances;
|
|
178
|
-
return defined(instances[name]);
|
|
179
|
-
});
|
|
180
|
-
return defined(result);
|
|
181
|
-
}
|
|
182
|
-
_getPropertyNamesInHierarchy(batchId, results) {
|
|
183
|
-
traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
|
|
184
|
-
const classId = hierarchy.classIds[instanceIndex];
|
|
185
|
-
const instances = hierarchy.classes[classId].instances;
|
|
186
|
-
for (const name in instances) {
|
|
187
|
-
if (instances.hasOwnProperty(name)) {
|
|
188
|
-
if (results.indexOf(name) === -1) {
|
|
189
|
-
results.push(name);
|
|
190
|
-
}
|
|
21
|
+
constructor(json, binary, featureCount, options = {}) {
|
|
22
|
+
assert(featureCount >= 0);
|
|
23
|
+
this.json = json || {};
|
|
24
|
+
this.binary = binary;
|
|
25
|
+
this.featureCount = featureCount;
|
|
26
|
+
this._extensions = this.json?.extensions || {};
|
|
27
|
+
// Copy all top-level property fields from the json object, ignoring special fields
|
|
28
|
+
this._properties = {};
|
|
29
|
+
for (const propertyName in this.json) {
|
|
30
|
+
if (!IGNORED_PROPERTY_FIELDS[propertyName]) {
|
|
31
|
+
this._properties[propertyName] = this.json[propertyName];
|
|
32
|
+
}
|
|
191
33
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
return traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
|
|
197
|
-
const classId = hierarchy.classIds[instanceIndex];
|
|
198
|
-
const instanceClass = hierarchy.classes[classId];
|
|
199
|
-
const indexInClass = hierarchy.classIndexes[instanceIndex];
|
|
200
|
-
const propertyValues = instanceClass.instances[name];
|
|
201
|
-
if (defined(propertyValues)) {
|
|
202
|
-
if (defined(propertyValues.typedArray)) {
|
|
203
|
-
return this._getBinaryProperty(propertyValues, indexInClass);
|
|
34
|
+
this._binaryProperties = this._initializeBinaryProperties();
|
|
35
|
+
// TODO: hierarchy support is only partially implemented and not tested
|
|
36
|
+
if (options['3DTILES_batch_table_hierarchy']) {
|
|
37
|
+
this._hierarchy = initializeHierarchy(this, this.json, this.binary);
|
|
204
38
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
39
|
+
}
|
|
40
|
+
getExtension(extensionName) {
|
|
41
|
+
return this.json && this.json.extensions && this.json.extensions[extensionName];
|
|
42
|
+
}
|
|
43
|
+
memorySizeInBytes() {
|
|
44
|
+
return 0;
|
|
45
|
+
}
|
|
46
|
+
isClass(batchId, className) {
|
|
47
|
+
this._checkBatchId(batchId);
|
|
48
|
+
assert(typeof className === 'string', className);
|
|
49
|
+
// extension: 3DTILES_batch_table_hierarchy
|
|
50
|
+
if (this._hierarchy) {
|
|
51
|
+
// PERFORMANCE_IDEA : cache results in the ancestor classes
|
|
52
|
+
// to speed up this check if this area becomes a hotspot
|
|
53
|
+
// PERFORMANCE_IDEA : treat class names as integers for faster comparisons
|
|
54
|
+
const result = traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
|
|
55
|
+
const classId = hierarchy.classIds[instanceIndex];
|
|
56
|
+
const instanceClass = hierarchy.classes[classId];
|
|
57
|
+
return instanceClass.name === className;
|
|
58
|
+
});
|
|
59
|
+
return defined(result);
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
isExactClass(batchId, className) {
|
|
64
|
+
assert(typeof className === 'string', className);
|
|
65
|
+
return this.getExactClassName(batchId) === className;
|
|
66
|
+
}
|
|
67
|
+
getExactClassName(batchId) {
|
|
68
|
+
this._checkBatchId(batchId);
|
|
69
|
+
// extension: 3DTILES_batch_table_hierarchy
|
|
70
|
+
if (this._hierarchy) {
|
|
71
|
+
const classId = this._hierarchy.classIds[batchId];
|
|
72
|
+
const instanceClass = this._hierarchy.classes[classId];
|
|
73
|
+
return instanceClass.name;
|
|
74
|
+
}
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
hasProperty(batchId, name) {
|
|
78
|
+
this._checkBatchId(batchId);
|
|
79
|
+
assert(typeof name === 'string', name);
|
|
80
|
+
return defined(this._properties[name]) || this._hasPropertyInHierarchy(batchId, name);
|
|
81
|
+
}
|
|
82
|
+
getPropertyNames(batchId, results) {
|
|
83
|
+
this._checkBatchId(batchId);
|
|
84
|
+
results = defined(results) ? results : [];
|
|
85
|
+
results.length = 0;
|
|
86
|
+
const propertyNames = Object.keys(this._properties);
|
|
87
|
+
results.push(...propertyNames);
|
|
88
|
+
if (this._hierarchy) {
|
|
89
|
+
this._getPropertyNamesInHierarchy(batchId, results);
|
|
90
|
+
}
|
|
91
|
+
return results;
|
|
92
|
+
}
|
|
93
|
+
getProperty(batchId, name) {
|
|
94
|
+
this._checkBatchId(batchId);
|
|
95
|
+
assert(typeof name === 'string', name);
|
|
96
|
+
if (this._binaryProperties) {
|
|
97
|
+
const binaryProperty = this._binaryProperties[name];
|
|
98
|
+
if (defined(binaryProperty)) {
|
|
99
|
+
return this._getBinaryProperty(binaryProperty, batchId);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const propertyValues = this._properties[name];
|
|
103
|
+
if (defined(propertyValues)) {
|
|
104
|
+
return clone(propertyValues[batchId], true);
|
|
105
|
+
}
|
|
106
|
+
// EXTENSION: 3DTILES_batch_table_hierarchy
|
|
107
|
+
if (this._hierarchy) {
|
|
108
|
+
const hierarchyProperty = this._getHierarchyProperty(batchId, name);
|
|
109
|
+
if (defined(hierarchyProperty)) {
|
|
110
|
+
return hierarchyProperty;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
setProperty(batchId, name, value) {
|
|
116
|
+
const featureCount = this.featureCount;
|
|
117
|
+
this._checkBatchId(batchId);
|
|
118
|
+
assert(typeof name === 'string', name);
|
|
119
|
+
if (this._binaryProperties) {
|
|
120
|
+
const binaryProperty = this._binaryProperties[name];
|
|
121
|
+
if (binaryProperty) {
|
|
122
|
+
this._setBinaryProperty(binaryProperty, batchId, value);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// EXTENSION: 3DTILES_batch_table_hierarchy
|
|
127
|
+
if (this._hierarchy) {
|
|
128
|
+
if (this._setHierarchyProperty(this, batchId, name, value)) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
222
131
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
132
|
+
let propertyValues = this._properties[name];
|
|
133
|
+
if (!defined(propertyValues)) {
|
|
134
|
+
// Property does not exist. Create it.
|
|
135
|
+
this._properties[name] = new Array(featureCount);
|
|
136
|
+
propertyValues = this._properties[name];
|
|
137
|
+
}
|
|
138
|
+
propertyValues[batchId] = clone(value, true);
|
|
139
|
+
}
|
|
140
|
+
// PRIVATE METHODS
|
|
141
|
+
_checkBatchId(batchId) {
|
|
142
|
+
const valid = batchId >= 0 && batchId < this.featureCount;
|
|
143
|
+
if (!valid) {
|
|
144
|
+
throw new Error('batchId not in range [0, featureCount - 1].');
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
_getBinaryProperty(binaryProperty, index) {
|
|
148
|
+
return binaryProperty.unpack(binaryProperty.typedArray, index);
|
|
149
|
+
}
|
|
150
|
+
_setBinaryProperty(binaryProperty, index, value) {
|
|
151
|
+
binaryProperty.pack(value, binaryProperty.typedArray, index);
|
|
152
|
+
}
|
|
153
|
+
_initializeBinaryProperties() {
|
|
154
|
+
let binaryProperties = null;
|
|
155
|
+
for (const name in this._properties) {
|
|
156
|
+
const property = this._properties[name];
|
|
157
|
+
const binaryProperty = this._initializeBinaryProperty(name, property);
|
|
158
|
+
// Store any information needed to access the binary data, including the typed array,
|
|
159
|
+
// componentCount (e.g. a VEC4 would be 4), and the type used to pack and unpack (e.g. Cartesian4).
|
|
160
|
+
if (binaryProperty) {
|
|
161
|
+
binaryProperties = binaryProperties || {};
|
|
162
|
+
binaryProperties[name] = binaryProperty;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return binaryProperties;
|
|
166
|
+
}
|
|
167
|
+
_initializeBinaryProperty(name, property) {
|
|
168
|
+
if ('byteOffset' in property) {
|
|
169
|
+
// This is a binary property
|
|
170
|
+
const tile3DAccessor = property;
|
|
171
|
+
assert(this.binary, `Property ${name} requires a batch table binary.`);
|
|
172
|
+
assert(tile3DAccessor.type, `Property ${name} requires a type.`);
|
|
173
|
+
const accessor = createTypedArrayFromAccessor(tile3DAccessor, this.binary.buffer, this.binary.byteOffset | 0, this.featureCount);
|
|
174
|
+
// Store any information needed to access the binary data, including the typed array,
|
|
175
|
+
// componentCount (e.g. a VEC4 would be 4), and the type used to pack and unpack (e.g. Cartesian4).
|
|
176
|
+
return {
|
|
177
|
+
typedArray: accessor.values,
|
|
178
|
+
componentCount: accessor.size,
|
|
179
|
+
unpack: accessor.unpacker,
|
|
180
|
+
pack: accessor.packer
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
// EXTENSION SUPPORT: 3DTILES_batch_table_hierarchy
|
|
186
|
+
_hasPropertyInHierarchy(batchId, name) {
|
|
187
|
+
if (!this._hierarchy) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
const result = traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
|
|
191
|
+
const classId = hierarchy.classIds[instanceIndex];
|
|
192
|
+
const instances = hierarchy.classes[classId].instances;
|
|
193
|
+
return defined(instances[name]);
|
|
194
|
+
});
|
|
195
|
+
return defined(result);
|
|
196
|
+
}
|
|
197
|
+
_getPropertyNamesInHierarchy(batchId, results) {
|
|
198
|
+
traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
|
|
199
|
+
const classId = hierarchy.classIds[instanceIndex];
|
|
200
|
+
const instances = hierarchy.classes[classId].instances;
|
|
201
|
+
for (const name in instances) {
|
|
202
|
+
if (instances.hasOwnProperty(name)) {
|
|
203
|
+
if (results.indexOf(name) === -1) {
|
|
204
|
+
results.push(name);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
_getHierarchyProperty(batchId, name) {
|
|
211
|
+
return traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
|
|
212
|
+
const classId = hierarchy.classIds[instanceIndex];
|
|
213
|
+
const instanceClass = hierarchy.classes[classId];
|
|
214
|
+
const indexInClass = hierarchy.classIndexes[instanceIndex];
|
|
215
|
+
const propertyValues = instanceClass.instances[name];
|
|
216
|
+
if (defined(propertyValues)) {
|
|
217
|
+
if (defined(propertyValues.typedArray)) {
|
|
218
|
+
return this._getBinaryProperty(propertyValues, indexInClass);
|
|
219
|
+
}
|
|
220
|
+
return clone(propertyValues[indexInClass], true);
|
|
221
|
+
}
|
|
222
|
+
return null;
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
_setHierarchyProperty(batchTable, batchId, name, value) {
|
|
226
|
+
const result = traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
|
|
227
|
+
const classId = hierarchy.classIds[instanceIndex];
|
|
228
|
+
const instanceClass = hierarchy.classes[classId];
|
|
229
|
+
const indexInClass = hierarchy.classIndexes[instanceIndex];
|
|
230
|
+
const propertyValues = instanceClass.instances[name];
|
|
231
|
+
if (defined(propertyValues)) {
|
|
232
|
+
assert(instanceIndex === batchId, `Inherited property "${name}" is read-only.`);
|
|
233
|
+
if (defined(propertyValues.typedArray)) {
|
|
234
|
+
this._setBinaryProperty(propertyValues, indexInClass, value);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
propertyValues[indexInClass] = clone(value, true);
|
|
238
|
+
}
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
return false;
|
|
242
|
+
});
|
|
243
|
+
return defined(result);
|
|
244
|
+
}
|
|
229
245
|
}
|
|
230
|
-
//# sourceMappingURL=tile-3d-batch-table.js.map
|
|
@@ -1,69 +1,72 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT AND Apache-2.0
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
// This file is derived from the Cesium code base under Apache 2 license
|
|
5
|
+
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
1
6
|
import { GL, GLType } from '@loaders.gl/math';
|
|
7
|
+
// Reference:
|
|
8
|
+
// https://github.com/AnalyticalGraphicsInc/cesium/blob/1de96d087f0b17575eb1a3f736407b348c765d59/Source/Scene/Cesium3DTileFeatureTable.js
|
|
2
9
|
export default class Tile3DFeatureTable {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
this.json = featureTableJson;
|
|
9
|
-
this.buffer = featureTableBinary;
|
|
10
|
-
}
|
|
11
|
-
getExtension(extensionName) {
|
|
12
|
-
return this.json.extensions && this.json.extensions[extensionName];
|
|
13
|
-
}
|
|
14
|
-
hasProperty(propertyName) {
|
|
15
|
-
return Boolean(this.json[propertyName]);
|
|
16
|
-
}
|
|
17
|
-
getGlobalProperty(propertyName) {
|
|
18
|
-
let componentType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : GL.UNSIGNED_INT;
|
|
19
|
-
let componentLength = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
20
|
-
const jsonValue = this.json[propertyName];
|
|
21
|
-
if (jsonValue && Number.isFinite(jsonValue.byteOffset)) {
|
|
22
|
-
return this._getTypedArrayFromBinary(propertyName, componentType, componentLength, 1, jsonValue.byteOffset);
|
|
10
|
+
constructor(featureTableJson, featureTableBinary) {
|
|
11
|
+
this.featuresLength = 0;
|
|
12
|
+
this._cachedTypedArrays = {};
|
|
13
|
+
this.json = featureTableJson;
|
|
14
|
+
this.buffer = featureTableBinary;
|
|
23
15
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
getPropertyArray(propertyName, componentType, componentLength) {
|
|
27
|
-
const jsonValue = this.json[propertyName];
|
|
28
|
-
if (jsonValue && Number.isFinite(jsonValue.byteOffset)) {
|
|
29
|
-
if ('componentType' in jsonValue) {
|
|
30
|
-
componentType = GLType.fromName(jsonValue.componentType);
|
|
31
|
-
}
|
|
32
|
-
return this._getTypedArrayFromBinary(propertyName, componentType, componentLength, this.featuresLength, jsonValue.byteOffset);
|
|
16
|
+
getExtension(extensionName) {
|
|
17
|
+
return this.json.extensions && this.json.extensions[extensionName];
|
|
33
18
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
getProperty(propertyName, componentType, componentLength, featureId, result) {
|
|
37
|
-
const jsonValue = this.json[propertyName];
|
|
38
|
-
if (!jsonValue) {
|
|
39
|
-
return jsonValue;
|
|
19
|
+
hasProperty(propertyName) {
|
|
20
|
+
return Boolean(this.json[propertyName]);
|
|
40
21
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
22
|
+
getGlobalProperty(propertyName, componentType = GL.UNSIGNED_INT, componentLength = 1) {
|
|
23
|
+
const jsonValue = this.json[propertyName];
|
|
24
|
+
if (jsonValue && Number.isFinite(jsonValue.byteOffset)) {
|
|
25
|
+
return this._getTypedArrayFromBinary(propertyName, componentType, componentLength, 1, jsonValue.byteOffset);
|
|
26
|
+
}
|
|
27
|
+
return jsonValue;
|
|
44
28
|
}
|
|
45
|
-
|
|
46
|
-
|
|
29
|
+
getPropertyArray(propertyName, componentType, componentLength) {
|
|
30
|
+
const jsonValue = this.json[propertyName];
|
|
31
|
+
if (jsonValue && Number.isFinite(jsonValue.byteOffset)) {
|
|
32
|
+
if ('componentType' in jsonValue) {
|
|
33
|
+
componentType = GLType.fromName(jsonValue.componentType);
|
|
34
|
+
}
|
|
35
|
+
return this._getTypedArrayFromBinary(propertyName, componentType, componentLength, this.featuresLength, jsonValue.byteOffset);
|
|
36
|
+
}
|
|
37
|
+
return this._getTypedArrayFromArray(propertyName, componentType, jsonValue);
|
|
47
38
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
39
|
+
getProperty(propertyName, componentType, componentLength, featureId, result) {
|
|
40
|
+
const jsonValue = this.json[propertyName];
|
|
41
|
+
if (!jsonValue) {
|
|
42
|
+
return jsonValue;
|
|
43
|
+
}
|
|
44
|
+
const typedArray = this.getPropertyArray(propertyName, componentType, componentLength);
|
|
45
|
+
if (componentLength === 1) {
|
|
46
|
+
return typedArray[featureId];
|
|
47
|
+
}
|
|
48
|
+
for (let i = 0; i < componentLength; ++i) {
|
|
49
|
+
result[i] = typedArray[componentLength * featureId + i];
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
56
52
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
53
|
+
// HELPERS
|
|
54
|
+
_getTypedArrayFromBinary(propertyName, componentType, componentLength, count, byteOffset) {
|
|
55
|
+
const cachedTypedArrays = this._cachedTypedArrays;
|
|
56
|
+
let typedArray = cachedTypedArrays[propertyName];
|
|
57
|
+
if (!typedArray) {
|
|
58
|
+
typedArray = GLType.createTypedArray(componentType, this.buffer.buffer, this.buffer.byteOffset + byteOffset, count * componentLength);
|
|
59
|
+
cachedTypedArrays[propertyName] = typedArray;
|
|
60
|
+
}
|
|
61
|
+
return typedArray;
|
|
62
|
+
}
|
|
63
|
+
_getTypedArrayFromArray(propertyName, componentType, array) {
|
|
64
|
+
const cachedTypedArrays = this._cachedTypedArrays;
|
|
65
|
+
let typedArray = cachedTypedArrays[propertyName];
|
|
66
|
+
if (!typedArray) {
|
|
67
|
+
typedArray = GLType.createTypedArray(componentType, array);
|
|
68
|
+
cachedTypedArrays[propertyName] = typedArray;
|
|
69
|
+
}
|
|
70
|
+
return typedArray;
|
|
65
71
|
}
|
|
66
|
-
return typedArray;
|
|
67
|
-
}
|
|
68
72
|
}
|
|
69
|
-
//# sourceMappingURL=tile-3d-feature-table.js.map
|
package/dist/lib/constants.js
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
// TILE TYPES
|
|
1
5
|
export const TILE3D_TYPE = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
COMPOSITE: 'cmpt',
|
|
7
|
+
POINT_CLOUD: 'pnts',
|
|
8
|
+
BATCHED_3D_MODEL: 'b3dm',
|
|
9
|
+
INSTANCED_3D_MODEL: 'i3dm',
|
|
10
|
+
GEOMETRY: 'geom',
|
|
11
|
+
VECTOR: 'vect',
|
|
12
|
+
GLTF: 'glTF'
|
|
9
13
|
};
|
|
10
14
|
export const TILE3D_TYPES = Object.keys(TILE3D_TYPE);
|
|
11
15
|
export const MAGIC_ARRAY = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
BATCHED_MODEL: [98, 51, 100, 109],
|
|
17
|
+
INSTANCED_MODEL: [105, 51, 100, 109],
|
|
18
|
+
POINT_CLOUD: [112, 110, 116, 115],
|
|
19
|
+
COMPOSITE: [99, 109, 112, 116]
|
|
16
20
|
};
|
|
21
|
+
// TILE CONSTANTS
|
|
17
22
|
export const TILE3D_OPTIMIZATION_HINT = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
NOT_COMPUTED: -1,
|
|
24
|
+
USE_OPTIMIZATION: 1,
|
|
25
|
+
SKIP_OPTIMIZATION: 0
|
|
21
26
|
};
|
|
22
|
-
//# sourceMappingURL=constants.js.map
|