@itwin/core-frontend 3.0.0-dev.156 → 3.0.0-dev.161

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 (49) hide show
  1. package/lib/cjs/Viewport.js +2 -2
  2. package/lib/cjs/Viewport.js.map +1 -1
  3. package/lib/cjs/render/GraphicBuilder.d.ts +1 -1
  4. package/lib/cjs/render/GraphicBuilder.js.map +1 -1
  5. package/lib/cjs/tile/B3dmReader.d.ts +1 -0
  6. package/lib/cjs/tile/B3dmReader.d.ts.map +1 -1
  7. package/lib/cjs/tile/B3dmReader.js +7 -3
  8. package/lib/cjs/tile/B3dmReader.js.map +1 -1
  9. package/lib/cjs/tile/GltfReader.d.ts +466 -34
  10. package/lib/cjs/tile/GltfReader.d.ts.map +1 -1
  11. package/lib/cjs/tile/GltfReader.js +425 -180
  12. package/lib/cjs/tile/GltfReader.js.map +1 -1
  13. package/lib/cjs/tile/I3dmReader.d.ts +1 -0
  14. package/lib/cjs/tile/I3dmReader.d.ts.map +1 -1
  15. package/lib/cjs/tile/I3dmReader.js +6 -2
  16. package/lib/cjs/tile/I3dmReader.js.map +1 -1
  17. package/lib/cjs/tile/ImdlReader.d.ts +334 -10
  18. package/lib/cjs/tile/ImdlReader.d.ts.map +1 -1
  19. package/lib/cjs/tile/ImdlReader.js +84 -44
  20. package/lib/cjs/tile/ImdlReader.js.map +1 -1
  21. package/lib/cjs/tile/map/MapTiledGraphicsProvider.d.ts +3 -3
  22. package/lib/cjs/tile/map/MapTiledGraphicsProvider.d.ts.map +1 -1
  23. package/lib/cjs/tile/map/MapTiledGraphicsProvider.js +4 -6
  24. package/lib/cjs/tile/map/MapTiledGraphicsProvider.js.map +1 -1
  25. package/lib/esm/Viewport.js +2 -2
  26. package/lib/esm/Viewport.js.map +1 -1
  27. package/lib/esm/render/GraphicBuilder.d.ts +1 -1
  28. package/lib/esm/render/GraphicBuilder.js.map +1 -1
  29. package/lib/esm/tile/B3dmReader.d.ts +1 -0
  30. package/lib/esm/tile/B3dmReader.d.ts.map +1 -1
  31. package/lib/esm/tile/B3dmReader.js +8 -4
  32. package/lib/esm/tile/B3dmReader.js.map +1 -1
  33. package/lib/esm/tile/GltfReader.d.ts +466 -34
  34. package/lib/esm/tile/GltfReader.d.ts.map +1 -1
  35. package/lib/esm/tile/GltfReader.js +400 -157
  36. package/lib/esm/tile/GltfReader.js.map +1 -1
  37. package/lib/esm/tile/I3dmReader.d.ts +1 -0
  38. package/lib/esm/tile/I3dmReader.d.ts.map +1 -1
  39. package/lib/esm/tile/I3dmReader.js +7 -3
  40. package/lib/esm/tile/I3dmReader.js.map +1 -1
  41. package/lib/esm/tile/ImdlReader.d.ts +334 -10
  42. package/lib/esm/tile/ImdlReader.d.ts.map +1 -1
  43. package/lib/esm/tile/ImdlReader.js +86 -46
  44. package/lib/esm/tile/ImdlReader.js.map +1 -1
  45. package/lib/esm/tile/map/MapTiledGraphicsProvider.d.ts +3 -3
  46. package/lib/esm/tile/map/MapTiledGraphicsProvider.d.ts.map +1 -1
  47. package/lib/esm/tile/map/MapTiledGraphicsProvider.js +4 -6
  48. package/lib/esm/tile/map/MapTiledGraphicsProvider.js.map +1 -1
  49. package/package.json +22 -22
@@ -5,33 +5,173 @@
5
5
  /** @packageDocumentation
6
6
  * @module Tiles
7
7
  */
8
- import { assert, JsonUtils, utf8ToString } from "@itwin/core-bentley";
9
- import { Angle, Matrix3d, Point2d, Point3d, Range2d, Range3d, Transform, Vector3d } from "@itwin/core-geometry";
10
- import { BatchType, ColorDef, FillFlags, GltfBufferView, GltfDataType, GltfHeader, GltfMeshMode, ImageSource, ImageSourceFormat, LinePixels, MeshEdge, MeshEdges, MeshPolyline, OctEncodedNormal, PackedFeatureTable, QParams2d, QParams3d, QPoint2dList, QPoint3dList, Quantization, RenderTexture, TextureMapping, TileReadStatus, } from "@itwin/core-common";
8
+ import { assert, ByteStream, JsonUtils, utf8ToString } from "@itwin/core-bentley";
9
+ import { Angle, Matrix3d, Point2d, Point3d, Point4d, Range2d, Range3d, Transform, Vector3d } from "@itwin/core-geometry";
10
+ import { BatchType, ColorDef, Feature, FeatureTable, FillFlags, GltfHeader, ImageSource, ImageSourceFormat, LinePixels, MeshEdge, MeshEdges, MeshPolyline, OctEncodedNormal, PackedFeatureTable, QParams2d, QParams3d, QPoint2dList, QPoint3dList, Quantization, RenderTexture, TextureMapping, TileReadStatus, } from "@itwin/core-common";
11
11
  import { getImageSourceFormatForMimeType, imageElementFromImageSource } from "../ImageUtil";
12
+ import { IModelApp } from "../IModelApp";
12
13
  import { GraphicBranch } from "../render/GraphicBranch";
13
14
  import { DisplayParams } from "../render/primitives/DisplayParams";
14
15
  import { Mesh, MeshGraphicArgs } from "../render/primitives/mesh/MeshPrimitives";
15
16
  import { RealityMeshPrimitive } from "../render/primitives/mesh/RealityMeshPrimitive";
16
17
  import { TextureTransparency } from "../render/RenderTexture";
