Skip to content

Commit 08d04e7

Browse files
committed
add orbit controls
1 parent d561a7d commit 08d04e7

File tree

3 files changed

+108
-1
lines changed

3 files changed

+108
-1
lines changed

src/controls.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ interface IJoints {
1313
* the robot joints
1414
*/
1515
export class URDFControls extends GUI {
16+
private _orbitControlsFolder: any;
1617
private _workspaceFolder: any;
1718
private _sceneFolder: any;
1819
private _jointsFolder: any;
1920
private _jointsEditorFolder: any;
2021
private _workingPath = '';
2122

2223
controls: any = {
24+
orbitControls: {},
2325
path: {},
2426
scene: {
2527
background: {},
@@ -59,6 +61,9 @@ export class URDFControls extends GUI {
5961
'dg editor-folder'
6062
);
6163

64+
this._orbitControlsFolder = this.addFolder('Orbit Controls');
65+
this._orbitControlsFolder.domElement.setAttribute('class', 'dg camera-folder');
66+
6267
this._workspaceFolder = this.addFolder('Workspace');
6368
this._workspaceFolder.domElement.setAttribute(
6469
'class',
@@ -129,6 +134,51 @@ export class URDFControls extends GUI {
129134
});
130135
}
131136

137+
/**
138+
* Creates controls for panSpeed, zoomSpeed, rotateSpeed
139+
*
140+
* @returns - The controls to trigger callbacks when settings change
141+
*/
142+
createOrbitControls() {
143+
if (this._isEmpty(this.controls.orbitControls)) {
144+
const orbitControlSettings = {
145+
panSpeed: 2,
146+
zoomSpeed: 1,
147+
rotateSpeed: 2
148+
};
149+
150+
const minValue = 0.1;
151+
const maxValue = 5;
152+
this.controls.orbitControls = {
153+
panSpeed: this._orbitControlsFolder.add(
154+
orbitControlSettings,
155+
'panSpeed',
156+
minValue,
157+
maxValue
158+
),
159+
zoomSpeed: this._orbitControlsFolder.add(
160+
orbitControlSettings,
161+
'zoomSpeed',
162+
minValue,
163+
maxValue
164+
),
165+
rotateSpeed: this._orbitControlsFolder.add(
166+
orbitControlSettings,
167+
'rotateSpeed',
168+
minValue,
169+
maxValue
170+
)
171+
};
172+
173+
this._enforceNumericInput(this.controls.orbitControls.panSpeed);
174+
this._enforceNumericInput(this.controls.orbitControls.zoomSpeed);
175+
this._enforceNumericInput(this.controls.orbitControls.rotateSpeed);
176+
177+
this._orbitControlsFolder.open()
178+
}
179+
return this.controls.orbitControls;
180+
}
181+
132182
/**
133183
* Creates an input box and a button to modify the working path
134184
*

src/layout.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,34 @@ export class URDFLayout extends PanelLayout {
181181
return;
182182
}
183183

184+
this._setOrbitControls();
184185
this._setPathControls();
185186
this._setSceneControls();
186187
this._setJointControls();
187188
this._setLightControls();
188189
this._setEditorControls();
189190
}
190191

192+
/**
193+
* Set OrbitControls for panSpeed, zoomSpeed, rotateSpeed
194+
* render again.
195+
*/
196+
private _setOrbitControls(): void {
197+
const orbitControls = this._controlsPanel.createOrbitControls();
198+
199+
orbitControls.panSpeed.onChange((newPanSpeed: number) => {
200+
this._renderer.setOrbitControlsPanSpeed(newPanSpeed);
201+
});
202+
203+
orbitControls.zoomSpeed.onChange((newZoomSpeed: number) => {
204+
this._renderer.setOrbitControlsZoomSpeed(newZoomSpeed);
205+
});
206+
207+
orbitControls.rotateSpeed.onChange((newRotateSpeed: number) => {
208+
this._renderer.setOrbitControlsRotateSpeed(newRotateSpeed);
209+
});
210+
}
211+
191212
/**
192213
* Set callback for changing working directory to given user input and
193214
* render again.

src/renderer.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class URDFRenderer extends THREE.WebGLRenderer {
8080
*/
8181
private _initControls(): void {
8282
this._controls.rotateSpeed = 2.0;
83-
this._controls.zoomSpeed = 5;
83+
this._controls.zoomSpeed = 1;
8484
this._controls.panSpeed = 2;
8585
this._controls.enableZoom = true;
8686
this._controls.enableDamping = false;
@@ -448,6 +448,42 @@ export class URDFRenderer extends THREE.WebGLRenderer {
448448
}
449449
}
450450

451+
/**
452+
* Updates the OrbitControl's speed of panning
453+
*
454+
* @param newPanSpeed - Speed of panning
455+
*/
456+
setOrbitControlsPanSpeed(
457+
newPanSpeed: number,
458+
): void {
459+
this._controls.panSpeed = newPanSpeed;
460+
this.redraw();
461+
}
462+
463+
/**
464+
* Updates the OrbitControl's speed of panning
465+
*
466+
* @param newZoomSpeed - Speed of zooming
467+
*/
468+
setOrbitControlsZoomSpeed(
469+
newZoomSpeed: number,
470+
): void {
471+
this._controls.zoomSpeed = newZoomSpeed;
472+
this.redraw();
473+
}
474+
475+
/**
476+
* Updates the OrbitControl's speed of panning
477+
*
478+
* @param newRotateSpeed - Speed of panning
479+
*/
480+
setOrbitControlsRotateSpeed(
481+
newRotateSpeed: number,
482+
): void {
483+
this._controls.rotateSpeed = newRotateSpeed;
484+
this.redraw();
485+
}
486+
451487
/**
452488
* Refreshes the viewer by re-rendering the scene and its elements
453489
*/

0 commit comments

Comments
 (0)