repo: janusweb
action: commit
revision: 
path_from: 
revision_from: 5c7be04f0da43c2af6bd2787ae3a58e3db7c78b5:
path_to: 
revision_to: 
git.thebackupbox.net
janusweb
git clone git://git.thebackupbox.net/janusweb
commit 5c7be04f0da43c2af6bd2787ae3a58e3db7c78b5
Author: James Baicoianu 
Date:   Tue Mar 27 09:42:15 2018 -0700

    Fix light creation race condition

diff --git a/scripts/januslight.js b/scripts/januslight.js
index 28c39d6623b3c74a723b60793b7e18b9ac151310..
index ..46359e505d0095bfe90c4204706f83bc16fea59a 100644
--- a/scripts/januslight.js
+++ b/scripts/januslight.js
@@ -17,26 +17,14 @@ elation.require(['janusweb.janusbase'], function() {
     }
     this.createObject3D = function() {
       var obj = new THREE.Object3D();
-      if (this.light_directional) {
-        this.light = new THREE.DirectionalLight(this.properties.color, this.light_intensity);
-        obj.add(this.light);
-      } else if (this.light_cone_angle == 0) {
-        this.light = new THREE.PointLight(this.properties.color, 1, this.light_range);
-        this.light.position.set(0,0,0);
-        obj.add(this.light);
-      } else if (this.light_cone_angle > 0) {
-        var angle = Math.acos(this.light_cone_angle);
-        this.light = new THREE.SpotLight(this.properties.color, 1, this.light_range, angle);
-        //this.light.position.set(0,0,0);
-        obj.add(this.light);
-      } 
-      this.updateLight();
       return obj;
     }
     this.updateColor = function() {
       this.updateLight();
     }
     this.createChildren = function() {
+      this.createLight();
+      this.updateLight();
       // TODO - should be an easy way of toggling helpers
       /*
       var scene = this.objects['3d'];
@@ -57,8 +45,23 @@ elation.require(['janusweb.janusbase'], function() {
       this.localToWorld(this.light.target.position.set(0,0,-1));
       this.light.target.updateMatrixWorld();
     }
+    this.createLight = function() {
+      if (this.light_directional) {
+        this.light = new THREE.DirectionalLight(this.properties.color, this.light_intensity);
+      } else if (this.light_cone_angle == 0) {
+        this.light = new THREE.PointLight(this.properties.color, 1, this.light_range);
+        this.light.position.set(0,0,0);
+      } else if (this.light_cone_angle > 0) {
+        var angle = Math.acos(this.light_cone_angle);
+        this.light = new THREE.SpotLight(this.properties.color, 1, this.light_range, angle);
+        //this.light.position.set(0,0,0);
+      }
+    }
     this.updateLight = function() {
       if (this.light) {
+        if (this.light.parent !== this.objects['3d']) {
+          this.objects['3d'].add(this.light);
+        }
         //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;

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