Fly me to the Moon

Can my flight simulator fly to the moon using CesiumJS?

I noticed a MOON ellipsoid, but I saw no examples in the sandcastles. Do there exist terrain tiles for the moon?

CesiumJS does have compute the positions for the sun and moon correctly based on the given time in the viewer, but those are just images, not geometry.

While Cesium ion does not have terrain data for the moon, if you have lunar terrain (perhaps from some open datasets that NASA publishes) you can upload those GeoTIFFs to Cesium ion, replace the ellipsoid with the moon’s ellipsoid, and visualize the moon instead of the Earth.

CesiumJS currently only supports one central body, see: https://github.com/AnalyticalGraphicsInc/cesium/issues/6419

Thanks Omar for the info.

Based on my findings I suspect it’s still not possible to “fly to the moon” via the camera, due to the moon being an image instead of 2nd ellipsoid, with the Earth being the sole ellipsoid in Cesium?

I’m new to Cesium and have tried a few different ways to “fly to the moon” and have only had success with replacing the Earth ellipsoid with Cesium.Ellipsoid.MOON. While this works, it’s not practical for our needs.

The simple sandcastle demo linked below is one of my attempts to “fly to the moon”, and it seems as though it does but there is no moon to be seen. Am I doing something wrong, or is this just not possible while still maintaining the Earth ellipsoid?

The simple code:

Blockquote
var viewer = new Cesium.Viewer(“cesiumContainer”);
viewer.scene.moon.show = true;
viewer.scene.camera.flyTo({
destination: Cesium.Simon1994PlanetaryPositions.computeMoonPositionInEarthInertialFrame(),
complete: function() {
console.log(“onComplete: Fly To Moon (flyto-moon)”);
}
});

Lastly, I found that this “MoonSpec.js” file (…\Specs\Scene\MoonSpec.js) contains a function lookAtMoon(camera, date). Could this be leveraged in any way?

Sandcastle demo:

I eventually found a method to master Sun and Moon in Cesium.
Have fun! Link

Move slightly away from initial position to see the lines pointing to Sun and Moon; start clock to see them moving (updated only twice per seconds to avoid overloading). Play with the slider to change the zoom.

The trick to avoid nonsense results from Simon1994PlanetaryPositions:

var specificTime = Cesium.JulianDate.fromDate(new Date(Date.UTC(2024, 7, 31, 4, 0, 0)));
viewer.clock.currentTime = specificTime;
const icrfToFixed = new Cesium.Matrix3();
Cesium.Transforms.computeTemeToPseudoFixedMatrix(specificTime, icrfToFixed); // Time conversion
var moonPos = Cesium.Simon1994PlanetaryPositions.computeMoonPositionInEarthInertialFrame(specificTime);
Cesium.Matrix3.multiplyByVector(icrfToFixed, moonPos, moonPos); // Reference conversion

Don’t ask my why and how… I just reverse engineered undocumented lookAtMoon() function