@itwin/core-frontend 4.0.0-dev.44 → 4.0.0-dev.46
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/core-frontend.d.ts +1 -0
- package/lib/cjs/core-frontend.d.ts.map +1 -1
- package/lib/cjs/core-frontend.js +1 -0
- package/lib/cjs/core-frontend.js.map +1 -1
- package/lib/cjs/gltf/GltfModel.d.ts +91 -0
- package/lib/cjs/gltf/GltfModel.d.ts.map +1 -0
- package/lib/cjs/gltf/GltfModel.js +10 -0
- package/lib/cjs/gltf/GltfModel.js.map +1 -0
- package/lib/cjs/gltf/GltfParser.d.ts +26 -0
- package/lib/cjs/gltf/GltfParser.d.ts.map +1 -0
- package/lib/cjs/gltf/GltfParser.js +352 -0
- package/lib/cjs/gltf/GltfParser.js.map +1 -0
- package/lib/cjs/gltf/GltfSchema.d.ts +557 -0
- package/lib/cjs/gltf/GltfSchema.d.ts.map +1 -0
- package/lib/cjs/gltf/GltfSchema.js +138 -0
- package/lib/cjs/gltf/GltfSchema.js.map +1 -0
- package/lib/cjs/render/GraphicBuilder.d.ts +5 -2
- package/lib/cjs/render/GraphicBuilder.d.ts.map +1 -1
- package/lib/cjs/render/GraphicBuilder.js +12 -3
- package/lib/cjs/render/GraphicBuilder.js.map +1 -1
- package/lib/cjs/tile/B3dmReader.d.ts +2 -1
- package/lib/cjs/tile/B3dmReader.d.ts.map +1 -1
- package/lib/cjs/tile/B3dmReader.js +2 -1
- package/lib/cjs/tile/B3dmReader.js.map +1 -1
- package/lib/cjs/tile/GltfReader.d.ts +13 -420
- package/lib/cjs/tile/GltfReader.d.ts.map +1 -1
- package/lib/cjs/tile/GltfReader.js +118 -192
- package/lib/cjs/tile/GltfReader.js.map +1 -1
- package/lib/cjs/tile/RealityTileLoader.d.ts.map +1 -1
- package/lib/cjs/tile/RealityTileLoader.js +14 -2
- package/lib/cjs/tile/RealityTileLoader.js.map +1 -1
- package/lib/cjs/tile/Tile.d.ts +10 -1
- package/lib/cjs/tile/Tile.d.ts.map +1 -1
- package/lib/cjs/tile/Tile.js +22 -2
- package/lib/cjs/tile/Tile.js.map +1 -1
- package/lib/esm/core-frontend.d.ts +1 -0
- package/lib/esm/core-frontend.d.ts.map +1 -1
- package/lib/esm/core-frontend.js +1 -0
- package/lib/esm/core-frontend.js.map +1 -1
- package/lib/esm/gltf/GltfModel.d.ts +91 -0
- package/lib/esm/gltf/GltfModel.d.ts.map +1 -0
- package/lib/esm/gltf/GltfModel.js +9 -0
- package/lib/esm/gltf/GltfModel.js.map +1 -0
- package/lib/esm/gltf/GltfParser.d.ts +26 -0
- package/lib/esm/gltf/GltfParser.d.ts.map +1 -0
- package/lib/esm/gltf/GltfParser.js +329 -0
- package/lib/esm/gltf/GltfParser.js.map +1 -0
- package/lib/esm/gltf/GltfSchema.d.ts +557 -0
- package/lib/esm/gltf/GltfSchema.d.ts.map +1 -0
- package/lib/esm/gltf/GltfSchema.js +131 -0
- package/lib/esm/gltf/GltfSchema.js.map +1 -0
- package/lib/esm/render/GraphicBuilder.d.ts +5 -2
- package/lib/esm/render/GraphicBuilder.d.ts.map +1 -1
- package/lib/esm/render/GraphicBuilder.js +13 -4
- package/lib/esm/render/GraphicBuilder.js.map +1 -1
- package/lib/esm/tile/B3dmReader.d.ts +2 -1
- package/lib/esm/tile/B3dmReader.d.ts.map +1 -1
- package/lib/esm/tile/B3dmReader.js +2 -1
- package/lib/esm/tile/B3dmReader.js.map +1 -1
- package/lib/esm/tile/GltfReader.d.ts +13 -420
- package/lib/esm/tile/GltfReader.d.ts.map +1 -1
- package/lib/esm/tile/GltfReader.js +75 -149
- package/lib/esm/tile/GltfReader.js.map +1 -1
- package/lib/esm/tile/RealityTileLoader.d.ts.map +1 -1
- package/lib/esm/tile/RealityTileLoader.js +14 -2
- package/lib/esm/tile/RealityTileLoader.js.map +1 -1
- package/lib/esm/tile/Tile.d.ts +10 -1
- package/lib/esm/tile/Tile.d.ts.map +1 -1
- package/lib/esm/tile/Tile.js +22 -2
- package/lib/esm/tile/Tile.js.map +1 -1
- package/package.json +22 -22
|
@@ -26,7 +26,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
26
26
|
return result;
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.GltfGraphicsReader = exports.readGltfGraphics = exports.GltfReader = exports.GltfMeshData = exports.GltfReaderProps = exports.GltfBufferData =
|
|
29
|
+
exports.GltfGraphicsReader = exports.readGltfGraphics = exports.GltfReader = exports.GltfMeshData = exports.GltfReaderProps = exports.GltfBufferData = void 0;
|
|
30
30
|
const core_bentley_1 = require("@itwin/core-bentley");
|
|
31
31
|
const core_geometry_1 = require("@itwin/core-geometry");
|
|
32
32
|
const core_common_1 = require("@itwin/core-common");
|
|
@@ -38,102 +38,7 @@ const RealityMeshParams_1 = require("../render/RealityMeshParams");
|
|
|
38
38
|
const DisplayParams_1 = require("../render/primitives/DisplayParams");
|
|
39
39
|
const MeshPrimitives_1 = require("../render/primitives/mesh/MeshPrimitives");
|
|
40
40
|
const Primitives_1 = require("../render/primitives/Primitives");
|
|
41
|
-
|
|
42
|
-
/** Enumerates the types of [[GltfMeshPrimitive]] topologies. */
|
|
43
|
-
var GltfMeshMode;
|
|
44
|
-
(function (GltfMeshMode) {
|
|
45
|
-
GltfMeshMode[GltfMeshMode["Points"] = 0] = "Points";
|
|
46
|
-
GltfMeshMode[GltfMeshMode["Lines"] = 1] = "Lines";
|
|
47
|
-
GltfMeshMode[GltfMeshMode["LineStrip"] = 3] = "LineStrip";
|
|
48
|
-
GltfMeshMode[GltfMeshMode["Triangles"] = 4] = "Triangles";
|
|
49
|
-
/** Not currently supported. */
|
|
50
|
-
GltfMeshMode[GltfMeshMode["TriangleStrip"] = 5] = "TriangleStrip";
|
|
51
|
-
/** Not currently supported. */
|
|
52
|
-
GltfMeshMode[GltfMeshMode["TriangleFan"] = 6] = "TriangleFan";
|
|
53
|
-
})(GltfMeshMode || (GltfMeshMode = {}));
|
|
54
|
-
/** Enumerates the basic data types supported by accessors, material values, technique uniforms, etc.
|
|
55
|
-
* @internal
|
|
56
|
-
*/
|
|
57
|
-
var GltfDataType;
|
|
58
|
-
(function (GltfDataType) {
|
|
59
|
-
GltfDataType[GltfDataType["SignedByte"] = 5120] = "SignedByte";
|
|
60
|
-
GltfDataType[GltfDataType["UnsignedByte"] = 5121] = "UnsignedByte";
|
|
61
|
-
GltfDataType[GltfDataType["SignedShort"] = 5122] = "SignedShort";
|
|
62
|
-
GltfDataType[GltfDataType["UnsignedShort"] = 5123] = "UnsignedShort";
|
|
63
|
-
GltfDataType[GltfDataType["UInt32"] = 5125] = "UInt32";
|
|
64
|
-
GltfDataType[GltfDataType["Float"] = 5126] = "Float";
|
|
65
|
-
GltfDataType[GltfDataType["Rgb"] = 6407] = "Rgb";
|
|
66
|
-
GltfDataType[GltfDataType["Rgba"] = 6408] = "Rgba";
|
|
67
|
-
GltfDataType[GltfDataType["IntVec2"] = 35667] = "IntVec2";
|
|
68
|
-
GltfDataType[GltfDataType["IntVec3"] = 35668] = "IntVec3";
|
|
69
|
-
GltfDataType[GltfDataType["FloatVec2"] = 35664] = "FloatVec2";
|
|
70
|
-
GltfDataType[GltfDataType["FloatVec3"] = 35665] = "FloatVec3";
|
|
71
|
-
GltfDataType[GltfDataType["FloatVec4"] = 35666] = "FloatVec4";
|
|
72
|
-
GltfDataType[GltfDataType["FloatMat3"] = 35675] = "FloatMat3";
|
|
73
|
-
GltfDataType[GltfDataType["FloatMat4"] = 35676] = "FloatMat4";
|
|
74
|
-
GltfDataType[GltfDataType["Sampler2d"] = 35678] = "Sampler2d";
|
|
75
|
-
})(GltfDataType = exports.GltfDataType || (exports.GltfDataType = {}));
|
|
76
|
-
/** @internal */
|
|
77
|
-
var GltfMagFilter;
|
|
78
|
-
(function (GltfMagFilter) {
|
|
79
|
-
GltfMagFilter[GltfMagFilter["Nearest"] = 9728] = "Nearest";
|
|
80
|
-
GltfMagFilter[GltfMagFilter["Linear"] = 9729] = "Linear";
|
|
81
|
-
})(GltfMagFilter || (GltfMagFilter = {}));
|
|
82
|
-
/** @internal */
|
|
83
|
-
var GltfMinFilter;
|
|
84
|
-
(function (GltfMinFilter) {
|
|
85
|
-
GltfMinFilter[GltfMinFilter["Nearest"] = 9728] = "Nearest";
|
|
86
|
-
GltfMinFilter[GltfMinFilter["Linear"] = 9729] = "Linear";
|
|
87
|
-
GltfMinFilter[GltfMinFilter["NearestMipMapNearest"] = 9984] = "NearestMipMapNearest";
|
|
88
|
-
GltfMinFilter[GltfMinFilter["LinearMipMapNearest"] = 9985] = "LinearMipMapNearest";
|
|
89
|
-
GltfMinFilter[GltfMinFilter["NearestMipMapLinear"] = 9986] = "NearestMipMapLinear";
|
|
90
|
-
GltfMinFilter[GltfMinFilter["LinearMipMapLinear"] = 9987] = "LinearMipMapLinear";
|
|
91
|
-
})(GltfMinFilter || (GltfMinFilter = {}));
|
|
92
|
-
/** Describes how texture coordinates outside of the range [0..1] are handled.
|
|
93
|
-
* @internal
|
|
94
|
-
*/
|
|
95
|
-
var GltfWrapMode;
|
|
96
|
-
(function (GltfWrapMode) {
|
|
97
|
-
GltfWrapMode[GltfWrapMode["ClampToEdge"] = 33071] = "ClampToEdge";
|
|
98
|
-
GltfWrapMode[GltfWrapMode["MirroredRepeat"] = 33648] = "MirroredRepeat";
|
|
99
|
-
GltfWrapMode[GltfWrapMode["Repeat"] = 10497] = "Repeat";
|
|
100
|
-
})(GltfWrapMode = exports.GltfWrapMode || (exports.GltfWrapMode = {}));
|
|
101
|
-
/** Describes the intended target of a [[GltfBufferViewProps]]. */
|
|
102
|
-
var GltfBufferTarget;
|
|
103
|
-
(function (GltfBufferTarget) {
|
|
104
|
-
GltfBufferTarget[GltfBufferTarget["ArrayBuffer"] = 34962] = "ArrayBuffer";
|
|
105
|
-
GltfBufferTarget[GltfBufferTarget["ElementArrayBuffer"] = 24963] = "ElementArrayBuffer";
|
|
106
|
-
})(GltfBufferTarget || (GltfBufferTarget = {}));
|
|
107
|
-
function* dictionaryIterator(dict) {
|
|
108
|
-
if (Array.isArray(dict)) {
|
|
109
|
-
for (const elem of dict)
|
|
110
|
-
yield elem;
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
for (const key of Object.keys(dict)) {
|
|
114
|
-
const value = dict[key];
|
|
115
|
-
if (undefined !== value)
|
|
116
|
-
yield value;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
function getNodeMeshIds(node) {
|
|
121
|
-
if (undefined !== node.meshes)
|
|
122
|
-
return typeof node.meshes === "string" ? [node.meshes] : node.meshes;
|
|
123
|
-
else if (undefined !== node.mesh)
|
|
124
|
-
return [node.mesh];
|
|
125
|
-
return [];
|
|
126
|
-
}
|
|
127
|
-
/** GL states that can be enabled by a [[GltfTechnique]]. Only those queried by this implementation are enumerated. */
|
|
128
|
-
var GltfTechniqueState;
|
|
129
|
-
(function (GltfTechniqueState) {
|
|
130
|
-
/** Enables alpha blending. */
|
|
131
|
-
GltfTechniqueState[GltfTechniqueState["Blend"] = 3042] = "Blend";
|
|
132
|
-
})(GltfTechniqueState || (GltfTechniqueState = {}));
|
|
133
|
-
function isGltf1Material(material) {
|
|
134
|
-
const mat1 = material;
|
|
135
|
-
return undefined !== mat1.technique || undefined !== mat1.values;
|
|
136
|
-
}
|
|
41
|
+
const GltfSchema_1 = require("../gltf/GltfSchema");
|
|
137
42
|
/**
|
|
138
43
|
* A chunk of binary data exposed as a typed array.
|
|
139
44
|
* The count member indicates how many elements exist. This may be less than this.buffer.length due to padding added to the
|
|
@@ -154,15 +59,15 @@ class GltfBufferData {
|
|
|
154
59
|
if (expectedType !== actualType) {
|
|
155
60
|
// Some data is stored in smaller data types to save space if no values exceed the maximum of the smaller type.
|
|
156
61
|
switch (expectedType) {
|
|
157
|
-
case GltfDataType.Float:
|
|
158
|
-
case GltfDataType.UnsignedByte:
|
|
62
|
+
case GltfSchema_1.GltfDataType.Float:
|
|
63
|
+
case GltfSchema_1.GltfDataType.UnsignedByte:
|
|
159
64
|
return undefined;
|
|
160
|
-
case GltfDataType.UnsignedShort:
|
|
161
|
-
if (GltfDataType.UnsignedByte !== actualType)
|
|
65
|
+
case GltfSchema_1.GltfDataType.UnsignedShort:
|
|
66
|
+
if (GltfSchema_1.GltfDataType.UnsignedByte !== actualType)
|
|
162
67
|
return undefined;
|
|
163
68
|
break;
|
|
164
|
-
case GltfDataType.UInt32:
|
|
165
|
-
if (GltfDataType.UnsignedByte !== actualType && GltfDataType.UnsignedShort !== actualType)
|
|
69
|
+
case GltfSchema_1.GltfDataType.UInt32:
|
|
70
|
+
if (GltfSchema_1.GltfDataType.UnsignedByte !== actualType && GltfSchema_1.GltfDataType.UnsignedShort !== actualType)
|
|
166
71
|
return undefined;
|
|
167
72
|
break;
|
|
168
73
|
}
|
|
@@ -174,13 +79,13 @@ class GltfBufferData {
|
|
|
174
79
|
// NB: Endianness of typed array data is determined by the 'platform byte order'. Actual data is always little-endian.
|
|
175
80
|
// We are assuming little-endian platform. If we find a big-endian platform, we'll need to use a DataView instead.
|
|
176
81
|
switch (actualType) {
|
|
177
|
-
case GltfDataType.UnsignedByte:
|
|
82
|
+
case GltfSchema_1.GltfDataType.UnsignedByte:
|
|
178
83
|
return bytes;
|
|
179
|
-
case GltfDataType.UnsignedShort:
|
|
84
|
+
case GltfSchema_1.GltfDataType.UnsignedShort:
|
|
180
85
|
return new Uint16Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 2);
|
|
181
|
-
case GltfDataType.UInt32:
|
|
86
|
+
case GltfSchema_1.GltfDataType.UInt32:
|
|
182
87
|
return new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4);
|
|
183
|
-
case GltfDataType.Float:
|
|
88
|
+
case GltfSchema_1.GltfDataType.Float:
|
|
184
89
|
return new Float32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4);
|
|
185
90
|
default:
|
|
186
91
|
return undefined;
|
|
@@ -319,7 +224,7 @@ function colorFromJson(values) {
|
|
|
319
224
|
}
|
|
320
225
|
function colorFromMaterial(material, isTransparent) {
|
|
321
226
|
let color = core_common_1.ColorDef.white;
|
|
322
|
-
if (isGltf1Material(material)) {
|
|
227
|
+
if ((0, GltfSchema_1.isGltf1Material)(material)) {
|
|
323
228
|
if (material.values?.color && Array.isArray(material.values.color))
|
|
324
229
|
color = colorFromJson(material.values.color);
|
|
325
230
|
}
|
|
@@ -374,20 +279,6 @@ class TransformStack {
|
|
|
374
279
|
this._stack.pop();
|
|
375
280
|
}
|
|
376
281
|
}
|
|
377
|
-
function* traverseNodes(ids, nodes, traversed) {
|
|
378
|
-
for (const id of ids) {
|
|
379
|
-
if (traversed.has(id))
|
|
380
|
-
throw new Error("Cycle detected while traversing glTF nodes");
|
|
381
|
-
const node = nodes[id];
|
|
382
|
-
if (!node)
|
|
383
|
-
continue;
|
|
384
|
-
traversed.add(id);
|
|
385
|
-
yield node;
|
|
386
|
-
if (node.children)
|
|
387
|
-
for (const child of traverseNodes(node.children, nodes, traversed))
|
|
388
|
-
yield child;
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
282
|
function compareTextureKeys(lhs, rhs) {
|
|
392
283
|
const cmp = (0, core_bentley_1.compareBooleans)(lhs.isTransparent, rhs.isTransparent);
|
|
393
284
|
if (0 !== cmp)
|
|
@@ -412,7 +303,7 @@ class GltfReader {
|
|
|
412
303
|
* (We also don't want to produce mip-maps for them, which is determined indirectly from the wrap mode).
|
|
413
304
|
* Allow the default to be optionally overridden.
|
|
414
305
|
*/
|
|
415
|
-
this.defaultWrapMode = GltfWrapMode.Repeat;
|
|
306
|
+
this.defaultWrapMode = GltfSchema_1.GltfWrapMode.Repeat;
|
|
416
307
|
this._glTF = args.props.glTF;
|
|
417
308
|
this._version = args.props.version;
|
|
418
309
|
this._yAxisUp = args.props.yAxisUp;
|
|
@@ -461,7 +352,7 @@ class GltfReader {
|
|
|
461
352
|
* @throws Error if a node appears more than once during traversal
|
|
462
353
|
*/
|
|
463
354
|
traverseNodes(nodeIds) {
|
|
464
|
-
return
|
|
355
|
+
return (0, GltfSchema_1.traverseGltfNodes)(nodeIds, this._nodes, new Set());
|
|
465
356
|
}
|
|
466
357
|
/** Traverse the nodes specified by their scene, recursing into their child nodes.
|
|
467
358
|
* @throws Error if a node appears more than once during traversal
|
|
@@ -583,7 +474,7 @@ class GltfReader {
|
|
|
583
474
|
let thisBias;
|
|
584
475
|
if (undefined !== pseudoRtcBias)
|
|
585
476
|
thisBias = (undefined === thisTransform) ? pseudoRtcBias : thisTransform.matrix.multiplyInverse(pseudoRtcBias);
|
|
586
|
-
for (const meshKey of
|
|
477
|
+
for (const meshKey of (0, GltfSchema_1.getGltfNodeMeshIds)(node)) {
|
|
587
478
|
const nodeMesh = this._meshes[meshKey];
|
|
588
479
|
if (nodeMesh?.primitives) {
|
|
589
480
|
const meshes = this.readMeshPrimitives(node, featureTable, thisTransform, thisBias);
|
|
@@ -689,14 +580,14 @@ class GltfReader {
|
|
|
689
580
|
const type = accessor.componentType;
|
|
690
581
|
let dataSize = 0;
|
|
691
582
|
switch (type) {
|
|
692
|
-
case GltfDataType.UnsignedByte:
|
|
583
|
+
case GltfSchema_1.GltfDataType.UnsignedByte:
|
|
693
584
|
dataSize = 1;
|
|
694
585
|
break;
|
|
695
|
-
case GltfDataType.UnsignedShort:
|
|
586
|
+
case GltfSchema_1.GltfDataType.UnsignedShort:
|
|
696
587
|
dataSize = 2;
|
|
697
588
|
break;
|
|
698
|
-
case GltfDataType.UInt32:
|
|
699
|
-
case GltfDataType.Float:
|
|
589
|
+
case GltfSchema_1.GltfDataType.UInt32:
|
|
590
|
+
case GltfSchema_1.GltfDataType.Float:
|
|
700
591
|
dataSize = 4;
|
|
701
592
|
break;
|
|
702
593
|
default:
|
|
@@ -723,10 +614,10 @@ class GltfReader {
|
|
|
723
614
|
return undefined;
|
|
724
615
|
}
|
|
725
616
|
}
|
|
726
|
-
readBufferData32(json, accessorName) { return this.readBufferData(json, accessorName, GltfDataType.UInt32); }
|
|
727
|
-
readBufferData16(json, accessorName) { return this.readBufferData(json, accessorName, GltfDataType.UnsignedShort); }
|
|
728
|
-
readBufferData8(json, accessorName) { return this.readBufferData(json, accessorName, GltfDataType.UnsignedByte); }
|
|
729
|
-
readBufferDataFloat(json, accessorName) { return this.readBufferData(json, accessorName, GltfDataType.Float); }
|
|
617
|
+
readBufferData32(json, accessorName) { return this.readBufferData(json, accessorName, GltfSchema_1.GltfDataType.UInt32); }
|
|
618
|
+
readBufferData16(json, accessorName) { return this.readBufferData(json, accessorName, GltfSchema_1.GltfDataType.UnsignedShort); }
|
|
619
|
+
readBufferData8(json, accessorName) { return this.readBufferData(json, accessorName, GltfSchema_1.GltfDataType.UnsignedByte); }
|
|
620
|
+
readBufferDataFloat(json, accessorName) { return this.readBufferData(json, accessorName, GltfSchema_1.GltfDataType.Float); }
|
|
730
621
|
readBufferData(json, accessorName, type) {
|
|
731
622
|
const view = this.getBufferView(json, accessorName);
|
|
732
623
|
return undefined !== view ? view.toBufferData(type) : undefined;
|
|
@@ -746,7 +637,7 @@ class GltfReader {
|
|
|
746
637
|
if (typeof material !== "object")
|
|
747
638
|
return undefined;
|
|
748
639
|
// Bimium's shader value...almost certainly obsolete at this point.
|
|
749
|
-
if (isGltf1Material(material))
|
|
640
|
+
if ((0, GltfSchema_1.isGltf1Material)(material))
|
|
750
641
|
return material.diffuse ?? this.extractId(material.values?.tex);
|
|
751
642
|
// KHR_techniques_webgl extension
|
|
752
643
|
const techniques = this._glTF.extensions?.KHR_techniques_webgl?.techniques;
|
|
@@ -756,7 +647,7 @@ class GltfReader {
|
|
|
756
647
|
if (typeof uniforms === "object") {
|
|
757
648
|
for (const uniformName of Object.keys(uniforms)) {
|
|
758
649
|
const uniform = uniforms[uniformName];
|
|
759
|
-
if (typeof uniform === "object" && uniform.type === GltfDataType.Sampler2d)
|
|
650
|
+
if (typeof uniform === "object" && uniform.type === GltfSchema_1.GltfDataType.Sampler2d)
|
|
760
651
|
return this.extractId(ext.values[uniformName]?.index);
|
|
761
652
|
}
|
|
762
653
|
}
|
|
@@ -767,15 +658,15 @@ class GltfReader {
|
|
|
767
658
|
extractNormalMapId(material) {
|
|
768
659
|
if (typeof material !== "object")
|
|
769
660
|
return undefined;
|
|
770
|
-
if (isGltf1Material(material))
|
|
661
|
+
if ((0, GltfSchema_1.isGltf1Material)(material))
|
|
771
662
|
return undefined;
|
|
772
663
|
return this.extractId(material.normalTexture?.index);
|
|
773
664
|
}
|
|
774
665
|
isMaterialTransparent(material) {
|
|
775
|
-
if (isGltf1Material(material)) {
|
|
666
|
+
if ((0, GltfSchema_1.isGltf1Material)(material)) {
|
|
776
667
|
if (this._glTF.techniques && undefined !== material.technique) {
|
|
777
668
|
const technique = this._glTF.techniques[material.technique];
|
|
778
|
-
if (technique?.states?.enable?.some((state) => state === GltfTechniqueState.Blend))
|
|
669
|
+
if (technique?.states?.enable?.some((state) => state === GltfSchema_1.GltfTechniqueState.Blend))
|
|
779
670
|
return true;
|
|
780
671
|
}
|
|
781
672
|
return false;
|
|
@@ -801,7 +692,7 @@ class GltfReader {
|
|
|
801
692
|
}
|
|
802
693
|
readMeshPrimitives(node, featureTable, thisTransform, thisBias) {
|
|
803
694
|
const meshes = [];
|
|
804
|
-
for (const meshKey of
|
|
695
|
+
for (const meshKey of (0, GltfSchema_1.getGltfNodeMeshIds)(node)) {
|
|
805
696
|
const nodeMesh = this._meshes[meshKey];
|
|
806
697
|
if (nodeMesh?.primitives) {
|
|
807
698
|
for (const primitive of nodeMesh.primitives) {
|
|
@@ -829,15 +720,15 @@ class GltfReader {
|
|
|
829
720
|
if (!displayParams)
|
|
830
721
|
return undefined;
|
|
831
722
|
let primitiveType = -1;
|
|
832
|
-
const meshMode = core_bentley_1.JsonUtils.asInt(primitive.mode, GltfMeshMode.Triangles);
|
|
723
|
+
const meshMode = core_bentley_1.JsonUtils.asInt(primitive.mode, GltfSchema_1.GltfMeshMode.Triangles);
|
|
833
724
|
switch (meshMode) {
|
|
834
|
-
case GltfMeshMode.Lines:
|
|
725
|
+
case GltfSchema_1.GltfMeshMode.Lines:
|
|
835
726
|
primitiveType = MeshPrimitives_1.Mesh.PrimitiveType.Polyline;
|
|
836
727
|
break;
|
|
837
|
-
case GltfMeshMode.Points:
|
|
728
|
+
case GltfSchema_1.GltfMeshMode.Points:
|
|
838
729
|
primitiveType = MeshPrimitives_1.Mesh.PrimitiveType.Point;
|
|
839
730
|
break;
|
|
840
|
-
case GltfMeshMode.Triangles:
|
|
731
|
+
case GltfSchema_1.GltfMeshMode.Triangles:
|
|
841
732
|
primitiveType = MeshPrimitives_1.Mesh.PrimitiveType.Mesh;
|
|
842
733
|
break;
|
|
843
734
|
default:
|
|
@@ -857,30 +748,43 @@ class GltfReader {
|
|
|
857
748
|
quantizePositions: true,
|
|
858
749
|
});
|
|
859
750
|
const mesh = new GltfMeshData(meshPrimitive);
|
|
860
|
-
//
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
751
|
+
// ###TODO_GLTF: There can be more than one color attribute; COLOR_0 might not be the one we want.
|
|
752
|
+
if (!this.readColors(mesh, primitive.attributes, "COLOR_0")) {
|
|
753
|
+
// We don't have real colormap - just load material color. This will be used if non-Bentley
|
|
754
|
+
// tile or fit the color table is uniform. For a non-Bentley, non-Uniform, we'll set the
|
|
755
|
+
// uv parameters to pick the colors out of the color map texture.
|
|
756
|
+
meshPrimitive.colorMap.insert(displayParams.fillColor.tbgr); // White...
|
|
757
|
+
// _COLORINDEX is an ancient holdover from glTF 1.0 and Bimium...unlikely to actually encounter it in the wild.
|
|
758
|
+
const colorIndices = this.readBufferData16(primitive.attributes, "_COLORINDEX");
|
|
759
|
+
if (undefined !== colorIndices && material) {
|
|
760
|
+
let texStep;
|
|
761
|
+
if ((0, GltfSchema_1.isGltf1Material)(material))
|
|
762
|
+
texStep = material.values?.texStep;
|
|
763
|
+
else
|
|
764
|
+
texStep = material.extensions?.KHR_techniques_webgl?.values?.u_texStep;
|
|
765
|
+
if (texStep) {
|
|
766
|
+
const uvParams = [];
|
|
767
|
+
for (let i = 0; i < colorIndices.count; i++)
|
|
768
|
+
uvParams.push(new core_geometry_1.Point2d(texStep[1] + texStep[0] * colorIndices.buffer[i], .5));
|
|
769
|
+
const paramList = core_common_1.QPoint2dList.fromPoints(uvParams);
|
|
770
|
+
mesh.uvs = paramList.toTypedArray();
|
|
771
|
+
mesh.uvQParams = paramList.params;
|
|
772
|
+
}
|
|
878
773
|
}
|
|
879
774
|
}
|
|
880
775
|
const draco = primitive.extensions?.KHR_draco_mesh_compression;
|
|
881
776
|
if (draco)
|
|
882
777
|
return this.readDracoMeshPrimitive(mesh.primitive, draco) ? mesh : undefined;
|
|
883
778
|
this.readBatchTable(mesh.primitive, primitive);
|
|
779
|
+
if (mesh.primitive.features) {
|
|
780
|
+
const features = this.readPrimitiveFeatures(primitive);
|
|
781
|
+
if (features) {
|
|
782
|
+
if (features instanceof core_common_1.Feature)
|
|
783
|
+
mesh.primitive.features.add(features, 1);
|
|
784
|
+
else
|
|
785
|
+
mesh.primitive.features.setIndices(features);
|
|
786
|
+
}
|
|
787
|
+
}
|
|
884
788
|
if (!this.readVertices(mesh, primitive, pseudoRtcBias))
|
|
885
789
|
return undefined;
|
|
886
790
|
switch (primitiveType) {
|
|
@@ -891,7 +795,7 @@ class GltfReader {
|
|
|
891
795
|
return undefined;
|
|
892
796
|
if (!mesh.uvs) {
|
|
893
797
|
let texCoordIndex = 0;
|
|
894
|
-
if (!isGltf1Material(material) && undefined !== material.pbrMetallicRoughness?.baseColorTexture?.texCoord)
|
|
798
|
+
if (!(0, GltfSchema_1.isGltf1Material)(material) && undefined !== material.pbrMetallicRoughness?.baseColorTexture?.texCoord)
|
|
895
799
|
texCoordIndex = core_bentley_1.JsonUtils.asInt(material.pbrMetallicRoughness.baseColorTexture.texCoord);
|
|
896
800
|
this.readUVParams(mesh, primitive.attributes, `TEXCOORD_${texCoordIndex}`);
|
|
897
801
|
}
|
|
@@ -1020,8 +924,8 @@ class GltfReader {
|
|
|
1020
924
|
const view = this.getBufferView(primitive.attributes, "POSITION");
|
|
1021
925
|
if (undefined === view)
|
|
1022
926
|
return false;
|
|
1023
|
-
if (GltfDataType.Float === view.type) {
|
|
1024
|
-
const buffer = view.toBufferData(GltfDataType.Float);
|
|
927
|
+
if (GltfSchema_1.GltfDataType.Float === view.type) {
|
|
928
|
+
const buffer = view.toBufferData(GltfSchema_1.GltfDataType.Float);
|
|
1025
929
|
if (undefined === buffer)
|
|
1026
930
|
return false;
|
|
1027
931
|
const strideSkip = view.stride - 3;
|
|
@@ -1040,17 +944,15 @@ class GltfReader {
|
|
|
1040
944
|
mesh.points = positions.toTypedArray();
|
|
1041
945
|
}
|
|
1042
946
|
else {
|
|
1043
|
-
if (GltfDataType.UnsignedShort !== view.type)
|
|
947
|
+
if (GltfSchema_1.GltfDataType.UnsignedShort !== view.type)
|
|
1044
948
|
return false;
|
|
1045
|
-
const
|
|
1046
|
-
const
|
|
1047
|
-
|
|
949
|
+
const quantized = view.accessor.extensions?.WEB3D_quantized_attributes;
|
|
950
|
+
const rangeMin = quantized?.decodedMin;
|
|
951
|
+
const rangeMax = quantized?.decodedMax;
|
|
952
|
+
if (!rangeMin || !rangeMax) // required by spec...
|
|
1048
953
|
return false;
|
|
1049
|
-
|
|
1050
|
-
const
|
|
1051
|
-
if (undefined === rangeMin || undefined === rangeMax)
|
|
1052
|
-
return false;
|
|
1053
|
-
const buffer = view.toBufferData(GltfDataType.UnsignedShort);
|
|
954
|
+
// ###TODO apply WEB3D_quantized_attributes.decodeMatrix? Have not encountered in the wild; glTF 1.0 only.
|
|
955
|
+
const buffer = view.toBufferData(GltfSchema_1.GltfDataType.UnsignedShort);
|
|
1054
956
|
if (undefined === buffer || !(buffer.buffer instanceof Uint16Array))
|
|
1055
957
|
return false;
|
|
1056
958
|
(0, core_bentley_1.assert)(buffer.buffer instanceof Uint16Array);
|
|
@@ -1086,6 +988,9 @@ class GltfReader {
|
|
|
1086
988
|
}
|
|
1087
989
|
readBatchTable(_mesh, _json) {
|
|
1088
990
|
}
|
|
991
|
+
readPrimitiveFeatures(_primitive) {
|
|
992
|
+
return undefined;
|
|
993
|
+
}
|
|
1089
994
|
readMeshIndices(mesh, json) {
|
|
1090
995
|
if (undefined !== json.indices) {
|
|
1091
996
|
const data = this.readBufferData16(json, "indices") || this.readBufferData32(json, "indices");
|
|
@@ -1109,8 +1014,8 @@ class GltfReader {
|
|
|
1109
1014
|
if (undefined === view)
|
|
1110
1015
|
return false;
|
|
1111
1016
|
switch (view.type) {
|
|
1112
|
-
case GltfDataType.Float: {
|
|
1113
|
-
const data = view.toBufferData(GltfDataType.Float);
|
|
1017
|
+
case GltfSchema_1.GltfDataType.Float: {
|
|
1018
|
+
const data = view.toBufferData(GltfSchema_1.GltfDataType.Float);
|
|
1114
1019
|
if (undefined === data)
|
|
1115
1020
|
return false;
|
|
1116
1021
|
mesh.normals = new Uint16Array(data.count);
|
|
@@ -1122,8 +1027,8 @@ class GltfReader {
|
|
|
1122
1027
|
}
|
|
1123
1028
|
return true;
|
|
1124
1029
|
}
|
|
1125
|
-
case GltfDataType.UnsignedByte: {
|
|
1126
|
-
const data = view.toBufferData(GltfDataType.UnsignedByte);
|
|
1030
|
+
case GltfSchema_1.GltfDataType.UnsignedByte: {
|
|
1031
|
+
const data = view.toBufferData(GltfSchema_1.GltfDataType.UnsignedByte);
|
|
1127
1032
|
if (undefined === data)
|
|
1128
1033
|
return false;
|
|
1129
1034
|
// ###TODO: we shouldn't have to allocate OctEncodedNormal objects...just use uint16s / numbers...
|
|
@@ -1140,12 +1045,33 @@ class GltfReader {
|
|
|
1140
1045
|
return false;
|
|
1141
1046
|
}
|
|
1142
1047
|
}
|
|
1048
|
+
readColors(mesh, attribute, accessorName) {
|
|
1049
|
+
const view = this.getBufferView(attribute, accessorName);
|
|
1050
|
+
if (!view || (GltfSchema_1.GltfDataType.Float !== view.type && GltfSchema_1.GltfDataType.UnsignedByte !== view.type && GltfSchema_1.GltfDataType.SignedByte !== view.type))
|
|
1051
|
+
return false;
|
|
1052
|
+
const data = view.toBufferData(view.type);
|
|
1053
|
+
if (!data)
|
|
1054
|
+
return false;
|
|
1055
|
+
const hasAlpha = "VEC4" === view.accessor.type;
|
|
1056
|
+
const factor = view.type === GltfSchema_1.GltfDataType.Float ? 255 : 1;
|
|
1057
|
+
const rgbt = new Uint8Array(4);
|
|
1058
|
+
const color = new Uint32Array(rgbt.buffer);
|
|
1059
|
+
for (let i = 0; i < data.count; i++) {
|
|
1060
|
+
const index = view.stride * i;
|
|
1061
|
+
rgbt[0] = data.buffer[index] * factor;
|
|
1062
|
+
rgbt[1] = data.buffer[index + 1] * factor;
|
|
1063
|
+
rgbt[2] = data.buffer[index + 2] * factor;
|
|
1064
|
+
rgbt[3] = hasAlpha ? (255 - data.buffer[index + 3] * factor) : 0;
|
|
1065
|
+
mesh.primitive.colors.push(mesh.primitive.colorMap.insert(color[0]));
|
|
1066
|
+
}
|
|
1067
|
+
return true;
|
|
1068
|
+
}
|
|
1143
1069
|
readUVParams(mesh, json, accessorName) {
|
|
1144
1070
|
const view = this.getBufferView(json, accessorName);
|
|
1145
1071
|
if (view === undefined)
|
|
1146
1072
|
return false;
|
|
1147
1073
|
switch (view.type) {
|
|
1148
|
-
case GltfDataType.Float: {
|
|
1074
|
+
case GltfSchema_1.GltfDataType.Float: {
|
|
1149
1075
|
const data = this.readBufferDataFloat(json, accessorName);
|
|
1150
1076
|
if (!data)
|
|
1151
1077
|
return false;
|
|
@@ -1163,16 +1089,13 @@ class GltfReader {
|
|
|
1163
1089
|
}
|
|
1164
1090
|
return true;
|
|
1165
1091
|
}
|
|
1166
|
-
case GltfDataType.UnsignedShort: {
|
|
1167
|
-
const
|
|
1168
|
-
const
|
|
1169
|
-
|
|
1170
|
-
return false;
|
|
1171
|
-
const rangeMin = core_bentley_1.JsonUtils.asArray(quantized.decodedMin);
|
|
1172
|
-
const rangeMax = core_bentley_1.JsonUtils.asArray(quantized.decodedMax);
|
|
1092
|
+
case GltfSchema_1.GltfDataType.UnsignedShort: {
|
|
1093
|
+
const quantized = view.accessor.extensions?.WEB3D_quantized_attributes;
|
|
1094
|
+
const rangeMin = quantized?.decodedMin;
|
|
1095
|
+
const rangeMax = quantized?.decodedMax;
|
|
1173
1096
|
if (undefined === rangeMin || undefined === rangeMax)
|
|
1174
1097
|
return false;
|
|
1175
|
-
const qData = view.toBufferData(GltfDataType.UnsignedShort);
|
|
1098
|
+
const qData = view.toBufferData(GltfSchema_1.GltfDataType.UnsignedShort);
|
|
1176
1099
|
if (undefined === qData || !(qData.buffer instanceof Uint16Array))
|
|
1177
1100
|
return false;
|
|
1178
1101
|
mesh.uvRange = core_geometry_1.Range2d.createXYXY(rangeMin[0], rangeMin[1], rangeMax[0], rangeMax[1]);
|
|
@@ -1229,7 +1152,7 @@ class GltfReader {
|
|
|
1229
1152
|
// If any meshes are draco-compressed, dynamically load the decoder module and then decode the meshes.
|
|
1230
1153
|
const dracoMeshes = [];
|
|
1231
1154
|
for (const node of this.traverseScene()) {
|
|
1232
|
-
for (const meshId of
|
|
1155
|
+
for (const meshId of (0, GltfSchema_1.getGltfNodeMeshIds)(node)) {
|
|
1233
1156
|
const mesh = this._meshes[meshId];
|
|
1234
1157
|
if (mesh?.primitives)
|
|
1235
1158
|
for (const primitive of mesh.primitives)
|
|
@@ -1253,14 +1176,14 @@ class GltfReader {
|
|
|
1253
1176
|
// be required for the scene.
|
|
1254
1177
|
const promises = [];
|
|
1255
1178
|
try {
|
|
1256
|
-
for (const buffer of
|
|
1179
|
+
for (const buffer of (0, GltfSchema_1.gltfDictionaryIterator)(this._buffers))
|
|
1257
1180
|
if (!buffer.resolvedBuffer)
|
|
1258
1181
|
promises.push(this.resolveBuffer(buffer));
|
|
1259
1182
|
await Promise.all(promises);
|
|
1260
1183
|
if (this._isCanceled)
|
|
1261
1184
|
return;
|
|
1262
1185
|
promises.length = 0;
|
|
1263
|
-
for (const image of
|
|
1186
|
+
for (const image of (0, GltfSchema_1.gltfDictionaryIterator)(this._images))
|
|
1264
1187
|
if (!image.resolvedImage)
|
|
1265
1188
|
promises.push(this.resolveImage(image));
|
|
1266
1189
|
await Promise.all(promises);
|
|
@@ -1283,7 +1206,9 @@ class GltfReader {
|
|
|
1283
1206
|
}
|
|
1284
1207
|
resolveUrl(uri) {
|
|
1285
1208
|
try {
|
|
1286
|
-
|
|
1209
|
+
const resolved = new URL(uri, this._baseUrl);
|
|
1210
|
+
resolved.search = this._baseUrl?.search ?? "";
|
|
1211
|
+
return resolved.toString();
|
|
1287
1212
|
}
|
|
1288
1213
|
catch (_) {
|
|
1289
1214
|
return undefined;
|
|
@@ -1344,7 +1269,7 @@ class GltfReader {
|
|
|
1344
1269
|
let wrapT = sampler?.wrapT;
|
|
1345
1270
|
if (undefined === wrapS && undefined === wrapT)
|
|
1346
1271
|
wrapS = wrapT = this.defaultWrapMode;
|
|
1347
|
-
if (GltfWrapMode.ClampToEdge === wrapS || GltfWrapMode.ClampToEdge === wrapT)
|
|
1272
|
+
if (GltfSchema_1.GltfWrapMode.ClampToEdge === wrapS || GltfSchema_1.GltfWrapMode.ClampToEdge === wrapT)
|
|
1348
1273
|
return core_common_1.RenderTexture.Type.TileSection;
|
|
1349
1274
|
return core_common_1.RenderTexture.Type.Normal;
|
|
1350
1275
|
}
|
|
@@ -1413,7 +1338,8 @@ exports.GltfReader = GltfReader;
|
|
|
1413
1338
|
* @public
|
|
1414
1339
|
*/
|
|
1415
1340
|
async function readGltfGraphics(args) {
|
|
1416
|
-
const
|
|
1341
|
+
const baseUrl = typeof args.baseUrl === "string" ? new URL(args.baseUrl) : args.baseUrl;
|
|
1342
|
+
const props = GltfReaderProps.create(args.gltf, true, baseUrl); // glTF supports exactly one coordinate system with y axis up.
|
|
1417
1343
|
const reader = props ? new GltfGraphicsReader(props, args) : undefined;
|
|
1418
1344
|
if (!reader)
|
|
1419
1345
|
return undefined;
|