# Unigine::Plugins::Cesium Class (CPP) **Header:** #include This class is the interface of the [Cesium](../../../../code/plugins/cesium/index_cpp.md) plugin, a 3D Tiles client: it streams elevation, imagery, and pre-textured geometry from *[Cesium ion](https://cesium.com/platform/cesium-ion/)* for wherever the camera is, and renders them on a globe inside UNIGINE. Cesium positions data in Earth-centered, Earth-fixed (ECEF) coordinates; for precision the plugin keeps a local frame whose origin sits on the surface near the camera, converts the data into that frame for rendering, and moves the origin as the camera travels (rebasing). The geodetic position of that local origin is the anchor, owned by the *Geodetics* plugin and driven by *Cesium*. A double-precision engine build is required for a georeferenced globe. The host application supplies the camera via the **[getPlayer()](../../../...md#getPlayer_Player)** property; the plugin streams tiles around it and drives the anchor, unless the application declares itself a follower (see the **[isAnchorAutoUpdate()](../../../...md#isAnchorAutoUpdate_int)** property). High-detail [terrain insets](../../../../code/plugins/cesium/insets.md) listed in the configuration activate automatically when the camera comes within their activation distance, or on demand; the anchor stays pinned to the active inset. The streaming behavior is defined by the *[CesiumConfig](../../../../api/library/plugins/cesium/class.cesiumconfig_cpp.md)* class: after editing the configuration, apply it for the changes to take effect without restarting the plugin. Streamed assets require attribution, which the plugin exposes as a list of ready-made HTML credits for the application to display. The plugin always loads, even without an access token or a usable data source: in that case the globe stays idle, which is a normal state rather than an error. ## Cesium Class ### Enums ## INSET_STATUS Verdict on a world or terrain node offered as a [terrain inset](../../../../code/plugins/cesium/insets.md): either the inset is usable, or the reason it cannot be used. | Name | Description | |---|---| | **INSET_STATUS_OK** = 0 | The inset is usable. | | **INSET_STATUS_UNREADABLE** = 1 | The world file could not be read, the node is null, or the inset index is out of range. | | **INSET_STATUS_NO_TERRAIN** = 2 | The world contains no *[ObjectLandscapeTerrain](../../../../api/library/objects/landscape_terrain/class.objectlandscapeterrain_cpp.md)* node. Never returned for a node offered directly: such a node is the terrain itself. | | **INSET_STATUS_NO_GEOREFERENCE** = 3 | The terrain was not generated by *[Sandworm](../../../../editor2/sandworm/index.md)*: it does not carry the geodetic origin data *Sandworm* writes. | | **INSET_STATUS_NOT_TOPOCENTRIC** = 4 | The terrain was generated with a projection instead of the built-in topocentric one. Cesium places tiles tangentially, so only a topocentric terrain can line up with them; regenerate the terrain with the built-in topocentric projection to use it as an inset. | ### Members ## void setPlayer ( const Ptr < Player >& player ) Sets a new player (camera) the plugin streams tiles for and follows with the anchor. Without a player the anchor never moves and no tiles are selected. Pass a null player when no view is active: a camera that is not being rendered through makes the plugin stream tiles for nobody to look at. The camera frustum must be opened to planetary distances. ### Arguments - *const [Ptr](../../../../api/library/common/class.ptr_cpp.md)<[Player](../../../../api/library/players/class.player_cpp.md)>&* **player** - The player the plugin streams for ## Ptr < Player > getPlayer () const Returns the current player (camera) the plugin streams tiles for and follows with the anchor. Without a player the anchor never moves and no tiles are selected. Pass a null player when no view is active: a camera that is not being rendered through makes the plugin stream tiles for nobody to look at. The camera frustum must be opened to planetary distances. ### Return value Current player the plugin streams for ## void setAnchorAutoUpdate ( bool update ) Sets a new value indicating if the plugin updates the anchor automatically. When enabled (default), the plugin owns the anchor: it rebases the local frame as the camera travels and moves the anchor when a terrain inset is activated. Disable it on a follower whose anchor is set externally, such as a [Syncker](../../../../code/plugins/syncker/index.md) slave: the plugin then never moves the anchor, and **[setActiveInset()](../../../...md#setActiveInset_int_bool)** is refused. ### Arguments - *bool* **update** - Set **true** to enable automatic updating of the anchor by the plugin; **false** - to disable it. ## bool isAnchorAutoUpdate () const Returns the current value indicating if the plugin updates the anchor automatically. When enabled (default), the plugin owns the anchor: it rebases the local frame as the camera travels and moves the anchor when a terrain inset is activated. Disable it on a follower whose anchor is set externally, such as a [Syncker](../../../../code/plugins/syncker/index.md) slave: the plugin then never moves the anchor, and **[setActiveInset()](../../../...md#setActiveInset_int_bool)** is refused. ### Return value **true** if automatic updating of the anchor by the plugin is enabled ; otherwise **false**. ## int getNumInsets () const Returns the current number of terrain insets registered with the plugin. This is the inset count of the configuration as it stood when the configuration was last applied: entries added or removed through the API count only after the next apply. An index means the same slot here and in the configuration. ### Return value Current number of registered terrain insets ## int getActiveInsetIndex () const Returns the current index of the currently active (swapped-in) terrain inset, or -1 if none is active. Only one inset can be active at a time; a custom inset activated by node rather than by index is also reported as -1. ### Return value Current index of the currently active inset ## void setUseConfigInsets ( bool insets ) Sets a new value indicating if the terrains of the insets listed in the configuration are loaded. When enabled (default), the terrain of every enabled and usable inset is brought into the engine on the first update of the plugin, all at once, so that flying to any of them later costs nothing. The loaded terrains are hidden, engine-lifetime copies that survive world switches and cannot be unloaded, so an application that only edits the inset worlds should disable this option before the first update of the plugin. Insets are registered and validated either way: the option only decides whether their terrains are loaded, and it only affects loads still to come. ### Arguments - *bool* **insets** - Set **true** to enable loading of the terrains of the configured insets; **false** - to disable it. ## bool isUseConfigInsets () const Returns the current value indicating if the terrains of the insets listed in the configuration are loaded. When enabled (default), the terrain of every enabled and usable inset is brought into the engine on the first update of the plugin, all at once, so that flying to any of them later costs nothing. The loaded terrains are hidden, engine-lifetime copies that survive world switches and cannot be unloaded, so an application that only edits the inset worlds should disable this option before the first update of the plugin. Insets are registered and validated either way: the option only decides whether their terrains are loaded, and it only affects loads still to come. ### Return value **true** if loading of the terrains of the configured insets is enabled ; otherwise **false**. ## int getNumLoadedTiles () const Returns the current number of tiles currently loaded (held in memory) by the streaming client. ### Return value Current number of loaded tiles ## int getNumRenderTiles () const Returns the current number of tiles actually rendered for the current view. ### Return value Current number of rendered tiles ## int getNumLoadingTiles () const Returns the current number of tiles currently being streamed in. The tile counters, rather than the streaming flag, are what tells you tiles are arriving. ### Return value Current number of tiles being loaded ## int getNumVisitedTiles () const Returns the current number of tiles visited during the traversal of the tile tree for the view. ### Return value Current number of visited tiles ## int getNumCulledTiles () const Returns the current number of tiles culled during the traversal of the tile tree (see the frustum and fog culling options of the configuration). ### Return value Current number of culled tiles ## int getMaxTileDepth () const Returns the current maximum reached depth of the tile tree. The dataset is served as a tree of tiles: coarse at the root, each tile splitting into finer children. ### Return value Current maximum reached depth of the tile tree ## float getLoadProgress () const Returns the current progress of tile streaming for the view. ### Return value Current tile streaming progress ## int getUsedMemoryMb () const Returns the current amount of memory used by the loaded tiles, in megabytes (see the memory usage limit of the configuration). ### Return value Current amount of memory used by the loaded tiles, in megabytes ## int getNumCredits () const Returns the current number of attribution credits for the currently streamed assets. Each enabled asset requires attribution, which arrives as ready-made HTML: data provider names, the *Cesium ion* logo, and the like. The application is expected to display the credits (see **[getCreditHtml()](../../../...md#getCreditHtml_int_cstr)**). ### Return value Current number of attribution credits ## unsigned long long getCreditsHash () const Returns the current hash of the current set of credits. The hash changes whenever the set changes, so the application rebuilds its attribution UI on a hash change instead of comparing the strings every frame. The hash does not depend on the order of the credits, and a credit that stays in the set keeps its index, so the indices and the strings remain valid for as long as the hash matches. ### Return value Current hash of the current set of credits ## bool isStreaming () const Returns the current Returns a value indicating if the globe is streaming tiles: an access token and a usable tile source are available, and the tilesets are built. Idle is a normal state rather than an error: a fresh setup with no token yet simply streams nothing until the configuration is completed and applied (see **[applyConfig()](../../../...md#applyConfig_bool)**). ### Return value **true** if the globe is streaming tiles; otherwise **false**. --- ## Ptr < Node > getActiveInsetNode ( ) const Returns the terrain node behind the currently active inset, whether it comes from a configuration slot or was supplied by the application via **[setCustomActiveInset()](../../../...md#setCustomActiveInset_Node_bool)**. Since **[getActiveInsetIndex()](../../../...md#getActiveInsetIndex_int)** reports -1 both when nothing is active and when a custom inset is active, this is the way to tell the two apart. ### Return value Terrain node behind the active inset, or a null node when no inset is active. ## bool isInsetActive ( int index ) const Returns a value indicating if the terrain inset with the given index is currently the active (swapped-in) one. Only one inset can be active at a time. ### Arguments - *int* **index** - Index of the inset, in the [0; **[getNumInsets()](../../../...md#getNumInsets_int)**) range. ### Return value true if the inset with the given index is currently the active one; otherwise, false. ## Cesium::INSET_STATUS getInsetStatus ( int index ) const Returns the registration status of the inset with the given index: what inspecting its world file found, either that the inset is usable or the reason it cannot be used. *[INSET_STATUS_UNREADABLE](#INSET_STATUS_UNREADABLE)* is also returned when the index is out of range. Whether the inset is enabled does not affect the status. ### Arguments - *int* **index** - Index of the inset, in the [0; **[getNumInsets()](../../../...md#getNumInsets_int)**) range. ### Return value Status of the inset: one of the **[INSET_STATUS_*](../../../...md#INSET_STATUS_OK)** values. ## Ptr < Node > getInsetNode ( int index ) const Returns the terrain node of the registered inset with the given index. Terrains of the enabled, usable insets are loaded on the first update of the plugin (see **[isUseConfigInsets()](../../../...md#isUseConfigInsets_int)**); a null node is returned for an inset whose terrain has not been loaded, is disabled, or whose world is not usable. ### Arguments - *int* **index** - Index of the inset, in the [0; **[getNumInsets()](../../../...md#getNumInsets_int)**) range. ### Return value Terrain node of the inset. ## bool getInsetGeoPosition ( int index , Math:: dvec3 & geo ) const Outputs the geodetic origin of the registered inset with the given index, as carried by the terrain node of the inset. ### Arguments - *int* **index** - Index of the inset, in the [0; **[getNumInsets()](../../../...md#getNumInsets_int)**) range. - *Math::[dvec3](../../../../api/library/math/class.dvec3_cpp.md) &* **geo** - Output value: the geodetic origin of the inset (latitude, longitude, altitude). ### Return value true on success; otherwise, false. ## int findNearbyInset ( const Math:: dvec3 & geodetic_position ) const Returns the inset near the given geodetic position: the closest registered inset whose activation distance covers it. This is the same test the automatic proximity activation performs, so an application that is about to place the camera somewhere can learn in advance which inset expects the anchor there. ### Arguments - *const Math::[dvec3](../../../../api/library/math/class.dvec3_cpp.md) &* **geodetic_position** - Geodetic position as (latitude, longitude, altitude), in degrees and meters. ### Return value Index of the closest inset whose activation distance covers the position, or -1 if there is none. ## Cesium::INSET_STATUS checkInsetWorld ( const char * world_path ) const Checks if the given world can serve as a terrain inset, without registering it. The file is inspected exactly the way registration inspects it, so a configuration editor can show what is wrong with a path before anyone tries to fly there. ### Arguments - *const char ** **world_path** - Path to the `*.world` file to inspect. ### Return value *[INSET_STATUS_OK](#INSET_STATUS_OK)* if the world can serve as a terrain inset; otherwise, the reason it cannot. ## Cesium::INSET_STATUS checkInsetNode ( const Ptr < Node > & node ) const Checks if the given terrain node, already present in the world, can serve as a terrain inset. This is the verdict **[setCustomActiveInset()](../../../...md#setCustomActiveInset_Node_bool)** itself acts on, so the application can ask before offering the node and word the refusal the same way. A null node gives *[INSET_STATUS_UNREADABLE](#INSET_STATUS_UNREADABLE)*; *[INSET_STATUS_NO_TERRAIN](#INSET_STATUS_NO_TERRAIN)* never comes out of this check, as the node offered is the terrain itself. ### Arguments - *const [Ptr](../../../../api/library/common/class.ptr_cpp.md)<[Node](../../../../api/library/nodes/class.node_cpp.md)> &* **node** - Terrain node to inspect. ### Return value *[INSET_STATUS_OK](#INSET_STATUS_OK)* if the node can serve as a terrain inset; otherwise, the reason it cannot. ## bool setActiveInset ( int index ) Activates the registered inset with the given index, wherever the camera is. The terrain of an inset is authored around its own origin, so activation moves the anchor to that origin; the call is refused, with the reason logged, when the plugin does not drive the anchor (see **[isAnchorAutoUpdate()](../../../...md#isAnchorAutoUpdate_int)**), when the world of the inset is not usable, or when its terrain has not been loaded. Activating an inset manually stops the automatic proximity activation until **[clearActiveInset()](../../../...md#clearActiveInset_void)** is called. ### Arguments - *int* **index** - Index of the inset, in the [0; **[getNumInsets()](../../../...md#getNumInsets_int)**) range. ### Return value true if the inset was activated; otherwise, false. ## bool setCustomActiveInset ( const Ptr < Node > & node ) Treats an already loaded terrain node as the active inset: the global tiles are cut out of its bounds and streamed around it, without loading a world, without a distance check, and without touching the anchor, as the application owns the frame in this case. This suits a terrain that is present in the open world rather than listed in the configuration, which is how an editing session previews one. The call is refused with a warning if the node is not a *Sandworm*-generated topocentric terrain (see **[checkInsetNode()](../../../...md#checkInsetNode_Node_int)**). Automatic proximity activation stops until **[clearActiveInset()](../../../...md#clearActiveInset_void)** is called. The node is dropped when its world is torn down, so set it again after a world switch. ### Arguments - *const [Ptr](../../../../api/library/common/class.ptr_cpp.md)<[Node](../../../../api/library/nodes/class.node_cpp.md)> &* **node** - Loaded *Sandworm*-generated terrain node to use as the active inset. ### Return value true if the node was accepted; otherwise, false. ## void clearActiveInset ( ) Deactivates the currently active terrain inset, if any, and resumes the automatic proximity activation: the closest inset whose activation distance covers the camera activates again. ## bool hasActiveInset ( ) const Returns a value indicating if any terrain inset is currently active, either a registered or a custom one. While an inset is active, the anchor stays pinned to its origin and the automatic rebasing is suspended. ### Return value true if a terrain inset is currently active; otherwise, false. ## const char * getCreditHtml ( int index ) const Returns the attribution of the credit with the given index, as the ready-made HTML handed over by the streaming client. The list changes on its own schedule, so an index kept from an earlier frame can be stale: watch **[getCreditsHash()](../../../...md#getCreditsHash_ullong)** and rebuild on a change. ### Arguments - *int* **index** - Index of the credit, in the [0; **[getNumCredits()](../../../...md#getNumCredits_int)**) range. ### Return value HTML of the credit, or an empty string if the index is out of range. ## bool isCreditOnScreen ( int index ) const Returns a value indicating if the credit with the given index is required by the data provider to be displayed directly on the screen. Credits without this requirement may be shown in a separate attribution list or popover instead. ### Arguments - *int* **index** - Index of the credit, in the [0; **[getNumCredits()](../../../...md#getNumCredits_int)**) range. ### Return value true if the credit must be displayed on the screen; otherwise, false. ## void renderTileBounds ( bool depth_test = false ) Requests the debug overlay - the tile bounding volumes and the inset bounds - for the current frame. The request covers one frame and is consumed by the next update of the plugin, so an application that wants the bounds on screen calls this method every frame. The overlay is drawn through the engine visualizer, and turning the visualizer on is the application�s job (the show_visualizer console variable). ### Arguments - *bool* **depth_test** - true to draw the bounds with depth testing, hidden behind closer geometry; false to draw them on top of everything. ## CesiumConfig * getConfig ( ) Returns the live configuration of the plugin. Edit it through the *[CesiumConfig](../../../../api/library/plugins/cesium/class.cesiumconfig_cpp.md)* interface and call **[applyConfig()](../../../...md#applyConfig_bool)** for the changes to take effect. This is also the way the editor's Cesium panel configures the plugin. ### Return value Configuration of the plugin. ## bool applyConfig ( ) Applies the current configuration. The configuration is validated first, so the warnings reflect what is actually about to be built; the tilesets are then rebuilt, but only when a setting they read has changed: the access token, the asset list, the streaming settings, the tile masks, or the cache settings. A rebuild drops every streamed tile and re-streams. Edits the tilesets do not read, such as the inset list or the log level, are applied instantly without dropping anything. ### Return value true if the globe is streaming after the apply; otherwise, false.