CesiumGS / cesium-unreal

Bringing the 3D geospatial ecosystem to Unreal Engine
https://cesium.com/platform/cesium-for-unreal/
Apache License 2.0
916 stars 292 forks source link

Add support for multiple Cesium ion servers #1309

Closed kring closed 9 months ago

kring commented 9 months ago

This is useful for self-hosted Cesium ion, and also makes it easy to switch between multiple SaaS accounts.

Initially, the Cesium panel looks much the same as before:

image

Small differences:

  1. There's a dropdown at the top for selecting a server.
  2. The "status" (what user we're connected to Cesium ion as) is part of the dropdown ("not connected" in the screenshot above) rather than in a separate status line at the bottom.
  3. The status line at the bottom has been replaced with the plugin version, which opens a browser with the changelog when clicked.

After connecting, it looks like this:

image

Note the name of the signed-in user (CesiumJS) in the dropdown at the top.

Cesium ion servers are represented as Unreal "data assets" of type CesiumIonServer. Click the folder and magnifying glass icon next to the dropdown to browse to the asset for the selected server in the Content Browser:

image image

Double-click the CesiumIonSaaS server definition to edit it: image

To add a server, we can right-click on the existing one and choose "Duplicate". Or Add -> Miscellaneous -> Data Asset and then select CesiumIonServer. Edit the server properties as desired: image

(Note that I've specified the normal SaaS API URL and OAuth application ID so that I can actually use this server. But a user with a self-hosted Cesium ion would specify the appropriate values for their server.)

The new server shows up in the dropdown:

image

When I select it, the panel shows that that we are not currently connected to this server. We remain connected to the other one, though. Click the Connect to Cesium ion button to sign in to this server, too. The dropdown shows that we're connected to both:

image

If we close Unreal now, and reopen it, Cesium for Unreal will automatically "resume" both connections.

The toolbar buttons work much the same as before. The Add button opens the "Cesium ion Assets" panel, which has its own dropdown to select the server. Changing the current server on either panel also changes it on the other one (they always stay in sync):

image

The Upload button opens a web browser on the upload page of the current server. The Token button opens the token panel for the current server, and it now displays which server you're configuring the project default token for: image

The "Sign Out" button signs out of the currently selected server.

When we create a new Cesium3DTileset or CesiumIonRasterOverlay, it is configured to reference the currently selected server. This is a new property in the "Advanced" section of the object's properties:

image

This property replaces the old IonAssetEndpointUrl. When loading all levels that used this property, Cesium for Unreal will automatically create a corresponding server definition.

If there's a problem with the token, the token troubleshooting panel indicates which server is being used, and any "fixes" will apply to that server. image

When packaging a game, Unreal automatically embeds any CesiumIonServer data assets that are referenced by any of the levels. And these data assets include the server details as well as the project default token, so this information is shipped with the game. The login token is still stored in EditorPerProjectUserSettings.ini, so it is not shipped with the game (this is vitally important!)

cesium-concierge commented 9 months ago

Thanks for the pull request @kring!

Reviewers, don't forget to make sure that:

joseph-kaile commented 9 months ago
  1. connect to cesium ion.

  2. Open up CesiumIonSaaS data asset.

  3. change API to https://hello.cesium.com

  4. Close and reopen the project.

  5. the status will say connecting... and also show the full quick add panel.

I think it should show the login panel while connecting.

joseph-kaile commented 9 months ago
  1. Create a new CesiumIonSaaS data asset and connect.
  2. Add a Cesium World Terrain + Bing Maps Aerial imagery.
  3. (Force) Delete the new CesiumIonSaaS data asset.

An error message will appear and the Server Selector widget causes an error.

Doesn't happen if you skip step 2.

j9liu commented 9 months ago

Confirmed that when you open an old level for the first time, it will try to use the current server instance (as opposed to the intended default ion server). Maybe you could find / create the default ion server if this happens?

kring commented 9 months ago

Alright I think I've addressed all of the feedback (thanks for the thorough review!) and this is working well.

joseph-kaile commented 9 months ago

Works well, but I found one bug:

pIonObject was not valid in CesiumIonTokenTroubleshooting::canConnectToCesiumIon()

Steps to reproduce:

  1. Open CesiumIonSaaS.

  2. Clear the Default Cesium ion Access Token and Token ID.

  3. Open 04_MAIN_CesiumSublevels

  4. The ion Token Troubleshooting panel should open.

  5. Create a new token. The next ion Token Troubleshooting panel asks you to authorize the project default token.

  6. Reopen Open 04_MAIN_CesiumSublevels

  7. The Save Content window appears, asking you to save CesiumIonSaaS.

  8. Hit Dont Save.

  9. The error should appear.

kring commented 9 months ago

@joseph-kaile I think I've addressed that. The token troubleshooting panel now holds a TWeakObjectPtr to the tileset or overlay, so we can more reliably detect if it's unloaded while the panel is open.

joseph-kaile commented 9 months ago

@joseph-kaile I think I've addressed that. The token troubleshooting panel now holds a TWeakObjectPtr to the tileset or overlay, so we can more reliably detect if it's unloaded while the panel is open.

I verified that it fixed the issue.

j9liu commented 9 months ago

If there's no other issues @joseph-kaile or @kring, I'll merge once CI passes. Thanks!