17
- // eslint-disable-next-line prefer-const
18
- let forceLUT = false;
18
+ /* eslint-disable no-restricted-syntax */
19
+ /** Enumerates the types of [[GltfMeshPrimitive]] topologies. */
20
+ var GltfMeshMode;
21
+ (function (GltfMeshMode) {
22
+ GltfMeshMode[GltfMeshMode["Points"] = 0] = "Points";
23
+ GltfMeshMode[GltfMeshMode["Lines"] = 1] = "Lines";
24
+ GltfMeshMode[GltfMeshMode["LineStrip"] = 3] = "LineStrip";
25
+ GltfMeshMode[GltfMeshMode["Triangles"] = 4] = "Triangles";
26
+ /** Not currently supported. */
27
+ GltfMeshMode[GltfMeshMode["TriangleStrip"] = 5] = "TriangleStrip";
28
+ /** Not currently supported. */
29
+ GltfMeshMode[GltfMeshMode["TriangleFan"] = 6] = "TriangleFan";
30
+ })(GltfMeshMode || (GltfMeshMode = {}));
31
+ /** Enumerates the basic data types supported by accessors, material values, technique uniforms, etc.
32
+ * @internal
33
+ */
34
+ export var GltfDataType;
35
+ (function (GltfDataType) {
36
+ GltfDataType[GltfDataType["SignedByte"] = 5120] = "SignedByte";
37
+ GltfDataType[GltfDataType["UnsignedByte"] = 5121] = "UnsignedByte";
38
+ GltfDataType[GltfDataType["SignedShort"] = 5122] = "SignedShort";
39
+ GltfDataType[GltfDataType["UnsignedShort"] = 5123] = "UnsignedShort";
40
+ GltfDataType[GltfDataType["UInt32"] = 5125] = "UInt32";
41
+ GltfDataType[GltfDataType["Float"] = 5126] = "Float";
42
+ GltfDataType[GltfDataType["Rgb"] = 6407] = "Rgb";
43
+ GltfDataType[GltfDataType["Rgba"] = 6408] = "Rgba";
44
+ GltfDataType[GltfDataType["IntVec2"] = 35667] = "IntVec2";
45
+ GltfDataType[GltfDataType["IntVec3"] = 35668] = "IntVec3";
46
+ GltfDataType[GltfDataType["FloatVec2"] = 35664] = "FloatVec2";
47
+ GltfDataType[GltfDataType["FloatVec3"] = 35665] = "FloatVec3";
48
+ GltfDataType[GltfDataType["FloatVec4"] = 35666] = "FloatVec4";
49
+ GltfDataType[GltfDataType["FloatMat3"] = 35675] = "FloatMat3";
50
+ GltfDataType[GltfDataType["FloatMat4"] = 35676] = "FloatMat4";
51
+ GltfDataType[GltfDataType["Sampler2d"] = 35678] = "Sampler2d";
52
+ })(GltfDataType || (GltfDataType = {}));
53
+ /** @internal */
54
+ var GltfMagFilter;
55
+ (function (GltfMagFilter) {
56
+ GltfMagFilter[GltfMagFilter["Nearest"] = 9728] = "Nearest";
57
+ GltfMagFilter[GltfMagFilter["Linear"] = 9729] = "Linear";
58
+ })(GltfMagFilter || (GltfMagFilter = {}));
59
+ /** @internal */
60
+ var GltfMinFilter;
61
+ (function (GltfMinFilter) {
62
+ GltfMinFilter[GltfMinFilter["Nearest"] = 9728] = "Nearest";
63
+ GltfMinFilter[GltfMinFilter["Linear"] = 9729] = "Linear";
64
+ GltfMinFilter[GltfMinFilter["NearestMipMapNearest"] = 9984] = "NearestMipMapNearest";
65
+ GltfMinFilter[GltfMinFilter["LinearMipMapNearest"] = 9985] = "LinearMipMapNearest";
66
+ GltfMinFilter[GltfMinFilter["NearestMipMapLinear"] = 9986] = "NearestMipMapLinear";
67
+ GltfMinFilter[GltfMinFilter["LinearMipMapLinear"] = 9987] = "LinearMipMapLinear";
68
+ })(GltfMinFilter || (GltfMinFilter = {}));
69
+ /** Describes how texture coordinates outside of the range [0..1] are handled. */
70
+ var GltfWrapMode;
71
+ (function (GltfWrapMode) {
72
+ GltfWrapMode[GltfWrapMode["ClampToEdge"] = 33071] = "ClampToEdge";
73
+ GltfWrapMode[GltfWrapMode["MirroredRepeat"] = 33648] = "MirroredRepeat";
74
+ GltfWrapMode[GltfWrapMode["Repeat"] = 10497] = "Repeat";
75
+ })(GltfWrapMode || (GltfWrapMode = {}));
76
+ /** Describes the intended target of a [[GltfBufferViewProps]]. */
77
+ var GltfBufferTarget;
78
+ (function (GltfBufferTarget) {
79
+ GltfBufferTarget[GltfBufferTarget["ArrayBuffer"] = 34962] = "ArrayBuffer";
80
+ GltfBufferTarget[GltfBufferTarget["ElementArrayBuffer"] = 24963] = "ElementArrayBuffer";
81
+ })(GltfBufferTarget || (GltfBufferTarget = {}));
82
+ function getNodeMeshIds(node) {
83
+ if (undefined !== node.meshes)
84
+ return typeof node.meshes === "string" ? [node.meshes] : node.meshes;
85
+ else if (undefined !== node.mesh)
86
+ return [node.mesh];
87
+ return [];
88
+ }
89
+ function isGltf1Material(material) {
90
+ const mat1 = material;
91
+ return undefined !== mat1.technique || undefined !== mat1.values;
92
+ }
93
+ /**
94
+ * A chunk of binary data exposed as a typed array.
95
+ * The count member indicates how many elements exist. This may be less than this.buffer.length due to padding added to the
96
+ * binary stream to ensure correct alignment.
97
+ * @internal
98
+ */
99
+ export class GltfBufferData {
100
+ constructor(buffer, count) {
101
+ this.buffer = buffer;
102
+ this.count = count;
103
+ }
104
+ /**
105
+ * Create a GltfBufferData of the desired type. The actual type may differ from the desired type - for example, small 32-bit integers
106
+ * may be represented as 8-bit or 16-bit integers instead.
107
+ * If the actual data type is not convertible to the desired type, this function returns undefined.
108
+ */
109
+ static create(bytes, actualType, expectedType, count) {
110
+ if (expectedType !== actualType) {
111
+ // Some data is stored in smaller data types to save space if no values exceed the maximum of the smaller type.
112
+ switch (expectedType) {
113
+ case GltfDataType.Float:
114
+ case GltfDataType.UnsignedByte:
115
+ return undefined;
116
+ case GltfDataType.UnsignedShort:
117
+ if (GltfDataType.UnsignedByte !== actualType)
118
+ return undefined;
119
+ break;
120
+ case GltfDataType.UInt32:
121
+ if (GltfDataType.UnsignedByte !== actualType && GltfDataType.UnsignedShort !== actualType)
122
+ return undefined;
123
+ break;
124
+ }
125
+ }
126
+ const data = this.createDataBuffer(bytes, actualType);
127
+ return undefined !== data ? new GltfBufferData(data, count) : undefined;
128
+ }
129
+ static createDataBuffer(bytes, actualType) {
130
+ // NB: Endianness of typed array data is determined by the 'platform byte order'. Actual data is always little-endian.
131
+ // We are assuming little-endian platform. If we find a big-endian platform, we'll need to use a DataView instead.
132
+ switch (actualType) {
133
+ case GltfDataType.UnsignedByte:
134
+ return bytes;
135
+ case GltfDataType.UnsignedShort:
136
+ return new Uint16Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 2);
137
+ case GltfDataType.UInt32:
138
+ return new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4);
139
+ case GltfDataType.Float:
140
+ return new Float32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4);
141
+ default:
142
+ return undefined;
143
+ }
144
+ }
145
+ }
146
+ /**
147
+ * A view of a chunk of glTF binary data containing an array of elements of a specific data type.
148
+ * The count member indicates how many elements exist; this may be smaller than this.data.length.
149
+ * The count member may also indicate the number of elements of a type containing more than one value of the
150
+ * underlying type. For example, a buffer of 4 32-bit floating point 'vec2' elements will have a count of 4,
151
+ * but its data member will contain 8 32-bit floating point values (2 per vec2).
152
+ * The accessor member may contain additional JSON data specific to a particular buffer.
153
+ * @internal
154
+ */
155
+ class GltfBufferView {
156
+ constructor(data, count, type, accessor, stride) {
157
+ this.data = data;
158
+ this.count = count;
159
+ this.type = type;
160
+ this.accessor = accessor;
161
+ this.stride = stride;
162
+ }
163
+ get byteLength() { return this.data.length; }
164
+ toBufferData(desiredType) {
165
+ return GltfBufferData.create(this.data, this.type, desiredType, this.count);
166
+ }
167
+ }
19
168
  /** Data required for creating a [[GltfReader]] capable of deserializing [glTF](https://www.khronos.org/gltf/).
20
169
  * @internal
21
170
  */
