@inweb/viewer-three 26.10.1 → 26.10.2

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.
@@ -236,6 +236,7 @@
236
236
  enableGestures: true,
237
237
  geometryType: "vsfx",
238
238
  rulerUnit: "Default",
239
+ cameraMode: "perspective",
239
240
  };
240
241
  }
241
242
  class Options {
@@ -491,6 +492,13 @@
491
492
  this._data.rulerUnit = value;
492
493
  this.change();
493
494
  }
495
+ get cameraMode() {
496
+ return this._data.cameraMode || "perspective";
497
+ }
498
+ set cameraMode(value) {
499
+ this._data.cameraMode = value;
500
+ this.change();
501
+ }
494
502
  }
495
503
  const CanvasEvents = [
496
504
  "click",
@@ -33674,10 +33682,13 @@ void main() {
33674
33682
  class OrbitDragger {
33675
33683
  constructor(viewer) {
33676
33684
  this.updateControls = () => {
33685
+ this.orbit.target.copy(this.viewer.target);
33686
+ this.orbit.update();
33687
+ };
33688
+ this.updateControlsCamera = () => {
33677
33689
  this.orbit.maxDistance = this.viewer.camera.far;
33678
33690
  this.orbit.minDistance = this.viewer.camera.near;
33679
33691
  this.orbit.object = this.viewer.camera;
33680
- this.orbit.target.copy(this.viewer.target);
33681
33692
  this.orbit.update();
33682
33693
  };
33683
33694
  this.controlsStart = () => {
@@ -33734,6 +33745,7 @@ void main() {
33734
33745
  this.viewer.on("viewposition", this.updateControls);
33735
33746
  this.viewer.addEventListener("zoom", this.updateControls);
33736
33747
  this.viewer.addEventListener("drawviewpoint", this.updateControls);
33748
+ this.viewer.addEventListener("changecameramode", this.updateControlsCamera);
33737
33749
  this.viewer.addEventListener("contextmenu", this.stopContextMenu);
33738
33750
  this.updateControls();
33739
33751
  }
@@ -33743,6 +33755,7 @@ void main() {
33743
33755
  this.viewer.off("viewposition", this.updateControls);
33744
33756
  this.viewer.removeEventListener("zoom", this.updateControls);
33745
33757
  this.viewer.removeEventListener("drawviewpoint", this.updateControls);
33758
+ this.viewer.removeEventListener("changecameramode", this.updateControlsCamera);
33746
33759
  this.viewer.removeEventListener("contextmenu", this.stopContextMenu);
33747
33760
  this.orbit.removeEventListener("start", this.controlsStart);
33748
33761
  this.orbit.removeEventListener("change", this.controlsChange);
@@ -33764,6 +33777,9 @@ void main() {
33764
33777
  this.planeHelper.size = this.viewer.extents.getSize(new Vector3()).length();
33765
33778
  this.viewer.update();
33766
33779
  };
33780
+ this.updateTransformCamera = () => {
33781
+ this.transform.camera = this.viewer.camera;
33782
+ };
33767
33783
  this.onDoubleClick = (event) => {
33768
33784
  event.stopPropagation();
33769
33785
  this.plane.negate();
@@ -33789,16 +33805,18 @@ void main() {
33789
33805
  this.transform.addEventListener("change", this.transformChange);
33790
33806
  this.transform.addEventListener("dragging-changed", this.transformDrag);
33791
33807
  this.viewer.helpers.add(this.transform.getHelper());
33792
- this.viewer.on("explode", this.updatePlaneSize);
33793
- this.viewer.on("show", this.updatePlaneSize);
33794
- this.viewer.on("showall", this.updatePlaneSize);
33808
+ this.viewer.addEventListener("explode", this.updatePlaneSize);
33809
+ this.viewer.addEventListener("show", this.updatePlaneSize);
33810
+ this.viewer.addEventListener("showall", this.updatePlaneSize);
33811
+ this.viewer.addEventListener("changecameramode", this.updateTransformCamera);
33795
33812
  this.viewer.canvas.addEventListener("dblclick", this.onDoubleClick, true);
33796
33813
  this.viewer.update();
33797
33814
  }
33798
33815
  dispose() {
33799
- this.viewer.off("explode", this.updatePlaneSize);
33800
- this.viewer.off("show", this.updatePlaneSize);
33801
- this.viewer.off("showAll", this.updatePlaneSize);
33816
+ this.viewer.removeEventListener("explode", this.updatePlaneSize);
33817
+ this.viewer.removeEventListener("show", this.updatePlaneSize);
33818
+ this.viewer.removeEventListener("showall", this.updatePlaneSize);
33819
+ this.viewer.removeEventListener("changecameramode", this.updateTransformCamera);
33802
33820
  this.viewer.canvas.removeEventListener("dblclick", this.onDoubleClick, true);
33803
33821
  this.transform.removeEventListener("change", this.transformChange);
33804
33822
  this.transform.removeEventListener("dragging-changed", this.transformDrag);
@@ -33881,6 +33899,10 @@ void main() {
33881
33899
  this.updateSnapper = () => {
33882
33900
  this.snapper.update(this.viewer);
33883
33901
  };
33902
+ this.updateSnapperCamera = () => {
33903
+ this.snapper.camera = this.viewer.camera;
33904
+ this.overlay.camera = this.viewer.camera;
33905
+ };
33884
33906
  this.overlay = new MeasureOverlay(viewer.camera, viewer.canvas);
33885
33907
  this.overlay.attach();
33886
33908
  this.line = new MeasureLine(this.overlay);
@@ -33897,6 +33919,7 @@ void main() {
33897
33919
  this.viewer.addEventListener("isolate", this.updateSnapper);
33898
33920
  this.viewer.addEventListener("show", this.updateSnapper);
33899
33921
  this.viewer.addEventListener("showall", this.updateSnapper);
33922
+ this.viewer.addEventListener("changecameramode", this.updateSnapperCamera);
33900
33923
  }
33901
33924
  dispose() {
33902
33925
  this.viewer.canvas.removeEventListener("pointerdown", this.onPointerDown);
@@ -33909,6 +33932,8 @@ void main() {
33909
33932
  this.viewer.removeEventListener("isolate", this.updateSnapper);
33910
33933
  this.viewer.removeEventListener("show", this.updateSnapper);
33911
33934
  this.viewer.removeEventListener("showall", this.updateSnapper);
33935
+ this.viewer.removeEventListener("changecameramode", this.updateSnapperCamera);
33936
+ this.snapper.dispose();
33912
33937
  this.snapper.dispose();
33913
33938
  this.overlay.detach();
33914
33939
  this.overlay.dispose();
@@ -33960,16 +33985,16 @@ void main() {
33960
33985
  getDetectRadius(point) {
33961
33986
  const camera = this.camera;
33962
33987
  if (camera.isOrthographicCamera) {
33963
- const worldHeight = camera.top - camera.bottom;
33988
+ const fieldHeight = (camera.top - camera.bottom) / camera.zoom;
33964
33989
  const canvasHeight = this.canvas.height;
33965
- const worldUnitsPerPixel = worldHeight / canvasHeight;
33990
+ const worldUnitsPerPixel = fieldHeight / canvasHeight;
33966
33991
  return this.detectRadiusInPixels * worldUnitsPerPixel;
33967
33992
  }
33968
33993
  if (camera.isPerspectiveCamera) {
33969
33994
  const distance = camera.position.distanceTo(point);
33970
- const worldHeight = 2 * Math.tan(MathUtils.degToRad(camera.fov * 0.5)) * distance;
33995
+ const fieldHeight = 2 * Math.tan(MathUtils.degToRad(camera.fov * 0.5)) * distance;
33971
33996
  const canvasHeight = this.canvas.height;
33972
- const worldUnitsPerPixel = worldHeight / canvasHeight;
33997
+ const worldUnitsPerPixel = fieldHeight / canvasHeight;
33973
33998
  return this.detectRadiusInPixels * worldUnitsPerPixel;
33974
33999
  }
33975
34000
  return 0.1;
@@ -34066,7 +34091,7 @@ void main() {
34066
34091
  this.lines = [];
34067
34092
  }
34068
34093
  render() {
34069
- this.projector.updateProjectionMatrix();
34094
+ this.projector.setFromCamera(this.camera);
34070
34095
  this.lines.forEach((line) => line.render());
34071
34096
  }
34072
34097
  update() {
@@ -34217,6 +34242,10 @@ void main() {
34217
34242
  this.camera = camera;
34218
34243
  this.canvas = canvas;
34219
34244
  }
34245
+ setFromCamera(camera) {
34246
+ this.camera = camera;
34247
+ this.updateProjectionMatrix();
34248
+ }
34220
34249
  updateProjectionMatrix() {
34221
34250
  const rect = this.canvas.getBoundingClientRect();
34222
34251
  _widthHalf = rect.width / 2;
@@ -34393,7 +34422,7 @@ void main() {
34393
34422
  Points: { threshold: 0 },
34394
34423
  Sprite: { threshold: 0 },
34395
34424
  };
34396
- let intersects = this.raycaster.intersectObjects(this.groundObjects, false);
34425
+ const intersects = this.raycaster.intersectObjects(this.groundObjects, false);
34397
34426
  if (intersects.length > 0) {
34398
34427
  const groundY = intersects[0].point.y;
34399
34428
  const targetY = groundY + this.EYE_HEIGHT;
@@ -34485,6 +34514,9 @@ void main() {
34485
34514
  const size = this.viewer.extents.getSize(new Vector3());
34486
34515
  this.controls.movementSpeed = Math.min(size.x, size.y, size.z) / 2;
34487
34516
  };
34517
+ this.updateControlsCamera = () => {
34518
+ this.controls.object = this.viewer.camera;
34519
+ };
34488
34520
  this.controlsChange = () => {
34489
34521
  this.viewer.update();
34490
34522
  this.viewer.emitEvent({ type: "changecamera" });
@@ -34508,13 +34540,15 @@ void main() {
34508
34540
  this.controls.addEventListener("change", this.controlsChange);
34509
34541
  this.controls.addEventListener("walkspeedchange", this.walkspeedChange);
34510
34542
  this.viewer = viewer;
34511
- this.viewer.on("render", this.viewerRender);
34512
- this.viewer.on("zoom", this.viewerZoom);
34543
+ this.viewer.addEventListener("render", this.viewerRender);
34544
+ this.viewer.addEventListener("zoom", this.viewerZoom);
34545
+ this.viewer.addEventListener("changecameramode", this.updateControlsCamera);
34513
34546
  this.updateControls();
34514
34547
  }
34515
34548
  dispose() {
34516
- this.viewer.off("render", this.viewerRender);
34517
- this.viewer.off("zoom", this.viewerZoom);
34549
+ this.viewer.removeEventListener("render", this.viewerRender);
34550
+ this.viewer.removeEventListener("zoom", this.viewerZoom);
34551
+ this.viewer.removeEventListener("changecameramode", this.updateControlsCamera);
34518
34552
  this.controls.removeEventListener("walkspeedchange", this.walkspeedChange);
34519
34553
  this.controls.removeEventListener("change", this.controlsChange);
34520
34554
  this.controls.dispose();
@@ -34674,6 +34708,9 @@ void main() {
34674
34708
  const size = this.viewer.extents.getSize(new Vector3());
34675
34709
  this.controls.movementSpeed = Math.min(size.x, size.y, size.z) / 2;
34676
34710
  };
34711
+ this.updateControlsCamera = () => {
34712
+ this.controls.object = this.viewer.camera;
34713
+ };
34677
34714
  this.controlsChange = () => {
34678
34715
  this.viewer.update();
34679
34716
  this.viewer.emitEvent({ type: "changecamera" });
@@ -34691,13 +34728,15 @@ void main() {
34691
34728
  this.controls.addEventListener("change", this.controlsChange);
34692
34729
  this.controls.addEventListener("flyspeedchange", this.flyspeedChange);
34693
34730
  this.viewer = viewer;
34694
- this.viewer.on("render", this.viewerRender);
34695
- this.viewer.on("zoom", this.viewerZoom);
34731
+ this.viewer.addEventListener("render", this.viewerRender);
34732
+ this.viewer.addEventListener("zoom", this.viewerZoom);
34733
+ this.viewer.addEventListener("changecameramode", this.updateControlsCamera);
34696
34734
  this.updateControls();
34697
34735
  }
34698
34736
  dispose() {
34699
- this.viewer.off("render", this.viewerRender);
34700
- this.viewer.off("zoom", this.viewerZoom);
34737
+ this.viewer.removeEventListener("render", this.viewerRender);
34738
+ this.viewer.removeEventListener("zoom", this.viewerZoom);
34739
+ this.viewer.removeEventListener("changecameramode", this.updateControlsCamera);
34701
34740
  this.controls.removeEventListener("flyspeedchange", this.flyspeedChange);
34702
34741
  this.controls.removeEventListener("change", this.controlsChange);
34703
34742
  this.controls.dispose();
@@ -34995,10 +35034,10 @@ void main() {
34995
35034
 
34996
35035
  class CameraComponent {
34997
35036
  constructor(viewer) {
35037
+ this.optionsChange = () => {
35038
+ this.switchCameraMode(this.viewer.options.cameraMode);
35039
+ };
34998
35040
  this.geometryEnd = () => {
34999
- const extentsSize = this.viewer.extents.getBoundingSphere(new Sphere()).radius * 2;
35000
- const rendererSize = this.viewer.renderer.getSize(new Vector2());
35001
- const aspect = rendererSize.x / rendererSize.y;
35002
35041
  let camera;
35003
35042
  this.viewer.scene.traverse((object) => {
35004
35043
  if (object.isCamera)
@@ -35010,36 +35049,83 @@ void main() {
35010
35049
  if (camera) {
35011
35050
  camera.isDefaultCamera = true;
35012
35051
  camera.scale.set(1, 1, 1);
35013
- this.viewer.camera = camera;
35014
- this.viewer.renderPass.camera = camera;
35015
- this.viewer.helpersPass.camera = camera;
35016
- this.viewer.ssaaRenderPass.camera = camera;
35052
+ this.switchCamera(camera);
35053
+ const mode = this.getCameraMode(camera);
35054
+ this.viewer.options.cameraMode = mode;
35055
+ this.viewer.emitEvent({ type: "changecameramode", mode });
35017
35056
  }
35018
35057
  else {
35019
- camera = this.viewer.camera;
35020
- }
35021
- if (camera.isPerspectiveCamera) {
35022
- camera.aspect = aspect;
35023
- camera.near = extentsSize / 1000;
35024
- camera.far = extentsSize * 1000;
35025
- camera.updateProjectionMatrix();
35026
- }
35027
- if (camera.isOrthographicCamera) {
35028
- camera.left = camera.bottom * aspect;
35029
- camera.right = camera.top * aspect;
35030
- camera.near = 0;
35031
- camera.far = extentsSize * 1000;
35032
- camera.updateProjectionMatrix();
35033
- }
35034
- if (!camera.isDefaultCamera) {
35058
+ this.switchCamera(this.viewer.camera);
35035
35059
  this.viewer.executeCommand("setDefaultViewPosition");
35036
35060
  }
35037
35061
  };
35038
35062
  this.viewer = viewer;
35039
35063
  this.viewer.addEventListener("databasechunk", this.geometryEnd);
35064
+ this.viewer.addEventListener("optionschange", this.optionsChange);
35065
+ this.viewer.addEventListener("initialize", this.optionsChange);
35040
35066
  }
35041
35067
  dispose() {
35042
35068
  this.viewer.removeEventListener("databasechunk", this.geometryEnd);
35069
+ this.viewer.removeEventListener("optionschange", this.optionsChange);
35070
+ this.viewer.removeEventListener("initialize", this.optionsChange);
35071
+ }
35072
+ getCameraMode(camera) {
35073
+ return camera.isOrthographicCamera ? "orthographic" : "perspective";
35074
+ }
35075
+ switchCamera(camera) {
35076
+ const extentsSize = this.viewer.extents.getBoundingSphere(new Sphere()).radius * 2 || 1;
35077
+ const rendererSize = this.viewer.renderer.getSize(new Vector2());
35078
+ const aspect = rendererSize.x / rendererSize.y;
35079
+ if (camera.isPerspectiveCamera) {
35080
+ camera.aspect = aspect;
35081
+ camera.near = extentsSize / 1000;
35082
+ camera.far = extentsSize * 1000;
35083
+ }
35084
+ if (camera.isOrthographicCamera) {
35085
+ camera.left = camera.bottom * aspect;
35086
+ camera.right = camera.top * aspect;
35087
+ camera.near = 0;
35088
+ camera.far = extentsSize * 1000;
35089
+ }
35090
+ camera.updateProjectionMatrix();
35091
+ this.viewer.camera = camera;
35092
+ this.viewer.renderPass.camera = camera;
35093
+ this.viewer.helpersPass.camera = camera;
35094
+ this.viewer.ssaaRenderPass.camera = camera;
35095
+ this.viewer.update();
35096
+ }
35097
+ switchCameraMode(mode) {
35098
+ if (!mode)
35099
+ return;
35100
+ const currentCamera = this.viewer.camera;
35101
+ if (mode === this.getCameraMode(currentCamera))
35102
+ return;
35103
+ const target = this.viewer.target.clone();
35104
+ let camera;
35105
+ if (currentCamera.isOrthographicCamera) {
35106
+ const fov = currentCamera.userData.fov || 45;
35107
+ const fieldHeight = (currentCamera.top - currentCamera.bottom) / currentCamera.zoom;
35108
+ const distance = fieldHeight / (2 * Math.tan(MathUtils.degToRad(fov) / 2));
35109
+ const direction = new Vector3().subVectors(currentCamera.position, target).normalize();
35110
+ camera = new PerspectiveCamera(fov);
35111
+ camera.position.copy(direction).multiplyScalar(distance).add(target);
35112
+ }
35113
+ if (currentCamera.isPerspectiveCamera) {
35114
+ const fov = currentCamera.fov;
35115
+ const distance = currentCamera.position.distanceTo(target);
35116
+ const fieldHeight = 2 * Math.tan(MathUtils.degToRad(fov) / 2) * distance;
35117
+ camera = new OrthographicCamera();
35118
+ camera.top = fieldHeight / 2;
35119
+ camera.bottom = -fieldHeight / 2;
35120
+ camera.position.copy(currentCamera.position);
35121
+ camera.userData.fov = fov;
35122
+ }
35123
+ if (!camera)
35124
+ return;
35125
+ camera.up.copy(currentCamera.up);
35126
+ camera.quaternion.copy(currentCamera.quaternion);
35127
+ this.switchCamera(camera);
35128
+ this.viewer.emitEvent({ type: "changecameramode", mode });
35043
35129
  }
35044
35130
  }
35045
35131
 
@@ -57241,6 +57327,7 @@ void main() {
57241
57327
  this.renderPass.camera = camera;
57242
57328
  this.helpersPass.camera = camera;
57243
57329
  this.ssaaRenderPass.camera = camera;
57330
+ this.emitEvent({ type: "changecameramode", mode: "orthographic" });
57244
57331
  }
57245
57332
  };
57246
57333
  const setPerspectiveCamera = (perspective_camera) => {
@@ -57262,6 +57349,7 @@ void main() {
57262
57349
  this.renderPass.camera = camera;
57263
57350
  this.helpersPass.camera = camera;
57264
57351
  this.ssaaRenderPass.camera = camera;
57352
+ this.emitEvent({ type: "changecameramode", mode: "perspective" });
57265
57353
  }
57266
57354
  };
57267
57355
  const setClippingPlanes = (clipping_planes) => {