Skip to content

Commit caab092

Browse files
committed
Improve lighting
1 parent 1445894 commit caab092

File tree

3 files changed

+35
-41
lines changed

3 files changed

+35
-41
lines changed

src/controls.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -287,16 +287,15 @@ export class URDFControls extends GUI {
287287
this._lightsFolder.addFolder('Directional Light');
288288
const ambientFolder = this._lightsFolder.addFolder('Ambient Light');
289289
const hemisphereFolder = this._lightsFolder.addFolder('Hemisphere Light');
290-
const helpersFolder = this._lightsFolder.addFolder('Light Helpers');
291290

292291
// Initialize settings for each light type
293292
const directionalSettings = {
294-
// Spherical coordinates are more intuitive for light positioning
295293
Distance: 10.9, // Initial distance from origin
296294
Altitude: Math.PI / 4, // Initial altitude angle (radians)
297295
Azimuth: Math.PI / 4, // Initial azimuth angle (radians)
298296
Color: [255, 255, 255],
299297
Intensity: 1.0,
298+
ShowHelper: false,
300299
// Adding target controls
301300
Target: {
302301
X: 0,
@@ -312,13 +311,9 @@ export class URDFControls extends GUI {
312311

313312
const hemisphereSettings = {
314313
SkyColor: [255, 255, 255],
315-
GroundColor: [38, 50, 56], // Default hex: #263238
316-
Intensity: 1.0
317-
};
318-
319-
const helperSettings = {
320-
DirectionalHelper: true,
321-
HemisphereHelper: true
314+
GroundColor: [38, 50, 56],
315+
Intensity: 1.0,
316+
ShowHelper: false // Helper toggle moved here, off by default
322317
};
323318

324319
// Position limits and steps
@@ -396,7 +391,8 @@ export class URDFControls extends GUI {
396391
minIntensity,
397392
maxIntensity,
398393
intensityStep
399-
)
394+
),
395+
showHelper: directionalFolder.add(directionalSettings, 'ShowHelper')
400396
};
401397

402398
// Ambient light controls
@@ -424,16 +420,8 @@ export class URDFControls extends GUI {
424420
minIntensity,
425421
maxIntensity,
426422
intensityStep
427-
)
428-
};
429-
430-
// Light helpers controls
431-
this.controls.lights.helpers = {
432-
directionalHelper: helpersFolder.add(
433-
helperSettings,
434-
'DirectionalHelper'
435423
),
436-
hemisphereHelper: helpersFolder.add(helperSettings, 'HemisphereHelper')
424+
showHelper: hemisphereFolder.add(hemisphereSettings, 'ShowHelper')
437425
};
438426

439427
// Open main lights folder and directional subfolder

src/layout.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,11 @@ export class URDFLayout extends PanelLayout {
283283
this._renderer.setDirectionalLightIntensity(newIntensity);
284284
});
285285

286-
// Light helper visibility toggles
287-
lightControl.helpers.directionalHelper.onChange((visible: boolean) => {
286+
// Helper visibility toggle for directional light
287+
directional.showHelper.onChange((visible: boolean) => {
288288
this._renderer.setDirectionalLightHelperVisibility(visible);
289289
});
290290

291-
lightControl.helpers.hemisphereHelper.onChange((visible: boolean) => {
292-
this._renderer.setHemisphereLightHelperVisibility(visible);
293-
});
294-
295291
// Ambient light callbacks
296292
const ambient = lightControl.ambient;
297293

@@ -317,6 +313,11 @@ export class URDFLayout extends PanelLayout {
317313
hemisphere.intensity.onChange((newIntensity: number) => {
318314
this._renderer.setHemisphereLightIntensity(newIntensity);
319315
});
316+
317+
// Helper visibility toggle for hemisphere light
318+
hemisphere.showHelper.onChange((visible: boolean) => {
319+
this._renderer.setHemisphereLightHelperVisibility(visible);
320+
});
320321
}
321322

322323
/**

src/renderer.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -134,43 +134,48 @@ export class URDFRenderer extends THREE.WebGLRenderer {
134134
* Adds three lights to the scene
135135
*/
136136
private _addLights(): void {
137-
const directionalLight = new THREE.DirectionalLight(0xffffff, 1.0);
137+
// Directional light
138+
const directionalLight = new THREE.DirectionalLight(0xfff2cc, 1.8);
138139
directionalLight.castShadow = true;
139-
directionalLight.position.set(3, 10, 3);
140-
directionalLight.shadow.camera.top = 2;
141-
directionalLight.shadow.camera.bottom = -2;
142-
directionalLight.shadow.camera.left = -2;
143-
directionalLight.shadow.camera.right = 2;
144-
directionalLight.shadow.camera.near = 0.1;
145-
directionalLight.shadow.camera.far = 40;
140+
directionalLight.position.set(5, 12, 6);
141+
directionalLight.shadow.camera.top = 5;
142+
directionalLight.shadow.camera.bottom = -5;
143+
directionalLight.shadow.camera.left = -5;
144+
directionalLight.shadow.camera.right = 5;
145+
directionalLight.shadow.camera.near = 0.5;
146+
directionalLight.shadow.camera.far = 50;
146147
this._scene.add(directionalLight);
147148

148-
// Add a helper for the directional light
149+
// Directional light helper
149150
this._directionalLightHelper = new THREE.DirectionalLightHelper(
150151
directionalLight,
151152
2,
152153
new THREE.Color(0x000000)
153154
);
155+
this._directionalLightHelper.visible = false;
154156
this._scene.add(this._directionalLightHelper);
155157

156-
const ambientLight = new THREE.AmbientLight('#fff');
157-
ambientLight.intensity = 0.5;
158+
// Ambient light
159+
const ambientLight = new THREE.AmbientLight(0x404040);
160+
ambientLight.intensity = 0.1;
158161
ambientLight.position.set(0, 5, 0);
159162
this._scene.add(ambientLight);
160163

164+
// Hemisphere light
161165
const hemisphereLight = new THREE.HemisphereLight(
162-
this._colorSky,
163-
this._colorGround
166+
0x8888ff, // cool sky
167+
0x442200, // warm ground
168+
0.4
164169
);
165-
hemisphereLight.intensity = 1;
166170
this._scene.add(hemisphereLight);
167171

168-
// Add a helper for the hemisphere light
172+
// Hemisphere light helper
169173
this._hemisphereLightHelper = new THREE.HemisphereLightHelper(
170174
hemisphereLight,
171175
2
172176
);
173-
this._hemisphereLightHelper.material.color.set(0x000000); // Black color for helper
177+
this._hemisphereLightHelper.material.color.set(0x000000);
178+
this._hemisphereLightHelper.visible = false; // Set to hidden by default
174179
this._scene.add(this._hemisphereLightHelper);
175180
}
176181

0 commit comments

Comments
 (0)