22
171
  export class GltfReaderProps {
23
- constructor(buffer, binaryData, accessors, bufferViews, scene, nodes, meshes, materials, extensions, samplers, techniques, yAxisUp) {
24
- this.buffer = buffer;
172
+ constructor(binaryData, glTF, yAxisUp) {
25
173
  this.binaryData = binaryData;
26
- this.accessors = accessors;
27
- this.bufferViews = bufferViews;
28
- this.scene = scene;
29
- this.nodes = nodes;
30
- this.meshes = meshes;
31
- this.materials = materials;
32
- this.extensions = extensions;
33
- this.samplers = samplers;
34
- this.techniques = techniques;
174
+ this.glTF = glTF;
35
175
  this.yAxisUp = yAxisUp;
36
176
  }
37
177
  /** Attempt to construct a new GltfReaderProps from the binary data beginning at the supplied stream's current read position. */
@@ -41,23 +181,34 @@ export class GltfReaderProps {
41
181
  return undefined;
42
182
  const binaryData = new Uint8Array(buffer.arrayBuffer, header.binaryPosition);
43
183
  buffer.curPos = header.scenePosition;
44
- const sceneStrData = buffer.nextBytes(header.sceneStrLength);
45
- const sceneStr = utf8ToString(sceneStrData);
46
- if (undefined === sceneStr)
184
+ const jsonStrData = buffer.nextBytes(header.sceneStrLength);
185
+ const jsonStr = utf8ToString(jsonStrData);
186
+ if (undefined === jsonStr)
47
187
  return undefined;
48
188
  try {
49
- const sceneValue = JSON.parse(sceneStr);
50
- const nodes = JsonUtils.asObject(sceneValue.nodes);
51
- const meshes = JsonUtils.asObject(sceneValue.meshes);
52
- const materialValues = JsonUtils.asObject(sceneValue.materials);
53
- const accessors = JsonUtils.asObject(sceneValue.accessors);
54
- const bufferViews = JsonUtils.asObject(sceneValue.bufferViews);
55
- const extensions = JsonUtils.asObject(sceneValue.extensions);
56
- const samplers = JsonUtils.asObject(sceneValue.samplers);
57
- const techniques = JsonUtils.asObject(sceneValue.techniques);
58
- if (undefined === meshes)
59
- return undefined;
60
- return new GltfReaderProps(buffer, binaryData, accessors, bufferViews, sceneValue, nodes, meshes, materialValues, extensions, samplers, techniques, yAxisUp);
189
+ const json = JSON.parse(jsonStr);
190
+ const asset = JsonUtils.asObject(json.asset);
191
+ if (header.version === 2 && !asset)
192
+ return undefined; // asset is required in glTF 2.0
193
+ const glTF = {
194
+ asset,
195
+ scene: JsonUtils.asString(json.scene),
196
+ extensions: JsonUtils.asObject(json.extensions),
197
+ extensionsUsed: JsonUtils.asArray(json.extensionsUsed),
198
+ extensionsRequired: JsonUtils.asArray(json.extensionsRequired),
199
+ accessors: JsonUtils.asObject(json.accessors),
200
+ buffers: JsonUtils.asObject(json.buffers),
201
+ bufferViews: JsonUtils.asObject(json.bufferViews),
202
+ images: JsonUtils.asObject(json.images),
203
+ materials: JsonUtils.asObject(json.materials),
204
+ meshes: JsonUtils.asObject(json.meshes),
205
+ nodes: JsonUtils.asObject(json.nodes),
206
+ samplers: JsonUtils.asObject(json.samplers),
207
+ scenes: JsonUtils.asObject(json.scenes),
208
+ textures: JsonUtils.asObject(json.textures),
209
+ techniques: JsonUtils.asObject(json.techniques),
210
+ };
211
+ return glTF.meshes ? new GltfReaderProps(binaryData, glTF, yAxisUp) : undefined;
61
212
  }
62
213
  catch (e) {
63
214
  return undefined;
@@ -85,57 +236,123 @@ export class GltfMeshData {
85
236
  }
86
237
  }
87
238
  -------------------------------------- */
239
+ const emptyDict = {};
240
+ function colorFromJson(values) {
241
+ return ColorDef.from(values[0] * 255, values[1] * 255, values[2] * 255, (1.0 - values[3]) * 255);
242
+ }
243
+ function colorFromMaterial(material) {
244
+ var _a, _b, _c, _d, _e;
245
+ if (material) {
246
+ if (isGltf1Material(material)) {
247
+ if (((_a = material.values) === null || _a === void 0 ? void 0 : _a.color) && Array.isArray(material.values.color))
248
+ return colorFromJson(material.values.color);
249
+ }
250
+ else if ((_d = (_c = (_b = material.extensions) === null || _b === void 0 ? void 0 : _b.KHR_techniques_webgl) === null || _c === void 0 ? void 0 : _c.values) === null || _d === void 0 ? void 0 : _d.u_color) {
251
+ return colorFromJson(material.extensions.KHR_techniques_webgl.values.u_color);
252
+ }
253
+ else if ((_e = material.pbrMetallicRoughness) === null || _e === void 0 ? void 0 : _e.baseColorFactor) {
254
+ return colorFromJson(material.pbrMetallicRoughness.baseColorFactor);
255
+ }
256
+ }
257
+ return ColorDef.white;
258
+ }
259
+ class TransformStack {
260
+ constructor() {
261
+ this._stack = [];
262
+ }
263
+ get transform() {
264
+ return this._stack.length > 0 ? this._stack[this._stack.length - 1] : undefined;
265
+ }
266
+ get isEmpty() {
267
+ return 0 === this._stack.length;
268
+ }
269
+ push(node) {
270
+ let nodeTransform;
271
+ if (node.matrix) {
272
+ const origin = Point3d.create(node.matrix[12], node.matrix[13], node.matrix[14]);
273
+ const matrix = Matrix3d.createRowValues(node.matrix[0], node.matrix[4], node.matrix[8], node.matrix[1], node.matrix[5], node.matrix[9], node.matrix[2], node.matrix[6], node.matrix[10]);
274
+ nodeTransform = Transform.createOriginAndMatrix(origin, matrix);
275
+ }
276
+ else if (node.rotation || node.scale || node.translation) {
277
+ // SPEC: To compose the local transformation matrix, TRS properties MUST be converted to matrices and postmultiplied in the T * R * S order;
278
+ // first the scale is applied to the vertices, then the rotation, and then the translation.
279
+ const scale = Transform.createRefs(undefined, node.scale ? Matrix3d.createScale(node.scale[0], node.scale[1], node.scale[2]) : Matrix3d.identity);
280
+ const rot = Transform.createRefs(undefined, node.rotation ? Matrix3d.createFromQuaternion(Point4d.create(node.rotation[0], node.rotation[1], node.rotation[2], node.rotation[3])) : Matrix3d.identity);
281
+ rot.matrix.transposeInPlace(); // See comment on Matrix3d.createFromQuaternion
282
+ const trans = Transform.createTranslation(node.translation ? new Point3d(node.translation[0], node.translation[1], node.translation[2]) : Point3d.createZero());
283
+ nodeTransform = scale.multiplyTransformTransform(rot);
284
+ trans.multiplyTransformTransform(nodeTransform, nodeTransform);
285
+ }
286
+ const top = this.transform;
287
+ if (!top)
288
+ this._stack.push(nodeTransform);
289
+ else
290
+ this._stack.push(nodeTransform ? top.multiplyTransformTransform(nodeTransform) : top);
291
+ }
292
+ pop() {
293
+ assert(this._stack.length > 0);
294
+ this._stack.pop();
295
+ }
296
+ }
88
297
  /** Deserializes [glTF](https://www.khronos.org/gltf/).
89
298
  * @internal
90
299
  */
91
300
  export class GltfReader {
92
- constructor(props, iModel, modelId, is3d, system, type = BatchType.Primary, isCanceled, deduplicateVertices = false) {
93
- this._buffer = props.buffer;
94
- this._scene = props.scene;
95
- this._binaryData = props.binaryData;
96
- this._accessors = props.accessors;
97
- this._bufferViews = props.bufferViews;
98
- this._meshes = props.meshes;
99
- this._nodes = props.nodes;
100
- this._materialValues = props.materials;
101
- this._samplers = props.samplers;
102
- this._techniques = props.techniques;
103
- this._extensions = props.extensions;
104
- this._yAxisUp = props.yAxisUp;
105
- this._returnToCenter = this.extractReturnToCenter(props.extensions);
106
- this._textures = props.scene.textures;
107
- this._images = props.scene.images;
108
- this._renderMaterials = props.scene.renderMaterials;
109
- this._namedTextures = props.scene.namedTextures;
110
- this._iModel = iModel;
111
- this._modelId = modelId;
112
- this._is3d = is3d;
113
- this._system = system;
114
- this._type = type;
115
- this._canceled = isCanceled;
116
- this._deduplicateVertices = deduplicateVertices;
301
+ constructor(args) {
302
+ var _a, _b, _c, _d, _e, _f, _g;
303
+ this._binaryData = args.props.binaryData;
304
+ this._glTF = args.props.glTF;
305
+ this._yAxisUp = args.props.yAxisUp;
306
+ 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;
307
+ if (rtcCenter && 3 === rtcCenter.length)
308
+ if (0 !== rtcCenter[0] || 0 !== rtcCenter[1] || 0 !== rtcCenter[2])
309
+ this._returnToCenter = Point3d.fromJSON(rtcCenter);
310
+ this._iModel = args.iModel;
311
+ this._is3d = true !== args.is2d;
312
+ this._system = (_c = args.system) !== null && _c !== void 0 ? _c : IModelApp.renderSystem;
313
+ this._type = (_d = args.type) !== null && _d !== void 0 ? _d : BatchType.Primary;
314
+ this._canceled = args.shouldAbort;
315
+ this._deduplicateVertices = (_e = args.deduplicateVertices) !== null && _e !== void 0 ? _e : false;
316
+ this._vertexTableRequired = (_f = args.vertexTableRequired) !== null && _f !== void 0 ? _f : false;
317
+ // The original implementation of GltfReader would process and produce graphics for every node in glTF.nodes.
318
+ // What it's *supposed* to do is process the nodes in glTF.scenes[glTF.scene].nodes
319
+ // Some nodes may not be referenced by the configured scene, or only indirectly via GltfNode.children.
320
+ // Perhaps some faulty tiles existed that didn't define their scenes properly?
321
+ let sceneNodes;
322
+ if (this._glTF.scenes && undefined !== this._glTF.scene)
323
+ sceneNodes = (_g = this._glTF.scenes[this._glTF.scene]) === null || _g === void 0 ? void 0 : _g.nodes;
324
+ if (!sceneNodes)
325
+ sceneNodes = Object.keys(this._nodes);
326
+ this._sceneNodes = sceneNodes;
117
327
  }
328
+ get _nodes() { var _a; return (_a = this._glTF.nodes) !== null && _a !== void 0 ? _a : emptyDict; }
329
+ get _meshes() { var _a; return (_a = this._glTF.meshes) !== null && _a !== void 0 ? _a : emptyDict; }
330
+ get _accessors() { var _a; return (_a = this._glTF.accessors) !== null && _a !== void 0 ? _a : emptyDict; }
331
+ get _bufferViews() { var _a; return (_a = this._glTF.bufferViews) !== null && _a !== void 0 ? _a : emptyDict; }
332
+ get _materialValues() { var _a; return (_a = this._glTF.materials) !== null && _a !== void 0 ? _a : emptyDict; }
118
333
  get _isCanceled() { return undefined !== this._canceled && this._canceled(this); }
119
334
  get _isVolumeClassifier() { return BatchType.VolumeClassifier === this._type; }
120
335
  readGltfAndCreateGraphics(isLeaf, featureTable, contentRange, transformToRoot, pseudoRtcBias, instances) {
121
336
  var _a;
122
337
  if (this._isCanceled)
123
338
  return { readStatus: TileReadStatus.Canceled, isLeaf };
124
- if (this._returnToCenter !== undefined || ((_a = this._nodes[0]) === null || _a === void 0 ? void 0 : _a.matrix) !== undefined || (pseudoRtcBias !== undefined && pseudoRtcBias.magnitude() < 1.0E5))
339
+ // If contentRange was not supplied, we will compute it as we read the meshes.
340
+ if (!contentRange)
341
+ this._computedContentRange = contentRange = Range3d.createNull();
342
+ else
343
+ this._computedContentRange = undefined;
344
+ // ###TODO this looks like a hack? Why does it assume the first node's transform is special, or that the transform will be specified as a matrix instead of translation+rot+scale?
345
+ if (this._returnToCenter || ((_a = this._nodes[0]) === null || _a === void 0 ? void 0 : _a.matrix) || (pseudoRtcBias && pseudoRtcBias.magnitude() < 1.0E5))
125
346
  pseudoRtcBias = undefined;
126
- const childNodes = new Set();
127
- for (const key of Object.keys(this._nodes)) {
128
- const node = this._nodes[key];
129
- if (node.children)
130
- for (const child of node.children)
131
- childNodes.add(child.toString());
132
- }
347
+ const transformStack = new TransformStack();
133
348
  const renderGraphicList = [];
134
349
  let readStatus = TileReadStatus.InvalidTileData;
135
- for (const nodeKey of Object.keys(this._nodes))
136
- if (!childNodes.has(nodeKey))
137
- if (TileReadStatus.Success !== (readStatus = this.readNodeAndCreateGraphics(renderGraphicList, this._nodes[nodeKey], featureTable, undefined, instances, pseudoRtcBias)))
138
- return { readStatus, isLeaf };
350
+ for (const nodeKey of this._sceneNodes) {
351
+ assert(transformStack.isEmpty);
352
+ const node = this._nodes[nodeKey];
353
+ if (node && TileReadStatus.Success !== (readStatus = this.readNodeAndCreateGraphics(renderGraphicList, node, featureTable, transformStack, instances, pseudoRtcBias)))
354
+ return { readStatus, isLeaf };
355
+ }
139
356
  if (0 === renderGraphicList.length)
140
357
  return { readStatus: TileReadStatus.InvalidTileData, isLeaf };
141
358
  let renderGraphic;
@@ -145,20 +362,21 @@ export class GltfReader {
145
362
  renderGraphic = this._system.createGraphicList(renderGraphicList);
146
363
  let transform;
147
364
  let range = contentRange;
148
- if (undefined !== this._returnToCenter || undefined !== pseudoRtcBias || this._yAxisUp || undefined !== transformToRoot) {
149
- if (undefined !== this._returnToCenter)
150
- transform = Transform.createTranslationXYZ(this._returnToCenter[0], this._returnToCenter[1], this._returnToCenter[2]);
151
- else if (undefined !== pseudoRtcBias)
365
+ if (this._returnToCenter || pseudoRtcBias || this._yAxisUp || transformToRoot) {
366
+ if (this._returnToCenter)
367
+ transform = Transform.createTranslation(this._returnToCenter.clone());
368
+ else if (pseudoRtcBias)
152
369
  transform = Transform.createTranslationXYZ(pseudoRtcBias.x, pseudoRtcBias.y, pseudoRtcBias.z);
153
370
  else
154
371
  transform = Transform.createIdentity();
155
372
  if (this._yAxisUp)
156
373
  transform = transform.multiplyTransformMatrix3d(Matrix3d.createRotationAroundVector(Vector3d.create(1.0, 0.0, 0.0), Angle.createRadians(Angle.piOver2Radians)));
157
- if (undefined !== transformToRoot)
374
+ if (transformToRoot)
158
375
  transform = transformToRoot.multiplyTransformTransform(transform);
159
376
  range = transform.inverse().multiplyRange(contentRange);
160
377
  }
161
- renderGraphic = this._system.createBatch(renderGraphic, PackedFeatureTable.pack(featureTable), range);
378
+ if (featureTable)
379
+ renderGraphic = this._system.createBatch(renderGraphic, PackedFeatureTable.pack(featureTable), range);
162
380
  if (transform) {
163
381
  const branch = new GraphicBranch(true);
164
382
  branch.add(renderGraphic);
@@ -172,11 +390,9 @@ export class GltfReader {
172
390
  };
173
391
  }
174
392
  graphicFromMeshData(gltfMesh, meshGraphicArgs, instances) {
175
- if (!gltfMesh.points || !gltfMesh.pointRange) {
176
- assert(false);
393
+ if (!gltfMesh.points || !gltfMesh.pointRange)
177
394
  return;
178
- }
179
- const realityMeshPrimitive = (forceLUT || instances) ? undefined : RealityMeshPrimitive.createFromGltfMesh(gltfMesh);
395
+ const realityMeshPrimitive = (this._vertexTableRequired || instances) ? undefined : RealityMeshPrimitive.createFromGltfMesh(gltfMesh);
180
396
  if (realityMeshPrimitive) {
181
397
  const realityMesh = this._system.createRealityMesh(realityMeshPrimitive);
182
398
  if (realityMesh)
@@ -197,16 +413,12 @@ export class GltfReader {
197
413
  mesh.normals.push(new OctEncodedNormal(normal));
198
414
  return mesh.getGraphics(meshGraphicArgs, this._system, instances);
199
415
  }
200
- readNodeAndCreateGraphics(renderGraphicList, node, featureTable, parentTransform, instances, pseudoRtcBias) {
416
+ readNodeAndCreateGraphics(renderGraphicList, node, featureTable, transformStack, instances, pseudoRtcBias) {
201
417
  if (undefined === node)
202
418
  return TileReadStatus.InvalidTileData;
203
- let thisTransform = parentTransform;
204
- let thisBias;
205
- if (Array.isArray(node.matrix)) {
206
- const jTrans = node.matrix;
207
- const nodeTransform = Transform.createOriginAndMatrix(Point3d.create(jTrans[12], jTrans[13], jTrans[14]), Matrix3d.createRowValues(jTrans[0], jTrans[4], jTrans[8], jTrans[1], jTrans[5], jTrans[9], jTrans[2], jTrans[6], jTrans[10]));
208
- thisTransform = thisTransform ? thisTransform.multiplyTransformTransform(nodeTransform) : nodeTransform;
209
- }
419
+ // IMPORTANT: Do not return without popping this node from the stack.
420
+ transformStack.push(node);
421
+ const thisTransform = transformStack.transform;
210
422
  /**
211
423
  * This is a workaround for tiles generated by
212
424
  * context capture which have a large offset from the tileset origin that exceeds the
@@ -215,19 +427,24 @@ export class GltfReader {
215
427
  * as the vertices are supplied in a quantized format, applying the RTC bias to
216
428
  * quantization origin will make these tiles work correctly.
217
429
  */
218
- if (undefined !== pseudoRtcBias) {
430
+ let thisBias;
431
+ if (undefined !== pseudoRtcBias)
219
432
  thisBias = (undefined === thisTransform) ? pseudoRtcBias : thisTransform.matrix.multiplyInverse(pseudoRtcBias);
220
- }
221
- const meshKey = node.meshes ? node.meshes : node.mesh;
222
- if (undefined !== meshKey) {
433
+ for (const meshKey of getNodeMeshIds(node)) {
223
434
  const nodeMesh = this._meshes[meshKey];
224
- if (nodeMesh) {
435
+ if (nodeMesh === null || nodeMesh === void 0 ? void 0 : nodeMesh.primitives) {
225
436
  const meshGraphicArgs = new MeshGraphicArgs();
226
437
  const meshes = [];
227
438
  for (const primitive of nodeMesh.primitives) {
228
439
  const geometry = this.readMeshPrimitive(primitive, featureTable, thisBias);
229
- if (undefined !== geometry)
440
+ if (geometry) {
230
441
  meshes.push(geometry);
442
+ if (this._computedContentRange && geometry.pointRange) {
443
+ const invTransform = thisTransform === null || thisTransform === void 0 ? void 0 : thisTransform.inverse();
444
+ const meshRange = invTransform ? invTransform.multiplyRange(geometry.pointRange) : geometry.pointRange;
445
+ this._computedContentRange.extendRange(meshRange);
446
+ }
447
+ }
231
448
  }
232
449
  let renderGraphic;
233
450
  if (0 !== meshes.length) {
@@ -256,11 +473,16 @@ export class GltfReader {
256
473
  }
257
474
  }
258
475
  if (node.children) {
259
- for (const child of node.children)
260
- this.readNodeAndCreateGraphics(renderGraphicList, this._nodes[child], featureTable, thisTransform, instances);
476
+ for (const childId of node.children) {
477
+ const child = this._nodes[childId];
478
+ if (child)
479
+ this.readNodeAndCreateGraphics(renderGraphicList, child, featureTable, transformStack, instances);
480
+ }
261
481
  }
482
+ transformStack.pop();
262
483
  return TileReadStatus.Success;
263
484
  }
485
+ // ###TODO what is the actual type of `json`?
264
486
  getBufferView(json, accessorName) {
265
487
  try {
266
488
  const accessorValue = JsonUtils.asString(json[accessorName]);
@@ -315,21 +537,9 @@ export class GltfReader {
315
537
  return undefined !== view ? view.toBufferData(type) : undefined;
316
538
  }
317
539
  readFeatureIndices(_json) { return undefined; }
318
- colorFromJson(values) { return ColorDef.from(values[0] * 255, values[1] * 255, values[2] * 255, (1.0 - values[3]) * 255); }
319
- colorFromMaterial(materialJson) {
320
- if (materialJson) {
321
- if (materialJson.values && Array.isArray(materialJson.values.color))
322
- return this.colorFromJson(materialJson.values.color);
323
- else if (materialJson.pbrMetallicRoughness && Array.isArray(materialJson.pbrMetallicRoughness.baseColorFactor))
324
- return this.colorFromJson(materialJson.pbrMetallicRoughness.baseColorFactor);
325
- else if (materialJson.extensions && materialJson.extensions.KHR_techniques_webgl && materialJson.extensions.KHR_techniques_webgl.values && materialJson.extensions.KHR_techniques_webgl.values.u_color)
326
- return this.colorFromJson(materialJson.extensions.KHR_techniques_webgl.values.u_color);
327
- }
328
- return ColorDef.white;
329
- }
330
- extractTextureId(materialJson) {
540
+ extractTextureId(material) {
331
541
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
332
- if (typeof materialJson !== "object")
542
+ if (typeof material !== "object")
333
543
  return undefined;
334
544
  const extractId = (value) => {
335
545
  switch (typeof value) {
@@ -342,48 +552,36 @@ export class GltfReader {
342
552
  }
343
553
  };
344
554
  // Bimium's shader value...almost certainly obsolete at this point.
345
- let id = extractId((_a = materialJson.values) === null || _a === void 0 ? void 0 : _a.tex);
346
- if (undefined !== id)
347
- return id;
555
+ if (isGltf1Material(material))
556
+ return (_a = material.diffuse) !== null && _a !== void 0 ? _a : extractId((_b = material.values) === null || _b === void 0 ? void 0 : _b.tex);
348
557
  // KHR_techniques_webgl extension
349
- const techniques = (_c = (_b = this._extensions) === null || _b === void 0 ? void 0 : _b.KHR_techniques_webgl) === null || _c === void 0 ? void 0 : _c.techniques;
350
- const ext = Array.isArray(techniques) ? (_d = materialJson.extensions) === null || _d === void 0 ? void 0 : _d.KHR_techniques_webgl : undefined;
351
- if (undefined !== ext && typeof ext.values === "object") {
558
+ const techniques = (_d = (_c = this._glTF.extensions) === null || _c === void 0 ? void 0 : _c.KHR_techniques_webgl) === null || _d === void 0 ? void 0 : _d.techniques;
559
+ const ext = Array.isArray(techniques) ? (_e = material.extensions) === null || _e === void 0 ? void 0 : _e.KHR_techniques_webgl : undefined;
560
+ if (techniques && undefined !== ext && typeof (ext.values) === "object") {
352
561
  const uniforms = typeof ext.technique === "number" ? techniques[ext.technique].uniforms : undefined;
353
562
  if (typeof uniforms === "object") {
354
563
  for (const uniformName of Object.keys(uniforms)) {
355
564
  const uniform = uniforms[uniformName];
356
565
  if (typeof uniform === "object" && uniform.type === GltfDataType.Sampler2d)
357
- return extractId((_e = ext.values[uniformName]) === null || _e === void 0 ? void 0 : _e.index);
566
+ return extractId((_f = ext.values[uniformName]) === null || _f === void 0 ? void 0 : _f.index);
358
567
  }
359
568
  }
360
569
  }
361
- id = extractId((_f = materialJson.diffuseTexture) === null || _f === void 0 ? void 0 : _f.index);
362
- id = id !== null && id !== void 0 ? id : extractId((_g = materialJson.emissiveTexture) === null || _g === void 0 ? void 0 : _g.index);
363
- return id !== null && id !== void 0 ? id : extractId((_j = (_h = materialJson.pbrMetallicRoughness) === null || _h === void 0 ? void 0 : _h.baseColorTexture) === null || _j === void 0 ? void 0 : _j.index);
570
+ const id = extractId((_g = material.emissiveTexture) === null || _g === void 0 ? void 0 : _g.index);
571
+ return id !== null && id !== void 0 ? id : extractId((_j = (_h = material.pbrMetallicRoughness) === null || _h === void 0 ? void 0 : _h.baseColorTexture) === null || _j === void 0 ? void 0 : _j.index);
364
572
  }
365
573
  createDisplayParams(materialJson, hasBakedLighting) {
366
574
  const textureId = this.extractTextureId(materialJson);
367
575
  const textureMapping = undefined !== textureId ? this.findTextureMapping(textureId) : undefined;
368
- const color = this.colorFromMaterial(materialJson);
576
+ const color = colorFromMaterial(materialJson);
369
577
  return new DisplayParams(DisplayParams.Type.Mesh, color, color, 1, LinePixels.Solid, FillFlags.Always, undefined, undefined, hasBakedLighting, textureMapping);
370
578
  }
371
- extractReturnToCenter(extensions) {
372
- if (extensions === undefined) {
373
- return undefined;
374
- }
375
- const cesiumRtc = JsonUtils.asObject(extensions.CESIUM_RTC);
376
- if (cesiumRtc === undefined)
377
- return undefined;
378
- const rtc = JsonUtils.asArray(cesiumRtc.center);
379
- return (rtc[0] === 0.0 && rtc[1] === 0.0 && rtc[2] === 0.0) ? undefined : rtc;
380
- }
381
579
  readMeshPrimitive(primitive, featureTable, pseudoRtcBias) {
382
- var _a, _b;
580
+ var _a, _b, _c, _d, _e, _f;
383
581
  const materialName = JsonUtils.asString(primitive.material);
384
582
  const hasBakedLighting = undefined === primitive.attributes.NORMAL;
385
- const materialValue = 0 < materialName.length ? JsonUtils.asObject(this._materialValues[materialName]) : undefined;
386
- const displayParams = this.createDisplayParams(materialValue, hasBakedLighting);
583
+ const material = 0 < materialName.length ? this._materialValues[materialName] : undefined;
584
+ const displayParams = this.createDisplayParams(material, hasBakedLighting);
387
585
  if (undefined === displayParams)
388
586
  return undefined;
389
587
  let primitiveType = -1;
@@ -420,12 +618,12 @@ export class GltfReader {
420
618
  // uv parameters to pick the colors out of the color map texture.
421
619
  meshPrimitive.colorMap.insert(displayParams.fillColor.tbgr); // White...
422
620
  const colorIndices = this.readBufferData16(primitive.attributes, "_COLORINDEX");
423
- if (undefined !== colorIndices) {
621
+ if (undefined !== colorIndices && material) {
424
622
  let texStep;
425
- if (materialValue.values !== undefined && Array.isArray(materialValue.values.texStep))
426
- texStep = materialValue.values.texStep;
427
- else if (materialValue.extensions && materialValue.extensions.KHR_techniques_webgl && materialValue.extensions.KHR_techniques_webgl.values && Array.isArray(materialValue.extensions.KHR_techniques_webgl.values.u_texStep))
428
- texStep = materialValue.extensions.KHR_techniques_webgl.values.u_texStep;
623
+ if (isGltf1Material(material))
624
+ texStep = (_a = material.values) === null || _a === void 0 ? void 0 : _a.texStep;
625
+ else
626
+ texStep = (_d = (_c = (_b = material.extensions) === null || _b === void 0 ? void 0 : _b.KHR_techniques_webgl) === null || _c === void 0 ? void 0 : _c.values) === null || _d === void 0 ? void 0 : _d.u_texStep;
429
627
  if (texStep) {
430
628
  const uvParams = [];
431
629
  for (let i = 0; i < colorIndices.count; i++)
@@ -435,7 +633,7 @@ export class GltfReader {
435
633
  mesh.uvQParams = paramList.params;
436
634
  }
437
635
  }
438
- if ((_a = primitive.extensions) === null || _a === void 0 ? void 0 : _a.KHR_draco_mesh_compression) {
636
+ if ((_e = primitive.extensions) === null || _e === void 0 ? void 0 : _e.KHR_draco_mesh_compression) {
439
637
  return undefined; // Defer Draco decompression until web workers implementation.
440
638
  /*
441
639
  const dracoExtension = primitive.extensions.KHR_draco_mesh_compression;
@@ -473,7 +671,7 @@ export class GltfReader {
473
671
  }
474
672
  if (displayParams.textureMapping && !mesh.uvs)
475
673
  return undefined;
476
- if ((_b = primitive.extensions) === null || _b === void 0 ? void 0 : _b.CESIUM_primitive_outline) {
674
+ if ((_f = primitive.extensions) === null || _f === void 0 ? void 0 : _f.CESIUM_primitive_outline) {
477
675
  const data = this.readBufferData32(primitive.extensions.CESIUM_primitive_outline, "indices");
478
676
  if (data !== undefined) {
479
677
  assert(0 === data.count % 2);
@@ -717,33 +915,39 @@ export class GltfReader {
717
915
  return true;
718
916
  }
719
917
  async loadTextures() {
720
- if (undefined === this._textures)
918
+ var _a, _b;
919
+ if (undefined === this._glTF.textures)
721
920
  return;
722
921
  const transparentTextures = new Set();
723
- for (const name of Object.keys(this._materialValues)) {
724
- const materialValue = this._materialValues[name];
725
- let technique;
726
- if (undefined !== materialValue.values &&
727
- undefined !== materialValue.values.tex &&
728
- undefined !== materialValue.technique &&
729
- undefined !== (technique = this._techniques[materialValue.technique]) &&
730
- undefined !== technique.states &&
731
- Array.isArray(technique.states.enable)) {
732
- for (const enable of technique.states.enable)
733
- if (enable === 3042)
734
- transparentTextures.add(materialValue.values.tex);
922
+ if (this._glTF.techniques) {
923
+ for (const name of Object.keys(this._materialValues)) {
924
+ const material = this._materialValues[name];
925
+ if (material && isGltf1Material(material) && undefined !== material.technique && undefined !== ((_a = material.values) === null || _a === void 0 ? void 0 : _a.tex)) {
926
+ const technique = this._glTF.techniques[material.technique];
927
+ if ((_b = technique === null || technique === void 0 ? void 0 : technique.states) === null || _b === void 0 ? void 0 : _b.enable) {
928
+ for (const enable of technique.states.enable) {
929
+ if (3042 === enable) { // 3042 = BLEND
930
+ transparentTextures.add(material.values.tex.toString());
931
+ break;
932
+ }
933
+ }
934
+ }
935
+ }
735
936
  }
736
937
  }
737
938
  const promises = new Array();
738
- for (const name of Object.keys(this._textures))
939
+ for (const name of Object.keys(this._glTF.textures))
739
940
  promises.push(this.loadTexture(name, transparentTextures.has(name)));
740
941
  if (promises.length > 0)
741
942
  await Promise.all(promises);
742
943
  }
743
944
  async loadTextureImage(imageJson, samplerJson, isTransparent) {
945
+ var _a;
744
946
  try {
745
947
  const binaryImageJson = (imageJson.extensions && imageJson.extensions.KHR_binary_glTF) ? JsonUtils.asObject(imageJson.extensions.KHR_binary_glTF) : imageJson;
746
948
  const bufferView = this._bufferViews[binaryImageJson.bufferView];
949
+ if (!bufferView || undefined === bufferView.byteLength || bufferView.byteLength <= 0)
950
+ return undefined;
747
951
  const mimeType = JsonUtils.asString(binaryImageJson.mimeType);
748
952
  const format = getImageSourceFormatForMimeType(mimeType);
749
953
  if (undefined === format)
@@ -752,7 +956,7 @@ export class GltfReader {
752
956
  if (undefined !== samplerJson &&
753
957
  (undefined !== samplerJson.wrapS || undefined !== samplerJson.wrapT))
754
958
  textureType = RenderTexture.Type.TileSection;
755
- const offset = bufferView.byteOffset;
959
+ const offset = (_a = bufferView.byteOffset) !== null && _a !== void 0 ? _a : 0;
756
960
  /* -----------------------------------
757
961
  const jpegArray = this._binaryData.slice(offset, offset + bufferView.byteLength);
758
962
  const jpegArrayBuffer = jpegArray.buffer;
@@ -787,16 +991,55 @@ export class GltfReader {
787
991
  }
788
992
  }
789
993
  async loadTexture(textureId, isTransparent) {
790
- const textureJson = JsonUtils.asObject(this._textures[textureId]);
994
+ if (!this._glTF.textures || !this._glTF.images)
995
+ return;
996
+ const textureJson = JsonUtils.asObject(this._glTF.textures[textureId]);
791
997
  if (undefined === textureJson)
792
998
  return;
793
- const texture = await this.loadTextureImage(this._images[textureJson.source], undefined === this._samplers ? undefined : this._samplers[textureJson.sampler], isTransparent);
999
+ const texture = await this.loadTextureImage(this._glTF.images[textureJson.source], this._glTF.samplers ? this._glTF.samplers[textureJson.sampler] : undefined, isTransparent);
794
1000
  textureJson.renderTexture = texture;
795
1001
  }
796
1002
  findTextureMapping(textureId) {
797
- const textureJson = JsonUtils.asObject(this._textures[textureId]);
1003
+ const textureJson = this._glTF.textures ? JsonUtils.asObject(this._glTF.textures[textureId]) : undefined;
798
1004
  const texture = undefined !== textureJson ? textureJson.renderTexture : undefined;
799
1005
  return undefined !== texture ? new TextureMapping(texture, new TextureMapping.Params()) : undefined;
800
1006
  }
801
1007
  }
1008
+ /** Produce a [[RenderGraphic]] from a [glTF](https://www.khronos.org/gltf/) asset suitable for use in [view decorations]($docs/learning/frontend/ViewDecorations).
1009
+ * @returns a graphic produced from the glTF asset's default scene, or `undefined` if a graphic could not be produced from the asset.
1010
+ * @note Support for the full [glTF 2.0 specification](https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html) is currently a work in progress.
1011
+ * If a particular glTF asset fails to load and/or display properly, please
1012
+ * [submit an issue](https://github.com/iTwin/itwinjs-core/issues).
1013
+ * @see [Example decorator]($docs/learning/frontend/ViewDecorations#gltf-decorations) for an example of a decorator that reads and displays a glTF asset.
1014
+ * @public
1015
+ */
1016
+ export async function readGltfGraphics(args) {
1017
+ const stream = new ByteStream(args.gltf.buffer);
1018
+ const props = GltfReaderProps.create(stream, true); // glTF supports exactly one coordinate system with y axis up.
1019
+ const reader = props ? new Reader(props, args) : undefined;
1020
+ if (!reader)
1021
+ return undefined;
1022
+ const result = await reader.read();
1023
+ return result.graphic;
1024
+ }
1025
+ /** Implements [[readGltfGraphics]]. */
1026
+ class Reader extends GltfReader {
1027
+ constructor(props, args) {
1028
+ var _a, _b, _c;
1029
+ super({
1030
+ props,
1031
+ iModel: args.iModel,
1032
+ vertexTableRequired: true,
1033
+ });
1034
+ const pickableId = (_a = args.pickableOptions) === null || _a === void 0 ? void 0 : _a.id;
1035
+ if (pickableId) {
1036
+ this._featureTable = new FeatureTable(1, (_c = (_b = args.pickableOptions) === null || _b === void 0 ? void 0 : _b.modelId) !== null && _c !== void 0 ? _c : pickableId, BatchType.Primary);
1037
+ this._featureTable.insert(new Feature(pickableId));
1038
+ }
1039
+ }
1040
+ async read() {
1041
+ await this.loadTextures();
1042
+ return this.readGltfAndCreateGraphics(true, this._featureTable, undefined);
1043
+ }
1044
+ }
802
1045
  //# sourceMappingURL=GltfReader.js.map