Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/3dtiles_loader.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
const isEmbedded = window.self !== window.top;

window.gui = new dat.GUI();


// ---- Create a GlobeView ----

Expand All @@ -97,6 +97,7 @@
// Create a GlobeView
const view = new GlobeView(viewerDiv, placement, {
realisticLighting: true,
withSunLightLayer: true,
shadows: true,
controls: {
minDistance: 100,
Expand Down
1 change: 1 addition & 0 deletions examples/demo/src/Views/View3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class View3D extends View {
placement,
{
realisticLighting: true,
withSunLightLayer: true,
},
);

Expand Down
1 change: 1 addition & 0 deletions examples/mars.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
scaleDepth: 0.38,
},
realisticLighting: true,
withSunLightLayer: true,
});
setupLoadingScreen(viewerDiv, view);

Expand Down
1 change: 1 addition & 0 deletions examples/view_3d_map.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
// Create a GlobeView
const view = new itowns.GlobeView(viewerDiv, placement, {
realisticLighting: true,
withSunLightLayer: true,
});

// Setup loading screen and debug menu
Expand Down
1 change: 1 addition & 0 deletions examples/view_3d_mns_map.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
// Create a GlobeView
const view = new itowns.GlobeView(viewerDiv, placement, {
realisticLighting: true,
withSunLightLayer: true,
});

// Setup loading screen and debug menu
Expand Down
6 changes: 5 additions & 1 deletion packages/Main/src/Core/Prefab/Globe/SkyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class SkyManager {
const camera = this.view.camera3D as THREE.PerspectiveCamera | THREE.OrthographicCamera;
if (!this.enabled) { return; }

// sunLightLayer necessarily exists if SkyManager was created.
if (!this.view.sunLightLayer) { return; }
const sunDirection = this.view.sunLightLayer.sunDirection;
const moonDirection = new THREE.Vector3();
getMoonDirectionECEF(this.view.date, moonDirection);
Expand Down Expand Up @@ -137,7 +139,9 @@ class SkyManager {
}

private _setState(on: boolean) {
// Realistic rendering requires a dimmer sunlight
// Realistic rendering requires a dimmer sunlight.
// sunLightLayer necessarily exists if SkyManager was created.
if (!this.view.sunLightLayer) { return; }
this.view.sunLightLayer.sunLight.intensity *= on ? 0.1 : 10;
this.sky.visible = on;
this.skyLight.visible = on;
Expand Down
20 changes: 16 additions & 4 deletions packages/Main/src/Core/Prefab/GlobeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,13 @@ class GlobeView extends View {
* The maximum view distance is this factor times the camera's altitude (above sea level).
* @param {number} [options.fogSpread=0.5] - Proportion of the visible depth range that contains fog.
* Between 0 and 1.
* @param {boolean} [options.withSunLightLayer=false] - Create and add a SunLightLayer.
* If true, it can later be switched by setting this.sunLightLayer.visible to true/false.
* If false, it will be impossible to enable it later on.
* @param {boolean} [options.realisticLighting=false] - Enable realistic lighting.
* If true, it can later be switched by setting this.skyManager.enabled to true/false.
* If false, it will be impossible to enable it later on.
* Can only be enabled if withSunLightLayer was also enabled.
* @param {boolean} [options.shadows=false] - Enable shadow map rendering. Can be toggled
* later via `this.shadows`.
*/
Expand Down Expand Up @@ -164,13 +168,20 @@ class GlobeView extends View {
}

this.date = new Date(); // now
const withSunLightLayer = options.withSunLightLayer === true;

// Sunlight and shadow layer
this.sunLightLayer = new SunLightLayer(this);
this.addLayer(this.sunLightLayer);
if (withSunLightLayer) {
this.sunLightLayer = new SunLightLayer(this);
this.addLayer(this.sunLightLayer);
}

if (options.realisticLighting === true) {
this.skyManager = new SkyManager(this);
if (withSunLightLayer) {
this.skyManager = new SkyManager(this);
} else {
console.error('Realistic lighting cannot be enabled without sunlight layer option');
}
}

this.renderer.shadowMap.enabled = true;
Expand Down Expand Up @@ -229,10 +240,11 @@ class GlobeView extends View {
* @type {boolean}
*/
get shadows() {
return this.sunLightLayer.castShadow;
return this.sunLightLayer?.castShadow ?? false;
}

set shadows(value) {
if (!this.sunLightLayer) { return; }
if (this.sunLightLayer.castShadow == value) { return; }
this.sunLightLayer.castShadow = value;
this.notifyChange(this.camera3D);
Expand Down
1 change: 1 addition & 0 deletions packages/Main/test/unit/globeview.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('GlobeView', function () {
const viewer = new GlobeView(renderer.domElement, placement, {
renderer,
realisticLighting: true,
withSunLightLayer: true,
});
const pickedPosition = new THREE.Vector3();
pickedPosition.copy(viewer.camera.position());
Expand Down
Loading