Add default light when all leds are off

This commit is contained in:
Thomas Forgione 2024-07-04 11:57:06 +02:00
parent 4d16da2b92
commit 8820523f01
1 changed files with 30 additions and 16 deletions

View File

@ -161,6 +161,12 @@ export class Leds extends THREE.Object3D {
/** Whether we need to show the lines of the leds. */ /** Whether we need to show the lines of the leds. */
showLines: boolean; showLines: boolean;
/** A little light to be turned on when all leds are off, to show depth. */
light: THREE.PointLight;
/** Array of all the leds of the setup. */
leds: Array<Led>;
/** /**
* Create a set of leds from their configuration. * Create a set of leds from their configuration.
*/ */
@ -169,9 +175,15 @@ export class Leds extends THREE.Object3D {
this.showLines = showLines; this.showLines = showLines;
this.currentLedIndex = null; this.currentLedIndex = null;
this.light = new THREE.PointLight(0xffffff, 1000);
this.add(this.light);
this.leds = [];
for (let ledInfo of calibration.leds) { for (let ledInfo of calibration.leds) {
this.add(new Led(ledInfo, calibration.spheres)); let led = new Led(ledInfo, calibration.spheres);
this.add(led);
this.leds.push(led);
} }
} }
@ -181,21 +193,23 @@ export class Leds extends THREE.Object3D {
*/ */
toggle(led: Led): void { toggle(led: Led): void {
// If the specified led is the one on. // If the specified led is the one on.
if (this.currentLedIndex !== null && led === this.children[this.currentLedIndex]) { if (this.currentLedIndex !== null && led === this.leds[this.currentLedIndex]) {
this.currentLedIndex = null; this.currentLedIndex = null;
led.turnOff(); led.turnOff();
this.light.visible = true;
return; return;
} }
for (let index = 0; index < this.children.length; index++) { for (let index = 0; index < this.leds.length; index++) {
let child = <Led> this.children[index]; let child = this.leds[index];
if (led === this.children[index]) { if (led === this.leds[index]) {
child.turnOn(this.showLines); child.turnOn(this.showLines);
this.currentLedIndex = index; this.currentLedIndex = index;
} else { } else {
child.turnOff(); child.turnOff();
} }
} }
this.light.visible = false;
} }
/** /**
@ -203,7 +217,7 @@ export class Leds extends THREE.Object3D {
*/ */
setShowLines(showLines: boolean): void { setShowLines(showLines: boolean): void {
this.showLines = showLines; this.showLines = showLines;
for (let child of this.children) { for (let child of this.leds) {
if (child instanceof Led && child.on) { if (child instanceof Led && child.on) {
child.lines.visible = showLines; child.lines.visible = showLines;
} }
@ -216,15 +230,15 @@ export class Leds extends THREE.Object3D {
next(): Led { next(): Led {
if (this.currentLedIndex === null) { if (this.currentLedIndex === null) {
this.currentLedIndex = 0; this.currentLedIndex = 0;
let led = <Led> this.children[0]; let led = this.leds[0];
led.turnOn(this.showLines); led.turnOn(this.showLines);
return led; return led;
} }
(<Led> this.children[this.currentLedIndex]).turnOff(); this.leds[this.currentLedIndex].turnOff();
this.currentLedIndex = (this.currentLedIndex + 1) % this.children.length; this.currentLedIndex = (this.currentLedIndex + 1) % this.leds.length;
(<Led> this.children[this.currentLedIndex]).turnOn(this.showLines); this.leds[this.currentLedIndex].turnOn(this.showLines);
return <Led> this.children[this.currentLedIndex]; return <Led> this.leds[this.currentLedIndex];
} }
/** /**
@ -233,13 +247,13 @@ export class Leds extends THREE.Object3D {
previous(): Led { previous(): Led {
if (this.currentLedIndex === null) { if (this.currentLedIndex === null) {
this.currentLedIndex = 0; this.currentLedIndex = 0;
(<Led> this.children[0]).turnOn(this.showLines); this.leds[0].turnOn(this.showLines);
return <Led> this.children[0];; return this.leds[0];
} }
(<Led> this.children[this.currentLedIndex]).turnOff(); this.leds[this.currentLedIndex].turnOff();
this.currentLedIndex = (this.currentLedIndex + this.children.length - 1) % this.children.length; this.currentLedIndex = (this.currentLedIndex + this.leds.length - 1) % this.leds.length;
let led = (<Led> this.children[this.currentLedIndex]); let led = this.leds[this.currentLedIndex];
led.turnOn(this.showLines); led.turnOn(this.showLines);
return led; return led;
} }