@inweb/viewer-three 26.10.2 → 26.10.4

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.
@@ -33897,7 +33897,7 @@ void main() {
33897
33897
  this.overlay.render();
33898
33898
  };
33899
33899
  this.updateSnapper = () => {
33900
- this.snapper.update(this.viewer);
33900
+ this.snapper.setFromViewer(this.viewer);
33901
33901
  };
33902
33902
  this.updateSnapperCamera = () => {
33903
33903
  this.snapper.camera = this.viewer.camera;
@@ -33934,7 +33934,6 @@ void main() {
33934
33934
  this.viewer.removeEventListener("showall", this.updateSnapper);
33935
33935
  this.viewer.removeEventListener("changecameramode", this.updateSnapperCamera);
33936
33936
  this.snapper.dispose();
33937
- this.snapper.dispose();
33938
33937
  this.overlay.detach();
33939
33938
  this.overlay.dispose();
33940
33939
  super.dispose();
@@ -33951,6 +33950,7 @@ void main() {
33951
33950
  this.camera = camera;
33952
33951
  this.canvas = canvas;
33953
33952
  this.objects = [];
33953
+ this.clippingPlanes = [];
33954
33954
  this.raycaster = new Raycaster();
33955
33955
  this.detectRadiusInPixels = this.isMobile() ? MOBILE_SNAP_DISTANCE : DESKTOP_SNAP_DISTANCE;
33956
33956
  this.edgesCache = new WeakMap();
@@ -33966,7 +33966,7 @@ void main() {
33966
33966
  getMousePosition(event, target) {
33967
33967
  return target.set(event.clientX, event.clientY);
33968
33968
  }
33969
- getPointerIntersects(mouse, objects) {
33969
+ getPointerIntersects(mouse) {
33970
33970
  const rect = this.canvas.getBoundingClientRect();
33971
33971
  const x = ((mouse.x - rect.left) / rect.width) * 2 - 1;
33972
33972
  const y = (-(mouse.y - rect.top) / rect.height) * 2 + 1;
@@ -33980,7 +33980,11 @@ void main() {
33980
33980
  Points: { threshold: 0.01 },
33981
33981
  Sprite: {},
33982
33982
  };
33983
- return this.raycaster.intersectObjects(objects, false);
33983
+ let intersects = this.raycaster.intersectObjects(this.objects, false);
33984
+ this.clippingPlanes.forEach((plane) => {
33985
+ intersects = intersects.filter((intersect) => plane.distanceToPoint(intersect.point) >= 0);
33986
+ });
33987
+ return intersects;
33984
33988
  }
33985
33989
  getDetectRadius(point) {
33986
33990
  const camera = this.camera;
@@ -34001,7 +34005,7 @@ void main() {
34001
34005
  }
34002
34006
  getSnapPoint(event) {
34003
34007
  const mouse = this.getMousePosition(event, new Vector2());
34004
- const intersections = this.getPointerIntersects(mouse, this.objects);
34008
+ const intersections = this.getPointerIntersects(mouse);
34005
34009
  if (intersections.length === 0)
34006
34010
  return undefined;
34007
34011
  const object = intersections[0].object;
@@ -34049,40 +34053,47 @@ void main() {
34049
34053
  return object.localToWorld(snapPoint);
34050
34054
  return intersectionPoint.clone();
34051
34055
  }
34052
- update(viewer) {
34056
+ setFromViewer(viewer) {
34053
34057
  this.objects.length = 0;
34054
34058
  viewer.models.forEach((model) => {
34055
34059
  model.getVisibleObjects().forEach((object) => this.objects.push(object));
34056
34060
  });
34061
+ this.camera = viewer.camera;
34062
+ this.clippingPlanes = viewer.renderer.clippingPlanes || [];
34057
34063
  }
34058
34064
  }
34059
34065
  class MeasureOverlay {
34060
34066
  constructor(camera, canvas) {
34061
34067
  this.lines = [];
34068
+ this.resizeContainer = (entries) => {
34069
+ const { width, height } = entries[0].contentRect;
34070
+ if (!width || !height)
34071
+ return;
34072
+ this.container.style.width = `${width}px`;
34073
+ this.container.style.height = `${height}px`;
34074
+ };
34062
34075
  this.camera = camera;
34063
34076
  this.canvas = canvas;
34064
34077
  this.projector = new MeasureProjector(camera, canvas);
34078
+ this.resizeObserver = new ResizeObserver(this.resizeContainer);
34065
34079
  }
34066
34080
  attach() {
34067
34081
  this.container = document.createElement("div");
34068
34082
  this.container.id = "measure-container";
34069
- this.container.style.background = "rgba(0,0,0,0)";
34070
34083
  this.container.style.position = "absolute";
34071
- this.container.style.top = "0px";
34072
- this.container.style.left = "0px";
34073
- this.container.style.width = "100%";
34074
- this.container.style.height = "100%";
34075
34084
  this.container.style.outline = "none";
34076
34085
  this.container.style.pointerEvents = "none";
34077
34086
  this.container.style.overflow = "hidden";
34078
34087
  if (!this.canvas.parentElement)
34079
34088
  return;
34080
34089
  this.canvas.parentElement.appendChild(this.container);
34090
+ this.resizeObserver.observe(this.canvas.parentElement);
34081
34091
  }
34082
34092
  dispose() {
34083
34093
  this.clear();
34084
34094
  }
34085
34095
  detach() {
34096
+ this.resizeObserver.disconnect();
34086
34097
  this.container.remove();
34087
34098
  this.container = undefined;
34088
34099
  }
@@ -34508,11 +34519,205 @@ void main() {
34508
34519
  }
34509
34520
  }
34510
34521
 
34522
+ class JoyStickControls extends Controls {
34523
+ constructor(camera, domElement, canvasElement, groundObjects) {
34524
+ super(camera, domElement);
34525
+ this.EYE_HEIGHT = 1.7;
34526
+ this.FAILING_DISTANCE = 2;
34527
+ this.GROUND_FOLLOWING_SPEED = 0.05;
34528
+ this.WALK_SPEED_DELIMITER = 4;
34529
+ this.movementSpeed = 0.1;
34530
+ this.multiplier = 3;
34531
+ this.isActive = false;
34532
+ this.MAX_JOYSTICK_DISTANCE = 100;
34533
+ this.INTERNAL_RADIUS = 35;
34534
+ this.MAX_MOVE_STICK = 40;
34535
+ this.EXTERNAL_RADIUS = 65;
34536
+ this.CANVAS_SIZE = 200;
34537
+ this.pressed = false;
34538
+ this.onPointerDown = (event) => {
34539
+ event.preventDefault();
34540
+ this.pressed = true;
34541
+ };
34542
+ this.onPointerMove = (event) => {
34543
+ event.preventDefault();
34544
+ if (!this.pressed)
34545
+ return;
34546
+ let movedX = event.pageX;
34547
+ let movedY = event.pageY;
34548
+ if (this.joyStickCanvas.offsetParent &&
34549
+ this.joyStickCanvas.offsetParent.tagName.toUpperCase() === "BODY") {
34550
+ movedX -= this.joyStickCanvas.offsetLeft;
34551
+ movedY -= this.joyStickCanvas.offsetTop;
34552
+ }
34553
+ else if (this.joyStickCanvas.offsetParent) {
34554
+ movedX -= this.joyStickCanvas.offsetParent.offsetLeft;
34555
+ movedY -= this.joyStickCanvas.offsetParent.offsetTop;
34556
+ }
34557
+ const x = 100 * ((movedX - this.centerX) / this.MAX_MOVE_STICK);
34558
+ const y = 100 * ((movedY - this.centerY) / this.MAX_MOVE_STICK) * -1;
34559
+ const distance = Math.sqrt(x * x + y * y);
34560
+ if (distance > 20) {
34561
+ this.joyStickPosition.set(x, y);
34562
+ this.isActive = true;
34563
+ }
34564
+ else {
34565
+ this.joyStickPosition.set(0, 0);
34566
+ this.isActive = false;
34567
+ }
34568
+ this.draw();
34569
+ this.moveClock.start();
34570
+ this.update();
34571
+ };
34572
+ this.onPointerUp = (event) => {
34573
+ event.preventDefault();
34574
+ this.pressed = false;
34575
+ this.joyStickPosition.set(0, 0);
34576
+ this.isActive = false;
34577
+ this.moveClock.stop();
34578
+ this.draw();
34579
+ };
34580
+ this.onResize = () => {
34581
+ this.updateVisibility();
34582
+ this.updatePosition();
34583
+ };
34584
+ this.camera = camera;
34585
+ this.canvas = canvasElement;
34586
+ this.moveClock = new Clock(false);
34587
+ this.joyStickPosition = new Vector2(0, 0);
34588
+ this.groundObjects = groundObjects;
34589
+ this.raycaster = new Raycaster();
34590
+ this.raycaster.near = 0;
34591
+ this.raycaster.far = this.EYE_HEIGHT + this.FAILING_DISTANCE;
34592
+ this.centerX = this.CANVAS_SIZE / 2;
34593
+ this.centerY = this.CANVAS_SIZE / 2;
34594
+ this.overlayElement = document.createElement("div");
34595
+ this.overlayElement.id = "joyStickDiv";
34596
+ this.overlayElement.style.background = "rgba(0,0,0,0)";
34597
+ this.overlayElement.style.position = "fixed";
34598
+ this.overlayElement.style.zIndex = "0";
34599
+ this.overlayElement.style.touchAction = "none";
34600
+ document.body.appendChild(this.overlayElement);
34601
+ this.joyStickCanvas = document.createElement("canvas");
34602
+ this.joyStickCanvas.id = "joyStickCanvas";
34603
+ this.joyStickCanvas.width = this.CANVAS_SIZE;
34604
+ this.joyStickCanvas.height = this.CANVAS_SIZE;
34605
+ this.overlayElement.appendChild(this.joyStickCanvas);
34606
+ this.context = this.joyStickCanvas.getContext("2d");
34607
+ this.joyStickCanvas.addEventListener("pointerdown", this.onPointerDown);
34608
+ document.addEventListener("pointermove", this.onPointerMove);
34609
+ document.addEventListener("pointerup", this.onPointerUp);
34610
+ window.addEventListener("resize", this.onResize);
34611
+ document.addEventListener("fullscreenchange", this.onResize);
34612
+ this.updateVisibility();
34613
+ this.updatePosition();
34614
+ this.draw();
34615
+ }
34616
+ dispose() {
34617
+ this.joyStickCanvas.removeEventListener("pointerdown", this.onPointerDown);
34618
+ document.removeEventListener("pointermove", this.onPointerMove);
34619
+ document.removeEventListener("pointerup", this.onPointerUp);
34620
+ window.removeEventListener("resize", this.onResize);
34621
+ document.removeEventListener("fullscreenchange", this.onResize);
34622
+ this.overlayElement.remove();
34623
+ super.dispose();
34624
+ }
34625
+ updateVisibility() {
34626
+ const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
34627
+ const isNarrowScreen = window.innerWidth < 1024;
34628
+ if (isMobile || isNarrowScreen) {
34629
+ this.overlayElement.style.display = "block";
34630
+ }
34631
+ else {
34632
+ this.overlayElement.style.display = "none";
34633
+ }
34634
+ }
34635
+ updatePosition() {
34636
+ const rect = this.canvas.getBoundingClientRect();
34637
+ this.overlayElement.style.top = `${rect.height - this.CANVAS_SIZE}px`;
34638
+ this.overlayElement.style.left = `${rect.left}px`;
34639
+ this.overlayElement.style.width = `${this.CANVAS_SIZE}px`;
34640
+ this.overlayElement.style.height = `${this.CANVAS_SIZE}px`;
34641
+ }
34642
+ draw() {
34643
+ this.context.clearRect(0, 0, this.CANVAS_SIZE, this.CANVAS_SIZE);
34644
+ this.context.beginPath();
34645
+ this.context.arc(this.centerX, this.centerY, this.EXTERNAL_RADIUS, 0, 2 * Math.PI, false);
34646
+ this.context.lineWidth = 2;
34647
+ this.context.strokeStyle = "#35436E";
34648
+ this.context.globalAlpha = 0.5;
34649
+ this.context.stroke();
34650
+ let movedX = this.centerX + (this.joyStickPosition.x * this.MAX_MOVE_STICK) / 100;
34651
+ let movedY = this.centerY - (this.joyStickPosition.y * this.MAX_MOVE_STICK) / 100;
34652
+ movedX = Math.max(this.MAX_MOVE_STICK, Math.min(this.CANVAS_SIZE - this.MAX_MOVE_STICK, movedX));
34653
+ movedY = Math.max(this.MAX_MOVE_STICK, Math.min(this.CANVAS_SIZE - this.MAX_MOVE_STICK, movedY));
34654
+ this.context.beginPath();
34655
+ this.context.arc(movedX, movedY, this.INTERNAL_RADIUS, 0, 2 * Math.PI, false);
34656
+ this.context.fillStyle = "#35436E";
34657
+ this.context.lineWidth = 2;
34658
+ this.context.strokeStyle = "#35436E";
34659
+ this.context.globalAlpha = 0.5;
34660
+ this.context.fill();
34661
+ this.context.stroke();
34662
+ }
34663
+ updateGroundFollowing() {
34664
+ const up = new Vector3().copy(this.camera.up);
34665
+ this.raycaster.set(this.camera.position, up.negate());
34666
+ this.raycaster.params = this.raycaster.params = {
34667
+ Mesh: {},
34668
+ Line: { threshold: 0 },
34669
+ Line2: { threshold: 0 },
34670
+ LOD: { threshold: 0 },
34671
+ Points: { threshold: 0 },
34672
+ Sprite: { threshold: 0 },
34673
+ };
34674
+ const intersects = this.raycaster.intersectObjects(this.groundObjects, false);
34675
+ if (intersects.length > 0) {
34676
+ const groundY = intersects[0].point.y;
34677
+ const targetY = groundY + this.EYE_HEIGHT;
34678
+ this.camera.position.y = MathUtils.lerp(this.camera.position.y, targetY, this.GROUND_FOLLOWING_SPEED);
34679
+ }
34680
+ }
34681
+ update() {
34682
+ if (!this.isActive)
34683
+ return;
34684
+ const forwardInput = this.joyStickPosition.y / this.MAX_JOYSTICK_DISTANCE;
34685
+ const rightInput = this.joyStickPosition.x / this.MAX_JOYSTICK_DISTANCE;
34686
+ const timeDelta = this.moveClock.getDelta();
34687
+ const moveDelta = (timeDelta * this.multiplier * this.movementSpeed) / this.WALK_SPEED_DELIMITER;
34688
+ const forward = new Vector3();
34689
+ const sideways = new Vector3();
34690
+ this.camera.getWorldDirection(forward);
34691
+ if (this.groundObjects.length > 0) {
34692
+ forward.y = 0;
34693
+ }
34694
+ forward.normalize();
34695
+ sideways.setFromMatrixColumn(this.camera.matrix, 0);
34696
+ if (this.groundObjects.length > 0) {
34697
+ sideways.y = 0;
34698
+ }
34699
+ sideways.normalize();
34700
+ if (forwardInput !== 0) {
34701
+ this.camera.position.addScaledVector(forward, moveDelta * forwardInput);
34702
+ }
34703
+ if (rightInput !== 0) {
34704
+ this.camera.position.addScaledVector(sideways, moveDelta * rightInput);
34705
+ }
34706
+ if (forwardInput !== 0 || rightInput !== 0) {
34707
+ if (this.groundObjects.length > 0)
34708
+ this.updateGroundFollowing();
34709
+ this.dispatchEvent({ type: "change" });
34710
+ }
34711
+ }
34712
+ }
34713
+
34511
34714
  class WalkDragger {
34512
34715
  constructor(viewer) {
34513
34716
  this.updateControls = () => {
34514
34717
  const size = this.viewer.extents.getSize(new Vector3());
34515
34718
  this.controls.movementSpeed = Math.min(size.x, size.y, size.z) / 2;
34719
+ this.joyStickControls.movementSpeed = this.controls.movementSpeed;
34720
+ this.joyStickControls.multiplier = this.controls.multiplier;
34516
34721
  };
34517
34722
  this.updateControlsCamera = () => {
34518
34723
  this.controls.object = this.viewer.camera;
@@ -34523,8 +34728,10 @@ void main() {
34523
34728
  };
34524
34729
  this.walkspeedChange = (event) => {
34525
34730
  this.viewer.emitEvent(event);
34731
+ this.joyStickControls.multiplier = this.controls.multiplier;
34526
34732
  };
34527
34733
  this.viewerRender = () => {
34734
+ this.joyStickControls.update();
34528
34735
  this.controls.update();
34529
34736
  };
34530
34737
  this.viewerZoom = () => {
@@ -34539,6 +34746,8 @@ void main() {
34539
34746
  this.controls = new WalkControls(viewer.camera, viewer.canvas, meshOnlyGround);
34540
34747
  this.controls.addEventListener("change", this.controlsChange);
34541
34748
  this.controls.addEventListener("walkspeedchange", this.walkspeedChange);
34749
+ this.joyStickControls = new JoyStickControls(viewer.camera, viewer.canvas, viewer.canvas, meshOnlyGround);
34750
+ this.joyStickControls.addEventListener("change", this.controlsChange);
34542
34751
  this.viewer = viewer;
34543
34752
  this.viewer.addEventListener("render", this.viewerRender);
34544
34753
  this.viewer.addEventListener("zoom", this.viewerZoom);
@@ -34552,6 +34761,8 @@ void main() {
34552
34761
  this.controls.removeEventListener("walkspeedchange", this.walkspeedChange);
34553
34762
  this.controls.removeEventListener("change", this.controlsChange);
34554
34763
  this.controls.dispose();
34764
+ this.joyStickControls.removeEventListener("change", this.controlsChange);
34765
+ this.joyStickControls.dispose();
34555
34766
  }
34556
34767
  }
34557
34768
 
@@ -34707,6 +34918,8 @@ void main() {
34707
34918
  this.updateControls = () => {
34708
34919
  const size = this.viewer.extents.getSize(new Vector3());
34709
34920
  this.controls.movementSpeed = Math.min(size.x, size.y, size.z) / 2;
34921
+ this.joyStickControls.movementSpeed = this.controls.movementSpeed;
34922
+ this.joyStickControls.multiplier = this.controls.multiplier;
34710
34923
  };
34711
34924
  this.updateControlsCamera = () => {
34712
34925
  this.controls.object = this.viewer.camera;
@@ -34717,8 +34930,10 @@ void main() {
34717
34930
  };
34718
34931
  this.flyspeedChange = (event) => {
34719
34932
  this.viewer.emitEvent(event);
34933
+ this.joyStickControls.multiplier = this.controls.multiplier;
34720
34934
  };
34721
34935
  this.viewerRender = () => {
34936
+ this.joyStickControls.update();
34722
34937
  this.controls.update();
34723
34938
  };
34724
34939
  this.viewerZoom = () => {
@@ -34727,6 +34942,8 @@ void main() {
34727
34942
  this.controls = new FlyControls(viewer.camera, viewer.canvas);
34728
34943
  this.controls.addEventListener("change", this.controlsChange);
34729
34944
  this.controls.addEventListener("flyspeedchange", this.flyspeedChange);
34945
+ this.joyStickControls = new JoyStickControls(viewer.camera, viewer.canvas, viewer.canvas, []);
34946
+ this.joyStickControls.addEventListener("change", this.controlsChange);
34730
34947
  this.viewer = viewer;
34731
34948
  this.viewer.addEventListener("render", this.viewerRender);
34732
34949
  this.viewer.addEventListener("zoom", this.viewerZoom);
@@ -34740,6 +34957,8 @@ void main() {
34740
34957
  this.controls.removeEventListener("flyspeedchange", this.flyspeedChange);
34741
34958
  this.controls.removeEventListener("change", this.controlsChange);
34742
34959
  this.controls.dispose();
34960
+ this.joyStickControls.removeEventListener("change", this.controlsChange);
34961
+ this.joyStickControls.dispose();
34743
34962
  }
34744
34963
  }
34745
34964
 
@@ -36161,7 +36380,11 @@ void main() {
36161
36380
  Points: { threshold: 0.01 },
36162
36381
  Sprite: {},
36163
36382
  };
36164
- return this.raycaster.intersectObjects(objects, false);
36383
+ let intersects = this.raycaster.intersectObjects(objects, false);
36384
+ (this.viewer.renderer.clippingPlanes || []).forEach((plane) => {
36385
+ intersects = intersects.filter((intersect) => plane.distanceToPoint(intersect.point) >= 0);
36386
+ });
36387
+ return intersects;
36165
36388
  }
36166
36389
  select(objects, model) {
36167
36390
  if (!model) {
@@ -56139,16 +56362,17 @@ void main() {
56139
56362
  this._markupContainer = document.createElement("div");
56140
56363
  this._markupContainer.id = "markup-container";
56141
56364
  this._markupContainer.style.position = "absolute";
56142
- this._markupContainer.style.top = "0px";
56143
- this._markupContainer.style.left = "0px";
56144
56365
  this._markupContainer.style.outline = "0px";
56145
56366
  this._markupContainer.style.pointerEvents = "none";
56146
56367
  const parentDiv = this._container.parentElement;
56147
56368
  parentDiv.appendChild(this._markupContainer);
56148
- if (viewer)
56369
+ if (viewer) {
56149
56370
  this._viewer.addEventListener("resize", this.resizeViewer);
56150
- else
56371
+ }
56372
+ else {
56151
56373
  this._resizeObserver = new ResizeObserver(debounce(this.resizeContainer, 100));
56374
+ this._resizeObserver.observe(parentDiv);
56375
+ }
56152
56376
  this._markupColor.setColor(255, 0, 0);
56153
56377
  this.initializeKonva();
56154
56378
  if (this._viewer) {