diff --git a/gz3d/src/gzscene.js b/gz3d/src/gzscene.js index fcf1a251f6ebb534da1a945be8e5b617620b6729..078ad9602ef33709243e57c8e7797f752e5cfb84 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 75df2c6db151e0467c5a5599f0aef0a1fc27cfad..d459d08939a99785a8b581a9fdf79c692cd0a77b 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)); - } }; /**