From cce45f98bdf6f6326a8edc4c488c070e92f4b417 Mon Sep 17 00:00:00 2001 From: Sandro Weber <webers@in.tum.de> Date: Mon, 29 Feb 2016 16:10:03 +0100 Subject: [PATCH] [NRRPLT-3232] keep spotlight facing down during insertion Change-Id: Iacca141dec8daf53269bfbb94db430c0e75727fc --- gz3d/src/gzscene.js | 27 ++++++++++++--------------- gz3d/src/gzspawnmodel.js | 15 +++------------ 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/gz3d/src/gzscene.js b/gz3d/src/gzscene.js index fcf1a25..078ad96 100644 --- a/gz3d/src/gzscene.js +++ b/gz3d/src/gzscene.js @@ -999,6 +999,12 @@ GZ3D.Scene.prototype.createLight = function(type, diffuse, intensity, pose, var lightObj = elements[0]; var helper = elements[1]; + obj.add(lightObj); + obj.add(helper); + + helper.visible = this.showLightHelpers; + lightObj.up = new THREE.Vector3(0,0,1); + lightObj.shadowBias = -0.0005; if (name) { @@ -1009,16 +1015,14 @@ GZ3D.Scene.prototype.createLight = function(type, diffuse, intensity, pose, helper.name = '_lightHelper'; } + if ((type === this.LIGHT_SPOT || type === this.LIGHT_DIRECTIONAL) && !(direction instanceof THREE.Vector3)) { + direction = new THREE.Vector3(0, 0, -1); + } if (direction) { - var dir = new THREE.Vector3(direction.x, direction.y, - direction.z); - - obj.direction = new THREE.Vector3(); - obj.direction.copy(dir); - - dir.applyMatrix4(matrixWorld); // localToWorld - lightObj.target.position.copy(dir); + lightObj.target.name = name + '_target'; + obj.add(lightObj.target); + lightObj.target.position.copy(direction); lightObj.target.updateMatrixWorld(); } @@ -1031,13 +1035,6 @@ GZ3D.Scene.prototype.createLight = function(type, diffuse, intensity, pose, obj.serverProperties.initial = {}; obj.serverProperties.initial.diffuse = diffuse; - helper.visible = this.showLightHelpers; - lightObj.up = new THREE.Vector3(0,0,1); - lightObj.shadowBias = -0.0005; - - obj.add(lightObj); - obj.add(helper); - return obj; }; diff --git a/gz3d/src/gzspawnmodel.js b/gz3d/src/gzspawnmodel.js index 75df2c6..d459d08 100644 --- a/gz3d/src/gzspawnmodel.js +++ b/gz3d/src/gzspawnmodel.js @@ -55,15 +55,15 @@ GZ3D.SpawnModel.prototype.start = function(entity, callback) } else if (entity === 'pointlight') { - mesh = this.scene.createLight(1); + mesh = this.scene.createLight(this.scene.LIGHT_POINT); } else if (entity === 'spotlight') { - mesh = this.scene.createLight(2); + mesh = this.scene.createLight(this.scene.LIGHT_SPOT); } else if (entity === 'directionallight') { - mesh = this.scene.createLight(3); + mesh = this.scene.createLight(this.scene.LIGHT_DIRECTIONAL); } else { @@ -255,15 +255,6 @@ GZ3D.SpawnModel.prototype.moveSpawnedModel = function(positionX, positionY) } this.scene.setPose(this.obj, point, new THREE.Quaternion()); - - if (this.obj.children[0].children[0] && - (this.obj.children[0].children[0] instanceof THREE.SpotLight || - this.obj.children[0].children[0] instanceof THREE.DirectionalLight)) - { - var lightObj = this.obj.children[0].children[0]; - lightObj.target.position.copy(this.obj.position); - lightObj.target.position.add(new THREE.Vector3(0,0,-0.5)); - } }; /** -- GitLab