@inweb/viewer-three 26.10.6 → 26.11.0
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/README.md +7 -4
- package/dist/{plugins → extensions}/components/AxesHelperComponent.js +23 -1
- package/dist/extensions/components/AxesHelperComponent.js.map +1 -0
- package/dist/extensions/components/AxesHelperComponent.min.js +24 -0
- package/dist/{plugins → extensions}/components/AxesHelperComponent.module.js +24 -2
- package/dist/extensions/components/AxesHelperComponent.module.js.map +1 -0
- package/dist/{plugins → extensions}/components/ExtentsHelperComponent.js +18 -0
- package/dist/extensions/components/ExtentsHelperComponent.js.map +1 -0
- package/dist/{plugins/components/AxesHelperComponent.min.js → extensions/components/ExtentsHelperComponent.min.js} +1 -1
- package/dist/{plugins → extensions}/components/ExtentsHelperComponent.module.js +19 -1
- package/dist/extensions/components/ExtentsHelperComponent.module.js.map +1 -0
- package/dist/extensions/components/GridHelperComponent.js.map +1 -0
- package/dist/extensions/components/GridHelperComponent.module.js.map +1 -0
- package/dist/extensions/components/LightHelperComponent.js.map +1 -0
- package/dist/extensions/components/LightHelperComponent.module.js.map +1 -0
- package/dist/extensions/components/RoomEnvironmentComponent.js.map +1 -0
- package/dist/extensions/components/RoomEnvironmentComponent.module.js.map +1 -0
- package/dist/extensions/components/StatsPanelComponent.js.map +1 -0
- package/dist/extensions/components/StatsPanelComponent.module.js.map +1 -0
- package/dist/{plugins → extensions}/loaders/GLTFCloudLoader.js +2 -3
- package/dist/extensions/loaders/GLTFCloudLoader.js.map +1 -0
- package/dist/{plugins → extensions}/loaders/GLTFCloudLoader.min.js +1 -1
- package/dist/{plugins → extensions}/loaders/GLTFCloudLoader.module.js +2 -3
- package/dist/extensions/loaders/GLTFCloudLoader.module.js.map +1 -0
- package/dist/extensions/loaders/GLTFFileLoader.js +2499 -0
- package/dist/extensions/loaders/GLTFFileLoader.js.map +1 -0
- package/dist/extensions/loaders/GLTFFileLoader.min.js +24 -0
- package/dist/extensions/loaders/GLTFFileLoader.module.js +74 -0
- package/dist/extensions/loaders/GLTFFileLoader.module.js.map +1 -0
- package/dist/{plugins → extensions}/loaders/IFCXLoader.js +5 -7
- package/dist/extensions/loaders/IFCXLoader.js.map +1 -0
- package/dist/{plugins → extensions}/loaders/IFCXLoader.min.js +1 -1
- package/dist/{plugins → extensions}/loaders/IFCXLoader.module.js +5 -7
- package/dist/extensions/loaders/IFCXLoader.module.js.map +1 -0
- package/dist/{plugins → extensions}/loaders/PotreeLoader.js +1 -2
- package/dist/extensions/loaders/PotreeLoader.js.map +1 -0
- package/dist/{plugins → extensions}/loaders/PotreeLoader.min.js +1 -1
- package/dist/{plugins → extensions}/loaders/PotreeLoader.module.js +1 -2
- package/dist/extensions/loaders/PotreeLoader.module.js.map +1 -0
- package/dist/viewer-three.js +1015 -2926
- package/dist/viewer-three.js.map +1 -1
- package/dist/viewer-three.min.js +3 -3
- package/dist/viewer-three.module.js +847 -356
- package/dist/viewer-three.module.js.map +1 -1
- package/{plugins → extensions}/components/AxesHelperComponent.ts +31 -2
- package/{plugins → extensions}/components/ExtentsHelperComponent.ts +25 -0
- package/{plugins → extensions}/loaders/GLTFCloudLoader.ts +2 -3
- package/{src/Viewer → extensions}/loaders/GLTFFileLoader.ts +21 -12
- package/{plugins → extensions}/loaders/IFCX/IFCXCloudLoader.ts +5 -5
- package/{plugins → extensions}/loaders/IFCX/IFCXFileLoader.ts +3 -4
- package/{plugins → extensions}/loaders/Potree/PotreeFileLoader.ts +3 -4
- package/lib/Viewer/Viewer.d.ts +27 -20
- package/lib/Viewer/commands/GetSelected2.d.ts +2 -0
- package/lib/Viewer/commands/SelectModel.d.ts +1 -1
- package/lib/Viewer/commands/SetSelected2.d.ts +2 -0
- package/lib/Viewer/components/SelectionComponent.d.ts +1 -3
- package/lib/Viewer/components/index.d.ts +6 -6
- package/lib/Viewer/draggers/MeasureLineDragger.d.ts +7 -1
- package/lib/Viewer/loaders/DynamicGltfLoader/DynamicModelImpl.d.ts +0 -1
- package/lib/Viewer/loaders/GLTFBinaryExtension.d.ts +5 -0
- package/lib/Viewer/loaders/GLTFCloudDynamicLoader.d.ts +2 -2
- package/lib/Viewer/loaders/{GLTFFileLoader.d.ts → GLTFFileDynamicLoader.d.ts} +7 -1
- package/lib/Viewer/loaders/GLTFLoadingManager.d.ts +4 -3
- package/lib/Viewer/loaders/RangesLoader.d.ts +15 -0
- package/lib/Viewer/loaders/index.d.ts +22 -14
- package/lib/Viewer/measurement/Snapper.d.ts +15 -0
- package/lib/Viewer/measurement/UnitConverter.d.ts +63 -0
- package/lib/Viewer/measurement/UnitFormatter.d.ts +4 -0
- package/lib/Viewer/models/IModelImpl.d.ts +10 -8
- package/lib/Viewer/models/ModelImpl.d.ts +7 -5
- package/package.json +11 -11
- package/src/Viewer/Viewer.ts +120 -88
- package/src/Viewer/commands/ClearSelected.ts +3 -1
- package/src/Viewer/commands/GetModels.ts +1 -1
- package/src/Viewer/commands/GetSelected.ts +2 -2
- package/src/Viewer/commands/GetSelected2.ts +34 -0
- package/src/Viewer/commands/HideSelected.ts +3 -1
- package/src/Viewer/commands/SelectModel.ts +5 -5
- package/src/Viewer/commands/SetSelected.ts +9 -10
- package/src/Viewer/commands/SetSelected2.ts +42 -0
- package/src/Viewer/commands/ZoomToObjects.ts +5 -6
- package/src/Viewer/commands/ZoomToSelected.ts +3 -1
- package/src/Viewer/commands/index.ts +4 -0
- package/src/Viewer/components/CameraComponent.ts +6 -1
- package/src/Viewer/components/ExtentsComponent.ts +4 -1
- package/src/Viewer/components/SelectionComponent.ts +7 -30
- package/src/Viewer/components/index.ts +6 -6
- package/src/Viewer/draggers/MeasureLineDragger.ts +84 -226
- package/src/Viewer/loaders/DynamicGltfLoader/DynamicGltfLoader.js +263 -34
- package/src/Viewer/loaders/DynamicGltfLoader/DynamicModelImpl.ts +20 -10
- package/src/Viewer/loaders/DynamicGltfLoader/GltfStructure.js +4 -1
- package/src/Viewer/loaders/GLTFBinaryExtension.ts +91 -0
- package/src/Viewer/loaders/GLTFCloudDynamicLoader.ts +13 -19
- package/src/Viewer/loaders/GLTFFileDynamicLoader.ts +145 -0
- package/src/Viewer/loaders/GLTFLoadingManager.ts +5 -4
- package/src/Viewer/loaders/RangesLoader.ts +95 -0
- package/src/Viewer/loaders/index.ts +24 -16
- package/src/Viewer/measurement/Snapper.ts +208 -0
- package/src/Viewer/measurement/UnitConverter.ts +47 -0
- package/src/Viewer/measurement/UnitFormatter.ts +95 -0
- package/src/Viewer/models/IModelImpl.ts +15 -8
- package/src/Viewer/models/ModelImpl.ts +48 -17
- package/src/index-umd.ts +1 -1
- package/dist/plugins/components/AxesHelperComponent.js.map +0 -1
- package/dist/plugins/components/AxesHelperComponent.module.js.map +0 -1
- package/dist/plugins/components/ExtentsHelperComponent.js.map +0 -1
- package/dist/plugins/components/ExtentsHelperComponent.min.js +0 -24
- package/dist/plugins/components/ExtentsHelperComponent.module.js.map +0 -1
- package/dist/plugins/components/GridHelperComponent.js.map +0 -1
- package/dist/plugins/components/GridHelperComponent.module.js.map +0 -1
- package/dist/plugins/components/LightHelperComponent.js.map +0 -1
- package/dist/plugins/components/LightHelperComponent.module.js.map +0 -1
- package/dist/plugins/components/RoomEnvironmentComponent.js.map +0 -1
- package/dist/plugins/components/RoomEnvironmentComponent.module.js.map +0 -1
- package/dist/plugins/components/StatsPanelComponent.js.map +0 -1
- package/dist/plugins/components/StatsPanelComponent.module.js.map +0 -1
- package/dist/plugins/loaders/GLTFCloudLoader.js.map +0 -1
- package/dist/plugins/loaders/GLTFCloudLoader.module.js.map +0 -1
- package/dist/plugins/loaders/IFCXLoader.js.map +0 -1
- package/dist/plugins/loaders/IFCXLoader.module.js.map +0 -1
- package/dist/plugins/loaders/PotreeLoader.js.map +0 -1
- package/dist/plugins/loaders/PotreeLoader.module.js.map +0 -1
- /package/dist/{plugins → extensions}/components/GridHelperComponent.js +0 -0
- /package/dist/{plugins → extensions}/components/GridHelperComponent.min.js +0 -0
- /package/dist/{plugins → extensions}/components/GridHelperComponent.module.js +0 -0
- /package/dist/{plugins → extensions}/components/LightHelperComponent.js +0 -0
- /package/dist/{plugins → extensions}/components/LightHelperComponent.min.js +0 -0
- /package/dist/{plugins → extensions}/components/LightHelperComponent.module.js +0 -0
- /package/dist/{plugins → extensions}/components/RoomEnvironmentComponent.js +0 -0
- /package/dist/{plugins → extensions}/components/RoomEnvironmentComponent.min.js +0 -0
- /package/dist/{plugins → extensions}/components/RoomEnvironmentComponent.module.js +0 -0
- /package/dist/{plugins → extensions}/components/StatsPanelComponent.js +0 -0
- /package/dist/{plugins → extensions}/components/StatsPanelComponent.min.js +0 -0
- /package/dist/{plugins → extensions}/components/StatsPanelComponent.module.js +0 -0
- /package/{plugins → extensions}/components/GridHelperComponent.ts +0 -0
- /package/{plugins → extensions}/components/LightHelperComponent.ts +0 -0
- /package/{plugins → extensions}/components/RoomEnvironmentComponent.ts +0 -0
- /package/{plugins → extensions}/components/StatsPanelComponent.ts +0 -0
- /package/{plugins → extensions}/loaders/IFCX/IFCXLoader.ts +0 -0
- /package/{plugins → extensions}/loaders/IFCX/index.ts +0 -0
- /package/{plugins → extensions}/loaders/IFCX/render.js +0 -0
- /package/{plugins → extensions}/loaders/Potree/PotreeModelImpl.ts +0 -0
- /package/{plugins → extensions}/loaders/Potree/index.ts +0 -0
package/dist/viewer-three.js
CHANGED
|
@@ -171,6 +171,14 @@
|
|
|
171
171
|
cancel() {
|
|
172
172
|
this.abortController.abort();
|
|
173
173
|
}
|
|
174
|
+
extractFileName(file) {
|
|
175
|
+
const regex = /[^/\\?#:]+(?=\?|#|$)/;
|
|
176
|
+
if (typeof file === "string")
|
|
177
|
+
return (file.match(regex) || [])[0];
|
|
178
|
+
else if (file instanceof globalThis.File)
|
|
179
|
+
return (file.name.match(regex) || [])[0];
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
174
182
|
};
|
|
175
183
|
class Loaders {
|
|
176
184
|
constructor() {
|
|
@@ -236,6 +244,7 @@
|
|
|
236
244
|
enableGestures: true,
|
|
237
245
|
geometryType: "vsfx",
|
|
238
246
|
rulerUnit: "Default",
|
|
247
|
+
rulerPrecision: 2,
|
|
239
248
|
cameraMode: "perspective",
|
|
240
249
|
};
|
|
241
250
|
}
|
|
@@ -492,6 +501,13 @@
|
|
|
492
501
|
this._data.rulerUnit = value;
|
|
493
502
|
this.change();
|
|
494
503
|
}
|
|
504
|
+
get rulerPrecision() {
|
|
505
|
+
return this._data.rulerPrecision;
|
|
506
|
+
}
|
|
507
|
+
set rulerPrecision(value) {
|
|
508
|
+
this._data.rulerPrecision = value;
|
|
509
|
+
this.change();
|
|
510
|
+
}
|
|
495
511
|
get cameraMode() {
|
|
496
512
|
return this._data.cameraMode || "perspective";
|
|
497
513
|
}
|
|
@@ -9059,7 +9075,7 @@
|
|
|
9059
9075
|
}
|
|
9060
9076
|
}
|
|
9061
9077
|
const _offsetMatrix = new Matrix4();
|
|
9062
|
-
const _identityMatrix
|
|
9078
|
+
const _identityMatrix = new Matrix4();
|
|
9063
9079
|
class Skeleton {
|
|
9064
9080
|
constructor( bones = [], boneInverses = [] ) {
|
|
9065
9081
|
this.uuid = generateUUID();
|
|
@@ -9121,7 +9137,7 @@
|
|
|
9121
9137
|
const boneMatrices = this.boneMatrices;
|
|
9122
9138
|
const boneTexture = this.boneTexture;
|
|
9123
9139
|
for ( let i = 0, il = bones.length; i < il; i ++ ) {
|
|
9124
|
-
const matrix = bones[ i ] ? bones[ i ].matrixWorld : _identityMatrix
|
|
9140
|
+
const matrix = bones[ i ] ? bones[ i ].matrixWorld : _identityMatrix;
|
|
9125
9141
|
_offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
|
|
9126
9142
|
_offsetMatrix.toArray( boneMatrices, i * 16 );
|
|
9127
9143
|
}
|
|
@@ -18451,7 +18467,7 @@
|
|
|
18451
18467
|
}
|
|
18452
18468
|
}
|
|
18453
18469
|
const _position = new Vector3();
|
|
18454
|
-
const _quaternion
|
|
18470
|
+
const _quaternion = new Quaternion();
|
|
18455
18471
|
const _scale = new Vector3();
|
|
18456
18472
|
const _orientation = new Vector3();
|
|
18457
18473
|
class PositionalAudio extends Audio {
|
|
@@ -18511,8 +18527,8 @@
|
|
|
18511
18527
|
updateMatrixWorld( force ) {
|
|
18512
18528
|
super.updateMatrixWorld( force );
|
|
18513
18529
|
if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
|
|
18514
|
-
this.matrixWorld.decompose( _position, _quaternion
|
|
18515
|
-
_orientation.set( 0, 0, 1 ).applyQuaternion( _quaternion
|
|
18530
|
+
this.matrixWorld.decompose( _position, _quaternion, _scale );
|
|
18531
|
+
_orientation.set( 0, 0, 1 ).applyQuaternion( _quaternion );
|
|
18516
18532
|
const panner = this.panner;
|
|
18517
18533
|
if ( panner.positionX ) {
|
|
18518
18534
|
const endTime = this.context.currentTime + this.listener.timeDelta;
|
|
@@ -33876,116 +33892,91 @@ void main() {
|
|
|
33876
33892
|
}
|
|
33877
33893
|
}
|
|
33878
33894
|
|
|
33879
|
-
const
|
|
33880
|
-
|
|
33881
|
-
|
|
33882
|
-
|
|
33883
|
-
|
|
33884
|
-
|
|
33885
|
-
|
|
33886
|
-
|
|
33887
|
-
|
|
33888
|
-
|
|
33889
|
-
|
|
33890
|
-
|
|
33891
|
-
|
|
33892
|
-
|
|
33893
|
-
|
|
33894
|
-
|
|
33895
|
-
|
|
33896
|
-
|
|
33897
|
-
|
|
33898
|
-
|
|
33899
|
-
|
|
33900
|
-
|
|
33901
|
-
|
|
33902
|
-
|
|
33903
|
-
|
|
33904
|
-
|
|
33905
|
-
|
|
33906
|
-
|
|
33907
|
-
|
|
33908
|
-
|
|
33909
|
-
|
|
33910
|
-
|
|
33911
|
-
|
|
33912
|
-
|
|
33913
|
-
|
|
33914
|
-
|
|
33915
|
-
|
|
33916
|
-
|
|
33917
|
-
|
|
33918
|
-
|
|
33919
|
-
|
|
33920
|
-
|
|
33921
|
-
|
|
33922
|
-
|
|
33923
|
-
|
|
33924
|
-
|
|
33925
|
-
|
|
33926
|
-
|
|
33927
|
-
|
|
33928
|
-
|
|
33929
|
-
|
|
33930
|
-
|
|
33931
|
-
|
|
33932
|
-
|
|
33933
|
-
|
|
33934
|
-
|
|
33935
|
-
|
|
33936
|
-
|
|
33937
|
-
|
|
33938
|
-
|
|
33939
|
-
|
|
33940
|
-
|
|
33941
|
-
this.viewer.canvas.addEventListener("pointermove", this.onPointerMove);
|
|
33942
|
-
this.viewer.canvas.addEventListener("pointerup", this.onPointerUp);
|
|
33943
|
-
this.viewer.canvas.addEventListener("pointercancel", this.onPointerCancel);
|
|
33944
|
-
this.viewer.canvas.addEventListener("pointerleave", this.onPointerLeave);
|
|
33945
|
-
this.viewer.addEventListener("render", this.renderOverlay);
|
|
33946
|
-
this.viewer.addEventListener("hide", this.updateSnapper);
|
|
33947
|
-
this.viewer.addEventListener("isolate", this.updateSnapper);
|
|
33948
|
-
this.viewer.addEventListener("show", this.updateSnapper);
|
|
33949
|
-
this.viewer.addEventListener("showall", this.updateSnapper);
|
|
33950
|
-
this.viewer.addEventListener("changecameramode", this.updateSnapperCamera);
|
|
33895
|
+
const ModelUnits = {
|
|
33896
|
+
Meters: { name: "Meters", type: "m", scale: 1.0 },
|
|
33897
|
+
Centimeters: { name: "Centimeters", type: "cm", scale: 0.01 },
|
|
33898
|
+
Millimeters: { name: "Millimeters", type: "mm", scale: 0.001 },
|
|
33899
|
+
Feet: { name: "Feet", type: "ft", scale: 0.3048 },
|
|
33900
|
+
Inches: { name: "Inches", type: "in", scale: 0.0254 },
|
|
33901
|
+
Yards: { name: "Yards", type: "yd", scale: 0.9144 },
|
|
33902
|
+
Kilometers: { name: "Kilometers", type: "km", scale: 1000.0 },
|
|
33903
|
+
Miles: { name: "Miles", type: "mi", scale: 1609.344 },
|
|
33904
|
+
Micrometers: { name: "Micrometers", type: "µm", scale: 0.000001 },
|
|
33905
|
+
Mils: { name: "Mils", type: "mil", scale: 0.0000254 },
|
|
33906
|
+
MicroInches: { name: "Micro-inches", type: "µin", scale: 0.0000000254 },
|
|
33907
|
+
Default: { name: "File units", type: "unit", scale: 1.0 },
|
|
33908
|
+
};
|
|
33909
|
+
function convertUnits(fromUnits, toUnits, distance) {
|
|
33910
|
+
const fromFactor = 1 / (ModelUnits[fromUnits] || ModelUnits.Default).scale;
|
|
33911
|
+
const toFactor = (ModelUnits[toUnits] || ModelUnits.Default).scale || 1;
|
|
33912
|
+
return distance * fromFactor * toFactor;
|
|
33913
|
+
}
|
|
33914
|
+
|
|
33915
|
+
function getDisplayUnit(units) {
|
|
33916
|
+
return (ModelUnits[units] || ModelUnits.Default).type;
|
|
33917
|
+
}
|
|
33918
|
+
function calculatePrecision(value) {
|
|
33919
|
+
const distance = Math.abs(value);
|
|
33920
|
+
if (distance >= 1000)
|
|
33921
|
+
return 0;
|
|
33922
|
+
if (distance >= 10)
|
|
33923
|
+
return 1;
|
|
33924
|
+
if (distance >= 0.1)
|
|
33925
|
+
return 2;
|
|
33926
|
+
if (distance >= 0.001)
|
|
33927
|
+
return 3;
|
|
33928
|
+
return distance > 0 ? Math.floor(-Math.log10(distance)) + 1 : 2;
|
|
33929
|
+
}
|
|
33930
|
+
function formatNumber(distance, digits, precision) {
|
|
33931
|
+
let result = distance.toFixed(digits);
|
|
33932
|
+
if (precision === "Auto")
|
|
33933
|
+
result = result.replace(/\.0+$/, "").replace(/\.$/, "");
|
|
33934
|
+
if (+result !== distance)
|
|
33935
|
+
result = "~ " + result;
|
|
33936
|
+
return result;
|
|
33937
|
+
}
|
|
33938
|
+
function formatDistance(distance, units, precision = 2) {
|
|
33939
|
+
let digits;
|
|
33940
|
+
if (precision === "Auto")
|
|
33941
|
+
digits = calculatePrecision(distance);
|
|
33942
|
+
else if (Number.isFinite(precision))
|
|
33943
|
+
digits = precision;
|
|
33944
|
+
else
|
|
33945
|
+
digits = parseFloat(precision);
|
|
33946
|
+
if (!Number.isFinite(digits))
|
|
33947
|
+
digits = 2;
|
|
33948
|
+
else if (digits < 0)
|
|
33949
|
+
digits = 0;
|
|
33950
|
+
else if (digits > 10)
|
|
33951
|
+
digits = 10;
|
|
33952
|
+
if (ModelUnits[units]) {
|
|
33953
|
+
return formatNumber(distance, digits, precision) + " " + ModelUnits[units].type;
|
|
33954
|
+
}
|
|
33955
|
+
else if (units) {
|
|
33956
|
+
return formatNumber(distance, digits, precision) + " " + units;
|
|
33951
33957
|
}
|
|
33952
|
-
|
|
33953
|
-
|
|
33954
|
-
this.viewer.canvas.removeEventListener("pointermove", this.onPointerMove);
|
|
33955
|
-
this.viewer.canvas.removeEventListener("pointerup", this.onPointerUp);
|
|
33956
|
-
this.viewer.canvas.removeEventListener("pointercancel", this.onPointerCancel);
|
|
33957
|
-
this.viewer.canvas.removeEventListener("pointerleave", this.onPointerLeave);
|
|
33958
|
-
this.viewer.removeEventListener("render", this.renderOverlay);
|
|
33959
|
-
this.viewer.removeEventListener("hide", this.updateSnapper);
|
|
33960
|
-
this.viewer.removeEventListener("isolate", this.updateSnapper);
|
|
33961
|
-
this.viewer.removeEventListener("show", this.updateSnapper);
|
|
33962
|
-
this.viewer.removeEventListener("showall", this.updateSnapper);
|
|
33963
|
-
this.viewer.removeEventListener("changecameramode", this.updateSnapperCamera);
|
|
33964
|
-
this.snapper.dispose();
|
|
33965
|
-
this.overlay.detach();
|
|
33966
|
-
this.overlay.dispose();
|
|
33967
|
-
super.dispose();
|
|
33958
|
+
else {
|
|
33959
|
+
return formatNumber(distance, digits, precision);
|
|
33968
33960
|
}
|
|
33969
33961
|
}
|
|
33962
|
+
|
|
33963
|
+
const DESKTOP_SNAP_DISTANCE = 10;
|
|
33964
|
+
const MOBILE_SNAP_DISTANCE = 50;
|
|
33970
33965
|
const _vertex = new Vector3();
|
|
33971
33966
|
const _start$1 = new Vector3();
|
|
33972
33967
|
const _end$1 = new Vector3();
|
|
33973
33968
|
const _line = new Line3();
|
|
33974
33969
|
const _center = new Vector3();
|
|
33975
33970
|
const _projection = new Vector3();
|
|
33976
|
-
class
|
|
33977
|
-
constructor(camera, canvas) {
|
|
33971
|
+
class Snapper {
|
|
33972
|
+
constructor(camera, renderer, canvas) {
|
|
33978
33973
|
this.camera = camera;
|
|
33974
|
+
this.renderer = renderer;
|
|
33979
33975
|
this.canvas = canvas;
|
|
33980
|
-
this.objects = [];
|
|
33981
|
-
this.clippingPlanes = [];
|
|
33982
33976
|
this.raycaster = new Raycaster();
|
|
33983
33977
|
this.detectRadiusInPixels = this.isMobile() ? MOBILE_SNAP_DISTANCE : DESKTOP_SNAP_DISTANCE;
|
|
33984
33978
|
this.edgesCache = new WeakMap();
|
|
33985
33979
|
}
|
|
33986
|
-
dispose() {
|
|
33987
|
-
this.objects = [];
|
|
33988
|
-
}
|
|
33989
33980
|
isMobile() {
|
|
33990
33981
|
if (typeof navigator === "undefined")
|
|
33991
33982
|
return false;
|
|
@@ -33994,7 +33985,7 @@ void main() {
|
|
|
33994
33985
|
getMousePosition(event, target) {
|
|
33995
33986
|
return target.set(event.clientX, event.clientY);
|
|
33996
33987
|
}
|
|
33997
|
-
getPointerIntersects(mouse) {
|
|
33988
|
+
getPointerIntersects(mouse, objects) {
|
|
33998
33989
|
const rect = this.canvas.getBoundingClientRect();
|
|
33999
33990
|
const x = ((mouse.x - rect.left) / rect.width) * 2 - 1;
|
|
34000
33991
|
const y = (-(mouse.y - rect.top) / rect.height) * 2 + 1;
|
|
@@ -34008,8 +33999,8 @@ void main() {
|
|
|
34008
33999
|
Points: { threshold: 0.01 },
|
|
34009
34000
|
Sprite: {},
|
|
34010
34001
|
};
|
|
34011
|
-
let intersects = this.raycaster.intersectObjects(
|
|
34012
|
-
this.clippingPlanes.forEach((plane) => {
|
|
34002
|
+
let intersects = this.raycaster.intersectObjects(objects, false);
|
|
34003
|
+
(this.renderer.clippingPlanes || []).forEach((plane) => {
|
|
34013
34004
|
intersects = intersects.filter((intersect) => plane.distanceToPoint(intersect.point) >= 0);
|
|
34014
34005
|
});
|
|
34015
34006
|
return intersects;
|
|
@@ -34031,9 +34022,8 @@ void main() {
|
|
|
34031
34022
|
}
|
|
34032
34023
|
return 0.1;
|
|
34033
34024
|
}
|
|
34034
|
-
getSnapPoint(
|
|
34035
|
-
const
|
|
34036
|
-
const intersections = this.getPointerIntersects(mouse);
|
|
34025
|
+
getSnapPoint(mouse, objects) {
|
|
34026
|
+
const intersections = this.getPointerIntersects(mouse, objects);
|
|
34037
34027
|
if (intersections.length === 0)
|
|
34038
34028
|
return undefined;
|
|
34039
34029
|
const object = intersections[0].object;
|
|
@@ -34081,13 +34071,133 @@ void main() {
|
|
|
34081
34071
|
return object.localToWorld(snapPoint);
|
|
34082
34072
|
return intersectionPoint.clone();
|
|
34083
34073
|
}
|
|
34084
|
-
|
|
34074
|
+
}
|
|
34075
|
+
|
|
34076
|
+
const _downPoint = new Vector2();
|
|
34077
|
+
class MeasureLineDragger extends OrbitDragger {
|
|
34078
|
+
constructor(viewer) {
|
|
34079
|
+
super(viewer);
|
|
34080
|
+
this.scale = 1.0;
|
|
34081
|
+
this.units = "";
|
|
34082
|
+
this.precision = 2;
|
|
34083
|
+
this.onPointerDown = (event) => {
|
|
34084
|
+
if (event.button !== 0)
|
|
34085
|
+
return;
|
|
34086
|
+
const mouse = this.snapper.getMousePosition(event, _downPoint);
|
|
34087
|
+
this.line.startPoint = this.snapper.getSnapPoint(mouse, this.objects);
|
|
34088
|
+
this.line.render();
|
|
34089
|
+
this.viewer.canvas.setPointerCapture(event.pointerId);
|
|
34090
|
+
this.orbit.enabled = !this.line.startPoint;
|
|
34091
|
+
};
|
|
34092
|
+
this.onPointerMove = (event) => {
|
|
34093
|
+
if (this.orbit.enabled && this.orbit.state !== -1)
|
|
34094
|
+
return;
|
|
34095
|
+
const mouse = this.snapper.getMousePosition(event, _downPoint);
|
|
34096
|
+
const snapPoint = this.snapper.getSnapPoint(mouse, this.objects);
|
|
34097
|
+
if (snapPoint && this.line.endPoint && snapPoint.equals(this.line.endPoint))
|
|
34098
|
+
return;
|
|
34099
|
+
this.line.endPoint = snapPoint;
|
|
34100
|
+
this.line.render();
|
|
34101
|
+
if (this.line.startPoint)
|
|
34102
|
+
this.changed = true;
|
|
34103
|
+
};
|
|
34104
|
+
this.onPointerUp = (event) => {
|
|
34105
|
+
if (this.line.startPoint && this.line.endPoint && this.line.getDistance() > 0) {
|
|
34106
|
+
this.line = new MeasureLine(this.overlay, this.scale, this.units, this.precision);
|
|
34107
|
+
this.overlay.addLine(this.line);
|
|
34108
|
+
}
|
|
34109
|
+
else {
|
|
34110
|
+
this.line.startPoint = undefined;
|
|
34111
|
+
this.line.endPoint = undefined;
|
|
34112
|
+
this.line.render();
|
|
34113
|
+
}
|
|
34114
|
+
this.viewer.canvas.releasePointerCapture(event.pointerId);
|
|
34115
|
+
this.orbit.enabled = true;
|
|
34116
|
+
};
|
|
34117
|
+
this.onPointerCancel = (event) => {
|
|
34118
|
+
this.viewer.canvas.dispatchEvent(new PointerEvent("pointerup", event));
|
|
34119
|
+
};
|
|
34120
|
+
this.onPointerLeave = () => {
|
|
34121
|
+
this.line.endPoint = undefined;
|
|
34122
|
+
this.line.render();
|
|
34123
|
+
};
|
|
34124
|
+
this.clearOverlay = () => {
|
|
34125
|
+
this.overlay.clear();
|
|
34126
|
+
this.line = new MeasureLine(this.overlay, this.scale, this.units, this.precision);
|
|
34127
|
+
this.overlay.addLine(this.line);
|
|
34128
|
+
};
|
|
34129
|
+
this.renderOverlay = () => {
|
|
34130
|
+
this.overlay.render();
|
|
34131
|
+
};
|
|
34132
|
+
this.updateObjects = () => {
|
|
34133
|
+
this.objects.length = 0;
|
|
34134
|
+
this.viewer.models.forEach((model) => {
|
|
34135
|
+
model.getVisibleObjects().forEach((object) => this.objects.push(object));
|
|
34136
|
+
});
|
|
34137
|
+
};
|
|
34138
|
+
this.updateSnapperCamera = () => {
|
|
34139
|
+
this.snapper.camera = this.viewer.camera;
|
|
34140
|
+
this.overlay.camera = this.viewer.camera;
|
|
34141
|
+
};
|
|
34142
|
+
this.updateUnits = () => {
|
|
34143
|
+
var _a, _b;
|
|
34144
|
+
const model = this.viewer.models[0];
|
|
34145
|
+
const units = (_a = this.viewer.options.rulerUnit) !== null && _a !== void 0 ? _a : "Default";
|
|
34146
|
+
const precision = (_b = this.viewer.options.rulerPrecision) !== null && _b !== void 0 ? _b : "Default";
|
|
34147
|
+
if (units === "Default") {
|
|
34148
|
+
this.scale = model.getUnitScale();
|
|
34149
|
+
this.units = model.getUnitString();
|
|
34150
|
+
}
|
|
34151
|
+
else {
|
|
34152
|
+
this.scale = convertUnits(model.getUnits(), units, 1);
|
|
34153
|
+
this.units = units;
|
|
34154
|
+
}
|
|
34155
|
+
if (precision === "Default") {
|
|
34156
|
+
this.precision = model.getPrecision();
|
|
34157
|
+
}
|
|
34158
|
+
else {
|
|
34159
|
+
this.precision = precision;
|
|
34160
|
+
}
|
|
34161
|
+
this.overlay.updateLineUnits(this.scale, this.units, this.precision);
|
|
34162
|
+
};
|
|
34163
|
+
this.overlay = new MeasureOverlay(viewer.camera, viewer.canvas);
|
|
34164
|
+
this.overlay.attach();
|
|
34165
|
+
this.line = new MeasureLine(this.overlay, this.scale, this.units, this.precision);
|
|
34166
|
+
this.overlay.addLine(this.line);
|
|
34167
|
+
this.snapper = new Snapper(viewer.camera, viewer.renderer, viewer.canvas);
|
|
34168
|
+
this.objects = [];
|
|
34169
|
+
this.updateObjects();
|
|
34170
|
+
this.updateUnits();
|
|
34171
|
+
this.viewer.canvas.addEventListener("pointerdown", this.onPointerDown);
|
|
34172
|
+
this.viewer.canvas.addEventListener("pointermove", this.onPointerMove);
|
|
34173
|
+
this.viewer.canvas.addEventListener("pointerup", this.onPointerUp);
|
|
34174
|
+
this.viewer.canvas.addEventListener("pointercancel", this.onPointerCancel);
|
|
34175
|
+
this.viewer.canvas.addEventListener("pointerleave", this.onPointerLeave);
|
|
34176
|
+
this.viewer.addEventListener("render", this.renderOverlay);
|
|
34177
|
+
this.viewer.addEventListener("hide", this.updateObjects);
|
|
34178
|
+
this.viewer.addEventListener("isolate", this.updateObjects);
|
|
34179
|
+
this.viewer.addEventListener("show", this.updateObjects);
|
|
34180
|
+
this.viewer.addEventListener("showall", this.updateObjects);
|
|
34181
|
+
this.viewer.addEventListener("changecameramode", this.updateSnapperCamera);
|
|
34182
|
+
this.viewer.addEventListener("optionschange", this.updateUnits);
|
|
34183
|
+
}
|
|
34184
|
+
dispose() {
|
|
34185
|
+
this.viewer.canvas.removeEventListener("pointerdown", this.onPointerDown);
|
|
34186
|
+
this.viewer.canvas.removeEventListener("pointermove", this.onPointerMove);
|
|
34187
|
+
this.viewer.canvas.removeEventListener("pointerup", this.onPointerUp);
|
|
34188
|
+
this.viewer.canvas.removeEventListener("pointercancel", this.onPointerCancel);
|
|
34189
|
+
this.viewer.canvas.removeEventListener("pointerleave", this.onPointerLeave);
|
|
34190
|
+
this.viewer.removeEventListener("render", this.renderOverlay);
|
|
34191
|
+
this.viewer.removeEventListener("hide", this.updateObjects);
|
|
34192
|
+
this.viewer.removeEventListener("isolate", this.updateObjects);
|
|
34193
|
+
this.viewer.removeEventListener("show", this.updateObjects);
|
|
34194
|
+
this.viewer.removeEventListener("showall", this.updateObjects);
|
|
34195
|
+
this.viewer.removeEventListener("changecameramode", this.updateSnapperCamera);
|
|
34196
|
+
this.viewer.removeEventListener("optionschange", this.updateUnits);
|
|
34085
34197
|
this.objects.length = 0;
|
|
34086
|
-
|
|
34087
|
-
|
|
34088
|
-
|
|
34089
|
-
this.camera = viewer.camera;
|
|
34090
|
-
this.clippingPlanes = viewer.renderer.clippingPlanes || [];
|
|
34198
|
+
this.overlay.detach();
|
|
34199
|
+
this.overlay.dispose();
|
|
34200
|
+
super.dispose();
|
|
34091
34201
|
}
|
|
34092
34202
|
}
|
|
34093
34203
|
class MeasureOverlay {
|
|
@@ -34107,6 +34217,9 @@ void main() {
|
|
|
34107
34217
|
this.projector = new MeasureProjector(camera, canvas);
|
|
34108
34218
|
this.resizeObserver = new ResizeObserver(this.resizeContainer);
|
|
34109
34219
|
}
|
|
34220
|
+
dispose() {
|
|
34221
|
+
this.clear();
|
|
34222
|
+
}
|
|
34110
34223
|
attach() {
|
|
34111
34224
|
this.container = document.createElement("div");
|
|
34112
34225
|
this.container.id = "measure-container";
|
|
@@ -34119,9 +34232,6 @@ void main() {
|
|
|
34119
34232
|
this.canvas.parentElement.appendChild(this.container);
|
|
34120
34233
|
this.resizeObserver.observe(this.canvas);
|
|
34121
34234
|
}
|
|
34122
|
-
dispose() {
|
|
34123
|
-
this.clear();
|
|
34124
|
-
}
|
|
34125
34235
|
detach() {
|
|
34126
34236
|
this.resizeObserver.disconnect();
|
|
34127
34237
|
this.container.remove();
|
|
@@ -34129,7 +34239,7 @@ void main() {
|
|
|
34129
34239
|
}
|
|
34130
34240
|
clear() {
|
|
34131
34241
|
this.lines.forEach((line) => line.dispose());
|
|
34132
|
-
this.lines =
|
|
34242
|
+
this.lines.length = 0;
|
|
34133
34243
|
}
|
|
34134
34244
|
render() {
|
|
34135
34245
|
this.projector.setFromCamera(this.camera);
|
|
@@ -34144,13 +34254,18 @@ void main() {
|
|
|
34144
34254
|
removeLine(line) {
|
|
34145
34255
|
this.lines = this.lines.filter((x) => x !== line);
|
|
34146
34256
|
}
|
|
34257
|
+
updateLineUnits(scale, units, precision) {
|
|
34258
|
+
this.lines.forEach((line) => {
|
|
34259
|
+
line.scale = scale;
|
|
34260
|
+
line.units = units;
|
|
34261
|
+
line.precision = precision;
|
|
34262
|
+
});
|
|
34263
|
+
}
|
|
34147
34264
|
}
|
|
34148
34265
|
const _middlePoint = new Vector3();
|
|
34149
34266
|
class MeasureLine {
|
|
34150
|
-
constructor(overlay) {
|
|
34267
|
+
constructor(overlay, scale, units, precision) {
|
|
34151
34268
|
this.id = MathUtils.generateUUID();
|
|
34152
|
-
this.unit = "";
|
|
34153
|
-
this.scale = 1.0;
|
|
34154
34269
|
this.size = 10.0;
|
|
34155
34270
|
this.lineWidth = 2;
|
|
34156
34271
|
this.style = {
|
|
@@ -34161,6 +34276,9 @@ void main() {
|
|
|
34161
34276
|
font: "1rem system-ui",
|
|
34162
34277
|
};
|
|
34163
34278
|
this.overlay = overlay;
|
|
34279
|
+
this.scale = scale;
|
|
34280
|
+
this.units = units;
|
|
34281
|
+
this.precision = precision;
|
|
34164
34282
|
this.elementStartPoint = overlay.container.appendChild(document.createElement("div"));
|
|
34165
34283
|
this.elementEndPoint = overlay.container.appendChild(document.createElement("div"));
|
|
34166
34284
|
this.elementLine = overlay.container.appendChild(document.createElement("div"));
|
|
@@ -34215,10 +34333,10 @@ void main() {
|
|
|
34215
34333
|
_middlePoint.lerpVectors(this.startPoint, this.endPoint, 0.5);
|
|
34216
34334
|
const { point, visible } = projector.projectPoint(_middlePoint);
|
|
34217
34335
|
const distance = this.getDistance();
|
|
34218
|
-
this.elementLabel.style.display = visible && distance
|
|
34336
|
+
this.elementLabel.style.display = visible && distance > 0 ? "block" : "none";
|
|
34219
34337
|
this.elementLabel.style.left = `${point.x}px`;
|
|
34220
34338
|
this.elementLabel.style.top = `${point.y}px`;
|
|
34221
|
-
this.elementLabel.innerHTML =
|
|
34339
|
+
this.elementLabel.innerHTML = formatDistance(distance, this.units, this.precision);
|
|
34222
34340
|
}
|
|
34223
34341
|
else {
|
|
34224
34342
|
this.elementLabel.style.display = "none";
|
|
@@ -35022,7 +35140,8 @@ void main() {
|
|
|
35022
35140
|
const selection = viewer.getComponent("SelectionComponent");
|
|
35023
35141
|
selection.clearSelection();
|
|
35024
35142
|
viewer.update();
|
|
35025
|
-
viewer.emitEvent({ type: "select",
|
|
35143
|
+
viewer.emitEvent({ type: "select", handles: [] });
|
|
35144
|
+
viewer.emitEvent({ type: "select2", handles: [] });
|
|
35026
35145
|
}
|
|
35027
35146
|
|
|
35028
35147
|
function clearSlices(viewer) {
|
|
@@ -35111,22 +35230,31 @@ void main() {
|
|
|
35111
35230
|
}
|
|
35112
35231
|
|
|
35113
35232
|
function getModels(viewer) {
|
|
35114
|
-
return viewer.models.map((model) => model.
|
|
35233
|
+
return viewer.models.map((model) => model.id);
|
|
35115
35234
|
}
|
|
35116
35235
|
|
|
35117
35236
|
function getSelected(viewer) {
|
|
35118
|
-
const
|
|
35119
|
-
|
|
35237
|
+
const handles2 = viewer.executeCommand("getSelected2");
|
|
35238
|
+
const handles = handles2.map((handle) => handle.slice(handle.indexOf(":") + 1));
|
|
35120
35239
|
return handles;
|
|
35121
35240
|
}
|
|
35122
35241
|
|
|
35242
|
+
function getSelected2(viewer) {
|
|
35243
|
+
const handles2 = [];
|
|
35244
|
+
viewer.models.forEach((model) => {
|
|
35245
|
+
handles2.push(...model.getHandlesByObjects(viewer.selected));
|
|
35246
|
+
});
|
|
35247
|
+
return handles2;
|
|
35248
|
+
}
|
|
35249
|
+
|
|
35123
35250
|
function hideSelected(viewer) {
|
|
35124
35251
|
viewer.models.forEach((model) => model.hideObjects(viewer.selected));
|
|
35125
35252
|
const selection = viewer.getComponent("SelectionComponent");
|
|
35126
35253
|
selection.clearSelection();
|
|
35127
35254
|
viewer.update();
|
|
35128
35255
|
viewer.emitEvent({ type: "hide" });
|
|
35129
|
-
viewer.emitEvent({ type: "select",
|
|
35256
|
+
viewer.emitEvent({ type: "select", handles: [] });
|
|
35257
|
+
viewer.emitEvent({ type: "select2", handles: [] });
|
|
35130
35258
|
}
|
|
35131
35259
|
|
|
35132
35260
|
function isolateSelected(viewer) {
|
|
@@ -35153,14 +35281,13 @@ void main() {
|
|
|
35153
35281
|
viewer.emit({ type: "resetview" });
|
|
35154
35282
|
}
|
|
35155
35283
|
|
|
35156
|
-
function selectModel(viewer,
|
|
35284
|
+
function selectModel(viewer, id) {
|
|
35157
35285
|
const selection = viewer.getComponent("SelectionComponent");
|
|
35158
35286
|
selection.clearSelection();
|
|
35159
|
-
viewer.models
|
|
35160
|
-
.filter((model) => model.handle === handle)
|
|
35161
|
-
.forEach((model) => selection.select(model.getObjects(), model));
|
|
35287
|
+
viewer.models.filter((model) => model.id === id).forEach((model) => selection.select(model.getObjects(), model));
|
|
35162
35288
|
viewer.update();
|
|
35163
|
-
viewer.
|
|
35289
|
+
viewer.emitEvent({ type: "select", handles: viewer.getSelected() });
|
|
35290
|
+
viewer.emitEvent({ type: "select2", handles: viewer.getSelected2() });
|
|
35164
35291
|
}
|
|
35165
35292
|
|
|
35166
35293
|
function setActiveDragger(viewer, dragger = "") {
|
|
@@ -35172,16 +35299,31 @@ void main() {
|
|
|
35172
35299
|
}
|
|
35173
35300
|
|
|
35174
35301
|
function setSelected(viewer, handles = []) {
|
|
35175
|
-
const
|
|
35176
|
-
|
|
35302
|
+
const handles2 = [];
|
|
35303
|
+
handles.forEach((handle) => {
|
|
35304
|
+
if (handle.includes(":")) {
|
|
35305
|
+
handles2.push(handle);
|
|
35306
|
+
}
|
|
35307
|
+
else
|
|
35308
|
+
viewer.models.forEach((model) => {
|
|
35309
|
+
handles2.push(`${model.id}:${handle}`);
|
|
35310
|
+
});
|
|
35311
|
+
});
|
|
35312
|
+
viewer.executeCommand("setSelected2", handles2);
|
|
35313
|
+
}
|
|
35314
|
+
|
|
35315
|
+
function setSelected2(viewer, handles = []) {
|
|
35316
|
+
const selectionComponent = viewer.getComponent("SelectionComponent");
|
|
35317
|
+
selectionComponent.clearSelection();
|
|
35177
35318
|
viewer.models.forEach((model) => {
|
|
35178
35319
|
const objects = model.getObjectsByHandles(handles);
|
|
35179
35320
|
model.showObjects(objects);
|
|
35180
|
-
|
|
35321
|
+
selectionComponent.select(objects, model);
|
|
35181
35322
|
});
|
|
35182
35323
|
viewer.update();
|
|
35183
35324
|
viewer.emitEvent({ type: "show" });
|
|
35184
|
-
viewer.emitEvent({ type: "select", data: undefined, handles });
|
|
35325
|
+
viewer.emitEvent({ type: "select", data: undefined, handles: viewer.getSelected() });
|
|
35326
|
+
viewer.emitEvent({ type: "select2", data: undefined, handles });
|
|
35185
35327
|
}
|
|
35186
35328
|
|
|
35187
35329
|
function showAll(viewer) {
|
|
@@ -35195,21 +35337,19 @@ void main() {
|
|
|
35195
35337
|
}
|
|
35196
35338
|
|
|
35197
35339
|
function zoomToObjects(viewer, handles = []) {
|
|
35198
|
-
const
|
|
35199
|
-
|
|
35200
|
-
|
|
35201
|
-
|
|
35202
|
-
if (handleSet.has((_a = child.userData) === null || _a === void 0 ? void 0 : _a.handle))
|
|
35203
|
-
objects.push(child);
|
|
35340
|
+
const extents = new Box3();
|
|
35341
|
+
viewer.models.forEach((model) => {
|
|
35342
|
+
const objects = model.getObjectsByHandles(handles);
|
|
35343
|
+
objects.forEach((object) => extents.expandByObject(object));
|
|
35204
35344
|
});
|
|
35205
|
-
const extents = objects.reduce((result, object) => result.expandByObject(object), new Box3());
|
|
35206
35345
|
if (extents.isEmpty())
|
|
35207
35346
|
extents.copy(viewer.extents);
|
|
35208
35347
|
zoomTo(viewer, extents);
|
|
35209
35348
|
}
|
|
35210
35349
|
|
|
35211
35350
|
function zoomToSelected(viewer) {
|
|
35212
|
-
const extents =
|
|
35351
|
+
const extents = new Box3();
|
|
35352
|
+
viewer.selected.forEach((object) => extents.expandByObject(object));
|
|
35213
35353
|
if (extents.isEmpty())
|
|
35214
35354
|
extents.copy(viewer.extents);
|
|
35215
35355
|
zoomTo(viewer, extents);
|
|
@@ -35226,6 +35366,7 @@ void main() {
|
|
|
35226
35366
|
commands.registerCommand("getDefaultViewPositions", getDefaultViewPositions);
|
|
35227
35367
|
commands.registerCommand("getModels", getModels);
|
|
35228
35368
|
commands.registerCommand("getSelected", getSelected);
|
|
35369
|
+
commands.registerCommand("getSelected2", getSelected2);
|
|
35229
35370
|
commands.registerCommand("hideSelected", hideSelected);
|
|
35230
35371
|
commands.registerCommand("isolateSelected", isolateSelected);
|
|
35231
35372
|
commands.registerCommand("regenerateAll", regenerateAll);
|
|
@@ -35235,6 +35376,7 @@ void main() {
|
|
|
35235
35376
|
commands.registerCommand("setDefaultViewPosition", setDefaultViewPosition);
|
|
35236
35377
|
commands.registerCommand("setMarkupColor", setMarkupColor);
|
|
35237
35378
|
commands.registerCommand("setSelected", setSelected);
|
|
35379
|
+
commands.registerCommand("setSelected2", setSelected2);
|
|
35238
35380
|
commands.registerCommand("showAll", showAll);
|
|
35239
35381
|
commands.registerCommand("zoomToExtents", zoomToExtents);
|
|
35240
35382
|
commands.registerCommand("zoomToObjects", zoomToObjects);
|
|
@@ -35287,6 +35429,10 @@ void main() {
|
|
|
35287
35429
|
this.switchCameraMode(this.viewer.options.cameraMode);
|
|
35288
35430
|
};
|
|
35289
35431
|
this.geometryEnd = () => {
|
|
35432
|
+
if (this.viewer.models.length > 1) {
|
|
35433
|
+
this.switchCamera(this.viewer.camera);
|
|
35434
|
+
return;
|
|
35435
|
+
}
|
|
35290
35436
|
let camera;
|
|
35291
35437
|
this.viewer.scene.traverse((object) => {
|
|
35292
35438
|
if (object.isCamera)
|
|
@@ -35384,6 +35530,8 @@ void main() {
|
|
|
35384
35530
|
const extents = new Box3();
|
|
35385
35531
|
this.viewer.models.forEach((model) => model.getExtents(extents));
|
|
35386
35532
|
this.viewer.extents.copy(extents);
|
|
35533
|
+
if (this.viewer.models.length > 1)
|
|
35534
|
+
return;
|
|
35387
35535
|
this.viewer.extents.getCenter(this.viewer.target);
|
|
35388
35536
|
};
|
|
35389
35537
|
this.viewer = viewer;
|
|
@@ -36350,10 +36498,11 @@ void main() {
|
|
|
36350
36498
|
const upPosition = this.getMousePosition(event, new Vector2());
|
|
36351
36499
|
if (upPosition.distanceTo(this.downPosition) !== 0)
|
|
36352
36500
|
return;
|
|
36501
|
+
const snapper = new Snapper(this.viewer.camera, this.viewer.renderer, this.viewer.canvas);
|
|
36353
36502
|
let intersections = [];
|
|
36354
36503
|
this.viewer.models.forEach((model) => {
|
|
36355
36504
|
const objects = model.getVisibleObjects();
|
|
36356
|
-
const intersects =
|
|
36505
|
+
const intersects = snapper.getPointerIntersects(upPosition, objects);
|
|
36357
36506
|
if (intersects.length > 0)
|
|
36358
36507
|
intersections.push({ ...intersects[0], model });
|
|
36359
36508
|
});
|
|
@@ -36371,6 +36520,7 @@ void main() {
|
|
|
36371
36520
|
}
|
|
36372
36521
|
this.viewer.update();
|
|
36373
36522
|
this.viewer.emitEvent({ type: "select", data: undefined, handles: this.viewer.getSelected() });
|
|
36523
|
+
this.viewer.emitEvent({ type: "select2", data: undefined, handles: this.viewer.getSelected2() });
|
|
36374
36524
|
};
|
|
36375
36525
|
this.onDoubleClick = (event) => {
|
|
36376
36526
|
if (event.button !== 0)
|
|
@@ -36381,7 +36531,6 @@ void main() {
|
|
|
36381
36531
|
this.highlighter = this.viewer.getComponent("HighlighterComponent");
|
|
36382
36532
|
};
|
|
36383
36533
|
this.viewer = viewer;
|
|
36384
|
-
this.raycaster = new Raycaster();
|
|
36385
36534
|
this.downPosition = new Vector2();
|
|
36386
36535
|
this.viewer.addEventListener("pointerdown", this.onPointerDown);
|
|
36387
36536
|
this.viewer.addEventListener("pointerup", this.onPointerUp);
|
|
@@ -36397,26 +36546,6 @@ void main() {
|
|
|
36397
36546
|
getMousePosition(event, target) {
|
|
36398
36547
|
return target.set(event.clientX, event.clientY);
|
|
36399
36548
|
}
|
|
36400
|
-
getPointerIntersects(mouse, objects) {
|
|
36401
|
-
const rect = this.viewer.canvas.getBoundingClientRect();
|
|
36402
|
-
const x = ((mouse.x - rect.left) / rect.width) * 2 - 1;
|
|
36403
|
-
const y = (-(mouse.y - rect.top) / rect.height) * 2 + 1;
|
|
36404
|
-
const coords = new Vector2(x, y);
|
|
36405
|
-
this.raycaster.setFromCamera(coords, this.viewer.camera);
|
|
36406
|
-
this.raycaster.params = {
|
|
36407
|
-
Mesh: {},
|
|
36408
|
-
Line: { threshold: 0.05 },
|
|
36409
|
-
Line2: { threshold: 0.05 },
|
|
36410
|
-
LOD: {},
|
|
36411
|
-
Points: { threshold: 0.01 },
|
|
36412
|
-
Sprite: {},
|
|
36413
|
-
};
|
|
36414
|
-
let intersects = this.raycaster.intersectObjects(objects, false);
|
|
36415
|
-
(this.viewer.renderer.clippingPlanes || []).forEach((plane) => {
|
|
36416
|
-
intersects = intersects.filter((intersect) => plane.distanceToPoint(intersect.point) >= 0);
|
|
36417
|
-
});
|
|
36418
|
-
return intersects;
|
|
36419
|
-
}
|
|
36420
36549
|
select(objects, model) {
|
|
36421
36550
|
if (!model) {
|
|
36422
36551
|
this.viewer.models.forEach((model) => this.select(objects, model));
|
|
@@ -36615,2616 +36744,8 @@ void main() {
|
|
|
36615
36744
|
components.registerComponent("WCSHelperComponent", (viewer) => new WCSHelperComponent(viewer));
|
|
36616
36745
|
components.registerComponent("ResetComponent", (viewer) => new ResetComponent(viewer));
|
|
36617
36746
|
|
|
36618
|
-
function mergeGeometries( geometries, useGroups = false ) {
|
|
36619
|
-
const isIndexed = geometries[ 0 ].index !== null;
|
|
36620
|
-
const attributesUsed = new Set( Object.keys( geometries[ 0 ].attributes ) );
|
|
36621
|
-
const morphAttributesUsed = new Set( Object.keys( geometries[ 0 ].morphAttributes ) );
|
|
36622
|
-
const attributes = {};
|
|
36623
|
-
const morphAttributes = {};
|
|
36624
|
-
const morphTargetsRelative = geometries[ 0 ].morphTargetsRelative;
|
|
36625
|
-
const mergedGeometry = new BufferGeometry();
|
|
36626
|
-
let offset = 0;
|
|
36627
|
-
for ( let i = 0; i < geometries.length; ++ i ) {
|
|
36628
|
-
const geometry = geometries[ i ];
|
|
36629
|
-
let attributesCount = 0;
|
|
36630
|
-
if ( isIndexed !== ( geometry.index !== null ) ) {
|
|
36631
|
-
console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.' );
|
|
36632
|
-
return null;
|
|
36633
|
-
}
|
|
36634
|
-
for ( const name in geometry.attributes ) {
|
|
36635
|
-
if ( ! attributesUsed.has( name ) ) {
|
|
36636
|
-
console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. All geometries must have compatible attributes; make sure "' + name + '" attribute exists among all geometries, or in none of them.' );
|
|
36637
|
-
return null;
|
|
36638
|
-
}
|
|
36639
|
-
if ( attributes[ name ] === undefined ) attributes[ name ] = [];
|
|
36640
|
-
attributes[ name ].push( geometry.attributes[ name ] );
|
|
36641
|
-
attributesCount ++;
|
|
36642
|
-
}
|
|
36643
|
-
if ( attributesCount !== attributesUsed.size ) {
|
|
36644
|
-
console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. Make sure all geometries have the same number of attributes.' );
|
|
36645
|
-
return null;
|
|
36646
|
-
}
|
|
36647
|
-
if ( morphTargetsRelative !== geometry.morphTargetsRelative ) {
|
|
36648
|
-
console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. .morphTargetsRelative must be consistent throughout all geometries.' );
|
|
36649
|
-
return null;
|
|
36650
|
-
}
|
|
36651
|
-
for ( const name in geometry.morphAttributes ) {
|
|
36652
|
-
if ( ! morphAttributesUsed.has( name ) ) {
|
|
36653
|
-
console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. .morphAttributes must be consistent throughout all geometries.' );
|
|
36654
|
-
return null;
|
|
36655
|
-
}
|
|
36656
|
-
if ( morphAttributes[ name ] === undefined ) morphAttributes[ name ] = [];
|
|
36657
|
-
morphAttributes[ name ].push( geometry.morphAttributes[ name ] );
|
|
36658
|
-
}
|
|
36659
|
-
if ( useGroups ) {
|
|
36660
|
-
let count;
|
|
36661
|
-
if ( isIndexed ) {
|
|
36662
|
-
count = geometry.index.count;
|
|
36663
|
-
} else if ( geometry.attributes.position !== undefined ) {
|
|
36664
|
-
count = geometry.attributes.position.count;
|
|
36665
|
-
} else {
|
|
36666
|
-
console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. The geometry must have either an index or a position attribute' );
|
|
36667
|
-
return null;
|
|
36668
|
-
}
|
|
36669
|
-
mergedGeometry.addGroup( offset, count, i );
|
|
36670
|
-
offset += count;
|
|
36671
|
-
}
|
|
36672
|
-
}
|
|
36673
|
-
if ( isIndexed ) {
|
|
36674
|
-
let indexOffset = 0;
|
|
36675
|
-
const mergedIndex = [];
|
|
36676
|
-
for ( let i = 0; i < geometries.length; ++ i ) {
|
|
36677
|
-
const index = geometries[ i ].index;
|
|
36678
|
-
for ( let j = 0; j < index.count; ++ j ) {
|
|
36679
|
-
mergedIndex.push( index.getX( j ) + indexOffset );
|
|
36680
|
-
}
|
|
36681
|
-
indexOffset += geometries[ i ].attributes.position.count;
|
|
36682
|
-
}
|
|
36683
|
-
mergedGeometry.setIndex( mergedIndex );
|
|
36684
|
-
}
|
|
36685
|
-
for ( const name in attributes ) {
|
|
36686
|
-
const mergedAttribute = mergeAttributes( attributes[ name ] );
|
|
36687
|
-
if ( ! mergedAttribute ) {
|
|
36688
|
-
console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the ' + name + ' attribute.' );
|
|
36689
|
-
return null;
|
|
36690
|
-
}
|
|
36691
|
-
mergedGeometry.setAttribute( name, mergedAttribute );
|
|
36692
|
-
}
|
|
36693
|
-
for ( const name in morphAttributes ) {
|
|
36694
|
-
const numMorphTargets = morphAttributes[ name ][ 0 ].length;
|
|
36695
|
-
if ( numMorphTargets === 0 ) break;
|
|
36696
|
-
mergedGeometry.morphAttributes = mergedGeometry.morphAttributes || {};
|
|
36697
|
-
mergedGeometry.morphAttributes[ name ] = [];
|
|
36698
|
-
for ( let i = 0; i < numMorphTargets; ++ i ) {
|
|
36699
|
-
const morphAttributesToMerge = [];
|
|
36700
|
-
for ( let j = 0; j < morphAttributes[ name ].length; ++ j ) {
|
|
36701
|
-
morphAttributesToMerge.push( morphAttributes[ name ][ j ][ i ] );
|
|
36702
|
-
}
|
|
36703
|
-
const mergedMorphAttribute = mergeAttributes( morphAttributesToMerge );
|
|
36704
|
-
if ( ! mergedMorphAttribute ) {
|
|
36705
|
-
console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the ' + name + ' morphAttribute.' );
|
|
36706
|
-
return null;
|
|
36707
|
-
}
|
|
36708
|
-
mergedGeometry.morphAttributes[ name ].push( mergedMorphAttribute );
|
|
36709
|
-
}
|
|
36710
|
-
}
|
|
36711
|
-
return mergedGeometry;
|
|
36712
|
-
}
|
|
36713
|
-
function mergeAttributes( attributes ) {
|
|
36714
|
-
let TypedArray;
|
|
36715
|
-
let itemSize;
|
|
36716
|
-
let normalized;
|
|
36717
|
-
let gpuType = -1;
|
|
36718
|
-
let arrayLength = 0;
|
|
36719
|
-
for ( let i = 0; i < attributes.length; ++ i ) {
|
|
36720
|
-
const attribute = attributes[ i ];
|
|
36721
|
-
if ( TypedArray === undefined ) TypedArray = attribute.array.constructor;
|
|
36722
|
-
if ( TypedArray !== attribute.array.constructor ) {
|
|
36723
|
-
console.error( 'THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes.' );
|
|
36724
|
-
return null;
|
|
36725
|
-
}
|
|
36726
|
-
if ( itemSize === undefined ) itemSize = attribute.itemSize;
|
|
36727
|
-
if ( itemSize !== attribute.itemSize ) {
|
|
36728
|
-
console.error( 'THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes.' );
|
|
36729
|
-
return null;
|
|
36730
|
-
}
|
|
36731
|
-
if ( normalized === undefined ) normalized = attribute.normalized;
|
|
36732
|
-
if ( normalized !== attribute.normalized ) {
|
|
36733
|
-
console.error( 'THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes.' );
|
|
36734
|
-
return null;
|
|
36735
|
-
}
|
|
36736
|
-
if ( gpuType === -1 ) gpuType = attribute.gpuType;
|
|
36737
|
-
if ( gpuType !== attribute.gpuType ) {
|
|
36738
|
-
console.error( 'THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes.' );
|
|
36739
|
-
return null;
|
|
36740
|
-
}
|
|
36741
|
-
arrayLength += attribute.count * itemSize;
|
|
36742
|
-
}
|
|
36743
|
-
const array = new TypedArray( arrayLength );
|
|
36744
|
-
const result = new BufferAttribute( array, itemSize, normalized );
|
|
36745
|
-
let offset = 0;
|
|
36746
|
-
for ( let i = 0; i < attributes.length; ++ i ) {
|
|
36747
|
-
const attribute = attributes[ i ];
|
|
36748
|
-
if ( attribute.isInterleavedBufferAttribute ) {
|
|
36749
|
-
const tupleOffset = offset / itemSize;
|
|
36750
|
-
for ( let j = 0, l = attribute.count; j < l; j ++ ) {
|
|
36751
|
-
for ( let c = 0; c < itemSize; c ++ ) {
|
|
36752
|
-
const value = attribute.getComponent( j, c );
|
|
36753
|
-
result.setComponent( j + tupleOffset, c, value );
|
|
36754
|
-
}
|
|
36755
|
-
}
|
|
36756
|
-
} else {
|
|
36757
|
-
array.set( attribute.array, offset );
|
|
36758
|
-
}
|
|
36759
|
-
offset += attribute.count * itemSize;
|
|
36760
|
-
}
|
|
36761
|
-
if ( gpuType !== undefined ) {
|
|
36762
|
-
result.gpuType = gpuType;
|
|
36763
|
-
}
|
|
36764
|
-
return result;
|
|
36765
|
-
}
|
|
36766
|
-
function toTrianglesDrawMode( geometry, drawMode ) {
|
|
36767
|
-
if ( drawMode === TrianglesDrawMode ) {
|
|
36768
|
-
console.warn( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles.' );
|
|
36769
|
-
return geometry;
|
|
36770
|
-
}
|
|
36771
|
-
if ( drawMode === TriangleFanDrawMode || drawMode === TriangleStripDrawMode ) {
|
|
36772
|
-
let index = geometry.getIndex();
|
|
36773
|
-
if ( index === null ) {
|
|
36774
|
-
const indices = [];
|
|
36775
|
-
const position = geometry.getAttribute( 'position' );
|
|
36776
|
-
if ( position !== undefined ) {
|
|
36777
|
-
for ( let i = 0; i < position.count; i ++ ) {
|
|
36778
|
-
indices.push( i );
|
|
36779
|
-
}
|
|
36780
|
-
geometry.setIndex( indices );
|
|
36781
|
-
index = geometry.getIndex();
|
|
36782
|
-
} else {
|
|
36783
|
-
console.error( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible.' );
|
|
36784
|
-
return geometry;
|
|
36785
|
-
}
|
|
36786
|
-
}
|
|
36787
|
-
const numberOfTriangles = index.count - 2;
|
|
36788
|
-
const newIndices = [];
|
|
36789
|
-
if ( drawMode === TriangleFanDrawMode ) {
|
|
36790
|
-
for ( let i = 1; i <= numberOfTriangles; i ++ ) {
|
|
36791
|
-
newIndices.push( index.getX( 0 ) );
|
|
36792
|
-
newIndices.push( index.getX( i ) );
|
|
36793
|
-
newIndices.push( index.getX( i + 1 ) );
|
|
36794
|
-
}
|
|
36795
|
-
} else {
|
|
36796
|
-
for ( let i = 0; i < numberOfTriangles; i ++ ) {
|
|
36797
|
-
if ( i % 2 === 0 ) {
|
|
36798
|
-
newIndices.push( index.getX( i ) );
|
|
36799
|
-
newIndices.push( index.getX( i + 1 ) );
|
|
36800
|
-
newIndices.push( index.getX( i + 2 ) );
|
|
36801
|
-
} else {
|
|
36802
|
-
newIndices.push( index.getX( i + 2 ) );
|
|
36803
|
-
newIndices.push( index.getX( i + 1 ) );
|
|
36804
|
-
newIndices.push( index.getX( i ) );
|
|
36805
|
-
}
|
|
36806
|
-
}
|
|
36807
|
-
}
|
|
36808
|
-
if ( ( newIndices.length / 3 ) !== numberOfTriangles ) {
|
|
36809
|
-
console.error( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.' );
|
|
36810
|
-
}
|
|
36811
|
-
const newGeometry = geometry.clone();
|
|
36812
|
-
newGeometry.setIndex( newIndices );
|
|
36813
|
-
newGeometry.clearGroups();
|
|
36814
|
-
return newGeometry;
|
|
36815
|
-
} else {
|
|
36816
|
-
console.error( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:', drawMode );
|
|
36817
|
-
return geometry;
|
|
36818
|
-
}
|
|
36819
|
-
}
|
|
36820
|
-
|
|
36821
|
-
class GLTFLoader extends Loader {
|
|
36822
|
-
constructor( manager ) {
|
|
36823
|
-
super( manager );
|
|
36824
|
-
this.dracoLoader = null;
|
|
36825
|
-
this.ktx2Loader = null;
|
|
36826
|
-
this.meshoptDecoder = null;
|
|
36827
|
-
this.pluginCallbacks = [];
|
|
36828
|
-
this.register( function ( parser ) {
|
|
36829
|
-
return new GLTFMaterialsClearcoatExtension( parser );
|
|
36830
|
-
} );
|
|
36831
|
-
this.register( function ( parser ) {
|
|
36832
|
-
return new GLTFMaterialsDispersionExtension( parser );
|
|
36833
|
-
} );
|
|
36834
|
-
this.register( function ( parser ) {
|
|
36835
|
-
return new GLTFTextureBasisUExtension( parser );
|
|
36836
|
-
} );
|
|
36837
|
-
this.register( function ( parser ) {
|
|
36838
|
-
return new GLTFTextureWebPExtension( parser );
|
|
36839
|
-
} );
|
|
36840
|
-
this.register( function ( parser ) {
|
|
36841
|
-
return new GLTFTextureAVIFExtension( parser );
|
|
36842
|
-
} );
|
|
36843
|
-
this.register( function ( parser ) {
|
|
36844
|
-
return new GLTFMaterialsSheenExtension( parser );
|
|
36845
|
-
} );
|
|
36846
|
-
this.register( function ( parser ) {
|
|
36847
|
-
return new GLTFMaterialsTransmissionExtension( parser );
|
|
36848
|
-
} );
|
|
36849
|
-
this.register( function ( parser ) {
|
|
36850
|
-
return new GLTFMaterialsVolumeExtension( parser );
|
|
36851
|
-
} );
|
|
36852
|
-
this.register( function ( parser ) {
|
|
36853
|
-
return new GLTFMaterialsIorExtension( parser );
|
|
36854
|
-
} );
|
|
36855
|
-
this.register( function ( parser ) {
|
|
36856
|
-
return new GLTFMaterialsEmissiveStrengthExtension( parser );
|
|
36857
|
-
} );
|
|
36858
|
-
this.register( function ( parser ) {
|
|
36859
|
-
return new GLTFMaterialsSpecularExtension( parser );
|
|
36860
|
-
} );
|
|
36861
|
-
this.register( function ( parser ) {
|
|
36862
|
-
return new GLTFMaterialsIridescenceExtension( parser );
|
|
36863
|
-
} );
|
|
36864
|
-
this.register( function ( parser ) {
|
|
36865
|
-
return new GLTFMaterialsAnisotropyExtension( parser );
|
|
36866
|
-
} );
|
|
36867
|
-
this.register( function ( parser ) {
|
|
36868
|
-
return new GLTFMaterialsBumpExtension( parser );
|
|
36869
|
-
} );
|
|
36870
|
-
this.register( function ( parser ) {
|
|
36871
|
-
return new GLTFLightsExtension( parser );
|
|
36872
|
-
} );
|
|
36873
|
-
this.register( function ( parser ) {
|
|
36874
|
-
return new GLTFMeshoptCompression( parser );
|
|
36875
|
-
} );
|
|
36876
|
-
this.register( function ( parser ) {
|
|
36877
|
-
return new GLTFMeshGpuInstancing( parser );
|
|
36878
|
-
} );
|
|
36879
|
-
}
|
|
36880
|
-
load( url, onLoad, onProgress, onError ) {
|
|
36881
|
-
const scope = this;
|
|
36882
|
-
let resourcePath;
|
|
36883
|
-
if ( this.resourcePath !== '' ) {
|
|
36884
|
-
resourcePath = this.resourcePath;
|
|
36885
|
-
} else if ( this.path !== '' ) {
|
|
36886
|
-
const relativeUrl = LoaderUtils.extractUrlBase( url );
|
|
36887
|
-
resourcePath = LoaderUtils.resolveURL( relativeUrl, this.path );
|
|
36888
|
-
} else {
|
|
36889
|
-
resourcePath = LoaderUtils.extractUrlBase( url );
|
|
36890
|
-
}
|
|
36891
|
-
this.manager.itemStart( url );
|
|
36892
|
-
const _onError = function ( e ) {
|
|
36893
|
-
if ( onError ) {
|
|
36894
|
-
onError( e );
|
|
36895
|
-
} else {
|
|
36896
|
-
console.error( e );
|
|
36897
|
-
}
|
|
36898
|
-
scope.manager.itemError( url );
|
|
36899
|
-
scope.manager.itemEnd( url );
|
|
36900
|
-
};
|
|
36901
|
-
const loader = new FileLoader( this.manager );
|
|
36902
|
-
loader.setPath( this.path );
|
|
36903
|
-
loader.setResponseType( 'arraybuffer' );
|
|
36904
|
-
loader.setRequestHeader( this.requestHeader );
|
|
36905
|
-
loader.setWithCredentials( this.withCredentials );
|
|
36906
|
-
loader.load( url, function ( data ) {
|
|
36907
|
-
try {
|
|
36908
|
-
scope.parse( data, resourcePath, function ( gltf ) {
|
|
36909
|
-
onLoad( gltf );
|
|
36910
|
-
scope.manager.itemEnd( url );
|
|
36911
|
-
}, _onError );
|
|
36912
|
-
} catch ( e ) {
|
|
36913
|
-
_onError( e );
|
|
36914
|
-
}
|
|
36915
|
-
}, onProgress, _onError );
|
|
36916
|
-
}
|
|
36917
|
-
setDRACOLoader( dracoLoader ) {
|
|
36918
|
-
this.dracoLoader = dracoLoader;
|
|
36919
|
-
return this;
|
|
36920
|
-
}
|
|
36921
|
-
setKTX2Loader( ktx2Loader ) {
|
|
36922
|
-
this.ktx2Loader = ktx2Loader;
|
|
36923
|
-
return this;
|
|
36924
|
-
}
|
|
36925
|
-
setMeshoptDecoder( meshoptDecoder ) {
|
|
36926
|
-
this.meshoptDecoder = meshoptDecoder;
|
|
36927
|
-
return this;
|
|
36928
|
-
}
|
|
36929
|
-
register( callback ) {
|
|
36930
|
-
if ( this.pluginCallbacks.indexOf( callback ) === -1 ) {
|
|
36931
|
-
this.pluginCallbacks.push( callback );
|
|
36932
|
-
}
|
|
36933
|
-
return this;
|
|
36934
|
-
}
|
|
36935
|
-
unregister( callback ) {
|
|
36936
|
-
if ( this.pluginCallbacks.indexOf( callback ) !== -1 ) {
|
|
36937
|
-
this.pluginCallbacks.splice( this.pluginCallbacks.indexOf( callback ), 1 );
|
|
36938
|
-
}
|
|
36939
|
-
return this;
|
|
36940
|
-
}
|
|
36941
|
-
parse( data, path, onLoad, onError ) {
|
|
36942
|
-
let json;
|
|
36943
|
-
const extensions = {};
|
|
36944
|
-
const plugins = {};
|
|
36945
|
-
const textDecoder = new TextDecoder();
|
|
36946
|
-
if ( typeof data === 'string' ) {
|
|
36947
|
-
json = JSON.parse( data );
|
|
36948
|
-
} else if ( data instanceof ArrayBuffer ) {
|
|
36949
|
-
const magic = textDecoder.decode( new Uint8Array( data, 0, 4 ) );
|
|
36950
|
-
if ( magic === BINARY_EXTENSION_HEADER_MAGIC ) {
|
|
36951
|
-
try {
|
|
36952
|
-
extensions[ EXTENSIONS.KHR_BINARY_GLTF ] = new GLTFBinaryExtension( data );
|
|
36953
|
-
} catch ( error ) {
|
|
36954
|
-
if ( onError ) onError( error );
|
|
36955
|
-
return;
|
|
36956
|
-
}
|
|
36957
|
-
json = JSON.parse( extensions[ EXTENSIONS.KHR_BINARY_GLTF ].content );
|
|
36958
|
-
} else {
|
|
36959
|
-
json = JSON.parse( textDecoder.decode( data ) );
|
|
36960
|
-
}
|
|
36961
|
-
} else {
|
|
36962
|
-
json = data;
|
|
36963
|
-
}
|
|
36964
|
-
if ( json.asset === undefined || json.asset.version[ 0 ] < 2 ) {
|
|
36965
|
-
if ( onError ) onError( new Error( 'THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.' ) );
|
|
36966
|
-
return;
|
|
36967
|
-
}
|
|
36968
|
-
const parser = new GLTFParser( json, {
|
|
36969
|
-
path: path || this.resourcePath || '',
|
|
36970
|
-
crossOrigin: this.crossOrigin,
|
|
36971
|
-
requestHeader: this.requestHeader,
|
|
36972
|
-
manager: this.manager,
|
|
36973
|
-
ktx2Loader: this.ktx2Loader,
|
|
36974
|
-
meshoptDecoder: this.meshoptDecoder
|
|
36975
|
-
} );
|
|
36976
|
-
parser.fileLoader.setRequestHeader( this.requestHeader );
|
|
36977
|
-
for ( let i = 0; i < this.pluginCallbacks.length; i ++ ) {
|
|
36978
|
-
const plugin = this.pluginCallbacks[ i ]( parser );
|
|
36979
|
-
if ( ! plugin.name ) console.error( 'THREE.GLTFLoader: Invalid plugin found: missing name' );
|
|
36980
|
-
plugins[ plugin.name ] = plugin;
|
|
36981
|
-
extensions[ plugin.name ] = true;
|
|
36982
|
-
}
|
|
36983
|
-
if ( json.extensionsUsed ) {
|
|
36984
|
-
for ( let i = 0; i < json.extensionsUsed.length; ++ i ) {
|
|
36985
|
-
const extensionName = json.extensionsUsed[ i ];
|
|
36986
|
-
const extensionsRequired = json.extensionsRequired || [];
|
|
36987
|
-
switch ( extensionName ) {
|
|
36988
|
-
case EXTENSIONS.KHR_MATERIALS_UNLIT:
|
|
36989
|
-
extensions[ extensionName ] = new GLTFMaterialsUnlitExtension();
|
|
36990
|
-
break;
|
|
36991
|
-
case EXTENSIONS.KHR_DRACO_MESH_COMPRESSION:
|
|
36992
|
-
extensions[ extensionName ] = new GLTFDracoMeshCompressionExtension( json, this.dracoLoader );
|
|
36993
|
-
break;
|
|
36994
|
-
case EXTENSIONS.KHR_TEXTURE_TRANSFORM:
|
|
36995
|
-
extensions[ extensionName ] = new GLTFTextureTransformExtension();
|
|
36996
|
-
break;
|
|
36997
|
-
case EXTENSIONS.KHR_MESH_QUANTIZATION:
|
|
36998
|
-
extensions[ extensionName ] = new GLTFMeshQuantizationExtension();
|
|
36999
|
-
break;
|
|
37000
|
-
default:
|
|
37001
|
-
if ( extensionsRequired.indexOf( extensionName ) >= 0 && plugins[ extensionName ] === undefined ) {
|
|
37002
|
-
console.warn( 'THREE.GLTFLoader: Unknown extension "' + extensionName + '".' );
|
|
37003
|
-
}
|
|
37004
|
-
}
|
|
37005
|
-
}
|
|
37006
|
-
}
|
|
37007
|
-
parser.setExtensions( extensions );
|
|
37008
|
-
parser.setPlugins( plugins );
|
|
37009
|
-
parser.parse( onLoad, onError );
|
|
37010
|
-
}
|
|
37011
|
-
parseAsync( data, path ) {
|
|
37012
|
-
const scope = this;
|
|
37013
|
-
return new Promise( function ( resolve, reject ) {
|
|
37014
|
-
scope.parse( data, path, resolve, reject );
|
|
37015
|
-
} );
|
|
37016
|
-
}
|
|
37017
|
-
}
|
|
37018
|
-
function GLTFRegistry() {
|
|
37019
|
-
let objects = {};
|
|
37020
|
-
return {
|
|
37021
|
-
get: function ( key ) {
|
|
37022
|
-
return objects[ key ];
|
|
37023
|
-
},
|
|
37024
|
-
add: function ( key, object ) {
|
|
37025
|
-
objects[ key ] = object;
|
|
37026
|
-
},
|
|
37027
|
-
remove: function ( key ) {
|
|
37028
|
-
delete objects[ key ];
|
|
37029
|
-
},
|
|
37030
|
-
removeAll: function () {
|
|
37031
|
-
objects = {};
|
|
37032
|
-
}
|
|
37033
|
-
};
|
|
37034
|
-
}
|
|
37035
|
-
const EXTENSIONS = {
|
|
37036
|
-
KHR_BINARY_GLTF: 'KHR_binary_glTF',
|
|
37037
|
-
KHR_DRACO_MESH_COMPRESSION: 'KHR_draco_mesh_compression',
|
|
37038
|
-
KHR_LIGHTS_PUNCTUAL: 'KHR_lights_punctual',
|
|
37039
|
-
KHR_MATERIALS_CLEARCOAT: 'KHR_materials_clearcoat',
|
|
37040
|
-
KHR_MATERIALS_DISPERSION: 'KHR_materials_dispersion',
|
|
37041
|
-
KHR_MATERIALS_IOR: 'KHR_materials_ior',
|
|
37042
|
-
KHR_MATERIALS_SHEEN: 'KHR_materials_sheen',
|
|
37043
|
-
KHR_MATERIALS_SPECULAR: 'KHR_materials_specular',
|
|
37044
|
-
KHR_MATERIALS_TRANSMISSION: 'KHR_materials_transmission',
|
|
37045
|
-
KHR_MATERIALS_IRIDESCENCE: 'KHR_materials_iridescence',
|
|
37046
|
-
KHR_MATERIALS_ANISOTROPY: 'KHR_materials_anisotropy',
|
|
37047
|
-
KHR_MATERIALS_UNLIT: 'KHR_materials_unlit',
|
|
37048
|
-
KHR_MATERIALS_VOLUME: 'KHR_materials_volume',
|
|
37049
|
-
KHR_TEXTURE_BASISU: 'KHR_texture_basisu',
|
|
37050
|
-
KHR_TEXTURE_TRANSFORM: 'KHR_texture_transform',
|
|
37051
|
-
KHR_MESH_QUANTIZATION: 'KHR_mesh_quantization',
|
|
37052
|
-
KHR_MATERIALS_EMISSIVE_STRENGTH: 'KHR_materials_emissive_strength',
|
|
37053
|
-
EXT_MATERIALS_BUMP: 'EXT_materials_bump',
|
|
37054
|
-
EXT_TEXTURE_WEBP: 'EXT_texture_webp',
|
|
37055
|
-
EXT_TEXTURE_AVIF: 'EXT_texture_avif',
|
|
37056
|
-
EXT_MESHOPT_COMPRESSION: 'EXT_meshopt_compression',
|
|
37057
|
-
EXT_MESH_GPU_INSTANCING: 'EXT_mesh_gpu_instancing'
|
|
37058
|
-
};
|
|
37059
|
-
class GLTFLightsExtension {
|
|
37060
|
-
constructor( parser ) {
|
|
37061
|
-
this.parser = parser;
|
|
37062
|
-
this.name = EXTENSIONS.KHR_LIGHTS_PUNCTUAL;
|
|
37063
|
-
this.cache = { refs: {}, uses: {} };
|
|
37064
|
-
}
|
|
37065
|
-
_markDefs() {
|
|
37066
|
-
const parser = this.parser;
|
|
37067
|
-
const nodeDefs = this.parser.json.nodes || [];
|
|
37068
|
-
for ( let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex ++ ) {
|
|
37069
|
-
const nodeDef = nodeDefs[ nodeIndex ];
|
|
37070
|
-
if ( nodeDef.extensions
|
|
37071
|
-
&& nodeDef.extensions[ this.name ]
|
|
37072
|
-
&& nodeDef.extensions[ this.name ].light !== undefined ) {
|
|
37073
|
-
parser._addNodeRef( this.cache, nodeDef.extensions[ this.name ].light );
|
|
37074
|
-
}
|
|
37075
|
-
}
|
|
37076
|
-
}
|
|
37077
|
-
_loadLight( lightIndex ) {
|
|
37078
|
-
const parser = this.parser;
|
|
37079
|
-
const cacheKey = 'light:' + lightIndex;
|
|
37080
|
-
let dependency = parser.cache.get( cacheKey );
|
|
37081
|
-
if ( dependency ) return dependency;
|
|
37082
|
-
const json = parser.json;
|
|
37083
|
-
const extensions = ( json.extensions && json.extensions[ this.name ] ) || {};
|
|
37084
|
-
const lightDefs = extensions.lights || [];
|
|
37085
|
-
const lightDef = lightDefs[ lightIndex ];
|
|
37086
|
-
let lightNode;
|
|
37087
|
-
const color = new Color( 0xffffff );
|
|
37088
|
-
if ( lightDef.color !== undefined ) color.setRGB( lightDef.color[ 0 ], lightDef.color[ 1 ], lightDef.color[ 2 ], LinearSRGBColorSpace );
|
|
37089
|
-
const range = lightDef.range !== undefined ? lightDef.range : 0;
|
|
37090
|
-
switch ( lightDef.type ) {
|
|
37091
|
-
case 'directional':
|
|
37092
|
-
lightNode = new DirectionalLight( color );
|
|
37093
|
-
lightNode.target.position.set( 0, 0, -1 );
|
|
37094
|
-
lightNode.add( lightNode.target );
|
|
37095
|
-
break;
|
|
37096
|
-
case 'point':
|
|
37097
|
-
lightNode = new PointLight( color );
|
|
37098
|
-
lightNode.distance = range;
|
|
37099
|
-
break;
|
|
37100
|
-
case 'spot':
|
|
37101
|
-
lightNode = new SpotLight( color );
|
|
37102
|
-
lightNode.distance = range;
|
|
37103
|
-
lightDef.spot = lightDef.spot || {};
|
|
37104
|
-
lightDef.spot.innerConeAngle = lightDef.spot.innerConeAngle !== undefined ? lightDef.spot.innerConeAngle : 0;
|
|
37105
|
-
lightDef.spot.outerConeAngle = lightDef.spot.outerConeAngle !== undefined ? lightDef.spot.outerConeAngle : Math.PI / 4.0;
|
|
37106
|
-
lightNode.angle = lightDef.spot.outerConeAngle;
|
|
37107
|
-
lightNode.penumbra = 1.0 - lightDef.spot.innerConeAngle / lightDef.spot.outerConeAngle;
|
|
37108
|
-
lightNode.target.position.set( 0, 0, -1 );
|
|
37109
|
-
lightNode.add( lightNode.target );
|
|
37110
|
-
break;
|
|
37111
|
-
default:
|
|
37112
|
-
throw new Error( 'THREE.GLTFLoader: Unexpected light type: ' + lightDef.type );
|
|
37113
|
-
}
|
|
37114
|
-
lightNode.position.set( 0, 0, 0 );
|
|
37115
|
-
assignExtrasToUserData( lightNode, lightDef );
|
|
37116
|
-
if ( lightDef.intensity !== undefined ) lightNode.intensity = lightDef.intensity;
|
|
37117
|
-
lightNode.name = parser.createUniqueName( lightDef.name || ( 'light_' + lightIndex ) );
|
|
37118
|
-
dependency = Promise.resolve( lightNode );
|
|
37119
|
-
parser.cache.add( cacheKey, dependency );
|
|
37120
|
-
return dependency;
|
|
37121
|
-
}
|
|
37122
|
-
getDependency( type, index ) {
|
|
37123
|
-
if ( type !== 'light' ) return;
|
|
37124
|
-
return this._loadLight( index );
|
|
37125
|
-
}
|
|
37126
|
-
createNodeAttachment( nodeIndex ) {
|
|
37127
|
-
const self = this;
|
|
37128
|
-
const parser = this.parser;
|
|
37129
|
-
const json = parser.json;
|
|
37130
|
-
const nodeDef = json.nodes[ nodeIndex ];
|
|
37131
|
-
const lightDef = ( nodeDef.extensions && nodeDef.extensions[ this.name ] ) || {};
|
|
37132
|
-
const lightIndex = lightDef.light;
|
|
37133
|
-
if ( lightIndex === undefined ) return null;
|
|
37134
|
-
return this._loadLight( lightIndex ).then( function ( light ) {
|
|
37135
|
-
return parser._getNodeRef( self.cache, lightIndex, light );
|
|
37136
|
-
} );
|
|
37137
|
-
}
|
|
37138
|
-
}
|
|
37139
|
-
class GLTFMaterialsUnlitExtension {
|
|
37140
|
-
constructor() {
|
|
37141
|
-
this.name = EXTENSIONS.KHR_MATERIALS_UNLIT;
|
|
37142
|
-
}
|
|
37143
|
-
getMaterialType() {
|
|
37144
|
-
return MeshBasicMaterial;
|
|
37145
|
-
}
|
|
37146
|
-
extendParams( materialParams, materialDef, parser ) {
|
|
37147
|
-
const pending = [];
|
|
37148
|
-
materialParams.color = new Color( 1.0, 1.0, 1.0 );
|
|
37149
|
-
materialParams.opacity = 1.0;
|
|
37150
|
-
const metallicRoughness = materialDef.pbrMetallicRoughness;
|
|
37151
|
-
if ( metallicRoughness ) {
|
|
37152
|
-
if ( Array.isArray( metallicRoughness.baseColorFactor ) ) {
|
|
37153
|
-
const array = metallicRoughness.baseColorFactor;
|
|
37154
|
-
materialParams.color.setRGB( array[ 0 ], array[ 1 ], array[ 2 ], LinearSRGBColorSpace );
|
|
37155
|
-
materialParams.opacity = array[ 3 ];
|
|
37156
|
-
}
|
|
37157
|
-
if ( metallicRoughness.baseColorTexture !== undefined ) {
|
|
37158
|
-
pending.push( parser.assignTexture( materialParams, 'map', metallicRoughness.baseColorTexture, SRGBColorSpace ) );
|
|
37159
|
-
}
|
|
37160
|
-
}
|
|
37161
|
-
return Promise.all( pending );
|
|
37162
|
-
}
|
|
37163
|
-
}
|
|
37164
|
-
class GLTFMaterialsEmissiveStrengthExtension {
|
|
37165
|
-
constructor( parser ) {
|
|
37166
|
-
this.parser = parser;
|
|
37167
|
-
this.name = EXTENSIONS.KHR_MATERIALS_EMISSIVE_STRENGTH;
|
|
37168
|
-
}
|
|
37169
|
-
extendMaterialParams( materialIndex, materialParams ) {
|
|
37170
|
-
const parser = this.parser;
|
|
37171
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37172
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
|
|
37173
|
-
return Promise.resolve();
|
|
37174
|
-
}
|
|
37175
|
-
const emissiveStrength = materialDef.extensions[ this.name ].emissiveStrength;
|
|
37176
|
-
if ( emissiveStrength !== undefined ) {
|
|
37177
|
-
materialParams.emissiveIntensity = emissiveStrength;
|
|
37178
|
-
}
|
|
37179
|
-
return Promise.resolve();
|
|
37180
|
-
}
|
|
37181
|
-
}
|
|
37182
|
-
class GLTFMaterialsClearcoatExtension {
|
|
37183
|
-
constructor( parser ) {
|
|
37184
|
-
this.parser = parser;
|
|
37185
|
-
this.name = EXTENSIONS.KHR_MATERIALS_CLEARCOAT;
|
|
37186
|
-
}
|
|
37187
|
-
getMaterialType( materialIndex ) {
|
|
37188
|
-
const parser = this.parser;
|
|
37189
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37190
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
|
|
37191
|
-
return MeshPhysicalMaterial;
|
|
37192
|
-
}
|
|
37193
|
-
extendMaterialParams( materialIndex, materialParams ) {
|
|
37194
|
-
const parser = this.parser;
|
|
37195
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37196
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
|
|
37197
|
-
return Promise.resolve();
|
|
37198
|
-
}
|
|
37199
|
-
const pending = [];
|
|
37200
|
-
const extension = materialDef.extensions[ this.name ];
|
|
37201
|
-
if ( extension.clearcoatFactor !== undefined ) {
|
|
37202
|
-
materialParams.clearcoat = extension.clearcoatFactor;
|
|
37203
|
-
}
|
|
37204
|
-
if ( extension.clearcoatTexture !== undefined ) {
|
|
37205
|
-
pending.push( parser.assignTexture( materialParams, 'clearcoatMap', extension.clearcoatTexture ) );
|
|
37206
|
-
}
|
|
37207
|
-
if ( extension.clearcoatRoughnessFactor !== undefined ) {
|
|
37208
|
-
materialParams.clearcoatRoughness = extension.clearcoatRoughnessFactor;
|
|
37209
|
-
}
|
|
37210
|
-
if ( extension.clearcoatRoughnessTexture !== undefined ) {
|
|
37211
|
-
pending.push( parser.assignTexture( materialParams, 'clearcoatRoughnessMap', extension.clearcoatRoughnessTexture ) );
|
|
37212
|
-
}
|
|
37213
|
-
if ( extension.clearcoatNormalTexture !== undefined ) {
|
|
37214
|
-
pending.push( parser.assignTexture( materialParams, 'clearcoatNormalMap', extension.clearcoatNormalTexture ) );
|
|
37215
|
-
if ( extension.clearcoatNormalTexture.scale !== undefined ) {
|
|
37216
|
-
const scale = extension.clearcoatNormalTexture.scale;
|
|
37217
|
-
materialParams.clearcoatNormalScale = new Vector2( scale, scale );
|
|
37218
|
-
}
|
|
37219
|
-
}
|
|
37220
|
-
return Promise.all( pending );
|
|
37221
|
-
}
|
|
37222
|
-
}
|
|
37223
|
-
class GLTFMaterialsDispersionExtension {
|
|
37224
|
-
constructor( parser ) {
|
|
37225
|
-
this.parser = parser;
|
|
37226
|
-
this.name = EXTENSIONS.KHR_MATERIALS_DISPERSION;
|
|
37227
|
-
}
|
|
37228
|
-
getMaterialType( materialIndex ) {
|
|
37229
|
-
const parser = this.parser;
|
|
37230
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37231
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
|
|
37232
|
-
return MeshPhysicalMaterial;
|
|
37233
|
-
}
|
|
37234
|
-
extendMaterialParams( materialIndex, materialParams ) {
|
|
37235
|
-
const parser = this.parser;
|
|
37236
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37237
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
|
|
37238
|
-
return Promise.resolve();
|
|
37239
|
-
}
|
|
37240
|
-
const extension = materialDef.extensions[ this.name ];
|
|
37241
|
-
materialParams.dispersion = extension.dispersion !== undefined ? extension.dispersion : 0;
|
|
37242
|
-
return Promise.resolve();
|
|
37243
|
-
}
|
|
37244
|
-
}
|
|
37245
|
-
class GLTFMaterialsIridescenceExtension {
|
|
37246
|
-
constructor( parser ) {
|
|
37247
|
-
this.parser = parser;
|
|
37248
|
-
this.name = EXTENSIONS.KHR_MATERIALS_IRIDESCENCE;
|
|
37249
|
-
}
|
|
37250
|
-
getMaterialType( materialIndex ) {
|
|
37251
|
-
const parser = this.parser;
|
|
37252
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37253
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
|
|
37254
|
-
return MeshPhysicalMaterial;
|
|
37255
|
-
}
|
|
37256
|
-
extendMaterialParams( materialIndex, materialParams ) {
|
|
37257
|
-
const parser = this.parser;
|
|
37258
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37259
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
|
|
37260
|
-
return Promise.resolve();
|
|
37261
|
-
}
|
|
37262
|
-
const pending = [];
|
|
37263
|
-
const extension = materialDef.extensions[ this.name ];
|
|
37264
|
-
if ( extension.iridescenceFactor !== undefined ) {
|
|
37265
|
-
materialParams.iridescence = extension.iridescenceFactor;
|
|
37266
|
-
}
|
|
37267
|
-
if ( extension.iridescenceTexture !== undefined ) {
|
|
37268
|
-
pending.push( parser.assignTexture( materialParams, 'iridescenceMap', extension.iridescenceTexture ) );
|
|
37269
|
-
}
|
|
37270
|
-
if ( extension.iridescenceIor !== undefined ) {
|
|
37271
|
-
materialParams.iridescenceIOR = extension.iridescenceIor;
|
|
37272
|
-
}
|
|
37273
|
-
if ( materialParams.iridescenceThicknessRange === undefined ) {
|
|
37274
|
-
materialParams.iridescenceThicknessRange = [ 100, 400 ];
|
|
37275
|
-
}
|
|
37276
|
-
if ( extension.iridescenceThicknessMinimum !== undefined ) {
|
|
37277
|
-
materialParams.iridescenceThicknessRange[ 0 ] = extension.iridescenceThicknessMinimum;
|
|
37278
|
-
}
|
|
37279
|
-
if ( extension.iridescenceThicknessMaximum !== undefined ) {
|
|
37280
|
-
materialParams.iridescenceThicknessRange[ 1 ] = extension.iridescenceThicknessMaximum;
|
|
37281
|
-
}
|
|
37282
|
-
if ( extension.iridescenceThicknessTexture !== undefined ) {
|
|
37283
|
-
pending.push( parser.assignTexture( materialParams, 'iridescenceThicknessMap', extension.iridescenceThicknessTexture ) );
|
|
37284
|
-
}
|
|
37285
|
-
return Promise.all( pending );
|
|
37286
|
-
}
|
|
37287
|
-
}
|
|
37288
|
-
class GLTFMaterialsSheenExtension {
|
|
37289
|
-
constructor( parser ) {
|
|
37290
|
-
this.parser = parser;
|
|
37291
|
-
this.name = EXTENSIONS.KHR_MATERIALS_SHEEN;
|
|
37292
|
-
}
|
|
37293
|
-
getMaterialType( materialIndex ) {
|
|
37294
|
-
const parser = this.parser;
|
|
37295
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37296
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
|
|
37297
|
-
return MeshPhysicalMaterial;
|
|
37298
|
-
}
|
|
37299
|
-
extendMaterialParams( materialIndex, materialParams ) {
|
|
37300
|
-
const parser = this.parser;
|
|
37301
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37302
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
|
|
37303
|
-
return Promise.resolve();
|
|
37304
|
-
}
|
|
37305
|
-
const pending = [];
|
|
37306
|
-
materialParams.sheenColor = new Color( 0, 0, 0 );
|
|
37307
|
-
materialParams.sheenRoughness = 0;
|
|
37308
|
-
materialParams.sheen = 1;
|
|
37309
|
-
const extension = materialDef.extensions[ this.name ];
|
|
37310
|
-
if ( extension.sheenColorFactor !== undefined ) {
|
|
37311
|
-
const colorFactor = extension.sheenColorFactor;
|
|
37312
|
-
materialParams.sheenColor.setRGB( colorFactor[ 0 ], colorFactor[ 1 ], colorFactor[ 2 ], LinearSRGBColorSpace );
|
|
37313
|
-
}
|
|
37314
|
-
if ( extension.sheenRoughnessFactor !== undefined ) {
|
|
37315
|
-
materialParams.sheenRoughness = extension.sheenRoughnessFactor;
|
|
37316
|
-
}
|
|
37317
|
-
if ( extension.sheenColorTexture !== undefined ) {
|
|
37318
|
-
pending.push( parser.assignTexture( materialParams, 'sheenColorMap', extension.sheenColorTexture, SRGBColorSpace ) );
|
|
37319
|
-
}
|
|
37320
|
-
if ( extension.sheenRoughnessTexture !== undefined ) {
|
|
37321
|
-
pending.push( parser.assignTexture( materialParams, 'sheenRoughnessMap', extension.sheenRoughnessTexture ) );
|
|
37322
|
-
}
|
|
37323
|
-
return Promise.all( pending );
|
|
37324
|
-
}
|
|
37325
|
-
}
|
|
37326
|
-
class GLTFMaterialsTransmissionExtension {
|
|
37327
|
-
constructor( parser ) {
|
|
37328
|
-
this.parser = parser;
|
|
37329
|
-
this.name = EXTENSIONS.KHR_MATERIALS_TRANSMISSION;
|
|
37330
|
-
}
|
|
37331
|
-
getMaterialType( materialIndex ) {
|
|
37332
|
-
const parser = this.parser;
|
|
37333
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37334
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
|
|
37335
|
-
return MeshPhysicalMaterial;
|
|
37336
|
-
}
|
|
37337
|
-
extendMaterialParams( materialIndex, materialParams ) {
|
|
37338
|
-
const parser = this.parser;
|
|
37339
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37340
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
|
|
37341
|
-
return Promise.resolve();
|
|
37342
|
-
}
|
|
37343
|
-
const pending = [];
|
|
37344
|
-
const extension = materialDef.extensions[ this.name ];
|
|
37345
|
-
if ( extension.transmissionFactor !== undefined ) {
|
|
37346
|
-
materialParams.transmission = extension.transmissionFactor;
|
|
37347
|
-
}
|
|
37348
|
-
if ( extension.transmissionTexture !== undefined ) {
|
|
37349
|
-
pending.push( parser.assignTexture( materialParams, 'transmissionMap', extension.transmissionTexture ) );
|
|
37350
|
-
}
|
|
37351
|
-
return Promise.all( pending );
|
|
37352
|
-
}
|
|
37353
|
-
}
|
|
37354
|
-
class GLTFMaterialsVolumeExtension {
|
|
37355
|
-
constructor( parser ) {
|
|
37356
|
-
this.parser = parser;
|
|
37357
|
-
this.name = EXTENSIONS.KHR_MATERIALS_VOLUME;
|
|
37358
|
-
}
|
|
37359
|
-
getMaterialType( materialIndex ) {
|
|
37360
|
-
const parser = this.parser;
|
|
37361
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37362
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
|
|
37363
|
-
return MeshPhysicalMaterial;
|
|
37364
|
-
}
|
|
37365
|
-
extendMaterialParams( materialIndex, materialParams ) {
|
|
37366
|
-
const parser = this.parser;
|
|
37367
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37368
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
|
|
37369
|
-
return Promise.resolve();
|
|
37370
|
-
}
|
|
37371
|
-
const pending = [];
|
|
37372
|
-
const extension = materialDef.extensions[ this.name ];
|
|
37373
|
-
materialParams.thickness = extension.thicknessFactor !== undefined ? extension.thicknessFactor : 0;
|
|
37374
|
-
if ( extension.thicknessTexture !== undefined ) {
|
|
37375
|
-
pending.push( parser.assignTexture( materialParams, 'thicknessMap', extension.thicknessTexture ) );
|
|
37376
|
-
}
|
|
37377
|
-
materialParams.attenuationDistance = extension.attenuationDistance || Infinity;
|
|
37378
|
-
const colorArray = extension.attenuationColor || [ 1, 1, 1 ];
|
|
37379
|
-
materialParams.attenuationColor = new Color().setRGB( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ], LinearSRGBColorSpace );
|
|
37380
|
-
return Promise.all( pending );
|
|
37381
|
-
}
|
|
37382
|
-
}
|
|
37383
|
-
class GLTFMaterialsIorExtension {
|
|
37384
|
-
constructor( parser ) {
|
|
37385
|
-
this.parser = parser;
|
|
37386
|
-
this.name = EXTENSIONS.KHR_MATERIALS_IOR;
|
|
37387
|
-
}
|
|
37388
|
-
getMaterialType( materialIndex ) {
|
|
37389
|
-
const parser = this.parser;
|
|
37390
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37391
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
|
|
37392
|
-
return MeshPhysicalMaterial;
|
|
37393
|
-
}
|
|
37394
|
-
extendMaterialParams( materialIndex, materialParams ) {
|
|
37395
|
-
const parser = this.parser;
|
|
37396
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37397
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
|
|
37398
|
-
return Promise.resolve();
|
|
37399
|
-
}
|
|
37400
|
-
const extension = materialDef.extensions[ this.name ];
|
|
37401
|
-
materialParams.ior = extension.ior !== undefined ? extension.ior : 1.5;
|
|
37402
|
-
return Promise.resolve();
|
|
37403
|
-
}
|
|
37404
|
-
}
|
|
37405
|
-
class GLTFMaterialsSpecularExtension {
|
|
37406
|
-
constructor( parser ) {
|
|
37407
|
-
this.parser = parser;
|
|
37408
|
-
this.name = EXTENSIONS.KHR_MATERIALS_SPECULAR;
|
|
37409
|
-
}
|
|
37410
|
-
getMaterialType( materialIndex ) {
|
|
37411
|
-
const parser = this.parser;
|
|
37412
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37413
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
|
|
37414
|
-
return MeshPhysicalMaterial;
|
|
37415
|
-
}
|
|
37416
|
-
extendMaterialParams( materialIndex, materialParams ) {
|
|
37417
|
-
const parser = this.parser;
|
|
37418
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37419
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
|
|
37420
|
-
return Promise.resolve();
|
|
37421
|
-
}
|
|
37422
|
-
const pending = [];
|
|
37423
|
-
const extension = materialDef.extensions[ this.name ];
|
|
37424
|
-
materialParams.specularIntensity = extension.specularFactor !== undefined ? extension.specularFactor : 1.0;
|
|
37425
|
-
if ( extension.specularTexture !== undefined ) {
|
|
37426
|
-
pending.push( parser.assignTexture( materialParams, 'specularIntensityMap', extension.specularTexture ) );
|
|
37427
|
-
}
|
|
37428
|
-
const colorArray = extension.specularColorFactor || [ 1, 1, 1 ];
|
|
37429
|
-
materialParams.specularColor = new Color().setRGB( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ], LinearSRGBColorSpace );
|
|
37430
|
-
if ( extension.specularColorTexture !== undefined ) {
|
|
37431
|
-
pending.push( parser.assignTexture( materialParams, 'specularColorMap', extension.specularColorTexture, SRGBColorSpace ) );
|
|
37432
|
-
}
|
|
37433
|
-
return Promise.all( pending );
|
|
37434
|
-
}
|
|
37435
|
-
}
|
|
37436
|
-
class GLTFMaterialsBumpExtension {
|
|
37437
|
-
constructor( parser ) {
|
|
37438
|
-
this.parser = parser;
|
|
37439
|
-
this.name = EXTENSIONS.EXT_MATERIALS_BUMP;
|
|
37440
|
-
}
|
|
37441
|
-
getMaterialType( materialIndex ) {
|
|
37442
|
-
const parser = this.parser;
|
|
37443
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37444
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
|
|
37445
|
-
return MeshPhysicalMaterial;
|
|
37446
|
-
}
|
|
37447
|
-
extendMaterialParams( materialIndex, materialParams ) {
|
|
37448
|
-
const parser = this.parser;
|
|
37449
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37450
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
|
|
37451
|
-
return Promise.resolve();
|
|
37452
|
-
}
|
|
37453
|
-
const pending = [];
|
|
37454
|
-
const extension = materialDef.extensions[ this.name ];
|
|
37455
|
-
materialParams.bumpScale = extension.bumpFactor !== undefined ? extension.bumpFactor : 1.0;
|
|
37456
|
-
if ( extension.bumpTexture !== undefined ) {
|
|
37457
|
-
pending.push( parser.assignTexture( materialParams, 'bumpMap', extension.bumpTexture ) );
|
|
37458
|
-
}
|
|
37459
|
-
return Promise.all( pending );
|
|
37460
|
-
}
|
|
37461
|
-
}
|
|
37462
|
-
class GLTFMaterialsAnisotropyExtension {
|
|
37463
|
-
constructor( parser ) {
|
|
37464
|
-
this.parser = parser;
|
|
37465
|
-
this.name = EXTENSIONS.KHR_MATERIALS_ANISOTROPY;
|
|
37466
|
-
}
|
|
37467
|
-
getMaterialType( materialIndex ) {
|
|
37468
|
-
const parser = this.parser;
|
|
37469
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37470
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
|
|
37471
|
-
return MeshPhysicalMaterial;
|
|
37472
|
-
}
|
|
37473
|
-
extendMaterialParams( materialIndex, materialParams ) {
|
|
37474
|
-
const parser = this.parser;
|
|
37475
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37476
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
|
|
37477
|
-
return Promise.resolve();
|
|
37478
|
-
}
|
|
37479
|
-
const pending = [];
|
|
37480
|
-
const extension = materialDef.extensions[ this.name ];
|
|
37481
|
-
if ( extension.anisotropyStrength !== undefined ) {
|
|
37482
|
-
materialParams.anisotropy = extension.anisotropyStrength;
|
|
37483
|
-
}
|
|
37484
|
-
if ( extension.anisotropyRotation !== undefined ) {
|
|
37485
|
-
materialParams.anisotropyRotation = extension.anisotropyRotation;
|
|
37486
|
-
}
|
|
37487
|
-
if ( extension.anisotropyTexture !== undefined ) {
|
|
37488
|
-
pending.push( parser.assignTexture( materialParams, 'anisotropyMap', extension.anisotropyTexture ) );
|
|
37489
|
-
}
|
|
37490
|
-
return Promise.all( pending );
|
|
37491
|
-
}
|
|
37492
|
-
}
|
|
37493
|
-
class GLTFTextureBasisUExtension {
|
|
37494
|
-
constructor( parser ) {
|
|
37495
|
-
this.parser = parser;
|
|
37496
|
-
this.name = EXTENSIONS.KHR_TEXTURE_BASISU;
|
|
37497
|
-
}
|
|
37498
|
-
loadTexture( textureIndex ) {
|
|
37499
|
-
const parser = this.parser;
|
|
37500
|
-
const json = parser.json;
|
|
37501
|
-
const textureDef = json.textures[ textureIndex ];
|
|
37502
|
-
if ( ! textureDef.extensions || ! textureDef.extensions[ this.name ] ) {
|
|
37503
|
-
return null;
|
|
37504
|
-
}
|
|
37505
|
-
const extension = textureDef.extensions[ this.name ];
|
|
37506
|
-
const loader = parser.options.ktx2Loader;
|
|
37507
|
-
if ( ! loader ) {
|
|
37508
|
-
if ( json.extensionsRequired && json.extensionsRequired.indexOf( this.name ) >= 0 ) {
|
|
37509
|
-
throw new Error( 'THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures' );
|
|
37510
|
-
} else {
|
|
37511
|
-
return null;
|
|
37512
|
-
}
|
|
37513
|
-
}
|
|
37514
|
-
return parser.loadTextureImage( textureIndex, extension.source, loader );
|
|
37515
|
-
}
|
|
37516
|
-
}
|
|
37517
|
-
class GLTFTextureWebPExtension {
|
|
37518
|
-
constructor( parser ) {
|
|
37519
|
-
this.parser = parser;
|
|
37520
|
-
this.name = EXTENSIONS.EXT_TEXTURE_WEBP;
|
|
37521
|
-
}
|
|
37522
|
-
loadTexture( textureIndex ) {
|
|
37523
|
-
const name = this.name;
|
|
37524
|
-
const parser = this.parser;
|
|
37525
|
-
const json = parser.json;
|
|
37526
|
-
const textureDef = json.textures[ textureIndex ];
|
|
37527
|
-
if ( ! textureDef.extensions || ! textureDef.extensions[ name ] ) {
|
|
37528
|
-
return null;
|
|
37529
|
-
}
|
|
37530
|
-
const extension = textureDef.extensions[ name ];
|
|
37531
|
-
const source = json.images[ extension.source ];
|
|
37532
|
-
let loader = parser.textureLoader;
|
|
37533
|
-
if ( source.uri ) {
|
|
37534
|
-
const handler = parser.options.manager.getHandler( source.uri );
|
|
37535
|
-
if ( handler !== null ) loader = handler;
|
|
37536
|
-
}
|
|
37537
|
-
return parser.loadTextureImage( textureIndex, extension.source, loader );
|
|
37538
|
-
}
|
|
37539
|
-
}
|
|
37540
|
-
class GLTFTextureAVIFExtension {
|
|
37541
|
-
constructor( parser ) {
|
|
37542
|
-
this.parser = parser;
|
|
37543
|
-
this.name = EXTENSIONS.EXT_TEXTURE_AVIF;
|
|
37544
|
-
}
|
|
37545
|
-
loadTexture( textureIndex ) {
|
|
37546
|
-
const name = this.name;
|
|
37547
|
-
const parser = this.parser;
|
|
37548
|
-
const json = parser.json;
|
|
37549
|
-
const textureDef = json.textures[ textureIndex ];
|
|
37550
|
-
if ( ! textureDef.extensions || ! textureDef.extensions[ name ] ) {
|
|
37551
|
-
return null;
|
|
37552
|
-
}
|
|
37553
|
-
const extension = textureDef.extensions[ name ];
|
|
37554
|
-
const source = json.images[ extension.source ];
|
|
37555
|
-
let loader = parser.textureLoader;
|
|
37556
|
-
if ( source.uri ) {
|
|
37557
|
-
const handler = parser.options.manager.getHandler( source.uri );
|
|
37558
|
-
if ( handler !== null ) loader = handler;
|
|
37559
|
-
}
|
|
37560
|
-
return parser.loadTextureImage( textureIndex, extension.source, loader );
|
|
37561
|
-
}
|
|
37562
|
-
}
|
|
37563
|
-
class GLTFMeshoptCompression {
|
|
37564
|
-
constructor( parser ) {
|
|
37565
|
-
this.name = EXTENSIONS.EXT_MESHOPT_COMPRESSION;
|
|
37566
|
-
this.parser = parser;
|
|
37567
|
-
}
|
|
37568
|
-
loadBufferView( index ) {
|
|
37569
|
-
const json = this.parser.json;
|
|
37570
|
-
const bufferView = json.bufferViews[ index ];
|
|
37571
|
-
if ( bufferView.extensions && bufferView.extensions[ this.name ] ) {
|
|
37572
|
-
const extensionDef = bufferView.extensions[ this.name ];
|
|
37573
|
-
const buffer = this.parser.getDependency( 'buffer', extensionDef.buffer );
|
|
37574
|
-
const decoder = this.parser.options.meshoptDecoder;
|
|
37575
|
-
if ( ! decoder || ! decoder.supported ) {
|
|
37576
|
-
if ( json.extensionsRequired && json.extensionsRequired.indexOf( this.name ) >= 0 ) {
|
|
37577
|
-
throw new Error( 'THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files' );
|
|
37578
|
-
} else {
|
|
37579
|
-
return null;
|
|
37580
|
-
}
|
|
37581
|
-
}
|
|
37582
|
-
return buffer.then( function ( res ) {
|
|
37583
|
-
const byteOffset = extensionDef.byteOffset || 0;
|
|
37584
|
-
const byteLength = extensionDef.byteLength || 0;
|
|
37585
|
-
const count = extensionDef.count;
|
|
37586
|
-
const stride = extensionDef.byteStride;
|
|
37587
|
-
const source = new Uint8Array( res, byteOffset, byteLength );
|
|
37588
|
-
if ( decoder.decodeGltfBufferAsync ) {
|
|
37589
|
-
return decoder.decodeGltfBufferAsync( count, stride, source, extensionDef.mode, extensionDef.filter ).then( function ( res ) {
|
|
37590
|
-
return res.buffer;
|
|
37591
|
-
} );
|
|
37592
|
-
} else {
|
|
37593
|
-
return decoder.ready.then( function () {
|
|
37594
|
-
const result = new ArrayBuffer( count * stride );
|
|
37595
|
-
decoder.decodeGltfBuffer( new Uint8Array( result ), count, stride, source, extensionDef.mode, extensionDef.filter );
|
|
37596
|
-
return result;
|
|
37597
|
-
} );
|
|
37598
|
-
}
|
|
37599
|
-
} );
|
|
37600
|
-
} else {
|
|
37601
|
-
return null;
|
|
37602
|
-
}
|
|
37603
|
-
}
|
|
37604
|
-
}
|
|
37605
|
-
class GLTFMeshGpuInstancing {
|
|
37606
|
-
constructor( parser ) {
|
|
37607
|
-
this.name = EXTENSIONS.EXT_MESH_GPU_INSTANCING;
|
|
37608
|
-
this.parser = parser;
|
|
37609
|
-
}
|
|
37610
|
-
createNodeMesh( nodeIndex ) {
|
|
37611
|
-
const json = this.parser.json;
|
|
37612
|
-
const nodeDef = json.nodes[ nodeIndex ];
|
|
37613
|
-
if ( ! nodeDef.extensions || ! nodeDef.extensions[ this.name ] ||
|
|
37614
|
-
nodeDef.mesh === undefined ) {
|
|
37615
|
-
return null;
|
|
37616
|
-
}
|
|
37617
|
-
const meshDef = json.meshes[ nodeDef.mesh ];
|
|
37618
|
-
for ( const primitive of meshDef.primitives ) {
|
|
37619
|
-
if ( primitive.mode !== WEBGL_CONSTANTS.TRIANGLES &&
|
|
37620
|
-
primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_STRIP &&
|
|
37621
|
-
primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_FAN &&
|
|
37622
|
-
primitive.mode !== undefined ) {
|
|
37623
|
-
return null;
|
|
37624
|
-
}
|
|
37625
|
-
}
|
|
37626
|
-
const extensionDef = nodeDef.extensions[ this.name ];
|
|
37627
|
-
const attributesDef = extensionDef.attributes;
|
|
37628
|
-
const pending = [];
|
|
37629
|
-
const attributes = {};
|
|
37630
|
-
for ( const key in attributesDef ) {
|
|
37631
|
-
pending.push( this.parser.getDependency( 'accessor', attributesDef[ key ] ).then( accessor => {
|
|
37632
|
-
attributes[ key ] = accessor;
|
|
37633
|
-
return attributes[ key ];
|
|
37634
|
-
} ) );
|
|
37635
|
-
}
|
|
37636
|
-
if ( pending.length < 1 ) {
|
|
37637
|
-
return null;
|
|
37638
|
-
}
|
|
37639
|
-
pending.push( this.parser.createNodeMesh( nodeIndex ) );
|
|
37640
|
-
return Promise.all( pending ).then( results => {
|
|
37641
|
-
const nodeObject = results.pop();
|
|
37642
|
-
const meshes = nodeObject.isGroup ? nodeObject.children : [ nodeObject ];
|
|
37643
|
-
const count = results[ 0 ].count;
|
|
37644
|
-
const instancedMeshes = [];
|
|
37645
|
-
for ( const mesh of meshes ) {
|
|
37646
|
-
const m = new Matrix4();
|
|
37647
|
-
const p = new Vector3();
|
|
37648
|
-
const q = new Quaternion();
|
|
37649
|
-
const s = new Vector3( 1, 1, 1 );
|
|
37650
|
-
const instancedMesh = new InstancedMesh( mesh.geometry, mesh.material, count );
|
|
37651
|
-
for ( let i = 0; i < count; i ++ ) {
|
|
37652
|
-
if ( attributes.TRANSLATION ) {
|
|
37653
|
-
p.fromBufferAttribute( attributes.TRANSLATION, i );
|
|
37654
|
-
}
|
|
37655
|
-
if ( attributes.ROTATION ) {
|
|
37656
|
-
q.fromBufferAttribute( attributes.ROTATION, i );
|
|
37657
|
-
}
|
|
37658
|
-
if ( attributes.SCALE ) {
|
|
37659
|
-
s.fromBufferAttribute( attributes.SCALE, i );
|
|
37660
|
-
}
|
|
37661
|
-
instancedMesh.setMatrixAt( i, m.compose( p, q, s ) );
|
|
37662
|
-
}
|
|
37663
|
-
for ( const attributeName in attributes ) {
|
|
37664
|
-
if ( attributeName === '_COLOR_0' ) {
|
|
37665
|
-
const attr = attributes[ attributeName ];
|
|
37666
|
-
instancedMesh.instanceColor = new InstancedBufferAttribute( attr.array, attr.itemSize, attr.normalized );
|
|
37667
|
-
} else if ( attributeName !== 'TRANSLATION' &&
|
|
37668
|
-
attributeName !== 'ROTATION' &&
|
|
37669
|
-
attributeName !== 'SCALE' ) {
|
|
37670
|
-
mesh.geometry.setAttribute( attributeName, attributes[ attributeName ] );
|
|
37671
|
-
}
|
|
37672
|
-
}
|
|
37673
|
-
Object3D.prototype.copy.call( instancedMesh, mesh );
|
|
37674
|
-
this.parser.assignFinalMaterial( instancedMesh );
|
|
37675
|
-
instancedMeshes.push( instancedMesh );
|
|
37676
|
-
}
|
|
37677
|
-
if ( nodeObject.isGroup ) {
|
|
37678
|
-
nodeObject.clear();
|
|
37679
|
-
nodeObject.add( ... instancedMeshes );
|
|
37680
|
-
return nodeObject;
|
|
37681
|
-
}
|
|
37682
|
-
return instancedMeshes[ 0 ];
|
|
37683
|
-
} );
|
|
37684
|
-
}
|
|
37685
|
-
}
|
|
37686
|
-
const BINARY_EXTENSION_HEADER_MAGIC = 'glTF';
|
|
37687
|
-
const BINARY_EXTENSION_HEADER_LENGTH = 12;
|
|
37688
|
-
const BINARY_EXTENSION_CHUNK_TYPES = { JSON: 0x4E4F534A, BIN: 0x004E4942 };
|
|
37689
|
-
class GLTFBinaryExtension {
|
|
37690
|
-
constructor( data ) {
|
|
37691
|
-
this.name = EXTENSIONS.KHR_BINARY_GLTF;
|
|
37692
|
-
this.content = null;
|
|
37693
|
-
this.body = null;
|
|
37694
|
-
const headerView = new DataView( data, 0, BINARY_EXTENSION_HEADER_LENGTH );
|
|
37695
|
-
const textDecoder = new TextDecoder();
|
|
37696
|
-
this.header = {
|
|
37697
|
-
magic: textDecoder.decode( new Uint8Array( data.slice( 0, 4 ) ) ),
|
|
37698
|
-
version: headerView.getUint32( 4, true ),
|
|
37699
|
-
length: headerView.getUint32( 8, true )
|
|
37700
|
-
};
|
|
37701
|
-
if ( this.header.magic !== BINARY_EXTENSION_HEADER_MAGIC ) {
|
|
37702
|
-
throw new Error( 'THREE.GLTFLoader: Unsupported glTF-Binary header.' );
|
|
37703
|
-
} else if ( this.header.version < 2.0 ) {
|
|
37704
|
-
throw new Error( 'THREE.GLTFLoader: Legacy binary file detected.' );
|
|
37705
|
-
}
|
|
37706
|
-
const chunkContentsLength = this.header.length - BINARY_EXTENSION_HEADER_LENGTH;
|
|
37707
|
-
const chunkView = new DataView( data, BINARY_EXTENSION_HEADER_LENGTH );
|
|
37708
|
-
let chunkIndex = 0;
|
|
37709
|
-
while ( chunkIndex < chunkContentsLength ) {
|
|
37710
|
-
const chunkLength = chunkView.getUint32( chunkIndex, true );
|
|
37711
|
-
chunkIndex += 4;
|
|
37712
|
-
const chunkType = chunkView.getUint32( chunkIndex, true );
|
|
37713
|
-
chunkIndex += 4;
|
|
37714
|
-
if ( chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON ) {
|
|
37715
|
-
const contentArray = new Uint8Array( data, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength );
|
|
37716
|
-
this.content = textDecoder.decode( contentArray );
|
|
37717
|
-
} else if ( chunkType === BINARY_EXTENSION_CHUNK_TYPES.BIN ) {
|
|
37718
|
-
const byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex;
|
|
37719
|
-
this.body = data.slice( byteOffset, byteOffset + chunkLength );
|
|
37720
|
-
}
|
|
37721
|
-
chunkIndex += chunkLength;
|
|
37722
|
-
}
|
|
37723
|
-
if ( this.content === null ) {
|
|
37724
|
-
throw new Error( 'THREE.GLTFLoader: JSON content not found.' );
|
|
37725
|
-
}
|
|
37726
|
-
}
|
|
37727
|
-
}
|
|
37728
|
-
class GLTFDracoMeshCompressionExtension {
|
|
37729
|
-
constructor( json, dracoLoader ) {
|
|
37730
|
-
if ( ! dracoLoader ) {
|
|
37731
|
-
throw new Error( 'THREE.GLTFLoader: No DRACOLoader instance provided.' );
|
|
37732
|
-
}
|
|
37733
|
-
this.name = EXTENSIONS.KHR_DRACO_MESH_COMPRESSION;
|
|
37734
|
-
this.json = json;
|
|
37735
|
-
this.dracoLoader = dracoLoader;
|
|
37736
|
-
this.dracoLoader.preload();
|
|
37737
|
-
}
|
|
37738
|
-
decodePrimitive( primitive, parser ) {
|
|
37739
|
-
const json = this.json;
|
|
37740
|
-
const dracoLoader = this.dracoLoader;
|
|
37741
|
-
const bufferViewIndex = primitive.extensions[ this.name ].bufferView;
|
|
37742
|
-
const gltfAttributeMap = primitive.extensions[ this.name ].attributes;
|
|
37743
|
-
const threeAttributeMap = {};
|
|
37744
|
-
const attributeNormalizedMap = {};
|
|
37745
|
-
const attributeTypeMap = {};
|
|
37746
|
-
for ( const attributeName in gltfAttributeMap ) {
|
|
37747
|
-
const threeAttributeName = ATTRIBUTES[ attributeName ] || attributeName.toLowerCase();
|
|
37748
|
-
threeAttributeMap[ threeAttributeName ] = gltfAttributeMap[ attributeName ];
|
|
37749
|
-
}
|
|
37750
|
-
for ( const attributeName in primitive.attributes ) {
|
|
37751
|
-
const threeAttributeName = ATTRIBUTES[ attributeName ] || attributeName.toLowerCase();
|
|
37752
|
-
if ( gltfAttributeMap[ attributeName ] !== undefined ) {
|
|
37753
|
-
const accessorDef = json.accessors[ primitive.attributes[ attributeName ] ];
|
|
37754
|
-
const componentType = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ];
|
|
37755
|
-
attributeTypeMap[ threeAttributeName ] = componentType.name;
|
|
37756
|
-
attributeNormalizedMap[ threeAttributeName ] = accessorDef.normalized === true;
|
|
37757
|
-
}
|
|
37758
|
-
}
|
|
37759
|
-
return parser.getDependency( 'bufferView', bufferViewIndex ).then( function ( bufferView ) {
|
|
37760
|
-
return new Promise( function ( resolve, reject ) {
|
|
37761
|
-
dracoLoader.decodeDracoFile( bufferView, function ( geometry ) {
|
|
37762
|
-
for ( const attributeName in geometry.attributes ) {
|
|
37763
|
-
const attribute = geometry.attributes[ attributeName ];
|
|
37764
|
-
const normalized = attributeNormalizedMap[ attributeName ];
|
|
37765
|
-
if ( normalized !== undefined ) attribute.normalized = normalized;
|
|
37766
|
-
}
|
|
37767
|
-
resolve( geometry );
|
|
37768
|
-
}, threeAttributeMap, attributeTypeMap, LinearSRGBColorSpace, reject );
|
|
37769
|
-
} );
|
|
37770
|
-
} );
|
|
37771
|
-
}
|
|
37772
|
-
}
|
|
37773
|
-
class GLTFTextureTransformExtension {
|
|
37774
|
-
constructor() {
|
|
37775
|
-
this.name = EXTENSIONS.KHR_TEXTURE_TRANSFORM;
|
|
37776
|
-
}
|
|
37777
|
-
extendTexture( texture, transform ) {
|
|
37778
|
-
if ( ( transform.texCoord === undefined || transform.texCoord === texture.channel )
|
|
37779
|
-
&& transform.offset === undefined
|
|
37780
|
-
&& transform.rotation === undefined
|
|
37781
|
-
&& transform.scale === undefined ) {
|
|
37782
|
-
return texture;
|
|
37783
|
-
}
|
|
37784
|
-
texture = texture.clone();
|
|
37785
|
-
if ( transform.texCoord !== undefined ) {
|
|
37786
|
-
texture.channel = transform.texCoord;
|
|
37787
|
-
}
|
|
37788
|
-
if ( transform.offset !== undefined ) {
|
|
37789
|
-
texture.offset.fromArray( transform.offset );
|
|
37790
|
-
}
|
|
37791
|
-
if ( transform.rotation !== undefined ) {
|
|
37792
|
-
texture.rotation = transform.rotation;
|
|
37793
|
-
}
|
|
37794
|
-
if ( transform.scale !== undefined ) {
|
|
37795
|
-
texture.repeat.fromArray( transform.scale );
|
|
37796
|
-
}
|
|
37797
|
-
texture.needsUpdate = true;
|
|
37798
|
-
return texture;
|
|
37799
|
-
}
|
|
37800
|
-
}
|
|
37801
|
-
class GLTFMeshQuantizationExtension {
|
|
37802
|
-
constructor() {
|
|
37803
|
-
this.name = EXTENSIONS.KHR_MESH_QUANTIZATION;
|
|
37804
|
-
}
|
|
37805
|
-
}
|
|
37806
|
-
class GLTFCubicSplineInterpolant extends Interpolant {
|
|
37807
|
-
constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
|
|
37808
|
-
super( parameterPositions, sampleValues, sampleSize, resultBuffer );
|
|
37809
|
-
}
|
|
37810
|
-
copySampleValue_( index ) {
|
|
37811
|
-
const result = this.resultBuffer,
|
|
37812
|
-
values = this.sampleValues,
|
|
37813
|
-
valueSize = this.valueSize,
|
|
37814
|
-
offset = index * valueSize * 3 + valueSize;
|
|
37815
|
-
for ( let i = 0; i !== valueSize; i ++ ) {
|
|
37816
|
-
result[ i ] = values[ offset + i ];
|
|
37817
|
-
}
|
|
37818
|
-
return result;
|
|
37819
|
-
}
|
|
37820
|
-
interpolate_( i1, t0, t, t1 ) {
|
|
37821
|
-
const result = this.resultBuffer;
|
|
37822
|
-
const values = this.sampleValues;
|
|
37823
|
-
const stride = this.valueSize;
|
|
37824
|
-
const stride2 = stride * 2;
|
|
37825
|
-
const stride3 = stride * 3;
|
|
37826
|
-
const td = t1 - t0;
|
|
37827
|
-
const p = ( t - t0 ) / td;
|
|
37828
|
-
const pp = p * p;
|
|
37829
|
-
const ppp = pp * p;
|
|
37830
|
-
const offset1 = i1 * stride3;
|
|
37831
|
-
const offset0 = offset1 - stride3;
|
|
37832
|
-
const s2 = -2 * ppp + 3 * pp;
|
|
37833
|
-
const s3 = ppp - pp;
|
|
37834
|
-
const s0 = 1 - s2;
|
|
37835
|
-
const s1 = s3 - pp + p;
|
|
37836
|
-
for ( let i = 0; i !== stride; i ++ ) {
|
|
37837
|
-
const p0 = values[ offset0 + i + stride ];
|
|
37838
|
-
const m0 = values[ offset0 + i + stride2 ] * td;
|
|
37839
|
-
const p1 = values[ offset1 + i + stride ];
|
|
37840
|
-
const m1 = values[ offset1 + i ] * td;
|
|
37841
|
-
result[ i ] = s0 * p0 + s1 * m0 + s2 * p1 + s3 * m1;
|
|
37842
|
-
}
|
|
37843
|
-
return result;
|
|
37844
|
-
}
|
|
37845
|
-
}
|
|
37846
|
-
const _quaternion = new Quaternion();
|
|
37847
|
-
class GLTFCubicSplineQuaternionInterpolant extends GLTFCubicSplineInterpolant {
|
|
37848
|
-
interpolate_( i1, t0, t, t1 ) {
|
|
37849
|
-
const result = super.interpolate_( i1, t0, t, t1 );
|
|
37850
|
-
_quaternion.fromArray( result ).normalize().toArray( result );
|
|
37851
|
-
return result;
|
|
37852
|
-
}
|
|
37853
|
-
}
|
|
37854
|
-
const WEBGL_CONSTANTS = {
|
|
37855
|
-
POINTS: 0,
|
|
37856
|
-
LINES: 1,
|
|
37857
|
-
LINE_LOOP: 2,
|
|
37858
|
-
LINE_STRIP: 3,
|
|
37859
|
-
TRIANGLES: 4,
|
|
37860
|
-
TRIANGLE_STRIP: 5,
|
|
37861
|
-
TRIANGLE_FAN: 6};
|
|
37862
|
-
const WEBGL_COMPONENT_TYPES = {
|
|
37863
|
-
5120: Int8Array,
|
|
37864
|
-
5121: Uint8Array,
|
|
37865
|
-
5122: Int16Array,
|
|
37866
|
-
5123: Uint16Array,
|
|
37867
|
-
5125: Uint32Array,
|
|
37868
|
-
5126: Float32Array
|
|
37869
|
-
};
|
|
37870
|
-
const WEBGL_FILTERS = {
|
|
37871
|
-
9728: NearestFilter,
|
|
37872
|
-
9729: LinearFilter,
|
|
37873
|
-
9984: NearestMipmapNearestFilter,
|
|
37874
|
-
9985: LinearMipmapNearestFilter,
|
|
37875
|
-
9986: NearestMipmapLinearFilter,
|
|
37876
|
-
9987: LinearMipmapLinearFilter
|
|
37877
|
-
};
|
|
37878
|
-
const WEBGL_WRAPPINGS = {
|
|
37879
|
-
33071: ClampToEdgeWrapping,
|
|
37880
|
-
33648: MirroredRepeatWrapping,
|
|
37881
|
-
10497: RepeatWrapping
|
|
37882
|
-
};
|
|
37883
|
-
const WEBGL_TYPE_SIZES = {
|
|
37884
|
-
'SCALAR': 1,
|
|
37885
|
-
'VEC2': 2,
|
|
37886
|
-
'VEC3': 3,
|
|
37887
|
-
'VEC4': 4,
|
|
37888
|
-
'MAT2': 4,
|
|
37889
|
-
'MAT3': 9,
|
|
37890
|
-
'MAT4': 16
|
|
37891
|
-
};
|
|
37892
|
-
const ATTRIBUTES = {
|
|
37893
|
-
POSITION: 'position',
|
|
37894
|
-
NORMAL: 'normal',
|
|
37895
|
-
TANGENT: 'tangent',
|
|
37896
|
-
TEXCOORD_0: 'uv',
|
|
37897
|
-
TEXCOORD_1: 'uv1',
|
|
37898
|
-
TEXCOORD_2: 'uv2',
|
|
37899
|
-
TEXCOORD_3: 'uv3',
|
|
37900
|
-
COLOR_0: 'color',
|
|
37901
|
-
WEIGHTS_0: 'skinWeight',
|
|
37902
|
-
JOINTS_0: 'skinIndex',
|
|
37903
|
-
};
|
|
37904
|
-
const PATH_PROPERTIES = {
|
|
37905
|
-
scale: 'scale',
|
|
37906
|
-
translation: 'position',
|
|
37907
|
-
rotation: 'quaternion',
|
|
37908
|
-
weights: 'morphTargetInfluences'
|
|
37909
|
-
};
|
|
37910
|
-
const INTERPOLATION = {
|
|
37911
|
-
CUBICSPLINE: undefined,
|
|
37912
|
-
LINEAR: InterpolateLinear,
|
|
37913
|
-
STEP: InterpolateDiscrete
|
|
37914
|
-
};
|
|
37915
|
-
const ALPHA_MODES = {
|
|
37916
|
-
OPAQUE: 'OPAQUE',
|
|
37917
|
-
MASK: 'MASK',
|
|
37918
|
-
BLEND: 'BLEND'
|
|
37919
|
-
};
|
|
37920
|
-
function createDefaultMaterial( cache ) {
|
|
37921
|
-
if ( cache[ 'DefaultMaterial' ] === undefined ) {
|
|
37922
|
-
cache[ 'DefaultMaterial' ] = new MeshStandardMaterial( {
|
|
37923
|
-
color: 0xFFFFFF,
|
|
37924
|
-
emissive: 0x000000,
|
|
37925
|
-
metalness: 1,
|
|
37926
|
-
roughness: 1,
|
|
37927
|
-
transparent: false,
|
|
37928
|
-
depthTest: true,
|
|
37929
|
-
side: FrontSide
|
|
37930
|
-
} );
|
|
37931
|
-
}
|
|
37932
|
-
return cache[ 'DefaultMaterial' ];
|
|
37933
|
-
}
|
|
37934
|
-
function addUnknownExtensionsToUserData( knownExtensions, object, objectDef ) {
|
|
37935
|
-
for ( const name in objectDef.extensions ) {
|
|
37936
|
-
if ( knownExtensions[ name ] === undefined ) {
|
|
37937
|
-
object.userData.gltfExtensions = object.userData.gltfExtensions || {};
|
|
37938
|
-
object.userData.gltfExtensions[ name ] = objectDef.extensions[ name ];
|
|
37939
|
-
}
|
|
37940
|
-
}
|
|
37941
|
-
}
|
|
37942
|
-
function assignExtrasToUserData( object, gltfDef ) {
|
|
37943
|
-
if ( gltfDef.extras !== undefined ) {
|
|
37944
|
-
if ( typeof gltfDef.extras === 'object' ) {
|
|
37945
|
-
Object.assign( object.userData, gltfDef.extras );
|
|
37946
|
-
} else {
|
|
37947
|
-
console.warn( 'THREE.GLTFLoader: Ignoring primitive type .extras, ' + gltfDef.extras );
|
|
37948
|
-
}
|
|
37949
|
-
}
|
|
37950
|
-
}
|
|
37951
|
-
function addMorphTargets( geometry, targets, parser ) {
|
|
37952
|
-
let hasMorphPosition = false;
|
|
37953
|
-
let hasMorphNormal = false;
|
|
37954
|
-
let hasMorphColor = false;
|
|
37955
|
-
for ( let i = 0, il = targets.length; i < il; i ++ ) {
|
|
37956
|
-
const target = targets[ i ];
|
|
37957
|
-
if ( target.POSITION !== undefined ) hasMorphPosition = true;
|
|
37958
|
-
if ( target.NORMAL !== undefined ) hasMorphNormal = true;
|
|
37959
|
-
if ( target.COLOR_0 !== undefined ) hasMorphColor = true;
|
|
37960
|
-
if ( hasMorphPosition && hasMorphNormal && hasMorphColor ) break;
|
|
37961
|
-
}
|
|
37962
|
-
if ( ! hasMorphPosition && ! hasMorphNormal && ! hasMorphColor ) return Promise.resolve( geometry );
|
|
37963
|
-
const pendingPositionAccessors = [];
|
|
37964
|
-
const pendingNormalAccessors = [];
|
|
37965
|
-
const pendingColorAccessors = [];
|
|
37966
|
-
for ( let i = 0, il = targets.length; i < il; i ++ ) {
|
|
37967
|
-
const target = targets[ i ];
|
|
37968
|
-
if ( hasMorphPosition ) {
|
|
37969
|
-
const pendingAccessor = target.POSITION !== undefined
|
|
37970
|
-
? parser.getDependency( 'accessor', target.POSITION )
|
|
37971
|
-
: geometry.attributes.position;
|
|
37972
|
-
pendingPositionAccessors.push( pendingAccessor );
|
|
37973
|
-
}
|
|
37974
|
-
if ( hasMorphNormal ) {
|
|
37975
|
-
const pendingAccessor = target.NORMAL !== undefined
|
|
37976
|
-
? parser.getDependency( 'accessor', target.NORMAL )
|
|
37977
|
-
: geometry.attributes.normal;
|
|
37978
|
-
pendingNormalAccessors.push( pendingAccessor );
|
|
37979
|
-
}
|
|
37980
|
-
if ( hasMorphColor ) {
|
|
37981
|
-
const pendingAccessor = target.COLOR_0 !== undefined
|
|
37982
|
-
? parser.getDependency( 'accessor', target.COLOR_0 )
|
|
37983
|
-
: geometry.attributes.color;
|
|
37984
|
-
pendingColorAccessors.push( pendingAccessor );
|
|
37985
|
-
}
|
|
37986
|
-
}
|
|
37987
|
-
return Promise.all( [
|
|
37988
|
-
Promise.all( pendingPositionAccessors ),
|
|
37989
|
-
Promise.all( pendingNormalAccessors ),
|
|
37990
|
-
Promise.all( pendingColorAccessors )
|
|
37991
|
-
] ).then( function ( accessors ) {
|
|
37992
|
-
const morphPositions = accessors[ 0 ];
|
|
37993
|
-
const morphNormals = accessors[ 1 ];
|
|
37994
|
-
const morphColors = accessors[ 2 ];
|
|
37995
|
-
if ( hasMorphPosition ) geometry.morphAttributes.position = morphPositions;
|
|
37996
|
-
if ( hasMorphNormal ) geometry.morphAttributes.normal = morphNormals;
|
|
37997
|
-
if ( hasMorphColor ) geometry.morphAttributes.color = morphColors;
|
|
37998
|
-
geometry.morphTargetsRelative = true;
|
|
37999
|
-
return geometry;
|
|
38000
|
-
} );
|
|
38001
|
-
}
|
|
38002
|
-
function updateMorphTargets( mesh, meshDef ) {
|
|
38003
|
-
mesh.updateMorphTargets();
|
|
38004
|
-
if ( meshDef.weights !== undefined ) {
|
|
38005
|
-
for ( let i = 0, il = meshDef.weights.length; i < il; i ++ ) {
|
|
38006
|
-
mesh.morphTargetInfluences[ i ] = meshDef.weights[ i ];
|
|
38007
|
-
}
|
|
38008
|
-
}
|
|
38009
|
-
if ( meshDef.extras && Array.isArray( meshDef.extras.targetNames ) ) {
|
|
38010
|
-
const targetNames = meshDef.extras.targetNames;
|
|
38011
|
-
if ( mesh.morphTargetInfluences.length === targetNames.length ) {
|
|
38012
|
-
mesh.morphTargetDictionary = {};
|
|
38013
|
-
for ( let i = 0, il = targetNames.length; i < il; i ++ ) {
|
|
38014
|
-
mesh.morphTargetDictionary[ targetNames[ i ] ] = i;
|
|
38015
|
-
}
|
|
38016
|
-
} else {
|
|
38017
|
-
console.warn( 'THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.' );
|
|
38018
|
-
}
|
|
38019
|
-
}
|
|
38020
|
-
}
|
|
38021
|
-
function createPrimitiveKey( primitiveDef ) {
|
|
38022
|
-
let geometryKey;
|
|
38023
|
-
const dracoExtension = primitiveDef.extensions && primitiveDef.extensions[ EXTENSIONS.KHR_DRACO_MESH_COMPRESSION ];
|
|
38024
|
-
if ( dracoExtension ) {
|
|
38025
|
-
geometryKey = 'draco:' + dracoExtension.bufferView
|
|
38026
|
-
+ ':' + dracoExtension.indices
|
|
38027
|
-
+ ':' + createAttributesKey( dracoExtension.attributes );
|
|
38028
|
-
} else {
|
|
38029
|
-
geometryKey = primitiveDef.indices + ':' + createAttributesKey( primitiveDef.attributes ) + ':' + primitiveDef.mode;
|
|
38030
|
-
}
|
|
38031
|
-
if ( primitiveDef.targets !== undefined ) {
|
|
38032
|
-
for ( let i = 0, il = primitiveDef.targets.length; i < il; i ++ ) {
|
|
38033
|
-
geometryKey += ':' + createAttributesKey( primitiveDef.targets[ i ] );
|
|
38034
|
-
}
|
|
38035
|
-
}
|
|
38036
|
-
return geometryKey;
|
|
38037
|
-
}
|
|
38038
|
-
function createAttributesKey( attributes ) {
|
|
38039
|
-
let attributesKey = '';
|
|
38040
|
-
const keys = Object.keys( attributes ).sort();
|
|
38041
|
-
for ( let i = 0, il = keys.length; i < il; i ++ ) {
|
|
38042
|
-
attributesKey += keys[ i ] + ':' + attributes[ keys[ i ] ] + ';';
|
|
38043
|
-
}
|
|
38044
|
-
return attributesKey;
|
|
38045
|
-
}
|
|
38046
|
-
function getNormalizedComponentScale( constructor ) {
|
|
38047
|
-
switch ( constructor ) {
|
|
38048
|
-
case Int8Array:
|
|
38049
|
-
return 1 / 127;
|
|
38050
|
-
case Uint8Array:
|
|
38051
|
-
return 1 / 255;
|
|
38052
|
-
case Int16Array:
|
|
38053
|
-
return 1 / 32767;
|
|
38054
|
-
case Uint16Array:
|
|
38055
|
-
return 1 / 65535;
|
|
38056
|
-
default:
|
|
38057
|
-
throw new Error( 'THREE.GLTFLoader: Unsupported normalized accessor component type.' );
|
|
38058
|
-
}
|
|
38059
|
-
}
|
|
38060
|
-
function getImageURIMimeType( uri ) {
|
|
38061
|
-
if ( uri.search( /\.jpe?g($|\?)/i ) > 0 || uri.search( /^data\:image\/jpeg/ ) === 0 ) return 'image/jpeg';
|
|
38062
|
-
if ( uri.search( /\.webp($|\?)/i ) > 0 || uri.search( /^data\:image\/webp/ ) === 0 ) return 'image/webp';
|
|
38063
|
-
if ( uri.search( /\.ktx2($|\?)/i ) > 0 || uri.search( /^data\:image\/ktx2/ ) === 0 ) return 'image/ktx2';
|
|
38064
|
-
return 'image/png';
|
|
38065
|
-
}
|
|
38066
|
-
const _identityMatrix = new Matrix4();
|
|
38067
|
-
class GLTFParser {
|
|
38068
|
-
constructor( json = {}, options = {} ) {
|
|
38069
|
-
this.json = json;
|
|
38070
|
-
this.extensions = {};
|
|
38071
|
-
this.plugins = {};
|
|
38072
|
-
this.options = options;
|
|
38073
|
-
this.cache = new GLTFRegistry();
|
|
38074
|
-
this.associations = new Map();
|
|
38075
|
-
this.primitiveCache = {};
|
|
38076
|
-
this.nodeCache = {};
|
|
38077
|
-
this.meshCache = { refs: {}, uses: {} };
|
|
38078
|
-
this.cameraCache = { refs: {}, uses: {} };
|
|
38079
|
-
this.lightCache = { refs: {}, uses: {} };
|
|
38080
|
-
this.sourceCache = {};
|
|
38081
|
-
this.textureCache = {};
|
|
38082
|
-
this.nodeNamesUsed = {};
|
|
38083
|
-
let isSafari = false;
|
|
38084
|
-
let safariVersion = -1;
|
|
38085
|
-
let isFirefox = false;
|
|
38086
|
-
let firefoxVersion = -1;
|
|
38087
|
-
if ( typeof navigator !== 'undefined' ) {
|
|
38088
|
-
const userAgent = navigator.userAgent;
|
|
38089
|
-
isSafari = /^((?!chrome|android).)*safari/i.test( userAgent ) === true;
|
|
38090
|
-
const safariMatch = userAgent.match( /Version\/(\d+)/ );
|
|
38091
|
-
safariVersion = isSafari && safariMatch ? parseInt( safariMatch[ 1 ], 10 ) : -1;
|
|
38092
|
-
isFirefox = userAgent.indexOf( 'Firefox' ) > -1;
|
|
38093
|
-
firefoxVersion = isFirefox ? userAgent.match( /Firefox\/([0-9]+)\./ )[ 1 ] : -1;
|
|
38094
|
-
}
|
|
38095
|
-
if ( typeof createImageBitmap === 'undefined' || ( isSafari && safariVersion < 17 ) || ( isFirefox && firefoxVersion < 98 ) ) {
|
|
38096
|
-
this.textureLoader = new TextureLoader( this.options.manager );
|
|
38097
|
-
} else {
|
|
38098
|
-
this.textureLoader = new ImageBitmapLoader( this.options.manager );
|
|
38099
|
-
}
|
|
38100
|
-
this.textureLoader.setCrossOrigin( this.options.crossOrigin );
|
|
38101
|
-
this.textureLoader.setRequestHeader( this.options.requestHeader );
|
|
38102
|
-
this.fileLoader = new FileLoader( this.options.manager );
|
|
38103
|
-
this.fileLoader.setResponseType( 'arraybuffer' );
|
|
38104
|
-
if ( this.options.crossOrigin === 'use-credentials' ) {
|
|
38105
|
-
this.fileLoader.setWithCredentials( true );
|
|
38106
|
-
}
|
|
38107
|
-
}
|
|
38108
|
-
setExtensions( extensions ) {
|
|
38109
|
-
this.extensions = extensions;
|
|
38110
|
-
}
|
|
38111
|
-
setPlugins( plugins ) {
|
|
38112
|
-
this.plugins = plugins;
|
|
38113
|
-
}
|
|
38114
|
-
parse( onLoad, onError ) {
|
|
38115
|
-
const parser = this;
|
|
38116
|
-
const json = this.json;
|
|
38117
|
-
const extensions = this.extensions;
|
|
38118
|
-
this.cache.removeAll();
|
|
38119
|
-
this.nodeCache = {};
|
|
38120
|
-
this._invokeAll( function ( ext ) {
|
|
38121
|
-
return ext._markDefs && ext._markDefs();
|
|
38122
|
-
} );
|
|
38123
|
-
Promise.all( this._invokeAll( function ( ext ) {
|
|
38124
|
-
return ext.beforeRoot && ext.beforeRoot();
|
|
38125
|
-
} ) ).then( function () {
|
|
38126
|
-
return Promise.all( [
|
|
38127
|
-
parser.getDependencies( 'scene' ),
|
|
38128
|
-
parser.getDependencies( 'animation' ),
|
|
38129
|
-
parser.getDependencies( 'camera' ),
|
|
38130
|
-
] );
|
|
38131
|
-
} ).then( function ( dependencies ) {
|
|
38132
|
-
const result = {
|
|
38133
|
-
scene: dependencies[ 0 ][ json.scene || 0 ],
|
|
38134
|
-
scenes: dependencies[ 0 ],
|
|
38135
|
-
animations: dependencies[ 1 ],
|
|
38136
|
-
cameras: dependencies[ 2 ],
|
|
38137
|
-
asset: json.asset,
|
|
38138
|
-
parser: parser,
|
|
38139
|
-
userData: {}
|
|
38140
|
-
};
|
|
38141
|
-
addUnknownExtensionsToUserData( extensions, result, json );
|
|
38142
|
-
assignExtrasToUserData( result, json );
|
|
38143
|
-
return Promise.all( parser._invokeAll( function ( ext ) {
|
|
38144
|
-
return ext.afterRoot && ext.afterRoot( result );
|
|
38145
|
-
} ) ).then( function () {
|
|
38146
|
-
for ( const scene of result.scenes ) {
|
|
38147
|
-
scene.updateMatrixWorld();
|
|
38148
|
-
}
|
|
38149
|
-
onLoad( result );
|
|
38150
|
-
} );
|
|
38151
|
-
} ).catch( onError );
|
|
38152
|
-
}
|
|
38153
|
-
_markDefs() {
|
|
38154
|
-
const nodeDefs = this.json.nodes || [];
|
|
38155
|
-
const skinDefs = this.json.skins || [];
|
|
38156
|
-
const meshDefs = this.json.meshes || [];
|
|
38157
|
-
for ( let skinIndex = 0, skinLength = skinDefs.length; skinIndex < skinLength; skinIndex ++ ) {
|
|
38158
|
-
const joints = skinDefs[ skinIndex ].joints;
|
|
38159
|
-
for ( let i = 0, il = joints.length; i < il; i ++ ) {
|
|
38160
|
-
nodeDefs[ joints[ i ] ].isBone = true;
|
|
38161
|
-
}
|
|
38162
|
-
}
|
|
38163
|
-
for ( let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex ++ ) {
|
|
38164
|
-
const nodeDef = nodeDefs[ nodeIndex ];
|
|
38165
|
-
if ( nodeDef.mesh !== undefined ) {
|
|
38166
|
-
this._addNodeRef( this.meshCache, nodeDef.mesh );
|
|
38167
|
-
if ( nodeDef.skin !== undefined ) {
|
|
38168
|
-
meshDefs[ nodeDef.mesh ].isSkinnedMesh = true;
|
|
38169
|
-
}
|
|
38170
|
-
}
|
|
38171
|
-
if ( nodeDef.camera !== undefined ) {
|
|
38172
|
-
this._addNodeRef( this.cameraCache, nodeDef.camera );
|
|
38173
|
-
}
|
|
38174
|
-
}
|
|
38175
|
-
}
|
|
38176
|
-
_addNodeRef( cache, index ) {
|
|
38177
|
-
if ( index === undefined ) return;
|
|
38178
|
-
if ( cache.refs[ index ] === undefined ) {
|
|
38179
|
-
cache.refs[ index ] = cache.uses[ index ] = 0;
|
|
38180
|
-
}
|
|
38181
|
-
cache.refs[ index ] ++;
|
|
38182
|
-
}
|
|
38183
|
-
_getNodeRef( cache, index, object ) {
|
|
38184
|
-
if ( cache.refs[ index ] <= 1 ) return object;
|
|
38185
|
-
const ref = object.clone();
|
|
38186
|
-
const updateMappings = ( original, clone ) => {
|
|
38187
|
-
const mappings = this.associations.get( original );
|
|
38188
|
-
if ( mappings != null ) {
|
|
38189
|
-
this.associations.set( clone, mappings );
|
|
38190
|
-
}
|
|
38191
|
-
for ( const [ i, child ] of original.children.entries() ) {
|
|
38192
|
-
updateMappings( child, clone.children[ i ] );
|
|
38193
|
-
}
|
|
38194
|
-
};
|
|
38195
|
-
updateMappings( object, ref );
|
|
38196
|
-
ref.name += '_instance_' + ( cache.uses[ index ] ++ );
|
|
38197
|
-
return ref;
|
|
38198
|
-
}
|
|
38199
|
-
_invokeOne( func ) {
|
|
38200
|
-
const extensions = Object.values( this.plugins );
|
|
38201
|
-
extensions.push( this );
|
|
38202
|
-
for ( let i = 0; i < extensions.length; i ++ ) {
|
|
38203
|
-
const result = func( extensions[ i ] );
|
|
38204
|
-
if ( result ) return result;
|
|
38205
|
-
}
|
|
38206
|
-
return null;
|
|
38207
|
-
}
|
|
38208
|
-
_invokeAll( func ) {
|
|
38209
|
-
const extensions = Object.values( this.plugins );
|
|
38210
|
-
extensions.unshift( this );
|
|
38211
|
-
const pending = [];
|
|
38212
|
-
for ( let i = 0; i < extensions.length; i ++ ) {
|
|
38213
|
-
const result = func( extensions[ i ] );
|
|
38214
|
-
if ( result ) pending.push( result );
|
|
38215
|
-
}
|
|
38216
|
-
return pending;
|
|
38217
|
-
}
|
|
38218
|
-
getDependency( type, index ) {
|
|
38219
|
-
const cacheKey = type + ':' + index;
|
|
38220
|
-
let dependency = this.cache.get( cacheKey );
|
|
38221
|
-
if ( ! dependency ) {
|
|
38222
|
-
switch ( type ) {
|
|
38223
|
-
case 'scene':
|
|
38224
|
-
dependency = this.loadScene( index );
|
|
38225
|
-
break;
|
|
38226
|
-
case 'node':
|
|
38227
|
-
dependency = this._invokeOne( function ( ext ) {
|
|
38228
|
-
return ext.loadNode && ext.loadNode( index );
|
|
38229
|
-
} );
|
|
38230
|
-
break;
|
|
38231
|
-
case 'mesh':
|
|
38232
|
-
dependency = this._invokeOne( function ( ext ) {
|
|
38233
|
-
return ext.loadMesh && ext.loadMesh( index );
|
|
38234
|
-
} );
|
|
38235
|
-
break;
|
|
38236
|
-
case 'accessor':
|
|
38237
|
-
dependency = this.loadAccessor( index );
|
|
38238
|
-
break;
|
|
38239
|
-
case 'bufferView':
|
|
38240
|
-
dependency = this._invokeOne( function ( ext ) {
|
|
38241
|
-
return ext.loadBufferView && ext.loadBufferView( index );
|
|
38242
|
-
} );
|
|
38243
|
-
break;
|
|
38244
|
-
case 'buffer':
|
|
38245
|
-
dependency = this.loadBuffer( index );
|
|
38246
|
-
break;
|
|
38247
|
-
case 'material':
|
|
38248
|
-
dependency = this._invokeOne( function ( ext ) {
|
|
38249
|
-
return ext.loadMaterial && ext.loadMaterial( index );
|
|
38250
|
-
} );
|
|
38251
|
-
break;
|
|
38252
|
-
case 'texture':
|
|
38253
|
-
dependency = this._invokeOne( function ( ext ) {
|
|
38254
|
-
return ext.loadTexture && ext.loadTexture( index );
|
|
38255
|
-
} );
|
|
38256
|
-
break;
|
|
38257
|
-
case 'skin':
|
|
38258
|
-
dependency = this.loadSkin( index );
|
|
38259
|
-
break;
|
|
38260
|
-
case 'animation':
|
|
38261
|
-
dependency = this._invokeOne( function ( ext ) {
|
|
38262
|
-
return ext.loadAnimation && ext.loadAnimation( index );
|
|
38263
|
-
} );
|
|
38264
|
-
break;
|
|
38265
|
-
case 'camera':
|
|
38266
|
-
dependency = this.loadCamera( index );
|
|
38267
|
-
break;
|
|
38268
|
-
default:
|
|
38269
|
-
dependency = this._invokeOne( function ( ext ) {
|
|
38270
|
-
return ext != this && ext.getDependency && ext.getDependency( type, index );
|
|
38271
|
-
} );
|
|
38272
|
-
if ( ! dependency ) {
|
|
38273
|
-
throw new Error( 'Unknown type: ' + type );
|
|
38274
|
-
}
|
|
38275
|
-
break;
|
|
38276
|
-
}
|
|
38277
|
-
this.cache.add( cacheKey, dependency );
|
|
38278
|
-
}
|
|
38279
|
-
return dependency;
|
|
38280
|
-
}
|
|
38281
|
-
getDependencies( type ) {
|
|
38282
|
-
let dependencies = this.cache.get( type );
|
|
38283
|
-
if ( ! dependencies ) {
|
|
38284
|
-
const parser = this;
|
|
38285
|
-
const defs = this.json[ type + ( type === 'mesh' ? 'es' : 's' ) ] || [];
|
|
38286
|
-
dependencies = Promise.all( defs.map( function ( def, index ) {
|
|
38287
|
-
return parser.getDependency( type, index );
|
|
38288
|
-
} ) );
|
|
38289
|
-
this.cache.add( type, dependencies );
|
|
38290
|
-
}
|
|
38291
|
-
return dependencies;
|
|
38292
|
-
}
|
|
38293
|
-
loadBuffer( bufferIndex ) {
|
|
38294
|
-
const bufferDef = this.json.buffers[ bufferIndex ];
|
|
38295
|
-
const loader = this.fileLoader;
|
|
38296
|
-
if ( bufferDef.type && bufferDef.type !== 'arraybuffer' ) {
|
|
38297
|
-
throw new Error( 'THREE.GLTFLoader: ' + bufferDef.type + ' buffer type is not supported.' );
|
|
38298
|
-
}
|
|
38299
|
-
if ( bufferDef.uri === undefined && bufferIndex === 0 ) {
|
|
38300
|
-
return Promise.resolve( this.extensions[ EXTENSIONS.KHR_BINARY_GLTF ].body );
|
|
38301
|
-
}
|
|
38302
|
-
const options = this.options;
|
|
38303
|
-
return new Promise( function ( resolve, reject ) {
|
|
38304
|
-
loader.load( LoaderUtils.resolveURL( bufferDef.uri, options.path ), resolve, undefined, function () {
|
|
38305
|
-
reject( new Error( 'THREE.GLTFLoader: Failed to load buffer "' + bufferDef.uri + '".' ) );
|
|
38306
|
-
} );
|
|
38307
|
-
} );
|
|
38308
|
-
}
|
|
38309
|
-
loadBufferView( bufferViewIndex ) {
|
|
38310
|
-
const bufferViewDef = this.json.bufferViews[ bufferViewIndex ];
|
|
38311
|
-
return this.getDependency( 'buffer', bufferViewDef.buffer ).then( function ( buffer ) {
|
|
38312
|
-
const byteLength = bufferViewDef.byteLength || 0;
|
|
38313
|
-
const byteOffset = bufferViewDef.byteOffset || 0;
|
|
38314
|
-
return buffer.slice( byteOffset, byteOffset + byteLength );
|
|
38315
|
-
} );
|
|
38316
|
-
}
|
|
38317
|
-
loadAccessor( accessorIndex ) {
|
|
38318
|
-
const parser = this;
|
|
38319
|
-
const json = this.json;
|
|
38320
|
-
const accessorDef = this.json.accessors[ accessorIndex ];
|
|
38321
|
-
if ( accessorDef.bufferView === undefined && accessorDef.sparse === undefined ) {
|
|
38322
|
-
const itemSize = WEBGL_TYPE_SIZES[ accessorDef.type ];
|
|
38323
|
-
const TypedArray = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ];
|
|
38324
|
-
const normalized = accessorDef.normalized === true;
|
|
38325
|
-
const array = new TypedArray( accessorDef.count * itemSize );
|
|
38326
|
-
return Promise.resolve( new BufferAttribute( array, itemSize, normalized ) );
|
|
38327
|
-
}
|
|
38328
|
-
const pendingBufferViews = [];
|
|
38329
|
-
if ( accessorDef.bufferView !== undefined ) {
|
|
38330
|
-
pendingBufferViews.push( this.getDependency( 'bufferView', accessorDef.bufferView ) );
|
|
38331
|
-
} else {
|
|
38332
|
-
pendingBufferViews.push( null );
|
|
38333
|
-
}
|
|
38334
|
-
if ( accessorDef.sparse !== undefined ) {
|
|
38335
|
-
pendingBufferViews.push( this.getDependency( 'bufferView', accessorDef.sparse.indices.bufferView ) );
|
|
38336
|
-
pendingBufferViews.push( this.getDependency( 'bufferView', accessorDef.sparse.values.bufferView ) );
|
|
38337
|
-
}
|
|
38338
|
-
return Promise.all( pendingBufferViews ).then( function ( bufferViews ) {
|
|
38339
|
-
const bufferView = bufferViews[ 0 ];
|
|
38340
|
-
const itemSize = WEBGL_TYPE_SIZES[ accessorDef.type ];
|
|
38341
|
-
const TypedArray = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ];
|
|
38342
|
-
const elementBytes = TypedArray.BYTES_PER_ELEMENT;
|
|
38343
|
-
const itemBytes = elementBytes * itemSize;
|
|
38344
|
-
const byteOffset = accessorDef.byteOffset || 0;
|
|
38345
|
-
const byteStride = accessorDef.bufferView !== undefined ? json.bufferViews[ accessorDef.bufferView ].byteStride : undefined;
|
|
38346
|
-
const normalized = accessorDef.normalized === true;
|
|
38347
|
-
let array, bufferAttribute;
|
|
38348
|
-
if ( byteStride && byteStride !== itemBytes ) {
|
|
38349
|
-
const ibSlice = Math.floor( byteOffset / byteStride );
|
|
38350
|
-
const ibCacheKey = 'InterleavedBuffer:' + accessorDef.bufferView + ':' + accessorDef.componentType + ':' + ibSlice + ':' + accessorDef.count;
|
|
38351
|
-
let ib = parser.cache.get( ibCacheKey );
|
|
38352
|
-
if ( ! ib ) {
|
|
38353
|
-
array = new TypedArray( bufferView, ibSlice * byteStride, accessorDef.count * byteStride / elementBytes );
|
|
38354
|
-
ib = new InterleavedBuffer( array, byteStride / elementBytes );
|
|
38355
|
-
parser.cache.add( ibCacheKey, ib );
|
|
38356
|
-
}
|
|
38357
|
-
bufferAttribute = new InterleavedBufferAttribute( ib, itemSize, ( byteOffset % byteStride ) / elementBytes, normalized );
|
|
38358
|
-
} else {
|
|
38359
|
-
if ( bufferView === null ) {
|
|
38360
|
-
array = new TypedArray( accessorDef.count * itemSize );
|
|
38361
|
-
} else {
|
|
38362
|
-
array = new TypedArray( bufferView, byteOffset, accessorDef.count * itemSize );
|
|
38363
|
-
}
|
|
38364
|
-
bufferAttribute = new BufferAttribute( array, itemSize, normalized );
|
|
38365
|
-
}
|
|
38366
|
-
if ( accessorDef.sparse !== undefined ) {
|
|
38367
|
-
const itemSizeIndices = WEBGL_TYPE_SIZES.SCALAR;
|
|
38368
|
-
const TypedArrayIndices = WEBGL_COMPONENT_TYPES[ accessorDef.sparse.indices.componentType ];
|
|
38369
|
-
const byteOffsetIndices = accessorDef.sparse.indices.byteOffset || 0;
|
|
38370
|
-
const byteOffsetValues = accessorDef.sparse.values.byteOffset || 0;
|
|
38371
|
-
const sparseIndices = new TypedArrayIndices( bufferViews[ 1 ], byteOffsetIndices, accessorDef.sparse.count * itemSizeIndices );
|
|
38372
|
-
const sparseValues = new TypedArray( bufferViews[ 2 ], byteOffsetValues, accessorDef.sparse.count * itemSize );
|
|
38373
|
-
if ( bufferView !== null ) {
|
|
38374
|
-
bufferAttribute = new BufferAttribute( bufferAttribute.array.slice(), bufferAttribute.itemSize, bufferAttribute.normalized );
|
|
38375
|
-
}
|
|
38376
|
-
bufferAttribute.normalized = false;
|
|
38377
|
-
for ( let i = 0, il = sparseIndices.length; i < il; i ++ ) {
|
|
38378
|
-
const index = sparseIndices[ i ];
|
|
38379
|
-
bufferAttribute.setX( index, sparseValues[ i * itemSize ] );
|
|
38380
|
-
if ( itemSize >= 2 ) bufferAttribute.setY( index, sparseValues[ i * itemSize + 1 ] );
|
|
38381
|
-
if ( itemSize >= 3 ) bufferAttribute.setZ( index, sparseValues[ i * itemSize + 2 ] );
|
|
38382
|
-
if ( itemSize >= 4 ) bufferAttribute.setW( index, sparseValues[ i * itemSize + 3 ] );
|
|
38383
|
-
if ( itemSize >= 5 ) throw new Error( 'THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.' );
|
|
38384
|
-
}
|
|
38385
|
-
bufferAttribute.normalized = normalized;
|
|
38386
|
-
}
|
|
38387
|
-
return bufferAttribute;
|
|
38388
|
-
} );
|
|
38389
|
-
}
|
|
38390
|
-
loadTexture( textureIndex ) {
|
|
38391
|
-
const json = this.json;
|
|
38392
|
-
const options = this.options;
|
|
38393
|
-
const textureDef = json.textures[ textureIndex ];
|
|
38394
|
-
const sourceIndex = textureDef.source;
|
|
38395
|
-
const sourceDef = json.images[ sourceIndex ];
|
|
38396
|
-
let loader = this.textureLoader;
|
|
38397
|
-
if ( sourceDef.uri ) {
|
|
38398
|
-
const handler = options.manager.getHandler( sourceDef.uri );
|
|
38399
|
-
if ( handler !== null ) loader = handler;
|
|
38400
|
-
}
|
|
38401
|
-
return this.loadTextureImage( textureIndex, sourceIndex, loader );
|
|
38402
|
-
}
|
|
38403
|
-
loadTextureImage( textureIndex, sourceIndex, loader ) {
|
|
38404
|
-
const parser = this;
|
|
38405
|
-
const json = this.json;
|
|
38406
|
-
const textureDef = json.textures[ textureIndex ];
|
|
38407
|
-
const sourceDef = json.images[ sourceIndex ];
|
|
38408
|
-
const cacheKey = ( sourceDef.uri || sourceDef.bufferView ) + ':' + textureDef.sampler;
|
|
38409
|
-
if ( this.textureCache[ cacheKey ] ) {
|
|
38410
|
-
return this.textureCache[ cacheKey ];
|
|
38411
|
-
}
|
|
38412
|
-
const promise = this.loadImageSource( sourceIndex, loader ).then( function ( texture ) {
|
|
38413
|
-
texture.flipY = false;
|
|
38414
|
-
texture.name = textureDef.name || sourceDef.name || '';
|
|
38415
|
-
if ( texture.name === '' && typeof sourceDef.uri === 'string' && sourceDef.uri.startsWith( 'data:image/' ) === false ) {
|
|
38416
|
-
texture.name = sourceDef.uri;
|
|
38417
|
-
}
|
|
38418
|
-
const samplers = json.samplers || {};
|
|
38419
|
-
const sampler = samplers[ textureDef.sampler ] || {};
|
|
38420
|
-
texture.magFilter = WEBGL_FILTERS[ sampler.magFilter ] || LinearFilter;
|
|
38421
|
-
texture.minFilter = WEBGL_FILTERS[ sampler.minFilter ] || LinearMipmapLinearFilter;
|
|
38422
|
-
texture.wrapS = WEBGL_WRAPPINGS[ sampler.wrapS ] || RepeatWrapping;
|
|
38423
|
-
texture.wrapT = WEBGL_WRAPPINGS[ sampler.wrapT ] || RepeatWrapping;
|
|
38424
|
-
texture.generateMipmaps = ! texture.isCompressedTexture && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
|
|
38425
|
-
parser.associations.set( texture, { textures: textureIndex } );
|
|
38426
|
-
return texture;
|
|
38427
|
-
} ).catch( function () {
|
|
38428
|
-
return null;
|
|
38429
|
-
} );
|
|
38430
|
-
this.textureCache[ cacheKey ] = promise;
|
|
38431
|
-
return promise;
|
|
38432
|
-
}
|
|
38433
|
-
loadImageSource( sourceIndex, loader ) {
|
|
38434
|
-
const parser = this;
|
|
38435
|
-
const json = this.json;
|
|
38436
|
-
const options = this.options;
|
|
38437
|
-
if ( this.sourceCache[ sourceIndex ] !== undefined ) {
|
|
38438
|
-
return this.sourceCache[ sourceIndex ].then( ( texture ) => texture.clone() );
|
|
38439
|
-
}
|
|
38440
|
-
const sourceDef = json.images[ sourceIndex ];
|
|
38441
|
-
const URL = self.URL || self.webkitURL;
|
|
38442
|
-
let sourceURI = sourceDef.uri || '';
|
|
38443
|
-
let isObjectURL = false;
|
|
38444
|
-
if ( sourceDef.bufferView !== undefined ) {
|
|
38445
|
-
sourceURI = parser.getDependency( 'bufferView', sourceDef.bufferView ).then( function ( bufferView ) {
|
|
38446
|
-
isObjectURL = true;
|
|
38447
|
-
const blob = new Blob( [ bufferView ], { type: sourceDef.mimeType } );
|
|
38448
|
-
sourceURI = URL.createObjectURL( blob );
|
|
38449
|
-
return sourceURI;
|
|
38450
|
-
} );
|
|
38451
|
-
} else if ( sourceDef.uri === undefined ) {
|
|
38452
|
-
throw new Error( 'THREE.GLTFLoader: Image ' + sourceIndex + ' is missing URI and bufferView' );
|
|
38453
|
-
}
|
|
38454
|
-
const promise = Promise.resolve( sourceURI ).then( function ( sourceURI ) {
|
|
38455
|
-
return new Promise( function ( resolve, reject ) {
|
|
38456
|
-
let onLoad = resolve;
|
|
38457
|
-
if ( loader.isImageBitmapLoader === true ) {
|
|
38458
|
-
onLoad = function ( imageBitmap ) {
|
|
38459
|
-
const texture = new Texture( imageBitmap );
|
|
38460
|
-
texture.needsUpdate = true;
|
|
38461
|
-
resolve( texture );
|
|
38462
|
-
};
|
|
38463
|
-
}
|
|
38464
|
-
loader.load( LoaderUtils.resolveURL( sourceURI, options.path ), onLoad, undefined, reject );
|
|
38465
|
-
} );
|
|
38466
|
-
} ).then( function ( texture ) {
|
|
38467
|
-
if ( isObjectURL === true ) {
|
|
38468
|
-
URL.revokeObjectURL( sourceURI );
|
|
38469
|
-
}
|
|
38470
|
-
assignExtrasToUserData( texture, sourceDef );
|
|
38471
|
-
texture.userData.mimeType = sourceDef.mimeType || getImageURIMimeType( sourceDef.uri );
|
|
38472
|
-
return texture;
|
|
38473
|
-
} ).catch( function ( error ) {
|
|
38474
|
-
console.error( 'THREE.GLTFLoader: Couldn\'t load texture', sourceURI );
|
|
38475
|
-
throw error;
|
|
38476
|
-
} );
|
|
38477
|
-
this.sourceCache[ sourceIndex ] = promise;
|
|
38478
|
-
return promise;
|
|
38479
|
-
}
|
|
38480
|
-
assignTexture( materialParams, mapName, mapDef, colorSpace ) {
|
|
38481
|
-
const parser = this;
|
|
38482
|
-
return this.getDependency( 'texture', mapDef.index ).then( function ( texture ) {
|
|
38483
|
-
if ( ! texture ) return null;
|
|
38484
|
-
if ( mapDef.texCoord !== undefined && mapDef.texCoord > 0 ) {
|
|
38485
|
-
texture = texture.clone();
|
|
38486
|
-
texture.channel = mapDef.texCoord;
|
|
38487
|
-
}
|
|
38488
|
-
if ( parser.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ] ) {
|
|
38489
|
-
const transform = mapDef.extensions !== undefined ? mapDef.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ] : undefined;
|
|
38490
|
-
if ( transform ) {
|
|
38491
|
-
const gltfReference = parser.associations.get( texture );
|
|
38492
|
-
texture = parser.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ].extendTexture( texture, transform );
|
|
38493
|
-
parser.associations.set( texture, gltfReference );
|
|
38494
|
-
}
|
|
38495
|
-
}
|
|
38496
|
-
if ( colorSpace !== undefined ) {
|
|
38497
|
-
texture.colorSpace = colorSpace;
|
|
38498
|
-
}
|
|
38499
|
-
materialParams[ mapName ] = texture;
|
|
38500
|
-
return texture;
|
|
38501
|
-
} );
|
|
38502
|
-
}
|
|
38503
|
-
assignFinalMaterial( mesh ) {
|
|
38504
|
-
const geometry = mesh.geometry;
|
|
38505
|
-
let material = mesh.material;
|
|
38506
|
-
const useDerivativeTangents = geometry.attributes.tangent === undefined;
|
|
38507
|
-
const useVertexColors = geometry.attributes.color !== undefined;
|
|
38508
|
-
const useFlatShading = geometry.attributes.normal === undefined;
|
|
38509
|
-
if ( mesh.isPoints ) {
|
|
38510
|
-
const cacheKey = 'PointsMaterial:' + material.uuid;
|
|
38511
|
-
let pointsMaterial = this.cache.get( cacheKey );
|
|
38512
|
-
if ( ! pointsMaterial ) {
|
|
38513
|
-
pointsMaterial = new PointsMaterial();
|
|
38514
|
-
Material.prototype.copy.call( pointsMaterial, material );
|
|
38515
|
-
pointsMaterial.color.copy( material.color );
|
|
38516
|
-
pointsMaterial.map = material.map;
|
|
38517
|
-
pointsMaterial.sizeAttenuation = false;
|
|
38518
|
-
this.cache.add( cacheKey, pointsMaterial );
|
|
38519
|
-
}
|
|
38520
|
-
material = pointsMaterial;
|
|
38521
|
-
} else if ( mesh.isLine ) {
|
|
38522
|
-
const cacheKey = 'LineBasicMaterial:' + material.uuid;
|
|
38523
|
-
let lineMaterial = this.cache.get( cacheKey );
|
|
38524
|
-
if ( ! lineMaterial ) {
|
|
38525
|
-
lineMaterial = new LineBasicMaterial();
|
|
38526
|
-
Material.prototype.copy.call( lineMaterial, material );
|
|
38527
|
-
lineMaterial.color.copy( material.color );
|
|
38528
|
-
lineMaterial.map = material.map;
|
|
38529
|
-
this.cache.add( cacheKey, lineMaterial );
|
|
38530
|
-
}
|
|
38531
|
-
material = lineMaterial;
|
|
38532
|
-
}
|
|
38533
|
-
if ( useDerivativeTangents || useVertexColors || useFlatShading ) {
|
|
38534
|
-
let cacheKey = 'ClonedMaterial:' + material.uuid + ':';
|
|
38535
|
-
if ( useDerivativeTangents ) cacheKey += 'derivative-tangents:';
|
|
38536
|
-
if ( useVertexColors ) cacheKey += 'vertex-colors:';
|
|
38537
|
-
if ( useFlatShading ) cacheKey += 'flat-shading:';
|
|
38538
|
-
let cachedMaterial = this.cache.get( cacheKey );
|
|
38539
|
-
if ( ! cachedMaterial ) {
|
|
38540
|
-
cachedMaterial = material.clone();
|
|
38541
|
-
if ( useVertexColors ) cachedMaterial.vertexColors = true;
|
|
38542
|
-
if ( useFlatShading ) cachedMaterial.flatShading = true;
|
|
38543
|
-
if ( useDerivativeTangents ) {
|
|
38544
|
-
if ( cachedMaterial.normalScale ) cachedMaterial.normalScale.y *= -1;
|
|
38545
|
-
if ( cachedMaterial.clearcoatNormalScale ) cachedMaterial.clearcoatNormalScale.y *= -1;
|
|
38546
|
-
}
|
|
38547
|
-
this.cache.add( cacheKey, cachedMaterial );
|
|
38548
|
-
this.associations.set( cachedMaterial, this.associations.get( material ) );
|
|
38549
|
-
}
|
|
38550
|
-
material = cachedMaterial;
|
|
38551
|
-
}
|
|
38552
|
-
mesh.material = material;
|
|
38553
|
-
}
|
|
38554
|
-
getMaterialType( ) {
|
|
38555
|
-
return MeshStandardMaterial;
|
|
38556
|
-
}
|
|
38557
|
-
loadMaterial( materialIndex ) {
|
|
38558
|
-
const parser = this;
|
|
38559
|
-
const json = this.json;
|
|
38560
|
-
const extensions = this.extensions;
|
|
38561
|
-
const materialDef = json.materials[ materialIndex ];
|
|
38562
|
-
let materialType;
|
|
38563
|
-
const materialParams = {};
|
|
38564
|
-
const materialExtensions = materialDef.extensions || {};
|
|
38565
|
-
const pending = [];
|
|
38566
|
-
if ( materialExtensions[ EXTENSIONS.KHR_MATERIALS_UNLIT ] ) {
|
|
38567
|
-
const kmuExtension = extensions[ EXTENSIONS.KHR_MATERIALS_UNLIT ];
|
|
38568
|
-
materialType = kmuExtension.getMaterialType();
|
|
38569
|
-
pending.push( kmuExtension.extendParams( materialParams, materialDef, parser ) );
|
|
38570
|
-
} else {
|
|
38571
|
-
const metallicRoughness = materialDef.pbrMetallicRoughness || {};
|
|
38572
|
-
materialParams.color = new Color( 1.0, 1.0, 1.0 );
|
|
38573
|
-
materialParams.opacity = 1.0;
|
|
38574
|
-
if ( Array.isArray( metallicRoughness.baseColorFactor ) ) {
|
|
38575
|
-
const array = metallicRoughness.baseColorFactor;
|
|
38576
|
-
materialParams.color.setRGB( array[ 0 ], array[ 1 ], array[ 2 ], LinearSRGBColorSpace );
|
|
38577
|
-
materialParams.opacity = array[ 3 ];
|
|
38578
|
-
}
|
|
38579
|
-
if ( metallicRoughness.baseColorTexture !== undefined ) {
|
|
38580
|
-
pending.push( parser.assignTexture( materialParams, 'map', metallicRoughness.baseColorTexture, SRGBColorSpace ) );
|
|
38581
|
-
}
|
|
38582
|
-
materialParams.metalness = metallicRoughness.metallicFactor !== undefined ? metallicRoughness.metallicFactor : 1.0;
|
|
38583
|
-
materialParams.roughness = metallicRoughness.roughnessFactor !== undefined ? metallicRoughness.roughnessFactor : 1.0;
|
|
38584
|
-
if ( metallicRoughness.metallicRoughnessTexture !== undefined ) {
|
|
38585
|
-
pending.push( parser.assignTexture( materialParams, 'metalnessMap', metallicRoughness.metallicRoughnessTexture ) );
|
|
38586
|
-
pending.push( parser.assignTexture( materialParams, 'roughnessMap', metallicRoughness.metallicRoughnessTexture ) );
|
|
38587
|
-
}
|
|
38588
|
-
materialType = this._invokeOne( function ( ext ) {
|
|
38589
|
-
return ext.getMaterialType && ext.getMaterialType( materialIndex );
|
|
38590
|
-
} );
|
|
38591
|
-
pending.push( Promise.all( this._invokeAll( function ( ext ) {
|
|
38592
|
-
return ext.extendMaterialParams && ext.extendMaterialParams( materialIndex, materialParams );
|
|
38593
|
-
} ) ) );
|
|
38594
|
-
}
|
|
38595
|
-
if ( materialDef.doubleSided === true ) {
|
|
38596
|
-
materialParams.side = DoubleSide;
|
|
38597
|
-
}
|
|
38598
|
-
const alphaMode = materialDef.alphaMode || ALPHA_MODES.OPAQUE;
|
|
38599
|
-
if ( alphaMode === ALPHA_MODES.BLEND ) {
|
|
38600
|
-
materialParams.transparent = true;
|
|
38601
|
-
materialParams.depthWrite = false;
|
|
38602
|
-
} else {
|
|
38603
|
-
materialParams.transparent = false;
|
|
38604
|
-
if ( alphaMode === ALPHA_MODES.MASK ) {
|
|
38605
|
-
materialParams.alphaTest = materialDef.alphaCutoff !== undefined ? materialDef.alphaCutoff : 0.5;
|
|
38606
|
-
}
|
|
38607
|
-
}
|
|
38608
|
-
if ( materialDef.normalTexture !== undefined && materialType !== MeshBasicMaterial ) {
|
|
38609
|
-
pending.push( parser.assignTexture( materialParams, 'normalMap', materialDef.normalTexture ) );
|
|
38610
|
-
materialParams.normalScale = new Vector2( 1, 1 );
|
|
38611
|
-
if ( materialDef.normalTexture.scale !== undefined ) {
|
|
38612
|
-
const scale = materialDef.normalTexture.scale;
|
|
38613
|
-
materialParams.normalScale.set( scale, scale );
|
|
38614
|
-
}
|
|
38615
|
-
}
|
|
38616
|
-
if ( materialDef.occlusionTexture !== undefined && materialType !== MeshBasicMaterial ) {
|
|
38617
|
-
pending.push( parser.assignTexture( materialParams, 'aoMap', materialDef.occlusionTexture ) );
|
|
38618
|
-
if ( materialDef.occlusionTexture.strength !== undefined ) {
|
|
38619
|
-
materialParams.aoMapIntensity = materialDef.occlusionTexture.strength;
|
|
38620
|
-
}
|
|
38621
|
-
}
|
|
38622
|
-
if ( materialDef.emissiveFactor !== undefined && materialType !== MeshBasicMaterial ) {
|
|
38623
|
-
const emissiveFactor = materialDef.emissiveFactor;
|
|
38624
|
-
materialParams.emissive = new Color().setRGB( emissiveFactor[ 0 ], emissiveFactor[ 1 ], emissiveFactor[ 2 ], LinearSRGBColorSpace );
|
|
38625
|
-
}
|
|
38626
|
-
if ( materialDef.emissiveTexture !== undefined && materialType !== MeshBasicMaterial ) {
|
|
38627
|
-
pending.push( parser.assignTexture( materialParams, 'emissiveMap', materialDef.emissiveTexture, SRGBColorSpace ) );
|
|
38628
|
-
}
|
|
38629
|
-
return Promise.all( pending ).then( function () {
|
|
38630
|
-
const material = new materialType( materialParams );
|
|
38631
|
-
if ( materialDef.name ) material.name = materialDef.name;
|
|
38632
|
-
assignExtrasToUserData( material, materialDef );
|
|
38633
|
-
parser.associations.set( material, { materials: materialIndex } );
|
|
38634
|
-
if ( materialDef.extensions ) addUnknownExtensionsToUserData( extensions, material, materialDef );
|
|
38635
|
-
return material;
|
|
38636
|
-
} );
|
|
38637
|
-
}
|
|
38638
|
-
createUniqueName( originalName ) {
|
|
38639
|
-
const sanitizedName = PropertyBinding.sanitizeNodeName( originalName || '' );
|
|
38640
|
-
if ( sanitizedName in this.nodeNamesUsed ) {
|
|
38641
|
-
return sanitizedName + '_' + ( ++ this.nodeNamesUsed[ sanitizedName ] );
|
|
38642
|
-
} else {
|
|
38643
|
-
this.nodeNamesUsed[ sanitizedName ] = 0;
|
|
38644
|
-
return sanitizedName;
|
|
38645
|
-
}
|
|
38646
|
-
}
|
|
38647
|
-
loadGeometries( primitives ) {
|
|
38648
|
-
const parser = this;
|
|
38649
|
-
const extensions = this.extensions;
|
|
38650
|
-
const cache = this.primitiveCache;
|
|
38651
|
-
function createDracoPrimitive( primitive ) {
|
|
38652
|
-
return extensions[ EXTENSIONS.KHR_DRACO_MESH_COMPRESSION ]
|
|
38653
|
-
.decodePrimitive( primitive, parser )
|
|
38654
|
-
.then( function ( geometry ) {
|
|
38655
|
-
return addPrimitiveAttributes( geometry, primitive, parser );
|
|
38656
|
-
} );
|
|
38657
|
-
}
|
|
38658
|
-
const pending = [];
|
|
38659
|
-
for ( let i = 0, il = primitives.length; i < il; i ++ ) {
|
|
38660
|
-
const primitive = primitives[ i ];
|
|
38661
|
-
const cacheKey = createPrimitiveKey( primitive );
|
|
38662
|
-
const cached = cache[ cacheKey ];
|
|
38663
|
-
if ( cached ) {
|
|
38664
|
-
pending.push( cached.promise );
|
|
38665
|
-
} else {
|
|
38666
|
-
let geometryPromise;
|
|
38667
|
-
if ( primitive.extensions && primitive.extensions[ EXTENSIONS.KHR_DRACO_MESH_COMPRESSION ] ) {
|
|
38668
|
-
geometryPromise = createDracoPrimitive( primitive );
|
|
38669
|
-
} else {
|
|
38670
|
-
geometryPromise = addPrimitiveAttributes( new BufferGeometry(), primitive, parser );
|
|
38671
|
-
}
|
|
38672
|
-
cache[ cacheKey ] = { primitive: primitive, promise: geometryPromise };
|
|
38673
|
-
pending.push( geometryPromise );
|
|
38674
|
-
}
|
|
38675
|
-
}
|
|
38676
|
-
return Promise.all( pending );
|
|
38677
|
-
}
|
|
38678
|
-
loadMesh( meshIndex ) {
|
|
38679
|
-
const parser = this;
|
|
38680
|
-
const json = this.json;
|
|
38681
|
-
const extensions = this.extensions;
|
|
38682
|
-
const meshDef = json.meshes[ meshIndex ];
|
|
38683
|
-
const primitives = meshDef.primitives;
|
|
38684
|
-
const pending = [];
|
|
38685
|
-
for ( let i = 0, il = primitives.length; i < il; i ++ ) {
|
|
38686
|
-
const material = primitives[ i ].material === undefined
|
|
38687
|
-
? createDefaultMaterial( this.cache )
|
|
38688
|
-
: this.getDependency( 'material', primitives[ i ].material );
|
|
38689
|
-
pending.push( material );
|
|
38690
|
-
}
|
|
38691
|
-
pending.push( parser.loadGeometries( primitives ) );
|
|
38692
|
-
return Promise.all( pending ).then( function ( results ) {
|
|
38693
|
-
const materials = results.slice( 0, results.length - 1 );
|
|
38694
|
-
const geometries = results[ results.length - 1 ];
|
|
38695
|
-
const meshes = [];
|
|
38696
|
-
for ( let i = 0, il = geometries.length; i < il; i ++ ) {
|
|
38697
|
-
const geometry = geometries[ i ];
|
|
38698
|
-
const primitive = primitives[ i ];
|
|
38699
|
-
let mesh;
|
|
38700
|
-
const material = materials[ i ];
|
|
38701
|
-
if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLES ||
|
|
38702
|
-
primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP ||
|
|
38703
|
-
primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN ||
|
|
38704
|
-
primitive.mode === undefined ) {
|
|
38705
|
-
mesh = meshDef.isSkinnedMesh === true
|
|
38706
|
-
? new SkinnedMesh( geometry, material )
|
|
38707
|
-
: new Mesh( geometry, material );
|
|
38708
|
-
if ( mesh.isSkinnedMesh === true ) {
|
|
38709
|
-
mesh.normalizeSkinWeights();
|
|
38710
|
-
}
|
|
38711
|
-
if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP ) {
|
|
38712
|
-
mesh.geometry = toTrianglesDrawMode( mesh.geometry, TriangleStripDrawMode );
|
|
38713
|
-
} else if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN ) {
|
|
38714
|
-
mesh.geometry = toTrianglesDrawMode( mesh.geometry, TriangleFanDrawMode );
|
|
38715
|
-
}
|
|
38716
|
-
} else if ( primitive.mode === WEBGL_CONSTANTS.LINES ) {
|
|
38717
|
-
mesh = new LineSegments( geometry, material );
|
|
38718
|
-
} else if ( primitive.mode === WEBGL_CONSTANTS.LINE_STRIP ) {
|
|
38719
|
-
mesh = new Line$1( geometry, material );
|
|
38720
|
-
} else if ( primitive.mode === WEBGL_CONSTANTS.LINE_LOOP ) {
|
|
38721
|
-
mesh = new LineLoop( geometry, material );
|
|
38722
|
-
} else if ( primitive.mode === WEBGL_CONSTANTS.POINTS ) {
|
|
38723
|
-
mesh = new Points( geometry, material );
|
|
38724
|
-
} else {
|
|
38725
|
-
throw new Error( 'THREE.GLTFLoader: Primitive mode unsupported: ' + primitive.mode );
|
|
38726
|
-
}
|
|
38727
|
-
if ( Object.keys( mesh.geometry.morphAttributes ).length > 0 ) {
|
|
38728
|
-
updateMorphTargets( mesh, meshDef );
|
|
38729
|
-
}
|
|
38730
|
-
mesh.name = parser.createUniqueName( meshDef.name || ( 'mesh_' + meshIndex ) );
|
|
38731
|
-
assignExtrasToUserData( mesh, meshDef );
|
|
38732
|
-
if ( primitive.extensions ) addUnknownExtensionsToUserData( extensions, mesh, primitive );
|
|
38733
|
-
parser.assignFinalMaterial( mesh );
|
|
38734
|
-
meshes.push( mesh );
|
|
38735
|
-
}
|
|
38736
|
-
for ( let i = 0, il = meshes.length; i < il; i ++ ) {
|
|
38737
|
-
parser.associations.set( meshes[ i ], {
|
|
38738
|
-
meshes: meshIndex,
|
|
38739
|
-
primitives: i
|
|
38740
|
-
} );
|
|
38741
|
-
}
|
|
38742
|
-
if ( meshes.length === 1 ) {
|
|
38743
|
-
if ( meshDef.extensions ) addUnknownExtensionsToUserData( extensions, meshes[ 0 ], meshDef );
|
|
38744
|
-
return meshes[ 0 ];
|
|
38745
|
-
}
|
|
38746
|
-
const group = new Group$1();
|
|
38747
|
-
if ( meshDef.extensions ) addUnknownExtensionsToUserData( extensions, group, meshDef );
|
|
38748
|
-
parser.associations.set( group, { meshes: meshIndex } );
|
|
38749
|
-
for ( let i = 0, il = meshes.length; i < il; i ++ ) {
|
|
38750
|
-
group.add( meshes[ i ] );
|
|
38751
|
-
}
|
|
38752
|
-
return group;
|
|
38753
|
-
} );
|
|
38754
|
-
}
|
|
38755
|
-
loadCamera( cameraIndex ) {
|
|
38756
|
-
let camera;
|
|
38757
|
-
const cameraDef = this.json.cameras[ cameraIndex ];
|
|
38758
|
-
const params = cameraDef[ cameraDef.type ];
|
|
38759
|
-
if ( ! params ) {
|
|
38760
|
-
console.warn( 'THREE.GLTFLoader: Missing camera parameters.' );
|
|
38761
|
-
return;
|
|
38762
|
-
}
|
|
38763
|
-
if ( cameraDef.type === 'perspective' ) {
|
|
38764
|
-
camera = new PerspectiveCamera( MathUtils.radToDeg( params.yfov ), params.aspectRatio || 1, params.znear || 1, params.zfar || 2e6 );
|
|
38765
|
-
} else if ( cameraDef.type === 'orthographic' ) {
|
|
38766
|
-
camera = new OrthographicCamera( - params.xmag, params.xmag, params.ymag, - params.ymag, params.znear, params.zfar );
|
|
38767
|
-
}
|
|
38768
|
-
if ( cameraDef.name ) camera.name = this.createUniqueName( cameraDef.name );
|
|
38769
|
-
assignExtrasToUserData( camera, cameraDef );
|
|
38770
|
-
return Promise.resolve( camera );
|
|
38771
|
-
}
|
|
38772
|
-
loadSkin( skinIndex ) {
|
|
38773
|
-
const skinDef = this.json.skins[ skinIndex ];
|
|
38774
|
-
const pending = [];
|
|
38775
|
-
for ( let i = 0, il = skinDef.joints.length; i < il; i ++ ) {
|
|
38776
|
-
pending.push( this._loadNodeShallow( skinDef.joints[ i ] ) );
|
|
38777
|
-
}
|
|
38778
|
-
if ( skinDef.inverseBindMatrices !== undefined ) {
|
|
38779
|
-
pending.push( this.getDependency( 'accessor', skinDef.inverseBindMatrices ) );
|
|
38780
|
-
} else {
|
|
38781
|
-
pending.push( null );
|
|
38782
|
-
}
|
|
38783
|
-
return Promise.all( pending ).then( function ( results ) {
|
|
38784
|
-
const inverseBindMatrices = results.pop();
|
|
38785
|
-
const jointNodes = results;
|
|
38786
|
-
const bones = [];
|
|
38787
|
-
const boneInverses = [];
|
|
38788
|
-
for ( let i = 0, il = jointNodes.length; i < il; i ++ ) {
|
|
38789
|
-
const jointNode = jointNodes[ i ];
|
|
38790
|
-
if ( jointNode ) {
|
|
38791
|
-
bones.push( jointNode );
|
|
38792
|
-
const mat = new Matrix4();
|
|
38793
|
-
if ( inverseBindMatrices !== null ) {
|
|
38794
|
-
mat.fromArray( inverseBindMatrices.array, i * 16 );
|
|
38795
|
-
}
|
|
38796
|
-
boneInverses.push( mat );
|
|
38797
|
-
} else {
|
|
38798
|
-
console.warn( 'THREE.GLTFLoader: Joint "%s" could not be found.', skinDef.joints[ i ] );
|
|
38799
|
-
}
|
|
38800
|
-
}
|
|
38801
|
-
return new Skeleton( bones, boneInverses );
|
|
38802
|
-
} );
|
|
38803
|
-
}
|
|
38804
|
-
loadAnimation( animationIndex ) {
|
|
38805
|
-
const json = this.json;
|
|
38806
|
-
const parser = this;
|
|
38807
|
-
const animationDef = json.animations[ animationIndex ];
|
|
38808
|
-
const animationName = animationDef.name ? animationDef.name : 'animation_' + animationIndex;
|
|
38809
|
-
const pendingNodes = [];
|
|
38810
|
-
const pendingInputAccessors = [];
|
|
38811
|
-
const pendingOutputAccessors = [];
|
|
38812
|
-
const pendingSamplers = [];
|
|
38813
|
-
const pendingTargets = [];
|
|
38814
|
-
for ( let i = 0, il = animationDef.channels.length; i < il; i ++ ) {
|
|
38815
|
-
const channel = animationDef.channels[ i ];
|
|
38816
|
-
const sampler = animationDef.samplers[ channel.sampler ];
|
|
38817
|
-
const target = channel.target;
|
|
38818
|
-
const name = target.node;
|
|
38819
|
-
const input = animationDef.parameters !== undefined ? animationDef.parameters[ sampler.input ] : sampler.input;
|
|
38820
|
-
const output = animationDef.parameters !== undefined ? animationDef.parameters[ sampler.output ] : sampler.output;
|
|
38821
|
-
if ( target.node === undefined ) continue;
|
|
38822
|
-
pendingNodes.push( this.getDependency( 'node', name ) );
|
|
38823
|
-
pendingInputAccessors.push( this.getDependency( 'accessor', input ) );
|
|
38824
|
-
pendingOutputAccessors.push( this.getDependency( 'accessor', output ) );
|
|
38825
|
-
pendingSamplers.push( sampler );
|
|
38826
|
-
pendingTargets.push( target );
|
|
38827
|
-
}
|
|
38828
|
-
return Promise.all( [
|
|
38829
|
-
Promise.all( pendingNodes ),
|
|
38830
|
-
Promise.all( pendingInputAccessors ),
|
|
38831
|
-
Promise.all( pendingOutputAccessors ),
|
|
38832
|
-
Promise.all( pendingSamplers ),
|
|
38833
|
-
Promise.all( pendingTargets )
|
|
38834
|
-
] ).then( function ( dependencies ) {
|
|
38835
|
-
const nodes = dependencies[ 0 ];
|
|
38836
|
-
const inputAccessors = dependencies[ 1 ];
|
|
38837
|
-
const outputAccessors = dependencies[ 2 ];
|
|
38838
|
-
const samplers = dependencies[ 3 ];
|
|
38839
|
-
const targets = dependencies[ 4 ];
|
|
38840
|
-
const tracks = [];
|
|
38841
|
-
for ( let i = 0, il = nodes.length; i < il; i ++ ) {
|
|
38842
|
-
const node = nodes[ i ];
|
|
38843
|
-
const inputAccessor = inputAccessors[ i ];
|
|
38844
|
-
const outputAccessor = outputAccessors[ i ];
|
|
38845
|
-
const sampler = samplers[ i ];
|
|
38846
|
-
const target = targets[ i ];
|
|
38847
|
-
if ( node === undefined ) continue;
|
|
38848
|
-
if ( node.updateMatrix ) {
|
|
38849
|
-
node.updateMatrix();
|
|
38850
|
-
}
|
|
38851
|
-
const createdTracks = parser._createAnimationTracks( node, inputAccessor, outputAccessor, sampler, target );
|
|
38852
|
-
if ( createdTracks ) {
|
|
38853
|
-
for ( let k = 0; k < createdTracks.length; k ++ ) {
|
|
38854
|
-
tracks.push( createdTracks[ k ] );
|
|
38855
|
-
}
|
|
38856
|
-
}
|
|
38857
|
-
}
|
|
38858
|
-
const animation = new AnimationClip( animationName, undefined, tracks );
|
|
38859
|
-
assignExtrasToUserData( animation, animationDef );
|
|
38860
|
-
return animation;
|
|
38861
|
-
} );
|
|
38862
|
-
}
|
|
38863
|
-
createNodeMesh( nodeIndex ) {
|
|
38864
|
-
const json = this.json;
|
|
38865
|
-
const parser = this;
|
|
38866
|
-
const nodeDef = json.nodes[ nodeIndex ];
|
|
38867
|
-
if ( nodeDef.mesh === undefined ) return null;
|
|
38868
|
-
return parser.getDependency( 'mesh', nodeDef.mesh ).then( function ( mesh ) {
|
|
38869
|
-
const node = parser._getNodeRef( parser.meshCache, nodeDef.mesh, mesh );
|
|
38870
|
-
if ( nodeDef.weights !== undefined ) {
|
|
38871
|
-
node.traverse( function ( o ) {
|
|
38872
|
-
if ( ! o.isMesh ) return;
|
|
38873
|
-
for ( let i = 0, il = nodeDef.weights.length; i < il; i ++ ) {
|
|
38874
|
-
o.morphTargetInfluences[ i ] = nodeDef.weights[ i ];
|
|
38875
|
-
}
|
|
38876
|
-
} );
|
|
38877
|
-
}
|
|
38878
|
-
return node;
|
|
38879
|
-
} );
|
|
38880
|
-
}
|
|
38881
|
-
loadNode( nodeIndex ) {
|
|
38882
|
-
const json = this.json;
|
|
38883
|
-
const parser = this;
|
|
38884
|
-
const nodeDef = json.nodes[ nodeIndex ];
|
|
38885
|
-
const nodePending = parser._loadNodeShallow( nodeIndex );
|
|
38886
|
-
const childPending = [];
|
|
38887
|
-
const childrenDef = nodeDef.children || [];
|
|
38888
|
-
for ( let i = 0, il = childrenDef.length; i < il; i ++ ) {
|
|
38889
|
-
childPending.push( parser.getDependency( 'node', childrenDef[ i ] ) );
|
|
38890
|
-
}
|
|
38891
|
-
const skeletonPending = nodeDef.skin === undefined
|
|
38892
|
-
? Promise.resolve( null )
|
|
38893
|
-
: parser.getDependency( 'skin', nodeDef.skin );
|
|
38894
|
-
return Promise.all( [
|
|
38895
|
-
nodePending,
|
|
38896
|
-
Promise.all( childPending ),
|
|
38897
|
-
skeletonPending
|
|
38898
|
-
] ).then( function ( results ) {
|
|
38899
|
-
const node = results[ 0 ];
|
|
38900
|
-
const children = results[ 1 ];
|
|
38901
|
-
const skeleton = results[ 2 ];
|
|
38902
|
-
if ( skeleton !== null ) {
|
|
38903
|
-
node.traverse( function ( mesh ) {
|
|
38904
|
-
if ( ! mesh.isSkinnedMesh ) return;
|
|
38905
|
-
mesh.bind( skeleton, _identityMatrix );
|
|
38906
|
-
} );
|
|
38907
|
-
}
|
|
38908
|
-
for ( let i = 0, il = children.length; i < il; i ++ ) {
|
|
38909
|
-
node.add( children[ i ] );
|
|
38910
|
-
}
|
|
38911
|
-
return node;
|
|
38912
|
-
} );
|
|
38913
|
-
}
|
|
38914
|
-
_loadNodeShallow( nodeIndex ) {
|
|
38915
|
-
const json = this.json;
|
|
38916
|
-
const extensions = this.extensions;
|
|
38917
|
-
const parser = this;
|
|
38918
|
-
if ( this.nodeCache[ nodeIndex ] !== undefined ) {
|
|
38919
|
-
return this.nodeCache[ nodeIndex ];
|
|
38920
|
-
}
|
|
38921
|
-
const nodeDef = json.nodes[ nodeIndex ];
|
|
38922
|
-
const nodeName = nodeDef.name ? parser.createUniqueName( nodeDef.name ) : '';
|
|
38923
|
-
const pending = [];
|
|
38924
|
-
const meshPromise = parser._invokeOne( function ( ext ) {
|
|
38925
|
-
return ext.createNodeMesh && ext.createNodeMesh( nodeIndex );
|
|
38926
|
-
} );
|
|
38927
|
-
if ( meshPromise ) {
|
|
38928
|
-
pending.push( meshPromise );
|
|
38929
|
-
}
|
|
38930
|
-
if ( nodeDef.camera !== undefined ) {
|
|
38931
|
-
pending.push( parser.getDependency( 'camera', nodeDef.camera ).then( function ( camera ) {
|
|
38932
|
-
return parser._getNodeRef( parser.cameraCache, nodeDef.camera, camera );
|
|
38933
|
-
} ) );
|
|
38934
|
-
}
|
|
38935
|
-
parser._invokeAll( function ( ext ) {
|
|
38936
|
-
return ext.createNodeAttachment && ext.createNodeAttachment( nodeIndex );
|
|
38937
|
-
} ).forEach( function ( promise ) {
|
|
38938
|
-
pending.push( promise );
|
|
38939
|
-
} );
|
|
38940
|
-
this.nodeCache[ nodeIndex ] = Promise.all( pending ).then( function ( objects ) {
|
|
38941
|
-
let node;
|
|
38942
|
-
if ( nodeDef.isBone === true ) {
|
|
38943
|
-
node = new Bone();
|
|
38944
|
-
} else if ( objects.length > 1 ) {
|
|
38945
|
-
node = new Group$1();
|
|
38946
|
-
} else if ( objects.length === 1 ) {
|
|
38947
|
-
node = objects[ 0 ];
|
|
38948
|
-
} else {
|
|
38949
|
-
node = new Object3D();
|
|
38950
|
-
}
|
|
38951
|
-
if ( node !== objects[ 0 ] ) {
|
|
38952
|
-
for ( let i = 0, il = objects.length; i < il; i ++ ) {
|
|
38953
|
-
node.add( objects[ i ] );
|
|
38954
|
-
}
|
|
38955
|
-
}
|
|
38956
|
-
if ( nodeDef.name ) {
|
|
38957
|
-
node.userData.name = nodeDef.name;
|
|
38958
|
-
node.name = nodeName;
|
|
38959
|
-
}
|
|
38960
|
-
assignExtrasToUserData( node, nodeDef );
|
|
38961
|
-
if ( nodeDef.extensions ) addUnknownExtensionsToUserData( extensions, node, nodeDef );
|
|
38962
|
-
if ( nodeDef.matrix !== undefined ) {
|
|
38963
|
-
const matrix = new Matrix4();
|
|
38964
|
-
matrix.fromArray( nodeDef.matrix );
|
|
38965
|
-
node.applyMatrix4( matrix );
|
|
38966
|
-
} else {
|
|
38967
|
-
if ( nodeDef.translation !== undefined ) {
|
|
38968
|
-
node.position.fromArray( nodeDef.translation );
|
|
38969
|
-
}
|
|
38970
|
-
if ( nodeDef.rotation !== undefined ) {
|
|
38971
|
-
node.quaternion.fromArray( nodeDef.rotation );
|
|
38972
|
-
}
|
|
38973
|
-
if ( nodeDef.scale !== undefined ) {
|
|
38974
|
-
node.scale.fromArray( nodeDef.scale );
|
|
38975
|
-
}
|
|
38976
|
-
}
|
|
38977
|
-
if ( ! parser.associations.has( node ) ) {
|
|
38978
|
-
parser.associations.set( node, {} );
|
|
38979
|
-
} else if ( nodeDef.mesh !== undefined && parser.meshCache.refs[ nodeDef.mesh ] > 1 ) {
|
|
38980
|
-
const mapping = parser.associations.get( node );
|
|
38981
|
-
parser.associations.set( node, { ...mapping } );
|
|
38982
|
-
}
|
|
38983
|
-
parser.associations.get( node ).nodes = nodeIndex;
|
|
38984
|
-
return node;
|
|
38985
|
-
} );
|
|
38986
|
-
return this.nodeCache[ nodeIndex ];
|
|
38987
|
-
}
|
|
38988
|
-
loadScene( sceneIndex ) {
|
|
38989
|
-
const extensions = this.extensions;
|
|
38990
|
-
const sceneDef = this.json.scenes[ sceneIndex ];
|
|
38991
|
-
const parser = this;
|
|
38992
|
-
const scene = new Group$1();
|
|
38993
|
-
if ( sceneDef.name ) scene.name = parser.createUniqueName( sceneDef.name );
|
|
38994
|
-
assignExtrasToUserData( scene, sceneDef );
|
|
38995
|
-
if ( sceneDef.extensions ) addUnknownExtensionsToUserData( extensions, scene, sceneDef );
|
|
38996
|
-
const nodeIds = sceneDef.nodes || [];
|
|
38997
|
-
const pending = [];
|
|
38998
|
-
for ( let i = 0, il = nodeIds.length; i < il; i ++ ) {
|
|
38999
|
-
pending.push( parser.getDependency( 'node', nodeIds[ i ] ) );
|
|
39000
|
-
}
|
|
39001
|
-
return Promise.all( pending ).then( function ( nodes ) {
|
|
39002
|
-
for ( let i = 0, il = nodes.length; i < il; i ++ ) {
|
|
39003
|
-
scene.add( nodes[ i ] );
|
|
39004
|
-
}
|
|
39005
|
-
const reduceAssociations = ( node ) => {
|
|
39006
|
-
const reducedAssociations = new Map();
|
|
39007
|
-
for ( const [ key, value ] of parser.associations ) {
|
|
39008
|
-
if ( key instanceof Material || key instanceof Texture ) {
|
|
39009
|
-
reducedAssociations.set( key, value );
|
|
39010
|
-
}
|
|
39011
|
-
}
|
|
39012
|
-
node.traverse( ( node ) => {
|
|
39013
|
-
const mappings = parser.associations.get( node );
|
|
39014
|
-
if ( mappings != null ) {
|
|
39015
|
-
reducedAssociations.set( node, mappings );
|
|
39016
|
-
}
|
|
39017
|
-
} );
|
|
39018
|
-
return reducedAssociations;
|
|
39019
|
-
};
|
|
39020
|
-
parser.associations = reduceAssociations( scene );
|
|
39021
|
-
return scene;
|
|
39022
|
-
} );
|
|
39023
|
-
}
|
|
39024
|
-
_createAnimationTracks( node, inputAccessor, outputAccessor, sampler, target ) {
|
|
39025
|
-
const tracks = [];
|
|
39026
|
-
const targetName = node.name ? node.name : node.uuid;
|
|
39027
|
-
const targetNames = [];
|
|
39028
|
-
if ( PATH_PROPERTIES[ target.path ] === PATH_PROPERTIES.weights ) {
|
|
39029
|
-
node.traverse( function ( object ) {
|
|
39030
|
-
if ( object.morphTargetInfluences ) {
|
|
39031
|
-
targetNames.push( object.name ? object.name : object.uuid );
|
|
39032
|
-
}
|
|
39033
|
-
} );
|
|
39034
|
-
} else {
|
|
39035
|
-
targetNames.push( targetName );
|
|
39036
|
-
}
|
|
39037
|
-
let TypedKeyframeTrack;
|
|
39038
|
-
switch ( PATH_PROPERTIES[ target.path ] ) {
|
|
39039
|
-
case PATH_PROPERTIES.weights:
|
|
39040
|
-
TypedKeyframeTrack = NumberKeyframeTrack;
|
|
39041
|
-
break;
|
|
39042
|
-
case PATH_PROPERTIES.rotation:
|
|
39043
|
-
TypedKeyframeTrack = QuaternionKeyframeTrack;
|
|
39044
|
-
break;
|
|
39045
|
-
case PATH_PROPERTIES.translation:
|
|
39046
|
-
case PATH_PROPERTIES.scale:
|
|
39047
|
-
TypedKeyframeTrack = VectorKeyframeTrack;
|
|
39048
|
-
break;
|
|
39049
|
-
default:
|
|
39050
|
-
switch ( outputAccessor.itemSize ) {
|
|
39051
|
-
case 1:
|
|
39052
|
-
TypedKeyframeTrack = NumberKeyframeTrack;
|
|
39053
|
-
break;
|
|
39054
|
-
case 2:
|
|
39055
|
-
case 3:
|
|
39056
|
-
default:
|
|
39057
|
-
TypedKeyframeTrack = VectorKeyframeTrack;
|
|
39058
|
-
break;
|
|
39059
|
-
}
|
|
39060
|
-
break;
|
|
39061
|
-
}
|
|
39062
|
-
const interpolation = sampler.interpolation !== undefined ? INTERPOLATION[ sampler.interpolation ] : InterpolateLinear;
|
|
39063
|
-
const outputArray = this._getArrayFromAccessor( outputAccessor );
|
|
39064
|
-
for ( let j = 0, jl = targetNames.length; j < jl; j ++ ) {
|
|
39065
|
-
const track = new TypedKeyframeTrack(
|
|
39066
|
-
targetNames[ j ] + '.' + PATH_PROPERTIES[ target.path ],
|
|
39067
|
-
inputAccessor.array,
|
|
39068
|
-
outputArray,
|
|
39069
|
-
interpolation
|
|
39070
|
-
);
|
|
39071
|
-
if ( sampler.interpolation === 'CUBICSPLINE' ) {
|
|
39072
|
-
this._createCubicSplineTrackInterpolant( track );
|
|
39073
|
-
}
|
|
39074
|
-
tracks.push( track );
|
|
39075
|
-
}
|
|
39076
|
-
return tracks;
|
|
39077
|
-
}
|
|
39078
|
-
_getArrayFromAccessor( accessor ) {
|
|
39079
|
-
let outputArray = accessor.array;
|
|
39080
|
-
if ( accessor.normalized ) {
|
|
39081
|
-
const scale = getNormalizedComponentScale( outputArray.constructor );
|
|
39082
|
-
const scaled = new Float32Array( outputArray.length );
|
|
39083
|
-
for ( let j = 0, jl = outputArray.length; j < jl; j ++ ) {
|
|
39084
|
-
scaled[ j ] = outputArray[ j ] * scale;
|
|
39085
|
-
}
|
|
39086
|
-
outputArray = scaled;
|
|
39087
|
-
}
|
|
39088
|
-
return outputArray;
|
|
39089
|
-
}
|
|
39090
|
-
_createCubicSplineTrackInterpolant( track ) {
|
|
39091
|
-
track.createInterpolant = function InterpolantFactoryMethodGLTFCubicSpline( result ) {
|
|
39092
|
-
const interpolantType = ( this instanceof QuaternionKeyframeTrack ) ? GLTFCubicSplineQuaternionInterpolant : GLTFCubicSplineInterpolant;
|
|
39093
|
-
return new interpolantType( this.times, this.values, this.getValueSize() / 3, result );
|
|
39094
|
-
};
|
|
39095
|
-
track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = true;
|
|
39096
|
-
}
|
|
39097
|
-
}
|
|
39098
|
-
function computeBounds( geometry, primitiveDef, parser ) {
|
|
39099
|
-
const attributes = primitiveDef.attributes;
|
|
39100
|
-
const box = new Box3();
|
|
39101
|
-
if ( attributes.POSITION !== undefined ) {
|
|
39102
|
-
const accessor = parser.json.accessors[ attributes.POSITION ];
|
|
39103
|
-
const min = accessor.min;
|
|
39104
|
-
const max = accessor.max;
|
|
39105
|
-
if ( min !== undefined && max !== undefined ) {
|
|
39106
|
-
box.set(
|
|
39107
|
-
new Vector3( min[ 0 ], min[ 1 ], min[ 2 ] ),
|
|
39108
|
-
new Vector3( max[ 0 ], max[ 1 ], max[ 2 ] )
|
|
39109
|
-
);
|
|
39110
|
-
if ( accessor.normalized ) {
|
|
39111
|
-
const boxScale = getNormalizedComponentScale( WEBGL_COMPONENT_TYPES[ accessor.componentType ] );
|
|
39112
|
-
box.min.multiplyScalar( boxScale );
|
|
39113
|
-
box.max.multiplyScalar( boxScale );
|
|
39114
|
-
}
|
|
39115
|
-
} else {
|
|
39116
|
-
console.warn( 'THREE.GLTFLoader: Missing min/max properties for accessor POSITION.' );
|
|
39117
|
-
return;
|
|
39118
|
-
}
|
|
39119
|
-
} else {
|
|
39120
|
-
return;
|
|
39121
|
-
}
|
|
39122
|
-
const targets = primitiveDef.targets;
|
|
39123
|
-
if ( targets !== undefined ) {
|
|
39124
|
-
const maxDisplacement = new Vector3();
|
|
39125
|
-
const vector = new Vector3();
|
|
39126
|
-
for ( let i = 0, il = targets.length; i < il; i ++ ) {
|
|
39127
|
-
const target = targets[ i ];
|
|
39128
|
-
if ( target.POSITION !== undefined ) {
|
|
39129
|
-
const accessor = parser.json.accessors[ target.POSITION ];
|
|
39130
|
-
const min = accessor.min;
|
|
39131
|
-
const max = accessor.max;
|
|
39132
|
-
if ( min !== undefined && max !== undefined ) {
|
|
39133
|
-
vector.setX( Math.max( Math.abs( min[ 0 ] ), Math.abs( max[ 0 ] ) ) );
|
|
39134
|
-
vector.setY( Math.max( Math.abs( min[ 1 ] ), Math.abs( max[ 1 ] ) ) );
|
|
39135
|
-
vector.setZ( Math.max( Math.abs( min[ 2 ] ), Math.abs( max[ 2 ] ) ) );
|
|
39136
|
-
if ( accessor.normalized ) {
|
|
39137
|
-
const boxScale = getNormalizedComponentScale( WEBGL_COMPONENT_TYPES[ accessor.componentType ] );
|
|
39138
|
-
vector.multiplyScalar( boxScale );
|
|
39139
|
-
}
|
|
39140
|
-
maxDisplacement.max( vector );
|
|
39141
|
-
} else {
|
|
39142
|
-
console.warn( 'THREE.GLTFLoader: Missing min/max properties for accessor POSITION.' );
|
|
39143
|
-
}
|
|
39144
|
-
}
|
|
39145
|
-
}
|
|
39146
|
-
box.expandByVector( maxDisplacement );
|
|
39147
|
-
}
|
|
39148
|
-
geometry.boundingBox = box;
|
|
39149
|
-
const sphere = new Sphere();
|
|
39150
|
-
box.getCenter( sphere.center );
|
|
39151
|
-
sphere.radius = box.min.distanceTo( box.max ) / 2;
|
|
39152
|
-
geometry.boundingSphere = sphere;
|
|
39153
|
-
}
|
|
39154
|
-
function addPrimitiveAttributes( geometry, primitiveDef, parser ) {
|
|
39155
|
-
const attributes = primitiveDef.attributes;
|
|
39156
|
-
const pending = [];
|
|
39157
|
-
function assignAttributeAccessor( accessorIndex, attributeName ) {
|
|
39158
|
-
return parser.getDependency( 'accessor', accessorIndex )
|
|
39159
|
-
.then( function ( accessor ) {
|
|
39160
|
-
geometry.setAttribute( attributeName, accessor );
|
|
39161
|
-
} );
|
|
39162
|
-
}
|
|
39163
|
-
for ( const gltfAttributeName in attributes ) {
|
|
39164
|
-
const threeAttributeName = ATTRIBUTES[ gltfAttributeName ] || gltfAttributeName.toLowerCase();
|
|
39165
|
-
if ( threeAttributeName in geometry.attributes ) continue;
|
|
39166
|
-
pending.push( assignAttributeAccessor( attributes[ gltfAttributeName ], threeAttributeName ) );
|
|
39167
|
-
}
|
|
39168
|
-
if ( primitiveDef.indices !== undefined && ! geometry.index ) {
|
|
39169
|
-
const accessor = parser.getDependency( 'accessor', primitiveDef.indices ).then( function ( accessor ) {
|
|
39170
|
-
geometry.setIndex( accessor );
|
|
39171
|
-
} );
|
|
39172
|
-
pending.push( accessor );
|
|
39173
|
-
}
|
|
39174
|
-
if ( ColorManagement.workingColorSpace !== LinearSRGBColorSpace && 'COLOR_0' in attributes ) {
|
|
39175
|
-
console.warn( `THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${ColorManagement.workingColorSpace}" not supported.` );
|
|
39176
|
-
}
|
|
39177
|
-
assignExtrasToUserData( geometry, primitiveDef );
|
|
39178
|
-
computeBounds( geometry, primitiveDef, parser );
|
|
39179
|
-
return Promise.all( pending ).then( function () {
|
|
39180
|
-
return primitiveDef.targets !== undefined
|
|
39181
|
-
? addMorphTargets( geometry, primitiveDef.targets, parser )
|
|
39182
|
-
: geometry;
|
|
39183
|
-
} );
|
|
39184
|
-
}
|
|
39185
|
-
|
|
39186
|
-
class GLTFLoadingManager extends LoadingManager {
|
|
39187
|
-
constructor(file, params = {}) {
|
|
39188
|
-
super();
|
|
39189
|
-
this.path = "";
|
|
39190
|
-
this.resourcePath = "";
|
|
39191
|
-
this.fileURL = "";
|
|
39192
|
-
this.dataURLs = new Map();
|
|
39193
|
-
this.path = params.path || "";
|
|
39194
|
-
const externalFiles = params.externalFiles || new Map();
|
|
39195
|
-
if (typeof file === "string") {
|
|
39196
|
-
this.fileURL = file;
|
|
39197
|
-
this.resourcePath = LoaderUtils.extractUrlBase(file);
|
|
39198
|
-
}
|
|
39199
|
-
else {
|
|
39200
|
-
externalFiles.forEach((value, key) => (this.fileURL = value === file ? key : this.fileURL));
|
|
39201
|
-
externalFiles.set(this.fileURL, file);
|
|
39202
|
-
}
|
|
39203
|
-
externalFiles.forEach((value, key) => {
|
|
39204
|
-
let dataURL;
|
|
39205
|
-
if (typeof value === "string")
|
|
39206
|
-
dataURL = value;
|
|
39207
|
-
else
|
|
39208
|
-
dataURL = URL.createObjectURL(new Blob([value]));
|
|
39209
|
-
this.dataURLs.set(key, dataURL);
|
|
39210
|
-
});
|
|
39211
|
-
this.setURLModifier((url) => {
|
|
39212
|
-
const key = decodeURI(url)
|
|
39213
|
-
.replace(this.path, "")
|
|
39214
|
-
.replace(this.resourcePath, "")
|
|
39215
|
-
.replace(/^(\.?\/)/, "");
|
|
39216
|
-
const dataURL = this.dataURLs.get(key);
|
|
39217
|
-
return dataURL !== null && dataURL !== void 0 ? dataURL : url;
|
|
39218
|
-
});
|
|
39219
|
-
}
|
|
39220
|
-
dispose() {
|
|
39221
|
-
this.dataURLs.forEach(URL.revokeObjectURL);
|
|
39222
|
-
}
|
|
39223
|
-
}
|
|
39224
|
-
|
|
39225
36747
|
class ModelImpl {
|
|
39226
36748
|
constructor(scene) {
|
|
39227
|
-
this.handle = "1";
|
|
39228
36749
|
this.scene = scene;
|
|
39229
36750
|
}
|
|
39230
36751
|
dispose() {
|
|
@@ -39244,6 +36765,18 @@ void main() {
|
|
|
39244
36765
|
this.scene.traverse(disposeObject);
|
|
39245
36766
|
this.scene.clear();
|
|
39246
36767
|
}
|
|
36768
|
+
getUnits() {
|
|
36769
|
+
return "Meters";
|
|
36770
|
+
}
|
|
36771
|
+
getUnitScale() {
|
|
36772
|
+
return convertUnits(this.getUnits(), "Meters", 1);
|
|
36773
|
+
}
|
|
36774
|
+
getUnitString() {
|
|
36775
|
+
return getDisplayUnit(this.getUnits());
|
|
36776
|
+
}
|
|
36777
|
+
getPrecision() {
|
|
36778
|
+
return 2;
|
|
36779
|
+
}
|
|
39247
36780
|
getExtents(target) {
|
|
39248
36781
|
this.scene.traverseVisible((object) => !object.children.length && target.expandByObject(object));
|
|
39249
36782
|
return target;
|
|
@@ -39266,27 +36799,45 @@ void main() {
|
|
|
39266
36799
|
}
|
|
39267
36800
|
return false;
|
|
39268
36801
|
}
|
|
36802
|
+
hasHandle(handle) {
|
|
36803
|
+
return !handle.includes(":") || handle.split(":", 1)[0] === this.id + "";
|
|
36804
|
+
}
|
|
39269
36805
|
getOwnObjects(objects) {
|
|
39270
36806
|
if (!Array.isArray(objects))
|
|
39271
36807
|
objects = [objects];
|
|
39272
36808
|
return objects.filter((object) => this.hasObject(object));
|
|
39273
36809
|
}
|
|
36810
|
+
getOwnHandles(handles) {
|
|
36811
|
+
if (!Array.isArray(handles))
|
|
36812
|
+
handles = [handles];
|
|
36813
|
+
return handles.filter((handle) => this.hasHandle(handle));
|
|
36814
|
+
}
|
|
39274
36815
|
getObjectsByHandles(handles) {
|
|
39275
|
-
const
|
|
36816
|
+
const ownHandles = this.getOwnHandles(handles);
|
|
36817
|
+
if (ownHandles.length === 0)
|
|
36818
|
+
return [];
|
|
36819
|
+
const handleSet = new Set(ownHandles.map((handle) => handle.slice(handle.indexOf(":") + 1)));
|
|
39276
36820
|
const objects = [];
|
|
39277
|
-
this.scene.traverse((object) =>
|
|
36821
|
+
this.scene.traverse((object) => {
|
|
36822
|
+
const handle = object.userData.handle;
|
|
36823
|
+
if (handle && handleSet.has(handle))
|
|
36824
|
+
objects.push(object);
|
|
36825
|
+
});
|
|
39278
36826
|
return objects;
|
|
39279
36827
|
}
|
|
39280
36828
|
getHandlesByObjects(objects) {
|
|
39281
|
-
|
|
39282
|
-
|
|
39283
|
-
|
|
39284
|
-
|
|
39285
|
-
|
|
36829
|
+
const ownObjects = this.getOwnObjects(objects);
|
|
36830
|
+
if (ownObjects.length === 0)
|
|
36831
|
+
return [];
|
|
36832
|
+
const handleSet = new Set();
|
|
36833
|
+
ownObjects.forEach((object) => {
|
|
36834
|
+
const handle = object.userData.handle;
|
|
36835
|
+
if (handle)
|
|
36836
|
+
handleSet.add(`${this.id}:${handle}`);
|
|
36837
|
+
});
|
|
36838
|
+
return Array.from(handleSet);
|
|
39286
36839
|
}
|
|
39287
36840
|
hideObjects(objects) {
|
|
39288
|
-
if (!Array.isArray(objects))
|
|
39289
|
-
objects = [objects];
|
|
39290
36841
|
this.getOwnObjects(objects).forEach((object) => (object.visible = false));
|
|
39291
36842
|
return this;
|
|
39292
36843
|
}
|
|
@@ -39302,8 +36853,6 @@ void main() {
|
|
|
39302
36853
|
return this;
|
|
39303
36854
|
}
|
|
39304
36855
|
showObjects(objects) {
|
|
39305
|
-
if (!Array.isArray(objects))
|
|
39306
|
-
objects = [objects];
|
|
39307
36856
|
this.getOwnObjects(objects).forEach((object) => {
|
|
39308
36857
|
object.visible = true;
|
|
39309
36858
|
object.traverseAncestors((parent) => (parent.visible = true));
|
|
@@ -39359,42 +36908,6 @@ void main() {
|
|
|
39359
36908
|
}
|
|
39360
36909
|
}
|
|
39361
36910
|
|
|
39362
|
-
class GLTFFileLoader extends Loader$1 {
|
|
39363
|
-
constructor(viewer) {
|
|
39364
|
-
super();
|
|
39365
|
-
this.viewer = viewer;
|
|
39366
|
-
}
|
|
39367
|
-
isSupport(file, format) {
|
|
39368
|
-
return ((typeof file === "string" || file instanceof globalThis.File || file instanceof ArrayBuffer) &&
|
|
39369
|
-
/(gltf|glb)$/i.test(format));
|
|
39370
|
-
}
|
|
39371
|
-
async load(file, format, params) {
|
|
39372
|
-
const manager = new GLTFLoadingManager(file, params);
|
|
39373
|
-
const loader = new GLTFLoader(manager);
|
|
39374
|
-
loader.setPath(manager.path);
|
|
39375
|
-
loader.setCrossOrigin(params.crossOrigin || loader.crossOrigin);
|
|
39376
|
-
loader.setWithCredentials(params.withCredentials || loader.withCredentials);
|
|
39377
|
-
const progress = (event) => {
|
|
39378
|
-
const { lengthComputable, loaded, total } = event;
|
|
39379
|
-
const progress = lengthComputable ? loaded / total : 1;
|
|
39380
|
-
this.viewer.emitEvent({ type: "geometryprogress", data: progress, file });
|
|
39381
|
-
};
|
|
39382
|
-
const gltf = await loader.loadAsync(manager.fileURL, progress);
|
|
39383
|
-
if (!this.viewer.scene)
|
|
39384
|
-
return this;
|
|
39385
|
-
const modelImpl = new ModelImpl(gltf.scene);
|
|
39386
|
-
modelImpl.loader = this;
|
|
39387
|
-
modelImpl.viewer = this.viewer;
|
|
39388
|
-
this.viewer.scene.add(gltf.scene);
|
|
39389
|
-
this.viewer.models.push(modelImpl);
|
|
39390
|
-
this.viewer.syncOptions();
|
|
39391
|
-
this.viewer.syncOverlay();
|
|
39392
|
-
this.viewer.update();
|
|
39393
|
-
this.viewer.emitEvent({ type: "databasechunk", data: gltf.scene, file });
|
|
39394
|
-
return this;
|
|
39395
|
-
}
|
|
39396
|
-
}
|
|
39397
|
-
|
|
39398
36911
|
class DynamicModelImpl extends ModelImpl {
|
|
39399
36912
|
getExtents(target) {
|
|
39400
36913
|
return target.union(this.gltfLoader.getTotalGeometryExtent());
|
|
@@ -39413,31 +36926,40 @@ void main() {
|
|
|
39413
36926
|
return this.gltfLoader.originalObjects.has(object);
|
|
39414
36927
|
}
|
|
39415
36928
|
getObjectsByHandles(handles) {
|
|
39416
|
-
const
|
|
36929
|
+
const ownHandles = this.getOwnHandles(handles);
|
|
36930
|
+
if (ownHandles.length === 0)
|
|
36931
|
+
return [];
|
|
36932
|
+
const handlesSet = new Set(ownHandles);
|
|
39417
36933
|
const objects = [];
|
|
39418
36934
|
handlesSet.forEach((handle) => {
|
|
39419
|
-
|
|
39420
|
-
const handles = this.gltfLoader.handleToObjects.get(handle2) || [];
|
|
39421
|
-
objects.push(...Array.from(handles));
|
|
36935
|
+
objects.push(...this.gltfLoader.getObjectsByHandle(handle));
|
|
39422
36936
|
});
|
|
39423
36937
|
return objects;
|
|
39424
36938
|
}
|
|
39425
36939
|
getHandlesByObjects(objects) {
|
|
39426
|
-
const
|
|
39427
|
-
|
|
36940
|
+
const ownObjects = this.getOwnObjects(objects);
|
|
36941
|
+
if (ownObjects.length === 0)
|
|
36942
|
+
return [];
|
|
36943
|
+
const handleSet = new Set();
|
|
36944
|
+
ownObjects.forEach((object) => {
|
|
36945
|
+
const handle = object.userData.handle;
|
|
36946
|
+
if (handle)
|
|
36947
|
+
handleSet.add(handle);
|
|
36948
|
+
});
|
|
36949
|
+
return Array.from(handleSet);
|
|
39428
36950
|
}
|
|
39429
36951
|
hideObjects(objects) {
|
|
39430
|
-
const handles =
|
|
36952
|
+
const handles = this.getHandlesByObjects(objects);
|
|
39431
36953
|
this.gltfLoader.hideObjects(handles);
|
|
39432
36954
|
return this;
|
|
39433
36955
|
}
|
|
39434
36956
|
isolateObjects(objects) {
|
|
39435
|
-
const handles =
|
|
36957
|
+
const handles = this.getHandlesByObjects(objects);
|
|
39436
36958
|
this.gltfLoader.isolateObjects(new Set(handles));
|
|
39437
36959
|
return this;
|
|
39438
36960
|
}
|
|
39439
36961
|
showObjects(objects) {
|
|
39440
|
-
const handles =
|
|
36962
|
+
const handles = this.getHandlesByObjects(objects);
|
|
39441
36963
|
this.gltfLoader.showObjects(handles);
|
|
39442
36964
|
return this;
|
|
39443
36965
|
}
|
|
@@ -39501,11 +37023,14 @@ void main() {
|
|
|
39501
37023
|
this.materials = new Map();
|
|
39502
37024
|
this.textureCache = new Map();
|
|
39503
37025
|
this.materialCache = new Map();
|
|
37026
|
+
this.uri = "";
|
|
37027
|
+
this._nextObjectId = 0;
|
|
39504
37028
|
}
|
|
39505
37029
|
async initialize(loader) {
|
|
39506
37030
|
this.json = await this.loadController.loadJson();
|
|
39507
37031
|
this.baseUrl = await this.loadController.baseUrl();
|
|
39508
37032
|
this.loader = loader;
|
|
37033
|
+
this.uri = this.json.buffers[0].uri || "";
|
|
39509
37034
|
}
|
|
39510
37035
|
clear() {
|
|
39511
37036
|
this.json = null;
|
|
@@ -39599,7 +37124,7 @@ void main() {
|
|
|
39599
37124
|
await this.loader.waitForChunkSlot();
|
|
39600
37125
|
try {
|
|
39601
37126
|
const length = range.end - range.start;
|
|
39602
|
-
const buffer = await this.loadController.loadBinaryData([{ offset: range.start, length }]);
|
|
37127
|
+
const buffer = await this.loadController.loadBinaryData([{ offset: range.start, length }], this.uri);
|
|
39603
37128
|
for (const req of range.requests) {
|
|
39604
37129
|
const relOffset = req.offset - range.start;
|
|
39605
37130
|
try {
|
|
@@ -39916,6 +37441,156 @@ void main() {
|
|
|
39916
37441
|
}
|
|
39917
37442
|
}
|
|
39918
37443
|
|
|
37444
|
+
function mergeGeometries( geometries, useGroups = false ) {
|
|
37445
|
+
const isIndexed = geometries[ 0 ].index !== null;
|
|
37446
|
+
const attributesUsed = new Set( Object.keys( geometries[ 0 ].attributes ) );
|
|
37447
|
+
const morphAttributesUsed = new Set( Object.keys( geometries[ 0 ].morphAttributes ) );
|
|
37448
|
+
const attributes = {};
|
|
37449
|
+
const morphAttributes = {};
|
|
37450
|
+
const morphTargetsRelative = geometries[ 0 ].morphTargetsRelative;
|
|
37451
|
+
const mergedGeometry = new BufferGeometry();
|
|
37452
|
+
let offset = 0;
|
|
37453
|
+
for ( let i = 0; i < geometries.length; ++ i ) {
|
|
37454
|
+
const geometry = geometries[ i ];
|
|
37455
|
+
let attributesCount = 0;
|
|
37456
|
+
if ( isIndexed !== ( geometry.index !== null ) ) {
|
|
37457
|
+
console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.' );
|
|
37458
|
+
return null;
|
|
37459
|
+
}
|
|
37460
|
+
for ( const name in geometry.attributes ) {
|
|
37461
|
+
if ( ! attributesUsed.has( name ) ) {
|
|
37462
|
+
console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. All geometries must have compatible attributes; make sure "' + name + '" attribute exists among all geometries, or in none of them.' );
|
|
37463
|
+
return null;
|
|
37464
|
+
}
|
|
37465
|
+
if ( attributes[ name ] === undefined ) attributes[ name ] = [];
|
|
37466
|
+
attributes[ name ].push( geometry.attributes[ name ] );
|
|
37467
|
+
attributesCount ++;
|
|
37468
|
+
}
|
|
37469
|
+
if ( attributesCount !== attributesUsed.size ) {
|
|
37470
|
+
console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. Make sure all geometries have the same number of attributes.' );
|
|
37471
|
+
return null;
|
|
37472
|
+
}
|
|
37473
|
+
if ( morphTargetsRelative !== geometry.morphTargetsRelative ) {
|
|
37474
|
+
console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. .morphTargetsRelative must be consistent throughout all geometries.' );
|
|
37475
|
+
return null;
|
|
37476
|
+
}
|
|
37477
|
+
for ( const name in geometry.morphAttributes ) {
|
|
37478
|
+
if ( ! morphAttributesUsed.has( name ) ) {
|
|
37479
|
+
console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. .morphAttributes must be consistent throughout all geometries.' );
|
|
37480
|
+
return null;
|
|
37481
|
+
}
|
|
37482
|
+
if ( morphAttributes[ name ] === undefined ) morphAttributes[ name ] = [];
|
|
37483
|
+
morphAttributes[ name ].push( geometry.morphAttributes[ name ] );
|
|
37484
|
+
}
|
|
37485
|
+
if ( useGroups ) {
|
|
37486
|
+
let count;
|
|
37487
|
+
if ( isIndexed ) {
|
|
37488
|
+
count = geometry.index.count;
|
|
37489
|
+
} else if ( geometry.attributes.position !== undefined ) {
|
|
37490
|
+
count = geometry.attributes.position.count;
|
|
37491
|
+
} else {
|
|
37492
|
+
console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. The geometry must have either an index or a position attribute' );
|
|
37493
|
+
return null;
|
|
37494
|
+
}
|
|
37495
|
+
mergedGeometry.addGroup( offset, count, i );
|
|
37496
|
+
offset += count;
|
|
37497
|
+
}
|
|
37498
|
+
}
|
|
37499
|
+
if ( isIndexed ) {
|
|
37500
|
+
let indexOffset = 0;
|
|
37501
|
+
const mergedIndex = [];
|
|
37502
|
+
for ( let i = 0; i < geometries.length; ++ i ) {
|
|
37503
|
+
const index = geometries[ i ].index;
|
|
37504
|
+
for ( let j = 0; j < index.count; ++ j ) {
|
|
37505
|
+
mergedIndex.push( index.getX( j ) + indexOffset );
|
|
37506
|
+
}
|
|
37507
|
+
indexOffset += geometries[ i ].attributes.position.count;
|
|
37508
|
+
}
|
|
37509
|
+
mergedGeometry.setIndex( mergedIndex );
|
|
37510
|
+
}
|
|
37511
|
+
for ( const name in attributes ) {
|
|
37512
|
+
const mergedAttribute = mergeAttributes( attributes[ name ] );
|
|
37513
|
+
if ( ! mergedAttribute ) {
|
|
37514
|
+
console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the ' + name + ' attribute.' );
|
|
37515
|
+
return null;
|
|
37516
|
+
}
|
|
37517
|
+
mergedGeometry.setAttribute( name, mergedAttribute );
|
|
37518
|
+
}
|
|
37519
|
+
for ( const name in morphAttributes ) {
|
|
37520
|
+
const numMorphTargets = morphAttributes[ name ][ 0 ].length;
|
|
37521
|
+
if ( numMorphTargets === 0 ) break;
|
|
37522
|
+
mergedGeometry.morphAttributes = mergedGeometry.morphAttributes || {};
|
|
37523
|
+
mergedGeometry.morphAttributes[ name ] = [];
|
|
37524
|
+
for ( let i = 0; i < numMorphTargets; ++ i ) {
|
|
37525
|
+
const morphAttributesToMerge = [];
|
|
37526
|
+
for ( let j = 0; j < morphAttributes[ name ].length; ++ j ) {
|
|
37527
|
+
morphAttributesToMerge.push( morphAttributes[ name ][ j ][ i ] );
|
|
37528
|
+
}
|
|
37529
|
+
const mergedMorphAttribute = mergeAttributes( morphAttributesToMerge );
|
|
37530
|
+
if ( ! mergedMorphAttribute ) {
|
|
37531
|
+
console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the ' + name + ' morphAttribute.' );
|
|
37532
|
+
return null;
|
|
37533
|
+
}
|
|
37534
|
+
mergedGeometry.morphAttributes[ name ].push( mergedMorphAttribute );
|
|
37535
|
+
}
|
|
37536
|
+
}
|
|
37537
|
+
return mergedGeometry;
|
|
37538
|
+
}
|
|
37539
|
+
function mergeAttributes( attributes ) {
|
|
37540
|
+
let TypedArray;
|
|
37541
|
+
let itemSize;
|
|
37542
|
+
let normalized;
|
|
37543
|
+
let gpuType = -1;
|
|
37544
|
+
let arrayLength = 0;
|
|
37545
|
+
for ( let i = 0; i < attributes.length; ++ i ) {
|
|
37546
|
+
const attribute = attributes[ i ];
|
|
37547
|
+
if ( TypedArray === undefined ) TypedArray = attribute.array.constructor;
|
|
37548
|
+
if ( TypedArray !== attribute.array.constructor ) {
|
|
37549
|
+
console.error( 'THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes.' );
|
|
37550
|
+
return null;
|
|
37551
|
+
}
|
|
37552
|
+
if ( itemSize === undefined ) itemSize = attribute.itemSize;
|
|
37553
|
+
if ( itemSize !== attribute.itemSize ) {
|
|
37554
|
+
console.error( 'THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes.' );
|
|
37555
|
+
return null;
|
|
37556
|
+
}
|
|
37557
|
+
if ( normalized === undefined ) normalized = attribute.normalized;
|
|
37558
|
+
if ( normalized !== attribute.normalized ) {
|
|
37559
|
+
console.error( 'THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes.' );
|
|
37560
|
+
return null;
|
|
37561
|
+
}
|
|
37562
|
+
if ( gpuType === -1 ) gpuType = attribute.gpuType;
|
|
37563
|
+
if ( gpuType !== attribute.gpuType ) {
|
|
37564
|
+
console.error( 'THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes.' );
|
|
37565
|
+
return null;
|
|
37566
|
+
}
|
|
37567
|
+
arrayLength += attribute.count * itemSize;
|
|
37568
|
+
}
|
|
37569
|
+
const array = new TypedArray( arrayLength );
|
|
37570
|
+
const result = new BufferAttribute( array, itemSize, normalized );
|
|
37571
|
+
let offset = 0;
|
|
37572
|
+
for ( let i = 0; i < attributes.length; ++ i ) {
|
|
37573
|
+
const attribute = attributes[ i ];
|
|
37574
|
+
if ( attribute.isInterleavedBufferAttribute ) {
|
|
37575
|
+
const tupleOffset = offset / itemSize;
|
|
37576
|
+
for ( let j = 0, l = attribute.count; j < l; j ++ ) {
|
|
37577
|
+
for ( let c = 0; c < itemSize; c ++ ) {
|
|
37578
|
+
const value = attribute.getComponent( j, c );
|
|
37579
|
+
result.setComponent( j + tupleOffset, c, value );
|
|
37580
|
+
}
|
|
37581
|
+
}
|
|
37582
|
+
} else {
|
|
37583
|
+
array.set( attribute.array, offset );
|
|
37584
|
+
}
|
|
37585
|
+
offset += attribute.count * itemSize;
|
|
37586
|
+
}
|
|
37587
|
+
if ( gpuType !== undefined ) {
|
|
37588
|
+
result.gpuType = gpuType;
|
|
37589
|
+
}
|
|
37590
|
+
return result;
|
|
37591
|
+
}
|
|
37592
|
+
|
|
37593
|
+
const STRUCTURE_ID_SEPARATOR = ":";
|
|
39919
37594
|
class DynamicGltfLoader {
|
|
39920
37595
|
constructor(camera, scene, renderer) {
|
|
39921
37596
|
this.camera = camera;
|
|
@@ -39928,6 +37603,7 @@ void main() {
|
|
|
39928
37603
|
geometryerror: [],
|
|
39929
37604
|
update: [],
|
|
39930
37605
|
geometrymemory: [],
|
|
37606
|
+
optimizationprogress: [],
|
|
39931
37607
|
};
|
|
39932
37608
|
this.loadDistance = 100;
|
|
39933
37609
|
this.unloadDistance = 150;
|
|
@@ -39969,7 +37645,6 @@ void main() {
|
|
|
39969
37645
|
this.hiddenHandles = new Set();
|
|
39970
37646
|
this.newOptimizedObjects = new Set();
|
|
39971
37647
|
this.oldOptimizeObjects = new Set();
|
|
39972
|
-
this.maxConcurrentChunks = 8;
|
|
39973
37648
|
this.activeChunkLoads = 0;
|
|
39974
37649
|
this.chunkQueue = [];
|
|
39975
37650
|
this.objectIdToIndex = new Map();
|
|
@@ -39978,6 +37653,7 @@ void main() {
|
|
|
39978
37653
|
this.maxConcurrentChunks = 6;
|
|
39979
37654
|
this.mergedObjectMap = new Map();
|
|
39980
37655
|
this.mergedGeometryVisibility = new Map();
|
|
37656
|
+
this._webglInfoCache = null;
|
|
39981
37657
|
}
|
|
39982
37658
|
setVisibleEdges(visible) {
|
|
39983
37659
|
this.visibleEdges = visible;
|
|
@@ -40081,6 +37757,123 @@ void main() {
|
|
|
40081
37757
|
this.updateMemoryIndicator();
|
|
40082
37758
|
console.log(`Final memory usage: ${Math.round(currentMemoryUsage / (1024 * 1024))}MB`);
|
|
40083
37759
|
}
|
|
37760
|
+
getStats() {
|
|
37761
|
+
let totalObjects = 0;
|
|
37762
|
+
let renderedObjects = 0;
|
|
37763
|
+
let totalTriangles = 0;
|
|
37764
|
+
let renderedTriangles = 0;
|
|
37765
|
+
let totalLines = 0;
|
|
37766
|
+
let renderedLines = 0;
|
|
37767
|
+
let totalEdges = 0;
|
|
37768
|
+
let renderedEdges = 0;
|
|
37769
|
+
this.scene.traverse((object) => {
|
|
37770
|
+
totalObjects++;
|
|
37771
|
+
const geometry = object.geometry;
|
|
37772
|
+
if (!geometry) return;
|
|
37773
|
+
let triCount = 0;
|
|
37774
|
+
if (geometry.index) {
|
|
37775
|
+
triCount = Math.floor(geometry.index.count / 3);
|
|
37776
|
+
} else if (geometry.attributes && geometry.attributes.position) {
|
|
37777
|
+
triCount = Math.floor(geometry.attributes.position.count / 3);
|
|
37778
|
+
}
|
|
37779
|
+
totalTriangles += triCount;
|
|
37780
|
+
let lineCount = 0;
|
|
37781
|
+
if (geometry.index) {
|
|
37782
|
+
lineCount = Math.floor(geometry.index.count / 2);
|
|
37783
|
+
} else if (geometry.attributes && geometry.attributes.position) {
|
|
37784
|
+
lineCount = Math.floor(geometry.attributes.position.count / 2);
|
|
37785
|
+
}
|
|
37786
|
+
if (object.type === "Line" || object.type === "LineSegments" || object.type === "LineLoop") {
|
|
37787
|
+
if (object.userData.isEdge) {
|
|
37788
|
+
totalEdges += lineCount;
|
|
37789
|
+
} else {
|
|
37790
|
+
totalLines += lineCount;
|
|
37791
|
+
}
|
|
37792
|
+
}
|
|
37793
|
+
if (object.visible !== false) {
|
|
37794
|
+
if (object.isMesh || object.isLine || object.isPoints) {
|
|
37795
|
+
renderedObjects++;
|
|
37796
|
+
if (object.isMesh) {
|
|
37797
|
+
renderedTriangles += triCount;
|
|
37798
|
+
} else if (object.type === "Line" || object.type === "LineSegments" || object.type === "LineLoop") {
|
|
37799
|
+
if (object.userData.isEdge) {
|
|
37800
|
+
renderedEdges += lineCount;
|
|
37801
|
+
} else {
|
|
37802
|
+
renderedLines += lineCount;
|
|
37803
|
+
}
|
|
37804
|
+
}
|
|
37805
|
+
}
|
|
37806
|
+
}
|
|
37807
|
+
});
|
|
37808
|
+
const geometryCount = this.geometryCache ? this.geometryCache.size : 0;
|
|
37809
|
+
const geometryMemoryBytes = Array.from(this.geometryCache?.values?.() || []).reduce((a, b) => a + b, 0);
|
|
37810
|
+
const uniqueMaterialIds = new Set();
|
|
37811
|
+
const uniqueTextureIds = new Set();
|
|
37812
|
+
if (Array.isArray(this.structures)) {
|
|
37813
|
+
for (const structure of this.structures) {
|
|
37814
|
+
console.log(structure.materialCache.values());
|
|
37815
|
+
try {
|
|
37816
|
+
for (const entry of structure.materialCache.values()) {
|
|
37817
|
+
if (entry?.mesh?.uuid) uniqueMaterialIds.add(entry.mesh.uuid);
|
|
37818
|
+
if (entry?.points?.uuid) uniqueMaterialIds.add(entry.points.uuid);
|
|
37819
|
+
if (entry?.lines?.uuid) uniqueMaterialIds.add(entry.lines.uuid);
|
|
37820
|
+
}
|
|
37821
|
+
} catch (exp) {
|
|
37822
|
+
console.error("Error adding material to uniqueMaterialIds", exp);
|
|
37823
|
+
}
|
|
37824
|
+
}
|
|
37825
|
+
}
|
|
37826
|
+
const materialCount = uniqueMaterialIds.size;
|
|
37827
|
+
const textureCount = uniqueTextureIds.size;
|
|
37828
|
+
const estimatedGpuMemoryBytes = geometryMemoryBytes;
|
|
37829
|
+
if (!this._webglInfoCache) {
|
|
37830
|
+
try {
|
|
37831
|
+
const gl = this.renderer.getContext();
|
|
37832
|
+
const dbgInfo = gl.getExtension("WEBGL_debug_renderer_info");
|
|
37833
|
+
if (dbgInfo) {
|
|
37834
|
+
const rendererStr = gl.getParameter(dbgInfo.UNMASKED_RENDERER_WEBGL);
|
|
37835
|
+
const vendorStr = gl.getParameter(dbgInfo.UNMASKED_VENDOR_WEBGL);
|
|
37836
|
+
this._webglInfoCache = { renderer: rendererStr, vendor: vendorStr };
|
|
37837
|
+
} else {
|
|
37838
|
+
this._webglInfoCache = { renderer: null, vendor: null };
|
|
37839
|
+
}
|
|
37840
|
+
} catch (e) {
|
|
37841
|
+
console.error("Error getting webgl info", e);
|
|
37842
|
+
this._webglInfoCache = { renderer: null, vendor: null };
|
|
37843
|
+
}
|
|
37844
|
+
}
|
|
37845
|
+
const size = new Vector2();
|
|
37846
|
+
if (this.renderer && this.renderer.getSize) {
|
|
37847
|
+
this.renderer.getSize(size);
|
|
37848
|
+
}
|
|
37849
|
+
return {
|
|
37850
|
+
scene: {
|
|
37851
|
+
beforeOptimization: {
|
|
37852
|
+
objects: totalObjects - renderedObjects,
|
|
37853
|
+
triangles: totalTriangles - renderedTriangles,
|
|
37854
|
+
lines: totalLines - renderedLines,
|
|
37855
|
+
edges: totalEdges - renderedEdges,
|
|
37856
|
+
},
|
|
37857
|
+
afterOptimization: {
|
|
37858
|
+
objects: renderedObjects,
|
|
37859
|
+
triangles: renderedTriangles,
|
|
37860
|
+
lines: renderedLines,
|
|
37861
|
+
edges: renderedEdges,
|
|
37862
|
+
},
|
|
37863
|
+
},
|
|
37864
|
+
memory: {
|
|
37865
|
+
geometries: { count: geometryCount, bytes: geometryMemoryBytes },
|
|
37866
|
+
textures: { count: textureCount },
|
|
37867
|
+
materials: { count: materialCount },
|
|
37868
|
+
totalEstimatedGpuBytes: estimatedGpuMemoryBytes,
|
|
37869
|
+
},
|
|
37870
|
+
system: {
|
|
37871
|
+
webglRenderer: this._webglInfoCache?.renderer || "",
|
|
37872
|
+
webglVendor: this._webglInfoCache?.vendor || "",
|
|
37873
|
+
viewport: { width: size.x || 0, height: size.y || 0 },
|
|
37874
|
+
},
|
|
37875
|
+
};
|
|
37876
|
+
}
|
|
40084
37877
|
async loadNode(nodeId, onLoadFinishCb) {
|
|
40085
37878
|
const node = this.nodes.get(nodeId);
|
|
40086
37879
|
if (!node || node.loaded || node.loading) return;
|
|
@@ -40251,7 +38044,7 @@ void main() {
|
|
|
40251
38044
|
if (node.handle) {
|
|
40252
38045
|
mesh.userData.handle = node.handle;
|
|
40253
38046
|
} else {
|
|
40254
|
-
mesh.userData.handle =
|
|
38047
|
+
mesh.userData.handle = this.getFullHandle(node.structure.id, mesh.userData.handle);
|
|
40255
38048
|
}
|
|
40256
38049
|
if (mesh.material.name === "edges") {
|
|
40257
38050
|
mesh.userData.isEdge = true;
|
|
@@ -40392,12 +38185,15 @@ void main() {
|
|
|
40392
38185
|
})),
|
|
40393
38186
|
});
|
|
40394
38187
|
}
|
|
38188
|
+
getFullHandle(structureId, originalHandle) {
|
|
38189
|
+
return `${structureId}${STRUCTURE_ID_SEPARATOR}${originalHandle}`;
|
|
38190
|
+
}
|
|
40395
38191
|
async processNodeHierarchy(structure, nodeId, parentGroup) {
|
|
40396
38192
|
const nodeDef = structure.json.nodes[nodeId];
|
|
40397
38193
|
let nodeGroup = null;
|
|
40398
38194
|
let handle = null;
|
|
40399
38195
|
if (nodeDef.extras?.handle) {
|
|
40400
|
-
handle =
|
|
38196
|
+
handle = this.getFullHandle(structure.id, nodeDef.extras.handle);
|
|
40401
38197
|
}
|
|
40402
38198
|
if (nodeDef.camera !== undefined) {
|
|
40403
38199
|
const camera = this.loadCamera(structure, nodeDef.camera, nodeDef);
|
|
@@ -40414,7 +38210,7 @@ void main() {
|
|
|
40414
38210
|
if (nodeDef.extras) {
|
|
40415
38211
|
nodeGroup.userData = { ...nodeDef.extras };
|
|
40416
38212
|
if (nodeGroup.userData.handle) {
|
|
40417
|
-
nodeGroup.userData.handle =
|
|
38213
|
+
nodeGroup.userData.handle = this.getFullHandle(structure.id, nodeGroup.userData.handle);
|
|
40418
38214
|
}
|
|
40419
38215
|
}
|
|
40420
38216
|
if (nodeDef.matrix) {
|
|
@@ -40459,7 +38255,7 @@ void main() {
|
|
|
40459
38255
|
this.edgeNodes.push(uniqueNodeId);
|
|
40460
38256
|
}
|
|
40461
38257
|
if (meshDef.extras && meshDef.extras.handle) {
|
|
40462
|
-
handle =
|
|
38258
|
+
handle = this.getFullHandle(structure.id, meshDef.extras.handle);
|
|
40463
38259
|
}
|
|
40464
38260
|
this.nodes.set(uniqueNodeId, {
|
|
40465
38261
|
position: nodeGroup ? nodeGroup.position.clone() : new Vector3().setFromMatrixPosition(nodeMatrix),
|
|
@@ -40472,7 +38268,7 @@ void main() {
|
|
|
40472
38268
|
structure,
|
|
40473
38269
|
extras: nodeDef.extras,
|
|
40474
38270
|
geometryExtents,
|
|
40475
|
-
handle,
|
|
38271
|
+
handle: handle || this.getFullHandle(structure.id, structure._nextObjectId++),
|
|
40476
38272
|
});
|
|
40477
38273
|
}
|
|
40478
38274
|
if (nodeDef.children) {
|
|
@@ -40545,12 +38341,12 @@ void main() {
|
|
|
40545
38341
|
}
|
|
40546
38342
|
}
|
|
40547
38343
|
async loadNodes() {
|
|
40548
|
-
console.time("
|
|
38344
|
+
console.time("Process nodes");
|
|
40549
38345
|
await this.processNodes();
|
|
40550
|
-
console.timeEnd("
|
|
40551
|
-
console.time("
|
|
38346
|
+
console.timeEnd("Process nodes");
|
|
38347
|
+
console.time("Optimize scene");
|
|
40552
38348
|
await this.optimizeScene();
|
|
40553
|
-
console.timeEnd("
|
|
38349
|
+
console.timeEnd("Optimize scene");
|
|
40554
38350
|
}
|
|
40555
38351
|
cleanupPartialLoad() {
|
|
40556
38352
|
this.nodesToLoad.forEach((nodeId) => {
|
|
@@ -40871,7 +38667,7 @@ void main() {
|
|
|
40871
38667
|
this.handleToObjects.set(fullHandle, new Set());
|
|
40872
38668
|
}
|
|
40873
38669
|
this.handleToObjects.get(fullHandle).add(object);
|
|
40874
|
-
object.userData.structureId = object.userData.handle.split(
|
|
38670
|
+
object.userData.structureId = object.userData.handle.split(STRUCTURE_ID_SEPARATOR)[0];
|
|
40875
38671
|
}
|
|
40876
38672
|
getObjectsByHandle(handle) {
|
|
40877
38673
|
if (!handle) return [];
|
|
@@ -40937,10 +38733,28 @@ void main() {
|
|
|
40937
38733
|
}
|
|
40938
38734
|
this.originalObjects.add(object);
|
|
40939
38735
|
}
|
|
40940
|
-
|
|
38736
|
+
yieldToUI() {
|
|
38737
|
+
return new Promise((resolve) => {
|
|
38738
|
+
requestAnimationFrame(() => {
|
|
38739
|
+
setTimeout(resolve, 0);
|
|
38740
|
+
});
|
|
38741
|
+
});
|
|
38742
|
+
}
|
|
38743
|
+
async optimizeScene() {
|
|
38744
|
+
console.log("Starting scene optimization...");
|
|
38745
|
+
this.dispatchEvent("optimizationprogress", {
|
|
38746
|
+
phase: "start",
|
|
38747
|
+
progress: 0,
|
|
38748
|
+
message: "Starting optimization...",
|
|
38749
|
+
});
|
|
40941
38750
|
this.originalObjects.clear();
|
|
40942
38751
|
this.originalObjectsToSelection.clear();
|
|
40943
38752
|
const structureGroups = new Map();
|
|
38753
|
+
this.dispatchEvent("optimizationprogress", {
|
|
38754
|
+
phase: "collecting",
|
|
38755
|
+
progress: 5,
|
|
38756
|
+
message: "Collecting scene objects...",
|
|
38757
|
+
});
|
|
40944
38758
|
this.scene.traverse((object) => {
|
|
40945
38759
|
if (object.userData.structureId) {
|
|
40946
38760
|
const structureId = object.userData.structureId;
|
|
@@ -40969,16 +38783,44 @@ void main() {
|
|
|
40969
38783
|
}
|
|
40970
38784
|
}
|
|
40971
38785
|
});
|
|
38786
|
+
let processedGroups = 0;
|
|
38787
|
+
const totalGroups = structureGroups.size;
|
|
38788
|
+
this.dispatchEvent("optimizationprogress", {
|
|
38789
|
+
phase: "merging",
|
|
38790
|
+
progress: 10,
|
|
38791
|
+
message: `Merging ${totalGroups} structure groups...`,
|
|
38792
|
+
current: 0,
|
|
38793
|
+
total: totalGroups,
|
|
38794
|
+
});
|
|
40972
38795
|
for (const group of structureGroups.values()) {
|
|
40973
38796
|
group.mapMeshes.clear();
|
|
40974
38797
|
group.mapLines.clear();
|
|
40975
38798
|
group.mapLineSegments.clear();
|
|
40976
38799
|
group.mapPoints.clear();
|
|
40977
|
-
this.mergeMeshGroups(group.meshes, group.rootGroup);
|
|
40978
|
-
this.
|
|
40979
|
-
this.
|
|
40980
|
-
this.
|
|
38800
|
+
await this.mergeMeshGroups(group.meshes, group.rootGroup);
|
|
38801
|
+
await this.yieldToUI();
|
|
38802
|
+
await this.mergeLineGroups(group.lines, group.rootGroup);
|
|
38803
|
+
await this.yieldToUI();
|
|
38804
|
+
await this.mergeLineSegmentGroups(group.lineSegments, group.rootGroup);
|
|
38805
|
+
await this.yieldToUI();
|
|
38806
|
+
await this.mergePointsGroups(group.points, group.rootGroup);
|
|
38807
|
+
processedGroups++;
|
|
38808
|
+
const progress = 10 + Math.round((processedGroups / totalGroups) * 80);
|
|
38809
|
+
this.dispatchEvent("optimizationprogress", {
|
|
38810
|
+
phase: "merging",
|
|
38811
|
+
progress,
|
|
38812
|
+
message: `Processing structure ${processedGroups}/${totalGroups}...`,
|
|
38813
|
+
current: processedGroups,
|
|
38814
|
+
total: totalGroups,
|
|
38815
|
+
});
|
|
38816
|
+
console.log(`Optimization progress: ${processedGroups}/${totalGroups} structure groups processed (${progress}%)`);
|
|
38817
|
+
await this.yieldToUI();
|
|
40981
38818
|
}
|
|
38819
|
+
this.dispatchEvent("optimizationprogress", {
|
|
38820
|
+
phase: "finalizing",
|
|
38821
|
+
progress: 95,
|
|
38822
|
+
message: "Finalizing optimization...",
|
|
38823
|
+
});
|
|
40982
38824
|
this.originalObjects.forEach((obj) => {
|
|
40983
38825
|
obj.visible = false;
|
|
40984
38826
|
if (!(obj instanceof Points) && !obj.userData.isEdge) {
|
|
@@ -40987,9 +38829,15 @@ void main() {
|
|
|
40987
38829
|
});
|
|
40988
38830
|
this.initializeObjectVisibility();
|
|
40989
38831
|
console.log(`Optimization complete. Total objects: ${this.maxObjectId}`);
|
|
38832
|
+
this.dispatchEvent("optimizationprogress", {
|
|
38833
|
+
phase: "complete",
|
|
38834
|
+
progress: 100,
|
|
38835
|
+
message: `Optimization complete! ${this.maxObjectId} objects processed.`,
|
|
38836
|
+
});
|
|
40990
38837
|
this.dispatchEvent("update");
|
|
40991
38838
|
}
|
|
40992
|
-
mergeMeshGroups(materialGroups, rootGroup) {
|
|
38839
|
+
async mergeMeshGroups(materialGroups, rootGroup) {
|
|
38840
|
+
let processedGroups = 0;
|
|
40993
38841
|
for (const group of materialGroups) {
|
|
40994
38842
|
if (!group.material) {
|
|
40995
38843
|
console.warn("Skipping mesh group with null material");
|
|
@@ -41003,8 +38851,6 @@ void main() {
|
|
|
41003
38851
|
let currentVertexOffset = 0;
|
|
41004
38852
|
for (const mesh of group.objects) {
|
|
41005
38853
|
const geometry = mesh.geometry.clone();
|
|
41006
|
-
mesh.updateWorldMatrix(true, false);
|
|
41007
|
-
geometry.applyMatrix4(mesh.matrixWorld);
|
|
41008
38854
|
const handle = mesh.userData.handle;
|
|
41009
38855
|
if (!this.objectIdToIndex.has(handle)) {
|
|
41010
38856
|
this.objectIdToIndex.set(handle, this.maxObjectId++);
|
|
@@ -41063,6 +38909,10 @@ void main() {
|
|
|
41063
38909
|
this.handleToOptimizedObjects.set(handle, mergedObjects);
|
|
41064
38910
|
}
|
|
41065
38911
|
});
|
|
38912
|
+
processedGroups++;
|
|
38913
|
+
if (processedGroups % 5 === 0) {
|
|
38914
|
+
await this.yieldToUI();
|
|
38915
|
+
}
|
|
41066
38916
|
} catch (error) {
|
|
41067
38917
|
console.error("Failed to merge meshes for material:", error);
|
|
41068
38918
|
group.objects.forEach((mesh) => {
|
|
@@ -41071,7 +38921,8 @@ void main() {
|
|
|
41071
38921
|
}
|
|
41072
38922
|
}
|
|
41073
38923
|
}
|
|
41074
|
-
mergeLineGroups(materialGroups, rootGroup) {
|
|
38924
|
+
async mergeLineGroups(materialGroups, rootGroup) {
|
|
38925
|
+
let processedGroups = 0;
|
|
41075
38926
|
for (const group of materialGroups) {
|
|
41076
38927
|
if (group.objects.length === 0) continue;
|
|
41077
38928
|
if (!group.material) {
|
|
@@ -41090,7 +38941,9 @@ void main() {
|
|
|
41090
38941
|
let posOffset = 0;
|
|
41091
38942
|
const indices = [];
|
|
41092
38943
|
let vertexOffset = 0;
|
|
38944
|
+
let isEdge = false;
|
|
41093
38945
|
group.objects.forEach((line) => {
|
|
38946
|
+
isEdge = line.userData.isEdge;
|
|
41094
38947
|
const geometry = line.geometry;
|
|
41095
38948
|
const positionAttr = geometry.attributes.position;
|
|
41096
38949
|
const vertexCount = positionAttr.count;
|
|
@@ -41103,12 +38956,9 @@ void main() {
|
|
|
41103
38956
|
vertexCount,
|
|
41104
38957
|
});
|
|
41105
38958
|
currentVertexOffset += vertexCount;
|
|
41106
|
-
line.updateWorldMatrix(true, false);
|
|
41107
|
-
const matrix = line.matrixWorld;
|
|
41108
38959
|
const vector = new Vector3();
|
|
41109
38960
|
for (let i = 0; i < vertexCount; i++) {
|
|
41110
38961
|
vector.fromBufferAttribute(positionAttr, i);
|
|
41111
|
-
vector.applyMatrix4(matrix);
|
|
41112
38962
|
positions[posOffset++] = vector.x;
|
|
41113
38963
|
positions[posOffset++] = vector.y;
|
|
41114
38964
|
positions[posOffset++] = vector.z;
|
|
@@ -41141,6 +38991,7 @@ void main() {
|
|
|
41141
38991
|
geometry.setAttribute("visibility", new BufferAttribute(visibilityArray, 1));
|
|
41142
38992
|
const visibilityMaterial = this.createVisibilityMaterial(group.material);
|
|
41143
38993
|
const mergedLine = new LineSegments(geometry, visibilityMaterial);
|
|
38994
|
+
mergedLine.userData.isEdge = isEdge;
|
|
41144
38995
|
const mergedObjects = [mergedLine];
|
|
41145
38996
|
if (this.useVAO) {
|
|
41146
38997
|
this.createVAO(mergedLine);
|
|
@@ -41163,9 +39014,14 @@ void main() {
|
|
|
41163
39014
|
this.handleToOptimizedObjects.set(handle, mergedObjects);
|
|
41164
39015
|
}
|
|
41165
39016
|
});
|
|
39017
|
+
processedGroups++;
|
|
39018
|
+
if (processedGroups % 5 === 0) {
|
|
39019
|
+
await this.yieldToUI();
|
|
39020
|
+
}
|
|
41166
39021
|
}
|
|
41167
39022
|
}
|
|
41168
|
-
mergeLineSegmentGroups(materialGroups, rootGroup) {
|
|
39023
|
+
async mergeLineSegmentGroups(materialGroups, rootGroup) {
|
|
39024
|
+
let processedGroups = 0;
|
|
41169
39025
|
for (const group of materialGroups) {
|
|
41170
39026
|
if (!group.material) {
|
|
41171
39027
|
console.warn("Skipping line segment group with null material");
|
|
@@ -41177,10 +39033,10 @@ void main() {
|
|
|
41177
39033
|
const handles = new Set();
|
|
41178
39034
|
const objectMapping = new Map();
|
|
41179
39035
|
let currentVertexOffset = 0;
|
|
39036
|
+
let isEdge = false;
|
|
41180
39037
|
for (const line of group.objects) {
|
|
39038
|
+
isEdge = line.userData.isEdge;
|
|
41181
39039
|
const geometry = line.geometry.clone();
|
|
41182
|
-
line.updateWorldMatrix(true, false);
|
|
41183
|
-
geometry.applyMatrix4(line.matrixWorld);
|
|
41184
39040
|
const handle = line.userData.handle;
|
|
41185
39041
|
if (!this.objectIdToIndex.has(handle)) {
|
|
41186
39042
|
this.objectIdToIndex.set(handle, this.maxObjectId++);
|
|
@@ -41213,6 +39069,7 @@ void main() {
|
|
|
41213
39069
|
mergedGeometry.setAttribute("visibility", new BufferAttribute(visibilityArray, 1));
|
|
41214
39070
|
const visibilityMaterial = this.createVisibilityMaterial(group.material);
|
|
41215
39071
|
const mergedLine = new LineSegments(mergedGeometry, visibilityMaterial);
|
|
39072
|
+
mergedLine.userData.isEdge = isEdge;
|
|
41216
39073
|
if (this.useVAO) {
|
|
41217
39074
|
this.createVAO(mergedLine);
|
|
41218
39075
|
}
|
|
@@ -41239,6 +39096,10 @@ void main() {
|
|
|
41239
39096
|
this.handleToOptimizedObjects.set(handle, mergedObjects);
|
|
41240
39097
|
}
|
|
41241
39098
|
});
|
|
39099
|
+
processedGroups++;
|
|
39100
|
+
if (processedGroups % 5 === 0) {
|
|
39101
|
+
await this.yieldToUI();
|
|
39102
|
+
}
|
|
41242
39103
|
} catch (error) {
|
|
41243
39104
|
console.warn("Failed to merge line segments for material:", error);
|
|
41244
39105
|
group.objects.forEach((line) => {
|
|
@@ -41247,7 +39108,8 @@ void main() {
|
|
|
41247
39108
|
}
|
|
41248
39109
|
}
|
|
41249
39110
|
}
|
|
41250
|
-
mergePointsGroups(materialGroups, rootGroup) {
|
|
39111
|
+
async mergePointsGroups(materialGroups, rootGroup) {
|
|
39112
|
+
let processedGroups = 0;
|
|
41251
39113
|
for (const group of materialGroups) {
|
|
41252
39114
|
if (!group.material) {
|
|
41253
39115
|
console.warn("Skipping points group with null material");
|
|
@@ -41259,8 +39121,6 @@ void main() {
|
|
|
41259
39121
|
const handles = new Set();
|
|
41260
39122
|
for (const points of group.objects) {
|
|
41261
39123
|
const geometry = points.geometry.clone();
|
|
41262
|
-
points.updateWorldMatrix(true, false);
|
|
41263
|
-
geometry.applyMatrix4(points.matrixWorld);
|
|
41264
39124
|
geometries.push(geometry);
|
|
41265
39125
|
optimizedObjects.push(points);
|
|
41266
39126
|
handles.add(points.userData.handle);
|
|
@@ -41289,6 +39149,10 @@ void main() {
|
|
|
41289
39149
|
this.handleToOptimizedObjects.set(handle, mergedObjects);
|
|
41290
39150
|
}
|
|
41291
39151
|
});
|
|
39152
|
+
processedGroups++;
|
|
39153
|
+
if (processedGroups % 5 === 0) {
|
|
39154
|
+
await this.yieldToUI();
|
|
39155
|
+
}
|
|
41292
39156
|
} catch (error) {
|
|
41293
39157
|
console.warn("Failed to merge points for material:", error);
|
|
41294
39158
|
group.objects.forEach((points) => {
|
|
@@ -41307,7 +39171,6 @@ void main() {
|
|
|
41307
39171
|
const hasNormals = lineSegmentsArray.some((segment) => segment.geometry.attributes.normal !== undefined);
|
|
41308
39172
|
lineSegmentsArray.forEach((segment) => {
|
|
41309
39173
|
const clonedGeometry = segment.geometry.clone();
|
|
41310
|
-
segment.updateWorldMatrix(true, false);
|
|
41311
39174
|
clonedGeometry.applyMatrix4(segment.matrixWorld);
|
|
41312
39175
|
if (hasNormals && !clonedGeometry.attributes.normal) {
|
|
41313
39176
|
clonedGeometry.computeVertexNormals();
|
|
@@ -41524,8 +39387,225 @@ void main() {
|
|
|
41524
39387
|
}
|
|
41525
39388
|
}
|
|
41526
39389
|
|
|
41527
|
-
class
|
|
39390
|
+
class GLTFLoadingManager extends LoadingManager {
|
|
39391
|
+
constructor(file, params = {}) {
|
|
39392
|
+
super();
|
|
39393
|
+
this.path = "";
|
|
39394
|
+
this.resourcePath = "";
|
|
39395
|
+
this.fileURL = "";
|
|
39396
|
+
this.dataURLs = new Map();
|
|
39397
|
+
this.path = params.path || "";
|
|
39398
|
+
const externalFiles = params.externalFiles || new Map();
|
|
39399
|
+
if (typeof file === "string") {
|
|
39400
|
+
this.fileURL = file;
|
|
39401
|
+
this.resourcePath = LoaderUtils.extractUrlBase(file);
|
|
39402
|
+
}
|
|
39403
|
+
else {
|
|
39404
|
+
externalFiles.forEach((value, key) => (this.fileURL = value === file ? key : this.fileURL));
|
|
39405
|
+
externalFiles.set(this.fileURL, file);
|
|
39406
|
+
}
|
|
39407
|
+
externalFiles.forEach((value, key) => {
|
|
39408
|
+
let dataURL;
|
|
39409
|
+
if (typeof value === "string")
|
|
39410
|
+
dataURL = value;
|
|
39411
|
+
else
|
|
39412
|
+
dataURL = URL.createObjectURL(new Blob([value]));
|
|
39413
|
+
this.dataURLs.set(key, dataURL);
|
|
39414
|
+
});
|
|
39415
|
+
this.setURLModifier((url) => {
|
|
39416
|
+
const key = decodeURI(url)
|
|
39417
|
+
.replace(this.path, "")
|
|
39418
|
+
.replace(this.resourcePath, "")
|
|
39419
|
+
.replace(/^(\.?\/)/, "");
|
|
39420
|
+
const dataURL = this.dataURLs.get(key);
|
|
39421
|
+
return dataURL !== null && dataURL !== void 0 ? dataURL : url;
|
|
39422
|
+
});
|
|
39423
|
+
}
|
|
39424
|
+
dispose() {
|
|
39425
|
+
this.dataURLs.forEach((dataURL) => URL.revokeObjectURL(dataURL));
|
|
39426
|
+
}
|
|
39427
|
+
}
|
|
39428
|
+
|
|
39429
|
+
const BINARY_EXTENSION_HEADER_MAGIC = "glTF";
|
|
39430
|
+
const BINARY_EXTENSION_HEADER_LENGTH = 12;
|
|
39431
|
+
const BINARY_EXTENSION_CHUNK_TYPES = { JSON: 0x4e4f534a, BIN: 0x004e4042 };
|
|
39432
|
+
class GLTFBinaryExtension {
|
|
39433
|
+
constructor(data) {
|
|
39434
|
+
const headerView = new DataView(data, 0, BINARY_EXTENSION_HEADER_LENGTH);
|
|
39435
|
+
const textDecoder = new TextDecoder();
|
|
39436
|
+
const magic = textDecoder.decode(new Uint8Array(data.slice(0, 4)));
|
|
39437
|
+
if (magic !== BINARY_EXTENSION_HEADER_MAGIC) {
|
|
39438
|
+
this.content = textDecoder.decode(data);
|
|
39439
|
+
return;
|
|
39440
|
+
}
|
|
39441
|
+
const header = {
|
|
39442
|
+
magic,
|
|
39443
|
+
version: headerView.getUint32(4, true),
|
|
39444
|
+
length: headerView.getUint32(8, true),
|
|
39445
|
+
};
|
|
39446
|
+
if (header.magic !== BINARY_EXTENSION_HEADER_MAGIC) {
|
|
39447
|
+
throw new Error("Unsupported glTF-Binary header.");
|
|
39448
|
+
}
|
|
39449
|
+
if (header.version < 2.0) {
|
|
39450
|
+
throw new Error("Legacy binary file detected.");
|
|
39451
|
+
}
|
|
39452
|
+
const chunkContentsLength = header.length - BINARY_EXTENSION_HEADER_LENGTH;
|
|
39453
|
+
const chunkView = new DataView(data, BINARY_EXTENSION_HEADER_LENGTH);
|
|
39454
|
+
let chunkIndex = 0;
|
|
39455
|
+
while (chunkIndex < chunkContentsLength) {
|
|
39456
|
+
const chunkLength = chunkView.getUint32(chunkIndex, true);
|
|
39457
|
+
chunkIndex += 4;
|
|
39458
|
+
const chunkType = chunkView.getUint32(chunkIndex, true);
|
|
39459
|
+
chunkIndex += 4;
|
|
39460
|
+
if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON) {
|
|
39461
|
+
const contentArray = new Uint8Array(data, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength);
|
|
39462
|
+
this.content = textDecoder.decode(contentArray);
|
|
39463
|
+
}
|
|
39464
|
+
else if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.BIN) {
|
|
39465
|
+
const byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex;
|
|
39466
|
+
this.body = data.slice(byteOffset, byteOffset + chunkLength);
|
|
39467
|
+
}
|
|
39468
|
+
chunkIndex += chunkLength;
|
|
39469
|
+
}
|
|
39470
|
+
if (typeof this.content === "undefined") {
|
|
39471
|
+
throw new Error("JSON content not found.");
|
|
39472
|
+
}
|
|
39473
|
+
}
|
|
39474
|
+
}
|
|
39475
|
+
|
|
39476
|
+
class RangesLoader {
|
|
39477
|
+
constructor() {
|
|
39478
|
+
this.requestHeader = {};
|
|
39479
|
+
this.withCredentials = false;
|
|
39480
|
+
this.abortSignal = undefined;
|
|
39481
|
+
}
|
|
39482
|
+
setRequestHeader(requestHeader) {
|
|
39483
|
+
this.requestHeader = requestHeader;
|
|
39484
|
+
}
|
|
39485
|
+
setWithCredentials(withCredentials) {
|
|
39486
|
+
this.withCredentials = withCredentials;
|
|
39487
|
+
}
|
|
39488
|
+
setAbortSignal(abortSignal) {
|
|
39489
|
+
this.abortSignal = abortSignal;
|
|
39490
|
+
}
|
|
39491
|
+
async load(url, ranges) {
|
|
39492
|
+
const init = {
|
|
39493
|
+
headers: {
|
|
39494
|
+
...this.requestHeader,
|
|
39495
|
+
Range: "bytes=" + ranges.map((x) => `${x.offset}-${x.offset + x.length - 1}`).join(","),
|
|
39496
|
+
},
|
|
39497
|
+
credentials: this.withCredentials ? "include" : "same-origin",
|
|
39498
|
+
signal: this.abortSignal,
|
|
39499
|
+
};
|
|
39500
|
+
const response = await fetch(url, init);
|
|
39501
|
+
if (!response.ok) {
|
|
39502
|
+
throw new Error(`Failed to fetch "${url}", status ${response.status}`);
|
|
39503
|
+
}
|
|
39504
|
+
if (response.status !== 206) {
|
|
39505
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
39506
|
+
return this.extractRanges(arrayBuffer, ranges);
|
|
39507
|
+
}
|
|
39508
|
+
return response.arrayBuffer();
|
|
39509
|
+
}
|
|
39510
|
+
extractRanges(arrayBuffer, ranges) {
|
|
39511
|
+
const totalLength = ranges.reduce((sum, range) => sum + range.length, 0);
|
|
39512
|
+
const result = new Uint8Array(totalLength);
|
|
39513
|
+
let offset = 0;
|
|
39514
|
+
for (const range of ranges) {
|
|
39515
|
+
const chunk = new Uint8Array(arrayBuffer, range.offset, range.length);
|
|
39516
|
+
result.set(chunk, offset);
|
|
39517
|
+
offset += range.length;
|
|
39518
|
+
}
|
|
39519
|
+
return result.buffer;
|
|
39520
|
+
}
|
|
39521
|
+
}
|
|
39522
|
+
|
|
39523
|
+
class GLTFFileDynamicLoader extends Loader$1 {
|
|
39524
|
+
constructor(viewer) {
|
|
39525
|
+
super();
|
|
39526
|
+
this.viewer = viewer;
|
|
39527
|
+
}
|
|
39528
|
+
dispose() {
|
|
39529
|
+
if (this.gltfLoader)
|
|
39530
|
+
this.gltfLoader.clear();
|
|
39531
|
+
if (this.manager)
|
|
39532
|
+
this.manager.dispose();
|
|
39533
|
+
}
|
|
39534
|
+
isSupport(file, format) {
|
|
39535
|
+
return ((typeof file === "string" || file instanceof globalThis.File || file instanceof ArrayBuffer) &&
|
|
39536
|
+
/(gltf|glb)$/i.test(format));
|
|
39537
|
+
}
|
|
39538
|
+
async load(file, format, params) {
|
|
39539
|
+
this.manager = new GLTFLoadingManager(file, params);
|
|
39540
|
+
const scene = new Group$1();
|
|
39541
|
+
this.gltfLoader = new DynamicGltfLoader(this.viewer.camera, scene, this.viewer.renderer);
|
|
39542
|
+
this.gltfLoader.memoryLimit = this.viewer.options.memoryLimit;
|
|
39543
|
+
this.gltfLoader.visibleEdges = this.viewer.options.edgeModel;
|
|
39544
|
+
const modelImpl = new DynamicModelImpl(scene);
|
|
39545
|
+
modelImpl.id = params.modelId || this.extractFileName(file);
|
|
39546
|
+
modelImpl.gltfLoader = this.gltfLoader;
|
|
39547
|
+
this.gltfLoader.addEventListener("databasechunk", () => {
|
|
39548
|
+
this.viewer.scene.add(scene);
|
|
39549
|
+
this.viewer.models.push(modelImpl);
|
|
39550
|
+
this.viewer.syncOptions();
|
|
39551
|
+
this.viewer.syncOverlay();
|
|
39552
|
+
this.viewer.update();
|
|
39553
|
+
this.viewer.emitEvent({ type: "databasechunk", data: scene, file });
|
|
39554
|
+
});
|
|
39555
|
+
this.gltfLoader.addEventListener("geometryerror", (data) => {
|
|
39556
|
+
this.viewer.emitEvent({ type: "geometryerror", data, file });
|
|
39557
|
+
});
|
|
39558
|
+
this.gltfLoader.addEventListener("update", (data) => {
|
|
39559
|
+
this.viewer.update();
|
|
39560
|
+
});
|
|
39561
|
+
const loadController = {
|
|
39562
|
+
loadJson: async () => {
|
|
39563
|
+
const loader = new FileLoader(this.manager);
|
|
39564
|
+
loader.setPath(this.manager.path);
|
|
39565
|
+
loader.setRequestHeader(params.requestHeader || {});
|
|
39566
|
+
loader.setWithCredentials(params.withCredentials || loader.withCredentials);
|
|
39567
|
+
loader.setResponseType("arraybuffer");
|
|
39568
|
+
const progress = (event) => {
|
|
39569
|
+
const { lengthComputable, loaded, total } = event;
|
|
39570
|
+
const progress = lengthComputable ? loaded / total : 1;
|
|
39571
|
+
this.viewer.emitEvent({ type: "geometryprogress", data: progress, file });
|
|
39572
|
+
};
|
|
39573
|
+
const data = await loader.loadAsync(this.manager.fileURL, progress);
|
|
39574
|
+
const extension = new GLTFBinaryExtension(data);
|
|
39575
|
+
this.gltf = JSON.parse(extension.content);
|
|
39576
|
+
this.bin = extension.body;
|
|
39577
|
+
return this.gltf;
|
|
39578
|
+
},
|
|
39579
|
+
loadBinaryData: (ranges, uri = "") => {
|
|
39580
|
+
const loader = new RangesLoader();
|
|
39581
|
+
loader.setRequestHeader(params.requestHeader || {});
|
|
39582
|
+
loader.setWithCredentials(params.withCredentials || false);
|
|
39583
|
+
loader.setAbortSignal(this.gltfLoader.abortController.signal);
|
|
39584
|
+
if (this.bin)
|
|
39585
|
+
return loader.extractRanges(this.bin, ranges);
|
|
39586
|
+
const path = this.manager.path || this.manager.resourcePath;
|
|
39587
|
+
const url = LoaderUtils.resolveURL(uri, path);
|
|
39588
|
+
return loader.load(this.manager.resolveURL(url), ranges);
|
|
39589
|
+
},
|
|
39590
|
+
baseUrl: () => {
|
|
39591
|
+
const path = this.manager.path || this.manager.resourcePath;
|
|
39592
|
+
return Promise.resolve(path);
|
|
39593
|
+
},
|
|
39594
|
+
};
|
|
39595
|
+
const structure = new GltfStructure(modelImpl.id, loadController);
|
|
39596
|
+
await this.gltfLoader.loadStructure(structure);
|
|
39597
|
+
await this.gltfLoader.loadNodes();
|
|
39598
|
+
return this;
|
|
39599
|
+
}
|
|
39600
|
+
cancel() {
|
|
39601
|
+
if (this.gltfLoader)
|
|
39602
|
+
this.gltfLoader.abortLoading();
|
|
39603
|
+
}
|
|
39604
|
+
}
|
|
39605
|
+
|
|
39606
|
+
class GLTFCloudDynamicLoader extends Loader$1 {
|
|
41528
39607
|
constructor(viewer) {
|
|
39608
|
+
super();
|
|
41529
39609
|
this.requestId = 0;
|
|
41530
39610
|
this.viewer = viewer;
|
|
41531
39611
|
}
|
|
@@ -41540,17 +39620,15 @@ void main() {
|
|
|
41540
39620
|
typeof file.downloadResourceRange === "function" &&
|
|
41541
39621
|
/.gltf$/i.test(file.database));
|
|
41542
39622
|
}
|
|
41543
|
-
async load(model, format, params) {
|
|
39623
|
+
async load(model, format, params = {}) {
|
|
41544
39624
|
const scene = new Group$1();
|
|
41545
39625
|
this.gltfLoader = new DynamicGltfLoader(this.viewer.camera, scene, this.viewer.renderer);
|
|
41546
39626
|
this.gltfLoader.memoryLimit = this.viewer.options.memoryLimit;
|
|
41547
39627
|
this.gltfLoader.setVisibleEdges(this.viewer.options.edgeModel);
|
|
39628
|
+
const modelImpl = new DynamicModelImpl(scene);
|
|
39629
|
+
modelImpl.id = model.file.id;
|
|
39630
|
+
modelImpl.gltfLoader = this.gltfLoader;
|
|
41548
39631
|
this.gltfLoader.addEventListener("databasechunk", (data) => {
|
|
41549
|
-
const modelImpl = new DynamicModelImpl(scene);
|
|
41550
|
-
modelImpl.loader = this;
|
|
41551
|
-
modelImpl.viewer = this.viewer;
|
|
41552
|
-
modelImpl.gltfLoader = this.gltfLoader;
|
|
41553
|
-
modelImpl.modelId = model.id;
|
|
41554
39632
|
this.viewer.scene.add(scene);
|
|
41555
39633
|
this.viewer.models.push(modelImpl);
|
|
41556
39634
|
this.viewer.syncOptions();
|
|
@@ -41558,10 +39636,6 @@ void main() {
|
|
|
41558
39636
|
this.viewer.update();
|
|
41559
39637
|
this.viewer.emitEvent({ type: "databasechunk", data: scene, file: model.file, model });
|
|
41560
39638
|
});
|
|
41561
|
-
this.gltfLoader.addEventListener("geometryprogress", (data) => {
|
|
41562
|
-
const progress = data.loaded / data.total;
|
|
41563
|
-
this.viewer.emitEvent({ type: "geometryprogress", data: progress, file: model.file, model });
|
|
41564
|
-
});
|
|
41565
39639
|
this.gltfLoader.addEventListener("geometryerror", (data) => {
|
|
41566
39640
|
this.viewer.emitEvent({ type: "geometryerror", data, file: model.file, model });
|
|
41567
39641
|
});
|
|
@@ -41571,7 +39645,7 @@ void main() {
|
|
|
41571
39645
|
const loadController = {
|
|
41572
39646
|
loadJson: async () => {
|
|
41573
39647
|
const progress = (progress) => {
|
|
41574
|
-
this.viewer.emitEvent({ type: "geometryprogress", data: progress, file: model });
|
|
39648
|
+
this.viewer.emitEvent({ type: "geometryprogress", data: progress, file: model.file, model });
|
|
41575
39649
|
};
|
|
41576
39650
|
const arrayBuffer = await model.downloadResource(model.database, progress, this.gltfLoader.getAbortController().signal);
|
|
41577
39651
|
const text = new TextDecoder().decode(arrayBuffer);
|
|
@@ -41588,7 +39662,7 @@ void main() {
|
|
|
41588
39662
|
},
|
|
41589
39663
|
baseUrl: () => Promise.resolve(`${model.httpClient.serverUrl}${model.path}/`),
|
|
41590
39664
|
};
|
|
41591
|
-
const structure = new GltfStructure(
|
|
39665
|
+
const structure = new GltfStructure(modelImpl.id, loadController);
|
|
41592
39666
|
await this.gltfLoader.loadStructure(structure);
|
|
41593
39667
|
await this.gltfLoader.loadNodes();
|
|
41594
39668
|
return this;
|
|
@@ -41600,7 +39674,7 @@ void main() {
|
|
|
41600
39674
|
}
|
|
41601
39675
|
|
|
41602
39676
|
const loaders = loadersRegistry("threejs");
|
|
41603
|
-
loaders.registerLoader("gltf-file", (viewer) => new
|
|
39677
|
+
loaders.registerLoader("gltf-file", (viewer) => new GLTFFileDynamicLoader(viewer));
|
|
41604
39678
|
loaders.registerLoader("gltf-cloud", (viewer) => new GLTFCloudDynamicLoader(viewer));
|
|
41605
39679
|
|
|
41606
39680
|
const CopyShader = {
|
|
@@ -56561,24 +54635,25 @@ js: import "konva/skia-backend";
|
|
|
56561
54635
|
class Viewer extends EventEmitter2 {
|
|
56562
54636
|
constructor(client) {
|
|
56563
54637
|
super();
|
|
56564
|
-
this._options = new Options(this);
|
|
56565
54638
|
this.client = client;
|
|
56566
|
-
this.
|
|
56567
|
-
this.canvaseventlistener = (event) => this.emit(event);
|
|
54639
|
+
this.options = new Options(this);
|
|
56568
54640
|
this.loaders = [];
|
|
56569
54641
|
this.models = [];
|
|
54642
|
+
this.canvasEvents = CANVAS_EVENTS.slice();
|
|
54643
|
+
this.canvaseventlistener = (event) => this.emit(event);
|
|
56570
54644
|
this.selected = [];
|
|
56571
54645
|
this.extents = new Box3();
|
|
56572
|
-
this.target = new Vector3();
|
|
54646
|
+
this.target = new Vector3(0, 0, 0);
|
|
56573
54647
|
this._activeDragger = null;
|
|
56574
54648
|
this._components = [];
|
|
54649
|
+
this._renderNeeded = false;
|
|
56575
54650
|
this._renderTime = 0;
|
|
56576
54651
|
this.render = this.render.bind(this);
|
|
56577
54652
|
this.update = this.update.bind(this);
|
|
56578
54653
|
this._markup = new KonvaMarkup();
|
|
56579
54654
|
}
|
|
56580
|
-
get
|
|
56581
|
-
return this.
|
|
54655
|
+
get markup() {
|
|
54656
|
+
return this._markup;
|
|
56582
54657
|
}
|
|
56583
54658
|
get draggers() {
|
|
56584
54659
|
return [...draggers.getDraggers().keys()];
|
|
@@ -56586,14 +54661,10 @@ js: import "konva/skia-backend";
|
|
|
56586
54661
|
get components() {
|
|
56587
54662
|
return [...components.getComponents().keys()];
|
|
56588
54663
|
}
|
|
56589
|
-
get markup() {
|
|
56590
|
-
return this._markup;
|
|
56591
|
-
}
|
|
56592
54664
|
initialize(canvas, onProgress) {
|
|
56593
54665
|
this.addEventListener("optionschange", (event) => this.syncOptions(event.data));
|
|
56594
54666
|
this.scene = new Scene();
|
|
56595
54667
|
this.helpers = new Helpers();
|
|
56596
|
-
this.target = new Vector3(0, 0, 0);
|
|
56597
54668
|
const pixelRatio = window.devicePixelRatio;
|
|
56598
54669
|
const rect = canvas.parentElement.getBoundingClientRect();
|
|
56599
54670
|
const width = rect.width || 1;
|
|
@@ -56744,21 +54815,25 @@ js: import "konva/skia-backend";
|
|
|
56744
54815
|
async open(file, params = {}) {
|
|
56745
54816
|
if (!this.renderer)
|
|
56746
54817
|
return this;
|
|
56747
|
-
|
|
54818
|
+
const mode = params.mode || "file";
|
|
54819
|
+
if (mode !== "assembly" && mode !== "a" && mode !== "append") {
|
|
56748
54820
|
this.cancel();
|
|
56749
54821
|
this.clear();
|
|
56750
54822
|
}
|
|
56751
|
-
this.emitEvent({ type: "open", file });
|
|
54823
|
+
this.emitEvent({ type: "open", mode, file });
|
|
56752
54824
|
let model = file;
|
|
56753
54825
|
if (model && typeof model.getModels === "function") {
|
|
56754
54826
|
const models = await model.getModels();
|
|
56755
54827
|
model = models.find((model) => model.default) || models[0] || file;
|
|
56756
54828
|
}
|
|
54829
|
+
if (model && typeof model.database === "string") {
|
|
54830
|
+
file = model.file;
|
|
54831
|
+
}
|
|
56757
54832
|
if (!model)
|
|
56758
54833
|
throw new Error(`Format not supported`);
|
|
56759
54834
|
let format = params.format;
|
|
56760
|
-
if (!format && typeof
|
|
56761
|
-
format =
|
|
54835
|
+
if (!format && typeof file["type"] === "string")
|
|
54836
|
+
format = file["type"].split(".").pop();
|
|
56762
54837
|
if (!format && typeof file === "string")
|
|
56763
54838
|
format = file.split(".").pop();
|
|
56764
54839
|
if (!format && file instanceof globalThis.File)
|
|
@@ -56785,7 +54860,7 @@ js: import "konva/skia-backend";
|
|
|
56785
54860
|
}
|
|
56786
54861
|
loadGltfFile(file, externalFiles, params = {}) {
|
|
56787
54862
|
console.warn("Viewer.loadGltfFile() has been deprecated since 26.4 and will be removed in a future release, use Viewer.open() instead.");
|
|
56788
|
-
return this.open(file, { ...params, format: "gltf", externalFiles, mode: "
|
|
54863
|
+
return this.open(file, { ...params, format: "gltf", externalFiles, mode: "assembly" });
|
|
56789
54864
|
}
|
|
56790
54865
|
cancel() {
|
|
56791
54866
|
this.loaders.forEach((loader) => loader.cancel());
|
|
@@ -56805,12 +54880,17 @@ js: import "konva/skia-backend";
|
|
|
56805
54880
|
this.models = [];
|
|
56806
54881
|
this.scene.clear();
|
|
56807
54882
|
this.helpers.clear();
|
|
54883
|
+
this.extents.makeEmpty();
|
|
54884
|
+
this.target.set(0, 0, 0);
|
|
56808
54885
|
this.syncOptions();
|
|
56809
54886
|
this.syncOverlay();
|
|
56810
54887
|
this.update(true);
|
|
56811
54888
|
this.emitEvent({ type: "clear" });
|
|
56812
54889
|
return this;
|
|
56813
54890
|
}
|
|
54891
|
+
is3D() {
|
|
54892
|
+
return true;
|
|
54893
|
+
}
|
|
56814
54894
|
syncOptions(options = this.options) {
|
|
56815
54895
|
if (!this.renderer)
|
|
56816
54896
|
return;
|
|
@@ -56842,9 +54922,15 @@ js: import "konva/skia-backend";
|
|
|
56842
54922
|
getSelected() {
|
|
56843
54923
|
return this.executeCommand("getSelected");
|
|
56844
54924
|
}
|
|
54925
|
+
getSelected2() {
|
|
54926
|
+
return this.executeCommand("getSelected2");
|
|
54927
|
+
}
|
|
56845
54928
|
setSelected(handles) {
|
|
56846
54929
|
this.executeCommand("setSelected", handles);
|
|
56847
54930
|
}
|
|
54931
|
+
setSelected2(handles) {
|
|
54932
|
+
this.executeCommand("setSelected2", handles);
|
|
54933
|
+
}
|
|
56848
54934
|
clearSelected() {
|
|
56849
54935
|
this.executeCommand("clearSelected");
|
|
56850
54936
|
}
|
|
@@ -56904,37 +54990,8 @@ js: import "konva/skia-backend";
|
|
|
56904
54990
|
getComponent(name) {
|
|
56905
54991
|
return this._components.find((component) => component.name === name);
|
|
56906
54992
|
}
|
|
56907
|
-
is3D() {
|
|
56908
|
-
return true;
|
|
56909
|
-
}
|
|
56910
|
-
screenToWorld(position) {
|
|
56911
|
-
if (!this.renderer)
|
|
56912
|
-
return { x: position.x, y: position.y, z: 0 };
|
|
56913
|
-
const rect = this.canvas.getBoundingClientRect();
|
|
56914
|
-
const x = position.x / (rect.width / 2) - 1;
|
|
56915
|
-
const y = -position.y / (rect.height / 2) + 1;
|
|
56916
|
-
const point = new Vector3(x, y, -1);
|
|
56917
|
-
point.unproject(this.camera);
|
|
56918
|
-
return { x: point.x, y: point.y, z: point.z };
|
|
56919
|
-
}
|
|
56920
|
-
worldToScreen(position) {
|
|
56921
|
-
if (!this.renderer)
|
|
56922
|
-
return { x: position.x, y: position.y };
|
|
56923
|
-
const point = new Vector3(position.x, position.y, position.z);
|
|
56924
|
-
point.project(this.camera);
|
|
56925
|
-
const rect = this.canvas.getBoundingClientRect();
|
|
56926
|
-
const x = (point.x + 1) * (rect.width / 2);
|
|
56927
|
-
const y = (-point.y + 1) * (rect.height / 2);
|
|
56928
|
-
return { x, y };
|
|
56929
|
-
}
|
|
56930
|
-
getScale() {
|
|
56931
|
-
return { x: 1, y: 1, z: 1 };
|
|
56932
|
-
}
|
|
56933
|
-
executeCommand(id, ...args) {
|
|
56934
|
-
return commands.executeCommand(id, this, ...args);
|
|
56935
|
-
}
|
|
56936
54993
|
drawViewpoint(viewpoint) {
|
|
56937
|
-
var _a, _b, _c;
|
|
54994
|
+
var _a, _b, _c, _d;
|
|
56938
54995
|
if (!this.renderer)
|
|
56939
54996
|
return;
|
|
56940
54997
|
const getVector3FromPoint3d = ({ x, y, z }) => new Vector3(x, y, z);
|
|
@@ -56986,11 +55043,13 @@ js: import "konva/skia-backend";
|
|
|
56986
55043
|
}
|
|
56987
55044
|
};
|
|
56988
55045
|
const setClippingPlanes = (clipping_planes) => {
|
|
56989
|
-
|
|
56990
|
-
|
|
56991
|
-
|
|
56992
|
-
|
|
56993
|
-
|
|
55046
|
+
if (clipping_planes) {
|
|
55047
|
+
clipping_planes.forEach((clipping_plane) => {
|
|
55048
|
+
const plane = new Plane();
|
|
55049
|
+
plane.setFromNormalAndCoplanarPoint(getVector3FromPoint3d(clipping_plane.direction), getVector3FromPoint3d(clipping_plane.location));
|
|
55050
|
+
this.renderer.clippingPlanes.push(plane);
|
|
55051
|
+
});
|
|
55052
|
+
}
|
|
56994
55053
|
};
|
|
56995
55054
|
const setSelection = (selection) => {
|
|
56996
55055
|
if (selection)
|
|
@@ -57006,9 +55065,9 @@ js: import "konva/skia-backend";
|
|
|
57006
55065
|
setOrthogonalCamera(viewpoint.orthogonal_camera);
|
|
57007
55066
|
setPerspectiveCamera(viewpoint.perspective_camera);
|
|
57008
55067
|
setClippingPlanes(viewpoint.clipping_planes);
|
|
57009
|
-
setSelection(viewpoint.selection);
|
|
55068
|
+
setSelection(((_b = viewpoint.custom_fields) === null || _b === void 0 ? void 0 : _b.selection2) || viewpoint.selection);
|
|
57010
55069
|
this._markup.setViewpoint(viewpoint);
|
|
57011
|
-
this.target
|
|
55070
|
+
this.target.copy(getVector3FromPoint3d((_d = (_c = viewpoint.custom_fields) === null || _c === void 0 ? void 0 : _c.camera_target) !== null && _d !== void 0 ? _d : this.target));
|
|
57012
55071
|
this.setActiveDragger(draggerName);
|
|
57013
55072
|
this.emitEvent({ type: "drawviewpoint", data: viewpoint });
|
|
57014
55073
|
this.update();
|
|
@@ -57055,6 +55114,9 @@ js: import "konva/skia-backend";
|
|
|
57055
55114
|
const getSelection = () => {
|
|
57056
55115
|
return this.getSelected().map((handle) => ({ handle }));
|
|
57057
55116
|
};
|
|
55117
|
+
const getSelection2 = () => {
|
|
55118
|
+
return this.getSelected2().map((handle) => ({ handle }));
|
|
55119
|
+
};
|
|
57058
55120
|
const viewpoint = { custom_fields: {} };
|
|
57059
55121
|
viewpoint.orthogonal_camera = getOrthogonalCamera();
|
|
57060
55122
|
viewpoint.perspective_camera = getPerspectiveCamera();
|
|
@@ -57063,9 +55125,36 @@ js: import "konva/skia-backend";
|
|
|
57063
55125
|
viewpoint.description = new Date().toDateString();
|
|
57064
55126
|
this._markup.getViewpoint(viewpoint);
|
|
57065
55127
|
viewpoint.custom_fields.camera_target = getPoint3dFromVector3(this.target);
|
|
55128
|
+
viewpoint.custom_fields.selection2 = getSelection2();
|
|
57066
55129
|
this.emitEvent({ type: "createviewpoint", data: viewpoint });
|
|
57067
55130
|
return viewpoint;
|
|
57068
55131
|
}
|
|
55132
|
+
screenToWorld(position) {
|
|
55133
|
+
if (!this.renderer)
|
|
55134
|
+
return { x: position.x, y: position.y, z: 0 };
|
|
55135
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
55136
|
+
const x = position.x / (rect.width / 2) - 1;
|
|
55137
|
+
const y = -position.y / (rect.height / 2) + 1;
|
|
55138
|
+
const point = new Vector3(x, y, -1);
|
|
55139
|
+
point.unproject(this.camera);
|
|
55140
|
+
return { x: point.x, y: point.y, z: point.z };
|
|
55141
|
+
}
|
|
55142
|
+
worldToScreen(position) {
|
|
55143
|
+
if (!this.renderer)
|
|
55144
|
+
return { x: position.x, y: position.y };
|
|
55145
|
+
const point = new Vector3(position.x, position.y, position.z);
|
|
55146
|
+
point.project(this.camera);
|
|
55147
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
55148
|
+
const x = (point.x + 1) * (rect.width / 2);
|
|
55149
|
+
const y = (-point.y + 1) * (rect.height / 2);
|
|
55150
|
+
return { x, y };
|
|
55151
|
+
}
|
|
55152
|
+
getScale() {
|
|
55153
|
+
return { x: 1, y: 1, z: 1 };
|
|
55154
|
+
}
|
|
55155
|
+
executeCommand(id, ...args) {
|
|
55156
|
+
return commands.executeCommand(id, this, ...args);
|
|
55157
|
+
}
|
|
57069
55158
|
}
|
|
57070
55159
|
|
|
57071
55160
|
if (typeof window !== "undefined")
|