feat(map): add Cesium visual settings and fullscreen-safe scene windows
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@nodedc/map-cesium-react",
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.4",
|
||||
"description": "Shared credential-free Cesium adapter for NODE.DC Map Page consumers.",
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
|
||||
@@ -15,6 +15,7 @@ import type {
|
||||
MapProviderId,
|
||||
MapRuntimeState,
|
||||
} from "./contracts.js";
|
||||
import {applyMapSceneEffects} from "./sceneEffects.js";
|
||||
import { advanceGhostPins } from "./ghostPins.js";
|
||||
import {
|
||||
parseProviderEndpoint,
|
||||
@@ -495,7 +496,9 @@ function applyPresentation(
|
||||
buildings.maximumScreenSpaceError =
|
||||
settings.buildings_maximum_screen_space_error;
|
||||
buildings.style = new Cesium.Cesium3DTileStyle({
|
||||
color: `color('${settings.buildings_color}', ${settings.buildings_opacity})`,
|
||||
color: settings.buildings_style_default
|
||||
? `Boolean(\${feature['cesium#color']}) ? color(\${feature['cesium#color']}, ${settings.buildings_opacity}) : color('#ffffff', ${settings.buildings_opacity})`
|
||||
: `color('${settings.buildings_color}', ${settings.buildings_opacity})`,
|
||||
});
|
||||
}
|
||||
runtime.ghostPins.show = layers.targets;
|
||||
@@ -541,9 +544,9 @@ function applyPresentation(
|
||||
}
|
||||
viewer.shadows = settings.shadows_enabled;
|
||||
const sunDate = Cesium.JulianDate.toDate(Cesium.JulianDate.now());
|
||||
sunDate.setUTCHours(
|
||||
clamp(Math.round(settings.sun_hour), 0, 24),
|
||||
0,
|
||||
if (!settings.sun_time_current) sunDate.setUTCHours(
|
||||
Math.floor(clamp(settings.sun_hour, 0, 24)),
|
||||
Math.round((settings.sun_hour % 1) * 60),
|
||||
0,
|
||||
0,
|
||||
);
|
||||
@@ -556,6 +559,7 @@ function applyPresentation(
|
||||
2,
|
||||
);
|
||||
viewer.scene.light = sun;
|
||||
applyMapSceneEffects(runtime, settings);
|
||||
viewer.scene.requestRender();
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ export type MapLayerVisibility = {
|
||||
targets: boolean;
|
||||
};
|
||||
|
||||
export type MapVisualSettings = {
|
||||
export type MapVisualSettings = Partial<MapSceneEffects> & {
|
||||
atmosphere_enabled: boolean;
|
||||
atmosphere_hue: number;
|
||||
atmosphere_saturation: number;
|
||||
@@ -120,6 +120,7 @@ export type MapVisualSettings = {
|
||||
fog_enabled: boolean;
|
||||
fog_density: number;
|
||||
sun_enabled: boolean;
|
||||
sun_time_current?: boolean;
|
||||
sun_hour: number;
|
||||
sun_intensity: number;
|
||||
shadows_enabled: boolean;
|
||||
@@ -134,6 +135,7 @@ export type MapVisualSettings = {
|
||||
globe_color: string;
|
||||
background_color: string;
|
||||
terrain_exaggeration: number;
|
||||
buildings_style_default?: boolean;
|
||||
buildings_color: string;
|
||||
buildings_opacity: number;
|
||||
buildings_maximum_screen_space_error: number;
|
||||
@@ -155,6 +157,32 @@ export type MapVisualSettings = {
|
||||
camera_animation_enabled: boolean;
|
||||
};
|
||||
|
||||
/** Optional controls preserve presentation in existing hosts until explicitly supplied. */
|
||||
export type MapSceneEffects = {
|
||||
skybox_enabled: boolean;
|
||||
sun_visible: boolean;
|
||||
moon_visible: boolean;
|
||||
ground_atmosphere_enabled: boolean;
|
||||
sun_color: string;
|
||||
shadow_darkness: number;
|
||||
shadow_soft: boolean;
|
||||
terrain_maximum_screen_space_error: number;
|
||||
resolution_scale: number;
|
||||
fxaa_enabled: boolean;
|
||||
hdr_enabled: boolean;
|
||||
exposure: number;
|
||||
tonemapper: "PBR_NEUTRAL" | "ACES" | "FILMIC" | "REINHARD" | "MODIFIED_REINHARD";
|
||||
bloom_enabled: boolean;
|
||||
bloom_contrast: number;
|
||||
bloom_brightness: number;
|
||||
bloom_sigma: number;
|
||||
bloom_step_size: number;
|
||||
ao_enabled: boolean;
|
||||
ao_intensity: number;
|
||||
ao_bias: number;
|
||||
ao_length_cap: number;
|
||||
};
|
||||
|
||||
export type MapCacheIntent = {
|
||||
enabled: boolean;
|
||||
no_overwrite: boolean;
|
||||
|
||||
@@ -23,6 +23,7 @@ export type {
|
||||
MapRuntimeConfiguration,
|
||||
MapRuntimeState,
|
||||
MapVisualSettings,
|
||||
MapSceneEffects,
|
||||
} from "./contracts.js";
|
||||
export {
|
||||
advanceGhostPins,
|
||||
@@ -38,3 +39,5 @@ export {
|
||||
readSafeErrorCode,
|
||||
withProviderState,
|
||||
} from "./runtime.js";
|
||||
|
||||
export {DEFAULT_MAP_SCENE_EFFECTS} from "./sceneEffects.js";
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import type {MapSceneContext, MapSceneEffects, MapVisualSettings} from './contracts.js';
|
||||
|
||||
/** Native Cesium 1.147 defaults; adding a settings window does not change the scene. */
|
||||
export const DEFAULT_MAP_SCENE_EFFECTS: Readonly<MapSceneEffects> = Object.freeze({
|
||||
skybox_enabled:true, sun_visible:true, moon_visible:true, ground_atmosphere_enabled:true,
|
||||
sun_color:'#ffffff', shadow_darkness:0.3, shadow_soft:false,
|
||||
terrain_maximum_screen_space_error:2, resolution_scale:1, fxaa_enabled:false,
|
||||
hdr_enabled:false, exposure:1, tonemapper:'PBR_NEUTRAL',
|
||||
bloom_enabled:false, bloom_contrast:128, bloom_brightness:-0.3, bloom_sigma:2, bloom_step_size:1,
|
||||
ao_enabled:false, ao_intensity:3, ao_bias:0.1, ao_length_cap:0.26,
|
||||
});
|
||||
|
||||
/** Mutates visual properties only: never touches sources, camera, cache or domain objects. */
|
||||
export function applyMapSceneEffects({Cesium,viewer}:Pick<MapSceneContext,'Cesium'|'viewer'>,s:MapVisualSettings):void {
|
||||
const scene=viewer.scene, stages=scene.postProcessStages;
|
||||
if(s.skybox_enabled!==undefined && scene.skyBox)scene.skyBox.show=s.skybox_enabled;
|
||||
if(s.sun_visible!==undefined && scene.sun)scene.sun.show=s.sun_visible;
|
||||
if(s.moon_visible!==undefined && scene.moon)scene.moon.show=s.moon_visible;
|
||||
if(s.ground_atmosphere_enabled!==undefined)scene.globe.showGroundAtmosphere=s.ground_atmosphere_enabled;
|
||||
if(s.sun_color!==undefined)scene.light.color=Cesium.Color.fromCssColorString(s.sun_color)??Cesium.Color.WHITE;
|
||||
if(s.shadow_darkness!==undefined)viewer.shadowMap.darkness=s.shadow_darkness;
|
||||
if(s.shadow_soft!==undefined)viewer.shadowMap.softShadows=s.shadow_soft;
|
||||
if(s.terrain_maximum_screen_space_error!==undefined)scene.globe.maximumScreenSpaceError=s.terrain_maximum_screen_space_error;
|
||||
if(s.resolution_scale!==undefined)viewer.resolutionScale=s.resolution_scale;
|
||||
if(s.fxaa_enabled!==undefined)stages.fxaa.enabled=s.fxaa_enabled;
|
||||
if(s.hdr_enabled!==undefined)scene.highDynamicRange=s.hdr_enabled;
|
||||
if(s.exposure!==undefined)stages.exposure=s.exposure;
|
||||
if(s.tonemapper!==undefined)stages.tonemapper=Cesium.Tonemapper[s.tonemapper];
|
||||
if(s.bloom_enabled!==undefined)stages.bloom.enabled=s.bloom_enabled;
|
||||
if(s.bloom_contrast!==undefined)stages.bloom.uniforms.contrast=s.bloom_contrast;
|
||||
if(s.bloom_brightness!==undefined)stages.bloom.uniforms.brightness=s.bloom_brightness;
|
||||
if(s.bloom_sigma!==undefined)stages.bloom.uniforms.sigma=s.bloom_sigma;
|
||||
if(s.bloom_step_size!==undefined)stages.bloom.uniforms.stepSize=s.bloom_step_size;
|
||||
if(s.ao_enabled!==undefined)stages.ambientOcclusion.enabled=s.ao_enabled && Cesium.PostProcessStageLibrary.isAmbientOcclusionSupported(scene);
|
||||
if(s.ao_intensity!==undefined)stages.ambientOcclusion.uniforms.intensity=s.ao_intensity;
|
||||
if(s.ao_bias!==undefined)stages.ambientOcclusion.uniforms.bias=s.ao_bias;
|
||||
if(s.ao_length_cap!==undefined)stages.ambientOcclusion.uniforms.lengthCap=s.ao_length_cap;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {applyMapSceneEffects,DEFAULT_MAP_SCENE_EFFECTS} from '../dist/sceneEffects.js';
|
||||
|
||||
function context(supported=true){
|
||||
const viewer={resolutionScale:1,shadowMap:{},scene:{skyBox:{},sun:{},moon:{},globe:{},light:{},postProcessStages:{fxaa:{},bloom:{uniforms:{}},ambientOcclusion:{uniforms:{}}}}};
|
||||
const Cesium={Color:{fromCssColorString:value=>value,WHITE:'white'},Tonemapper:{ACES:'ACES',PBR_NEUTRAL:'PBR_NEUTRAL'},PostProcessStageLibrary:{isAmbientOcclusionSupported:()=>supported}};
|
||||
return {viewer,Cesium};
|
||||
}
|
||||
test('optional effects leave legacy consumers unchanged',()=>{
|
||||
const c=context(),before=structuredClone(c.viewer);applyMapSceneEffects(c,{});assert.deepEqual(c.viewer,before);
|
||||
});
|
||||
test('effects apply live and reset without changing camera or providers',()=>{
|
||||
const c=context();c.viewer.camera={position:'unchanged'};c.viewer.terrainProvider={id:'cache'};
|
||||
applyMapSceneEffects(c,{...DEFAULT_MAP_SCENE_EFFECTS,bloom_enabled:true,bloom_contrast:64,hdr_enabled:true,exposure:2,tonemapper:'ACES',ao_enabled:true,ao_intensity:6,sun_visible:false,resolution_scale:.7});
|
||||
const {scene}=c.viewer;
|
||||
assert.equal(scene.postProcessStages.bloom.enabled,true);assert.equal(scene.postProcessStages.bloom.uniforms.contrast,64);
|
||||
assert.equal(scene.postProcessStages.ambientOcclusion.uniforms.intensity,6);assert.equal(scene.postProcessStages.ambientOcclusion.enabled,true);
|
||||
assert.equal(scene.highDynamicRange,true);assert.equal(scene.postProcessStages.exposure,2);assert.equal(scene.postProcessStages.tonemapper,'ACES');
|
||||
assert.equal(scene.sun.show,false);assert.equal(c.viewer.resolutionScale,.7);
|
||||
applyMapSceneEffects(c,DEFAULT_MAP_SCENE_EFFECTS);
|
||||
assert.equal(scene.postProcessStages.bloom.enabled,false);assert.equal(scene.highDynamicRange,false);assert.equal(scene.sun.show,true);
|
||||
assert.deepEqual(c.viewer.camera,{position:'unchanged'});assert.deepEqual(c.viewer.terrainProvider,{id:'cache'});
|
||||
});
|
||||
test('unsupported ambient occlusion stays off',()=>{
|
||||
const c=context(false);applyMapSceneEffects(c,{ao_enabled:true});assert.equal(c.viewer.scene.postProcessStages.ambientOcclusion.enabled,false);
|
||||
});
|
||||
Reference in New Issue
Block a user