@itwin/core-frontend 3.0.0-dev.167 → 3.0.0-dev.172
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/lib/cjs/IModelApp.d.ts +1 -1
- package/lib/cjs/IModelApp.d.ts.map +1 -1
- package/lib/cjs/IModelApp.js.map +1 -1
- package/lib/cjs/ImageUtil.d.ts.map +1 -1
- package/lib/cjs/ImageUtil.js +4 -1
- package/lib/cjs/ImageUtil.js.map +1 -1
- package/lib/cjs/ViewManager.d.ts +6 -6
- package/lib/cjs/ViewManager.js +5 -5
- package/lib/cjs/ViewManager.js.map +1 -1
- package/lib/cjs/Viewport.d.ts +5 -3
- package/lib/cjs/Viewport.d.ts.map +1 -1
- package/lib/cjs/Viewport.js +5 -3
- package/lib/cjs/Viewport.js.map +1 -1
- package/lib/cjs/render/RenderSystem.d.ts +1 -0
- package/lib/cjs/render/RenderSystem.d.ts.map +1 -1
- package/lib/cjs/render/RenderSystem.js +1 -0
- package/lib/cjs/render/RenderSystem.js.map +1 -1
- package/lib/cjs/tile/B3dmReader.js +2 -2
- package/lib/cjs/tile/B3dmReader.js.map +1 -1
- package/lib/cjs/tile/DynamicIModelTile.js +1 -1
- package/lib/cjs/tile/DynamicIModelTile.js.map +1 -1
- package/lib/cjs/tile/GltfReader.d.ts +129 -36
- package/lib/cjs/tile/GltfReader.d.ts.map +1 -1
- package/lib/cjs/tile/GltfReader.js +261 -122
- package/lib/cjs/tile/GltfReader.js.map +1 -1
- package/lib/cjs/tile/I3dmReader.js +2 -2
- package/lib/cjs/tile/I3dmReader.js.map +1 -1
- package/lib/cjs/tile/IModelTile.js +1 -1
- package/lib/cjs/tile/IModelTile.js.map +1 -1
- package/lib/cjs/tile/ImdlReader.d.ts +12 -1
- package/lib/cjs/tile/ImdlReader.d.ts.map +1 -1
- package/lib/cjs/tile/ImdlReader.js +47 -3
- package/lib/cjs/tile/ImdlReader.js.map +1 -1
- package/lib/cjs/tile/RealityTileLoader.js +1 -1
- package/lib/cjs/tile/RealityTileLoader.js.map +1 -1
- package/lib/cjs/tile/map/CesiumTerrainProvider.js +1 -1
- package/lib/cjs/tile/map/CesiumTerrainProvider.js.map +1 -1
- package/lib/esm/IModelApp.d.ts +1 -1
- package/lib/esm/IModelApp.d.ts.map +1 -1
- package/lib/esm/IModelApp.js.map +1 -1
- package/lib/esm/ImageUtil.d.ts.map +1 -1
- package/lib/esm/ImageUtil.js +4 -1
- package/lib/esm/ImageUtil.js.map +1 -1
- package/lib/esm/ViewManager.d.ts +6 -6
- package/lib/esm/ViewManager.js +5 -5
- package/lib/esm/ViewManager.js.map +1 -1
- package/lib/esm/Viewport.d.ts +5 -3
- package/lib/esm/Viewport.d.ts.map +1 -1
- package/lib/esm/Viewport.js +5 -3
- package/lib/esm/Viewport.js.map +1 -1
- package/lib/esm/render/RenderSystem.d.ts +1 -0
- package/lib/esm/render/RenderSystem.d.ts.map +1 -1
- package/lib/esm/render/RenderSystem.js +1 -0
- package/lib/esm/render/RenderSystem.js.map +1 -1
- package/lib/esm/tile/B3dmReader.js +2 -2
- package/lib/esm/tile/B3dmReader.js.map +1 -1
- package/lib/esm/tile/DynamicIModelTile.js +1 -1
- package/lib/esm/tile/DynamicIModelTile.js.map +1 -1
- package/lib/esm/tile/GltfReader.d.ts +129 -36
- package/lib/esm/tile/GltfReader.d.ts.map +1 -1
- package/lib/esm/tile/GltfReader.js +261 -123
- package/lib/esm/tile/GltfReader.js.map +1 -1
- package/lib/esm/tile/I3dmReader.js +2 -2
- package/lib/esm/tile/I3dmReader.js.map +1 -1
- package/lib/esm/tile/IModelTile.js +1 -1
- package/lib/esm/tile/IModelTile.js.map +1 -1
- package/lib/esm/tile/ImdlReader.d.ts +12 -1
- package/lib/esm/tile/ImdlReader.d.ts.map +1 -1
- package/lib/esm/tile/ImdlReader.js +45 -2
- package/lib/esm/tile/ImdlReader.js.map +1 -1
- package/lib/esm/tile/RealityTileLoader.js +1 -1
- package/lib/esm/tile/RealityTileLoader.js.map +1 -1
- package/lib/esm/tile/map/CesiumTerrainProvider.js +1 -1
- package/lib/esm/tile/map/CesiumTerrainProvider.js.map +1 -1
- package/package.json +22 -22
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @module Tiles
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.readGltfGraphics = exports.GltfReader = exports.GltfMeshData = exports.GltfReaderProps = exports.GltfBufferData = exports.GltfDataType = void 0;
|
|
10
|
+
exports.GltfGraphicsReader = exports.readGltfGraphics = exports.GltfReader = exports.GltfMeshData = exports.GltfReaderProps = exports.GltfBufferData = exports.GltfDataType = void 0;
|
|
11
11
|
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
12
|
const core_geometry_1 = require("@itwin/core-geometry");
|
|
13
13
|
const core_common_1 = require("@itwin/core-common");
|
|
@@ -82,6 +82,19 @@ var GltfBufferTarget;
|
|
|
82
82
|
GltfBufferTarget[GltfBufferTarget["ArrayBuffer"] = 34962] = "ArrayBuffer";
|
|
83
83
|
GltfBufferTarget[GltfBufferTarget["ElementArrayBuffer"] = 24963] = "ElementArrayBuffer";
|
|
84
84
|
})(GltfBufferTarget || (GltfBufferTarget = {}));
|
|
85
|
+
function* dictionaryIterator(dict) {
|
|
86
|
+
if (Array.isArray(dict)) {
|
|
87
|
+
for (const elem of dict)
|
|
88
|
+
yield elem;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
for (const key of Object.keys(dict)) {
|
|
92
|
+
const value = dict[key];
|
|
93
|
+
if (undefined !== value)
|
|
94
|
+
yield value;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
85
98
|
function getNodeMeshIds(node) {
|
|
86
99
|
if (undefined !== node.meshes)
|
|
87
100
|
return typeof node.meshes === "string" ? [node.meshes] : node.meshes;
|
|
@@ -173,50 +186,80 @@ class GltfBufferView {
|
|
|
173
186
|
* @internal
|
|
174
187
|
*/
|
|
175
188
|
class GltfReaderProps {
|
|
176
|
-
constructor(
|
|
177
|
-
this.
|
|
189
|
+
constructor(glTF, version, yAxisUp, binaryData, baseUrl) {
|
|
190
|
+
this.version = version;
|
|
178
191
|
this.glTF = glTF;
|
|
192
|
+
this.binaryData = binaryData;
|
|
179
193
|
this.yAxisUp = yAxisUp;
|
|
194
|
+
this.baseUrl = baseUrl;
|
|
180
195
|
}
|
|
181
196
|
/** Attempt to construct a new GltfReaderProps from the binary data beginning at the supplied stream's current read position. */
|
|
182
|
-
static create(
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
197
|
+
static create(source, yAxisUp = false, baseUrl) {
|
|
198
|
+
let version;
|
|
199
|
+
let json;
|
|
200
|
+
let binaryData;
|
|
201
|
+
if (source instanceof Uint8Array) {
|
|
202
|
+
// It may be JSON - check for magic indicating glb.
|
|
203
|
+
const buffer = core_bentley_1.ByteStream.fromUint8Array(source);
|
|
204
|
+
if (core_common_1.TileFormat.Gltf !== buffer.nextUint32) {
|
|
205
|
+
try {
|
|
206
|
+
const utf8Json = (0, core_bentley_1.utf8ToString)(source);
|
|
207
|
+
if (!utf8Json)
|
|
208
|
+
return undefined;
|
|
209
|
+
json = JSON.parse(utf8Json);
|
|
210
|
+
version = 2;
|
|
211
|
+
}
|
|
212
|
+
catch (_) {
|
|
213
|
+
return undefined;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
buffer.reset();
|
|
218
|
+
const header = new core_common_1.GlbHeader(buffer);
|
|
219
|
+
if (!header.isValid)
|
|
220
|
+
return undefined;
|
|
221
|
+
version = header.version;
|
|
222
|
+
if (header.binaryChunk)
|
|
223
|
+
binaryData = new Uint8Array(source.buffer, source.byteOffset + header.binaryChunk.offset, header.binaryChunk.length);
|
|
224
|
+
try {
|
|
225
|
+
const jsonBytes = new Uint8Array(source.buffer, source.byteOffset + header.jsonChunk.offset, header.jsonChunk.length);
|
|
226
|
+
const jsonStr = (0, core_bentley_1.utf8ToString)(jsonBytes);
|
|
227
|
+
if (undefined === jsonStr)
|
|
228
|
+
return undefined;
|
|
229
|
+
json = JSON.parse(jsonStr);
|
|
230
|
+
}
|
|
231
|
+
catch (_) {
|
|
232
|
+
return undefined;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
216
235
|
}
|
|
217
|
-
|
|
218
|
-
|
|
236
|
+
else {
|
|
237
|
+
version = 2; // ###TODO verify against source.asset?.version
|
|
238
|
+
json = source;
|
|
219
239
|
}
|
|
240
|
+
// asset is required in glTF 2, optional in glTF 1
|
|
241
|
+
const asset = core_bentley_1.JsonUtils.asObject(json.asset);
|
|
242
|
+
if (version === 2 && !asset)
|
|
243
|
+
return undefined;
|
|
244
|
+
const glTF = {
|
|
245
|
+
asset,
|
|
246
|
+
scene: core_bentley_1.JsonUtils.asString(json.scene),
|
|
247
|
+
extensions: core_bentley_1.JsonUtils.asObject(json.extensions),
|
|
248
|
+
extensionsUsed: core_bentley_1.JsonUtils.asArray(json.extensionsUsed),
|
|
249
|
+
extensionsRequired: core_bentley_1.JsonUtils.asArray(json.extensionsRequired),
|
|
250
|
+
accessors: core_bentley_1.JsonUtils.asObject(json.accessors),
|
|
251
|
+
buffers: core_bentley_1.JsonUtils.asObject(json.buffers),
|
|
252
|
+
bufferViews: core_bentley_1.JsonUtils.asObject(json.bufferViews),
|
|
253
|
+
images: core_bentley_1.JsonUtils.asObject(json.images),
|
|
254
|
+
materials: core_bentley_1.JsonUtils.asObject(json.materials),
|
|
255
|
+
meshes: core_bentley_1.JsonUtils.asObject(json.meshes),
|
|
256
|
+
nodes: core_bentley_1.JsonUtils.asObject(json.nodes),
|
|
257
|
+
samplers: core_bentley_1.JsonUtils.asObject(json.samplers),
|
|
258
|
+
scenes: core_bentley_1.JsonUtils.asObject(json.scenes),
|
|
259
|
+
textures: core_bentley_1.JsonUtils.asObject(json.textures),
|
|
260
|
+
techniques: core_bentley_1.JsonUtils.asObject(json.techniques),
|
|
261
|
+
};
|
|
262
|
+
return glTF.meshes ? new GltfReaderProps(glTF, version, yAxisUp, binaryData, baseUrl) : undefined;
|
|
220
263
|
}
|
|
221
264
|
}
|
|
222
265
|
exports.GltfReaderProps = GltfReaderProps;
|
|
@@ -300,15 +343,30 @@ class TransformStack {
|
|
|
300
343
|
this._stack.pop();
|
|
301
344
|
}
|
|
302
345
|
}
|
|
346
|
+
function* traverseNodes(ids, nodes, traversed) {
|
|
347
|
+
for (const id of ids) {
|
|
348
|
+
if (traversed.has(id))
|
|
349
|
+
throw new Error("Cycle detected while traversing glTF nodes");
|
|
350
|
+
const node = nodes[id];
|
|
351
|
+
if (!node)
|
|
352
|
+
continue;
|
|
353
|
+
traversed.add(id);
|
|
354
|
+
yield node;
|
|
355
|
+
if (node.children)
|
|
356
|
+
for (const child of traverseNodes(node.children, nodes, traversed))
|
|
357
|
+
yield child;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
303
360
|
/** Deserializes [glTF](https://www.khronos.org/gltf/).
|
|
304
361
|
* @internal
|
|
305
362
|
*/
|
|
306
363
|
class GltfReader {
|
|
307
364
|
constructor(args) {
|
|
308
365
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
309
|
-
this._binaryData = args.props.binaryData;
|
|
310
366
|
this._glTF = args.props.glTF;
|
|
367
|
+
this._version = args.props.version;
|
|
311
368
|
this._yAxisUp = args.props.yAxisUp;
|
|
369
|
+
this._baseUrl = args.props.baseUrl;
|
|
312
370
|
const rtcCenter = (_b = (_a = args.props.glTF.extensions) === null || _a === void 0 ? void 0 : _a.CESIUM_RTC) === null || _b === void 0 ? void 0 : _b.center;
|
|
313
371
|
if (rtcCenter && 3 === rtcCenter.length)
|
|
314
372
|
if (0 !== rtcCenter[0] || 0 !== rtcCenter[1] || 0 !== rtcCenter[2])
|
|
@@ -320,6 +378,12 @@ class GltfReader {
|
|
|
320
378
|
this._canceled = args.shouldAbort;
|
|
321
379
|
this._deduplicateVertices = (_e = args.deduplicateVertices) !== null && _e !== void 0 ? _e : false;
|
|
322
380
|
this._vertexTableRequired = (_f = args.vertexTableRequired) !== null && _f !== void 0 ? _f : false;
|
|
381
|
+
const binaryData = args.props.binaryData;
|
|
382
|
+
if (binaryData) {
|
|
383
|
+
const buffer = this._buffers[this._version === 2 ? 0 : "binary_glTF"];
|
|
384
|
+
if (buffer && undefined === buffer.uri)
|
|
385
|
+
buffer.resolvedBuffer = binaryData;
|
|
386
|
+
}
|
|
323
387
|
// The original implementation of GltfReader would process and produce graphics for every node in glTF.nodes.
|
|
324
388
|
// What it's *supposed* to do is process the nodes in glTF.scenes[glTF.scene].nodes
|
|
325
389
|
// Some nodes may not be referenced by the configured scene, or only indirectly via GltfNode.children.
|
|
@@ -335,9 +399,26 @@ class GltfReader {
|
|
|
335
399
|
get _meshes() { var _a; return (_a = this._glTF.meshes) !== null && _a !== void 0 ? _a : emptyDict; }
|
|
336
400
|
get _accessors() { var _a; return (_a = this._glTF.accessors) !== null && _a !== void 0 ? _a : emptyDict; }
|
|
337
401
|
get _bufferViews() { var _a; return (_a = this._glTF.bufferViews) !== null && _a !== void 0 ? _a : emptyDict; }
|
|
338
|
-
get
|
|
402
|
+
get _materials() { var _a; return (_a = this._glTF.materials) !== null && _a !== void 0 ? _a : emptyDict; }
|
|
403
|
+
get _samplers() { var _a; return (_a = this._glTF.samplers) !== null && _a !== void 0 ? _a : emptyDict; }
|
|
404
|
+
get _textures() { var _a; return (_a = this._glTF.textures) !== null && _a !== void 0 ? _a : emptyDict; }
|
|
405
|
+
get _images() { var _a; return (_a = this._glTF.images) !== null && _a !== void 0 ? _a : emptyDict; }
|
|
406
|
+
get _buffers() { var _a; return (_a = this._glTF.buffers) !== null && _a !== void 0 ? _a : emptyDict; }
|
|
339
407
|
get _isCanceled() { return undefined !== this._canceled && this._canceled(this); }
|
|
340
408
|
get _isVolumeClassifier() { return core_common_1.BatchType.VolumeClassifier === this._type; }
|
|
409
|
+
/** Traverse the nodes specified by their Ids, recursing into their child nodes.
|
|
410
|
+
* @param nodeIds The Ids of the nodes to traverse.
|
|
411
|
+
* @throws Error if a node appears more than once during traversal
|
|
412
|
+
*/
|
|
413
|
+
traverseNodes(nodeIds) {
|
|
414
|
+
return traverseNodes(nodeIds, this._nodes, new Set());
|
|
415
|
+
}
|
|
416
|
+
/** Traverse the nodes specified by their scene, recursing into their child nodes.
|
|
417
|
+
* @throws Error if a node appears more than once during traversal
|
|
418
|
+
*/
|
|
419
|
+
traverseScene() {
|
|
420
|
+
return this.traverseNodes(this._sceneNodes);
|
|
421
|
+
}
|
|
341
422
|
readGltfAndCreateGraphics(isLeaf, featureTable, contentRange, transformToRoot, pseudoRtcBias, instances) {
|
|
342
423
|
var _a;
|
|
343
424
|
if (this._isCanceled)
|
|
@@ -492,10 +573,16 @@ class GltfReader {
|
|
|
492
573
|
getBufferView(json, accessorName) {
|
|
493
574
|
try {
|
|
494
575
|
const accessorValue = core_bentley_1.JsonUtils.asString(json[accessorName]);
|
|
495
|
-
const accessor =
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
576
|
+
const accessor = accessorValue ? this._accessors[accessorValue] : undefined;
|
|
577
|
+
if (!accessor)
|
|
578
|
+
return undefined;
|
|
579
|
+
const bufferViewAccessorValue = accessor.bufferView;
|
|
580
|
+
const bufferView = undefined !== bufferViewAccessorValue ? this._bufferViews[bufferViewAccessorValue] : undefined;
|
|
581
|
+
if (!bufferView || undefined === bufferView.buffer)
|
|
582
|
+
return undefined;
|
|
583
|
+
const buffer = this._buffers[bufferView.buffer];
|
|
584
|
+
const bufferData = buffer === null || buffer === void 0 ? void 0 : buffer.resolvedBuffer;
|
|
585
|
+
if (!bufferData)
|
|
499
586
|
return undefined;
|
|
500
587
|
const type = accessor.componentType;
|
|
501
588
|
let dataSize = 0;
|
|
@@ -526,8 +613,8 @@ class GltfReader {
|
|
|
526
613
|
const offset = ((bufferView && bufferView.byteOffset) ? bufferView.byteOffset : 0) + (accessor.byteOffset ? accessor.byteOffset : 0);
|
|
527
614
|
const length = byteStride * accessor.count;
|
|
528
615
|
// If the data is misaligned (Scalable mesh tile publisher) use slice to copy -- else use subarray.
|
|
529
|
-
|
|
530
|
-
const bytes =
|
|
616
|
+
const aligned = 0 === (bufferData.byteOffset + offset) % dataSize;
|
|
617
|
+
const bytes = aligned ? bufferData.subarray(offset, offset + length) : bufferData.slice(offset, offset + length);
|
|
531
618
|
return new GltfBufferView(bytes, accessor.count, type, accessor, byteStride / dataSize);
|
|
532
619
|
}
|
|
533
620
|
catch (e) {
|
|
@@ -586,8 +673,8 @@ class GltfReader {
|
|
|
586
673
|
var _a, _b, _c, _d, _e, _f;
|
|
587
674
|
const materialName = core_bentley_1.JsonUtils.asString(primitive.material);
|
|
588
675
|
const hasBakedLighting = undefined === primitive.attributes.NORMAL;
|
|
589
|
-
const material = 0 < materialName.length ? this.
|
|
590
|
-
const displayParams = this.createDisplayParams(material, hasBakedLighting);
|
|
676
|
+
const material = 0 < materialName.length ? this._materials[materialName] : undefined;
|
|
677
|
+
const displayParams = material ? this.createDisplayParams(material, hasBakedLighting) : undefined;
|
|
591
678
|
if (undefined === displayParams)
|
|
592
679
|
return undefined;
|
|
593
680
|
let primitiveType = -1;
|
|
@@ -606,7 +693,6 @@ class GltfReader {
|
|
|
606
693
|
(0, core_bentley_1.assert)(false);
|
|
607
694
|
return undefined;
|
|
608
695
|
}
|
|
609
|
-
const isPlanar = core_bentley_1.JsonUtils.asBool(primitive.isPlanar);
|
|
610
696
|
const isVolumeClassifier = this._isVolumeClassifier;
|
|
611
697
|
const meshPrimitive = MeshPrimitives_1.Mesh.create({
|
|
612
698
|
displayParams,
|
|
@@ -614,7 +700,7 @@ class GltfReader {
|
|
|
614
700
|
type: primitiveType,
|
|
615
701
|
range: core_geometry_1.Range3d.createNull(),
|
|
616
702
|
is2d: !this._is3d,
|
|
617
|
-
isPlanar,
|
|
703
|
+
isPlanar: false,
|
|
618
704
|
hasBakedLighting,
|
|
619
705
|
isVolumeClassifier,
|
|
620
706
|
});
|
|
@@ -840,12 +926,13 @@ class GltfReader {
|
|
|
840
926
|
}
|
|
841
927
|
readUVParams(mesh, json, accessorName) {
|
|
842
928
|
const view = this.getBufferView(json, accessorName);
|
|
843
|
-
let data;
|
|
844
929
|
if (view === undefined)
|
|
845
930
|
return false;
|
|
846
931
|
switch (view.type) {
|
|
847
932
|
case GltfDataType.Float: {
|
|
848
|
-
data = this.readBufferDataFloat(json, accessorName);
|
|
933
|
+
const data = this.readBufferDataFloat(json, accessorName);
|
|
934
|
+
if (!data)
|
|
935
|
+
return false;
|
|
849
936
|
mesh.uvRange = core_geometry_1.Range2d.createNull();
|
|
850
937
|
for (let i = 0; i < data.count; i++) {
|
|
851
938
|
const index = view.stride * i; // 2 float per param...
|
|
@@ -920,14 +1007,91 @@ class GltfReader {
|
|
|
920
1007
|
polylines.push(new core_common_1.MeshPolyline(indices));
|
|
921
1008
|
return true;
|
|
922
1009
|
}
|
|
923
|
-
async
|
|
1010
|
+
async resolveResources() {
|
|
1011
|
+
// ###TODO traverse the scene nodes to find resources referenced by them, instead of resolving everything - some resources may not
|
|
1012
|
+
// be required for the scene.
|
|
1013
|
+
const promises = [];
|
|
1014
|
+
try {
|
|
1015
|
+
for (const buffer of dictionaryIterator(this._buffers))
|
|
1016
|
+
if (!buffer.resolvedBuffer)
|
|
1017
|
+
promises.push(this.resolveBuffer(buffer));
|
|
1018
|
+
await Promise.all(promises);
|
|
1019
|
+
if (this._isCanceled)
|
|
1020
|
+
return;
|
|
1021
|
+
promises.length = 0;
|
|
1022
|
+
for (const image of dictionaryIterator(this._images))
|
|
1023
|
+
if (!image.resolvedImage)
|
|
1024
|
+
promises.push(this.resolveImage(image));
|
|
1025
|
+
await Promise.all(promises);
|
|
1026
|
+
if (this._isCanceled)
|
|
1027
|
+
return;
|
|
1028
|
+
this.resolveTextures();
|
|
1029
|
+
}
|
|
1030
|
+
catch (_) {
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
resolveUrl(uri) {
|
|
1034
|
+
try {
|
|
1035
|
+
return new URL(uri, this._baseUrl).toString();
|
|
1036
|
+
}
|
|
1037
|
+
catch (_) {
|
|
1038
|
+
return undefined;
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
async resolveBuffer(buffer) {
|
|
1042
|
+
if (buffer.resolvedBuffer || undefined === buffer.uri)
|
|
1043
|
+
return;
|
|
1044
|
+
try {
|
|
1045
|
+
const url = this.resolveUrl(buffer.uri);
|
|
1046
|
+
const response = url ? await fetch(url) : undefined;
|
|
1047
|
+
if (this._isCanceled)
|
|
1048
|
+
return;
|
|
1049
|
+
const data = await (response === null || response === void 0 ? void 0 : response.arrayBuffer());
|
|
1050
|
+
if (this._isCanceled)
|
|
1051
|
+
return;
|
|
1052
|
+
if (data)
|
|
1053
|
+
buffer.resolvedBuffer = new Uint8Array(data);
|
|
1054
|
+
}
|
|
1055
|
+
catch (_) {
|
|
1056
|
+
//
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
async resolveImage(image) {
|
|
1060
|
+
var _a, _b, _c;
|
|
1061
|
+
if (image.resolvedImage)
|
|
1062
|
+
return;
|
|
1063
|
+
const bvSrc = undefined !== image.bufferView ? image : (_a = image.extensions) === null || _a === void 0 ? void 0 : _a.KHR_binary_glTF;
|
|
1064
|
+
if (undefined !== (bvSrc === null || bvSrc === void 0 ? void 0 : bvSrc.bufferView)) {
|
|
1065
|
+
const format = undefined !== bvSrc.mimeType ? (0, ImageUtil_1.getImageSourceFormatForMimeType)(bvSrc.mimeType) : undefined;
|
|
1066
|
+
const bufferView = this._bufferViews[bvSrc.bufferView];
|
|
1067
|
+
if (undefined === format || !bufferView || !bufferView.byteLength || bufferView.byteLength < 0)
|
|
1068
|
+
return;
|
|
1069
|
+
const bufferData = (_b = this._buffers[bufferView.buffer]) === null || _b === void 0 ? void 0 : _b.resolvedBuffer;
|
|
1070
|
+
if (!bufferData)
|
|
1071
|
+
return;
|
|
1072
|
+
const offset = (_c = bufferView.byteOffset) !== null && _c !== void 0 ? _c : 0;
|
|
1073
|
+
const bytes = bufferData.subarray(offset, offset + bufferView.byteLength);
|
|
1074
|
+
try {
|
|
1075
|
+
image.resolvedImage = await (0, ImageUtil_1.imageElementFromImageSource)(new core_common_1.ImageSource(bytes, format));
|
|
1076
|
+
}
|
|
1077
|
+
catch (_) {
|
|
1078
|
+
//
|
|
1079
|
+
}
|
|
1080
|
+
return;
|
|
1081
|
+
}
|
|
1082
|
+
const url = undefined !== image.uri ? this.resolveUrl(image.uri) : undefined;
|
|
1083
|
+
if (undefined !== url)
|
|
1084
|
+
image.resolvedImage = await (0, ImageUtil_1.tryImageElementFromUrl)(url);
|
|
1085
|
+
}
|
|
1086
|
+
resolveTextures() {
|
|
924
1087
|
var _a, _b;
|
|
925
1088
|
if (undefined === this._glTF.textures)
|
|
926
1089
|
return;
|
|
1090
|
+
// ###TODO this seems pretty hacky, and won't work for glTF 2.0 even if the KHR_techniques_webgl extension is used...
|
|
927
1091
|
const transparentTextures = new Set();
|
|
928
1092
|
if (this._glTF.techniques) {
|
|
929
|
-
for (const name of Object.keys(this.
|
|
930
|
-
const material = this.
|
|
1093
|
+
for (const name of Object.keys(this._materials)) {
|
|
1094
|
+
const material = this._materials[name];
|
|
931
1095
|
if (material && isGltf1Material(material) && undefined !== material.technique && undefined !== ((_a = material.values) === null || _a === void 0 ? void 0 : _a.tex)) {
|
|
932
1096
|
const technique = this._glTF.techniques[material.technique];
|
|
933
1097
|
if ((_b = technique === null || technique === void 0 ? void 0 : technique.states) === null || _b === void 0 ? void 0 : _b.enable) {
|
|
@@ -941,74 +1105,42 @@ class GltfReader {
|
|
|
941
1105
|
}
|
|
942
1106
|
}
|
|
943
1107
|
}
|
|
944
|
-
const
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
const bufferView = this._bufferViews[binaryImageJson.bufferView];
|
|
955
|
-
if (!bufferView || undefined === bufferView.byteLength || bufferView.byteLength <= 0)
|
|
956
|
-
return undefined;
|
|
957
|
-
const mimeType = core_bentley_1.JsonUtils.asString(binaryImageJson.mimeType);
|
|
958
|
-
const format = (0, ImageUtil_1.getImageSourceFormatForMimeType)(mimeType);
|
|
959
|
-
if (undefined === format)
|
|
960
|
-
return undefined;
|
|
961
|
-
let textureType = core_common_1.RenderTexture.Type.Normal;
|
|
962
|
-
if (undefined !== samplerJson &&
|
|
963
|
-
(undefined !== samplerJson.wrapS || undefined !== samplerJson.wrapT))
|
|
964
|
-
textureType = core_common_1.RenderTexture.Type.TileSection;
|
|
965
|
-
const offset = (_a = bufferView.byteOffset) !== null && _a !== void 0 ? _a : 0;
|
|
966
|
-
/* -----------------------------------
|
|
967
|
-
const jpegArray = this._binaryData.slice(offset, offset + bufferView.byteLength);
|
|
968
|
-
const jpegArrayBuffer = jpegArray.buffer;
|
|
969
|
-
const workerOp = new ImageDecodeWorkerOperation(jpegArrayBuffer, mimeType);
|
|
970
|
-
try {
|
|
971
|
-
const imageBitmap = await GltfReader.webWorkerManager.queueOperation(workerOp)
|
|
972
|
-
return this._isCanceled ? undefined : this._system.createTextureFromImage(imageBitmap, isTransparent && ImageSourceFormat.Png === format, this._iModel, textureParams))
|
|
973
|
-
} catch {
|
|
974
|
-
return undefined;
|
|
1108
|
+
for (const node of this.traverseScene()) {
|
|
1109
|
+
for (const meshId of getNodeMeshIds(node)) {
|
|
1110
|
+
const mesh = this._meshes[meshId];
|
|
1111
|
+
if (!(mesh === null || mesh === void 0 ? void 0 : mesh.primitives))
|
|
1112
|
+
continue;
|
|
1113
|
+
for (const primitive of mesh.primitives) {
|
|
1114
|
+
const material = undefined !== primitive.material ? this._materials[primitive.material] : undefined;
|
|
1115
|
+
const textureId = material ? this.extractTextureId(material) : undefined;
|
|
1116
|
+
if (undefined !== textureId)
|
|
1117
|
+
this.resolveTexture(textureId, transparentTextures.has(textureId));
|
|
975
1118
|
}
|
|
976
|
-
------------------------------------- */
|
|
977
|
-
const bytes = this._binaryData.subarray(offset, offset + bufferView.byteLength);
|
|
978
|
-
const imageSource = new core_common_1.ImageSource(bytes, format);
|
|
979
|
-
try {
|
|
980
|
-
const image = await (0, ImageUtil_1.imageElementFromImageSource)(imageSource);
|
|
981
|
-
if (this._isCanceled)
|
|
982
|
-
return undefined;
|
|
983
|
-
return this._system.createTexture({
|
|
984
|
-
type: textureType,
|
|
985
|
-
image: {
|
|
986
|
-
source: image,
|
|
987
|
-
transparency: isTransparent && core_common_1.ImageSourceFormat.Png === format ? RenderTexture_1.TextureTransparency.Translucent : RenderTexture_1.TextureTransparency.Opaque,
|
|
988
|
-
},
|
|
989
|
-
});
|
|
990
|
-
}
|
|
991
|
-
catch {
|
|
992
|
-
return undefined;
|
|
993
1119
|
}
|
|
994
1120
|
}
|
|
995
|
-
catch (e) {
|
|
996
|
-
return undefined;
|
|
997
|
-
}
|
|
998
1121
|
}
|
|
999
|
-
|
|
1000
|
-
|
|
1122
|
+
resolveTexture(textureId, isTransparent) {
|
|
1123
|
+
var _a;
|
|
1124
|
+
const texture = this._textures[textureId];
|
|
1125
|
+
if (!texture || texture.resolvedTexture || undefined === texture.source)
|
|
1001
1126
|
return;
|
|
1002
|
-
const
|
|
1003
|
-
if (
|
|
1127
|
+
const image = (_a = this._images[texture.source]) === null || _a === void 0 ? void 0 : _a.resolvedImage;
|
|
1128
|
+
if (!image)
|
|
1004
1129
|
return;
|
|
1005
|
-
const
|
|
1006
|
-
|
|
1130
|
+
const samplerId = texture.sampler;
|
|
1131
|
+
const sampler = undefined !== samplerId ? this._samplers[samplerId] : undefined;
|
|
1132
|
+
const textureType = undefined !== (sampler === null || sampler === void 0 ? void 0 : sampler.wrapS) || undefined !== (sampler === null || sampler === void 0 ? void 0 : sampler.wrapT) ? core_common_1.RenderTexture.Type.TileSection : core_common_1.RenderTexture.Type.Normal;
|
|
1133
|
+
texture.resolvedTexture = this._system.createTexture({
|
|
1134
|
+
type: textureType,
|
|
1135
|
+
image: {
|
|
1136
|
+
source: image,
|
|
1137
|
+
transparency: isTransparent ? RenderTexture_1.TextureTransparency.Translucent : RenderTexture_1.TextureTransparency.Opaque,
|
|
1138
|
+
},
|
|
1139
|
+
});
|
|
1007
1140
|
}
|
|
1008
1141
|
findTextureMapping(textureId) {
|
|
1009
|
-
const
|
|
1010
|
-
|
|
1011
|
-
return undefined !== texture ? new core_common_1.TextureMapping(texture, new core_common_1.TextureMapping.Params()) : undefined;
|
|
1142
|
+
const texture = this._textures[textureId];
|
|
1143
|
+
return (texture === null || texture === void 0 ? void 0 : texture.resolvedTexture) ? new core_common_1.TextureMapping(texture.resolvedTexture, new core_common_1.TextureMapping.Params()) : undefined;
|
|
1012
1144
|
}
|
|
1013
1145
|
}
|
|
1014
1146
|
exports.GltfReader = GltfReader;
|
|
@@ -1021,17 +1153,18 @@ exports.GltfReader = GltfReader;
|
|
|
1021
1153
|
* @public
|
|
1022
1154
|
*/
|
|
1023
1155
|
async function readGltfGraphics(args) {
|
|
1024
|
-
const
|
|
1025
|
-
const
|
|
1026
|
-
const reader = props ? new Reader(props, args) : undefined;
|
|
1156
|
+
const props = GltfReaderProps.create(args.gltf, true, args.baseUrl); // glTF supports exactly one coordinate system with y axis up.
|
|
1157
|
+
const reader = props ? new GltfGraphicsReader(props, args) : undefined;
|
|
1027
1158
|
if (!reader)
|
|
1028
1159
|
return undefined;
|
|
1029
1160
|
const result = await reader.read();
|
|
1030
1161
|
return result.graphic;
|
|
1031
1162
|
}
|
|
1032
1163
|
exports.readGltfGraphics = readGltfGraphics;
|
|
1033
|
-
/** Implements [[readGltfGraphics]].
|
|
1034
|
-
|
|
1164
|
+
/** Implements [[readGltfGraphics]]. Exported strictly for tests.
|
|
1165
|
+
* @internal
|
|
1166
|
+
*/
|
|
1167
|
+
class GltfGraphicsReader extends GltfReader {
|
|
1035
1168
|
constructor(props, args) {
|
|
1036
1169
|
var _a, _b, _c;
|
|
1037
1170
|
super({
|
|
@@ -1039,6 +1172,7 @@ class Reader extends GltfReader {
|
|
|
1039
1172
|
iModel: args.iModel,
|
|
1040
1173
|
vertexTableRequired: true,
|
|
1041
1174
|
});
|
|
1175
|
+
this.binaryData = props.binaryData;
|
|
1042
1176
|
const pickableId = (_a = args.pickableOptions) === null || _a === void 0 ? void 0 : _a.id;
|
|
1043
1177
|
if (pickableId) {
|
|
1044
1178
|
this._featureTable = new core_common_1.FeatureTable(1, (_c = (_b = args.pickableOptions) === null || _b === void 0 ? void 0 : _b.modelId) !== null && _c !== void 0 ? _c : pickableId, core_common_1.BatchType.Primary);
|
|
@@ -1046,8 +1180,13 @@ class Reader extends GltfReader {
|
|
|
1046
1180
|
}
|
|
1047
1181
|
}
|
|
1048
1182
|
async read() {
|
|
1049
|
-
await this.
|
|
1183
|
+
await this.resolveResources();
|
|
1050
1184
|
return this.readGltfAndCreateGraphics(true, this._featureTable, undefined);
|
|
1051
1185
|
}
|
|
1186
|
+
get nodes() { return this._nodes; }
|
|
1187
|
+
get scenes() { var _a; return (_a = this._glTF.scenes) !== null && _a !== void 0 ? _a : emptyDict; }
|
|
1188
|
+
get sceneNodes() { return this._sceneNodes; }
|
|
1189
|
+
get textures() { return this._textures; }
|
|
1052
1190
|
}
|
|
1191
|
+
exports.GltfGraphicsReader = GltfGraphicsReader;
|
|
1053
1192
|
//# sourceMappingURL=GltfReader.js.map
|