@inweb/viewer-three 26.10.5 → 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 +1023 -2928
- package/dist/viewer-three.js.map +1 -1
- package/dist/viewer-three.min.js +3 -3
- package/dist/viewer-three.module.js +856 -359
- 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/draggers/OrbitDragger.d.ts +3 -0
- 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/HighlighterComponent.ts +5 -3
- 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/draggers/OrbitDragger.ts +6 -0
- 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;
|
|
@@ -33714,6 +33730,9 @@ void main() {
|
|
|
33714
33730
|
this.orbit.object = this.viewer.camera;
|
|
33715
33731
|
this.orbit.update();
|
|
33716
33732
|
};
|
|
33733
|
+
this.optionsChange = ({ data: options }) => {
|
|
33734
|
+
this.orbit.zoomSpeed = Math.abs(this.orbit.zoomSpeed) * (options.reverseZoomWheel ? -1 : 1);
|
|
33735
|
+
};
|
|
33717
33736
|
this.controlsStart = () => {
|
|
33718
33737
|
this.changed = false;
|
|
33719
33738
|
};
|
|
@@ -33769,6 +33788,7 @@ void main() {
|
|
|
33769
33788
|
this.viewer.addEventListener("zoom", this.updateControls);
|
|
33770
33789
|
this.viewer.addEventListener("drawviewpoint", this.updateControls);
|
|
33771
33790
|
this.viewer.addEventListener("changecameramode", this.updateControlsCamera);
|
|
33791
|
+
this.viewer.addEventListener("optionschange", this.optionsChange);
|
|
33772
33792
|
this.viewer.addEventListener("contextmenu", this.stopContextMenu);
|
|
33773
33793
|
this.updateControls();
|
|
33774
33794
|
}
|
|
@@ -33779,6 +33799,7 @@ void main() {
|
|
|
33779
33799
|
this.viewer.removeEventListener("zoom", this.updateControls);
|
|
33780
33800
|
this.viewer.removeEventListener("drawviewpoint", this.updateControls);
|
|
33781
33801
|
this.viewer.removeEventListener("changecameramode", this.updateControlsCamera);
|
|
33802
|
+
this.viewer.removeEventListener("optionschange", this.optionsChange);
|
|
33782
33803
|
this.viewer.removeEventListener("contextmenu", this.stopContextMenu);
|
|
33783
33804
|
this.orbit.removeEventListener("start", this.controlsStart);
|
|
33784
33805
|
this.orbit.removeEventListener("change", this.controlsChange);
|
|
@@ -33871,116 +33892,91 @@ void main() {
|
|
|
33871
33892
|
}
|
|
33872
33893
|
}
|
|
33873
33894
|
|
|
33874
|
-
const
|
|
33875
|
-
|
|
33876
|
-
|
|
33877
|
-
|
|
33878
|
-
|
|
33879
|
-
|
|
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
|
-
this.viewer.canvas.addEventListener("pointermove", this.onPointerMove);
|
|
33937
|
-
this.viewer.canvas.addEventListener("pointerup", this.onPointerUp);
|
|
33938
|
-
this.viewer.canvas.addEventListener("pointercancel", this.onPointerCancel);
|
|
33939
|
-
this.viewer.canvas.addEventListener("pointerleave", this.onPointerLeave);
|
|
33940
|
-
this.viewer.addEventListener("render", this.renderOverlay);
|
|
33941
|
-
this.viewer.addEventListener("hide", this.updateSnapper);
|
|
33942
|
-
this.viewer.addEventListener("isolate", this.updateSnapper);
|
|
33943
|
-
this.viewer.addEventListener("show", this.updateSnapper);
|
|
33944
|
-
this.viewer.addEventListener("showall", this.updateSnapper);
|
|
33945
|
-
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;
|
|
33946
33957
|
}
|
|
33947
|
-
|
|
33948
|
-
|
|
33949
|
-
this.viewer.canvas.removeEventListener("pointermove", this.onPointerMove);
|
|
33950
|
-
this.viewer.canvas.removeEventListener("pointerup", this.onPointerUp);
|
|
33951
|
-
this.viewer.canvas.removeEventListener("pointercancel", this.onPointerCancel);
|
|
33952
|
-
this.viewer.canvas.removeEventListener("pointerleave", this.onPointerLeave);
|
|
33953
|
-
this.viewer.removeEventListener("render", this.renderOverlay);
|
|
33954
|
-
this.viewer.removeEventListener("hide", this.updateSnapper);
|
|
33955
|
-
this.viewer.removeEventListener("isolate", this.updateSnapper);
|
|
33956
|
-
this.viewer.removeEventListener("show", this.updateSnapper);
|
|
33957
|
-
this.viewer.removeEventListener("showall", this.updateSnapper);
|
|
33958
|
-
this.viewer.removeEventListener("changecameramode", this.updateSnapperCamera);
|
|
33959
|
-
this.snapper.dispose();
|
|
33960
|
-
this.overlay.detach();
|
|
33961
|
-
this.overlay.dispose();
|
|
33962
|
-
super.dispose();
|
|
33958
|
+
else {
|
|
33959
|
+
return formatNumber(distance, digits, precision);
|
|
33963
33960
|
}
|
|
33964
33961
|
}
|
|
33962
|
+
|
|
33963
|
+
const DESKTOP_SNAP_DISTANCE = 10;
|
|
33964
|
+
const MOBILE_SNAP_DISTANCE = 50;
|
|
33965
33965
|
const _vertex = new Vector3();
|
|
33966
33966
|
const _start$1 = new Vector3();
|
|
33967
33967
|
const _end$1 = new Vector3();
|
|
33968
33968
|
const _line = new Line3();
|
|
33969
33969
|
const _center = new Vector3();
|
|
33970
33970
|
const _projection = new Vector3();
|
|
33971
|
-
class
|
|
33972
|
-
constructor(camera, canvas) {
|
|
33971
|
+
class Snapper {
|
|
33972
|
+
constructor(camera, renderer, canvas) {
|
|
33973
33973
|
this.camera = camera;
|
|
33974
|
+
this.renderer = renderer;
|
|
33974
33975
|
this.canvas = canvas;
|
|
33975
|
-
this.objects = [];
|
|
33976
|
-
this.clippingPlanes = [];
|
|
33977
33976
|
this.raycaster = new Raycaster();
|
|
33978
33977
|
this.detectRadiusInPixels = this.isMobile() ? MOBILE_SNAP_DISTANCE : DESKTOP_SNAP_DISTANCE;
|
|
33979
33978
|
this.edgesCache = new WeakMap();
|
|
33980
33979
|
}
|
|
33981
|
-
dispose() {
|
|
33982
|
-
this.objects = [];
|
|
33983
|
-
}
|
|
33984
33980
|
isMobile() {
|
|
33985
33981
|
if (typeof navigator === "undefined")
|
|
33986
33982
|
return false;
|
|
@@ -33989,7 +33985,7 @@ void main() {
|
|
|
33989
33985
|
getMousePosition(event, target) {
|
|
33990
33986
|
return target.set(event.clientX, event.clientY);
|
|
33991
33987
|
}
|
|
33992
|
-
getPointerIntersects(mouse) {
|
|
33988
|
+
getPointerIntersects(mouse, objects) {
|
|
33993
33989
|
const rect = this.canvas.getBoundingClientRect();
|
|
33994
33990
|
const x = ((mouse.x - rect.left) / rect.width) * 2 - 1;
|
|
33995
33991
|
const y = (-(mouse.y - rect.top) / rect.height) * 2 + 1;
|
|
@@ -34003,8 +33999,8 @@ void main() {
|
|
|
34003
33999
|
Points: { threshold: 0.01 },
|
|
34004
34000
|
Sprite: {},
|
|
34005
34001
|
};
|
|
34006
|
-
let intersects = this.raycaster.intersectObjects(
|
|
34007
|
-
this.clippingPlanes.forEach((plane) => {
|
|
34002
|
+
let intersects = this.raycaster.intersectObjects(objects, false);
|
|
34003
|
+
(this.renderer.clippingPlanes || []).forEach((plane) => {
|
|
34008
34004
|
intersects = intersects.filter((intersect) => plane.distanceToPoint(intersect.point) >= 0);
|
|
34009
34005
|
});
|
|
34010
34006
|
return intersects;
|
|
@@ -34026,9 +34022,8 @@ void main() {
|
|
|
34026
34022
|
}
|
|
34027
34023
|
return 0.1;
|
|
34028
34024
|
}
|
|
34029
|
-
getSnapPoint(
|
|
34030
|
-
const
|
|
34031
|
-
const intersections = this.getPointerIntersects(mouse);
|
|
34025
|
+
getSnapPoint(mouse, objects) {
|
|
34026
|
+
const intersections = this.getPointerIntersects(mouse, objects);
|
|
34032
34027
|
if (intersections.length === 0)
|
|
34033
34028
|
return undefined;
|
|
34034
34029
|
const object = intersections[0].object;
|
|
@@ -34076,13 +34071,133 @@ void main() {
|
|
|
34076
34071
|
return object.localToWorld(snapPoint);
|
|
34077
34072
|
return intersectionPoint.clone();
|
|
34078
34073
|
}
|
|
34079
|
-
|
|
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);
|
|
34080
34197
|
this.objects.length = 0;
|
|
34081
|
-
|
|
34082
|
-
|
|
34083
|
-
|
|
34084
|
-
this.camera = viewer.camera;
|
|
34085
|
-
this.clippingPlanes = viewer.renderer.clippingPlanes || [];
|
|
34198
|
+
this.overlay.detach();
|
|
34199
|
+
this.overlay.dispose();
|
|
34200
|
+
super.dispose();
|
|
34086
34201
|
}
|
|
34087
34202
|
}
|
|
34088
34203
|
class MeasureOverlay {
|
|
@@ -34102,6 +34217,9 @@ void main() {
|
|
|
34102
34217
|
this.projector = new MeasureProjector(camera, canvas);
|
|
34103
34218
|
this.resizeObserver = new ResizeObserver(this.resizeContainer);
|
|
34104
34219
|
}
|
|
34220
|
+
dispose() {
|
|
34221
|
+
this.clear();
|
|
34222
|
+
}
|
|
34105
34223
|
attach() {
|
|
34106
34224
|
this.container = document.createElement("div");
|
|
34107
34225
|
this.container.id = "measure-container";
|
|
@@ -34114,9 +34232,6 @@ void main() {
|
|
|
34114
34232
|
this.canvas.parentElement.appendChild(this.container);
|
|
34115
34233
|
this.resizeObserver.observe(this.canvas);
|
|
34116
34234
|
}
|
|
34117
|
-
dispose() {
|
|
34118
|
-
this.clear();
|
|
34119
|
-
}
|
|
34120
34235
|
detach() {
|
|
34121
34236
|
this.resizeObserver.disconnect();
|
|
34122
34237
|
this.container.remove();
|
|
@@ -34124,7 +34239,7 @@ void main() {
|
|
|
34124
34239
|
}
|
|
34125
34240
|
clear() {
|
|
34126
34241
|
this.lines.forEach((line) => line.dispose());
|
|
34127
|
-
this.lines =
|
|
34242
|
+
this.lines.length = 0;
|
|
34128
34243
|
}
|
|
34129
34244
|
render() {
|
|
34130
34245
|
this.projector.setFromCamera(this.camera);
|
|
@@ -34139,13 +34254,18 @@ void main() {
|
|
|
34139
34254
|
removeLine(line) {
|
|
34140
34255
|
this.lines = this.lines.filter((x) => x !== line);
|
|
34141
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
|
+
}
|
|
34142
34264
|
}
|
|
34143
34265
|
const _middlePoint = new Vector3();
|
|
34144
34266
|
class MeasureLine {
|
|
34145
|
-
constructor(overlay) {
|
|
34267
|
+
constructor(overlay, scale, units, precision) {
|
|
34146
34268
|
this.id = MathUtils.generateUUID();
|
|
34147
|
-
this.unit = "";
|
|
34148
|
-
this.scale = 1.0;
|
|
34149
34269
|
this.size = 10.0;
|
|
34150
34270
|
this.lineWidth = 2;
|
|
34151
34271
|
this.style = {
|
|
@@ -34156,6 +34276,9 @@ void main() {
|
|
|
34156
34276
|
font: "1rem system-ui",
|
|
34157
34277
|
};
|
|
34158
34278
|
this.overlay = overlay;
|
|
34279
|
+
this.scale = scale;
|
|
34280
|
+
this.units = units;
|
|
34281
|
+
this.precision = precision;
|
|
34159
34282
|
this.elementStartPoint = overlay.container.appendChild(document.createElement("div"));
|
|
34160
34283
|
this.elementEndPoint = overlay.container.appendChild(document.createElement("div"));
|
|
34161
34284
|
this.elementLine = overlay.container.appendChild(document.createElement("div"));
|
|
@@ -34210,10 +34333,10 @@ void main() {
|
|
|
34210
34333
|
_middlePoint.lerpVectors(this.startPoint, this.endPoint, 0.5);
|
|
34211
34334
|
const { point, visible } = projector.projectPoint(_middlePoint);
|
|
34212
34335
|
const distance = this.getDistance();
|
|
34213
|
-
this.elementLabel.style.display = visible && distance
|
|
34336
|
+
this.elementLabel.style.display = visible && distance > 0 ? "block" : "none";
|
|
34214
34337
|
this.elementLabel.style.left = `${point.x}px`;
|
|
34215
34338
|
this.elementLabel.style.top = `${point.y}px`;
|
|
34216
|
-
this.elementLabel.innerHTML =
|
|
34339
|
+
this.elementLabel.innerHTML = formatDistance(distance, this.units, this.precision);
|
|
34217
34340
|
}
|
|
34218
34341
|
else {
|
|
34219
34342
|
this.elementLabel.style.display = "none";
|
|
@@ -35017,7 +35140,8 @@ void main() {
|
|
|
35017
35140
|
const selection = viewer.getComponent("SelectionComponent");
|
|
35018
35141
|
selection.clearSelection();
|
|
35019
35142
|
viewer.update();
|
|
35020
|
-
viewer.emitEvent({ type: "select",
|
|
35143
|
+
viewer.emitEvent({ type: "select", handles: [] });
|
|
35144
|
+
viewer.emitEvent({ type: "select2", handles: [] });
|
|
35021
35145
|
}
|
|
35022
35146
|
|
|
35023
35147
|
function clearSlices(viewer) {
|
|
@@ -35106,22 +35230,31 @@ void main() {
|
|
|
35106
35230
|
}
|
|
35107
35231
|
|
|
35108
35232
|
function getModels(viewer) {
|
|
35109
|
-
return viewer.models.map((model) => model.
|
|
35233
|
+
return viewer.models.map((model) => model.id);
|
|
35110
35234
|
}
|
|
35111
35235
|
|
|
35112
35236
|
function getSelected(viewer) {
|
|
35113
|
-
const
|
|
35114
|
-
|
|
35237
|
+
const handles2 = viewer.executeCommand("getSelected2");
|
|
35238
|
+
const handles = handles2.map((handle) => handle.slice(handle.indexOf(":") + 1));
|
|
35115
35239
|
return handles;
|
|
35116
35240
|
}
|
|
35117
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
|
+
|
|
35118
35250
|
function hideSelected(viewer) {
|
|
35119
35251
|
viewer.models.forEach((model) => model.hideObjects(viewer.selected));
|
|
35120
35252
|
const selection = viewer.getComponent("SelectionComponent");
|
|
35121
35253
|
selection.clearSelection();
|
|
35122
35254
|
viewer.update();
|
|
35123
35255
|
viewer.emitEvent({ type: "hide" });
|
|
35124
|
-
viewer.emitEvent({ type: "select",
|
|
35256
|
+
viewer.emitEvent({ type: "select", handles: [] });
|
|
35257
|
+
viewer.emitEvent({ type: "select2", handles: [] });
|
|
35125
35258
|
}
|
|
35126
35259
|
|
|
35127
35260
|
function isolateSelected(viewer) {
|
|
@@ -35148,14 +35281,13 @@ void main() {
|
|
|
35148
35281
|
viewer.emit({ type: "resetview" });
|
|
35149
35282
|
}
|
|
35150
35283
|
|
|
35151
|
-
function selectModel(viewer,
|
|
35284
|
+
function selectModel(viewer, id) {
|
|
35152
35285
|
const selection = viewer.getComponent("SelectionComponent");
|
|
35153
35286
|
selection.clearSelection();
|
|
35154
|
-
viewer.models
|
|
35155
|
-
.filter((model) => model.handle === handle)
|
|
35156
|
-
.forEach((model) => selection.select(model.getObjects(), model));
|
|
35287
|
+
viewer.models.filter((model) => model.id === id).forEach((model) => selection.select(model.getObjects(), model));
|
|
35157
35288
|
viewer.update();
|
|
35158
|
-
viewer.
|
|
35289
|
+
viewer.emitEvent({ type: "select", handles: viewer.getSelected() });
|
|
35290
|
+
viewer.emitEvent({ type: "select2", handles: viewer.getSelected2() });
|
|
35159
35291
|
}
|
|
35160
35292
|
|
|
35161
35293
|
function setActiveDragger(viewer, dragger = "") {
|
|
@@ -35167,16 +35299,31 @@ void main() {
|
|
|
35167
35299
|
}
|
|
35168
35300
|
|
|
35169
35301
|
function setSelected(viewer, handles = []) {
|
|
35170
|
-
const
|
|
35171
|
-
|
|
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();
|
|
35172
35318
|
viewer.models.forEach((model) => {
|
|
35173
35319
|
const objects = model.getObjectsByHandles(handles);
|
|
35174
35320
|
model.showObjects(objects);
|
|
35175
|
-
|
|
35321
|
+
selectionComponent.select(objects, model);
|
|
35176
35322
|
});
|
|
35177
35323
|
viewer.update();
|
|
35178
35324
|
viewer.emitEvent({ type: "show" });
|
|
35179
|
-
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 });
|
|
35180
35327
|
}
|
|
35181
35328
|
|
|
35182
35329
|
function showAll(viewer) {
|
|
@@ -35190,21 +35337,19 @@ void main() {
|
|
|
35190
35337
|
}
|
|
35191
35338
|
|
|
35192
35339
|
function zoomToObjects(viewer, handles = []) {
|
|
35193
|
-
const
|
|
35194
|
-
|
|
35195
|
-
|
|
35196
|
-
|
|
35197
|
-
if (handleSet.has((_a = child.userData) === null || _a === void 0 ? void 0 : _a.handle))
|
|
35198
|
-
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));
|
|
35199
35344
|
});
|
|
35200
|
-
const extents = objects.reduce((result, object) => result.expandByObject(object), new Box3());
|
|
35201
35345
|
if (extents.isEmpty())
|
|
35202
35346
|
extents.copy(viewer.extents);
|
|
35203
35347
|
zoomTo(viewer, extents);
|
|
35204
35348
|
}
|
|
35205
35349
|
|
|
35206
35350
|
function zoomToSelected(viewer) {
|
|
35207
|
-
const extents =
|
|
35351
|
+
const extents = new Box3();
|
|
35352
|
+
viewer.selected.forEach((object) => extents.expandByObject(object));
|
|
35208
35353
|
if (extents.isEmpty())
|
|
35209
35354
|
extents.copy(viewer.extents);
|
|
35210
35355
|
zoomTo(viewer, extents);
|
|
@@ -35221,6 +35366,7 @@ void main() {
|
|
|
35221
35366
|
commands.registerCommand("getDefaultViewPositions", getDefaultViewPositions);
|
|
35222
35367
|
commands.registerCommand("getModels", getModels);
|
|
35223
35368
|
commands.registerCommand("getSelected", getSelected);
|
|
35369
|
+
commands.registerCommand("getSelected2", getSelected2);
|
|
35224
35370
|
commands.registerCommand("hideSelected", hideSelected);
|
|
35225
35371
|
commands.registerCommand("isolateSelected", isolateSelected);
|
|
35226
35372
|
commands.registerCommand("regenerateAll", regenerateAll);
|
|
@@ -35230,6 +35376,7 @@ void main() {
|
|
|
35230
35376
|
commands.registerCommand("setDefaultViewPosition", setDefaultViewPosition);
|
|
35231
35377
|
commands.registerCommand("setMarkupColor", setMarkupColor);
|
|
35232
35378
|
commands.registerCommand("setSelected", setSelected);
|
|
35379
|
+
commands.registerCommand("setSelected2", setSelected2);
|
|
35233
35380
|
commands.registerCommand("showAll", showAll);
|
|
35234
35381
|
commands.registerCommand("zoomToExtents", zoomToExtents);
|
|
35235
35382
|
commands.registerCommand("zoomToObjects", zoomToObjects);
|
|
@@ -35282,6 +35429,10 @@ void main() {
|
|
|
35282
35429
|
this.switchCameraMode(this.viewer.options.cameraMode);
|
|
35283
35430
|
};
|
|
35284
35431
|
this.geometryEnd = () => {
|
|
35432
|
+
if (this.viewer.models.length > 1) {
|
|
35433
|
+
this.switchCamera(this.viewer.camera);
|
|
35434
|
+
return;
|
|
35435
|
+
}
|
|
35285
35436
|
let camera;
|
|
35286
35437
|
this.viewer.scene.traverse((object) => {
|
|
35287
35438
|
if (object.isCamera)
|
|
@@ -35379,6 +35530,8 @@ void main() {
|
|
|
35379
35530
|
const extents = new Box3();
|
|
35380
35531
|
this.viewer.models.forEach((model) => model.getExtents(extents));
|
|
35381
35532
|
this.viewer.extents.copy(extents);
|
|
35533
|
+
if (this.viewer.models.length > 1)
|
|
35534
|
+
return;
|
|
35382
35535
|
this.viewer.extents.getCenter(this.viewer.target);
|
|
35383
35536
|
};
|
|
35384
35537
|
this.viewer = viewer;
|
|
@@ -36304,8 +36457,9 @@ void main() {
|
|
|
36304
36457
|
});
|
|
36305
36458
|
}
|
|
36306
36459
|
syncHighlightColors() {
|
|
36307
|
-
const
|
|
36308
|
-
const {
|
|
36460
|
+
const options = this.viewer.options.enableCustomHighlight ? this.viewer.options : Options.defaults();
|
|
36461
|
+
const { facesColor, facesTransparancy, facesOverlap } = options;
|
|
36462
|
+
const { edgesColor, edgesVisibility, edgesOverlap } = options;
|
|
36309
36463
|
this.facesMaterial.color.setRGB(facesColor.r / 255, facesColor.g / 255, facesColor.b / 255);
|
|
36310
36464
|
this.facesMaterial.opacity = (255 - facesTransparancy) / 255;
|
|
36311
36465
|
this.facesMaterial.depthTest = !facesOverlap;
|
|
@@ -36344,10 +36498,11 @@ void main() {
|
|
|
36344
36498
|
const upPosition = this.getMousePosition(event, new Vector2());
|
|
36345
36499
|
if (upPosition.distanceTo(this.downPosition) !== 0)
|
|
36346
36500
|
return;
|
|
36501
|
+
const snapper = new Snapper(this.viewer.camera, this.viewer.renderer, this.viewer.canvas);
|
|
36347
36502
|
let intersections = [];
|
|
36348
36503
|
this.viewer.models.forEach((model) => {
|
|
36349
36504
|
const objects = model.getVisibleObjects();
|
|
36350
|
-
const intersects =
|
|
36505
|
+
const intersects = snapper.getPointerIntersects(upPosition, objects);
|
|
36351
36506
|
if (intersects.length > 0)
|
|
36352
36507
|
intersections.push({ ...intersects[0], model });
|
|
36353
36508
|
});
|
|
@@ -36365,6 +36520,7 @@ void main() {
|
|
|
36365
36520
|
}
|
|
36366
36521
|
this.viewer.update();
|
|
36367
36522
|
this.viewer.emitEvent({ type: "select", data: undefined, handles: this.viewer.getSelected() });
|
|
36523
|
+
this.viewer.emitEvent({ type: "select2", data: undefined, handles: this.viewer.getSelected2() });
|
|
36368
36524
|
};
|
|
36369
36525
|
this.onDoubleClick = (event) => {
|
|
36370
36526
|
if (event.button !== 0)
|
|
@@ -36375,7 +36531,6 @@ void main() {
|
|
|
36375
36531
|
this.highlighter = this.viewer.getComponent("HighlighterComponent");
|
|
36376
36532
|
};
|
|
36377
36533
|
this.viewer = viewer;
|
|
36378
|
-
this.raycaster = new Raycaster();
|
|
36379
36534
|
this.downPosition = new Vector2();
|
|
36380
36535
|
this.viewer.addEventListener("pointerdown", this.onPointerDown);
|
|
36381
36536
|
this.viewer.addEventListener("pointerup", this.onPointerUp);
|
|
@@ -36391,26 +36546,6 @@ void main() {
|
|
|
36391
36546
|
getMousePosition(event, target) {
|
|
36392
36547
|
return target.set(event.clientX, event.clientY);
|
|
36393
36548
|
}
|
|
36394
|
-
getPointerIntersects(mouse, objects) {
|
|
36395
|
-
const rect = this.viewer.canvas.getBoundingClientRect();
|
|
36396
|
-
const x = ((mouse.x - rect.left) / rect.width) * 2 - 1;
|
|
36397
|
-
const y = (-(mouse.y - rect.top) / rect.height) * 2 + 1;
|
|
36398
|
-
const coords = new Vector2(x, y);
|
|
36399
|
-
this.raycaster.setFromCamera(coords, this.viewer.camera);
|
|
36400
|
-
this.raycaster.params = {
|
|
36401
|
-
Mesh: {},
|
|
36402
|
-
Line: { threshold: 0.05 },
|
|
36403
|
-
Line2: { threshold: 0.05 },
|
|
36404
|
-
LOD: {},
|
|
36405
|
-
Points: { threshold: 0.01 },
|
|
36406
|
-
Sprite: {},
|
|
36407
|
-
};
|
|
36408
|
-
let intersects = this.raycaster.intersectObjects(objects, false);
|
|
36409
|
-
(this.viewer.renderer.clippingPlanes || []).forEach((plane) => {
|
|
36410
|
-
intersects = intersects.filter((intersect) => plane.distanceToPoint(intersect.point) >= 0);
|
|
36411
|
-
});
|
|
36412
|
-
return intersects;
|
|
36413
|
-
}
|
|
36414
36549
|
select(objects, model) {
|
|
36415
36550
|
if (!model) {
|
|
36416
36551
|
this.viewer.models.forEach((model) => this.select(objects, model));
|
|
@@ -36609,2616 +36744,8 @@ void main() {
|
|
|
36609
36744
|
components.registerComponent("WCSHelperComponent", (viewer) => new WCSHelperComponent(viewer));
|
|
36610
36745
|
components.registerComponent("ResetComponent", (viewer) => new ResetComponent(viewer));
|
|
36611
36746
|
|
|
36612
|
-
function mergeGeometries( geometries, useGroups = false ) {
|
|
36613
|
-
const isIndexed = geometries[ 0 ].index !== null;
|
|
36614
|
-
const attributesUsed = new Set( Object.keys( geometries[ 0 ].attributes ) );
|
|
36615
|
-
const morphAttributesUsed = new Set( Object.keys( geometries[ 0 ].morphAttributes ) );
|
|
36616
|
-
const attributes = {};
|
|
36617
|
-
const morphAttributes = {};
|
|
36618
|
-
const morphTargetsRelative = geometries[ 0 ].morphTargetsRelative;
|
|
36619
|
-
const mergedGeometry = new BufferGeometry();
|
|
36620
|
-
let offset = 0;
|
|
36621
|
-
for ( let i = 0; i < geometries.length; ++ i ) {
|
|
36622
|
-
const geometry = geometries[ i ];
|
|
36623
|
-
let attributesCount = 0;
|
|
36624
|
-
if ( isIndexed !== ( geometry.index !== null ) ) {
|
|
36625
|
-
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.' );
|
|
36626
|
-
return null;
|
|
36627
|
-
}
|
|
36628
|
-
for ( const name in geometry.attributes ) {
|
|
36629
|
-
if ( ! attributesUsed.has( name ) ) {
|
|
36630
|
-
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.' );
|
|
36631
|
-
return null;
|
|
36632
|
-
}
|
|
36633
|
-
if ( attributes[ name ] === undefined ) attributes[ name ] = [];
|
|
36634
|
-
attributes[ name ].push( geometry.attributes[ name ] );
|
|
36635
|
-
attributesCount ++;
|
|
36636
|
-
}
|
|
36637
|
-
if ( attributesCount !== attributesUsed.size ) {
|
|
36638
|
-
console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. Make sure all geometries have the same number of attributes.' );
|
|
36639
|
-
return null;
|
|
36640
|
-
}
|
|
36641
|
-
if ( morphTargetsRelative !== geometry.morphTargetsRelative ) {
|
|
36642
|
-
console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. .morphTargetsRelative must be consistent throughout all geometries.' );
|
|
36643
|
-
return null;
|
|
36644
|
-
}
|
|
36645
|
-
for ( const name in geometry.morphAttributes ) {
|
|
36646
|
-
if ( ! morphAttributesUsed.has( name ) ) {
|
|
36647
|
-
console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. .morphAttributes must be consistent throughout all geometries.' );
|
|
36648
|
-
return null;
|
|
36649
|
-
}
|
|
36650
|
-
if ( morphAttributes[ name ] === undefined ) morphAttributes[ name ] = [];
|
|
36651
|
-
morphAttributes[ name ].push( geometry.morphAttributes[ name ] );
|
|
36652
|
-
}
|
|
36653
|
-
if ( useGroups ) {
|
|
36654
|
-
let count;
|
|
36655
|
-
if ( isIndexed ) {
|
|
36656
|
-
count = geometry.index.count;
|
|
36657
|
-
} else if ( geometry.attributes.position !== undefined ) {
|
|
36658
|
-
count = geometry.attributes.position.count;
|
|
36659
|
-
} else {
|
|
36660
|
-
console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. The geometry must have either an index or a position attribute' );
|
|
36661
|
-
return null;
|
|
36662
|
-
}
|
|
36663
|
-
mergedGeometry.addGroup( offset, count, i );
|
|
36664
|
-
offset += count;
|
|
36665
|
-
}
|
|
36666
|
-
}
|
|
36667
|
-
if ( isIndexed ) {
|
|
36668
|
-
let indexOffset = 0;
|
|
36669
|
-
const mergedIndex = [];
|
|
36670
|
-
for ( let i = 0; i < geometries.length; ++ i ) {
|
|
36671
|
-
const index = geometries[ i ].index;
|
|
36672
|
-
for ( let j = 0; j < index.count; ++ j ) {
|
|
36673
|
-
mergedIndex.push( index.getX( j ) + indexOffset );
|
|
36674
|
-
}
|
|
36675
|
-
indexOffset += geometries[ i ].attributes.position.count;
|
|
36676
|
-
}
|
|
36677
|
-
mergedGeometry.setIndex( mergedIndex );
|
|
36678
|
-
}
|
|
36679
|
-
for ( const name in attributes ) {
|
|
36680
|
-
const mergedAttribute = mergeAttributes( attributes[ name ] );
|
|
36681
|
-
if ( ! mergedAttribute ) {
|
|
36682
|
-
console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the ' + name + ' attribute.' );
|
|
36683
|
-
return null;
|
|
36684
|
-
}
|
|
36685
|
-
mergedGeometry.setAttribute( name, mergedAttribute );
|
|
36686
|
-
}
|
|
36687
|
-
for ( const name in morphAttributes ) {
|
|
36688
|
-
const numMorphTargets = morphAttributes[ name ][ 0 ].length;
|
|
36689
|
-
if ( numMorphTargets === 0 ) break;
|
|
36690
|
-
mergedGeometry.morphAttributes = mergedGeometry.morphAttributes || {};
|
|
36691
|
-
mergedGeometry.morphAttributes[ name ] = [];
|
|
36692
|
-
for ( let i = 0; i < numMorphTargets; ++ i ) {
|
|
36693
|
-
const morphAttributesToMerge = [];
|
|
36694
|
-
for ( let j = 0; j < morphAttributes[ name ].length; ++ j ) {
|
|
36695
|
-
morphAttributesToMerge.push( morphAttributes[ name ][ j ][ i ] );
|
|
36696
|
-
}
|
|
36697
|
-
const mergedMorphAttribute = mergeAttributes( morphAttributesToMerge );
|
|
36698
|
-
if ( ! mergedMorphAttribute ) {
|
|
36699
|
-
console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the ' + name + ' morphAttribute.' );
|
|
36700
|
-
return null;
|
|
36701
|
-
}
|
|
36702
|
-
mergedGeometry.morphAttributes[ name ].push( mergedMorphAttribute );
|
|
36703
|
-
}
|
|
36704
|
-
}
|
|
36705
|
-
return mergedGeometry;
|
|
36706
|
-
}
|
|
36707
|
-
function mergeAttributes( attributes ) {
|
|
36708
|
-
let TypedArray;
|
|
36709
|
-
let itemSize;
|
|
36710
|
-
let normalized;
|
|
36711
|
-
let gpuType = -1;
|
|
36712
|
-
let arrayLength = 0;
|
|
36713
|
-
for ( let i = 0; i < attributes.length; ++ i ) {
|
|
36714
|
-
const attribute = attributes[ i ];
|
|
36715
|
-
if ( TypedArray === undefined ) TypedArray = attribute.array.constructor;
|
|
36716
|
-
if ( TypedArray !== attribute.array.constructor ) {
|
|
36717
|
-
console.error( 'THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes.' );
|
|
36718
|
-
return null;
|
|
36719
|
-
}
|
|
36720
|
-
if ( itemSize === undefined ) itemSize = attribute.itemSize;
|
|
36721
|
-
if ( itemSize !== attribute.itemSize ) {
|
|
36722
|
-
console.error( 'THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes.' );
|
|
36723
|
-
return null;
|
|
36724
|
-
}
|
|
36725
|
-
if ( normalized === undefined ) normalized = attribute.normalized;
|
|
36726
|
-
if ( normalized !== attribute.normalized ) {
|
|
36727
|
-
console.error( 'THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes.' );
|
|
36728
|
-
return null;
|
|
36729
|
-
}
|
|
36730
|
-
if ( gpuType === -1 ) gpuType = attribute.gpuType;
|
|
36731
|
-
if ( gpuType !== attribute.gpuType ) {
|
|
36732
|
-
console.error( 'THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes.' );
|
|
36733
|
-
return null;
|
|
36734
|
-
}
|
|
36735
|
-
arrayLength += attribute.count * itemSize;
|
|
36736
|
-
}
|
|
36737
|
-
const array = new TypedArray( arrayLength );
|
|
36738
|
-
const result = new BufferAttribute( array, itemSize, normalized );
|
|
36739
|
-
let offset = 0;
|
|
36740
|
-
for ( let i = 0; i < attributes.length; ++ i ) {
|
|
36741
|
-
const attribute = attributes[ i ];
|
|
36742
|
-
if ( attribute.isInterleavedBufferAttribute ) {
|
|
36743
|
-
const tupleOffset = offset / itemSize;
|
|
36744
|
-
for ( let j = 0, l = attribute.count; j < l; j ++ ) {
|
|
36745
|
-
for ( let c = 0; c < itemSize; c ++ ) {
|
|
36746
|
-
const value = attribute.getComponent( j, c );
|
|
36747
|
-
result.setComponent( j + tupleOffset, c, value );
|
|
36748
|
-
}
|
|
36749
|
-
}
|
|
36750
|
-
} else {
|
|
36751
|
-
array.set( attribute.array, offset );
|
|
36752
|
-
}
|
|
36753
|
-
offset += attribute.count * itemSize;
|
|
36754
|
-
}
|
|
36755
|
-
if ( gpuType !== undefined ) {
|
|
36756
|
-
result.gpuType = gpuType;
|
|
36757
|
-
}
|
|
36758
|
-
return result;
|
|
36759
|
-
}
|
|
36760
|
-
function toTrianglesDrawMode( geometry, drawMode ) {
|
|
36761
|
-
if ( drawMode === TrianglesDrawMode ) {
|
|
36762
|
-
console.warn( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles.' );
|
|
36763
|
-
return geometry;
|
|
36764
|
-
}
|
|
36765
|
-
if ( drawMode === TriangleFanDrawMode || drawMode === TriangleStripDrawMode ) {
|
|
36766
|
-
let index = geometry.getIndex();
|
|
36767
|
-
if ( index === null ) {
|
|
36768
|
-
const indices = [];
|
|
36769
|
-
const position = geometry.getAttribute( 'position' );
|
|
36770
|
-
if ( position !== undefined ) {
|
|
36771
|
-
for ( let i = 0; i < position.count; i ++ ) {
|
|
36772
|
-
indices.push( i );
|
|
36773
|
-
}
|
|
36774
|
-
geometry.setIndex( indices );
|
|
36775
|
-
index = geometry.getIndex();
|
|
36776
|
-
} else {
|
|
36777
|
-
console.error( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible.' );
|
|
36778
|
-
return geometry;
|
|
36779
|
-
}
|
|
36780
|
-
}
|
|
36781
|
-
const numberOfTriangles = index.count - 2;
|
|
36782
|
-
const newIndices = [];
|
|
36783
|
-
if ( drawMode === TriangleFanDrawMode ) {
|
|
36784
|
-
for ( let i = 1; i <= numberOfTriangles; i ++ ) {
|
|
36785
|
-
newIndices.push( index.getX( 0 ) );
|
|
36786
|
-
newIndices.push( index.getX( i ) );
|
|
36787
|
-
newIndices.push( index.getX( i + 1 ) );
|
|
36788
|
-
}
|
|
36789
|
-
} else {
|
|
36790
|
-
for ( let i = 0; i < numberOfTriangles; i ++ ) {
|
|
36791
|
-
if ( i % 2 === 0 ) {
|
|
36792
|
-
newIndices.push( index.getX( i ) );
|
|
36793
|
-
newIndices.push( index.getX( i + 1 ) );
|
|
36794
|
-
newIndices.push( index.getX( i + 2 ) );
|
|
36795
|
-
} else {
|
|
36796
|
-
newIndices.push( index.getX( i + 2 ) );
|
|
36797
|
-
newIndices.push( index.getX( i + 1 ) );
|
|
36798
|
-
newIndices.push( index.getX( i ) );
|
|
36799
|
-
}
|
|
36800
|
-
}
|
|
36801
|
-
}
|
|
36802
|
-
if ( ( newIndices.length / 3 ) !== numberOfTriangles ) {
|
|
36803
|
-
console.error( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.' );
|
|
36804
|
-
}
|
|
36805
|
-
const newGeometry = geometry.clone();
|
|
36806
|
-
newGeometry.setIndex( newIndices );
|
|
36807
|
-
newGeometry.clearGroups();
|
|
36808
|
-
return newGeometry;
|
|
36809
|
-
} else {
|
|
36810
|
-
console.error( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:', drawMode );
|
|
36811
|
-
return geometry;
|
|
36812
|
-
}
|
|
36813
|
-
}
|
|
36814
|
-
|
|
36815
|
-
class GLTFLoader extends Loader {
|
|
36816
|
-
constructor( manager ) {
|
|
36817
|
-
super( manager );
|
|
36818
|
-
this.dracoLoader = null;
|
|
36819
|
-
this.ktx2Loader = null;
|
|
36820
|
-
this.meshoptDecoder = null;
|
|
36821
|
-
this.pluginCallbacks = [];
|
|
36822
|
-
this.register( function ( parser ) {
|
|
36823
|
-
return new GLTFMaterialsClearcoatExtension( parser );
|
|
36824
|
-
} );
|
|
36825
|
-
this.register( function ( parser ) {
|
|
36826
|
-
return new GLTFMaterialsDispersionExtension( parser );
|
|
36827
|
-
} );
|
|
36828
|
-
this.register( function ( parser ) {
|
|
36829
|
-
return new GLTFTextureBasisUExtension( parser );
|
|
36830
|
-
} );
|
|
36831
|
-
this.register( function ( parser ) {
|
|
36832
|
-
return new GLTFTextureWebPExtension( parser );
|
|
36833
|
-
} );
|
|
36834
|
-
this.register( function ( parser ) {
|
|
36835
|
-
return new GLTFTextureAVIFExtension( parser );
|
|
36836
|
-
} );
|
|
36837
|
-
this.register( function ( parser ) {
|
|
36838
|
-
return new GLTFMaterialsSheenExtension( parser );
|
|
36839
|
-
} );
|
|
36840
|
-
this.register( function ( parser ) {
|
|
36841
|
-
return new GLTFMaterialsTransmissionExtension( parser );
|
|
36842
|
-
} );
|
|
36843
|
-
this.register( function ( parser ) {
|
|
36844
|
-
return new GLTFMaterialsVolumeExtension( parser );
|
|
36845
|
-
} );
|
|
36846
|
-
this.register( function ( parser ) {
|
|
36847
|
-
return new GLTFMaterialsIorExtension( parser );
|
|
36848
|
-
} );
|
|
36849
|
-
this.register( function ( parser ) {
|
|
36850
|
-
return new GLTFMaterialsEmissiveStrengthExtension( parser );
|
|
36851
|
-
} );
|
|
36852
|
-
this.register( function ( parser ) {
|
|
36853
|
-
return new GLTFMaterialsSpecularExtension( parser );
|
|
36854
|
-
} );
|
|
36855
|
-
this.register( function ( parser ) {
|
|
36856
|
-
return new GLTFMaterialsIridescenceExtension( parser );
|
|
36857
|
-
} );
|
|
36858
|
-
this.register( function ( parser ) {
|
|
36859
|
-
return new GLTFMaterialsAnisotropyExtension( parser );
|
|
36860
|
-
} );
|
|
36861
|
-
this.register( function ( parser ) {
|
|
36862
|
-
return new GLTFMaterialsBumpExtension( parser );
|
|
36863
|
-
} );
|
|
36864
|
-
this.register( function ( parser ) {
|
|
36865
|
-
return new GLTFLightsExtension( parser );
|
|
36866
|
-
} );
|
|
36867
|
-
this.register( function ( parser ) {
|
|
36868
|
-
return new GLTFMeshoptCompression( parser );
|
|
36869
|
-
} );
|
|
36870
|
-
this.register( function ( parser ) {
|
|
36871
|
-
return new GLTFMeshGpuInstancing( parser );
|
|
36872
|
-
} );
|
|
36873
|
-
}
|
|
36874
|
-
load( url, onLoad, onProgress, onError ) {
|
|
36875
|
-
const scope = this;
|
|
36876
|
-
let resourcePath;
|
|
36877
|
-
if ( this.resourcePath !== '' ) {
|
|
36878
|
-
resourcePath = this.resourcePath;
|
|
36879
|
-
} else if ( this.path !== '' ) {
|
|
36880
|
-
const relativeUrl = LoaderUtils.extractUrlBase( url );
|
|
36881
|
-
resourcePath = LoaderUtils.resolveURL( relativeUrl, this.path );
|
|
36882
|
-
} else {
|
|
36883
|
-
resourcePath = LoaderUtils.extractUrlBase( url );
|
|
36884
|
-
}
|
|
36885
|
-
this.manager.itemStart( url );
|
|
36886
|
-
const _onError = function ( e ) {
|
|
36887
|
-
if ( onError ) {
|
|
36888
|
-
onError( e );
|
|
36889
|
-
} else {
|
|
36890
|
-
console.error( e );
|
|
36891
|
-
}
|
|
36892
|
-
scope.manager.itemError( url );
|
|
36893
|
-
scope.manager.itemEnd( url );
|
|
36894
|
-
};
|
|
36895
|
-
const loader = new FileLoader( this.manager );
|
|
36896
|
-
loader.setPath( this.path );
|
|
36897
|
-
loader.setResponseType( 'arraybuffer' );
|
|
36898
|
-
loader.setRequestHeader( this.requestHeader );
|
|
36899
|
-
loader.setWithCredentials( this.withCredentials );
|
|
36900
|
-
loader.load( url, function ( data ) {
|
|
36901
|
-
try {
|
|
36902
|
-
scope.parse( data, resourcePath, function ( gltf ) {
|
|
36903
|
-
onLoad( gltf );
|
|
36904
|
-
scope.manager.itemEnd( url );
|
|
36905
|
-
}, _onError );
|
|
36906
|
-
} catch ( e ) {
|
|
36907
|
-
_onError( e );
|
|
36908
|
-
}
|
|
36909
|
-
}, onProgress, _onError );
|
|
36910
|
-
}
|
|
36911
|
-
setDRACOLoader( dracoLoader ) {
|
|
36912
|
-
this.dracoLoader = dracoLoader;
|
|
36913
|
-
return this;
|
|
36914
|
-
}
|
|
36915
|
-
setKTX2Loader( ktx2Loader ) {
|
|
36916
|
-
this.ktx2Loader = ktx2Loader;
|
|
36917
|
-
return this;
|
|
36918
|
-
}
|
|
36919
|
-
setMeshoptDecoder( meshoptDecoder ) {
|
|
36920
|
-
this.meshoptDecoder = meshoptDecoder;
|
|
36921
|
-
return this;
|
|
36922
|
-
}
|
|
36923
|
-
register( callback ) {
|
|
36924
|
-
if ( this.pluginCallbacks.indexOf( callback ) === -1 ) {
|
|
36925
|
-
this.pluginCallbacks.push( callback );
|
|
36926
|
-
}
|
|
36927
|
-
return this;
|
|
36928
|
-
}
|
|
36929
|
-
unregister( callback ) {
|
|
36930
|
-
if ( this.pluginCallbacks.indexOf( callback ) !== -1 ) {
|
|
36931
|
-
this.pluginCallbacks.splice( this.pluginCallbacks.indexOf( callback ), 1 );
|
|
36932
|
-
}
|
|
36933
|
-
return this;
|
|
36934
|
-
}
|
|
36935
|
-
parse( data, path, onLoad, onError ) {
|
|
36936
|
-
let json;
|
|
36937
|
-
const extensions = {};
|
|
36938
|
-
const plugins = {};
|
|
36939
|
-
const textDecoder = new TextDecoder();
|
|
36940
|
-
if ( typeof data === 'string' ) {
|
|
36941
|
-
json = JSON.parse( data );
|
|
36942
|
-
} else if ( data instanceof ArrayBuffer ) {
|
|
36943
|
-
const magic = textDecoder.decode( new Uint8Array( data, 0, 4 ) );
|
|
36944
|
-
if ( magic === BINARY_EXTENSION_HEADER_MAGIC ) {
|
|
36945
|
-
try {
|
|
36946
|
-
extensions[ EXTENSIONS.KHR_BINARY_GLTF ] = new GLTFBinaryExtension( data );
|
|
36947
|
-
} catch ( error ) {
|
|
36948
|
-
if ( onError ) onError( error );
|
|
36949
|
-
return;
|
|
36950
|
-
}
|
|
36951
|
-
json = JSON.parse( extensions[ EXTENSIONS.KHR_BINARY_GLTF ].content );
|
|
36952
|
-
} else {
|
|
36953
|
-
json = JSON.parse( textDecoder.decode( data ) );
|
|
36954
|
-
}
|
|
36955
|
-
} else {
|
|
36956
|
-
json = data;
|
|
36957
|
-
}
|
|
36958
|
-
if ( json.asset === undefined || json.asset.version[ 0 ] < 2 ) {
|
|
36959
|
-
if ( onError ) onError( new Error( 'THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.' ) );
|
|
36960
|
-
return;
|
|
36961
|
-
}
|
|
36962
|
-
const parser = new GLTFParser( json, {
|
|
36963
|
-
path: path || this.resourcePath || '',
|
|
36964
|
-
crossOrigin: this.crossOrigin,
|
|
36965
|
-
requestHeader: this.requestHeader,
|
|
36966
|
-
manager: this.manager,
|
|
36967
|
-
ktx2Loader: this.ktx2Loader,
|
|
36968
|
-
meshoptDecoder: this.meshoptDecoder
|
|
36969
|
-
} );
|
|
36970
|
-
parser.fileLoader.setRequestHeader( this.requestHeader );
|
|
36971
|
-
for ( let i = 0; i < this.pluginCallbacks.length; i ++ ) {
|
|
36972
|
-
const plugin = this.pluginCallbacks[ i ]( parser );
|
|
36973
|
-
if ( ! plugin.name ) console.error( 'THREE.GLTFLoader: Invalid plugin found: missing name' );
|
|
36974
|
-
plugins[ plugin.name ] = plugin;
|
|
36975
|
-
extensions[ plugin.name ] = true;
|
|
36976
|
-
}
|
|
36977
|
-
if ( json.extensionsUsed ) {
|
|
36978
|
-
for ( let i = 0; i < json.extensionsUsed.length; ++ i ) {
|
|
36979
|
-
const extensionName = json.extensionsUsed[ i ];
|
|
36980
|
-
const extensionsRequired = json.extensionsRequired || [];
|
|
36981
|
-
switch ( extensionName ) {
|
|
36982
|
-
case EXTENSIONS.KHR_MATERIALS_UNLIT:
|
|
36983
|
-
extensions[ extensionName ] = new GLTFMaterialsUnlitExtension();
|
|
36984
|
-
break;
|
|
36985
|
-
case EXTENSIONS.KHR_DRACO_MESH_COMPRESSION:
|
|
36986
|
-
extensions[ extensionName ] = new GLTFDracoMeshCompressionExtension( json, this.dracoLoader );
|
|
36987
|
-
break;
|
|
36988
|
-
case EXTENSIONS.KHR_TEXTURE_TRANSFORM:
|
|
36989
|
-
extensions[ extensionName ] = new GLTFTextureTransformExtension();
|
|
36990
|
-
break;
|
|
36991
|
-
case EXTENSIONS.KHR_MESH_QUANTIZATION:
|
|
36992
|
-
extensions[ extensionName ] = new GLTFMeshQuantizationExtension();
|
|
36993
|
-
break;
|
|
36994
|
-
default:
|
|
36995
|
-
if ( extensionsRequired.indexOf( extensionName ) >= 0 && plugins[ extensionName ] === undefined ) {
|
|
36996
|
-
console.warn( 'THREE.GLTFLoader: Unknown extension "' + extensionName + '".' );
|
|
36997
|
-
}
|
|
36998
|
-
}
|
|
36999
|
-
}
|
|
37000
|
-
}
|
|
37001
|
-
parser.setExtensions( extensions );
|
|
37002
|
-
parser.setPlugins( plugins );
|
|
37003
|
-
parser.parse( onLoad, onError );
|
|
37004
|
-
}
|
|
37005
|
-
parseAsync( data, path ) {
|
|
37006
|
-
const scope = this;
|
|
37007
|
-
return new Promise( function ( resolve, reject ) {
|
|
37008
|
-
scope.parse( data, path, resolve, reject );
|
|
37009
|
-
} );
|
|
37010
|
-
}
|
|
37011
|
-
}
|
|
37012
|
-
function GLTFRegistry() {
|
|
37013
|
-
let objects = {};
|
|
37014
|
-
return {
|
|
37015
|
-
get: function ( key ) {
|
|
37016
|
-
return objects[ key ];
|
|
37017
|
-
},
|
|
37018
|
-
add: function ( key, object ) {
|
|
37019
|
-
objects[ key ] = object;
|
|
37020
|
-
},
|
|
37021
|
-
remove: function ( key ) {
|
|
37022
|
-
delete objects[ key ];
|
|
37023
|
-
},
|
|
37024
|
-
removeAll: function () {
|
|
37025
|
-
objects = {};
|
|
37026
|
-
}
|
|
37027
|
-
};
|
|
37028
|
-
}
|
|
37029
|
-
const EXTENSIONS = {
|
|
37030
|
-
KHR_BINARY_GLTF: 'KHR_binary_glTF',
|
|
37031
|
-
KHR_DRACO_MESH_COMPRESSION: 'KHR_draco_mesh_compression',
|
|
37032
|
-
KHR_LIGHTS_PUNCTUAL: 'KHR_lights_punctual',
|
|
37033
|
-
KHR_MATERIALS_CLEARCOAT: 'KHR_materials_clearcoat',
|
|
37034
|
-
KHR_MATERIALS_DISPERSION: 'KHR_materials_dispersion',
|
|
37035
|
-
KHR_MATERIALS_IOR: 'KHR_materials_ior',
|
|
37036
|
-
KHR_MATERIALS_SHEEN: 'KHR_materials_sheen',
|
|
37037
|
-
KHR_MATERIALS_SPECULAR: 'KHR_materials_specular',
|
|
37038
|
-
KHR_MATERIALS_TRANSMISSION: 'KHR_materials_transmission',
|
|
37039
|
-
KHR_MATERIALS_IRIDESCENCE: 'KHR_materials_iridescence',
|
|
37040
|
-
KHR_MATERIALS_ANISOTROPY: 'KHR_materials_anisotropy',
|
|
37041
|
-
KHR_MATERIALS_UNLIT: 'KHR_materials_unlit',
|
|
37042
|
-
KHR_MATERIALS_VOLUME: 'KHR_materials_volume',
|
|
37043
|
-
KHR_TEXTURE_BASISU: 'KHR_texture_basisu',
|
|
37044
|
-
KHR_TEXTURE_TRANSFORM: 'KHR_texture_transform',
|
|
37045
|
-
KHR_MESH_QUANTIZATION: 'KHR_mesh_quantization',
|
|
37046
|
-
KHR_MATERIALS_EMISSIVE_STRENGTH: 'KHR_materials_emissive_strength',
|
|
37047
|
-
EXT_MATERIALS_BUMP: 'EXT_materials_bump',
|
|
37048
|
-
EXT_TEXTURE_WEBP: 'EXT_texture_webp',
|
|
37049
|
-
EXT_TEXTURE_AVIF: 'EXT_texture_avif',
|
|
37050
|
-
EXT_MESHOPT_COMPRESSION: 'EXT_meshopt_compression',
|
|
37051
|
-
EXT_MESH_GPU_INSTANCING: 'EXT_mesh_gpu_instancing'
|
|
37052
|
-
};
|
|
37053
|
-
class GLTFLightsExtension {
|
|
37054
|
-
constructor( parser ) {
|
|
37055
|
-
this.parser = parser;
|
|
37056
|
-
this.name = EXTENSIONS.KHR_LIGHTS_PUNCTUAL;
|
|
37057
|
-
this.cache = { refs: {}, uses: {} };
|
|
37058
|
-
}
|
|
37059
|
-
_markDefs() {
|
|
37060
|
-
const parser = this.parser;
|
|
37061
|
-
const nodeDefs = this.parser.json.nodes || [];
|
|
37062
|
-
for ( let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex ++ ) {
|
|
37063
|
-
const nodeDef = nodeDefs[ nodeIndex ];
|
|
37064
|
-
if ( nodeDef.extensions
|
|
37065
|
-
&& nodeDef.extensions[ this.name ]
|
|
37066
|
-
&& nodeDef.extensions[ this.name ].light !== undefined ) {
|
|
37067
|
-
parser._addNodeRef( this.cache, nodeDef.extensions[ this.name ].light );
|
|
37068
|
-
}
|
|
37069
|
-
}
|
|
37070
|
-
}
|
|
37071
|
-
_loadLight( lightIndex ) {
|
|
37072
|
-
const parser = this.parser;
|
|
37073
|
-
const cacheKey = 'light:' + lightIndex;
|
|
37074
|
-
let dependency = parser.cache.get( cacheKey );
|
|
37075
|
-
if ( dependency ) return dependency;
|
|
37076
|
-
const json = parser.json;
|
|
37077
|
-
const extensions = ( json.extensions && json.extensions[ this.name ] ) || {};
|
|
37078
|
-
const lightDefs = extensions.lights || [];
|
|
37079
|
-
const lightDef = lightDefs[ lightIndex ];
|
|
37080
|
-
let lightNode;
|
|
37081
|
-
const color = new Color( 0xffffff );
|
|
37082
|
-
if ( lightDef.color !== undefined ) color.setRGB( lightDef.color[ 0 ], lightDef.color[ 1 ], lightDef.color[ 2 ], LinearSRGBColorSpace );
|
|
37083
|
-
const range = lightDef.range !== undefined ? lightDef.range : 0;
|
|
37084
|
-
switch ( lightDef.type ) {
|
|
37085
|
-
case 'directional':
|
|
37086
|
-
lightNode = new DirectionalLight( color );
|
|
37087
|
-
lightNode.target.position.set( 0, 0, -1 );
|
|
37088
|
-
lightNode.add( lightNode.target );
|
|
37089
|
-
break;
|
|
37090
|
-
case 'point':
|
|
37091
|
-
lightNode = new PointLight( color );
|
|
37092
|
-
lightNode.distance = range;
|
|
37093
|
-
break;
|
|
37094
|
-
case 'spot':
|
|
37095
|
-
lightNode = new SpotLight( color );
|
|
37096
|
-
lightNode.distance = range;
|
|
37097
|
-
lightDef.spot = lightDef.spot || {};
|
|
37098
|
-
lightDef.spot.innerConeAngle = lightDef.spot.innerConeAngle !== undefined ? lightDef.spot.innerConeAngle : 0;
|
|
37099
|
-
lightDef.spot.outerConeAngle = lightDef.spot.outerConeAngle !== undefined ? lightDef.spot.outerConeAngle : Math.PI / 4.0;
|
|
37100
|
-
lightNode.angle = lightDef.spot.outerConeAngle;
|
|
37101
|
-
lightNode.penumbra = 1.0 - lightDef.spot.innerConeAngle / lightDef.spot.outerConeAngle;
|
|
37102
|
-
lightNode.target.position.set( 0, 0, -1 );
|
|
37103
|
-
lightNode.add( lightNode.target );
|
|
37104
|
-
break;
|
|
37105
|
-
default:
|
|
37106
|
-
throw new Error( 'THREE.GLTFLoader: Unexpected light type: ' + lightDef.type );
|
|
37107
|
-
}
|
|
37108
|
-
lightNode.position.set( 0, 0, 0 );
|
|
37109
|
-
assignExtrasToUserData( lightNode, lightDef );
|
|
37110
|
-
if ( lightDef.intensity !== undefined ) lightNode.intensity = lightDef.intensity;
|
|
37111
|
-
lightNode.name = parser.createUniqueName( lightDef.name || ( 'light_' + lightIndex ) );
|
|
37112
|
-
dependency = Promise.resolve( lightNode );
|
|
37113
|
-
parser.cache.add( cacheKey, dependency );
|
|
37114
|
-
return dependency;
|
|
37115
|
-
}
|
|
37116
|
-
getDependency( type, index ) {
|
|
37117
|
-
if ( type !== 'light' ) return;
|
|
37118
|
-
return this._loadLight( index );
|
|
37119
|
-
}
|
|
37120
|
-
createNodeAttachment( nodeIndex ) {
|
|
37121
|
-
const self = this;
|
|
37122
|
-
const parser = this.parser;
|
|
37123
|
-
const json = parser.json;
|
|
37124
|
-
const nodeDef = json.nodes[ nodeIndex ];
|
|
37125
|
-
const lightDef = ( nodeDef.extensions && nodeDef.extensions[ this.name ] ) || {};
|
|
37126
|
-
const lightIndex = lightDef.light;
|
|
37127
|
-
if ( lightIndex === undefined ) return null;
|
|
37128
|
-
return this._loadLight( lightIndex ).then( function ( light ) {
|
|
37129
|
-
return parser._getNodeRef( self.cache, lightIndex, light );
|
|
37130
|
-
} );
|
|
37131
|
-
}
|
|
37132
|
-
}
|
|
37133
|
-
class GLTFMaterialsUnlitExtension {
|
|
37134
|
-
constructor() {
|
|
37135
|
-
this.name = EXTENSIONS.KHR_MATERIALS_UNLIT;
|
|
37136
|
-
}
|
|
37137
|
-
getMaterialType() {
|
|
37138
|
-
return MeshBasicMaterial;
|
|
37139
|
-
}
|
|
37140
|
-
extendParams( materialParams, materialDef, parser ) {
|
|
37141
|
-
const pending = [];
|
|
37142
|
-
materialParams.color = new Color( 1.0, 1.0, 1.0 );
|
|
37143
|
-
materialParams.opacity = 1.0;
|
|
37144
|
-
const metallicRoughness = materialDef.pbrMetallicRoughness;
|
|
37145
|
-
if ( metallicRoughness ) {
|
|
37146
|
-
if ( Array.isArray( metallicRoughness.baseColorFactor ) ) {
|
|
37147
|
-
const array = metallicRoughness.baseColorFactor;
|
|
37148
|
-
materialParams.color.setRGB( array[ 0 ], array[ 1 ], array[ 2 ], LinearSRGBColorSpace );
|
|
37149
|
-
materialParams.opacity = array[ 3 ];
|
|
37150
|
-
}
|
|
37151
|
-
if ( metallicRoughness.baseColorTexture !== undefined ) {
|
|
37152
|
-
pending.push( parser.assignTexture( materialParams, 'map', metallicRoughness.baseColorTexture, SRGBColorSpace ) );
|
|
37153
|
-
}
|
|
37154
|
-
}
|
|
37155
|
-
return Promise.all( pending );
|
|
37156
|
-
}
|
|
37157
|
-
}
|
|
37158
|
-
class GLTFMaterialsEmissiveStrengthExtension {
|
|
37159
|
-
constructor( parser ) {
|
|
37160
|
-
this.parser = parser;
|
|
37161
|
-
this.name = EXTENSIONS.KHR_MATERIALS_EMISSIVE_STRENGTH;
|
|
37162
|
-
}
|
|
37163
|
-
extendMaterialParams( materialIndex, materialParams ) {
|
|
37164
|
-
const parser = this.parser;
|
|
37165
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37166
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
|
|
37167
|
-
return Promise.resolve();
|
|
37168
|
-
}
|
|
37169
|
-
const emissiveStrength = materialDef.extensions[ this.name ].emissiveStrength;
|
|
37170
|
-
if ( emissiveStrength !== undefined ) {
|
|
37171
|
-
materialParams.emissiveIntensity = emissiveStrength;
|
|
37172
|
-
}
|
|
37173
|
-
return Promise.resolve();
|
|
37174
|
-
}
|
|
37175
|
-
}
|
|
37176
|
-
class GLTFMaterialsClearcoatExtension {
|
|
37177
|
-
constructor( parser ) {
|
|
37178
|
-
this.parser = parser;
|
|
37179
|
-
this.name = EXTENSIONS.KHR_MATERIALS_CLEARCOAT;
|
|
37180
|
-
}
|
|
37181
|
-
getMaterialType( materialIndex ) {
|
|
37182
|
-
const parser = this.parser;
|
|
37183
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37184
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
|
|
37185
|
-
return MeshPhysicalMaterial;
|
|
37186
|
-
}
|
|
37187
|
-
extendMaterialParams( materialIndex, materialParams ) {
|
|
37188
|
-
const parser = this.parser;
|
|
37189
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37190
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
|
|
37191
|
-
return Promise.resolve();
|
|
37192
|
-
}
|
|
37193
|
-
const pending = [];
|
|
37194
|
-
const extension = materialDef.extensions[ this.name ];
|
|
37195
|
-
if ( extension.clearcoatFactor !== undefined ) {
|
|
37196
|
-
materialParams.clearcoat = extension.clearcoatFactor;
|
|
37197
|
-
}
|
|
37198
|
-
if ( extension.clearcoatTexture !== undefined ) {
|
|
37199
|
-
pending.push( parser.assignTexture( materialParams, 'clearcoatMap', extension.clearcoatTexture ) );
|
|
37200
|
-
}
|
|
37201
|
-
if ( extension.clearcoatRoughnessFactor !== undefined ) {
|
|
37202
|
-
materialParams.clearcoatRoughness = extension.clearcoatRoughnessFactor;
|
|
37203
|
-
}
|
|
37204
|
-
if ( extension.clearcoatRoughnessTexture !== undefined ) {
|
|
37205
|
-
pending.push( parser.assignTexture( materialParams, 'clearcoatRoughnessMap', extension.clearcoatRoughnessTexture ) );
|
|
37206
|
-
}
|
|
37207
|
-
if ( extension.clearcoatNormalTexture !== undefined ) {
|
|
37208
|
-
pending.push( parser.assignTexture( materialParams, 'clearcoatNormalMap', extension.clearcoatNormalTexture ) );
|
|
37209
|
-
if ( extension.clearcoatNormalTexture.scale !== undefined ) {
|
|
37210
|
-
const scale = extension.clearcoatNormalTexture.scale;
|
|
37211
|
-
materialParams.clearcoatNormalScale = new Vector2( scale, scale );
|
|
37212
|
-
}
|
|
37213
|
-
}
|
|
37214
|
-
return Promise.all( pending );
|
|
37215
|
-
}
|
|
37216
|
-
}
|
|
37217
|
-
class GLTFMaterialsDispersionExtension {
|
|
37218
|
-
constructor( parser ) {
|
|
37219
|
-
this.parser = parser;
|
|
37220
|
-
this.name = EXTENSIONS.KHR_MATERIALS_DISPERSION;
|
|
37221
|
-
}
|
|
37222
|
-
getMaterialType( materialIndex ) {
|
|
37223
|
-
const parser = this.parser;
|
|
37224
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37225
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
|
|
37226
|
-
return MeshPhysicalMaterial;
|
|
37227
|
-
}
|
|
37228
|
-
extendMaterialParams( materialIndex, materialParams ) {
|
|
37229
|
-
const parser = this.parser;
|
|
37230
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37231
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
|
|
37232
|
-
return Promise.resolve();
|
|
37233
|
-
}
|
|
37234
|
-
const extension = materialDef.extensions[ this.name ];
|
|
37235
|
-
materialParams.dispersion = extension.dispersion !== undefined ? extension.dispersion : 0;
|
|
37236
|
-
return Promise.resolve();
|
|
37237
|
-
}
|
|
37238
|
-
}
|
|
37239
|
-
class GLTFMaterialsIridescenceExtension {
|
|
37240
|
-
constructor( parser ) {
|
|
37241
|
-
this.parser = parser;
|
|
37242
|
-
this.name = EXTENSIONS.KHR_MATERIALS_IRIDESCENCE;
|
|
37243
|
-
}
|
|
37244
|
-
getMaterialType( materialIndex ) {
|
|
37245
|
-
const parser = this.parser;
|
|
37246
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37247
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
|
|
37248
|
-
return MeshPhysicalMaterial;
|
|
37249
|
-
}
|
|
37250
|
-
extendMaterialParams( materialIndex, materialParams ) {
|
|
37251
|
-
const parser = this.parser;
|
|
37252
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37253
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
|
|
37254
|
-
return Promise.resolve();
|
|
37255
|
-
}
|
|
37256
|
-
const pending = [];
|
|
37257
|
-
const extension = materialDef.extensions[ this.name ];
|
|
37258
|
-
if ( extension.iridescenceFactor !== undefined ) {
|
|
37259
|
-
materialParams.iridescence = extension.iridescenceFactor;
|
|
37260
|
-
}
|
|
37261
|
-
if ( extension.iridescenceTexture !== undefined ) {
|
|
37262
|
-
pending.push( parser.assignTexture( materialParams, 'iridescenceMap', extension.iridescenceTexture ) );
|
|
37263
|
-
}
|
|
37264
|
-
if ( extension.iridescenceIor !== undefined ) {
|
|
37265
|
-
materialParams.iridescenceIOR = extension.iridescenceIor;
|
|
37266
|
-
}
|
|
37267
|
-
if ( materialParams.iridescenceThicknessRange === undefined ) {
|
|
37268
|
-
materialParams.iridescenceThicknessRange = [ 100, 400 ];
|
|
37269
|
-
}
|
|
37270
|
-
if ( extension.iridescenceThicknessMinimum !== undefined ) {
|
|
37271
|
-
materialParams.iridescenceThicknessRange[ 0 ] = extension.iridescenceThicknessMinimum;
|
|
37272
|
-
}
|
|
37273
|
-
if ( extension.iridescenceThicknessMaximum !== undefined ) {
|
|
37274
|
-
materialParams.iridescenceThicknessRange[ 1 ] = extension.iridescenceThicknessMaximum;
|
|
37275
|
-
}
|
|
37276
|
-
if ( extension.iridescenceThicknessTexture !== undefined ) {
|
|
37277
|
-
pending.push( parser.assignTexture( materialParams, 'iridescenceThicknessMap', extension.iridescenceThicknessTexture ) );
|
|
37278
|
-
}
|
|
37279
|
-
return Promise.all( pending );
|
|
37280
|
-
}
|
|
37281
|
-
}
|
|
37282
|
-
class GLTFMaterialsSheenExtension {
|
|
37283
|
-
constructor( parser ) {
|
|
37284
|
-
this.parser = parser;
|
|
37285
|
-
this.name = EXTENSIONS.KHR_MATERIALS_SHEEN;
|
|
37286
|
-
}
|
|
37287
|
-
getMaterialType( materialIndex ) {
|
|
37288
|
-
const parser = this.parser;
|
|
37289
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37290
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
|
|
37291
|
-
return MeshPhysicalMaterial;
|
|
37292
|
-
}
|
|
37293
|
-
extendMaterialParams( materialIndex, materialParams ) {
|
|
37294
|
-
const parser = this.parser;
|
|
37295
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37296
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
|
|
37297
|
-
return Promise.resolve();
|
|
37298
|
-
}
|
|
37299
|
-
const pending = [];
|
|
37300
|
-
materialParams.sheenColor = new Color( 0, 0, 0 );
|
|
37301
|
-
materialParams.sheenRoughness = 0;
|
|
37302
|
-
materialParams.sheen = 1;
|
|
37303
|
-
const extension = materialDef.extensions[ this.name ];
|
|
37304
|
-
if ( extension.sheenColorFactor !== undefined ) {
|
|
37305
|
-
const colorFactor = extension.sheenColorFactor;
|
|
37306
|
-
materialParams.sheenColor.setRGB( colorFactor[ 0 ], colorFactor[ 1 ], colorFactor[ 2 ], LinearSRGBColorSpace );
|
|
37307
|
-
}
|
|
37308
|
-
if ( extension.sheenRoughnessFactor !== undefined ) {
|
|
37309
|
-
materialParams.sheenRoughness = extension.sheenRoughnessFactor;
|
|
37310
|
-
}
|
|
37311
|
-
if ( extension.sheenColorTexture !== undefined ) {
|
|
37312
|
-
pending.push( parser.assignTexture( materialParams, 'sheenColorMap', extension.sheenColorTexture, SRGBColorSpace ) );
|
|
37313
|
-
}
|
|
37314
|
-
if ( extension.sheenRoughnessTexture !== undefined ) {
|
|
37315
|
-
pending.push( parser.assignTexture( materialParams, 'sheenRoughnessMap', extension.sheenRoughnessTexture ) );
|
|
37316
|
-
}
|
|
37317
|
-
return Promise.all( pending );
|
|
37318
|
-
}
|
|
37319
|
-
}
|
|
37320
|
-
class GLTFMaterialsTransmissionExtension {
|
|
37321
|
-
constructor( parser ) {
|
|
37322
|
-
this.parser = parser;
|
|
37323
|
-
this.name = EXTENSIONS.KHR_MATERIALS_TRANSMISSION;
|
|
37324
|
-
}
|
|
37325
|
-
getMaterialType( materialIndex ) {
|
|
37326
|
-
const parser = this.parser;
|
|
37327
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37328
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
|
|
37329
|
-
return MeshPhysicalMaterial;
|
|
37330
|
-
}
|
|
37331
|
-
extendMaterialParams( materialIndex, materialParams ) {
|
|
37332
|
-
const parser = this.parser;
|
|
37333
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37334
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
|
|
37335
|
-
return Promise.resolve();
|
|
37336
|
-
}
|
|
37337
|
-
const pending = [];
|
|
37338
|
-
const extension = materialDef.extensions[ this.name ];
|
|
37339
|
-
if ( extension.transmissionFactor !== undefined ) {
|
|
37340
|
-
materialParams.transmission = extension.transmissionFactor;
|
|
37341
|
-
}
|
|
37342
|
-
if ( extension.transmissionTexture !== undefined ) {
|
|
37343
|
-
pending.push( parser.assignTexture( materialParams, 'transmissionMap', extension.transmissionTexture ) );
|
|
37344
|
-
}
|
|
37345
|
-
return Promise.all( pending );
|
|
37346
|
-
}
|
|
37347
|
-
}
|
|
37348
|
-
class GLTFMaterialsVolumeExtension {
|
|
37349
|
-
constructor( parser ) {
|
|
37350
|
-
this.parser = parser;
|
|
37351
|
-
this.name = EXTENSIONS.KHR_MATERIALS_VOLUME;
|
|
37352
|
-
}
|
|
37353
|
-
getMaterialType( materialIndex ) {
|
|
37354
|
-
const parser = this.parser;
|
|
37355
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37356
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
|
|
37357
|
-
return MeshPhysicalMaterial;
|
|
37358
|
-
}
|
|
37359
|
-
extendMaterialParams( materialIndex, materialParams ) {
|
|
37360
|
-
const parser = this.parser;
|
|
37361
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37362
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
|
|
37363
|
-
return Promise.resolve();
|
|
37364
|
-
}
|
|
37365
|
-
const pending = [];
|
|
37366
|
-
const extension = materialDef.extensions[ this.name ];
|
|
37367
|
-
materialParams.thickness = extension.thicknessFactor !== undefined ? extension.thicknessFactor : 0;
|
|
37368
|
-
if ( extension.thicknessTexture !== undefined ) {
|
|
37369
|
-
pending.push( parser.assignTexture( materialParams, 'thicknessMap', extension.thicknessTexture ) );
|
|
37370
|
-
}
|
|
37371
|
-
materialParams.attenuationDistance = extension.attenuationDistance || Infinity;
|
|
37372
|
-
const colorArray = extension.attenuationColor || [ 1, 1, 1 ];
|
|
37373
|
-
materialParams.attenuationColor = new Color().setRGB( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ], LinearSRGBColorSpace );
|
|
37374
|
-
return Promise.all( pending );
|
|
37375
|
-
}
|
|
37376
|
-
}
|
|
37377
|
-
class GLTFMaterialsIorExtension {
|
|
37378
|
-
constructor( parser ) {
|
|
37379
|
-
this.parser = parser;
|
|
37380
|
-
this.name = EXTENSIONS.KHR_MATERIALS_IOR;
|
|
37381
|
-
}
|
|
37382
|
-
getMaterialType( materialIndex ) {
|
|
37383
|
-
const parser = this.parser;
|
|
37384
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37385
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
|
|
37386
|
-
return MeshPhysicalMaterial;
|
|
37387
|
-
}
|
|
37388
|
-
extendMaterialParams( materialIndex, materialParams ) {
|
|
37389
|
-
const parser = this.parser;
|
|
37390
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37391
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
|
|
37392
|
-
return Promise.resolve();
|
|
37393
|
-
}
|
|
37394
|
-
const extension = materialDef.extensions[ this.name ];
|
|
37395
|
-
materialParams.ior = extension.ior !== undefined ? extension.ior : 1.5;
|
|
37396
|
-
return Promise.resolve();
|
|
37397
|
-
}
|
|
37398
|
-
}
|
|
37399
|
-
class GLTFMaterialsSpecularExtension {
|
|
37400
|
-
constructor( parser ) {
|
|
37401
|
-
this.parser = parser;
|
|
37402
|
-
this.name = EXTENSIONS.KHR_MATERIALS_SPECULAR;
|
|
37403
|
-
}
|
|
37404
|
-
getMaterialType( materialIndex ) {
|
|
37405
|
-
const parser = this.parser;
|
|
37406
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37407
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
|
|
37408
|
-
return MeshPhysicalMaterial;
|
|
37409
|
-
}
|
|
37410
|
-
extendMaterialParams( materialIndex, materialParams ) {
|
|
37411
|
-
const parser = this.parser;
|
|
37412
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37413
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
|
|
37414
|
-
return Promise.resolve();
|
|
37415
|
-
}
|
|
37416
|
-
const pending = [];
|
|
37417
|
-
const extension = materialDef.extensions[ this.name ];
|
|
37418
|
-
materialParams.specularIntensity = extension.specularFactor !== undefined ? extension.specularFactor : 1.0;
|
|
37419
|
-
if ( extension.specularTexture !== undefined ) {
|
|
37420
|
-
pending.push( parser.assignTexture( materialParams, 'specularIntensityMap', extension.specularTexture ) );
|
|
37421
|
-
}
|
|
37422
|
-
const colorArray = extension.specularColorFactor || [ 1, 1, 1 ];
|
|
37423
|
-
materialParams.specularColor = new Color().setRGB( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ], LinearSRGBColorSpace );
|
|
37424
|
-
if ( extension.specularColorTexture !== undefined ) {
|
|
37425
|
-
pending.push( parser.assignTexture( materialParams, 'specularColorMap', extension.specularColorTexture, SRGBColorSpace ) );
|
|
37426
|
-
}
|
|
37427
|
-
return Promise.all( pending );
|
|
37428
|
-
}
|
|
37429
|
-
}
|
|
37430
|
-
class GLTFMaterialsBumpExtension {
|
|
37431
|
-
constructor( parser ) {
|
|
37432
|
-
this.parser = parser;
|
|
37433
|
-
this.name = EXTENSIONS.EXT_MATERIALS_BUMP;
|
|
37434
|
-
}
|
|
37435
|
-
getMaterialType( materialIndex ) {
|
|
37436
|
-
const parser = this.parser;
|
|
37437
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37438
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
|
|
37439
|
-
return MeshPhysicalMaterial;
|
|
37440
|
-
}
|
|
37441
|
-
extendMaterialParams( materialIndex, materialParams ) {
|
|
37442
|
-
const parser = this.parser;
|
|
37443
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37444
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
|
|
37445
|
-
return Promise.resolve();
|
|
37446
|
-
}
|
|
37447
|
-
const pending = [];
|
|
37448
|
-
const extension = materialDef.extensions[ this.name ];
|
|
37449
|
-
materialParams.bumpScale = extension.bumpFactor !== undefined ? extension.bumpFactor : 1.0;
|
|
37450
|
-
if ( extension.bumpTexture !== undefined ) {
|
|
37451
|
-
pending.push( parser.assignTexture( materialParams, 'bumpMap', extension.bumpTexture ) );
|
|
37452
|
-
}
|
|
37453
|
-
return Promise.all( pending );
|
|
37454
|
-
}
|
|
37455
|
-
}
|
|
37456
|
-
class GLTFMaterialsAnisotropyExtension {
|
|
37457
|
-
constructor( parser ) {
|
|
37458
|
-
this.parser = parser;
|
|
37459
|
-
this.name = EXTENSIONS.KHR_MATERIALS_ANISOTROPY;
|
|
37460
|
-
}
|
|
37461
|
-
getMaterialType( materialIndex ) {
|
|
37462
|
-
const parser = this.parser;
|
|
37463
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37464
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
|
|
37465
|
-
return MeshPhysicalMaterial;
|
|
37466
|
-
}
|
|
37467
|
-
extendMaterialParams( materialIndex, materialParams ) {
|
|
37468
|
-
const parser = this.parser;
|
|
37469
|
-
const materialDef = parser.json.materials[ materialIndex ];
|
|
37470
|
-
if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
|
|
37471
|
-
return Promise.resolve();
|
|
37472
|
-
}
|
|
37473
|
-
const pending = [];
|
|
37474
|
-
const extension = materialDef.extensions[ this.name ];
|
|
37475
|
-
if ( extension.anisotropyStrength !== undefined ) {
|
|
37476
|
-
materialParams.anisotropy = extension.anisotropyStrength;
|
|
37477
|
-
}
|
|
37478
|
-
if ( extension.anisotropyRotation !== undefined ) {
|
|
37479
|
-
materialParams.anisotropyRotation = extension.anisotropyRotation;
|
|
37480
|
-
}
|
|
37481
|
-
if ( extension.anisotropyTexture !== undefined ) {
|
|
37482
|
-
pending.push( parser.assignTexture( materialParams, 'anisotropyMap', extension.anisotropyTexture ) );
|
|
37483
|
-
}
|
|
37484
|
-
return Promise.all( pending );
|
|
37485
|
-
}
|
|
37486
|
-
}
|
|
37487
|
-
class GLTFTextureBasisUExtension {
|
|
37488
|
-
constructor( parser ) {
|
|
37489
|
-
this.parser = parser;
|
|
37490
|
-
this.name = EXTENSIONS.KHR_TEXTURE_BASISU;
|
|
37491
|
-
}
|
|
37492
|
-
loadTexture( textureIndex ) {
|
|
37493
|
-
const parser = this.parser;
|
|
37494
|
-
const json = parser.json;
|
|
37495
|
-
const textureDef = json.textures[ textureIndex ];
|
|
37496
|
-
if ( ! textureDef.extensions || ! textureDef.extensions[ this.name ] ) {
|
|
37497
|
-
return null;
|
|
37498
|
-
}
|
|
37499
|
-
const extension = textureDef.extensions[ this.name ];
|
|
37500
|
-
const loader = parser.options.ktx2Loader;
|
|
37501
|
-
if ( ! loader ) {
|
|
37502
|
-
if ( json.extensionsRequired && json.extensionsRequired.indexOf( this.name ) >= 0 ) {
|
|
37503
|
-
throw new Error( 'THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures' );
|
|
37504
|
-
} else {
|
|
37505
|
-
return null;
|
|
37506
|
-
}
|
|
37507
|
-
}
|
|
37508
|
-
return parser.loadTextureImage( textureIndex, extension.source, loader );
|
|
37509
|
-
}
|
|
37510
|
-
}
|
|
37511
|
-
class GLTFTextureWebPExtension {
|
|
37512
|
-
constructor( parser ) {
|
|
37513
|
-
this.parser = parser;
|
|
37514
|
-
this.name = EXTENSIONS.EXT_TEXTURE_WEBP;
|
|
37515
|
-
}
|
|
37516
|
-
loadTexture( textureIndex ) {
|
|
37517
|
-
const name = this.name;
|
|
37518
|
-
const parser = this.parser;
|
|
37519
|
-
const json = parser.json;
|
|
37520
|
-
const textureDef = json.textures[ textureIndex ];
|
|
37521
|
-
if ( ! textureDef.extensions || ! textureDef.extensions[ name ] ) {
|
|
37522
|
-
return null;
|
|
37523
|
-
}
|
|
37524
|
-
const extension = textureDef.extensions[ name ];
|
|
37525
|
-
const source = json.images[ extension.source ];
|
|
37526
|
-
let loader = parser.textureLoader;
|
|
37527
|
-
if ( source.uri ) {
|
|
37528
|
-
const handler = parser.options.manager.getHandler( source.uri );
|
|
37529
|
-
if ( handler !== null ) loader = handler;
|
|
37530
|
-
}
|
|
37531
|
-
return parser.loadTextureImage( textureIndex, extension.source, loader );
|
|
37532
|
-
}
|
|
37533
|
-
}
|
|
37534
|
-
class GLTFTextureAVIFExtension {
|
|
37535
|
-
constructor( parser ) {
|
|
37536
|
-
this.parser = parser;
|
|
37537
|
-
this.name = EXTENSIONS.EXT_TEXTURE_AVIF;
|
|
37538
|
-
}
|
|
37539
|
-
loadTexture( textureIndex ) {
|
|
37540
|
-
const name = this.name;
|
|
37541
|
-
const parser = this.parser;
|
|
37542
|
-
const json = parser.json;
|
|
37543
|
-
const textureDef = json.textures[ textureIndex ];
|
|
37544
|
-
if ( ! textureDef.extensions || ! textureDef.extensions[ name ] ) {
|
|
37545
|
-
return null;
|
|
37546
|
-
}
|
|
37547
|
-
const extension = textureDef.extensions[ name ];
|
|
37548
|
-
const source = json.images[ extension.source ];
|
|
37549
|
-
let loader = parser.textureLoader;
|
|
37550
|
-
if ( source.uri ) {
|
|
37551
|
-
const handler = parser.options.manager.getHandler( source.uri );
|
|
37552
|
-
if ( handler !== null ) loader = handler;
|
|
37553
|
-
}
|
|
37554
|
-
return parser.loadTextureImage( textureIndex, extension.source, loader );
|
|
37555
|
-
}
|
|
37556
|
-
}
|
|
37557
|
-
class GLTFMeshoptCompression {
|
|
37558
|
-
constructor( parser ) {
|
|
37559
|
-
this.name = EXTENSIONS.EXT_MESHOPT_COMPRESSION;
|
|
37560
|
-
this.parser = parser;
|
|
37561
|
-
}
|
|
37562
|
-
loadBufferView( index ) {
|
|
37563
|
-
const json = this.parser.json;
|
|
37564
|
-
const bufferView = json.bufferViews[ index ];
|
|
37565
|
-
if ( bufferView.extensions && bufferView.extensions[ this.name ] ) {
|
|
37566
|
-
const extensionDef = bufferView.extensions[ this.name ];
|
|
37567
|
-
const buffer = this.parser.getDependency( 'buffer', extensionDef.buffer );
|
|
37568
|
-
const decoder = this.parser.options.meshoptDecoder;
|
|
37569
|
-
if ( ! decoder || ! decoder.supported ) {
|
|
37570
|
-
if ( json.extensionsRequired && json.extensionsRequired.indexOf( this.name ) >= 0 ) {
|
|
37571
|
-
throw new Error( 'THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files' );
|
|
37572
|
-
} else {
|
|
37573
|
-
return null;
|
|
37574
|
-
}
|
|
37575
|
-
}
|
|
37576
|
-
return buffer.then( function ( res ) {
|
|
37577
|
-
const byteOffset = extensionDef.byteOffset || 0;
|
|
37578
|
-
const byteLength = extensionDef.byteLength || 0;
|
|
37579
|
-
const count = extensionDef.count;
|
|
37580
|
-
const stride = extensionDef.byteStride;
|
|
37581
|
-
const source = new Uint8Array( res, byteOffset, byteLength );
|
|
37582
|
-
if ( decoder.decodeGltfBufferAsync ) {
|
|
37583
|
-
return decoder.decodeGltfBufferAsync( count, stride, source, extensionDef.mode, extensionDef.filter ).then( function ( res ) {
|
|
37584
|
-
return res.buffer;
|
|
37585
|
-
} );
|
|
37586
|
-
} else {
|
|
37587
|
-
return decoder.ready.then( function () {
|
|
37588
|
-
const result = new ArrayBuffer( count * stride );
|
|
37589
|
-
decoder.decodeGltfBuffer( new Uint8Array( result ), count, stride, source, extensionDef.mode, extensionDef.filter );
|
|
37590
|
-
return result;
|
|
37591
|
-
} );
|
|
37592
|
-
}
|
|
37593
|
-
} );
|
|
37594
|
-
} else {
|
|
37595
|
-
return null;
|
|
37596
|
-
}
|
|
37597
|
-
}
|
|
37598
|
-
}
|
|
37599
|
-
class GLTFMeshGpuInstancing {
|
|
37600
|
-
constructor( parser ) {
|
|
37601
|
-
this.name = EXTENSIONS.EXT_MESH_GPU_INSTANCING;
|
|
37602
|
-
this.parser = parser;
|
|
37603
|
-
}
|
|
37604
|
-
createNodeMesh( nodeIndex ) {
|
|
37605
|
-
const json = this.parser.json;
|
|
37606
|
-
const nodeDef = json.nodes[ nodeIndex ];
|
|
37607
|
-
if ( ! nodeDef.extensions || ! nodeDef.extensions[ this.name ] ||
|
|
37608
|
-
nodeDef.mesh === undefined ) {
|
|
37609
|
-
return null;
|
|
37610
|
-
}
|
|
37611
|
-
const meshDef = json.meshes[ nodeDef.mesh ];
|
|
37612
|
-
for ( const primitive of meshDef.primitives ) {
|
|
37613
|
-
if ( primitive.mode !== WEBGL_CONSTANTS.TRIANGLES &&
|
|
37614
|
-
primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_STRIP &&
|
|
37615
|
-
primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_FAN &&
|
|
37616
|
-
primitive.mode !== undefined ) {
|
|
37617
|
-
return null;
|
|
37618
|
-
}
|
|
37619
|
-
}
|
|
37620
|
-
const extensionDef = nodeDef.extensions[ this.name ];
|
|
37621
|
-
const attributesDef = extensionDef.attributes;
|
|
37622
|
-
const pending = [];
|
|
37623
|
-
const attributes = {};
|
|
37624
|
-
for ( const key in attributesDef ) {
|
|
37625
|
-
pending.push( this.parser.getDependency( 'accessor', attributesDef[ key ] ).then( accessor => {
|
|
37626
|
-
attributes[ key ] = accessor;
|
|
37627
|
-
return attributes[ key ];
|
|
37628
|
-
} ) );
|
|
37629
|
-
}
|
|
37630
|
-
if ( pending.length < 1 ) {
|
|
37631
|
-
return null;
|
|
37632
|
-
}
|
|
37633
|
-
pending.push( this.parser.createNodeMesh( nodeIndex ) );
|
|
37634
|
-
return Promise.all( pending ).then( results => {
|
|
37635
|
-
const nodeObject = results.pop();
|
|
37636
|
-
const meshes = nodeObject.isGroup ? nodeObject.children : [ nodeObject ];
|
|
37637
|
-
const count = results[ 0 ].count;
|
|
37638
|
-
const instancedMeshes = [];
|
|
37639
|
-
for ( const mesh of meshes ) {
|
|
37640
|
-
const m = new Matrix4();
|
|
37641
|
-
const p = new Vector3();
|
|
37642
|
-
const q = new Quaternion();
|
|
37643
|
-
const s = new Vector3( 1, 1, 1 );
|
|
37644
|
-
const instancedMesh = new InstancedMesh( mesh.geometry, mesh.material, count );
|
|
37645
|
-
for ( let i = 0; i < count; i ++ ) {
|
|
37646
|
-
if ( attributes.TRANSLATION ) {
|
|
37647
|
-
p.fromBufferAttribute( attributes.TRANSLATION, i );
|
|
37648
|
-
}
|
|
37649
|
-
if ( attributes.ROTATION ) {
|
|
37650
|
-
q.fromBufferAttribute( attributes.ROTATION, i );
|
|
37651
|
-
}
|
|
37652
|
-
if ( attributes.SCALE ) {
|
|
37653
|
-
s.fromBufferAttribute( attributes.SCALE, i );
|
|
37654
|
-
}
|
|
37655
|
-
instancedMesh.setMatrixAt( i, m.compose( p, q, s ) );
|
|
37656
|
-
}
|
|
37657
|
-
for ( const attributeName in attributes ) {
|
|
37658
|
-
if ( attributeName === '_COLOR_0' ) {
|
|
37659
|
-
const attr = attributes[ attributeName ];
|
|
37660
|
-
instancedMesh.instanceColor = new InstancedBufferAttribute( attr.array, attr.itemSize, attr.normalized );
|
|
37661
|
-
} else if ( attributeName !== 'TRANSLATION' &&
|
|
37662
|
-
attributeName !== 'ROTATION' &&
|
|
37663
|
-
attributeName !== 'SCALE' ) {
|
|
37664
|
-
mesh.geometry.setAttribute( attributeName, attributes[ attributeName ] );
|
|
37665
|
-
}
|
|
37666
|
-
}
|
|
37667
|
-
Object3D.prototype.copy.call( instancedMesh, mesh );
|
|
37668
|
-
this.parser.assignFinalMaterial( instancedMesh );
|
|
37669
|
-
instancedMeshes.push( instancedMesh );
|
|
37670
|
-
}
|
|
37671
|
-
if ( nodeObject.isGroup ) {
|
|
37672
|
-
nodeObject.clear();
|
|
37673
|
-
nodeObject.add( ... instancedMeshes );
|
|
37674
|
-
return nodeObject;
|
|
37675
|
-
}
|
|
37676
|
-
return instancedMeshes[ 0 ];
|
|
37677
|
-
} );
|
|
37678
|
-
}
|
|
37679
|
-
}
|
|
37680
|
-
const BINARY_EXTENSION_HEADER_MAGIC = 'glTF';
|
|
37681
|
-
const BINARY_EXTENSION_HEADER_LENGTH = 12;
|
|
37682
|
-
const BINARY_EXTENSION_CHUNK_TYPES = { JSON: 0x4E4F534A, BIN: 0x004E4942 };
|
|
37683
|
-
class GLTFBinaryExtension {
|
|
37684
|
-
constructor( data ) {
|
|
37685
|
-
this.name = EXTENSIONS.KHR_BINARY_GLTF;
|
|
37686
|
-
this.content = null;
|
|
37687
|
-
this.body = null;
|
|
37688
|
-
const headerView = new DataView( data, 0, BINARY_EXTENSION_HEADER_LENGTH );
|
|
37689
|
-
const textDecoder = new TextDecoder();
|
|
37690
|
-
this.header = {
|
|
37691
|
-
magic: textDecoder.decode( new Uint8Array( data.slice( 0, 4 ) ) ),
|
|
37692
|
-
version: headerView.getUint32( 4, true ),
|
|
37693
|
-
length: headerView.getUint32( 8, true )
|
|
37694
|
-
};
|
|
37695
|
-
if ( this.header.magic !== BINARY_EXTENSION_HEADER_MAGIC ) {
|
|
37696
|
-
throw new Error( 'THREE.GLTFLoader: Unsupported glTF-Binary header.' );
|
|
37697
|
-
} else if ( this.header.version < 2.0 ) {
|
|
37698
|
-
throw new Error( 'THREE.GLTFLoader: Legacy binary file detected.' );
|
|
37699
|
-
}
|
|
37700
|
-
const chunkContentsLength = this.header.length - BINARY_EXTENSION_HEADER_LENGTH;
|
|
37701
|
-
const chunkView = new DataView( data, BINARY_EXTENSION_HEADER_LENGTH );
|
|
37702
|
-
let chunkIndex = 0;
|
|
37703
|
-
while ( chunkIndex < chunkContentsLength ) {
|
|
37704
|
-
const chunkLength = chunkView.getUint32( chunkIndex, true );
|
|
37705
|
-
chunkIndex += 4;
|
|
37706
|
-
const chunkType = chunkView.getUint32( chunkIndex, true );
|
|
37707
|
-
chunkIndex += 4;
|
|
37708
|
-
if ( chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON ) {
|
|
37709
|
-
const contentArray = new Uint8Array( data, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength );
|
|
37710
|
-
this.content = textDecoder.decode( contentArray );
|
|
37711
|
-
} else if ( chunkType === BINARY_EXTENSION_CHUNK_TYPES.BIN ) {
|
|
37712
|
-
const byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex;
|
|
37713
|
-
this.body = data.slice( byteOffset, byteOffset + chunkLength );
|
|
37714
|
-
}
|
|
37715
|
-
chunkIndex += chunkLength;
|
|
37716
|
-
}
|
|
37717
|
-
if ( this.content === null ) {
|
|
37718
|
-
throw new Error( 'THREE.GLTFLoader: JSON content not found.' );
|
|
37719
|
-
}
|
|
37720
|
-
}
|
|
37721
|
-
}
|
|
37722
|
-
class GLTFDracoMeshCompressionExtension {
|
|
37723
|
-
constructor( json, dracoLoader ) {
|
|
37724
|
-
if ( ! dracoLoader ) {
|
|
37725
|
-
throw new Error( 'THREE.GLTFLoader: No DRACOLoader instance provided.' );
|
|
37726
|
-
}
|
|
37727
|
-
this.name = EXTENSIONS.KHR_DRACO_MESH_COMPRESSION;
|
|
37728
|
-
this.json = json;
|
|
37729
|
-
this.dracoLoader = dracoLoader;
|
|
37730
|
-
this.dracoLoader.preload();
|
|
37731
|
-
}
|
|
37732
|
-
decodePrimitive( primitive, parser ) {
|
|
37733
|
-
const json = this.json;
|
|
37734
|
-
const dracoLoader = this.dracoLoader;
|
|
37735
|
-
const bufferViewIndex = primitive.extensions[ this.name ].bufferView;
|
|
37736
|
-
const gltfAttributeMap = primitive.extensions[ this.name ].attributes;
|
|
37737
|
-
const threeAttributeMap = {};
|
|
37738
|
-
const attributeNormalizedMap = {};
|
|
37739
|
-
const attributeTypeMap = {};
|
|
37740
|
-
for ( const attributeName in gltfAttributeMap ) {
|
|
37741
|
-
const threeAttributeName = ATTRIBUTES[ attributeName ] || attributeName.toLowerCase();
|
|
37742
|
-
threeAttributeMap[ threeAttributeName ] = gltfAttributeMap[ attributeName ];
|
|
37743
|
-
}
|
|
37744
|
-
for ( const attributeName in primitive.attributes ) {
|
|
37745
|
-
const threeAttributeName = ATTRIBUTES[ attributeName ] || attributeName.toLowerCase();
|
|
37746
|
-
if ( gltfAttributeMap[ attributeName ] !== undefined ) {
|
|
37747
|
-
const accessorDef = json.accessors[ primitive.attributes[ attributeName ] ];
|
|
37748
|
-
const componentType = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ];
|
|
37749
|
-
attributeTypeMap[ threeAttributeName ] = componentType.name;
|
|
37750
|
-
attributeNormalizedMap[ threeAttributeName ] = accessorDef.normalized === true;
|
|
37751
|
-
}
|
|
37752
|
-
}
|
|
37753
|
-
return parser.getDependency( 'bufferView', bufferViewIndex ).then( function ( bufferView ) {
|
|
37754
|
-
return new Promise( function ( resolve, reject ) {
|
|
37755
|
-
dracoLoader.decodeDracoFile( bufferView, function ( geometry ) {
|
|
37756
|
-
for ( const attributeName in geometry.attributes ) {
|
|
37757
|
-
const attribute = geometry.attributes[ attributeName ];
|
|
37758
|
-
const normalized = attributeNormalizedMap[ attributeName ];
|
|
37759
|
-
if ( normalized !== undefined ) attribute.normalized = normalized;
|
|
37760
|
-
}
|
|
37761
|
-
resolve( geometry );
|
|
37762
|
-
}, threeAttributeMap, attributeTypeMap, LinearSRGBColorSpace, reject );
|
|
37763
|
-
} );
|
|
37764
|
-
} );
|
|
37765
|
-
}
|
|
37766
|
-
}
|
|
37767
|
-
class GLTFTextureTransformExtension {
|
|
37768
|
-
constructor() {
|
|
37769
|
-
this.name = EXTENSIONS.KHR_TEXTURE_TRANSFORM;
|
|
37770
|
-
}
|
|
37771
|
-
extendTexture( texture, transform ) {
|
|
37772
|
-
if ( ( transform.texCoord === undefined || transform.texCoord === texture.channel )
|
|
37773
|
-
&& transform.offset === undefined
|
|
37774
|
-
&& transform.rotation === undefined
|
|
37775
|
-
&& transform.scale === undefined ) {
|
|
37776
|
-
return texture;
|
|
37777
|
-
}
|
|
37778
|
-
texture = texture.clone();
|
|
37779
|
-
if ( transform.texCoord !== undefined ) {
|
|
37780
|
-
texture.channel = transform.texCoord;
|
|
37781
|
-
}
|
|
37782
|
-
if ( transform.offset !== undefined ) {
|
|
37783
|
-
texture.offset.fromArray( transform.offset );
|
|
37784
|
-
}
|
|
37785
|
-
if ( transform.rotation !== undefined ) {
|
|
37786
|
-
texture.rotation = transform.rotation;
|
|
37787
|
-
}
|
|
37788
|
-
if ( transform.scale !== undefined ) {
|
|
37789
|
-
texture.repeat.fromArray( transform.scale );
|
|
37790
|
-
}
|
|
37791
|
-
texture.needsUpdate = true;
|
|
37792
|
-
return texture;
|
|
37793
|
-
}
|
|
37794
|
-
}
|
|
37795
|
-
class GLTFMeshQuantizationExtension {
|
|
37796
|
-
constructor() {
|
|
37797
|
-
this.name = EXTENSIONS.KHR_MESH_QUANTIZATION;
|
|
37798
|
-
}
|
|
37799
|
-
}
|
|
37800
|
-
class GLTFCubicSplineInterpolant extends Interpolant {
|
|
37801
|
-
constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
|
|
37802
|
-
super( parameterPositions, sampleValues, sampleSize, resultBuffer );
|
|
37803
|
-
}
|
|
37804
|
-
copySampleValue_( index ) {
|
|
37805
|
-
const result = this.resultBuffer,
|
|
37806
|
-
values = this.sampleValues,
|
|
37807
|
-
valueSize = this.valueSize,
|
|
37808
|
-
offset = index * valueSize * 3 + valueSize;
|
|
37809
|
-
for ( let i = 0; i !== valueSize; i ++ ) {
|
|
37810
|
-
result[ i ] = values[ offset + i ];
|
|
37811
|
-
}
|
|
37812
|
-
return result;
|
|
37813
|
-
}
|
|
37814
|
-
interpolate_( i1, t0, t, t1 ) {
|
|
37815
|
-
const result = this.resultBuffer;
|
|
37816
|
-
const values = this.sampleValues;
|
|
37817
|
-
const stride = this.valueSize;
|
|
37818
|
-
const stride2 = stride * 2;
|
|
37819
|
-
const stride3 = stride * 3;
|
|
37820
|
-
const td = t1 - t0;
|
|
37821
|
-
const p = ( t - t0 ) / td;
|
|
37822
|
-
const pp = p * p;
|
|
37823
|
-
const ppp = pp * p;
|
|
37824
|
-
const offset1 = i1 * stride3;
|
|
37825
|
-
const offset0 = offset1 - stride3;
|
|
37826
|
-
const s2 = -2 * ppp + 3 * pp;
|
|
37827
|
-
const s3 = ppp - pp;
|
|
37828
|
-
const s0 = 1 - s2;
|
|
37829
|
-
const s1 = s3 - pp + p;
|
|
37830
|
-
for ( let i = 0; i !== stride; i ++ ) {
|
|
37831
|
-
const p0 = values[ offset0 + i + stride ];
|
|
37832
|
-
const m0 = values[ offset0 + i + stride2 ] * td;
|
|
37833
|
-
const p1 = values[ offset1 + i + stride ];
|
|
37834
|
-
const m1 = values[ offset1 + i ] * td;
|
|
37835
|
-
result[ i ] = s0 * p0 + s1 * m0 + s2 * p1 + s3 * m1;
|
|
37836
|
-
}
|
|
37837
|
-
return result;
|
|
37838
|
-
}
|
|
37839
|
-
}
|
|
37840
|
-
const _quaternion = new Quaternion();
|
|
37841
|
-
class GLTFCubicSplineQuaternionInterpolant extends GLTFCubicSplineInterpolant {
|
|
37842
|
-
interpolate_( i1, t0, t, t1 ) {
|
|
37843
|
-
const result = super.interpolate_( i1, t0, t, t1 );
|
|
37844
|
-
_quaternion.fromArray( result ).normalize().toArray( result );
|
|
37845
|
-
return result;
|
|
37846
|
-
}
|
|
37847
|
-
}
|
|
37848
|
-
const WEBGL_CONSTANTS = {
|
|
37849
|
-
POINTS: 0,
|
|
37850
|
-
LINES: 1,
|
|
37851
|
-
LINE_LOOP: 2,
|
|
37852
|
-
LINE_STRIP: 3,
|
|
37853
|
-
TRIANGLES: 4,
|
|
37854
|
-
TRIANGLE_STRIP: 5,
|
|
37855
|
-
TRIANGLE_FAN: 6};
|
|
37856
|
-
const WEBGL_COMPONENT_TYPES = {
|
|
37857
|
-
5120: Int8Array,
|
|
37858
|
-
5121: Uint8Array,
|
|
37859
|
-
5122: Int16Array,
|
|
37860
|
-
5123: Uint16Array,
|
|
37861
|
-
5125: Uint32Array,
|
|
37862
|
-
5126: Float32Array
|
|
37863
|
-
};
|
|
37864
|
-
const WEBGL_FILTERS = {
|
|
37865
|
-
9728: NearestFilter,
|
|
37866
|
-
9729: LinearFilter,
|
|
37867
|
-
9984: NearestMipmapNearestFilter,
|
|
37868
|
-
9985: LinearMipmapNearestFilter,
|
|
37869
|
-
9986: NearestMipmapLinearFilter,
|
|
37870
|
-
9987: LinearMipmapLinearFilter
|
|
37871
|
-
};
|
|
37872
|
-
const WEBGL_WRAPPINGS = {
|
|
37873
|
-
33071: ClampToEdgeWrapping,
|
|
37874
|
-
33648: MirroredRepeatWrapping,
|
|
37875
|
-
10497: RepeatWrapping
|
|
37876
|
-
};
|
|
37877
|
-
const WEBGL_TYPE_SIZES = {
|
|
37878
|
-
'SCALAR': 1,
|
|
37879
|
-
'VEC2': 2,
|
|
37880
|
-
'VEC3': 3,
|
|
37881
|
-
'VEC4': 4,
|
|
37882
|
-
'MAT2': 4,
|
|
37883
|
-
'MAT3': 9,
|
|
37884
|
-
'MAT4': 16
|
|
37885
|
-
};
|
|
37886
|
-
const ATTRIBUTES = {
|
|
37887
|
-
POSITION: 'position',
|
|
37888
|
-
NORMAL: 'normal',
|
|
37889
|
-
TANGENT: 'tangent',
|
|
37890
|
-
TEXCOORD_0: 'uv',
|
|
37891
|
-
TEXCOORD_1: 'uv1',
|
|
37892
|
-
TEXCOORD_2: 'uv2',
|
|
37893
|
-
TEXCOORD_3: 'uv3',
|
|
37894
|
-
COLOR_0: 'color',
|
|
37895
|
-
WEIGHTS_0: 'skinWeight',
|
|
37896
|
-
JOINTS_0: 'skinIndex',
|
|
37897
|
-
};
|
|
37898
|
-
const PATH_PROPERTIES = {
|
|
37899
|
-
scale: 'scale',
|
|
37900
|
-
translation: 'position',
|
|
37901
|
-
rotation: 'quaternion',
|
|
37902
|
-
weights: 'morphTargetInfluences'
|
|
37903
|
-
};
|
|
37904
|
-
const INTERPOLATION = {
|
|
37905
|
-
CUBICSPLINE: undefined,
|
|
37906
|
-
LINEAR: InterpolateLinear,
|
|
37907
|
-
STEP: InterpolateDiscrete
|
|
37908
|
-
};
|
|
37909
|
-
const ALPHA_MODES = {
|
|
37910
|
-
OPAQUE: 'OPAQUE',
|
|
37911
|
-
MASK: 'MASK',
|
|
37912
|
-
BLEND: 'BLEND'
|
|
37913
|
-
};
|
|
37914
|
-
function createDefaultMaterial( cache ) {
|
|
37915
|
-
if ( cache[ 'DefaultMaterial' ] === undefined ) {
|
|
37916
|
-
cache[ 'DefaultMaterial' ] = new MeshStandardMaterial( {
|
|
37917
|
-
color: 0xFFFFFF,
|
|
37918
|
-
emissive: 0x000000,
|
|
37919
|
-
metalness: 1,
|
|
37920
|
-
roughness: 1,
|
|
37921
|
-
transparent: false,
|
|
37922
|
-
depthTest: true,
|
|
37923
|
-
side: FrontSide
|
|
37924
|
-
} );
|
|
37925
|
-
}
|
|
37926
|
-
return cache[ 'DefaultMaterial' ];
|
|
37927
|
-
}
|
|
37928
|
-
function addUnknownExtensionsToUserData( knownExtensions, object, objectDef ) {
|
|
37929
|
-
for ( const name in objectDef.extensions ) {
|
|
37930
|
-
if ( knownExtensions[ name ] === undefined ) {
|
|
37931
|
-
object.userData.gltfExtensions = object.userData.gltfExtensions || {};
|
|
37932
|
-
object.userData.gltfExtensions[ name ] = objectDef.extensions[ name ];
|
|
37933
|
-
}
|
|
37934
|
-
}
|
|
37935
|
-
}
|
|
37936
|
-
function assignExtrasToUserData( object, gltfDef ) {
|
|
37937
|
-
if ( gltfDef.extras !== undefined ) {
|
|
37938
|
-
if ( typeof gltfDef.extras === 'object' ) {
|
|
37939
|
-
Object.assign( object.userData, gltfDef.extras );
|
|
37940
|
-
} else {
|
|
37941
|
-
console.warn( 'THREE.GLTFLoader: Ignoring primitive type .extras, ' + gltfDef.extras );
|
|
37942
|
-
}
|
|
37943
|
-
}
|
|
37944
|
-
}
|
|
37945
|
-
function addMorphTargets( geometry, targets, parser ) {
|
|
37946
|
-
let hasMorphPosition = false;
|
|
37947
|
-
let hasMorphNormal = false;
|
|
37948
|
-
let hasMorphColor = false;
|
|
37949
|
-
for ( let i = 0, il = targets.length; i < il; i ++ ) {
|
|
37950
|
-
const target = targets[ i ];
|
|
37951
|
-
if ( target.POSITION !== undefined ) hasMorphPosition = true;
|
|
37952
|
-
if ( target.NORMAL !== undefined ) hasMorphNormal = true;
|
|
37953
|
-
if ( target.COLOR_0 !== undefined ) hasMorphColor = true;
|
|
37954
|
-
if ( hasMorphPosition && hasMorphNormal && hasMorphColor ) break;
|
|
37955
|
-
}
|
|
37956
|
-
if ( ! hasMorphPosition && ! hasMorphNormal && ! hasMorphColor ) return Promise.resolve( geometry );
|
|
37957
|
-
const pendingPositionAccessors = [];
|
|
37958
|
-
const pendingNormalAccessors = [];
|
|
37959
|
-
const pendingColorAccessors = [];
|
|
37960
|
-
for ( let i = 0, il = targets.length; i < il; i ++ ) {
|
|
37961
|
-
const target = targets[ i ];
|
|
37962
|
-
if ( hasMorphPosition ) {
|
|
37963
|
-
const pendingAccessor = target.POSITION !== undefined
|
|
37964
|
-
? parser.getDependency( 'accessor', target.POSITION )
|
|
37965
|
-
: geometry.attributes.position;
|
|
37966
|
-
pendingPositionAccessors.push( pendingAccessor );
|
|
37967
|
-
}
|
|
37968
|
-
if ( hasMorphNormal ) {
|
|
37969
|
-
const pendingAccessor = target.NORMAL !== undefined
|
|
37970
|
-
? parser.getDependency( 'accessor', target.NORMAL )
|
|
37971
|
-
: geometry.attributes.normal;
|
|
37972
|
-
pendingNormalAccessors.push( pendingAccessor );
|
|
37973
|
-
}
|
|
37974
|
-
if ( hasMorphColor ) {
|
|
37975
|
-
const pendingAccessor = target.COLOR_0 !== undefined
|
|
37976
|
-
? parser.getDependency( 'accessor', target.COLOR_0 )
|
|
37977
|
-
: geometry.attributes.color;
|
|
37978
|
-
pendingColorAccessors.push( pendingAccessor );
|
|
37979
|
-
}
|
|
37980
|
-
}
|
|
37981
|
-
return Promise.all( [
|
|
37982
|
-
Promise.all( pendingPositionAccessors ),
|
|
37983
|
-
Promise.all( pendingNormalAccessors ),
|
|
37984
|
-
Promise.all( pendingColorAccessors )
|
|
37985
|
-
] ).then( function ( accessors ) {
|
|
37986
|
-
const morphPositions = accessors[ 0 ];
|
|
37987
|
-
const morphNormals = accessors[ 1 ];
|
|
37988
|
-
const morphColors = accessors[ 2 ];
|
|
37989
|
-
if ( hasMorphPosition ) geometry.morphAttributes.position = morphPositions;
|
|
37990
|
-
if ( hasMorphNormal ) geometry.morphAttributes.normal = morphNormals;
|
|
37991
|
-
if ( hasMorphColor ) geometry.morphAttributes.color = morphColors;
|
|
37992
|
-
geometry.morphTargetsRelative = true;
|
|
37993
|
-
return geometry;
|
|
37994
|
-
} );
|
|
37995
|
-
}
|
|
37996
|
-
function updateMorphTargets( mesh, meshDef ) {
|
|
37997
|
-
mesh.updateMorphTargets();
|
|
37998
|
-
if ( meshDef.weights !== undefined ) {
|
|
37999
|
-
for ( let i = 0, il = meshDef.weights.length; i < il; i ++ ) {
|
|
38000
|
-
mesh.morphTargetInfluences[ i ] = meshDef.weights[ i ];
|
|
38001
|
-
}
|
|
38002
|
-
}
|
|
38003
|
-
if ( meshDef.extras && Array.isArray( meshDef.extras.targetNames ) ) {
|
|
38004
|
-
const targetNames = meshDef.extras.targetNames;
|
|
38005
|
-
if ( mesh.morphTargetInfluences.length === targetNames.length ) {
|
|
38006
|
-
mesh.morphTargetDictionary = {};
|
|
38007
|
-
for ( let i = 0, il = targetNames.length; i < il; i ++ ) {
|
|
38008
|
-
mesh.morphTargetDictionary[ targetNames[ i ] ] = i;
|
|
38009
|
-
}
|
|
38010
|
-
} else {
|
|
38011
|
-
console.warn( 'THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.' );
|
|
38012
|
-
}
|
|
38013
|
-
}
|
|
38014
|
-
}
|
|
38015
|
-
function createPrimitiveKey( primitiveDef ) {
|
|
38016
|
-
let geometryKey;
|
|
38017
|
-
const dracoExtension = primitiveDef.extensions && primitiveDef.extensions[ EXTENSIONS.KHR_DRACO_MESH_COMPRESSION ];
|
|
38018
|
-
if ( dracoExtension ) {
|
|
38019
|
-
geometryKey = 'draco:' + dracoExtension.bufferView
|
|
38020
|
-
+ ':' + dracoExtension.indices
|
|
38021
|
-
+ ':' + createAttributesKey( dracoExtension.attributes );
|
|
38022
|
-
} else {
|
|
38023
|
-
geometryKey = primitiveDef.indices + ':' + createAttributesKey( primitiveDef.attributes ) + ':' + primitiveDef.mode;
|
|
38024
|
-
}
|
|
38025
|
-
if ( primitiveDef.targets !== undefined ) {
|
|
38026
|
-
for ( let i = 0, il = primitiveDef.targets.length; i < il; i ++ ) {
|
|
38027
|
-
geometryKey += ':' + createAttributesKey( primitiveDef.targets[ i ] );
|
|
38028
|
-
}
|
|
38029
|
-
}
|
|
38030
|
-
return geometryKey;
|
|
38031
|
-
}
|
|
38032
|
-
function createAttributesKey( attributes ) {
|
|
38033
|
-
let attributesKey = '';
|
|
38034
|
-
const keys = Object.keys( attributes ).sort();
|
|
38035
|
-
for ( let i = 0, il = keys.length; i < il; i ++ ) {
|
|
38036
|
-
attributesKey += keys[ i ] + ':' + attributes[ keys[ i ] ] + ';';
|
|
38037
|
-
}
|
|
38038
|
-
return attributesKey;
|
|
38039
|
-
}
|
|
38040
|
-
function getNormalizedComponentScale( constructor ) {
|
|
38041
|
-
switch ( constructor ) {
|
|
38042
|
-
case Int8Array:
|
|
38043
|
-
return 1 / 127;
|
|
38044
|
-
case Uint8Array:
|
|
38045
|
-
return 1 / 255;
|
|
38046
|
-
case Int16Array:
|
|
38047
|
-
return 1 / 32767;
|
|
38048
|
-
case Uint16Array:
|
|
38049
|
-
return 1 / 65535;
|
|
38050
|
-
default:
|
|
38051
|
-
throw new Error( 'THREE.GLTFLoader: Unsupported normalized accessor component type.' );
|
|
38052
|
-
}
|
|
38053
|
-
}
|
|
38054
|
-
function getImageURIMimeType( uri ) {
|
|
38055
|
-
if ( uri.search( /\.jpe?g($|\?)/i ) > 0 || uri.search( /^data\:image\/jpeg/ ) === 0 ) return 'image/jpeg';
|
|
38056
|
-
if ( uri.search( /\.webp($|\?)/i ) > 0 || uri.search( /^data\:image\/webp/ ) === 0 ) return 'image/webp';
|
|
38057
|
-
if ( uri.search( /\.ktx2($|\?)/i ) > 0 || uri.search( /^data\:image\/ktx2/ ) === 0 ) return 'image/ktx2';
|
|
38058
|
-
return 'image/png';
|
|
38059
|
-
}
|
|
38060
|
-
const _identityMatrix = new Matrix4();
|
|
38061
|
-
class GLTFParser {
|
|
38062
|
-
constructor( json = {}, options = {} ) {
|
|
38063
|
-
this.json = json;
|
|
38064
|
-
this.extensions = {};
|
|
38065
|
-
this.plugins = {};
|
|
38066
|
-
this.options = options;
|
|
38067
|
-
this.cache = new GLTFRegistry();
|
|
38068
|
-
this.associations = new Map();
|
|
38069
|
-
this.primitiveCache = {};
|
|
38070
|
-
this.nodeCache = {};
|
|
38071
|
-
this.meshCache = { refs: {}, uses: {} };
|
|
38072
|
-
this.cameraCache = { refs: {}, uses: {} };
|
|
38073
|
-
this.lightCache = { refs: {}, uses: {} };
|
|
38074
|
-
this.sourceCache = {};
|
|
38075
|
-
this.textureCache = {};
|
|
38076
|
-
this.nodeNamesUsed = {};
|
|
38077
|
-
let isSafari = false;
|
|
38078
|
-
let safariVersion = -1;
|
|
38079
|
-
let isFirefox = false;
|
|
38080
|
-
let firefoxVersion = -1;
|
|
38081
|
-
if ( typeof navigator !== 'undefined' ) {
|
|
38082
|
-
const userAgent = navigator.userAgent;
|
|
38083
|
-
isSafari = /^((?!chrome|android).)*safari/i.test( userAgent ) === true;
|
|
38084
|
-
const safariMatch = userAgent.match( /Version\/(\d+)/ );
|
|
38085
|
-
safariVersion = isSafari && safariMatch ? parseInt( safariMatch[ 1 ], 10 ) : -1;
|
|
38086
|
-
isFirefox = userAgent.indexOf( 'Firefox' ) > -1;
|
|
38087
|
-
firefoxVersion = isFirefox ? userAgent.match( /Firefox\/([0-9]+)\./ )[ 1 ] : -1;
|
|
38088
|
-
}
|
|
38089
|
-
if ( typeof createImageBitmap === 'undefined' || ( isSafari && safariVersion < 17 ) || ( isFirefox && firefoxVersion < 98 ) ) {
|
|
38090
|
-
this.textureLoader = new TextureLoader( this.options.manager );
|
|
38091
|
-
} else {
|
|
38092
|
-
this.textureLoader = new ImageBitmapLoader( this.options.manager );
|
|
38093
|
-
}
|
|
38094
|
-
this.textureLoader.setCrossOrigin( this.options.crossOrigin );
|
|
38095
|
-
this.textureLoader.setRequestHeader( this.options.requestHeader );
|
|
38096
|
-
this.fileLoader = new FileLoader( this.options.manager );
|
|
38097
|
-
this.fileLoader.setResponseType( 'arraybuffer' );
|
|
38098
|
-
if ( this.options.crossOrigin === 'use-credentials' ) {
|
|
38099
|
-
this.fileLoader.setWithCredentials( true );
|
|
38100
|
-
}
|
|
38101
|
-
}
|
|
38102
|
-
setExtensions( extensions ) {
|
|
38103
|
-
this.extensions = extensions;
|
|
38104
|
-
}
|
|
38105
|
-
setPlugins( plugins ) {
|
|
38106
|
-
this.plugins = plugins;
|
|
38107
|
-
}
|
|
38108
|
-
parse( onLoad, onError ) {
|
|
38109
|
-
const parser = this;
|
|
38110
|
-
const json = this.json;
|
|
38111
|
-
const extensions = this.extensions;
|
|
38112
|
-
this.cache.removeAll();
|
|
38113
|
-
this.nodeCache = {};
|
|
38114
|
-
this._invokeAll( function ( ext ) {
|
|
38115
|
-
return ext._markDefs && ext._markDefs();
|
|
38116
|
-
} );
|
|
38117
|
-
Promise.all( this._invokeAll( function ( ext ) {
|
|
38118
|
-
return ext.beforeRoot && ext.beforeRoot();
|
|
38119
|
-
} ) ).then( function () {
|
|
38120
|
-
return Promise.all( [
|
|
38121
|
-
parser.getDependencies( 'scene' ),
|
|
38122
|
-
parser.getDependencies( 'animation' ),
|
|
38123
|
-
parser.getDependencies( 'camera' ),
|
|
38124
|
-
] );
|
|
38125
|
-
} ).then( function ( dependencies ) {
|
|
38126
|
-
const result = {
|
|
38127
|
-
scene: dependencies[ 0 ][ json.scene || 0 ],
|
|
38128
|
-
scenes: dependencies[ 0 ],
|
|
38129
|
-
animations: dependencies[ 1 ],
|
|
38130
|
-
cameras: dependencies[ 2 ],
|
|
38131
|
-
asset: json.asset,
|
|
38132
|
-
parser: parser,
|
|
38133
|
-
userData: {}
|
|
38134
|
-
};
|
|
38135
|
-
addUnknownExtensionsToUserData( extensions, result, json );
|
|
38136
|
-
assignExtrasToUserData( result, json );
|
|
38137
|
-
return Promise.all( parser._invokeAll( function ( ext ) {
|
|
38138
|
-
return ext.afterRoot && ext.afterRoot( result );
|
|
38139
|
-
} ) ).then( function () {
|
|
38140
|
-
for ( const scene of result.scenes ) {
|
|
38141
|
-
scene.updateMatrixWorld();
|
|
38142
|
-
}
|
|
38143
|
-
onLoad( result );
|
|
38144
|
-
} );
|
|
38145
|
-
} ).catch( onError );
|
|
38146
|
-
}
|
|
38147
|
-
_markDefs() {
|
|
38148
|
-
const nodeDefs = this.json.nodes || [];
|
|
38149
|
-
const skinDefs = this.json.skins || [];
|
|
38150
|
-
const meshDefs = this.json.meshes || [];
|
|
38151
|
-
for ( let skinIndex = 0, skinLength = skinDefs.length; skinIndex < skinLength; skinIndex ++ ) {
|
|
38152
|
-
const joints = skinDefs[ skinIndex ].joints;
|
|
38153
|
-
for ( let i = 0, il = joints.length; i < il; i ++ ) {
|
|
38154
|
-
nodeDefs[ joints[ i ] ].isBone = true;
|
|
38155
|
-
}
|
|
38156
|
-
}
|
|
38157
|
-
for ( let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex ++ ) {
|
|
38158
|
-
const nodeDef = nodeDefs[ nodeIndex ];
|
|
38159
|
-
if ( nodeDef.mesh !== undefined ) {
|
|
38160
|
-
this._addNodeRef( this.meshCache, nodeDef.mesh );
|
|
38161
|
-
if ( nodeDef.skin !== undefined ) {
|
|
38162
|
-
meshDefs[ nodeDef.mesh ].isSkinnedMesh = true;
|
|
38163
|
-
}
|
|
38164
|
-
}
|
|
38165
|
-
if ( nodeDef.camera !== undefined ) {
|
|
38166
|
-
this._addNodeRef( this.cameraCache, nodeDef.camera );
|
|
38167
|
-
}
|
|
38168
|
-
}
|
|
38169
|
-
}
|
|
38170
|
-
_addNodeRef( cache, index ) {
|
|
38171
|
-
if ( index === undefined ) return;
|
|
38172
|
-
if ( cache.refs[ index ] === undefined ) {
|
|
38173
|
-
cache.refs[ index ] = cache.uses[ index ] = 0;
|
|
38174
|
-
}
|
|
38175
|
-
cache.refs[ index ] ++;
|
|
38176
|
-
}
|
|
38177
|
-
_getNodeRef( cache, index, object ) {
|
|
38178
|
-
if ( cache.refs[ index ] <= 1 ) return object;
|
|
38179
|
-
const ref = object.clone();
|
|
38180
|
-
const updateMappings = ( original, clone ) => {
|
|
38181
|
-
const mappings = this.associations.get( original );
|
|
38182
|
-
if ( mappings != null ) {
|
|
38183
|
-
this.associations.set( clone, mappings );
|
|
38184
|
-
}
|
|
38185
|
-
for ( const [ i, child ] of original.children.entries() ) {
|
|
38186
|
-
updateMappings( child, clone.children[ i ] );
|
|
38187
|
-
}
|
|
38188
|
-
};
|
|
38189
|
-
updateMappings( object, ref );
|
|
38190
|
-
ref.name += '_instance_' + ( cache.uses[ index ] ++ );
|
|
38191
|
-
return ref;
|
|
38192
|
-
}
|
|
38193
|
-
_invokeOne( func ) {
|
|
38194
|
-
const extensions = Object.values( this.plugins );
|
|
38195
|
-
extensions.push( this );
|
|
38196
|
-
for ( let i = 0; i < extensions.length; i ++ ) {
|
|
38197
|
-
const result = func( extensions[ i ] );
|
|
38198
|
-
if ( result ) return result;
|
|
38199
|
-
}
|
|
38200
|
-
return null;
|
|
38201
|
-
}
|
|
38202
|
-
_invokeAll( func ) {
|
|
38203
|
-
const extensions = Object.values( this.plugins );
|
|
38204
|
-
extensions.unshift( this );
|
|
38205
|
-
const pending = [];
|
|
38206
|
-
for ( let i = 0; i < extensions.length; i ++ ) {
|
|
38207
|
-
const result = func( extensions[ i ] );
|
|
38208
|
-
if ( result ) pending.push( result );
|
|
38209
|
-
}
|
|
38210
|
-
return pending;
|
|
38211
|
-
}
|
|
38212
|
-
getDependency( type, index ) {
|
|
38213
|
-
const cacheKey = type + ':' + index;
|
|
38214
|
-
let dependency = this.cache.get( cacheKey );
|
|
38215
|
-
if ( ! dependency ) {
|
|
38216
|
-
switch ( type ) {
|
|
38217
|
-
case 'scene':
|
|
38218
|
-
dependency = this.loadScene( index );
|
|
38219
|
-
break;
|
|
38220
|
-
case 'node':
|
|
38221
|
-
dependency = this._invokeOne( function ( ext ) {
|
|
38222
|
-
return ext.loadNode && ext.loadNode( index );
|
|
38223
|
-
} );
|
|
38224
|
-
break;
|
|
38225
|
-
case 'mesh':
|
|
38226
|
-
dependency = this._invokeOne( function ( ext ) {
|
|
38227
|
-
return ext.loadMesh && ext.loadMesh( index );
|
|
38228
|
-
} );
|
|
38229
|
-
break;
|
|
38230
|
-
case 'accessor':
|
|
38231
|
-
dependency = this.loadAccessor( index );
|
|
38232
|
-
break;
|
|
38233
|
-
case 'bufferView':
|
|
38234
|
-
dependency = this._invokeOne( function ( ext ) {
|
|
38235
|
-
return ext.loadBufferView && ext.loadBufferView( index );
|
|
38236
|
-
} );
|
|
38237
|
-
break;
|
|
38238
|
-
case 'buffer':
|
|
38239
|
-
dependency = this.loadBuffer( index );
|
|
38240
|
-
break;
|
|
38241
|
-
case 'material':
|
|
38242
|
-
dependency = this._invokeOne( function ( ext ) {
|
|
38243
|
-
return ext.loadMaterial && ext.loadMaterial( index );
|
|
38244
|
-
} );
|
|
38245
|
-
break;
|
|
38246
|
-
case 'texture':
|
|
38247
|
-
dependency = this._invokeOne( function ( ext ) {
|
|
38248
|
-
return ext.loadTexture && ext.loadTexture( index );
|
|
38249
|
-
} );
|
|
38250
|
-
break;
|
|
38251
|
-
case 'skin':
|
|
38252
|
-
dependency = this.loadSkin( index );
|
|
38253
|
-
break;
|
|
38254
|
-
case 'animation':
|
|
38255
|
-
dependency = this._invokeOne( function ( ext ) {
|
|
38256
|
-
return ext.loadAnimation && ext.loadAnimation( index );
|
|
38257
|
-
} );
|
|
38258
|
-
break;
|
|
38259
|
-
case 'camera':
|
|
38260
|
-
dependency = this.loadCamera( index );
|
|
38261
|
-
break;
|
|
38262
|
-
default:
|
|
38263
|
-
dependency = this._invokeOne( function ( ext ) {
|
|
38264
|
-
return ext != this && ext.getDependency && ext.getDependency( type, index );
|
|
38265
|
-
} );
|
|
38266
|
-
if ( ! dependency ) {
|
|
38267
|
-
throw new Error( 'Unknown type: ' + type );
|
|
38268
|
-
}
|
|
38269
|
-
break;
|
|
38270
|
-
}
|
|
38271
|
-
this.cache.add( cacheKey, dependency );
|
|
38272
|
-
}
|
|
38273
|
-
return dependency;
|
|
38274
|
-
}
|
|
38275
|
-
getDependencies( type ) {
|
|
38276
|
-
let dependencies = this.cache.get( type );
|
|
38277
|
-
if ( ! dependencies ) {
|
|
38278
|
-
const parser = this;
|
|
38279
|
-
const defs = this.json[ type + ( type === 'mesh' ? 'es' : 's' ) ] || [];
|
|
38280
|
-
dependencies = Promise.all( defs.map( function ( def, index ) {
|
|
38281
|
-
return parser.getDependency( type, index );
|
|
38282
|
-
} ) );
|
|
38283
|
-
this.cache.add( type, dependencies );
|
|
38284
|
-
}
|
|
38285
|
-
return dependencies;
|
|
38286
|
-
}
|
|
38287
|
-
loadBuffer( bufferIndex ) {
|
|
38288
|
-
const bufferDef = this.json.buffers[ bufferIndex ];
|
|
38289
|
-
const loader = this.fileLoader;
|
|
38290
|
-
if ( bufferDef.type && bufferDef.type !== 'arraybuffer' ) {
|
|
38291
|
-
throw new Error( 'THREE.GLTFLoader: ' + bufferDef.type + ' buffer type is not supported.' );
|
|
38292
|
-
}
|
|
38293
|
-
if ( bufferDef.uri === undefined && bufferIndex === 0 ) {
|
|
38294
|
-
return Promise.resolve( this.extensions[ EXTENSIONS.KHR_BINARY_GLTF ].body );
|
|
38295
|
-
}
|
|
38296
|
-
const options = this.options;
|
|
38297
|
-
return new Promise( function ( resolve, reject ) {
|
|
38298
|
-
loader.load( LoaderUtils.resolveURL( bufferDef.uri, options.path ), resolve, undefined, function () {
|
|
38299
|
-
reject( new Error( 'THREE.GLTFLoader: Failed to load buffer "' + bufferDef.uri + '".' ) );
|
|
38300
|
-
} );
|
|
38301
|
-
} );
|
|
38302
|
-
}
|
|
38303
|
-
loadBufferView( bufferViewIndex ) {
|
|
38304
|
-
const bufferViewDef = this.json.bufferViews[ bufferViewIndex ];
|
|
38305
|
-
return this.getDependency( 'buffer', bufferViewDef.buffer ).then( function ( buffer ) {
|
|
38306
|
-
const byteLength = bufferViewDef.byteLength || 0;
|
|
38307
|
-
const byteOffset = bufferViewDef.byteOffset || 0;
|
|
38308
|
-
return buffer.slice( byteOffset, byteOffset + byteLength );
|
|
38309
|
-
} );
|
|
38310
|
-
}
|
|
38311
|
-
loadAccessor( accessorIndex ) {
|
|
38312
|
-
const parser = this;
|
|
38313
|
-
const json = this.json;
|
|
38314
|
-
const accessorDef = this.json.accessors[ accessorIndex ];
|
|
38315
|
-
if ( accessorDef.bufferView === undefined && accessorDef.sparse === undefined ) {
|
|
38316
|
-
const itemSize = WEBGL_TYPE_SIZES[ accessorDef.type ];
|
|
38317
|
-
const TypedArray = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ];
|
|
38318
|
-
const normalized = accessorDef.normalized === true;
|
|
38319
|
-
const array = new TypedArray( accessorDef.count * itemSize );
|
|
38320
|
-
return Promise.resolve( new BufferAttribute( array, itemSize, normalized ) );
|
|
38321
|
-
}
|
|
38322
|
-
const pendingBufferViews = [];
|
|
38323
|
-
if ( accessorDef.bufferView !== undefined ) {
|
|
38324
|
-
pendingBufferViews.push( this.getDependency( 'bufferView', accessorDef.bufferView ) );
|
|
38325
|
-
} else {
|
|
38326
|
-
pendingBufferViews.push( null );
|
|
38327
|
-
}
|
|
38328
|
-
if ( accessorDef.sparse !== undefined ) {
|
|
38329
|
-
pendingBufferViews.push( this.getDependency( 'bufferView', accessorDef.sparse.indices.bufferView ) );
|
|
38330
|
-
pendingBufferViews.push( this.getDependency( 'bufferView', accessorDef.sparse.values.bufferView ) );
|
|
38331
|
-
}
|
|
38332
|
-
return Promise.all( pendingBufferViews ).then( function ( bufferViews ) {
|
|
38333
|
-
const bufferView = bufferViews[ 0 ];
|
|
38334
|
-
const itemSize = WEBGL_TYPE_SIZES[ accessorDef.type ];
|
|
38335
|
-
const TypedArray = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ];
|
|
38336
|
-
const elementBytes = TypedArray.BYTES_PER_ELEMENT;
|
|
38337
|
-
const itemBytes = elementBytes * itemSize;
|
|
38338
|
-
const byteOffset = accessorDef.byteOffset || 0;
|
|
38339
|
-
const byteStride = accessorDef.bufferView !== undefined ? json.bufferViews[ accessorDef.bufferView ].byteStride : undefined;
|
|
38340
|
-
const normalized = accessorDef.normalized === true;
|
|
38341
|
-
let array, bufferAttribute;
|
|
38342
|
-
if ( byteStride && byteStride !== itemBytes ) {
|
|
38343
|
-
const ibSlice = Math.floor( byteOffset / byteStride );
|
|
38344
|
-
const ibCacheKey = 'InterleavedBuffer:' + accessorDef.bufferView + ':' + accessorDef.componentType + ':' + ibSlice + ':' + accessorDef.count;
|
|
38345
|
-
let ib = parser.cache.get( ibCacheKey );
|
|
38346
|
-
if ( ! ib ) {
|
|
38347
|
-
array = new TypedArray( bufferView, ibSlice * byteStride, accessorDef.count * byteStride / elementBytes );
|
|
38348
|
-
ib = new InterleavedBuffer( array, byteStride / elementBytes );
|
|
38349
|
-
parser.cache.add( ibCacheKey, ib );
|
|
38350
|
-
}
|
|
38351
|
-
bufferAttribute = new InterleavedBufferAttribute( ib, itemSize, ( byteOffset % byteStride ) / elementBytes, normalized );
|
|
38352
|
-
} else {
|
|
38353
|
-
if ( bufferView === null ) {
|
|
38354
|
-
array = new TypedArray( accessorDef.count * itemSize );
|
|
38355
|
-
} else {
|
|
38356
|
-
array = new TypedArray( bufferView, byteOffset, accessorDef.count * itemSize );
|
|
38357
|
-
}
|
|
38358
|
-
bufferAttribute = new BufferAttribute( array, itemSize, normalized );
|
|
38359
|
-
}
|
|
38360
|
-
if ( accessorDef.sparse !== undefined ) {
|
|
38361
|
-
const itemSizeIndices = WEBGL_TYPE_SIZES.SCALAR;
|
|
38362
|
-
const TypedArrayIndices = WEBGL_COMPONENT_TYPES[ accessorDef.sparse.indices.componentType ];
|
|
38363
|
-
const byteOffsetIndices = accessorDef.sparse.indices.byteOffset || 0;
|
|
38364
|
-
const byteOffsetValues = accessorDef.sparse.values.byteOffset || 0;
|
|
38365
|
-
const sparseIndices = new TypedArrayIndices( bufferViews[ 1 ], byteOffsetIndices, accessorDef.sparse.count * itemSizeIndices );
|
|
38366
|
-
const sparseValues = new TypedArray( bufferViews[ 2 ], byteOffsetValues, accessorDef.sparse.count * itemSize );
|
|
38367
|
-
if ( bufferView !== null ) {
|
|
38368
|
-
bufferAttribute = new BufferAttribute( bufferAttribute.array.slice(), bufferAttribute.itemSize, bufferAttribute.normalized );
|
|
38369
|
-
}
|
|
38370
|
-
bufferAttribute.normalized = false;
|
|
38371
|
-
for ( let i = 0, il = sparseIndices.length; i < il; i ++ ) {
|
|
38372
|
-
const index = sparseIndices[ i ];
|
|
38373
|
-
bufferAttribute.setX( index, sparseValues[ i * itemSize ] );
|
|
38374
|
-
if ( itemSize >= 2 ) bufferAttribute.setY( index, sparseValues[ i * itemSize + 1 ] );
|
|
38375
|
-
if ( itemSize >= 3 ) bufferAttribute.setZ( index, sparseValues[ i * itemSize + 2 ] );
|
|
38376
|
-
if ( itemSize >= 4 ) bufferAttribute.setW( index, sparseValues[ i * itemSize + 3 ] );
|
|
38377
|
-
if ( itemSize >= 5 ) throw new Error( 'THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.' );
|
|
38378
|
-
}
|
|
38379
|
-
bufferAttribute.normalized = normalized;
|
|
38380
|
-
}
|
|
38381
|
-
return bufferAttribute;
|
|
38382
|
-
} );
|
|
38383
|
-
}
|
|
38384
|
-
loadTexture( textureIndex ) {
|
|
38385
|
-
const json = this.json;
|
|
38386
|
-
const options = this.options;
|
|
38387
|
-
const textureDef = json.textures[ textureIndex ];
|
|
38388
|
-
const sourceIndex = textureDef.source;
|
|
38389
|
-
const sourceDef = json.images[ sourceIndex ];
|
|
38390
|
-
let loader = this.textureLoader;
|
|
38391
|
-
if ( sourceDef.uri ) {
|
|
38392
|
-
const handler = options.manager.getHandler( sourceDef.uri );
|
|
38393
|
-
if ( handler !== null ) loader = handler;
|
|
38394
|
-
}
|
|
38395
|
-
return this.loadTextureImage( textureIndex, sourceIndex, loader );
|
|
38396
|
-
}
|
|
38397
|
-
loadTextureImage( textureIndex, sourceIndex, loader ) {
|
|
38398
|
-
const parser = this;
|
|
38399
|
-
const json = this.json;
|
|
38400
|
-
const textureDef = json.textures[ textureIndex ];
|
|
38401
|
-
const sourceDef = json.images[ sourceIndex ];
|
|
38402
|
-
const cacheKey = ( sourceDef.uri || sourceDef.bufferView ) + ':' + textureDef.sampler;
|
|
38403
|
-
if ( this.textureCache[ cacheKey ] ) {
|
|
38404
|
-
return this.textureCache[ cacheKey ];
|
|
38405
|
-
}
|
|
38406
|
-
const promise = this.loadImageSource( sourceIndex, loader ).then( function ( texture ) {
|
|
38407
|
-
texture.flipY = false;
|
|
38408
|
-
texture.name = textureDef.name || sourceDef.name || '';
|
|
38409
|
-
if ( texture.name === '' && typeof sourceDef.uri === 'string' && sourceDef.uri.startsWith( 'data:image/' ) === false ) {
|
|
38410
|
-
texture.name = sourceDef.uri;
|
|
38411
|
-
}
|
|
38412
|
-
const samplers = json.samplers || {};
|
|
38413
|
-
const sampler = samplers[ textureDef.sampler ] || {};
|
|
38414
|
-
texture.magFilter = WEBGL_FILTERS[ sampler.magFilter ] || LinearFilter;
|
|
38415
|
-
texture.minFilter = WEBGL_FILTERS[ sampler.minFilter ] || LinearMipmapLinearFilter;
|
|
38416
|
-
texture.wrapS = WEBGL_WRAPPINGS[ sampler.wrapS ] || RepeatWrapping;
|
|
38417
|
-
texture.wrapT = WEBGL_WRAPPINGS[ sampler.wrapT ] || RepeatWrapping;
|
|
38418
|
-
texture.generateMipmaps = ! texture.isCompressedTexture && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
|
|
38419
|
-
parser.associations.set( texture, { textures: textureIndex } );
|
|
38420
|
-
return texture;
|
|
38421
|
-
} ).catch( function () {
|
|
38422
|
-
return null;
|
|
38423
|
-
} );
|
|
38424
|
-
this.textureCache[ cacheKey ] = promise;
|
|
38425
|
-
return promise;
|
|
38426
|
-
}
|
|
38427
|
-
loadImageSource( sourceIndex, loader ) {
|
|
38428
|
-
const parser = this;
|
|
38429
|
-
const json = this.json;
|
|
38430
|
-
const options = this.options;
|
|
38431
|
-
if ( this.sourceCache[ sourceIndex ] !== undefined ) {
|
|
38432
|
-
return this.sourceCache[ sourceIndex ].then( ( texture ) => texture.clone() );
|
|
38433
|
-
}
|
|
38434
|
-
const sourceDef = json.images[ sourceIndex ];
|
|
38435
|
-
const URL = self.URL || self.webkitURL;
|
|
38436
|
-
let sourceURI = sourceDef.uri || '';
|
|
38437
|
-
let isObjectURL = false;
|
|
38438
|
-
if ( sourceDef.bufferView !== undefined ) {
|
|
38439
|
-
sourceURI = parser.getDependency( 'bufferView', sourceDef.bufferView ).then( function ( bufferView ) {
|
|
38440
|
-
isObjectURL = true;
|
|
38441
|
-
const blob = new Blob( [ bufferView ], { type: sourceDef.mimeType } );
|
|
38442
|
-
sourceURI = URL.createObjectURL( blob );
|
|
38443
|
-
return sourceURI;
|
|
38444
|
-
} );
|
|
38445
|
-
} else if ( sourceDef.uri === undefined ) {
|
|
38446
|
-
throw new Error( 'THREE.GLTFLoader: Image ' + sourceIndex + ' is missing URI and bufferView' );
|
|
38447
|
-
}
|
|
38448
|
-
const promise = Promise.resolve( sourceURI ).then( function ( sourceURI ) {
|
|
38449
|
-
return new Promise( function ( resolve, reject ) {
|
|
38450
|
-
let onLoad = resolve;
|
|
38451
|
-
if ( loader.isImageBitmapLoader === true ) {
|
|
38452
|
-
onLoad = function ( imageBitmap ) {
|
|
38453
|
-
const texture = new Texture( imageBitmap );
|
|
38454
|
-
texture.needsUpdate = true;
|
|
38455
|
-
resolve( texture );
|
|
38456
|
-
};
|
|
38457
|
-
}
|
|
38458
|
-
loader.load( LoaderUtils.resolveURL( sourceURI, options.path ), onLoad, undefined, reject );
|
|
38459
|
-
} );
|
|
38460
|
-
} ).then( function ( texture ) {
|
|
38461
|
-
if ( isObjectURL === true ) {
|
|
38462
|
-
URL.revokeObjectURL( sourceURI );
|
|
38463
|
-
}
|
|
38464
|
-
assignExtrasToUserData( texture, sourceDef );
|
|
38465
|
-
texture.userData.mimeType = sourceDef.mimeType || getImageURIMimeType( sourceDef.uri );
|
|
38466
|
-
return texture;
|
|
38467
|
-
} ).catch( function ( error ) {
|
|
38468
|
-
console.error( 'THREE.GLTFLoader: Couldn\'t load texture', sourceURI );
|
|
38469
|
-
throw error;
|
|
38470
|
-
} );
|
|
38471
|
-
this.sourceCache[ sourceIndex ] = promise;
|
|
38472
|
-
return promise;
|
|
38473
|
-
}
|
|
38474
|
-
assignTexture( materialParams, mapName, mapDef, colorSpace ) {
|
|
38475
|
-
const parser = this;
|
|
38476
|
-
return this.getDependency( 'texture', mapDef.index ).then( function ( texture ) {
|
|
38477
|
-
if ( ! texture ) return null;
|
|
38478
|
-
if ( mapDef.texCoord !== undefined && mapDef.texCoord > 0 ) {
|
|
38479
|
-
texture = texture.clone();
|
|
38480
|
-
texture.channel = mapDef.texCoord;
|
|
38481
|
-
}
|
|
38482
|
-
if ( parser.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ] ) {
|
|
38483
|
-
const transform = mapDef.extensions !== undefined ? mapDef.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ] : undefined;
|
|
38484
|
-
if ( transform ) {
|
|
38485
|
-
const gltfReference = parser.associations.get( texture );
|
|
38486
|
-
texture = parser.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ].extendTexture( texture, transform );
|
|
38487
|
-
parser.associations.set( texture, gltfReference );
|
|
38488
|
-
}
|
|
38489
|
-
}
|
|
38490
|
-
if ( colorSpace !== undefined ) {
|
|
38491
|
-
texture.colorSpace = colorSpace;
|
|
38492
|
-
}
|
|
38493
|
-
materialParams[ mapName ] = texture;
|
|
38494
|
-
return texture;
|
|
38495
|
-
} );
|
|
38496
|
-
}
|
|
38497
|
-
assignFinalMaterial( mesh ) {
|
|
38498
|
-
const geometry = mesh.geometry;
|
|
38499
|
-
let material = mesh.material;
|
|
38500
|
-
const useDerivativeTangents = geometry.attributes.tangent === undefined;
|
|
38501
|
-
const useVertexColors = geometry.attributes.color !== undefined;
|
|
38502
|
-
const useFlatShading = geometry.attributes.normal === undefined;
|
|
38503
|
-
if ( mesh.isPoints ) {
|
|
38504
|
-
const cacheKey = 'PointsMaterial:' + material.uuid;
|
|
38505
|
-
let pointsMaterial = this.cache.get( cacheKey );
|
|
38506
|
-
if ( ! pointsMaterial ) {
|
|
38507
|
-
pointsMaterial = new PointsMaterial();
|
|
38508
|
-
Material.prototype.copy.call( pointsMaterial, material );
|
|
38509
|
-
pointsMaterial.color.copy( material.color );
|
|
38510
|
-
pointsMaterial.map = material.map;
|
|
38511
|
-
pointsMaterial.sizeAttenuation = false;
|
|
38512
|
-
this.cache.add( cacheKey, pointsMaterial );
|
|
38513
|
-
}
|
|
38514
|
-
material = pointsMaterial;
|
|
38515
|
-
} else if ( mesh.isLine ) {
|
|
38516
|
-
const cacheKey = 'LineBasicMaterial:' + material.uuid;
|
|
38517
|
-
let lineMaterial = this.cache.get( cacheKey );
|
|
38518
|
-
if ( ! lineMaterial ) {
|
|
38519
|
-
lineMaterial = new LineBasicMaterial();
|
|
38520
|
-
Material.prototype.copy.call( lineMaterial, material );
|
|
38521
|
-
lineMaterial.color.copy( material.color );
|
|
38522
|
-
lineMaterial.map = material.map;
|
|
38523
|
-
this.cache.add( cacheKey, lineMaterial );
|
|
38524
|
-
}
|
|
38525
|
-
material = lineMaterial;
|
|
38526
|
-
}
|
|
38527
|
-
if ( useDerivativeTangents || useVertexColors || useFlatShading ) {
|
|
38528
|
-
let cacheKey = 'ClonedMaterial:' + material.uuid + ':';
|
|
38529
|
-
if ( useDerivativeTangents ) cacheKey += 'derivative-tangents:';
|
|
38530
|
-
if ( useVertexColors ) cacheKey += 'vertex-colors:';
|
|
38531
|
-
if ( useFlatShading ) cacheKey += 'flat-shading:';
|
|
38532
|
-
let cachedMaterial = this.cache.get( cacheKey );
|
|
38533
|
-
if ( ! cachedMaterial ) {
|
|
38534
|
-
cachedMaterial = material.clone();
|
|
38535
|
-
if ( useVertexColors ) cachedMaterial.vertexColors = true;
|
|
38536
|
-
if ( useFlatShading ) cachedMaterial.flatShading = true;
|
|
38537
|
-
if ( useDerivativeTangents ) {
|
|
38538
|
-
if ( cachedMaterial.normalScale ) cachedMaterial.normalScale.y *= -1;
|
|
38539
|
-
if ( cachedMaterial.clearcoatNormalScale ) cachedMaterial.clearcoatNormalScale.y *= -1;
|
|
38540
|
-
}
|
|
38541
|
-
this.cache.add( cacheKey, cachedMaterial );
|
|
38542
|
-
this.associations.set( cachedMaterial, this.associations.get( material ) );
|
|
38543
|
-
}
|
|
38544
|
-
material = cachedMaterial;
|
|
38545
|
-
}
|
|
38546
|
-
mesh.material = material;
|
|
38547
|
-
}
|
|
38548
|
-
getMaterialType( ) {
|
|
38549
|
-
return MeshStandardMaterial;
|
|
38550
|
-
}
|
|
38551
|
-
loadMaterial( materialIndex ) {
|
|
38552
|
-
const parser = this;
|
|
38553
|
-
const json = this.json;
|
|
38554
|
-
const extensions = this.extensions;
|
|
38555
|
-
const materialDef = json.materials[ materialIndex ];
|
|
38556
|
-
let materialType;
|
|
38557
|
-
const materialParams = {};
|
|
38558
|
-
const materialExtensions = materialDef.extensions || {};
|
|
38559
|
-
const pending = [];
|
|
38560
|
-
if ( materialExtensions[ EXTENSIONS.KHR_MATERIALS_UNLIT ] ) {
|
|
38561
|
-
const kmuExtension = extensions[ EXTENSIONS.KHR_MATERIALS_UNLIT ];
|
|
38562
|
-
materialType = kmuExtension.getMaterialType();
|
|
38563
|
-
pending.push( kmuExtension.extendParams( materialParams, materialDef, parser ) );
|
|
38564
|
-
} else {
|
|
38565
|
-
const metallicRoughness = materialDef.pbrMetallicRoughness || {};
|
|
38566
|
-
materialParams.color = new Color( 1.0, 1.0, 1.0 );
|
|
38567
|
-
materialParams.opacity = 1.0;
|
|
38568
|
-
if ( Array.isArray( metallicRoughness.baseColorFactor ) ) {
|
|
38569
|
-
const array = metallicRoughness.baseColorFactor;
|
|
38570
|
-
materialParams.color.setRGB( array[ 0 ], array[ 1 ], array[ 2 ], LinearSRGBColorSpace );
|
|
38571
|
-
materialParams.opacity = array[ 3 ];
|
|
38572
|
-
}
|
|
38573
|
-
if ( metallicRoughness.baseColorTexture !== undefined ) {
|
|
38574
|
-
pending.push( parser.assignTexture( materialParams, 'map', metallicRoughness.baseColorTexture, SRGBColorSpace ) );
|
|
38575
|
-
}
|
|
38576
|
-
materialParams.metalness = metallicRoughness.metallicFactor !== undefined ? metallicRoughness.metallicFactor : 1.0;
|
|
38577
|
-
materialParams.roughness = metallicRoughness.roughnessFactor !== undefined ? metallicRoughness.roughnessFactor : 1.0;
|
|
38578
|
-
if ( metallicRoughness.metallicRoughnessTexture !== undefined ) {
|
|
38579
|
-
pending.push( parser.assignTexture( materialParams, 'metalnessMap', metallicRoughness.metallicRoughnessTexture ) );
|
|
38580
|
-
pending.push( parser.assignTexture( materialParams, 'roughnessMap', metallicRoughness.metallicRoughnessTexture ) );
|
|
38581
|
-
}
|
|
38582
|
-
materialType = this._invokeOne( function ( ext ) {
|
|
38583
|
-
return ext.getMaterialType && ext.getMaterialType( materialIndex );
|
|
38584
|
-
} );
|
|
38585
|
-
pending.push( Promise.all( this._invokeAll( function ( ext ) {
|
|
38586
|
-
return ext.extendMaterialParams && ext.extendMaterialParams( materialIndex, materialParams );
|
|
38587
|
-
} ) ) );
|
|
38588
|
-
}
|
|
38589
|
-
if ( materialDef.doubleSided === true ) {
|
|
38590
|
-
materialParams.side = DoubleSide;
|
|
38591
|
-
}
|
|
38592
|
-
const alphaMode = materialDef.alphaMode || ALPHA_MODES.OPAQUE;
|
|
38593
|
-
if ( alphaMode === ALPHA_MODES.BLEND ) {
|
|
38594
|
-
materialParams.transparent = true;
|
|
38595
|
-
materialParams.depthWrite = false;
|
|
38596
|
-
} else {
|
|
38597
|
-
materialParams.transparent = false;
|
|
38598
|
-
if ( alphaMode === ALPHA_MODES.MASK ) {
|
|
38599
|
-
materialParams.alphaTest = materialDef.alphaCutoff !== undefined ? materialDef.alphaCutoff : 0.5;
|
|
38600
|
-
}
|
|
38601
|
-
}
|
|
38602
|
-
if ( materialDef.normalTexture !== undefined && materialType !== MeshBasicMaterial ) {
|
|
38603
|
-
pending.push( parser.assignTexture( materialParams, 'normalMap', materialDef.normalTexture ) );
|
|
38604
|
-
materialParams.normalScale = new Vector2( 1, 1 );
|
|
38605
|
-
if ( materialDef.normalTexture.scale !== undefined ) {
|
|
38606
|
-
const scale = materialDef.normalTexture.scale;
|
|
38607
|
-
materialParams.normalScale.set( scale, scale );
|
|
38608
|
-
}
|
|
38609
|
-
}
|
|
38610
|
-
if ( materialDef.occlusionTexture !== undefined && materialType !== MeshBasicMaterial ) {
|
|
38611
|
-
pending.push( parser.assignTexture( materialParams, 'aoMap', materialDef.occlusionTexture ) );
|
|
38612
|
-
if ( materialDef.occlusionTexture.strength !== undefined ) {
|
|
38613
|
-
materialParams.aoMapIntensity = materialDef.occlusionTexture.strength;
|
|
38614
|
-
}
|
|
38615
|
-
}
|
|
38616
|
-
if ( materialDef.emissiveFactor !== undefined && materialType !== MeshBasicMaterial ) {
|
|
38617
|
-
const emissiveFactor = materialDef.emissiveFactor;
|
|
38618
|
-
materialParams.emissive = new Color().setRGB( emissiveFactor[ 0 ], emissiveFactor[ 1 ], emissiveFactor[ 2 ], LinearSRGBColorSpace );
|
|
38619
|
-
}
|
|
38620
|
-
if ( materialDef.emissiveTexture !== undefined && materialType !== MeshBasicMaterial ) {
|
|
38621
|
-
pending.push( parser.assignTexture( materialParams, 'emissiveMap', materialDef.emissiveTexture, SRGBColorSpace ) );
|
|
38622
|
-
}
|
|
38623
|
-
return Promise.all( pending ).then( function () {
|
|
38624
|
-
const material = new materialType( materialParams );
|
|
38625
|
-
if ( materialDef.name ) material.name = materialDef.name;
|
|
38626
|
-
assignExtrasToUserData( material, materialDef );
|
|
38627
|
-
parser.associations.set( material, { materials: materialIndex } );
|
|
38628
|
-
if ( materialDef.extensions ) addUnknownExtensionsToUserData( extensions, material, materialDef );
|
|
38629
|
-
return material;
|
|
38630
|
-
} );
|
|
38631
|
-
}
|
|
38632
|
-
createUniqueName( originalName ) {
|
|
38633
|
-
const sanitizedName = PropertyBinding.sanitizeNodeName( originalName || '' );
|
|
38634
|
-
if ( sanitizedName in this.nodeNamesUsed ) {
|
|
38635
|
-
return sanitizedName + '_' + ( ++ this.nodeNamesUsed[ sanitizedName ] );
|
|
38636
|
-
} else {
|
|
38637
|
-
this.nodeNamesUsed[ sanitizedName ] = 0;
|
|
38638
|
-
return sanitizedName;
|
|
38639
|
-
}
|
|
38640
|
-
}
|
|
38641
|
-
loadGeometries( primitives ) {
|
|
38642
|
-
const parser = this;
|
|
38643
|
-
const extensions = this.extensions;
|
|
38644
|
-
const cache = this.primitiveCache;
|
|
38645
|
-
function createDracoPrimitive( primitive ) {
|
|
38646
|
-
return extensions[ EXTENSIONS.KHR_DRACO_MESH_COMPRESSION ]
|
|
38647
|
-
.decodePrimitive( primitive, parser )
|
|
38648
|
-
.then( function ( geometry ) {
|
|
38649
|
-
return addPrimitiveAttributes( geometry, primitive, parser );
|
|
38650
|
-
} );
|
|
38651
|
-
}
|
|
38652
|
-
const pending = [];
|
|
38653
|
-
for ( let i = 0, il = primitives.length; i < il; i ++ ) {
|
|
38654
|
-
const primitive = primitives[ i ];
|
|
38655
|
-
const cacheKey = createPrimitiveKey( primitive );
|
|
38656
|
-
const cached = cache[ cacheKey ];
|
|
38657
|
-
if ( cached ) {
|
|
38658
|
-
pending.push( cached.promise );
|
|
38659
|
-
} else {
|
|
38660
|
-
let geometryPromise;
|
|
38661
|
-
if ( primitive.extensions && primitive.extensions[ EXTENSIONS.KHR_DRACO_MESH_COMPRESSION ] ) {
|
|
38662
|
-
geometryPromise = createDracoPrimitive( primitive );
|
|
38663
|
-
} else {
|
|
38664
|
-
geometryPromise = addPrimitiveAttributes( new BufferGeometry(), primitive, parser );
|
|
38665
|
-
}
|
|
38666
|
-
cache[ cacheKey ] = { primitive: primitive, promise: geometryPromise };
|
|
38667
|
-
pending.push( geometryPromise );
|
|
38668
|
-
}
|
|
38669
|
-
}
|
|
38670
|
-
return Promise.all( pending );
|
|
38671
|
-
}
|
|
38672
|
-
loadMesh( meshIndex ) {
|
|
38673
|
-
const parser = this;
|
|
38674
|
-
const json = this.json;
|
|
38675
|
-
const extensions = this.extensions;
|
|
38676
|
-
const meshDef = json.meshes[ meshIndex ];
|
|
38677
|
-
const primitives = meshDef.primitives;
|
|
38678
|
-
const pending = [];
|
|
38679
|
-
for ( let i = 0, il = primitives.length; i < il; i ++ ) {
|
|
38680
|
-
const material = primitives[ i ].material === undefined
|
|
38681
|
-
? createDefaultMaterial( this.cache )
|
|
38682
|
-
: this.getDependency( 'material', primitives[ i ].material );
|
|
38683
|
-
pending.push( material );
|
|
38684
|
-
}
|
|
38685
|
-
pending.push( parser.loadGeometries( primitives ) );
|
|
38686
|
-
return Promise.all( pending ).then( function ( results ) {
|
|
38687
|
-
const materials = results.slice( 0, results.length - 1 );
|
|
38688
|
-
const geometries = results[ results.length - 1 ];
|
|
38689
|
-
const meshes = [];
|
|
38690
|
-
for ( let i = 0, il = geometries.length; i < il; i ++ ) {
|
|
38691
|
-
const geometry = geometries[ i ];
|
|
38692
|
-
const primitive = primitives[ i ];
|
|
38693
|
-
let mesh;
|
|
38694
|
-
const material = materials[ i ];
|
|
38695
|
-
if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLES ||
|
|
38696
|
-
primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP ||
|
|
38697
|
-
primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN ||
|
|
38698
|
-
primitive.mode === undefined ) {
|
|
38699
|
-
mesh = meshDef.isSkinnedMesh === true
|
|
38700
|
-
? new SkinnedMesh( geometry, material )
|
|
38701
|
-
: new Mesh( geometry, material );
|
|
38702
|
-
if ( mesh.isSkinnedMesh === true ) {
|
|
38703
|
-
mesh.normalizeSkinWeights();
|
|
38704
|
-
}
|
|
38705
|
-
if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP ) {
|
|
38706
|
-
mesh.geometry = toTrianglesDrawMode( mesh.geometry, TriangleStripDrawMode );
|
|
38707
|
-
} else if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN ) {
|
|
38708
|
-
mesh.geometry = toTrianglesDrawMode( mesh.geometry, TriangleFanDrawMode );
|
|
38709
|
-
}
|
|
38710
|
-
} else if ( primitive.mode === WEBGL_CONSTANTS.LINES ) {
|
|
38711
|
-
mesh = new LineSegments( geometry, material );
|
|
38712
|
-
} else if ( primitive.mode === WEBGL_CONSTANTS.LINE_STRIP ) {
|
|
38713
|
-
mesh = new Line$1( geometry, material );
|
|
38714
|
-
} else if ( primitive.mode === WEBGL_CONSTANTS.LINE_LOOP ) {
|
|
38715
|
-
mesh = new LineLoop( geometry, material );
|
|
38716
|
-
} else if ( primitive.mode === WEBGL_CONSTANTS.POINTS ) {
|
|
38717
|
-
mesh = new Points( geometry, material );
|
|
38718
|
-
} else {
|
|
38719
|
-
throw new Error( 'THREE.GLTFLoader: Primitive mode unsupported: ' + primitive.mode );
|
|
38720
|
-
}
|
|
38721
|
-
if ( Object.keys( mesh.geometry.morphAttributes ).length > 0 ) {
|
|
38722
|
-
updateMorphTargets( mesh, meshDef );
|
|
38723
|
-
}
|
|
38724
|
-
mesh.name = parser.createUniqueName( meshDef.name || ( 'mesh_' + meshIndex ) );
|
|
38725
|
-
assignExtrasToUserData( mesh, meshDef );
|
|
38726
|
-
if ( primitive.extensions ) addUnknownExtensionsToUserData( extensions, mesh, primitive );
|
|
38727
|
-
parser.assignFinalMaterial( mesh );
|
|
38728
|
-
meshes.push( mesh );
|
|
38729
|
-
}
|
|
38730
|
-
for ( let i = 0, il = meshes.length; i < il; i ++ ) {
|
|
38731
|
-
parser.associations.set( meshes[ i ], {
|
|
38732
|
-
meshes: meshIndex,
|
|
38733
|
-
primitives: i
|
|
38734
|
-
} );
|
|
38735
|
-
}
|
|
38736
|
-
if ( meshes.length === 1 ) {
|
|
38737
|
-
if ( meshDef.extensions ) addUnknownExtensionsToUserData( extensions, meshes[ 0 ], meshDef );
|
|
38738
|
-
return meshes[ 0 ];
|
|
38739
|
-
}
|
|
38740
|
-
const group = new Group$1();
|
|
38741
|
-
if ( meshDef.extensions ) addUnknownExtensionsToUserData( extensions, group, meshDef );
|
|
38742
|
-
parser.associations.set( group, { meshes: meshIndex } );
|
|
38743
|
-
for ( let i = 0, il = meshes.length; i < il; i ++ ) {
|
|
38744
|
-
group.add( meshes[ i ] );
|
|
38745
|
-
}
|
|
38746
|
-
return group;
|
|
38747
|
-
} );
|
|
38748
|
-
}
|
|
38749
|
-
loadCamera( cameraIndex ) {
|
|
38750
|
-
let camera;
|
|
38751
|
-
const cameraDef = this.json.cameras[ cameraIndex ];
|
|
38752
|
-
const params = cameraDef[ cameraDef.type ];
|
|
38753
|
-
if ( ! params ) {
|
|
38754
|
-
console.warn( 'THREE.GLTFLoader: Missing camera parameters.' );
|
|
38755
|
-
return;
|
|
38756
|
-
}
|
|
38757
|
-
if ( cameraDef.type === 'perspective' ) {
|
|
38758
|
-
camera = new PerspectiveCamera( MathUtils.radToDeg( params.yfov ), params.aspectRatio || 1, params.znear || 1, params.zfar || 2e6 );
|
|
38759
|
-
} else if ( cameraDef.type === 'orthographic' ) {
|
|
38760
|
-
camera = new OrthographicCamera( - params.xmag, params.xmag, params.ymag, - params.ymag, params.znear, params.zfar );
|
|
38761
|
-
}
|
|
38762
|
-
if ( cameraDef.name ) camera.name = this.createUniqueName( cameraDef.name );
|
|
38763
|
-
assignExtrasToUserData( camera, cameraDef );
|
|
38764
|
-
return Promise.resolve( camera );
|
|
38765
|
-
}
|
|
38766
|
-
loadSkin( skinIndex ) {
|
|
38767
|
-
const skinDef = this.json.skins[ skinIndex ];
|
|
38768
|
-
const pending = [];
|
|
38769
|
-
for ( let i = 0, il = skinDef.joints.length; i < il; i ++ ) {
|
|
38770
|
-
pending.push( this._loadNodeShallow( skinDef.joints[ i ] ) );
|
|
38771
|
-
}
|
|
38772
|
-
if ( skinDef.inverseBindMatrices !== undefined ) {
|
|
38773
|
-
pending.push( this.getDependency( 'accessor', skinDef.inverseBindMatrices ) );
|
|
38774
|
-
} else {
|
|
38775
|
-
pending.push( null );
|
|
38776
|
-
}
|
|
38777
|
-
return Promise.all( pending ).then( function ( results ) {
|
|
38778
|
-
const inverseBindMatrices = results.pop();
|
|
38779
|
-
const jointNodes = results;
|
|
38780
|
-
const bones = [];
|
|
38781
|
-
const boneInverses = [];
|
|
38782
|
-
for ( let i = 0, il = jointNodes.length; i < il; i ++ ) {
|
|
38783
|
-
const jointNode = jointNodes[ i ];
|
|
38784
|
-
if ( jointNode ) {
|
|
38785
|
-
bones.push( jointNode );
|
|
38786
|
-
const mat = new Matrix4();
|
|
38787
|
-
if ( inverseBindMatrices !== null ) {
|
|
38788
|
-
mat.fromArray( inverseBindMatrices.array, i * 16 );
|
|
38789
|
-
}
|
|
38790
|
-
boneInverses.push( mat );
|
|
38791
|
-
} else {
|
|
38792
|
-
console.warn( 'THREE.GLTFLoader: Joint "%s" could not be found.', skinDef.joints[ i ] );
|
|
38793
|
-
}
|
|
38794
|
-
}
|
|
38795
|
-
return new Skeleton( bones, boneInverses );
|
|
38796
|
-
} );
|
|
38797
|
-
}
|
|
38798
|
-
loadAnimation( animationIndex ) {
|
|
38799
|
-
const json = this.json;
|
|
38800
|
-
const parser = this;
|
|
38801
|
-
const animationDef = json.animations[ animationIndex ];
|
|
38802
|
-
const animationName = animationDef.name ? animationDef.name : 'animation_' + animationIndex;
|
|
38803
|
-
const pendingNodes = [];
|
|
38804
|
-
const pendingInputAccessors = [];
|
|
38805
|
-
const pendingOutputAccessors = [];
|
|
38806
|
-
const pendingSamplers = [];
|
|
38807
|
-
const pendingTargets = [];
|
|
38808
|
-
for ( let i = 0, il = animationDef.channels.length; i < il; i ++ ) {
|
|
38809
|
-
const channel = animationDef.channels[ i ];
|
|
38810
|
-
const sampler = animationDef.samplers[ channel.sampler ];
|
|
38811
|
-
const target = channel.target;
|
|
38812
|
-
const name = target.node;
|
|
38813
|
-
const input = animationDef.parameters !== undefined ? animationDef.parameters[ sampler.input ] : sampler.input;
|
|
38814
|
-
const output = animationDef.parameters !== undefined ? animationDef.parameters[ sampler.output ] : sampler.output;
|
|
38815
|
-
if ( target.node === undefined ) continue;
|
|
38816
|
-
pendingNodes.push( this.getDependency( 'node', name ) );
|
|
38817
|
-
pendingInputAccessors.push( this.getDependency( 'accessor', input ) );
|
|
38818
|
-
pendingOutputAccessors.push( this.getDependency( 'accessor', output ) );
|
|
38819
|
-
pendingSamplers.push( sampler );
|
|
38820
|
-
pendingTargets.push( target );
|
|
38821
|
-
}
|
|
38822
|
-
return Promise.all( [
|
|
38823
|
-
Promise.all( pendingNodes ),
|
|
38824
|
-
Promise.all( pendingInputAccessors ),
|
|
38825
|
-
Promise.all( pendingOutputAccessors ),
|
|
38826
|
-
Promise.all( pendingSamplers ),
|
|
38827
|
-
Promise.all( pendingTargets )
|
|
38828
|
-
] ).then( function ( dependencies ) {
|
|
38829
|
-
const nodes = dependencies[ 0 ];
|
|
38830
|
-
const inputAccessors = dependencies[ 1 ];
|
|
38831
|
-
const outputAccessors = dependencies[ 2 ];
|
|
38832
|
-
const samplers = dependencies[ 3 ];
|
|
38833
|
-
const targets = dependencies[ 4 ];
|
|
38834
|
-
const tracks = [];
|
|
38835
|
-
for ( let i = 0, il = nodes.length; i < il; i ++ ) {
|
|
38836
|
-
const node = nodes[ i ];
|
|
38837
|
-
const inputAccessor = inputAccessors[ i ];
|
|
38838
|
-
const outputAccessor = outputAccessors[ i ];
|
|
38839
|
-
const sampler = samplers[ i ];
|
|
38840
|
-
const target = targets[ i ];
|
|
38841
|
-
if ( node === undefined ) continue;
|
|
38842
|
-
if ( node.updateMatrix ) {
|
|
38843
|
-
node.updateMatrix();
|
|
38844
|
-
}
|
|
38845
|
-
const createdTracks = parser._createAnimationTracks( node, inputAccessor, outputAccessor, sampler, target );
|
|
38846
|
-
if ( createdTracks ) {
|
|
38847
|
-
for ( let k = 0; k < createdTracks.length; k ++ ) {
|
|
38848
|
-
tracks.push( createdTracks[ k ] );
|
|
38849
|
-
}
|
|
38850
|
-
}
|
|
38851
|
-
}
|
|
38852
|
-
const animation = new AnimationClip( animationName, undefined, tracks );
|
|
38853
|
-
assignExtrasToUserData( animation, animationDef );
|
|
38854
|
-
return animation;
|
|
38855
|
-
} );
|
|
38856
|
-
}
|
|
38857
|
-
createNodeMesh( nodeIndex ) {
|
|
38858
|
-
const json = this.json;
|
|
38859
|
-
const parser = this;
|
|
38860
|
-
const nodeDef = json.nodes[ nodeIndex ];
|
|
38861
|
-
if ( nodeDef.mesh === undefined ) return null;
|
|
38862
|
-
return parser.getDependency( 'mesh', nodeDef.mesh ).then( function ( mesh ) {
|
|
38863
|
-
const node = parser._getNodeRef( parser.meshCache, nodeDef.mesh, mesh );
|
|
38864
|
-
if ( nodeDef.weights !== undefined ) {
|
|
38865
|
-
node.traverse( function ( o ) {
|
|
38866
|
-
if ( ! o.isMesh ) return;
|
|
38867
|
-
for ( let i = 0, il = nodeDef.weights.length; i < il; i ++ ) {
|
|
38868
|
-
o.morphTargetInfluences[ i ] = nodeDef.weights[ i ];
|
|
38869
|
-
}
|
|
38870
|
-
} );
|
|
38871
|
-
}
|
|
38872
|
-
return node;
|
|
38873
|
-
} );
|
|
38874
|
-
}
|
|
38875
|
-
loadNode( nodeIndex ) {
|
|
38876
|
-
const json = this.json;
|
|
38877
|
-
const parser = this;
|
|
38878
|
-
const nodeDef = json.nodes[ nodeIndex ];
|
|
38879
|
-
const nodePending = parser._loadNodeShallow( nodeIndex );
|
|
38880
|
-
const childPending = [];
|
|
38881
|
-
const childrenDef = nodeDef.children || [];
|
|
38882
|
-
for ( let i = 0, il = childrenDef.length; i < il; i ++ ) {
|
|
38883
|
-
childPending.push( parser.getDependency( 'node', childrenDef[ i ] ) );
|
|
38884
|
-
}
|
|
38885
|
-
const skeletonPending = nodeDef.skin === undefined
|
|
38886
|
-
? Promise.resolve( null )
|
|
38887
|
-
: parser.getDependency( 'skin', nodeDef.skin );
|
|
38888
|
-
return Promise.all( [
|
|
38889
|
-
nodePending,
|
|
38890
|
-
Promise.all( childPending ),
|
|
38891
|
-
skeletonPending
|
|
38892
|
-
] ).then( function ( results ) {
|
|
38893
|
-
const node = results[ 0 ];
|
|
38894
|
-
const children = results[ 1 ];
|
|
38895
|
-
const skeleton = results[ 2 ];
|
|
38896
|
-
if ( skeleton !== null ) {
|
|
38897
|
-
node.traverse( function ( mesh ) {
|
|
38898
|
-
if ( ! mesh.isSkinnedMesh ) return;
|
|
38899
|
-
mesh.bind( skeleton, _identityMatrix );
|
|
38900
|
-
} );
|
|
38901
|
-
}
|
|
38902
|
-
for ( let i = 0, il = children.length; i < il; i ++ ) {
|
|
38903
|
-
node.add( children[ i ] );
|
|
38904
|
-
}
|
|
38905
|
-
return node;
|
|
38906
|
-
} );
|
|
38907
|
-
}
|
|
38908
|
-
_loadNodeShallow( nodeIndex ) {
|
|
38909
|
-
const json = this.json;
|
|
38910
|
-
const extensions = this.extensions;
|
|
38911
|
-
const parser = this;
|
|
38912
|
-
if ( this.nodeCache[ nodeIndex ] !== undefined ) {
|
|
38913
|
-
return this.nodeCache[ nodeIndex ];
|
|
38914
|
-
}
|
|
38915
|
-
const nodeDef = json.nodes[ nodeIndex ];
|
|
38916
|
-
const nodeName = nodeDef.name ? parser.createUniqueName( nodeDef.name ) : '';
|
|
38917
|
-
const pending = [];
|
|
38918
|
-
const meshPromise = parser._invokeOne( function ( ext ) {
|
|
38919
|
-
return ext.createNodeMesh && ext.createNodeMesh( nodeIndex );
|
|
38920
|
-
} );
|
|
38921
|
-
if ( meshPromise ) {
|
|
38922
|
-
pending.push( meshPromise );
|
|
38923
|
-
}
|
|
38924
|
-
if ( nodeDef.camera !== undefined ) {
|
|
38925
|
-
pending.push( parser.getDependency( 'camera', nodeDef.camera ).then( function ( camera ) {
|
|
38926
|
-
return parser._getNodeRef( parser.cameraCache, nodeDef.camera, camera );
|
|
38927
|
-
} ) );
|
|
38928
|
-
}
|
|
38929
|
-
parser._invokeAll( function ( ext ) {
|
|
38930
|
-
return ext.createNodeAttachment && ext.createNodeAttachment( nodeIndex );
|
|
38931
|
-
} ).forEach( function ( promise ) {
|
|
38932
|
-
pending.push( promise );
|
|
38933
|
-
} );
|
|
38934
|
-
this.nodeCache[ nodeIndex ] = Promise.all( pending ).then( function ( objects ) {
|
|
38935
|
-
let node;
|
|
38936
|
-
if ( nodeDef.isBone === true ) {
|
|
38937
|
-
node = new Bone();
|
|
38938
|
-
} else if ( objects.length > 1 ) {
|
|
38939
|
-
node = new Group$1();
|
|
38940
|
-
} else if ( objects.length === 1 ) {
|
|
38941
|
-
node = objects[ 0 ];
|
|
38942
|
-
} else {
|
|
38943
|
-
node = new Object3D();
|
|
38944
|
-
}
|
|
38945
|
-
if ( node !== objects[ 0 ] ) {
|
|
38946
|
-
for ( let i = 0, il = objects.length; i < il; i ++ ) {
|
|
38947
|
-
node.add( objects[ i ] );
|
|
38948
|
-
}
|
|
38949
|
-
}
|
|
38950
|
-
if ( nodeDef.name ) {
|
|
38951
|
-
node.userData.name = nodeDef.name;
|
|
38952
|
-
node.name = nodeName;
|
|
38953
|
-
}
|
|
38954
|
-
assignExtrasToUserData( node, nodeDef );
|
|
38955
|
-
if ( nodeDef.extensions ) addUnknownExtensionsToUserData( extensions, node, nodeDef );
|
|
38956
|
-
if ( nodeDef.matrix !== undefined ) {
|
|
38957
|
-
const matrix = new Matrix4();
|
|
38958
|
-
matrix.fromArray( nodeDef.matrix );
|
|
38959
|
-
node.applyMatrix4( matrix );
|
|
38960
|
-
} else {
|
|
38961
|
-
if ( nodeDef.translation !== undefined ) {
|
|
38962
|
-
node.position.fromArray( nodeDef.translation );
|
|
38963
|
-
}
|
|
38964
|
-
if ( nodeDef.rotation !== undefined ) {
|
|
38965
|
-
node.quaternion.fromArray( nodeDef.rotation );
|
|
38966
|
-
}
|
|
38967
|
-
if ( nodeDef.scale !== undefined ) {
|
|
38968
|
-
node.scale.fromArray( nodeDef.scale );
|
|
38969
|
-
}
|
|
38970
|
-
}
|
|
38971
|
-
if ( ! parser.associations.has( node ) ) {
|
|
38972
|
-
parser.associations.set( node, {} );
|
|
38973
|
-
} else if ( nodeDef.mesh !== undefined && parser.meshCache.refs[ nodeDef.mesh ] > 1 ) {
|
|
38974
|
-
const mapping = parser.associations.get( node );
|
|
38975
|
-
parser.associations.set( node, { ...mapping } );
|
|
38976
|
-
}
|
|
38977
|
-
parser.associations.get( node ).nodes = nodeIndex;
|
|
38978
|
-
return node;
|
|
38979
|
-
} );
|
|
38980
|
-
return this.nodeCache[ nodeIndex ];
|
|
38981
|
-
}
|
|
38982
|
-
loadScene( sceneIndex ) {
|
|
38983
|
-
const extensions = this.extensions;
|
|
38984
|
-
const sceneDef = this.json.scenes[ sceneIndex ];
|
|
38985
|
-
const parser = this;
|
|
38986
|
-
const scene = new Group$1();
|
|
38987
|
-
if ( sceneDef.name ) scene.name = parser.createUniqueName( sceneDef.name );
|
|
38988
|
-
assignExtrasToUserData( scene, sceneDef );
|
|
38989
|
-
if ( sceneDef.extensions ) addUnknownExtensionsToUserData( extensions, scene, sceneDef );
|
|
38990
|
-
const nodeIds = sceneDef.nodes || [];
|
|
38991
|
-
const pending = [];
|
|
38992
|
-
for ( let i = 0, il = nodeIds.length; i < il; i ++ ) {
|
|
38993
|
-
pending.push( parser.getDependency( 'node', nodeIds[ i ] ) );
|
|
38994
|
-
}
|
|
38995
|
-
return Promise.all( pending ).then( function ( nodes ) {
|
|
38996
|
-
for ( let i = 0, il = nodes.length; i < il; i ++ ) {
|
|
38997
|
-
scene.add( nodes[ i ] );
|
|
38998
|
-
}
|
|
38999
|
-
const reduceAssociations = ( node ) => {
|
|
39000
|
-
const reducedAssociations = new Map();
|
|
39001
|
-
for ( const [ key, value ] of parser.associations ) {
|
|
39002
|
-
if ( key instanceof Material || key instanceof Texture ) {
|
|
39003
|
-
reducedAssociations.set( key, value );
|
|
39004
|
-
}
|
|
39005
|
-
}
|
|
39006
|
-
node.traverse( ( node ) => {
|
|
39007
|
-
const mappings = parser.associations.get( node );
|
|
39008
|
-
if ( mappings != null ) {
|
|
39009
|
-
reducedAssociations.set( node, mappings );
|
|
39010
|
-
}
|
|
39011
|
-
} );
|
|
39012
|
-
return reducedAssociations;
|
|
39013
|
-
};
|
|
39014
|
-
parser.associations = reduceAssociations( scene );
|
|
39015
|
-
return scene;
|
|
39016
|
-
} );
|
|
39017
|
-
}
|
|
39018
|
-
_createAnimationTracks( node, inputAccessor, outputAccessor, sampler, target ) {
|
|
39019
|
-
const tracks = [];
|
|
39020
|
-
const targetName = node.name ? node.name : node.uuid;
|
|
39021
|
-
const targetNames = [];
|
|
39022
|
-
if ( PATH_PROPERTIES[ target.path ] === PATH_PROPERTIES.weights ) {
|
|
39023
|
-
node.traverse( function ( object ) {
|
|
39024
|
-
if ( object.morphTargetInfluences ) {
|
|
39025
|
-
targetNames.push( object.name ? object.name : object.uuid );
|
|
39026
|
-
}
|
|
39027
|
-
} );
|
|
39028
|
-
} else {
|
|
39029
|
-
targetNames.push( targetName );
|
|
39030
|
-
}
|
|
39031
|
-
let TypedKeyframeTrack;
|
|
39032
|
-
switch ( PATH_PROPERTIES[ target.path ] ) {
|
|
39033
|
-
case PATH_PROPERTIES.weights:
|
|
39034
|
-
TypedKeyframeTrack = NumberKeyframeTrack;
|
|
39035
|
-
break;
|
|
39036
|
-
case PATH_PROPERTIES.rotation:
|
|
39037
|
-
TypedKeyframeTrack = QuaternionKeyframeTrack;
|
|
39038
|
-
break;
|
|
39039
|
-
case PATH_PROPERTIES.translation:
|
|
39040
|
-
case PATH_PROPERTIES.scale:
|
|
39041
|
-
TypedKeyframeTrack = VectorKeyframeTrack;
|
|
39042
|
-
break;
|
|
39043
|
-
default:
|
|
39044
|
-
switch ( outputAccessor.itemSize ) {
|
|
39045
|
-
case 1:
|
|
39046
|
-
TypedKeyframeTrack = NumberKeyframeTrack;
|
|
39047
|
-
break;
|
|
39048
|
-
case 2:
|
|
39049
|
-
case 3:
|
|
39050
|
-
default:
|
|
39051
|
-
TypedKeyframeTrack = VectorKeyframeTrack;
|
|
39052
|
-
break;
|
|
39053
|
-
}
|
|
39054
|
-
break;
|
|
39055
|
-
}
|
|
39056
|
-
const interpolation = sampler.interpolation !== undefined ? INTERPOLATION[ sampler.interpolation ] : InterpolateLinear;
|
|
39057
|
-
const outputArray = this._getArrayFromAccessor( outputAccessor );
|
|
39058
|
-
for ( let j = 0, jl = targetNames.length; j < jl; j ++ ) {
|
|
39059
|
-
const track = new TypedKeyframeTrack(
|
|
39060
|
-
targetNames[ j ] + '.' + PATH_PROPERTIES[ target.path ],
|
|
39061
|
-
inputAccessor.array,
|
|
39062
|
-
outputArray,
|
|
39063
|
-
interpolation
|
|
39064
|
-
);
|
|
39065
|
-
if ( sampler.interpolation === 'CUBICSPLINE' ) {
|
|
39066
|
-
this._createCubicSplineTrackInterpolant( track );
|
|
39067
|
-
}
|
|
39068
|
-
tracks.push( track );
|
|
39069
|
-
}
|
|
39070
|
-
return tracks;
|
|
39071
|
-
}
|
|
39072
|
-
_getArrayFromAccessor( accessor ) {
|
|
39073
|
-
let outputArray = accessor.array;
|
|
39074
|
-
if ( accessor.normalized ) {
|
|
39075
|
-
const scale = getNormalizedComponentScale( outputArray.constructor );
|
|
39076
|
-
const scaled = new Float32Array( outputArray.length );
|
|
39077
|
-
for ( let j = 0, jl = outputArray.length; j < jl; j ++ ) {
|
|
39078
|
-
scaled[ j ] = outputArray[ j ] * scale;
|
|
39079
|
-
}
|
|
39080
|
-
outputArray = scaled;
|
|
39081
|
-
}
|
|
39082
|
-
return outputArray;
|
|
39083
|
-
}
|
|
39084
|
-
_createCubicSplineTrackInterpolant( track ) {
|
|
39085
|
-
track.createInterpolant = function InterpolantFactoryMethodGLTFCubicSpline( result ) {
|
|
39086
|
-
const interpolantType = ( this instanceof QuaternionKeyframeTrack ) ? GLTFCubicSplineQuaternionInterpolant : GLTFCubicSplineInterpolant;
|
|
39087
|
-
return new interpolantType( this.times, this.values, this.getValueSize() / 3, result );
|
|
39088
|
-
};
|
|
39089
|
-
track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = true;
|
|
39090
|
-
}
|
|
39091
|
-
}
|
|
39092
|
-
function computeBounds( geometry, primitiveDef, parser ) {
|
|
39093
|
-
const attributes = primitiveDef.attributes;
|
|
39094
|
-
const box = new Box3();
|
|
39095
|
-
if ( attributes.POSITION !== undefined ) {
|
|
39096
|
-
const accessor = parser.json.accessors[ attributes.POSITION ];
|
|
39097
|
-
const min = accessor.min;
|
|
39098
|
-
const max = accessor.max;
|
|
39099
|
-
if ( min !== undefined && max !== undefined ) {
|
|
39100
|
-
box.set(
|
|
39101
|
-
new Vector3( min[ 0 ], min[ 1 ], min[ 2 ] ),
|
|
39102
|
-
new Vector3( max[ 0 ], max[ 1 ], max[ 2 ] )
|
|
39103
|
-
);
|
|
39104
|
-
if ( accessor.normalized ) {
|
|
39105
|
-
const boxScale = getNormalizedComponentScale( WEBGL_COMPONENT_TYPES[ accessor.componentType ] );
|
|
39106
|
-
box.min.multiplyScalar( boxScale );
|
|
39107
|
-
box.max.multiplyScalar( boxScale );
|
|
39108
|
-
}
|
|
39109
|
-
} else {
|
|
39110
|
-
console.warn( 'THREE.GLTFLoader: Missing min/max properties for accessor POSITION.' );
|
|
39111
|
-
return;
|
|
39112
|
-
}
|
|
39113
|
-
} else {
|
|
39114
|
-
return;
|
|
39115
|
-
}
|
|
39116
|
-
const targets = primitiveDef.targets;
|
|
39117
|
-
if ( targets !== undefined ) {
|
|
39118
|
-
const maxDisplacement = new Vector3();
|
|
39119
|
-
const vector = new Vector3();
|
|
39120
|
-
for ( let i = 0, il = targets.length; i < il; i ++ ) {
|
|
39121
|
-
const target = targets[ i ];
|
|
39122
|
-
if ( target.POSITION !== undefined ) {
|
|
39123
|
-
const accessor = parser.json.accessors[ target.POSITION ];
|
|
39124
|
-
const min = accessor.min;
|
|
39125
|
-
const max = accessor.max;
|
|
39126
|
-
if ( min !== undefined && max !== undefined ) {
|
|
39127
|
-
vector.setX( Math.max( Math.abs( min[ 0 ] ), Math.abs( max[ 0 ] ) ) );
|
|
39128
|
-
vector.setY( Math.max( Math.abs( min[ 1 ] ), Math.abs( max[ 1 ] ) ) );
|
|
39129
|
-
vector.setZ( Math.max( Math.abs( min[ 2 ] ), Math.abs( max[ 2 ] ) ) );
|
|
39130
|
-
if ( accessor.normalized ) {
|
|
39131
|
-
const boxScale = getNormalizedComponentScale( WEBGL_COMPONENT_TYPES[ accessor.componentType ] );
|
|
39132
|
-
vector.multiplyScalar( boxScale );
|
|
39133
|
-
}
|
|
39134
|
-
maxDisplacement.max( vector );
|
|
39135
|
-
} else {
|
|
39136
|
-
console.warn( 'THREE.GLTFLoader: Missing min/max properties for accessor POSITION.' );
|
|
39137
|
-
}
|
|
39138
|
-
}
|
|
39139
|
-
}
|
|
39140
|
-
box.expandByVector( maxDisplacement );
|
|
39141
|
-
}
|
|
39142
|
-
geometry.boundingBox = box;
|
|
39143
|
-
const sphere = new Sphere();
|
|
39144
|
-
box.getCenter( sphere.center );
|
|
39145
|
-
sphere.radius = box.min.distanceTo( box.max ) / 2;
|
|
39146
|
-
geometry.boundingSphere = sphere;
|
|
39147
|
-
}
|
|
39148
|
-
function addPrimitiveAttributes( geometry, primitiveDef, parser ) {
|
|
39149
|
-
const attributes = primitiveDef.attributes;
|
|
39150
|
-
const pending = [];
|
|
39151
|
-
function assignAttributeAccessor( accessorIndex, attributeName ) {
|
|
39152
|
-
return parser.getDependency( 'accessor', accessorIndex )
|
|
39153
|
-
.then( function ( accessor ) {
|
|
39154
|
-
geometry.setAttribute( attributeName, accessor );
|
|
39155
|
-
} );
|
|
39156
|
-
}
|
|
39157
|
-
for ( const gltfAttributeName in attributes ) {
|
|
39158
|
-
const threeAttributeName = ATTRIBUTES[ gltfAttributeName ] || gltfAttributeName.toLowerCase();
|
|
39159
|
-
if ( threeAttributeName in geometry.attributes ) continue;
|
|
39160
|
-
pending.push( assignAttributeAccessor( attributes[ gltfAttributeName ], threeAttributeName ) );
|
|
39161
|
-
}
|
|
39162
|
-
if ( primitiveDef.indices !== undefined && ! geometry.index ) {
|
|
39163
|
-
const accessor = parser.getDependency( 'accessor', primitiveDef.indices ).then( function ( accessor ) {
|
|
39164
|
-
geometry.setIndex( accessor );
|
|
39165
|
-
} );
|
|
39166
|
-
pending.push( accessor );
|
|
39167
|
-
}
|
|
39168
|
-
if ( ColorManagement.workingColorSpace !== LinearSRGBColorSpace && 'COLOR_0' in attributes ) {
|
|
39169
|
-
console.warn( `THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${ColorManagement.workingColorSpace}" not supported.` );
|
|
39170
|
-
}
|
|
39171
|
-
assignExtrasToUserData( geometry, primitiveDef );
|
|
39172
|
-
computeBounds( geometry, primitiveDef, parser );
|
|
39173
|
-
return Promise.all( pending ).then( function () {
|
|
39174
|
-
return primitiveDef.targets !== undefined
|
|
39175
|
-
? addMorphTargets( geometry, primitiveDef.targets, parser )
|
|
39176
|
-
: geometry;
|
|
39177
|
-
} );
|
|
39178
|
-
}
|
|
39179
|
-
|
|
39180
|
-
class GLTFLoadingManager extends LoadingManager {
|
|
39181
|
-
constructor(file, params = {}) {
|
|
39182
|
-
super();
|
|
39183
|
-
this.path = "";
|
|
39184
|
-
this.resourcePath = "";
|
|
39185
|
-
this.fileURL = "";
|
|
39186
|
-
this.dataURLs = new Map();
|
|
39187
|
-
this.path = params.path || "";
|
|
39188
|
-
const externalFiles = params.externalFiles || new Map();
|
|
39189
|
-
if (typeof file === "string") {
|
|
39190
|
-
this.fileURL = file;
|
|
39191
|
-
this.resourcePath = LoaderUtils.extractUrlBase(file);
|
|
39192
|
-
}
|
|
39193
|
-
else {
|
|
39194
|
-
externalFiles.forEach((value, key) => (this.fileURL = value === file ? key : this.fileURL));
|
|
39195
|
-
externalFiles.set(this.fileURL, file);
|
|
39196
|
-
}
|
|
39197
|
-
externalFiles.forEach((value, key) => {
|
|
39198
|
-
let dataURL;
|
|
39199
|
-
if (typeof value === "string")
|
|
39200
|
-
dataURL = value;
|
|
39201
|
-
else
|
|
39202
|
-
dataURL = URL.createObjectURL(new Blob([value]));
|
|
39203
|
-
this.dataURLs.set(key, dataURL);
|
|
39204
|
-
});
|
|
39205
|
-
this.setURLModifier((url) => {
|
|
39206
|
-
const key = decodeURI(url)
|
|
39207
|
-
.replace(this.path, "")
|
|
39208
|
-
.replace(this.resourcePath, "")
|
|
39209
|
-
.replace(/^(\.?\/)/, "");
|
|
39210
|
-
const dataURL = this.dataURLs.get(key);
|
|
39211
|
-
return dataURL !== null && dataURL !== void 0 ? dataURL : url;
|
|
39212
|
-
});
|
|
39213
|
-
}
|
|
39214
|
-
dispose() {
|
|
39215
|
-
this.dataURLs.forEach(URL.revokeObjectURL);
|
|
39216
|
-
}
|
|
39217
|
-
}
|
|
39218
|
-
|
|
39219
36747
|
class ModelImpl {
|
|
39220
36748
|
constructor(scene) {
|
|
39221
|
-
this.handle = "1";
|
|
39222
36749
|
this.scene = scene;
|
|
39223
36750
|
}
|
|
39224
36751
|
dispose() {
|
|
@@ -39238,6 +36765,18 @@ void main() {
|
|
|
39238
36765
|
this.scene.traverse(disposeObject);
|
|
39239
36766
|
this.scene.clear();
|
|
39240
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
|
+
}
|
|
39241
36780
|
getExtents(target) {
|
|
39242
36781
|
this.scene.traverseVisible((object) => !object.children.length && target.expandByObject(object));
|
|
39243
36782
|
return target;
|
|
@@ -39260,27 +36799,45 @@ void main() {
|
|
|
39260
36799
|
}
|
|
39261
36800
|
return false;
|
|
39262
36801
|
}
|
|
36802
|
+
hasHandle(handle) {
|
|
36803
|
+
return !handle.includes(":") || handle.split(":", 1)[0] === this.id + "";
|
|
36804
|
+
}
|
|
39263
36805
|
getOwnObjects(objects) {
|
|
39264
36806
|
if (!Array.isArray(objects))
|
|
39265
36807
|
objects = [objects];
|
|
39266
36808
|
return objects.filter((object) => this.hasObject(object));
|
|
39267
36809
|
}
|
|
36810
|
+
getOwnHandles(handles) {
|
|
36811
|
+
if (!Array.isArray(handles))
|
|
36812
|
+
handles = [handles];
|
|
36813
|
+
return handles.filter((handle) => this.hasHandle(handle));
|
|
36814
|
+
}
|
|
39268
36815
|
getObjectsByHandles(handles) {
|
|
39269
|
-
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)));
|
|
39270
36820
|
const objects = [];
|
|
39271
|
-
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
|
+
});
|
|
39272
36826
|
return objects;
|
|
39273
36827
|
}
|
|
39274
36828
|
getHandlesByObjects(objects) {
|
|
39275
|
-
|
|
39276
|
-
|
|
39277
|
-
|
|
39278
|
-
|
|
39279
|
-
|
|
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);
|
|
39280
36839
|
}
|
|
39281
36840
|
hideObjects(objects) {
|
|
39282
|
-
if (!Array.isArray(objects))
|
|
39283
|
-
objects = [objects];
|
|
39284
36841
|
this.getOwnObjects(objects).forEach((object) => (object.visible = false));
|
|
39285
36842
|
return this;
|
|
39286
36843
|
}
|
|
@@ -39296,8 +36853,6 @@ void main() {
|
|
|
39296
36853
|
return this;
|
|
39297
36854
|
}
|
|
39298
36855
|
showObjects(objects) {
|
|
39299
|
-
if (!Array.isArray(objects))
|
|
39300
|
-
objects = [objects];
|
|
39301
36856
|
this.getOwnObjects(objects).forEach((object) => {
|
|
39302
36857
|
object.visible = true;
|
|
39303
36858
|
object.traverseAncestors((parent) => (parent.visible = true));
|
|
@@ -39353,42 +36908,6 @@ void main() {
|
|
|
39353
36908
|
}
|
|
39354
36909
|
}
|
|
39355
36910
|
|
|
39356
|
-
class GLTFFileLoader extends Loader$1 {
|
|
39357
|
-
constructor(viewer) {
|
|
39358
|
-
super();
|
|
39359
|
-
this.viewer = viewer;
|
|
39360
|
-
}
|
|
39361
|
-
isSupport(file, format) {
|
|
39362
|
-
return ((typeof file === "string" || file instanceof globalThis.File || file instanceof ArrayBuffer) &&
|
|
39363
|
-
/(gltf|glb)$/i.test(format));
|
|
39364
|
-
}
|
|
39365
|
-
async load(file, format, params) {
|
|
39366
|
-
const manager = new GLTFLoadingManager(file, params);
|
|
39367
|
-
const loader = new GLTFLoader(manager);
|
|
39368
|
-
loader.setPath(manager.path);
|
|
39369
|
-
loader.setCrossOrigin(params.crossOrigin || loader.crossOrigin);
|
|
39370
|
-
loader.setWithCredentials(params.withCredentials || loader.withCredentials);
|
|
39371
|
-
const progress = (event) => {
|
|
39372
|
-
const { lengthComputable, loaded, total } = event;
|
|
39373
|
-
const progress = lengthComputable ? loaded / total : 1;
|
|
39374
|
-
this.viewer.emitEvent({ type: "geometryprogress", data: progress, file });
|
|
39375
|
-
};
|
|
39376
|
-
const gltf = await loader.loadAsync(manager.fileURL, progress);
|
|
39377
|
-
if (!this.viewer.scene)
|
|
39378
|
-
return this;
|
|
39379
|
-
const modelImpl = new ModelImpl(gltf.scene);
|
|
39380
|
-
modelImpl.loader = this;
|
|
39381
|
-
modelImpl.viewer = this.viewer;
|
|
39382
|
-
this.viewer.scene.add(gltf.scene);
|
|
39383
|
-
this.viewer.models.push(modelImpl);
|
|
39384
|
-
this.viewer.syncOptions();
|
|
39385
|
-
this.viewer.syncOverlay();
|
|
39386
|
-
this.viewer.update();
|
|
39387
|
-
this.viewer.emitEvent({ type: "databasechunk", data: gltf.scene, file });
|
|
39388
|
-
return this;
|
|
39389
|
-
}
|
|
39390
|
-
}
|
|
39391
|
-
|
|
39392
36911
|
class DynamicModelImpl extends ModelImpl {
|
|
39393
36912
|
getExtents(target) {
|
|
39394
36913
|
return target.union(this.gltfLoader.getTotalGeometryExtent());
|
|
@@ -39407,31 +36926,40 @@ void main() {
|
|
|
39407
36926
|
return this.gltfLoader.originalObjects.has(object);
|
|
39408
36927
|
}
|
|
39409
36928
|
getObjectsByHandles(handles) {
|
|
39410
|
-
const
|
|
36929
|
+
const ownHandles = this.getOwnHandles(handles);
|
|
36930
|
+
if (ownHandles.length === 0)
|
|
36931
|
+
return [];
|
|
36932
|
+
const handlesSet = new Set(ownHandles);
|
|
39411
36933
|
const objects = [];
|
|
39412
36934
|
handlesSet.forEach((handle) => {
|
|
39413
|
-
|
|
39414
|
-
const handles = this.gltfLoader.handleToObjects.get(handle2) || [];
|
|
39415
|
-
objects.push(...Array.from(handles));
|
|
36935
|
+
objects.push(...this.gltfLoader.getObjectsByHandle(handle));
|
|
39416
36936
|
});
|
|
39417
36937
|
return objects;
|
|
39418
36938
|
}
|
|
39419
36939
|
getHandlesByObjects(objects) {
|
|
39420
|
-
const
|
|
39421
|
-
|
|
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);
|
|
39422
36950
|
}
|
|
39423
36951
|
hideObjects(objects) {
|
|
39424
|
-
const handles =
|
|
36952
|
+
const handles = this.getHandlesByObjects(objects);
|
|
39425
36953
|
this.gltfLoader.hideObjects(handles);
|
|
39426
36954
|
return this;
|
|
39427
36955
|
}
|
|
39428
36956
|
isolateObjects(objects) {
|
|
39429
|
-
const handles =
|
|
36957
|
+
const handles = this.getHandlesByObjects(objects);
|
|
39430
36958
|
this.gltfLoader.isolateObjects(new Set(handles));
|
|
39431
36959
|
return this;
|
|
39432
36960
|
}
|
|
39433
36961
|
showObjects(objects) {
|
|
39434
|
-
const handles =
|
|
36962
|
+
const handles = this.getHandlesByObjects(objects);
|
|
39435
36963
|
this.gltfLoader.showObjects(handles);
|
|
39436
36964
|
return this;
|
|
39437
36965
|
}
|
|
@@ -39495,11 +37023,14 @@ void main() {
|
|
|
39495
37023
|
this.materials = new Map();
|
|
39496
37024
|
this.textureCache = new Map();
|
|
39497
37025
|
this.materialCache = new Map();
|
|
37026
|
+
this.uri = "";
|
|
37027
|
+
this._nextObjectId = 0;
|
|
39498
37028
|
}
|
|
39499
37029
|
async initialize(loader) {
|
|
39500
37030
|
this.json = await this.loadController.loadJson();
|
|
39501
37031
|
this.baseUrl = await this.loadController.baseUrl();
|
|
39502
37032
|
this.loader = loader;
|
|
37033
|
+
this.uri = this.json.buffers[0].uri || "";
|
|
39503
37034
|
}
|
|
39504
37035
|
clear() {
|
|
39505
37036
|
this.json = null;
|
|
@@ -39593,7 +37124,7 @@ void main() {
|
|
|
39593
37124
|
await this.loader.waitForChunkSlot();
|
|
39594
37125
|
try {
|
|
39595
37126
|
const length = range.end - range.start;
|
|
39596
|
-
const buffer = await this.loadController.loadBinaryData([{ offset: range.start, length }]);
|
|
37127
|
+
const buffer = await this.loadController.loadBinaryData([{ offset: range.start, length }], this.uri);
|
|
39597
37128
|
for (const req of range.requests) {
|
|
39598
37129
|
const relOffset = req.offset - range.start;
|
|
39599
37130
|
try {
|
|
@@ -39910,6 +37441,156 @@ void main() {
|
|
|
39910
37441
|
}
|
|
39911
37442
|
}
|
|
39912
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 = ":";
|
|
39913
37594
|
class DynamicGltfLoader {
|
|
39914
37595
|
constructor(camera, scene, renderer) {
|
|
39915
37596
|
this.camera = camera;
|
|
@@ -39922,6 +37603,7 @@ void main() {
|
|
|
39922
37603
|
geometryerror: [],
|
|
39923
37604
|
update: [],
|
|
39924
37605
|
geometrymemory: [],
|
|
37606
|
+
optimizationprogress: [],
|
|
39925
37607
|
};
|
|
39926
37608
|
this.loadDistance = 100;
|
|
39927
37609
|
this.unloadDistance = 150;
|
|
@@ -39963,7 +37645,6 @@ void main() {
|
|
|
39963
37645
|
this.hiddenHandles = new Set();
|
|
39964
37646
|
this.newOptimizedObjects = new Set();
|
|
39965
37647
|
this.oldOptimizeObjects = new Set();
|
|
39966
|
-
this.maxConcurrentChunks = 8;
|
|
39967
37648
|
this.activeChunkLoads = 0;
|
|
39968
37649
|
this.chunkQueue = [];
|
|
39969
37650
|
this.objectIdToIndex = new Map();
|
|
@@ -39972,6 +37653,7 @@ void main() {
|
|
|
39972
37653
|
this.maxConcurrentChunks = 6;
|
|
39973
37654
|
this.mergedObjectMap = new Map();
|
|
39974
37655
|
this.mergedGeometryVisibility = new Map();
|
|
37656
|
+
this._webglInfoCache = null;
|
|
39975
37657
|
}
|
|
39976
37658
|
setVisibleEdges(visible) {
|
|
39977
37659
|
this.visibleEdges = visible;
|
|
@@ -40075,6 +37757,123 @@ void main() {
|
|
|
40075
37757
|
this.updateMemoryIndicator();
|
|
40076
37758
|
console.log(`Final memory usage: ${Math.round(currentMemoryUsage / (1024 * 1024))}MB`);
|
|
40077
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
|
+
}
|
|
40078
37877
|
async loadNode(nodeId, onLoadFinishCb) {
|
|
40079
37878
|
const node = this.nodes.get(nodeId);
|
|
40080
37879
|
if (!node || node.loaded || node.loading) return;
|
|
@@ -40245,7 +38044,7 @@ void main() {
|
|
|
40245
38044
|
if (node.handle) {
|
|
40246
38045
|
mesh.userData.handle = node.handle;
|
|
40247
38046
|
} else {
|
|
40248
|
-
mesh.userData.handle =
|
|
38047
|
+
mesh.userData.handle = this.getFullHandle(node.structure.id, mesh.userData.handle);
|
|
40249
38048
|
}
|
|
40250
38049
|
if (mesh.material.name === "edges") {
|
|
40251
38050
|
mesh.userData.isEdge = true;
|
|
@@ -40386,12 +38185,15 @@ void main() {
|
|
|
40386
38185
|
})),
|
|
40387
38186
|
});
|
|
40388
38187
|
}
|
|
38188
|
+
getFullHandle(structureId, originalHandle) {
|
|
38189
|
+
return `${structureId}${STRUCTURE_ID_SEPARATOR}${originalHandle}`;
|
|
38190
|
+
}
|
|
40389
38191
|
async processNodeHierarchy(structure, nodeId, parentGroup) {
|
|
40390
38192
|
const nodeDef = structure.json.nodes[nodeId];
|
|
40391
38193
|
let nodeGroup = null;
|
|
40392
38194
|
let handle = null;
|
|
40393
38195
|
if (nodeDef.extras?.handle) {
|
|
40394
|
-
handle =
|
|
38196
|
+
handle = this.getFullHandle(structure.id, nodeDef.extras.handle);
|
|
40395
38197
|
}
|
|
40396
38198
|
if (nodeDef.camera !== undefined) {
|
|
40397
38199
|
const camera = this.loadCamera(structure, nodeDef.camera, nodeDef);
|
|
@@ -40408,7 +38210,7 @@ void main() {
|
|
|
40408
38210
|
if (nodeDef.extras) {
|
|
40409
38211
|
nodeGroup.userData = { ...nodeDef.extras };
|
|
40410
38212
|
if (nodeGroup.userData.handle) {
|
|
40411
|
-
nodeGroup.userData.handle =
|
|
38213
|
+
nodeGroup.userData.handle = this.getFullHandle(structure.id, nodeGroup.userData.handle);
|
|
40412
38214
|
}
|
|
40413
38215
|
}
|
|
40414
38216
|
if (nodeDef.matrix) {
|
|
@@ -40453,7 +38255,7 @@ void main() {
|
|
|
40453
38255
|
this.edgeNodes.push(uniqueNodeId);
|
|
40454
38256
|
}
|
|
40455
38257
|
if (meshDef.extras && meshDef.extras.handle) {
|
|
40456
|
-
handle =
|
|
38258
|
+
handle = this.getFullHandle(structure.id, meshDef.extras.handle);
|
|
40457
38259
|
}
|
|
40458
38260
|
this.nodes.set(uniqueNodeId, {
|
|
40459
38261
|
position: nodeGroup ? nodeGroup.position.clone() : new Vector3().setFromMatrixPosition(nodeMatrix),
|
|
@@ -40466,7 +38268,7 @@ void main() {
|
|
|
40466
38268
|
structure,
|
|
40467
38269
|
extras: nodeDef.extras,
|
|
40468
38270
|
geometryExtents,
|
|
40469
|
-
handle,
|
|
38271
|
+
handle: handle || this.getFullHandle(structure.id, structure._nextObjectId++),
|
|
40470
38272
|
});
|
|
40471
38273
|
}
|
|
40472
38274
|
if (nodeDef.children) {
|
|
@@ -40539,12 +38341,12 @@ void main() {
|
|
|
40539
38341
|
}
|
|
40540
38342
|
}
|
|
40541
38343
|
async loadNodes() {
|
|
40542
|
-
console.time("
|
|
38344
|
+
console.time("Process nodes");
|
|
40543
38345
|
await this.processNodes();
|
|
40544
|
-
console.timeEnd("
|
|
40545
|
-
console.time("
|
|
38346
|
+
console.timeEnd("Process nodes");
|
|
38347
|
+
console.time("Optimize scene");
|
|
40546
38348
|
await this.optimizeScene();
|
|
40547
|
-
console.timeEnd("
|
|
38349
|
+
console.timeEnd("Optimize scene");
|
|
40548
38350
|
}
|
|
40549
38351
|
cleanupPartialLoad() {
|
|
40550
38352
|
this.nodesToLoad.forEach((nodeId) => {
|
|
@@ -40865,7 +38667,7 @@ void main() {
|
|
|
40865
38667
|
this.handleToObjects.set(fullHandle, new Set());
|
|
40866
38668
|
}
|
|
40867
38669
|
this.handleToObjects.get(fullHandle).add(object);
|
|
40868
|
-
object.userData.structureId = object.userData.handle.split(
|
|
38670
|
+
object.userData.structureId = object.userData.handle.split(STRUCTURE_ID_SEPARATOR)[0];
|
|
40869
38671
|
}
|
|
40870
38672
|
getObjectsByHandle(handle) {
|
|
40871
38673
|
if (!handle) return [];
|
|
@@ -40931,10 +38733,28 @@ void main() {
|
|
|
40931
38733
|
}
|
|
40932
38734
|
this.originalObjects.add(object);
|
|
40933
38735
|
}
|
|
40934
|
-
|
|
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
|
+
});
|
|
40935
38750
|
this.originalObjects.clear();
|
|
40936
38751
|
this.originalObjectsToSelection.clear();
|
|
40937
38752
|
const structureGroups = new Map();
|
|
38753
|
+
this.dispatchEvent("optimizationprogress", {
|
|
38754
|
+
phase: "collecting",
|
|
38755
|
+
progress: 5,
|
|
38756
|
+
message: "Collecting scene objects...",
|
|
38757
|
+
});
|
|
40938
38758
|
this.scene.traverse((object) => {
|
|
40939
38759
|
if (object.userData.structureId) {
|
|
40940
38760
|
const structureId = object.userData.structureId;
|
|
@@ -40963,16 +38783,44 @@ void main() {
|
|
|
40963
38783
|
}
|
|
40964
38784
|
}
|
|
40965
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
|
+
});
|
|
40966
38795
|
for (const group of structureGroups.values()) {
|
|
40967
38796
|
group.mapMeshes.clear();
|
|
40968
38797
|
group.mapLines.clear();
|
|
40969
38798
|
group.mapLineSegments.clear();
|
|
40970
38799
|
group.mapPoints.clear();
|
|
40971
|
-
this.mergeMeshGroups(group.meshes, group.rootGroup);
|
|
40972
|
-
this.
|
|
40973
|
-
this.
|
|
40974
|
-
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();
|
|
40975
38818
|
}
|
|
38819
|
+
this.dispatchEvent("optimizationprogress", {
|
|
38820
|
+
phase: "finalizing",
|
|
38821
|
+
progress: 95,
|
|
38822
|
+
message: "Finalizing optimization...",
|
|
38823
|
+
});
|
|
40976
38824
|
this.originalObjects.forEach((obj) => {
|
|
40977
38825
|
obj.visible = false;
|
|
40978
38826
|
if (!(obj instanceof Points) && !obj.userData.isEdge) {
|
|
@@ -40981,9 +38829,15 @@ void main() {
|
|
|
40981
38829
|
});
|
|
40982
38830
|
this.initializeObjectVisibility();
|
|
40983
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
|
+
});
|
|
40984
38837
|
this.dispatchEvent("update");
|
|
40985
38838
|
}
|
|
40986
|
-
mergeMeshGroups(materialGroups, rootGroup) {
|
|
38839
|
+
async mergeMeshGroups(materialGroups, rootGroup) {
|
|
38840
|
+
let processedGroups = 0;
|
|
40987
38841
|
for (const group of materialGroups) {
|
|
40988
38842
|
if (!group.material) {
|
|
40989
38843
|
console.warn("Skipping mesh group with null material");
|
|
@@ -40997,8 +38851,6 @@ void main() {
|
|
|
40997
38851
|
let currentVertexOffset = 0;
|
|
40998
38852
|
for (const mesh of group.objects) {
|
|
40999
38853
|
const geometry = mesh.geometry.clone();
|
|
41000
|
-
mesh.updateWorldMatrix(true, false);
|
|
41001
|
-
geometry.applyMatrix4(mesh.matrixWorld);
|
|
41002
38854
|
const handle = mesh.userData.handle;
|
|
41003
38855
|
if (!this.objectIdToIndex.has(handle)) {
|
|
41004
38856
|
this.objectIdToIndex.set(handle, this.maxObjectId++);
|
|
@@ -41057,6 +38909,10 @@ void main() {
|
|
|
41057
38909
|
this.handleToOptimizedObjects.set(handle, mergedObjects);
|
|
41058
38910
|
}
|
|
41059
38911
|
});
|
|
38912
|
+
processedGroups++;
|
|
38913
|
+
if (processedGroups % 5 === 0) {
|
|
38914
|
+
await this.yieldToUI();
|
|
38915
|
+
}
|
|
41060
38916
|
} catch (error) {
|
|
41061
38917
|
console.error("Failed to merge meshes for material:", error);
|
|
41062
38918
|
group.objects.forEach((mesh) => {
|
|
@@ -41065,7 +38921,8 @@ void main() {
|
|
|
41065
38921
|
}
|
|
41066
38922
|
}
|
|
41067
38923
|
}
|
|
41068
|
-
mergeLineGroups(materialGroups, rootGroup) {
|
|
38924
|
+
async mergeLineGroups(materialGroups, rootGroup) {
|
|
38925
|
+
let processedGroups = 0;
|
|
41069
38926
|
for (const group of materialGroups) {
|
|
41070
38927
|
if (group.objects.length === 0) continue;
|
|
41071
38928
|
if (!group.material) {
|
|
@@ -41084,7 +38941,9 @@ void main() {
|
|
|
41084
38941
|
let posOffset = 0;
|
|
41085
38942
|
const indices = [];
|
|
41086
38943
|
let vertexOffset = 0;
|
|
38944
|
+
let isEdge = false;
|
|
41087
38945
|
group.objects.forEach((line) => {
|
|
38946
|
+
isEdge = line.userData.isEdge;
|
|
41088
38947
|
const geometry = line.geometry;
|
|
41089
38948
|
const positionAttr = geometry.attributes.position;
|
|
41090
38949
|
const vertexCount = positionAttr.count;
|
|
@@ -41097,12 +38956,9 @@ void main() {
|
|
|
41097
38956
|
vertexCount,
|
|
41098
38957
|
});
|
|
41099
38958
|
currentVertexOffset += vertexCount;
|
|
41100
|
-
line.updateWorldMatrix(true, false);
|
|
41101
|
-
const matrix = line.matrixWorld;
|
|
41102
38959
|
const vector = new Vector3();
|
|
41103
38960
|
for (let i = 0; i < vertexCount; i++) {
|
|
41104
38961
|
vector.fromBufferAttribute(positionAttr, i);
|
|
41105
|
-
vector.applyMatrix4(matrix);
|
|
41106
38962
|
positions[posOffset++] = vector.x;
|
|
41107
38963
|
positions[posOffset++] = vector.y;
|
|
41108
38964
|
positions[posOffset++] = vector.z;
|
|
@@ -41135,6 +38991,7 @@ void main() {
|
|
|
41135
38991
|
geometry.setAttribute("visibility", new BufferAttribute(visibilityArray, 1));
|
|
41136
38992
|
const visibilityMaterial = this.createVisibilityMaterial(group.material);
|
|
41137
38993
|
const mergedLine = new LineSegments(geometry, visibilityMaterial);
|
|
38994
|
+
mergedLine.userData.isEdge = isEdge;
|
|
41138
38995
|
const mergedObjects = [mergedLine];
|
|
41139
38996
|
if (this.useVAO) {
|
|
41140
38997
|
this.createVAO(mergedLine);
|
|
@@ -41157,9 +39014,14 @@ void main() {
|
|
|
41157
39014
|
this.handleToOptimizedObjects.set(handle, mergedObjects);
|
|
41158
39015
|
}
|
|
41159
39016
|
});
|
|
39017
|
+
processedGroups++;
|
|
39018
|
+
if (processedGroups % 5 === 0) {
|
|
39019
|
+
await this.yieldToUI();
|
|
39020
|
+
}
|
|
41160
39021
|
}
|
|
41161
39022
|
}
|
|
41162
|
-
mergeLineSegmentGroups(materialGroups, rootGroup) {
|
|
39023
|
+
async mergeLineSegmentGroups(materialGroups, rootGroup) {
|
|
39024
|
+
let processedGroups = 0;
|
|
41163
39025
|
for (const group of materialGroups) {
|
|
41164
39026
|
if (!group.material) {
|
|
41165
39027
|
console.warn("Skipping line segment group with null material");
|
|
@@ -41171,10 +39033,10 @@ void main() {
|
|
|
41171
39033
|
const handles = new Set();
|
|
41172
39034
|
const objectMapping = new Map();
|
|
41173
39035
|
let currentVertexOffset = 0;
|
|
39036
|
+
let isEdge = false;
|
|
41174
39037
|
for (const line of group.objects) {
|
|
39038
|
+
isEdge = line.userData.isEdge;
|
|
41175
39039
|
const geometry = line.geometry.clone();
|
|
41176
|
-
line.updateWorldMatrix(true, false);
|
|
41177
|
-
geometry.applyMatrix4(line.matrixWorld);
|
|
41178
39040
|
const handle = line.userData.handle;
|
|
41179
39041
|
if (!this.objectIdToIndex.has(handle)) {
|
|
41180
39042
|
this.objectIdToIndex.set(handle, this.maxObjectId++);
|
|
@@ -41207,6 +39069,7 @@ void main() {
|
|
|
41207
39069
|
mergedGeometry.setAttribute("visibility", new BufferAttribute(visibilityArray, 1));
|
|
41208
39070
|
const visibilityMaterial = this.createVisibilityMaterial(group.material);
|
|
41209
39071
|
const mergedLine = new LineSegments(mergedGeometry, visibilityMaterial);
|
|
39072
|
+
mergedLine.userData.isEdge = isEdge;
|
|
41210
39073
|
if (this.useVAO) {
|
|
41211
39074
|
this.createVAO(mergedLine);
|
|
41212
39075
|
}
|
|
@@ -41233,6 +39096,10 @@ void main() {
|
|
|
41233
39096
|
this.handleToOptimizedObjects.set(handle, mergedObjects);
|
|
41234
39097
|
}
|
|
41235
39098
|
});
|
|
39099
|
+
processedGroups++;
|
|
39100
|
+
if (processedGroups % 5 === 0) {
|
|
39101
|
+
await this.yieldToUI();
|
|
39102
|
+
}
|
|
41236
39103
|
} catch (error) {
|
|
41237
39104
|
console.warn("Failed to merge line segments for material:", error);
|
|
41238
39105
|
group.objects.forEach((line) => {
|
|
@@ -41241,7 +39108,8 @@ void main() {
|
|
|
41241
39108
|
}
|
|
41242
39109
|
}
|
|
41243
39110
|
}
|
|
41244
|
-
mergePointsGroups(materialGroups, rootGroup) {
|
|
39111
|
+
async mergePointsGroups(materialGroups, rootGroup) {
|
|
39112
|
+
let processedGroups = 0;
|
|
41245
39113
|
for (const group of materialGroups) {
|
|
41246
39114
|
if (!group.material) {
|
|
41247
39115
|
console.warn("Skipping points group with null material");
|
|
@@ -41253,8 +39121,6 @@ void main() {
|
|
|
41253
39121
|
const handles = new Set();
|
|
41254
39122
|
for (const points of group.objects) {
|
|
41255
39123
|
const geometry = points.geometry.clone();
|
|
41256
|
-
points.updateWorldMatrix(true, false);
|
|
41257
|
-
geometry.applyMatrix4(points.matrixWorld);
|
|
41258
39124
|
geometries.push(geometry);
|
|
41259
39125
|
optimizedObjects.push(points);
|
|
41260
39126
|
handles.add(points.userData.handle);
|
|
@@ -41283,6 +39149,10 @@ void main() {
|
|
|
41283
39149
|
this.handleToOptimizedObjects.set(handle, mergedObjects);
|
|
41284
39150
|
}
|
|
41285
39151
|
});
|
|
39152
|
+
processedGroups++;
|
|
39153
|
+
if (processedGroups % 5 === 0) {
|
|
39154
|
+
await this.yieldToUI();
|
|
39155
|
+
}
|
|
41286
39156
|
} catch (error) {
|
|
41287
39157
|
console.warn("Failed to merge points for material:", error);
|
|
41288
39158
|
group.objects.forEach((points) => {
|
|
@@ -41301,7 +39171,6 @@ void main() {
|
|
|
41301
39171
|
const hasNormals = lineSegmentsArray.some((segment) => segment.geometry.attributes.normal !== undefined);
|
|
41302
39172
|
lineSegmentsArray.forEach((segment) => {
|
|
41303
39173
|
const clonedGeometry = segment.geometry.clone();
|
|
41304
|
-
segment.updateWorldMatrix(true, false);
|
|
41305
39174
|
clonedGeometry.applyMatrix4(segment.matrixWorld);
|
|
41306
39175
|
if (hasNormals && !clonedGeometry.attributes.normal) {
|
|
41307
39176
|
clonedGeometry.computeVertexNormals();
|
|
@@ -41518,8 +39387,225 @@ void main() {
|
|
|
41518
39387
|
}
|
|
41519
39388
|
}
|
|
41520
39389
|
|
|
41521
|
-
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 {
|
|
41522
39607
|
constructor(viewer) {
|
|
39608
|
+
super();
|
|
41523
39609
|
this.requestId = 0;
|
|
41524
39610
|
this.viewer = viewer;
|
|
41525
39611
|
}
|
|
@@ -41534,17 +39620,15 @@ void main() {
|
|
|
41534
39620
|
typeof file.downloadResourceRange === "function" &&
|
|
41535
39621
|
/.gltf$/i.test(file.database));
|
|
41536
39622
|
}
|
|
41537
|
-
async load(model, format, params) {
|
|
39623
|
+
async load(model, format, params = {}) {
|
|
41538
39624
|
const scene = new Group$1();
|
|
41539
39625
|
this.gltfLoader = new DynamicGltfLoader(this.viewer.camera, scene, this.viewer.renderer);
|
|
41540
39626
|
this.gltfLoader.memoryLimit = this.viewer.options.memoryLimit;
|
|
41541
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;
|
|
41542
39631
|
this.gltfLoader.addEventListener("databasechunk", (data) => {
|
|
41543
|
-
const modelImpl = new DynamicModelImpl(scene);
|
|
41544
|
-
modelImpl.loader = this;
|
|
41545
|
-
modelImpl.viewer = this.viewer;
|
|
41546
|
-
modelImpl.gltfLoader = this.gltfLoader;
|
|
41547
|
-
modelImpl.modelId = model.id;
|
|
41548
39632
|
this.viewer.scene.add(scene);
|
|
41549
39633
|
this.viewer.models.push(modelImpl);
|
|
41550
39634
|
this.viewer.syncOptions();
|
|
@@ -41552,10 +39636,6 @@ void main() {
|
|
|
41552
39636
|
this.viewer.update();
|
|
41553
39637
|
this.viewer.emitEvent({ type: "databasechunk", data: scene, file: model.file, model });
|
|
41554
39638
|
});
|
|
41555
|
-
this.gltfLoader.addEventListener("geometryprogress", (data) => {
|
|
41556
|
-
const progress = data.loaded / data.total;
|
|
41557
|
-
this.viewer.emitEvent({ type: "geometryprogress", data: progress, file: model.file, model });
|
|
41558
|
-
});
|
|
41559
39639
|
this.gltfLoader.addEventListener("geometryerror", (data) => {
|
|
41560
39640
|
this.viewer.emitEvent({ type: "geometryerror", data, file: model.file, model });
|
|
41561
39641
|
});
|
|
@@ -41565,7 +39645,7 @@ void main() {
|
|
|
41565
39645
|
const loadController = {
|
|
41566
39646
|
loadJson: async () => {
|
|
41567
39647
|
const progress = (progress) => {
|
|
41568
|
-
this.viewer.emitEvent({ type: "geometryprogress", data: progress, file: model });
|
|
39648
|
+
this.viewer.emitEvent({ type: "geometryprogress", data: progress, file: model.file, model });
|
|
41569
39649
|
};
|
|
41570
39650
|
const arrayBuffer = await model.downloadResource(model.database, progress, this.gltfLoader.getAbortController().signal);
|
|
41571
39651
|
const text = new TextDecoder().decode(arrayBuffer);
|
|
@@ -41582,7 +39662,7 @@ void main() {
|
|
|
41582
39662
|
},
|
|
41583
39663
|
baseUrl: () => Promise.resolve(`${model.httpClient.serverUrl}${model.path}/`),
|
|
41584
39664
|
};
|
|
41585
|
-
const structure = new GltfStructure(
|
|
39665
|
+
const structure = new GltfStructure(modelImpl.id, loadController);
|
|
41586
39666
|
await this.gltfLoader.loadStructure(structure);
|
|
41587
39667
|
await this.gltfLoader.loadNodes();
|
|
41588
39668
|
return this;
|
|
@@ -41594,7 +39674,7 @@ void main() {
|
|
|
41594
39674
|
}
|
|
41595
39675
|
|
|
41596
39676
|
const loaders = loadersRegistry("threejs");
|
|
41597
|
-
loaders.registerLoader("gltf-file", (viewer) => new
|
|
39677
|
+
loaders.registerLoader("gltf-file", (viewer) => new GLTFFileDynamicLoader(viewer));
|
|
41598
39678
|
loaders.registerLoader("gltf-cloud", (viewer) => new GLTFCloudDynamicLoader(viewer));
|
|
41599
39679
|
|
|
41600
39680
|
const CopyShader = {
|
|
@@ -56555,24 +54635,25 @@ js: import "konva/skia-backend";
|
|
|
56555
54635
|
class Viewer extends EventEmitter2 {
|
|
56556
54636
|
constructor(client) {
|
|
56557
54637
|
super();
|
|
56558
|
-
this._options = new Options(this);
|
|
56559
54638
|
this.client = client;
|
|
56560
|
-
this.
|
|
56561
|
-
this.canvaseventlistener = (event) => this.emit(event);
|
|
54639
|
+
this.options = new Options(this);
|
|
56562
54640
|
this.loaders = [];
|
|
56563
54641
|
this.models = [];
|
|
54642
|
+
this.canvasEvents = CANVAS_EVENTS.slice();
|
|
54643
|
+
this.canvaseventlistener = (event) => this.emit(event);
|
|
56564
54644
|
this.selected = [];
|
|
56565
54645
|
this.extents = new Box3();
|
|
56566
|
-
this.target = new Vector3();
|
|
54646
|
+
this.target = new Vector3(0, 0, 0);
|
|
56567
54647
|
this._activeDragger = null;
|
|
56568
54648
|
this._components = [];
|
|
54649
|
+
this._renderNeeded = false;
|
|
56569
54650
|
this._renderTime = 0;
|
|
56570
54651
|
this.render = this.render.bind(this);
|
|
56571
54652
|
this.update = this.update.bind(this);
|
|
56572
54653
|
this._markup = new KonvaMarkup();
|
|
56573
54654
|
}
|
|
56574
|
-
get
|
|
56575
|
-
return this.
|
|
54655
|
+
get markup() {
|
|
54656
|
+
return this._markup;
|
|
56576
54657
|
}
|
|
56577
54658
|
get draggers() {
|
|
56578
54659
|
return [...draggers.getDraggers().keys()];
|
|
@@ -56580,14 +54661,10 @@ js: import "konva/skia-backend";
|
|
|
56580
54661
|
get components() {
|
|
56581
54662
|
return [...components.getComponents().keys()];
|
|
56582
54663
|
}
|
|
56583
|
-
get markup() {
|
|
56584
|
-
return this._markup;
|
|
56585
|
-
}
|
|
56586
54664
|
initialize(canvas, onProgress) {
|
|
56587
54665
|
this.addEventListener("optionschange", (event) => this.syncOptions(event.data));
|
|
56588
54666
|
this.scene = new Scene();
|
|
56589
54667
|
this.helpers = new Helpers();
|
|
56590
|
-
this.target = new Vector3(0, 0, 0);
|
|
56591
54668
|
const pixelRatio = window.devicePixelRatio;
|
|
56592
54669
|
const rect = canvas.parentElement.getBoundingClientRect();
|
|
56593
54670
|
const width = rect.width || 1;
|
|
@@ -56738,21 +54815,25 @@ js: import "konva/skia-backend";
|
|
|
56738
54815
|
async open(file, params = {}) {
|
|
56739
54816
|
if (!this.renderer)
|
|
56740
54817
|
return this;
|
|
56741
|
-
|
|
54818
|
+
const mode = params.mode || "file";
|
|
54819
|
+
if (mode !== "assembly" && mode !== "a" && mode !== "append") {
|
|
56742
54820
|
this.cancel();
|
|
56743
54821
|
this.clear();
|
|
56744
54822
|
}
|
|
56745
|
-
this.emitEvent({ type: "open", file });
|
|
54823
|
+
this.emitEvent({ type: "open", mode, file });
|
|
56746
54824
|
let model = file;
|
|
56747
54825
|
if (model && typeof model.getModels === "function") {
|
|
56748
54826
|
const models = await model.getModels();
|
|
56749
54827
|
model = models.find((model) => model.default) || models[0] || file;
|
|
56750
54828
|
}
|
|
54829
|
+
if (model && typeof model.database === "string") {
|
|
54830
|
+
file = model.file;
|
|
54831
|
+
}
|
|
56751
54832
|
if (!model)
|
|
56752
54833
|
throw new Error(`Format not supported`);
|
|
56753
54834
|
let format = params.format;
|
|
56754
|
-
if (!format && typeof
|
|
56755
|
-
format =
|
|
54835
|
+
if (!format && typeof file["type"] === "string")
|
|
54836
|
+
format = file["type"].split(".").pop();
|
|
56756
54837
|
if (!format && typeof file === "string")
|
|
56757
54838
|
format = file.split(".").pop();
|
|
56758
54839
|
if (!format && file instanceof globalThis.File)
|
|
@@ -56779,7 +54860,7 @@ js: import "konva/skia-backend";
|
|
|
56779
54860
|
}
|
|
56780
54861
|
loadGltfFile(file, externalFiles, params = {}) {
|
|
56781
54862
|
console.warn("Viewer.loadGltfFile() has been deprecated since 26.4 and will be removed in a future release, use Viewer.open() instead.");
|
|
56782
|
-
return this.open(file, { ...params, format: "gltf", externalFiles, mode: "
|
|
54863
|
+
return this.open(file, { ...params, format: "gltf", externalFiles, mode: "assembly" });
|
|
56783
54864
|
}
|
|
56784
54865
|
cancel() {
|
|
56785
54866
|
this.loaders.forEach((loader) => loader.cancel());
|
|
@@ -56799,12 +54880,17 @@ js: import "konva/skia-backend";
|
|
|
56799
54880
|
this.models = [];
|
|
56800
54881
|
this.scene.clear();
|
|
56801
54882
|
this.helpers.clear();
|
|
54883
|
+
this.extents.makeEmpty();
|
|
54884
|
+
this.target.set(0, 0, 0);
|
|
56802
54885
|
this.syncOptions();
|
|
56803
54886
|
this.syncOverlay();
|
|
56804
54887
|
this.update(true);
|
|
56805
54888
|
this.emitEvent({ type: "clear" });
|
|
56806
54889
|
return this;
|
|
56807
54890
|
}
|
|
54891
|
+
is3D() {
|
|
54892
|
+
return true;
|
|
54893
|
+
}
|
|
56808
54894
|
syncOptions(options = this.options) {
|
|
56809
54895
|
if (!this.renderer)
|
|
56810
54896
|
return;
|
|
@@ -56836,9 +54922,15 @@ js: import "konva/skia-backend";
|
|
|
56836
54922
|
getSelected() {
|
|
56837
54923
|
return this.executeCommand("getSelected");
|
|
56838
54924
|
}
|
|
54925
|
+
getSelected2() {
|
|
54926
|
+
return this.executeCommand("getSelected2");
|
|
54927
|
+
}
|
|
56839
54928
|
setSelected(handles) {
|
|
56840
54929
|
this.executeCommand("setSelected", handles);
|
|
56841
54930
|
}
|
|
54931
|
+
setSelected2(handles) {
|
|
54932
|
+
this.executeCommand("setSelected2", handles);
|
|
54933
|
+
}
|
|
56842
54934
|
clearSelected() {
|
|
56843
54935
|
this.executeCommand("clearSelected");
|
|
56844
54936
|
}
|
|
@@ -56898,37 +54990,8 @@ js: import "konva/skia-backend";
|
|
|
56898
54990
|
getComponent(name) {
|
|
56899
54991
|
return this._components.find((component) => component.name === name);
|
|
56900
54992
|
}
|
|
56901
|
-
is3D() {
|
|
56902
|
-
return true;
|
|
56903
|
-
}
|
|
56904
|
-
screenToWorld(position) {
|
|
56905
|
-
if (!this.renderer)
|
|
56906
|
-
return { x: position.x, y: position.y, z: 0 };
|
|
56907
|
-
const rect = this.canvas.getBoundingClientRect();
|
|
56908
|
-
const x = position.x / (rect.width / 2) - 1;
|
|
56909
|
-
const y = -position.y / (rect.height / 2) + 1;
|
|
56910
|
-
const point = new Vector3(x, y, -1);
|
|
56911
|
-
point.unproject(this.camera);
|
|
56912
|
-
return { x: point.x, y: point.y, z: point.z };
|
|
56913
|
-
}
|
|
56914
|
-
worldToScreen(position) {
|
|
56915
|
-
if (!this.renderer)
|
|
56916
|
-
return { x: position.x, y: position.y };
|
|
56917
|
-
const point = new Vector3(position.x, position.y, position.z);
|
|
56918
|
-
point.project(this.camera);
|
|
56919
|
-
const rect = this.canvas.getBoundingClientRect();
|
|
56920
|
-
const x = (point.x + 1) * (rect.width / 2);
|
|
56921
|
-
const y = (-point.y + 1) * (rect.height / 2);
|
|
56922
|
-
return { x, y };
|
|
56923
|
-
}
|
|
56924
|
-
getScale() {
|
|
56925
|
-
return { x: 1, y: 1, z: 1 };
|
|
56926
|
-
}
|
|
56927
|
-
executeCommand(id, ...args) {
|
|
56928
|
-
return commands.executeCommand(id, this, ...args);
|
|
56929
|
-
}
|
|
56930
54993
|
drawViewpoint(viewpoint) {
|
|
56931
|
-
var _a, _b, _c;
|
|
54994
|
+
var _a, _b, _c, _d;
|
|
56932
54995
|
if (!this.renderer)
|
|
56933
54996
|
return;
|
|
56934
54997
|
const getVector3FromPoint3d = ({ x, y, z }) => new Vector3(x, y, z);
|
|
@@ -56980,11 +55043,13 @@ js: import "konva/skia-backend";
|
|
|
56980
55043
|
}
|
|
56981
55044
|
};
|
|
56982
55045
|
const setClippingPlanes = (clipping_planes) => {
|
|
56983
|
-
|
|
56984
|
-
|
|
56985
|
-
|
|
56986
|
-
|
|
56987
|
-
|
|
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
|
+
}
|
|
56988
55053
|
};
|
|
56989
55054
|
const setSelection = (selection) => {
|
|
56990
55055
|
if (selection)
|
|
@@ -57000,9 +55065,9 @@ js: import "konva/skia-backend";
|
|
|
57000
55065
|
setOrthogonalCamera(viewpoint.orthogonal_camera);
|
|
57001
55066
|
setPerspectiveCamera(viewpoint.perspective_camera);
|
|
57002
55067
|
setClippingPlanes(viewpoint.clipping_planes);
|
|
57003
|
-
setSelection(viewpoint.selection);
|
|
55068
|
+
setSelection(((_b = viewpoint.custom_fields) === null || _b === void 0 ? void 0 : _b.selection2) || viewpoint.selection);
|
|
57004
55069
|
this._markup.setViewpoint(viewpoint);
|
|
57005
|
-
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));
|
|
57006
55071
|
this.setActiveDragger(draggerName);
|
|
57007
55072
|
this.emitEvent({ type: "drawviewpoint", data: viewpoint });
|
|
57008
55073
|
this.update();
|
|
@@ -57049,6 +55114,9 @@ js: import "konva/skia-backend";
|
|
|
57049
55114
|
const getSelection = () => {
|
|
57050
55115
|
return this.getSelected().map((handle) => ({ handle }));
|
|
57051
55116
|
};
|
|
55117
|
+
const getSelection2 = () => {
|
|
55118
|
+
return this.getSelected2().map((handle) => ({ handle }));
|
|
55119
|
+
};
|
|
57052
55120
|
const viewpoint = { custom_fields: {} };
|
|
57053
55121
|
viewpoint.orthogonal_camera = getOrthogonalCamera();
|
|
57054
55122
|
viewpoint.perspective_camera = getPerspectiveCamera();
|
|
@@ -57057,9 +55125,36 @@ js: import "konva/skia-backend";
|
|
|
57057
55125
|
viewpoint.description = new Date().toDateString();
|
|
57058
55126
|
this._markup.getViewpoint(viewpoint);
|
|
57059
55127
|
viewpoint.custom_fields.camera_target = getPoint3dFromVector3(this.target);
|
|
55128
|
+
viewpoint.custom_fields.selection2 = getSelection2();
|
|
57060
55129
|
this.emitEvent({ type: "createviewpoint", data: viewpoint });
|
|
57061
55130
|
return viewpoint;
|
|
57062
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
|
+
}
|
|
57063
55158
|
}
|
|
57064
55159
|
|
|
57065
55160
|
if (typeof window !== "undefined")
|