Skip to content

Issue controls panel UI #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions src/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ export class URDFControls extends GUI {
this.domElement.style.right = '5px';
this.domElement.setAttribute('class', 'dg main urdf-gui');

// Add resize functionality
this._setupResizeHandling({
minWidth: 150,
maxWidth: 500,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better to not restrict the max width. If the user wants the gui to occupy the full width of the window, that should be possible and it might be useful for extra long joint names.

grabZoneWidth: 12
});

// Create folders
this._workspaceFolder = this.addFolder('Workspace');
this._workspaceFolder.domElement.setAttribute(
'class',
Expand Down Expand Up @@ -207,4 +215,54 @@ export class URDFControls extends GUI {
}
return this.controls.joints;
}

/**
* Sets up panel resizing functionality
* @param minWidth - Minimum width of the panel
* @param maxWidth - Maximum width of the panel
* @param grabZoneWidth - Width of the area where the mouse can be clicked
*/
private _setupResizeHandling(options: {
minWidth: number;
maxWidth: number;
grabZoneWidth: number;
}): void {
let isResizing = false;
let startX: number;
let startWidth: number;

const { minWidth, maxWidth, grabZoneWidth } = options;

const onMouseMove = (e: MouseEvent) => {
if (!isResizing) {
return;
}

const width = startWidth - (e.clientX - startX);
if (width >= minWidth && width <= maxWidth) {
this.domElement.style.width = `${width}px`;
}
};

const onMouseUp = () => {
isResizing = false;
document.removeEventListener('mousemove', onMouseMove);
document.removeEventListener('mouseup', onMouseUp);
};

this.domElement.addEventListener('mousedown', (e: MouseEvent) => {
if (
e.clientX <
this.domElement.getBoundingClientRect().left + grabZoneWidth
) {
isResizing = true;
startX = e.clientX;
startWidth = parseInt(getComputedStyle(this.domElement).width, 10);
e.preventDefault();

document.addEventListener('mousemove', onMouseMove);
document.addEventListener('mouseup', onMouseUp);
}
});
}
}
10 changes: 5 additions & 5 deletions src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class URDFRenderer extends THREE.WebGLRenderer {
* Adds three lights to the scene
*/
private _addLights(): void {
const directionalLight = new THREE.DirectionalLight(0xffffff, 1.0);
const directionalLight = new THREE.DirectionalLight(0xff0000, 1.0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes to the lighting are not related to what this PR is trying to fix. These changes should be moved to a separate PR.

directionalLight.castShadow = true;
directionalLight.position.set(3, 10, 3);
directionalLight.shadow.camera.top = 2;
Expand All @@ -132,12 +132,12 @@ export class URDFRenderer extends THREE.WebGLRenderer {
directionalLight.shadow.camera.right = 2;
directionalLight.shadow.camera.near = 0.1;
directionalLight.shadow.camera.far = 40;
this._scene.add(directionalLight);
//this._scene.add(directionalLight);

const ambientLight = new THREE.AmbientLight('#fff');
ambientLight.intensity = 0.5;
const ambientLight = new THREE.AmbientLight('#ff0000');
ambientLight.intensity = 1;
ambientLight.position.set(0, 5, 0);
this._scene.add(ambientLight);
//this._scene.add(ambientLight);

const hemisphereLight = new THREE.HemisphereLight(
this._colorSky,
Expand Down
19 changes: 19 additions & 0 deletions style/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@
color: var(--gui-color-font);
border: none;
box-sizing: border-box;
min-width: 150px;
max-width: 500px;
padding-bottom: 20px;
}

/* Add a resize handle on the left border */
.urdf-gui::before {
content: '';
position: absolute;
width: 12px;
height: 100%;
cursor: ew-resize;
}

.urdf-gui li.folder {
Expand Down Expand Up @@ -128,3 +140,10 @@
max-height: 50vh;
overflow: scroll;
}

/* Style for Dat.GUI's close button */
.urdf-gui .close-button {
width: 100% !important;
color: white !important;
position: absolute;
}
Loading