repo: janusweb action: commit revision: path_from: revision_from: f3df5f712799d683e8d11b5d959821e2da50a958: path_to: revision_to:
commit f3df5f712799d683e8d11b5d959821e2da50a958 Author: James BaicoianuDate: Sun May 13 12:46:12 2018 -0700 Fixed spot and directional lights, added light_target diff --git a/scripts/januslight.js b/scripts/januslight.js
--- a/scripts/januslight.js
+++ b/scripts/januslight.js
@@ -5,9 +5,10 @@ elation.require(['janusweb.janusbase'], function() {
this.defineProperties({
light_directional: { type: 'bool', default: false, set: this.updateLight },
light_range: { type: 'float', default: 10, set: this.updateLight },
- light_intensity: { type: 'float', default: 100, set: this.updateLight },
+ light_intensity: { type: 'float', default: 10, set: this.updateLight },
light_cone_angle: { type: 'float', default: 0, set: this.updateLight },
light_cone_exponent: { type: 'float', default: 1, set: this.updateLight },
+ light_target: { type: 'object', set: this.updateLightTarget },
light_shadow: { type: 'boolean', default: false, set: this.updateLight },
light_shadow_near: { type: 'float', default: .1, set: this.updateLight },
light_shadow_far: { type: 'float', set: this.updateLight },
@@ -55,7 +56,7 @@ elation.require(['janusweb.janusbase'], function() {
}
this.createLight = function() {
if (!this.light) {
- if (this.light_directional) {
+ if (this.light_directional || this.light_cone_angle == 1) {
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);
@@ -63,7 +64,9 @@ elation.require(['janusweb.janusbase'], function() {
} 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.light.position.set(0,0,0);
+
+ this.updateLightTarget();
}
}
}
@@ -81,6 +84,30 @@ elation.require(['janusweb.janusbase'], function() {
this.updateShadowmap();
}
}
+ this.updateLightTarget = function() {
+ if (!this.light) return;
+
+ if (this.light_target) {
+ if (elation.utils.isString(this.light_target)) {
+ if (room.objects[this.light_target]) {
+ this.light.target = room.objects[this.light_target].objects['3d'];
+ } else if (this.light_target == 'player') {
+ this.light.target = player.objects['3d'];
+ }
+ } else if (this.light_target.objects && this.light_target.objects['3d']) {
+ this.light.target = this.light_target.objects['3d'];
+ } else if (this.light_target instanceof THREE.Object3D) {
+ this.light.target = this.light_target;
+ }
+ }
+
+ // If no target was specified, we're using the default, so make sure it's set up right
+ var target = this.light.target;
+ if (!target.parent) {
+ this.objects['3d'].add(target);
+ target.position.set(0,0,1);
+ }
+ }
this.updateShadowmap = function() {
var player = this.engine.client.player;
var shadowSize = player.getSetting('render.shadows.size', elation.config.get('janusweb.materials.shadows.size', 512));
@@ -101,6 +128,7 @@ elation.require(['janusweb.janusbase'], function() {
light_intensity: [ 'property', 'light_intensity'],
light_cone_angle: [ 'property', 'light_cone_angle'],
light_cone_exponent: [ 'property', 'light_cone_exponent'],
+ light_target: [ 'property', 'light_target'],
light_shadow: [ 'property', 'light_shadow'],
light_shadow_near: [ 'property', 'light_shadow_near'],
light_shadow_far: [ 'property', 'light_shadow_far'],
-----END OF PAGE-----