Skip to content

Commit 54db1a1

Browse files
committed
Set default colors to match theme in controls
1 parent 01698c8 commit 54db1a1

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

src/controls.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { GUI } from "dat.gui";
2+
import { Color } from "three";
23

34
interface Joints {
45
[name: string]: {
@@ -70,12 +71,13 @@ export class URDFControls extends GUI {
7071
}
7172

7273
createSceneControls(
73-
bgColor = [38, 50, 56],
74-
gridColor = [54, 66, 72]
74+
bgColor = new Color(0x263238),
75+
gridColor = new Color(0x263238)
7576
) {
77+
7678
const sceneSettings = {
77-
'Background': bgColor,
78-
'Grid': gridColor,
79+
'Background': this._convertColor2Array(bgColor),
80+
'Grid': this._convertColor2Array(gridColor),
7981
'Height': 0
8082
};
8183

@@ -92,6 +94,18 @@ export class URDFControls extends GUI {
9294
return this.controls.scene;
9395
}
9496

97+
private _convertColor2Array(color: THREE.Color): number[] {
98+
// Note: using hex value instead of the RGB values in Color because
99+
// those are dependant on the color space
100+
const hexColor = color.getHexString();
101+
const colorArray = [
102+
parseInt(hexColor.slice(0,2), 16),
103+
parseInt(hexColor.slice(2,4), 16),
104+
parseInt(hexColor.slice(4,6), 16)
105+
]
106+
return colorArray;
107+
}
108+
95109
createJointControls(joints: Joints) {
96110
Object.keys(joints).forEach((name: string) => {
97111
// Skip joints which should not be moved

src/layout.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import { XacroLoader } from 'xacro-parser';
2020
import { URDFControls } from './controls';
2121
import { URDFRenderer } from './renderer';
2222

23+
interface URDFColors {
24+
sky: Color,
25+
ground: Color
26+
}
2327

2428
/**
2529
* A URDF layout to host the URDF viewer
@@ -29,6 +33,7 @@ export class URDFLayout extends PanelLayout {
2933
private _robotModel: any = null;
3034
private _controlsPanel: URDFControls;
3135
private _renderer: URDFRenderer;
36+
private _colors: URDFColors;
3237
private _manager: LoadingManager;
3338
private _loader: URDFLoader;
3439
private _workingPath: string;
@@ -44,12 +49,14 @@ export class URDFLayout extends PanelLayout {
4449
// output area to render execution replies
4550
this._host = document.createElement('div');
4651

52+
this._colors = {
53+
sky: this._getThemeColor('--jp-layout-color1') || new Color(0x263238),
54+
ground: this._getThemeColor('--jp-layout-color2') || new Color(0x263238)
55+
};
56+
57+
this._renderer = new URDFRenderer(this._colors.sky, this._colors.ground);
4758
this._controlsPanel = new URDFControls();
4859

49-
const colorSky = this._getThemeColor('--jp-layout-color1') || new Color(0x263238);
50-
const colorGround = this._getThemeColor('--jp-layout-color2') || new Color(0x263238);
51-
this._renderer = new URDFRenderer(colorSky, colorGround);
52-
5360
this._urdfString = '';
5461
this._workingPath = '';
5562
this._manager = new LoadingManager;
@@ -207,7 +214,8 @@ export class URDFLayout extends PanelLayout {
207214
* Call renderer when scene colors are changed in the controls panel.
208215
*/
209216
private _setSceneControls(): void {
210-
const sceneControl = this._controlsPanel.createSceneControls();
217+
const sceneControl = this._controlsPanel.createSceneControls(
218+
this._colors.sky, this._colors.ground);
211219
sceneControl.background.onChange(
212220
(newColor: number[]) => this._renderer.setSkyColor(newColor));
213221
sceneControl.grid.onChange(

0 commit comments

Comments
 (0)