cesium-native 0.53.0
Loading...
Searching...
No Matches
GltfModifier.h
1#pragma once
2
3#include <Cesium3DTilesSelection/GltfModifierState.h>
4#include <Cesium3DTilesSelection/Tile.h>
5#include <Cesium3DTilesSelection/TileLoadRequester.h>
6#include <CesiumAsync/AsyncSystem.h>
7#include <CesiumAsync/Future.h>
8#include <CesiumGltf/Model.h>
9
10#include <spdlog/fwd.h>
11
12#include <memory>
13#include <optional>
14
15namespace CesiumAsync {
16
17class IAssetAccessor;
18
19} // namespace CesiumAsync
20
21namespace Cesium3DTilesSelection {
22
23class TilesetMetadata;
24class TilesetContentManager;
25
38 int64_t version;
39
44
48 std::shared_ptr<CesiumAsync::IAssetAccessor> pAssetAccessor;
49
53 std::shared_ptr<spdlog::logger> pLogger;
54
59
64 glm::dmat4 tileTransform;
65};
66
76
101class GltfModifier : private TileLoadRequester {
102public:
113 std::optional<int64_t> getCurrentVersion() const;
114
121 bool isActive() const;
122
133 void trigger();
134
150
159 bool needsWorkerThreadModification(const Tile& tile) const;
160
169 bool needsMainThreadModification(const Tile& tile) const;
170
171protected:
172 GltfModifier();
173 virtual ~GltfModifier();
174
198 const CesiumAsync::AsyncSystem& asyncSystem,
199 const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
200 const std::shared_ptr<spdlog::logger>& pLogger,
201 const TilesetMetadata& tilesetMetadata,
202 const Tile& rootTile);
203
204private:
213 TilesetContentManager& contentManager,
214 const TilesetMetadata& tilesetMetadata,
215 const Tile& rootTile);
216
223 void onUnregister(TilesetContentManager& contentManager);
224
238 void onOldVersionContentLoadingComplete(const Tile& tile);
239
251 void onWorkerThreadApplyComplete(const Tile& tile);
252
253 // TileLoadRequester implementation
254 double getWeight() const override;
255 bool hasMoreTilesToLoadInWorkerThread() const override;
256 const Tile* getNextTileToLoadInWorkerThread() override;
257 bool hasMoreTilesToLoadInMainThread() const override;
258 const Tile* getNextTileToLoadInMainThread() override;
259
260 std::optional<int64_t> _currentVersion;
261
262 const Tile* _pRootTile;
263
264 // Ideally these would be weak pointers, but we don't currently have a good
265 // way to do that.
266 std::vector<Tile::ConstPointer> _workerThreadQueue;
267 std::vector<Tile::ConstPointer> _mainThreadQueue;
268
269 friend class TilesetContentManager;
270 friend class MockTilesetContentManagerForGltfModifier;
271};
272
273} // namespace Cesium3DTilesSelection
bool needsMainThreadModification(const Tile &tile) const
Checks if the given tile needs to be processed by this GltfModifier in the main thread.
bool needsWorkerThreadModification(const Tile &tile) const
Checks if the given tile needs to be processed by this GltfModifier in a worker thread.
virtual CesiumAsync::Future< std::optional< GltfModifierOutput > > apply(GltfModifierInput &&input)=0
Implement this method to apply custom modification to a glTF model. It is called by the Tileset from ...
std::optional< int64_t > getCurrentVersion() const
Gets the current version number, or std::nullopt if the GltfModifier is currently inactive.
void trigger()
Call this the first time to activate this GltfModifier after it has been constructed in its default n...
bool isActive() const
Checks if this GltfModifier is active.
virtual CesiumAsync::Future< void > onRegister(const CesiumAsync::AsyncSystem &asyncSystem, const std::shared_ptr< CesiumAsync::IAssetAccessor > &pAssetAccessor, const std::shared_ptr< spdlog::logger > &pLogger, const TilesetMetadata &tilesetMetadata, const Tile &rootTile)
Notifies this instance that it has been registered with a Tileset.
TileLoadRequester() noexcept
Constructs a new instance.
A tile in a Tileset.
Definition Tile.h:123
Holds the metadata associated with a Tileset or an external tileset. This holds all of the fields of ...
A system for managing asynchronous requests and tasks.
Definition AsyncSystem.h:36
A value that will be available in the future, as produced by AsyncSystem.
Definition Future.h:29
Provides asynchronous access to assets, usually files downloaded via HTTP.
Classes that implement the 3D Tiles standard.
Classes that support asynchronous operations.
The input to GltfModifier::apply.
int64_t version
The version of the GltfModifier, as returned by GltfModifier::getCurrentVersion at the start of the m...
CesiumAsync::AsyncSystem asyncSystem
The async system that can be used to do work in threads.
const CesiumGltf::Model & previousModel
The model to be modified.
std::shared_ptr< CesiumAsync::IAssetAccessor > pAssetAccessor
An asset accessor that can be used to obtain additional assets.
glm::dmat4 tileTransform
The transformation of the model's coordinates to the tileset's coordinate system.
std::shared_ptr< spdlog::logger > pLogger
The logger.
The output of GltfModifier::apply.
CesiumGltf::Model modifiedModel
The new, modified model.
This class is not meant to be instantiated directly. Use Model instead.
Definition Model.h:14