Skip to content

Commit f13a060

Browse files
valentinMachadomgermerie
authored andcommitted
feat(planarcontrols) : add enabled attribute
1 parent ca77fc8 commit f13a060

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/Controls/PlanarControls.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ const plane = new THREE.Plane(
9090

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

178+
// Set to false to disable this control
179+
this.enabled = typeof options.enabled == 'boolean' ? options.enabled : defaultOptions.enabled;
180+
176181
if (this.camera.isOrthographicCamera) {
177182
cameraInitialZoom = this.camera.zoom;
178183

@@ -969,6 +974,10 @@ class PlanarControls extends THREE.EventDispatcher {
969974
* @ignore
970975
*/
971976
onMouseDown(event) {
977+
if (!this.enabled) {
978+
return;
979+
}
980+
972981
event.preventDefault();
973982

974983
this.view.domElement.focus();
@@ -1036,6 +1045,10 @@ class PlanarControls extends THREE.EventDispatcher {
10361045
* @ignore
10371046
*/
10381047
onMouseMove(event) {
1048+
if (!this.enabled) {
1049+
return;
1050+
}
1051+
10391052
event.preventDefault();
10401053

10411054
this.updateMousePositionAndDelta(event);
@@ -1053,7 +1066,7 @@ class PlanarControls extends THREE.EventDispatcher {
10531066
* @ignore
10541067
*/
10551068
onKeyDown(event) {
1056-
if (STATE.NONE !== this.state) {
1069+
if (STATE.NONE !== this.state || !this.enabled) {
10571070
return;
10581071
}
10591072
switch (event.keyCode) {
@@ -1083,6 +1096,10 @@ class PlanarControls extends THREE.EventDispatcher {
10831096
* @ignore
10841097
*/
10851098
onMouseWheel(event) {
1099+
if (!this.enabled) {
1100+
return;
1101+
}
1102+
10861103
event.preventDefault();
10871104
event.stopPropagation();
10881105

0 commit comments

Comments
 (0)