xeokit-bim-viewer
xeokit-bim-viewer copied to clipboard
Distinct between left- and right-mouse-button click in SectionTool.js
The SectionTool binds "mouseclicked" event and recieves the x/y coords to display the section-control-utility.
When left-mouse-button is clicked:
Unfortunately it also displays the section-control-utility AND the context menu when right-mouse-button is clicked:
From a UX perspective this behaviour is not ideal. Either the section-control-utility OR the context menu should appear. To achieve this it is necessary to distinct between these two different clicks like:
switch (event.which) {
case 1:
alert('Left Mouse button pressed.');
break;
case 2:
alert('Middle Mouse button pressed.');
break;
case 3:
alert('Right Mouse button pressed.');
break;
default:
alert('You have a strange Mouse!');
}
Unfortunately the "mouseclicked" event does not deliver the originating event to distinguish these cases (https://github.com/xeokit/xeokit-bim-viewer/blob/master/src/toolbar/SectionTool.js#L143).
_initSectionMode() {
this.viewer.scene.input.on("mouseclicked", (coords) => {
if (!this.getActive() || !this.getEnabled()) {
return;
}
const pickResult = this.viewer.scene.pick({
canvasPos: coords,
pickSurface: true // <<------ This causes picking to find the intersection point on the entity
});
if (pickResult) {
const sectionPlane = this._sectionPlanesPlugin.createSectionPlane({
pos: pickResult.worldPos,
dir: math.mulVec3Scalar(pickResult.worldNormal, -1)
});
sectionPlane.on("destroyed", () => {
this._updateSectionPlanesCount();
});
this._sectionPlanesPlugin.showControl(sectionPlane.id);
this._updateSectionPlanesCount();
}
});
Is there a way to distinct between left and right-mouse-button click in _initSectionMode()?
I suspect this probably needs to be changed in https://github.com/xeokit/xeokit-sdk... Any suggestions are welcome.