Skip to content

Commit

Permalink
refactor(web): handle cesium private property of shadow map (#531)
Browse files Browse the repository at this point in the history
  • Loading branch information
airslice authored Jun 29, 2023
1 parent de536e8 commit ae4cdd6
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions web/src/beta/lib/core/engines/Cesium/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,20 @@ export default ({

// shadow map
type ShadowMapBias = {
polygonOffsetFactor: number;
polygonOffsetUnits: number;
normalOffsetScale: number;
normalShading: boolean;
normalShadingSmooth: number;
depthBias: number;
polygonOffsetFactor?: number;
polygonOffsetUnits?: number;
normalOffsetScale?: number;
normalShading?: boolean;
normalShadingSmooth?: number;
depthBias?: number;
};

useEffect(() => {
const shadowMap = cesium?.current?.cesiumElement?.shadowMap as
| (ShadowMap & {
_terrainBias: ShadowMapBias;
_pointBias: ShadowMapBias;
_primitiveBias: ShadowMapBias;
_terrainBias?: ShadowMapBias;
_pointBias?: ShadowMapBias;
_primitiveBias?: ShadowMapBias;
})
| undefined;
if (!shadowMap) return;
Expand Down Expand Up @@ -183,9 +183,30 @@ export default ({
normalShadingSmooth: 0.1,
depthBias: 0.0005,
};
Object.assign(shadowMap._terrainBias, defaultTerrainBias);
Object.assign(shadowMap._primitiveBias, defaultPrimitiveBias);
Object.assign(shadowMap._pointBias, defaultPointBias);

if (!shadowMap._terrainBias) {
if (import.meta.env.DEV) {
throw new Error("`shadowMap._terrainBias` could not found");
}
} else {
Object.assign(shadowMap._terrainBias, defaultTerrainBias);
}

if (!shadowMap._primitiveBias) {
if (import.meta.env.DEV) {
throw new Error("`shadowMap._primitiveBias` could not found");
}
} else {
Object.assign(shadowMap._primitiveBias, defaultPrimitiveBias);
}

if (!shadowMap._pointBias) {
if (import.meta.env.DEV) {
throw new Error("`shadowMap._pointBias` could not found");
}
} else {
Object.assign(shadowMap._pointBias, defaultPointBias);
}
}, [
property?.atmosphere?.softShadow,
property?.atmosphere?.shadowDarkness,
Expand Down

0 comments on commit ae4cdd6

Please sign in to comment.