Skip to content

Commit

Permalink
Merge pull request #1292 from xeokit/add-entity-to-measurement-endpoints
Browse files Browse the repository at this point in the history
Add entity to measurement endpoints
  • Loading branch information
xeolabs authored Dec 12, 2023
2 parents 97c0672 + 84fc641 commit 85b8f06
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 23 deletions.
22 changes: 17 additions & 5 deletions dist/xeokit-sdk.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12015,7 +12015,7 @@ class AngleMeasurementsMouseControl extends AngleMeasurementsControl {
const cameraControl = this.angleMeasurementsPlugin.viewer.cameraControl;
const pointerLens = this.pointerLens;
let mouseHovering = false;
let mouseHoverEntity = false;
let hoveredEntity = null;
let lastMouseCanvasX = 0;
let lastMouseCanvasY = 0;
const mouseWorldPos = math.vec3();
Expand Down Expand Up @@ -12047,7 +12047,7 @@ class AngleMeasurementsMouseControl extends AngleMeasurementsControl {
}
const canvasPos = event.snappedCanvasPos || event.canvasPos;
mouseHovering = true;
mouseHoverEntity = event.entity;
hoveredEntity = event.entity;
mouseWorldPos.set(event.worldPos);
mouseHoverCanvasPos.set(canvasPos);
switch (this._mouseState) {
Expand All @@ -12062,6 +12062,7 @@ class AngleMeasurementsMouseControl extends AngleMeasurementsControl {
this._currentAngleMeasurement.cornerVisible = true;
this._currentAngleMeasurement.angleVisible = false;
this._currentAngleMeasurement.corner.worldPos = event.worldPos;
this._currentAngleMeasurement.corner.entity = event.entity;
}
this.markerDiv.style.marginLeft = `-10000px`;
this.markerDiv.style.marginTop = `-10000px`;
Expand All @@ -12073,6 +12074,7 @@ class AngleMeasurementsMouseControl extends AngleMeasurementsControl {
this._currentAngleMeasurement.targetVisible = true;
this._currentAngleMeasurement.angleVisible = true;
this._currentAngleMeasurement.target.worldPos = event.worldPos;
this._currentAngleMeasurement.target.entity = event.entity;
}
this.markerDiv.style.marginLeft = `-10000px`;
this.markerDiv.style.marginTop = `-10000px`;
Expand Down Expand Up @@ -12103,15 +12105,12 @@ class AngleMeasurementsMouseControl extends AngleMeasurementsControl {
this._currentAngleMeasurement = this.angleMeasurementsPlugin.createMeasurement({
id: math.createUUID(),
origin: {
entity: mouseHoverEntity,
worldPos: mouseWorldPos
},
corner: {
entity: mouseHoverEntity,
worldPos: mouseWorldPos
},
target: {
entity: mouseHoverEntity,
worldPos: mouseWorldPos
},
approximate: true
Expand All @@ -12123,6 +12122,7 @@ class AngleMeasurementsMouseControl extends AngleMeasurementsControl {
this._currentAngleMeasurement.targetWireVisible = false;
this._currentAngleMeasurement.targetVisible = false;
this._currentAngleMeasurement.angleVisible = false;
this._currentAngleMeasurement.origin.entity = hoveredEntity;
this._mouseState = MOUSE_FINDING_CORNER;
this.angleMeasurementsPlugin.fire("measurementStart", this._currentAngleMeasurement);
}
Expand All @@ -12132,11 +12132,13 @@ class AngleMeasurementsMouseControl extends AngleMeasurementsControl {
this._currentAngleMeasurement.targetWireVisible = false;
this._currentAngleMeasurement.targetVisible = true;
this._currentAngleMeasurement.angleVisible = true;
this._currentAngleMeasurement.corner.entity = hoveredEntity;
this._mouseState = MOUSE_FINDING_TARGET;
} else {
if (this._currentAngleMeasurement) {
this._currentAngleMeasurement.destroy();
this._currentAngleMeasurement = null;
hoveredEntity = null;
this._mouseState = MOUSE_FINDING_ORIGIN;
this.angleMeasurementsPlugin.fire("measurementCancel", this._currentAngleMeasurement);
}
Expand All @@ -12146,14 +12148,17 @@ class AngleMeasurementsMouseControl extends AngleMeasurementsControl {
if (mouseHovering) {
this._currentAngleMeasurement.targetVisible = true;
this._currentAngleMeasurement.angleVisible = true;
this._currentAngleMeasurement.target.entity = hoveredEntity;
this._currentAngleMeasurement.clickable = true;
hoveredEntity = null;
this.angleMeasurementsPlugin.fire("measurementEnd", this._currentAngleMeasurement);
this._currentAngleMeasurement = null;
this._mouseState = MOUSE_FINDING_ORIGIN;
} else {
if (this._currentAngleMeasurement) {
this._currentAngleMeasurement.destroy();
this._currentAngleMeasurement = null;
hoveredEntity = null;
this._mouseState = MOUSE_FINDING_ORIGIN;
this.angleMeasurementsPlugin.fire("measurementCancel", this._currentAngleMeasurement);
}
Expand Down Expand Up @@ -50120,6 +50125,7 @@ class DistanceMeasurementsMouseControl extends DistanceMeasurementsControl {
let pointerDownCanvasX;
let pointerDownCanvasY;
const clickTolerance = 20;
let hoveredEntity = null;

this._mouseState = MOUSE_FIRST_CLICK_EXPECTED;

Expand Down Expand Up @@ -50154,6 +50160,7 @@ class DistanceMeasurementsMouseControl extends DistanceMeasurementsControl {
this._markerDiv.style.background = "pink";
this._markerDiv.style.border = "2px solid red";
}
hoveredEntity = event.entity;
} else {
this._markerDiv.style.marginLeft = `-10000px`;
this._markerDiv.style.marginTop = `-10000px`;
Expand Down Expand Up @@ -50192,13 +50199,16 @@ class DistanceMeasurementsMouseControl extends DistanceMeasurementsControl {
}
if (this._currentDistanceMeasurement) {
if (mouseHovering) {
this._currentDistanceMeasurement.target.entity = hoveredEntity;
hoveredEntity = null;
this._currentDistanceMeasurement.clickable = true;
this.distanceMeasurementsPlugin.fire("measurementEnd", this._currentDistanceMeasurement);
this._currentDistanceMeasurement = null;
} else {
this._currentDistanceMeasurement.destroy();
this.distanceMeasurementsPlugin.fire("measurementCancel", this._currentDistanceMeasurement);
this._currentDistanceMeasurement = null;
hoveredEntity = null;
}
} else {
if (mouseHovering) {
Expand All @@ -50219,6 +50229,8 @@ class DistanceMeasurementsMouseControl extends DistanceMeasurementsControl {
this._currentDistanceMeasurementInitState.wireVisible = this._currentDistanceMeasurement.wireVisible;
this._currentDistanceMeasurementInitState.targetVisible = this._currentDistanceMeasurement.targetVisible;
this._currentDistanceMeasurement.clickable = false;
this._currentDistanceMeasurement.origin.entity = hoveredEntity;
hoveredEntity = null;
this.fire("measurementStart", this._currentDistanceMeasurement);
}
}
Expand Down
22 changes: 17 additions & 5 deletions dist/xeokit-sdk.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -12011,7 +12011,7 @@ class AngleMeasurementsMouseControl extends AngleMeasurementsControl {
const cameraControl = this.angleMeasurementsPlugin.viewer.cameraControl;
const pointerLens = this.pointerLens;
let mouseHovering = false;
let mouseHoverEntity = false;
let hoveredEntity = null;
let lastMouseCanvasX = 0;
let lastMouseCanvasY = 0;
const mouseWorldPos = math.vec3();
Expand Down Expand Up @@ -12043,7 +12043,7 @@ class AngleMeasurementsMouseControl extends AngleMeasurementsControl {
}
const canvasPos = event.snappedCanvasPos || event.canvasPos;
mouseHovering = true;
mouseHoverEntity = event.entity;
hoveredEntity = event.entity;
mouseWorldPos.set(event.worldPos);
mouseHoverCanvasPos.set(canvasPos);
switch (this._mouseState) {
Expand All @@ -12058,6 +12058,7 @@ class AngleMeasurementsMouseControl extends AngleMeasurementsControl {
this._currentAngleMeasurement.cornerVisible = true;
this._currentAngleMeasurement.angleVisible = false;
this._currentAngleMeasurement.corner.worldPos = event.worldPos;
this._currentAngleMeasurement.corner.entity = event.entity;
}
this.markerDiv.style.marginLeft = `-10000px`;
this.markerDiv.style.marginTop = `-10000px`;
Expand All @@ -12069,6 +12070,7 @@ class AngleMeasurementsMouseControl extends AngleMeasurementsControl {
this._currentAngleMeasurement.targetVisible = true;
this._currentAngleMeasurement.angleVisible = true;
this._currentAngleMeasurement.target.worldPos = event.worldPos;
this._currentAngleMeasurement.target.entity = event.entity;
}
this.markerDiv.style.marginLeft = `-10000px`;
this.markerDiv.style.marginTop = `-10000px`;
Expand Down Expand Up @@ -12099,15 +12101,12 @@ class AngleMeasurementsMouseControl extends AngleMeasurementsControl {
this._currentAngleMeasurement = this.angleMeasurementsPlugin.createMeasurement({
id: math.createUUID(),
origin: {
entity: mouseHoverEntity,
worldPos: mouseWorldPos
},
corner: {
entity: mouseHoverEntity,
worldPos: mouseWorldPos
},
target: {
entity: mouseHoverEntity,
worldPos: mouseWorldPos
},
approximate: true
Expand All @@ -12119,6 +12118,7 @@ class AngleMeasurementsMouseControl extends AngleMeasurementsControl {
this._currentAngleMeasurement.targetWireVisible = false;
this._currentAngleMeasurement.targetVisible = false;
this._currentAngleMeasurement.angleVisible = false;
this._currentAngleMeasurement.origin.entity = hoveredEntity;
this._mouseState = MOUSE_FINDING_CORNER;
this.angleMeasurementsPlugin.fire("measurementStart", this._currentAngleMeasurement);
}
Expand All @@ -12128,11 +12128,13 @@ class AngleMeasurementsMouseControl extends AngleMeasurementsControl {
this._currentAngleMeasurement.targetWireVisible = false;
this._currentAngleMeasurement.targetVisible = true;
this._currentAngleMeasurement.angleVisible = true;
this._currentAngleMeasurement.corner.entity = hoveredEntity;
this._mouseState = MOUSE_FINDING_TARGET;
} else {
if (this._currentAngleMeasurement) {
this._currentAngleMeasurement.destroy();
this._currentAngleMeasurement = null;
hoveredEntity = null;
this._mouseState = MOUSE_FINDING_ORIGIN;
this.angleMeasurementsPlugin.fire("measurementCancel", this._currentAngleMeasurement);
}
Expand All @@ -12142,14 +12144,17 @@ class AngleMeasurementsMouseControl extends AngleMeasurementsControl {
if (mouseHovering) {
this._currentAngleMeasurement.targetVisible = true;
this._currentAngleMeasurement.angleVisible = true;
this._currentAngleMeasurement.target.entity = hoveredEntity;
this._currentAngleMeasurement.clickable = true;
hoveredEntity = null;
this.angleMeasurementsPlugin.fire("measurementEnd", this._currentAngleMeasurement);
this._currentAngleMeasurement = null;
this._mouseState = MOUSE_FINDING_ORIGIN;
} else {
if (this._currentAngleMeasurement) {
this._currentAngleMeasurement.destroy();
this._currentAngleMeasurement = null;
hoveredEntity = null;
this._mouseState = MOUSE_FINDING_ORIGIN;
this.angleMeasurementsPlugin.fire("measurementCancel", this._currentAngleMeasurement);
}
Expand Down Expand Up @@ -50116,6 +50121,7 @@ class DistanceMeasurementsMouseControl extends DistanceMeasurementsControl {
let pointerDownCanvasX;
let pointerDownCanvasY;
const clickTolerance = 20;
let hoveredEntity = null;

this._mouseState = MOUSE_FIRST_CLICK_EXPECTED;

Expand Down Expand Up @@ -50150,6 +50156,7 @@ class DistanceMeasurementsMouseControl extends DistanceMeasurementsControl {
this._markerDiv.style.background = "pink";
this._markerDiv.style.border = "2px solid red";
}
hoveredEntity = event.entity;
} else {
this._markerDiv.style.marginLeft = `-10000px`;
this._markerDiv.style.marginTop = `-10000px`;
Expand Down Expand Up @@ -50188,13 +50195,16 @@ class DistanceMeasurementsMouseControl extends DistanceMeasurementsControl {
}
if (this._currentDistanceMeasurement) {
if (mouseHovering) {
this._currentDistanceMeasurement.target.entity = hoveredEntity;
hoveredEntity = null;
this._currentDistanceMeasurement.clickable = true;
this.distanceMeasurementsPlugin.fire("measurementEnd", this._currentDistanceMeasurement);
this._currentDistanceMeasurement = null;
} else {
this._currentDistanceMeasurement.destroy();
this.distanceMeasurementsPlugin.fire("measurementCancel", this._currentDistanceMeasurement);
this._currentDistanceMeasurement = null;
hoveredEntity = null;
}
} else {
if (mouseHovering) {
Expand All @@ -50215,6 +50225,8 @@ class DistanceMeasurementsMouseControl extends DistanceMeasurementsControl {
this._currentDistanceMeasurementInitState.wireVisible = this._currentDistanceMeasurement.wireVisible;
this._currentDistanceMeasurementInitState.targetVisible = this._currentDistanceMeasurement.targetVisible;
this._currentDistanceMeasurement.clickable = false;
this._currentDistanceMeasurement.origin.entity = hoveredEntity;
hoveredEntity = null;
this.fire("measurementStart", this._currentDistanceMeasurement);
}
}
Expand Down
Loading

0 comments on commit 85b8f06

Please sign in to comment.