diff --git a/ts/Led.ts b/ts/Led.ts index 774687a..8168908 100644 --- a/ts/Led.ts +++ b/ts/Led.ts @@ -161,6 +161,12 @@ export class Leds extends THREE.Object3D { /** Whether we need to show the lines of the leds. */ 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; + /** * Create a set of leds from their configuration. */ @@ -169,9 +175,15 @@ export class Leds extends THREE.Object3D { this.showLines = showLines; this.currentLedIndex = null; + this.light = new THREE.PointLight(0xffffff, 1000); + this.add(this.light); + + this.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 { // 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; led.turnOff(); + this.light.visible = true; return; } - for (let index = 0; index < this.children.length; index++) { - let child = this.children[index]; - if (led === this.children[index]) { + for (let index = 0; index < this.leds.length; index++) { + let child = this.leds[index]; + if (led === this.leds[index]) { child.turnOn(this.showLines); this.currentLedIndex = index; } else { child.turnOff(); } } + this.light.visible = false; } /** @@ -203,7 +217,7 @@ export class Leds extends THREE.Object3D { */ setShowLines(showLines: boolean): void { this.showLines = showLines; - for (let child of this.children) { + for (let child of this.leds) { if (child instanceof Led && child.on) { child.lines.visible = showLines; } @@ -216,15 +230,15 @@ export class Leds extends THREE.Object3D { next(): Led { if (this.currentLedIndex === null) { this.currentLedIndex = 0; - let led = this.children[0]; + let led = this.leds[0]; led.turnOn(this.showLines); return led; } - ( this.children[this.currentLedIndex]).turnOff(); - this.currentLedIndex = (this.currentLedIndex + 1) % this.children.length; - ( this.children[this.currentLedIndex]).turnOn(this.showLines); - return this.children[this.currentLedIndex]; + this.leds[this.currentLedIndex].turnOff(); + this.currentLedIndex = (this.currentLedIndex + 1) % this.leds.length; + this.leds[this.currentLedIndex].turnOn(this.showLines); + return this.leds[this.currentLedIndex]; } /** @@ -233,13 +247,13 @@ export class Leds extends THREE.Object3D { previous(): Led { if (this.currentLedIndex === null) { this.currentLedIndex = 0; - ( this.children[0]).turnOn(this.showLines); - return this.children[0];; + this.leds[0].turnOn(this.showLines); + return this.leds[0]; } - ( this.children[this.currentLedIndex]).turnOff(); - this.currentLedIndex = (this.currentLedIndex + this.children.length - 1) % this.children.length; - let led = ( this.children[this.currentLedIndex]); + this.leds[this.currentLedIndex].turnOff(); + this.currentLedIndex = (this.currentLedIndex + this.leds.length - 1) % this.leds.length; + let led = this.leds[this.currentLedIndex]; led.turnOn(this.showLines); return led; }