Skip to content

Commit

Permalink
feat(planarcontrols) : add enabled attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinMachado authored and mgermerie committed Apr 14, 2023
1 parent ca77fc8 commit f13a060
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Controls/PlanarControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const plane = new THREE.Plane(

// default parameters :
const defaultOptions = {
enabled: true,
enableRotation: true,
rotateSpeed: 2.0,
minPanSpeed: 0.05,
Expand Down Expand Up @@ -134,6 +135,7 @@ export const PLANAR_CONTROL_EVENT = {
* @class PlanarControls
* @param {PlanarView} view the view where the controls will be used
* @param {object} options
* @param {boolean} [options.enabled=true] Set to false to disable this control
* @param {boolean} [options.enableRotation=true] Enable the rotation with the `CTRL + Left mouse button`
* and in animations, like the smart zoom.
* @param {boolean} [options.enableSmartTravel=true] Enable smart travel with the `wheel-click / space-bar`.
Expand Down Expand Up @@ -173,6 +175,9 @@ class PlanarControls extends THREE.EventDispatcher {
this.view = view;
this.camera = view.camera.camera3D;

// Set to false to disable this control
this.enabled = typeof options.enabled == 'boolean' ? options.enabled : defaultOptions.enabled;

if (this.camera.isOrthographicCamera) {
cameraInitialZoom = this.camera.zoom;

Expand Down Expand Up @@ -969,6 +974,10 @@ class PlanarControls extends THREE.EventDispatcher {
* @ignore
*/
onMouseDown(event) {
if (!this.enabled) {
return;
}

event.preventDefault();

this.view.domElement.focus();
Expand Down Expand Up @@ -1036,6 +1045,10 @@ class PlanarControls extends THREE.EventDispatcher {
* @ignore
*/
onMouseMove(event) {
if (!this.enabled) {
return;
}

event.preventDefault();

this.updateMousePositionAndDelta(event);
Expand All @@ -1053,7 +1066,7 @@ class PlanarControls extends THREE.EventDispatcher {
* @ignore
*/
onKeyDown(event) {
if (STATE.NONE !== this.state) {
if (STATE.NONE !== this.state || !this.enabled) {
return;
}
switch (event.keyCode) {
Expand Down Expand Up @@ -1083,6 +1096,10 @@ class PlanarControls extends THREE.EventDispatcher {
* @ignore
*/
onMouseWheel(event) {
if (!this.enabled) {
return;
}

event.preventDefault();
event.stopPropagation();

Expand Down

0 comments on commit f13a060

Please sign in to comment.