diff --git a/gz3d/build/gz3d.js b/gz3d/build/gz3d.js index ea2a8711bdeaaf9fc222a233f897928556b21192..09b199b8296af9149d3443a8f89aa16395a6163d 100644 --- a/gz3d/build/gz3d.js +++ b/gz3d/build/gz3d.js @@ -2871,7 +2871,7 @@ GZ3D.GZIface.prototype.createLightFromMsg = function(light) obj = this.scene.createLight(light.type, light.diffuse, intensity, light.pose, range, light.cast_shadows, light.name, direction, light.specular, light.attenuation_constant, - light.attenuation_linear, light.attenuation_quadratic); + light.attenuation_linear, light.attenuation_quadratic, light.spot_outer_angle, light.spot_falloff); return obj; }; @@ -6000,7 +6000,7 @@ GZ3D.Scene.prototype.createBox = function(width, height, depth) */ GZ3D.Scene.prototype.createLight = function(type, diffuse, intensity, pose, distance, cast_shadows, name, direction, specular, attenuation_constant, - attenuation_linear, attenuation_quadratic) + attenuation_linear, attenuation_quadratic, spot_angle, spot_falloff) { var obj = new THREE.Object3D(); var color = new THREE.Color(); @@ -6055,7 +6055,7 @@ GZ3D.Scene.prototype.createLight = function(type, diffuse, intensity, pose, else if (type === 2) { elements = this.createSpotLight(obj, diffuse, intensity, - distance, cast_shadows); + distance, cast_shadows, spot_angle, spot_falloff); } else if (type === 3) { @@ -6096,9 +6096,8 @@ GZ3D.Scene.prototype.createLight = function(type, diffuse, intensity, pose, obj.add(lightObj); obj.add(helper); - lightObj.shadowCameraVisible = true; //debug - lightObj.shadowBias = -0.0001; lightObj.up = new THREE.Vector3(0,0,1); + lightObj.shadowBias = -0.0005; return obj; }; @@ -6151,7 +6150,7 @@ GZ3D.Scene.prototype.createPointLight = function(obj, color, intensity, * @returns {Object.<THREE.Light, THREE.Mesh>} */ GZ3D.Scene.prototype.createSpotLight = function(obj, color, intensity, - distance, cast_shadows) + distance, cast_shadows, angle, falloff) { if (typeof(intensity) === 'undefined') { @@ -6161,17 +6160,26 @@ GZ3D.Scene.prototype.createSpotLight = function(obj, color, intensity, { distance = 20; } + if (typeof(angle) === 'undefined') + { + angle = Math.PI/3; + } + if (typeof(falloff) === 'undefined') + { + falloff = 1; + } - var lightObj = new THREE.SpotLight(color, intensity); - lightObj.distance = distance; + var lightObj = new THREE.SpotLight(color, intensity, distance, angle, falloff); lightObj.position.set(0,0,0); lightObj.shadowDarkness = 0.3; + lightObj.shadowBias = 0.0001; lightObj.shadowCameraNear = 0.1; lightObj.shadowCameraFar = 50; + lightObj.shadowCameraFov = (2 * angle / Math.PI) * 180; - lightObj.shadowMapWidth = 2048; - lightObj.shadowMapHeight = 2048; + lightObj.shadowMapWidth = 4096; + lightObj.shadowMapHeight = 4096; if (cast_shadows) { @@ -6206,7 +6214,7 @@ GZ3D.Scene.prototype.createDirectionalLight = function(obj, color, intensity, } var lightObj = new THREE.DirectionalLight(color, intensity); - lightObj.shadowCameraNear = 1; + lightObj.shadowCameraNear = 0.1; lightObj.shadowCameraFar = 50; lightObj.shadowMapWidth = 4094; lightObj.shadowMapHeight = 4094; @@ -7500,16 +7508,15 @@ GZ3D.Scene.prototype.updateLight = function(entity, msg) lightObj.intensity = lightObj.intensity/(1+msg.attenuation_quadratic); } -// Not handling these on gzweb for now -// -// if (lightObj instanceof THREE.SpotLight) { -// if (msg.spot_outer_angle) { -// lightObj.angle = msg.spot_outer_angle; -// } -// if (msg.spot_falloff) { -// lightObj.exponent = msg.spot_falloff; -// } -// } + if (lightObj instanceof THREE.SpotLight) { + if (msg.spot_outer_angle) { + lightObj.angle = msg.spot_outer_angle; + lightObj.shadowCameraFov = (2 * msg.spot_outer_angle / Math.PI) * 180; + } + if (msg.spot_falloff) { + lightObj.exponent = msg.spot_falloff; + } + } if (msg.direction) { diff --git a/gz3d/src/gziface.js b/gz3d/src/gziface.js index 4d8e889ea85f128ff4b58ac41ed796e716feeaca..e97d0e54ff7413747d719c3a07c153bd9b76a1d8 100644 --- a/gz3d/src/gziface.js +++ b/gz3d/src/gziface.js @@ -792,7 +792,7 @@ GZ3D.GZIface.prototype.createLightFromMsg = function(light) obj = this.scene.createLight(light.type, light.diffuse, intensity, light.pose, range, light.cast_shadows, light.name, direction, light.specular, light.attenuation_constant, - light.attenuation_linear, light.attenuation_quadratic); + light.attenuation_linear, light.attenuation_quadratic, light.spot_outer_angle, light.spot_falloff); return obj; }; diff --git a/gz3d/src/gzscene.js b/gz3d/src/gzscene.js index fd72ad521e2b3d5c70e5b6609db2648533aafe55..d8a6c0943bdfec4c97378193999a00551369e1b8 100644 --- a/gz3d/src/gzscene.js +++ b/gz3d/src/gzscene.js @@ -919,7 +919,7 @@ GZ3D.Scene.prototype.createBox = function(width, height, depth) */ GZ3D.Scene.prototype.createLight = function(type, diffuse, intensity, pose, distance, cast_shadows, name, direction, specular, attenuation_constant, - attenuation_linear, attenuation_quadratic) + attenuation_linear, attenuation_quadratic, spot_angle, spot_falloff) { var obj = new THREE.Object3D(); var color = new THREE.Color(); @@ -974,7 +974,7 @@ GZ3D.Scene.prototype.createLight = function(type, diffuse, intensity, pose, else if (type === 2) { elements = this.createSpotLight(obj, diffuse, intensity, - distance, cast_shadows); + distance, cast_shadows, spot_angle, spot_falloff); } else if (type === 3) { @@ -1015,9 +1015,8 @@ GZ3D.Scene.prototype.createLight = function(type, diffuse, intensity, pose, obj.add(lightObj); obj.add(helper); - lightObj.shadowCameraVisible = true; //debug - lightObj.shadowBias = -0.0001; lightObj.up = new THREE.Vector3(0,0,1); + lightObj.shadowBias = -0.0005; return obj; }; @@ -1070,7 +1069,7 @@ GZ3D.Scene.prototype.createPointLight = function(obj, color, intensity, * @returns {Object.<THREE.Light, THREE.Mesh>} */ GZ3D.Scene.prototype.createSpotLight = function(obj, color, intensity, - distance, cast_shadows) + distance, cast_shadows, angle, falloff) { if (typeof(intensity) === 'undefined') { @@ -1080,17 +1079,26 @@ GZ3D.Scene.prototype.createSpotLight = function(obj, color, intensity, { distance = 20; } + if (typeof(angle) === 'undefined') + { + angle = Math.PI/3; + } + if (typeof(falloff) === 'undefined') + { + falloff = 1; + } - var lightObj = new THREE.SpotLight(color, intensity); - lightObj.distance = distance; + var lightObj = new THREE.SpotLight(color, intensity, distance, angle, falloff); lightObj.position.set(0,0,0); lightObj.shadowDarkness = 0.3; + lightObj.shadowBias = 0.0001; lightObj.shadowCameraNear = 0.1; lightObj.shadowCameraFar = 50; + lightObj.shadowCameraFov = (2 * angle / Math.PI) * 180; - lightObj.shadowMapWidth = 2048; - lightObj.shadowMapHeight = 2048; + lightObj.shadowMapWidth = 4096; + lightObj.shadowMapHeight = 4096; if (cast_shadows) { @@ -1125,7 +1133,7 @@ GZ3D.Scene.prototype.createDirectionalLight = function(obj, color, intensity, } var lightObj = new THREE.DirectionalLight(color, intensity); - lightObj.shadowCameraNear = 1; + lightObj.shadowCameraNear = 0.1; lightObj.shadowCameraFar = 50; lightObj.shadowMapWidth = 4094; lightObj.shadowMapHeight = 4094; @@ -2419,16 +2427,15 @@ GZ3D.Scene.prototype.updateLight = function(entity, msg) lightObj.intensity = lightObj.intensity/(1+msg.attenuation_quadratic); } -// Not handling these on gzweb for now -// -// if (lightObj instanceof THREE.SpotLight) { -// if (msg.spot_outer_angle) { -// lightObj.angle = msg.spot_outer_angle; -// } -// if (msg.spot_falloff) { -// lightObj.exponent = msg.spot_falloff; -// } -// } + if (lightObj instanceof THREE.SpotLight) { + if (msg.spot_outer_angle) { + lightObj.angle = msg.spot_outer_angle; + lightObj.shadowCameraFov = (2 * msg.spot_outer_angle / Math.PI) * 180; + } + if (msg.spot_falloff) { + lightObj.exponent = msg.spot_falloff; + } + } if (msg.direction) {