repo: janusweb
action: commit
revision: 
path_from: 
revision_from: 65d59f98ca31155c67d951a02317bcd432e926a5:
path_to: 
revision_to: 
git.thebackupbox.net
janusweb
git clone git://git.thebackupbox.net/janusweb
commit 65d59f98ca31155c67d951a02317bcd432e926a5
Author: James Baicoianu 
Date:   Sun Sep 10 00:26:54 2023 -0700

    Added light color_temperature attribute, deprecated Three.js API updates

diff --git a/scripts/januslight.js b/scripts/januslight.js
index b9947eff72769d9626f73251c9cf0e05156b75c6..
index ..8cee53273c1752b6714c14dc072e2ebb7c16e138 100644
--- a/scripts/januslight.js
+++ b/scripts/januslight.js
@@ -20,6 +20,7 @@ elation.require(['janusweb.janusbase'], function() {
         light_helper: { type: 'boolean', default: false, set: this.updateLightHelper },
         light_style: { type: 'string', default: '' },
         light_style_fps: { type: 'float', default: 10 },
+        color_temperature: { type: 'float', set: this.updateLight },
         collision_id: { type: 'string', default: 'sphere', set: this.updateCollider },
         collision_trigger: { type: 'boolean', default: true, set: this.updateCollider },
       });
@@ -73,14 +74,14 @@ elation.require(['janusweb.janusbase'], function() {
     this.getPlaceholderGeometry = function() {
       let placeholdergeo = null;
       if (this.light_cone_angle == 0) {
-        placeholdergeo = new THREE.SphereBufferGeometry(.1);
+        placeholdergeo = new THREE.SphereGeometry(.1);
       } else if (this.light_cone_angle == 1) {
-        placeholdergeo = new THREE.SphereBufferGeometry(.1);
+        placeholdergeo = new THREE.SphereGeometry(.1);
       } else {
         let angle = Math.acos(this.light_cone_angle),
             height = this.light_shadow_near,
             radius = Math.tan(angle) * height;
-        placeholdergeo = new THREE.ConeBufferGeometry(radius, height);
+        placeholdergeo = new THREE.ConeGeometry(radius, height);
         placeholdergeo.applyMatrix4(new THREE.Matrix4().makeRotationFromEuler(new THREE.Euler(-Math.PI/2, 0, 0)).setPosition(0, 0, height / 2));
       }
       return placeholdergeo;
@@ -139,7 +140,11 @@ elation.require(['janusweb.janusbase'], function() {
         this.light.intensity = .1;
         this.light.penumbra = this.light_penumbra;
         this.light.decay = this.light_decay;
-        this.light.color.copy(this.color);
+        if (this.color_temperature) {
+          this.light.color.copy(this.temperatureToRGB(this.color_temperature));
+        } else {
+          this.light.color.copy(this.color);
+        }
         this.light.color.multiplyScalar(this.light_intensity * avgscale * avgscale);
         this.light.distance = this.light_range * avgscale;
         if (this.light_cone_angle > 0 && this.light_cone_angle < 1) {
@@ -199,6 +204,42 @@ elation.require(['janusweb.janusbase'], function() {
       this.light.shadow.camera.top = d;
       this.light.shadow.camera.bottom = -d;
     }
+    this.temperatureToRGB = function(t) {
+      // From view-source:https://web.archive.org/web/20161108193229/https://tommitytom.co.uk/colourtemp/
+      let r = 0, g = 0, b = 0,
+          temp = Math.floor(t / 100 + 0.5),
+          rgb = null;
+
+      if (temp <= 66) {
+        r = 255;
+      } else {
+        r = temp - 60;
+        r = 329.698727446 * Math.pow(r, -0.1332047592);
+      }
+
+      if (temp <= 66) {
+        g = temp;
+        g = 99.4708025861 * Math.log(g) - 161.1195681661;
+      } else {
+        g = temp - 60;
+        g = 288.1221695283 * Math.pow(g, -0.0755148492);
+      }
+
+      if (temp >= 66) {
+        b = 255;
+      } else if (temp <= 19) {
+        b = 0;
+      } else {
+        b = temp - 10;
+        b = 138.5177312231 * Math.log(b) - 305.0447927307;
+      }
+
+      r = THREE.MathUtils.clamp(r, 0, 255) / 255;
+      g = THREE.MathUtils.clamp(g, 0, 255) / 255;
+      b = THREE.MathUtils.clamp(b, 0, 255) / 255;
+
+      return {r, g, b};
+    }
     this.getProxyObject = function(classdef) {
       if (!this._proxyobject) {
         this._proxyobject = elation.engine.things.janusobject.extendclass.getProxyObject.call(this, classdef);
@@ -215,6 +256,7 @@ elation.require(['janusweb.janusbase'], function() {
           light_shadow_far:    [ 'property', 'light_shadow_far'],
           light_shadow_bias:   [ 'property', 'light_shadow_bias'],
           light_shadow_radius: [ 'property', 'light_shadow_radius'],
+          color_temperature:   [ 'property', 'color_temperature'],
         };
       }
       return this._proxyobject;

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