repo: janusweb
action: commit
revision: 
path_from: 
revision_from: bd678b5ef2fa9c2b50244ab332e05e304596b726:
path_to: 
revision_to: 
git.thebackupbox.net
janusweb
git clone git://git.thebackupbox.net/janusweb
commit bd678b5ef2fa9c2b50244ab332e05e304596b726
Author: James Baicoianu 
Date:   Mon Sep 20 12:50:19 2021 -0700

    Added quake-inspired 'light_style' parameter

diff --git a/scripts/januslight.js b/scripts/januslight.js
index ee93783483efc60a8397226d4961b14248fedaef..
index ..b9947eff72769d9626f73251c9cf0e05156b75c6 100644
--- a/scripts/januslight.js
+++ b/scripts/januslight.js
@@ -18,6 +18,8 @@ elation.require(['janusweb.janusbase'], function() {
         light_shadow_bias: { type: 'float', default: .0001, set: this.updateLight },
         light_shadow_radius: { type: 'float', default: 2.5, set: this.updateLight },
         light_helper: { type: 'boolean', default: false, set: this.updateLightHelper },
+        light_style: { type: 'string', default: '' },
+        light_style_fps: { type: 'float', default: 10 },
         collision_id: { type: 'string', default: 'sphere', set: this.updateCollider },
         collision_trigger: { type: 'boolean', default: true, set: this.updateCollider },
       });
@@ -98,8 +100,14 @@ elation.require(['janusweb.janusbase'], function() {
         this.updateLightTarget();
       }
       if (this.light_directional || this.light_cone_angle == 1) {
-        this.light.position.subVectors(this.light.position, this.light.target.position).add(player.pos);
-        this.light.target.position.copy(player.pos);
+        //this.light.position.subVectors(this.light.position, this.light.target.position).add(player.pos).sub(this.pos);
+        this.light.position.subVectors(this.position, this.light.target.position).normalize().multiplyScalar(this.light_range / 2).add(player.pos).sub(this.pos);
+        this.light.target.position.copy(player.pos).sub(this.pos);
+      }
+      if (this.light_style != '') {
+        let idx = Math.floor(Date.now() / (1000 / this.light_style_fps)) % this.light_style.length;
+        let brightness = (this.light_style.charCodeAt(idx) - 97) / 13;
+        this.light.intensity = .1 * brightness;
       }
     }
     this.createLight = function() {
@@ -127,6 +135,7 @@ elation.require(['janusweb.janusbase'], function() {
         //this.light.intensity = this.light_intensity / 100;
         var avgscale = (this.scale.x + this.scale.y + this.scale.z) / 3;
         //this.light.intensity = this.light_intensity / 100;
+        let brightness = 1;
         this.light.intensity = .1;
         this.light.penumbra = this.light_penumbra;
         this.light.decay = this.light_decay;

-----END OF PAGE-----