Skip to content

Commit cd2ca69

Browse files
committed
Move GltfModifier version to an extension.
1 parent ad640dd commit cd2ca69

File tree

6 files changed

+94
-12
lines changed

6 files changed

+94
-12
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#pragma once
2+
3+
#include <Cesium3DTilesSelection/Library.h>
4+
#include <CesiumUtility/ExtensibleObject.h>
5+
6+
#include <optional>
7+
8+
namespace CesiumGltf {
9+
struct Model;
10+
}
11+
12+
namespace Cesium3DTilesSelection {
13+
14+
/** @brief An extension holding the "version" of a glTF produced by
15+
* {@link GltfModifier}.
16+
*/
17+
struct CESIUM3DTILESSELECTION_API GltfModifierVersionExtension
18+
: public CesiumUtility::ExtensibleObject {
19+
static std::optional<int32_t>
20+
getVersion(const CesiumGltf::Model& model) noexcept;
21+
22+
static void setVersion(CesiumGltf::Model& model, int32_t version) noexcept;
23+
24+
/**
25+
* @brief The original name of this type.
26+
*/
27+
static constexpr const char* TypeName = "GltfModifierVersionExtension";
28+
/**
29+
* @brief The official name of the extension. This should be the same as its
30+
* key in the `extensions` object.
31+
* */
32+
static constexpr const char* ExtensionName =
33+
"CESIUM_INTERNAL_gltf_modifier_version";
34+
35+
/**
36+
* @brief The current {@link GltfModifier} version number of the model.
37+
*/
38+
int32_t version = 0;
39+
40+
/**
41+
* @brief Calculates the size in bytes of this object, including the contents
42+
* of all collections, pointers, and strings. This will NOT include the size
43+
* of any extensions attached to the object. Calling this method may be slow
44+
* as it requires traversing the object's entire structure.
45+
*/
46+
int64_t getSizeBytes() const {
47+
int64_t accum = 0;
48+
accum += int64_t(sizeof(GltfModifierVersionExtension));
49+
accum += CesiumUtility::ExtensibleObject::getSizeBytes() -
50+
int64_t(sizeof(CesiumUtility::ExtensibleObject));
51+
return accum;
52+
}
53+
};
54+
55+
} // namespace Cesium3DTilesSelection
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <Cesium3DTilesSelection/GltfModifierVersionExtension.h>
2+
#include <CesiumGltf/Model.h>
3+
4+
namespace Cesium3DTilesSelection {
5+
6+
/* static */ std::optional<int32_t> GltfModifierVersionExtension::getVersion(
7+
const CesiumGltf::Model& model) noexcept {
8+
const auto* pExtension = model.getExtension<GltfModifierVersionExtension>();
9+
return pExtension ? std::make_optional(pExtension->version) : std::nullopt;
10+
}
11+
12+
/* static */ void GltfModifierVersionExtension::setVersion(
13+
CesiumGltf::Model& model,
14+
int32_t version) noexcept {
15+
auto* pExtension = model.getExtension<GltfModifierVersionExtension>();
16+
if (!pExtension) {
17+
pExtension = &model.addExtension<GltfModifierVersionExtension>();
18+
}
19+
pExtension->version = version;
20+
}
21+
22+
} // namespace Cesium3DTilesSelection

Cesium3DTilesSelection/src/Tile.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "TilesetContentManager.h"
22

33
#include <Cesium3DTilesSelection/GltfModifier.h>
4+
#include <Cesium3DTilesSelection/GltfModifierVersionExtension.h>
45
#include <Cesium3DTilesSelection/RasterMappedTo3DTile.h>
56
#include <Cesium3DTilesSelection/Tile.h>
67
#include <Cesium3DTilesSelection/TileContent.h>
@@ -285,10 +286,13 @@ bool Tile::needsWorkerThreadLoading(
285286
// finishLoading hasn't yet been called
286287
const std::optional<CesiumGltf::Model>& maybeModifiedModel =
287288
renderContent->getModifiedModel();
288-
std::optional<int> latestVersion =
289-
maybeModifiedModel ? maybeModifiedModel->version : std::nullopt;
289+
std::optional<int32_t> latestVersion =
290+
maybeModifiedModel
291+
? GltfModifierVersionExtension::getVersion(*maybeModifiedModel)
292+
: std::nullopt;
290293
if (!latestVersion)
291-
latestVersion = renderContent->getModel().version;
294+
latestVersion =
295+
GltfModifierVersionExtension::getVersion(renderContent->getModel());
292296
if (!latestVersion || latestVersion != modelVersion)
293297
return true;
294298
}

