This repository has been archived by the owner on Apr 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/reearth/reearth-web into cu…
…rrent-location
- Loading branch information
Showing
23 changed files
with
366 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "reearth-web", | ||
"version": "0.12.0", | ||
"version": "0.13.0", | ||
"description": "", | ||
"repository": "[email protected]:reearth/reearth-web.git", | ||
"author": "reearth", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
src/components/molecules/Visualizer/Engine/Cesium/core/Globe.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { | ||
ArcGISTiledElevationTerrainProvider, | ||
CesiumTerrainProvider, | ||
EllipsoidTerrainProvider, | ||
IonResource, | ||
TerrainProvider, | ||
} from "cesium"; | ||
import { pick } from "lodash-es"; | ||
import { useMemo } from "react"; | ||
import { Globe as CesiumGlobe } from "resium"; | ||
|
||
import { objKeys } from "@reearth/util/util"; | ||
|
||
import type { SceneProperty, TerrainProperty } from "../../ref"; | ||
|
||
export type Props = { | ||
property?: SceneProperty; | ||
cesiumIonAccessToken?: string; | ||
}; | ||
|
||
export default function Globe({ property, cesiumIonAccessToken }: Props): JSX.Element | null { | ||
const terrainProperty = useMemo( | ||
(): TerrainProperty => ({ | ||
...property?.terrain, | ||
...pick(property?.default, terrainPropertyKeys), | ||
}), | ||
[property?.terrain, property?.default], | ||
); | ||
|
||
const terrainProvider = useMemo((): TerrainProvider | undefined => { | ||
const opts = { | ||
terrain: terrainProperty?.terrain, | ||
terrainType: terrainProperty?.terrainType, | ||
terrainCesiumIonAccessToken: | ||
terrainProperty?.terrainCesiumIonAccessToken || cesiumIonAccessToken, | ||
terrainCesiumIonAsset: terrainProperty?.terrainCesiumIonAsset, | ||
terrainCesiumIonUrl: terrainProperty?.terrainCesiumIonUrl, | ||
}; | ||
const provider = opts.terrain ? terrainProviders[opts.terrainType || "cesium"] : undefined; | ||
return (typeof provider === "function" ? provider(opts) : provider) ?? defaultTerrainProvider; | ||
}, [ | ||
terrainProperty?.terrain, | ||
terrainProperty?.terrainType, | ||
terrainProperty?.terrainCesiumIonAccessToken, | ||
terrainProperty?.terrainCesiumIonAsset, | ||
terrainProperty?.terrainCesiumIonUrl, | ||
cesiumIonAccessToken, | ||
]); | ||
|
||
return ( | ||
<CesiumGlobe | ||
enableLighting={!!property?.atmosphere?.enable_lighting} | ||
showGroundAtmosphere={property?.atmosphere?.ground_atmosphere ?? true} | ||
atmosphereSaturationShift={property?.atmosphere?.surturation_shift} | ||
atmosphereHueShift={property?.atmosphere?.hue_shift} | ||
atmosphereBrightnessShift={property?.atmosphere?.brightness_shift} | ||
terrainProvider={terrainProvider} | ||
depthTestAgainstTerrain={!!terrainProperty.depthTestAgainstTerrain} | ||
terrainExaggerationRelativeHeight={terrainProperty.terrainExaggerationRelativeHeight} | ||
terrainExaggeration={terrainProperty.terrainExaggeration} | ||
/> | ||
); | ||
} | ||
|
||
const terrainPropertyKeys = objKeys<TerrainProperty>({ | ||
terrain: 0, | ||
terrainType: 0, | ||
terrainExaggeration: 0, | ||
terrainExaggerationRelativeHeight: 0, | ||
depthTestAgainstTerrain: 0, | ||
terrainCesiumIonAsset: 0, | ||
terrainCesiumIonAccessToken: 0, | ||
terrainCesiumIonUrl: 0, | ||
terrainUrl: 0, | ||
}); | ||
|
||
const defaultTerrainProvider = new EllipsoidTerrainProvider(); | ||
|
||
const terrainProviders: { | ||
[k in NonNullable<TerrainProperty["terrainType"]>]: | ||
| TerrainProvider | ||
| (( | ||
opts: Pick< | ||
TerrainProperty, | ||
"terrainCesiumIonAccessToken" | "terrainCesiumIonAsset" | "terrainCesiumIonUrl" | ||
>, | ||
) => TerrainProvider | null); | ||
} = { | ||
cesium: ({ terrainCesiumIonAccessToken }) => | ||
// https://github.com/CesiumGS/cesium/blob/main/Source/Core/createWorldTerrain.js | ||
new CesiumTerrainProvider({ | ||
url: IonResource.fromAssetId(1, { | ||
accessToken: terrainCesiumIonAccessToken, | ||
}), | ||
requestVertexNormals: false, | ||
requestWaterMask: false, | ||
}), | ||
arcgis: () => | ||
new ArcGISTiledElevationTerrainProvider({ | ||
url: "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer", | ||
}), | ||
cesiumion: ({ terrainCesiumIonAccessToken, terrainCesiumIonAsset, terrainCesiumIonUrl }) => | ||
terrainCesiumIonAsset | ||
? new CesiumTerrainProvider({ | ||
url: | ||
terrainCesiumIonUrl || | ||
IonResource.fromAssetId(parseInt(terrainCesiumIonAsset, 10), { | ||
accessToken: terrainCesiumIonAccessToken, | ||
}), | ||
requestVertexNormals: true, | ||
}) | ||
: null, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.