Cesium3DTilesSelection/src/TilesetContentManager.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <Cesium3DTilesSelection/BoundingVolume.h>
99
#include <Cesium3DTilesSelection/GltfModifier.h>
10+
#include <Cesium3DTilesSelection/GltfModifierVersionExtension.h>
1011
#include <Cesium3DTilesSelection/IPrepareRendererResources.h>
1112
#include <Cesium3DTilesSelection/RasterMappedTo3DTile.h>
1213
#include <Cesium3DTilesSelection/RasterOverlayCollection.h>
@@ -1214,7 +1215,7 @@ void TilesetContentManager::loadTileContent(
12141215
TileRenderContent* pRenderContent = tile.getContent().getRenderContent();
12151216
if (pRenderContent &&
12161217
pRenderContent->getGltfModifierState() == GltfModifier::State::Idle &&
1217-
pRenderContent->getModel().version !=
1218+
GltfModifierVersionExtension::getVersion(pRenderContent->getModel()) !=
12181219
_externals.pGltfModifier->getCurrentVersion()) {
12191220
this->reapplyGltfModifier(tile, tilesetOptions, pRenderContent);
12201221
return;
@@ -1361,7 +1362,8 @@ void TilesetContentManager::loadTileContent(
13611362
pTile->getContent().getRenderContent();
13621363
CESIUM_ASSERT(!pRenderContent || !pRenderContent->getModifiedModel());
13631364
if (pRenderContent &&
1364-
pRenderContent->getModel().version !=
1365+
GltfModifierVersionExtension::getVersion(
1366+
pRenderContent->getModel()) !=
13651367
thiz->_externals.pGltfModifier->getCurrentVersion()) {
13661368
thiz->_externals.pGltfModifier->onOldVersionContentLoadingComplete(
13671369
*pTile);
@@ -1634,7 +1636,8 @@ bool TilesetContentManager::discardOutdatedRenderResources(
16341636
renderContent.getModifiedModel();
16351637
const CesiumGltf::Model& model =
16361638
maybeModifiedModel ? *maybeModifiedModel : renderContent.getModel();
1637-
if (model.version != _externals.pGltfModifier->getCurrentVersion()) {
1639+
if (GltfModifierVersionExtension::getVersion(model) !=
1640+
_externals.pGltfModifier->getCurrentVersion()) {
16381641
_externals.pPrepareRendererResources->free(
16391642
tile,
16401643
maybeModifiedModel ? renderContent.getModifiedRenderResources()

Cesium3DTilesSelection/test/TestTilesetContentManager.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "TilesetJsonLoader.h"
55

66
#include <Cesium3DTilesContent/registerAllTileContentTypes.h>
7+
#include <Cesium3DTilesSelection/GltfModifierVersionExtension.h>
78
#include <Cesium3DTilesSelection/RasterOverlayCollection.h>
89
#include <Cesium3DTilesSelection/Tile.h>
910
#include <Cesium3DTilesSelection/TileLoadResult.h>
@@ -1879,7 +1880,9 @@ TEST_CASE("Test glTF modifier state machine") {
18791880
apply(GltfModifierInput&& input) override {
18801881
++applyCallCount;
18811882
GltfModifierOutput output{.modifiedModel = input.previousModel};
1882-
output.modifiedModel.version = getCurrentVersion();
1883+
GltfModifierVersionExtension::setVersion(
1884+
output.modifiedModel,
1885+
*getCurrentVersion());
18831886
return input.asyncSystem.createResolvedFuture(
18841887
std::make_optional(std::move(output)));
18851888
}

CesiumGltf/include/CesiumGltf/Model.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ namespace CesiumGltf {
1212

1313
/** @copydoc ModelSpec */
1414
struct CESIUMGLTF_API Model : public ModelSpec {
15-
16-
/** An optional version number for the model. This can be used by clients to
17-
* indicate state about the model.*/
18-
std::optional<int> version = std::nullopt;
19-
2015
Model() = default;
2116

2217
/**

0 commit comments

Comments
 (0)