diff --git a/CHANGES.md b/CHANGES.md index 44ae711d3..e77da32c7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ - Added support for `EXT_accessor_additional_types` in `AccessorView`. - Added `EllipsoidTilesetLoader` that will generate a tileset by tesselating the surface of an ellipsoid, producing a simple globe tileset without any terrain features. +- The `schemaUri` property in the `EXT_structural_metadata` glTF extension is now supported, allowing structural metadata schemas to be loaded from URIs rather than being embedded in the glTF itself. ##### Fixes :wrench: diff --git a/Cesium3DTiles/generated/include/Cesium3DTiles/Asset.h b/Cesium3DTiles/generated/include/Cesium3DTiles/Asset.h index d11a5f3e5..571eaaeb0 100644 --- a/Cesium3DTiles/generated/include/Cesium3DTiles/Asset.h +++ b/Cesium3DTiles/generated/include/Cesium3DTiles/Asset.h @@ -27,5 +27,23 @@ struct CESIUM3DTILES_API Asset final : public CesiumUtility::ExtensibleObject { * existing tileset is updated. */ std::optional tilesetVersion; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Asset)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t(this->version.capacity() * sizeof(char)); + if (this->tilesetVersion) { + accum += int64_t(this->tilesetVersion->capacity() * sizeof(char)); + } + return accum; + } }; } // namespace Cesium3DTiles diff --git a/Cesium3DTiles/generated/include/Cesium3DTiles/Availability.h b/Cesium3DTiles/generated/include/Cesium3DTiles/Availability.h index 6356396fd..b04006ec8 100644 --- a/Cesium3DTiles/generated/include/Cesium3DTiles/Availability.h +++ b/Cesium3DTiles/generated/include/Cesium3DTiles/Availability.h @@ -49,5 +49,20 @@ struct CESIUM3DTILES_API Availability final * */ std::optional constant; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Availability)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + + return accum; + } }; } // namespace Cesium3DTiles diff --git a/Cesium3DTiles/generated/include/Cesium3DTiles/BoundingVolume.h b/Cesium3DTiles/generated/include/Cesium3DTiles/BoundingVolume.h index f193d0c67..03e407e88 100644 --- a/Cesium3DTiles/generated/include/Cesium3DTiles/BoundingVolume.h +++ b/Cesium3DTiles/generated/include/Cesium3DTiles/BoundingVolume.h @@ -47,5 +47,22 @@ struct CESIUM3DTILES_API BoundingVolume final * shall not be negative. */ std::vector sphere; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(BoundingVolume)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t(sizeof(double) * this->box.capacity()); + accum += int64_t(sizeof(double) * this->region.capacity()); + accum += int64_t(sizeof(double) * this->sphere.capacity()); + return accum; + } }; } // namespace Cesium3DTiles diff --git a/Cesium3DTiles/generated/include/Cesium3DTiles/BufferSpec.h b/Cesium3DTiles/generated/include/Cesium3DTiles/BufferSpec.h index bc94aa084..ce5cfc408 100644 --- a/Cesium3DTiles/generated/include/Cesium3DTiles/BufferSpec.h +++ b/Cesium3DTiles/generated/include/Cesium3DTiles/BufferSpec.h @@ -37,6 +37,26 @@ struct CESIUM3DTILES_API BufferSpec : public CesiumUtility::ExtensibleObject { */ std::optional name; + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(BufferSpec)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + if (this->uri) { + accum += int64_t(this->uri->capacity() * sizeof(char)); + } + if (this->name) { + accum += int64_t(this->name->capacity() * sizeof(char)); + } + return accum; + } + private: /** * @brief This class is not meant to be instantiated directly. Use {@link Buffer} instead. diff --git a/Cesium3DTiles/generated/include/Cesium3DTiles/BufferView.h b/Cesium3DTiles/generated/include/Cesium3DTiles/BufferView.h index ad14c84d4..40c432856 100644 --- a/Cesium3DTiles/generated/include/Cesium3DTiles/BufferView.h +++ b/Cesium3DTiles/generated/include/Cesium3DTiles/BufferView.h @@ -37,5 +37,22 @@ struct CESIUM3DTILES_API BufferView final * @brief The name of the `bufferView`. */ std::optional name; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(BufferView)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + if (this->name) { + accum += int64_t(this->name->capacity() * sizeof(char)); + } + return accum; + } }; } // namespace Cesium3DTiles diff --git a/Cesium3DTiles/generated/include/Cesium3DTiles/Class.h b/Cesium3DTiles/generated/include/Cesium3DTiles/Class.h index edd7ca1c0..2061e057e 100644 --- a/Cesium3DTiles/generated/include/Cesium3DTiles/Class.h +++ b/Cesium3DTiles/generated/include/Cesium3DTiles/Class.h @@ -34,5 +34,32 @@ struct CESIUM3DTILES_API Class final : public CesiumUtility::ExtensibleObject { * identifiers matching the regular expression `^[a-zA-Z_][a-zA-Z0-9_]*$`. */ std::unordered_map properties; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Class)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + if (this->name) { + accum += int64_t(this->name->capacity() * sizeof(char)); + } + if (this->description) { + accum += int64_t(this->description->capacity() * sizeof(char)); + } + accum += int64_t( + this->properties.bucket_count() * + (sizeof(std::string) + sizeof(Cesium3DTiles::ClassProperty))); + for (const auto& [k, v] : this->properties) { + accum += int64_t(k.capacity() * sizeof(char) - sizeof(std::string)); + accum += v.getSizeBytes() - int64_t(sizeof(Cesium3DTiles::ClassProperty)); + } + return accum; + } }; } // namespace Cesium3DTiles diff --git a/Cesium3DTiles/generated/include/Cesium3DTiles/ClassProperty.h b/Cesium3DTiles/generated/include/Cesium3DTiles/ClassProperty.h index 3ce7883af..7d0233cef 100644 --- a/Cesium3DTiles/generated/include/Cesium3DTiles/ClassProperty.h +++ b/Cesium3DTiles/generated/include/Cesium3DTiles/ClassProperty.h @@ -189,5 +189,31 @@ struct CESIUM3DTILES_API ClassProperty final * interpreted. The semantic cannot be used by other properties in the class. */ std::optional semantic; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ClassProperty)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + if (this->name) { + accum += int64_t(this->name->capacity() * sizeof(char)); + } + if (this->description) { + accum += int64_t(this->description->capacity() * sizeof(char)); + } + if (this->enumType) { + accum += int64_t(this->enumType->capacity() * sizeof(char)); + } + if (this->semantic) { + accum += int64_t(this->semantic->capacity() * sizeof(char)); + } + return accum; + } }; } // namespace Cesium3DTiles diff --git a/Cesium3DTiles/generated/include/Cesium3DTiles/ClassStatistics.h b/Cesium3DTiles/generated/include/Cesium3DTiles/ClassStatistics.h index 821b8c52e..6b65fdd17 100644 --- a/Cesium3DTiles/generated/include/Cesium3DTiles/ClassStatistics.h +++ b/Cesium3DTiles/generated/include/Cesium3DTiles/ClassStatistics.h @@ -31,5 +31,27 @@ struct CESIUM3DTILES_API ClassStatistics final * statistics about property values. */ std::unordered_map properties; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ClassStatistics)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t( + this->properties.bucket_count() * + (sizeof(std::string) + sizeof(Cesium3DTiles::PropertyStatistics))); + for (const auto& [k, v] : this->properties) { + accum += int64_t(k.capacity() * sizeof(char) - sizeof(std::string)); + accum += + v.getSizeBytes() - int64_t(sizeof(Cesium3DTiles::PropertyStatistics)); + } + return accum; + } }; } // namespace Cesium3DTiles diff --git a/Cesium3DTiles/generated/include/Cesium3DTiles/Content.h b/Cesium3DTiles/generated/include/Cesium3DTiles/Content.h index 1a09fad04..df6147cab 100644 --- a/Cesium3DTiles/generated/include/Cesium3DTiles/Content.h +++ b/Cesium3DTiles/generated/include/Cesium3DTiles/Content.h @@ -44,5 +44,28 @@ struct CESIUM3DTILES_API Content final * array of `groups` that is defined for the containing tileset. */ std::optional group; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Content)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + if (this->boundingVolume) { + accum += this->boundingVolume->getSizeBytes() - + int64_t(sizeof(Cesium3DTiles::BoundingVolume)); + } + accum += int64_t(this->uri.capacity() * sizeof(char)); + if (this->metadata) { + accum += this->metadata->getSizeBytes() - + int64_t(sizeof(Cesium3DTiles::MetadataEntity)); + } + return accum; + } }; } // namespace Cesium3DTiles diff --git a/Cesium3DTiles/generated/include/Cesium3DTiles/Enum.h b/Cesium3DTiles/generated/include/Cesium3DTiles/Enum.h index ec959200b..ceb5f9aed 100644 --- a/Cesium3DTiles/generated/include/Cesium3DTiles/Enum.h +++ b/Cesium3DTiles/generated/include/Cesium3DTiles/Enum.h @@ -62,5 +62,30 @@ struct CESIUM3DTILES_API Enum final : public CesiumUtility::ExtensibleObject { * are not allowed. */ std::vector values; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Enum)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + if (this->name) { + accum += int64_t(this->name->capacity() * sizeof(char)); + } + if (this->description) { + accum += int64_t(this->description->capacity() * sizeof(char)); + } + accum += + int64_t(sizeof(Cesium3DTiles::EnumValue) * this->values.capacity()); + for (const Cesium3DTiles::EnumValue& value : this->values) { + accum += value.getSizeBytes() - int64_t(sizeof(Cesium3DTiles::EnumValue)); + } + return accum; + } }; } // namespace Cesium3DTiles diff --git a/Cesium3DTiles/generated/include/Cesium3DTiles/EnumValue.h b/Cesium3DTiles/generated/include/Cesium3DTiles/EnumValue.h index 2c01d1b99..5d262b999 100644 --- a/Cesium3DTiles/generated/include/Cesium3DTiles/EnumValue.h +++ b/Cesium3DTiles/generated/include/Cesium3DTiles/EnumValue.h @@ -32,5 +32,23 @@ struct CESIUM3DTILES_API EnumValue final * @brief The integer enum value. */ int64_t value = int64_t(); + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(EnumValue)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t(this->name.capacity() * sizeof(char)); + if (this->description) { + accum += int64_t(this->description->capacity() * sizeof(char)); + } + return accum; + } }; } // namespace Cesium3DTiles diff --git a/Cesium3DTiles/generated/include/Cesium3DTiles/Extension3dTilesBoundingVolumeS2.h b/Cesium3DTiles/generated/include/Cesium3DTiles/Extension3dTilesBoundingVolumeS2.h index 9710eb9be..54384c003 100644 --- a/Cesium3DTiles/generated/include/Cesium3DTiles/Extension3dTilesBoundingVolumeS2.h +++ b/Cesium3DTiles/generated/include/Cesium3DTiles/Extension3dTilesBoundingVolumeS2.h @@ -37,5 +37,20 @@ struct CESIUM3DTILES_API Extension3dTilesBoundingVolumeS2 final * the WGS84 ellipsoid. */ double maximumHeight = double(); + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Extension3dTilesBoundingVolumeS2)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t(this->token.capacity() * sizeof(char)); + return accum; + } }; } // namespace Cesium3DTiles diff --git a/Cesium3DTiles/generated/include/Cesium3DTiles/GroupMetadata.h b/Cesium3DTiles/generated/include/Cesium3DTiles/GroupMetadata.h index 88ccf60d6..26581668d 100644 --- a/Cesium3DTiles/generated/include/Cesium3DTiles/GroupMetadata.h +++ b/Cesium3DTiles/generated/include/Cesium3DTiles/GroupMetadata.h @@ -11,5 +11,19 @@ namespace Cesium3DTiles { */ struct CESIUM3DTILES_API GroupMetadata final : public MetadataEntity { static inline constexpr const char* TypeName = "GroupMetadata"; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(GroupMetadata)); + accum += MetadataEntity::getSizeBytes() - int64_t(sizeof(MetadataEntity)); + + return accum; + } }; } // namespace Cesium3DTiles diff --git a/Cesium3DTiles/generated/include/Cesium3DTiles/ImplicitTiling.h b/Cesium3DTiles/generated/include/Cesium3DTiles/ImplicitTiling.h index 5ca676e6f..508377d3a 100644 --- a/Cesium3DTiles/generated/include/Cesium3DTiles/ImplicitTiling.h +++ b/Cesium3DTiles/generated/include/Cesium3DTiles/ImplicitTiling.h @@ -54,5 +54,21 @@ struct CESIUM3DTILES_API ImplicitTiling final * @brief An object describing the location of subtree files. */ Cesium3DTiles::Subtrees subtrees; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ImplicitTiling)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += this->subtrees.getSizeBytes() - + int64_t(sizeof(Cesium3DTiles::Subtrees)); + return accum; + } }; } // namespace Cesium3DTiles diff --git a/Cesium3DTiles/generated/include/Cesium3DTiles/MetadataEntity.h b/Cesium3DTiles/generated/include/Cesium3DTiles/MetadataEntity.h index 15b1436ae..04b80693e 100644 --- a/Cesium3DTiles/generated/include/Cesium3DTiles/MetadataEntity.h +++ b/Cesium3DTiles/generated/include/Cesium3DTiles/MetadataEntity.h @@ -36,5 +36,27 @@ struct CESIUM3DTILES_API MetadataEntity * in this dictionary. */ std::unordered_map properties; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(MetadataEntity)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t(this->classProperty.capacity() * sizeof(char)); + accum += int64_t( + this->properties.bucket_count() * + (sizeof(std::string) + sizeof(CesiumUtility::JsonValue))); + for (const auto& [k, v] : this->properties) { + accum += int64_t(k.capacity() * sizeof(char) - sizeof(std::string)); + accum += int64_t(sizeof(CesiumUtility::JsonValue)); + } + return accum; + } }; } // namespace Cesium3DTiles diff --git a/Cesium3DTiles/generated/include/Cesium3DTiles/Properties.h b/Cesium3DTiles/generated/include/Cesium3DTiles/Properties.h index 6fa419e5e..2a200d9bf 100644 --- a/Cesium3DTiles/generated/include/Cesium3DTiles/Properties.h +++ b/Cesium3DTiles/generated/include/Cesium3DTiles/Properties.h @@ -25,5 +25,20 @@ struct CESIUM3DTILES_API Properties final * tileset. The maximum value shall not be smaller than the minimum value. */ double minimum = double(); + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Properties)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + + return accum; + } }; } // namespace Cesium3DTiles diff --git a/Cesium3DTiles/generated/include/Cesium3DTiles/PropertyStatistics.h b/Cesium3DTiles/generated/include/Cesium3DTiles/PropertyStatistics.h index e2a24a909..90ca918aa 100644 --- a/Cesium3DTiles/generated/include/Cesium3DTiles/PropertyStatistics.h +++ b/Cesium3DTiles/generated/include/Cesium3DTiles/PropertyStatistics.h @@ -81,5 +81,26 @@ struct CESIUM3DTILES_API PropertyStatistics final * component-wise occurrences. */ std::unordered_map occurrences; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(PropertyStatistics)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t( + this->occurrences.bucket_count() * + (sizeof(std::string) + sizeof(CesiumUtility::JsonValue))); + for (const auto& [k, v] : this->occurrences) { + accum += int64_t(k.capacity() * sizeof(char) - sizeof(std::string)); + accum += int64_t(sizeof(CesiumUtility::JsonValue)); + } + return accum; + } }; } // namespace Cesium3DTiles diff --git a/Cesium3DTiles/generated/include/Cesium3DTiles/PropertyTable.h b/Cesium3DTiles/generated/include/Cesium3DTiles/PropertyTable.h index 16177e63e..37a0abe48 100644 --- a/Cesium3DTiles/generated/include/Cesium3DTiles/PropertyTable.h +++ b/Cesium3DTiles/generated/include/Cesium3DTiles/PropertyTable.h @@ -45,5 +45,31 @@ struct CESIUM3DTILES_API PropertyTable final */ std::unordered_map properties; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(PropertyTable)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + if (this->name) { + accum += int64_t(this->name->capacity() * sizeof(char)); + } + accum += int64_t(this->classProperty.capacity() * sizeof(char)); + accum += int64_t( + this->properties.bucket_count() * + (sizeof(std::string) + sizeof(Cesium3DTiles::PropertyTableProperty))); + for (const auto& [k, v] : this->properties) { + accum += int64_t(k.capacity() * sizeof(char) - sizeof(std::string)); + accum += v.getSizeBytes() - + int64_t(sizeof(Cesium3DTiles::PropertyTableProperty)); + } + return accum; + } }; } // namespace Cesium3DTiles diff --git a/Cesium3DTiles/generated/include/Cesium3DTiles/PropertyTableProperty.h b/Cesium3DTiles/generated/include/Cesium3DTiles/PropertyTableProperty.h index 570cad86d..4e70c4900 100644 --- a/Cesium3DTiles/generated/include/Cesium3DTiles/PropertyTableProperty.h +++ b/Cesium3DTiles/generated/include/Cesium3DTiles/PropertyTableProperty.h @@ -135,5 +135,20 @@ struct CESIUM3DTILES_API PropertyTableProperty final * `scale` properties have been applied. */ std::optional min; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(PropertyTableProperty)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + + return accum; + } }; } // namespace Cesium3DTiles diff --git a/Cesium3DTiles/generated/include/Cesium3DTiles/Schema.h b/Cesium3DTiles/generated/include/Cesium3DTiles/Schema.h index 568e619d4..b7187536d 100644 --- a/Cesium3DTiles/generated/include/Cesium3DTiles/Schema.h +++ b/Cesium3DTiles/generated/include/Cesium3DTiles/Schema.h @@ -53,5 +53,43 @@ struct CESIUM3DTILES_API Schema final : public CesiumUtility::ExtensibleObject { * identifiers matching the regular expression `^[a-zA-Z_][a-zA-Z0-9_]*$`. */ std::unordered_map enums; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Schema)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t(this->id.capacity() * sizeof(char)); + if (this->name) { + accum += int64_t(this->name->capacity() * sizeof(char)); + } + if (this->description) { + accum += int64_t(this->description->capacity() * sizeof(char)); + } + if (this->version) { + accum += int64_t(this->version->capacity() * sizeof(char)); + } + accum += int64_t( + this->classes.bucket_count() * + (sizeof(std::string) + sizeof(Cesium3DTiles::Class))); + for (const auto& [k, v] : this->classes) { + accum += int64_t(k.capacity() * sizeof(char) - sizeof(std::string)); + accum += v.getSizeBytes() - int64_t(sizeof(Cesium3DTiles::Class)); + } + accum += int64_t( + this->enums.bucket_count() * + (sizeof(std::string) + sizeof(Cesium3DTiles::Enum))); + for (const auto& [k, v] : this->enums) { + accum += int64_t(k.capacity() * sizeof(char) - sizeof(std::string)); + accum += v.getSizeBytes() - int64_t(sizeof(Cesium3DTiles::Enum)); + } + return accum; + } }; } // namespace Cesium3DTiles diff --git a/Cesium3DTiles/generated/include/Cesium3DTiles/Statistics.h b/Cesium3DTiles/generated/include/Cesium3DTiles/Statistics.h index 121f595a4..e3ee0f4fe 100644 --- a/Cesium3DTiles/generated/include/Cesium3DTiles/Statistics.h +++ b/Cesium3DTiles/generated/include/Cesium3DTiles/Statistics.h @@ -24,5 +24,27 @@ struct CESIUM3DTILES_API Statistics final * statistics about entities that conform to the class. */ std::unordered_map classes; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Statistics)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t( + this->classes.bucket_count() * + (sizeof(std::string) + sizeof(Cesium3DTiles::ClassStatistics))); + for (const auto& [k, v] : this->classes) { + accum += int64_t(k.capacity() * sizeof(char) - sizeof(std::string)); + accum += + v.getSizeBytes() - int64_t(sizeof(Cesium3DTiles::ClassStatistics)); + } + return accum; + } }; } // namespace Cesium3DTiles diff --git a/Cesium3DTiles/generated/include/Cesium3DTiles/Subtree.h b/Cesium3DTiles/generated/include/Cesium3DTiles/Subtree.h index 21935e846..caa51e8de 100644 --- a/Cesium3DTiles/generated/include/Cesium3DTiles/Subtree.h +++ b/Cesium3DTiles/generated/include/Cesium3DTiles/Subtree.h @@ -99,5 +99,51 @@ struct CESIUM3DTILES_API Subtree final * @brief Subtree metadata encoded in JSON. */ std::optional subtreeMetadata; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Subtree)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t(sizeof(Cesium3DTiles::Buffer) * this->buffers.capacity()); + for (const Cesium3DTiles::Buffer& value : this->buffers) { + accum += value.getSizeBytes() - int64_t(sizeof(Cesium3DTiles::Buffer)); + } + accum += int64_t( + sizeof(Cesium3DTiles::BufferView) * this->bufferViews.capacity()); + for (const Cesium3DTiles::BufferView& value : this->bufferViews) { + accum += + value.getSizeBytes() - int64_t(sizeof(Cesium3DTiles::BufferView)); + } + accum += int64_t( + sizeof(Cesium3DTiles::PropertyTable) * this->propertyTables.capacity()); + for (const Cesium3DTiles::PropertyTable& value : this->propertyTables) { + accum += + value.getSizeBytes() - int64_t(sizeof(Cesium3DTiles::PropertyTable)); + } + accum += this->tileAvailability.getSizeBytes() - + int64_t(sizeof(Cesium3DTiles::Availability)); + accum += int64_t( + sizeof(Cesium3DTiles::Availability) * + this->contentAvailability.capacity()); + for (const Cesium3DTiles::Availability& value : this->contentAvailability) { + accum += + value.getSizeBytes() - int64_t(sizeof(Cesium3DTiles::Availability)); + } + accum += this->childSubtreeAvailability.getSizeBytes() - + int64_t(sizeof(Cesium3DTiles::Availability)); + accum += int64_t(sizeof(int64_t) * this->contentMetadata.capacity()); + if (this->subtreeMetadata) { + accum += this->subtreeMetadata->getSizeBytes() - + int64_t(sizeof(Cesium3DTiles::MetadataEntity)); + } + return accum; + } }; } // namespace Cesium3DTiles diff --git a/Cesium3DTiles/generated/include/Cesium3DTiles/Subtrees.h b/Cesium3DTiles/generated/include/Cesium3DTiles/Subtrees.h index 41269de17..8c83f8dec 100644 --- a/Cesium3DTiles/generated/include/Cesium3DTiles/Subtrees.h +++ b/Cesium3DTiles/generated/include/Cesium3DTiles/Subtrees.h @@ -20,5 +20,20 @@ struct CESIUM3DTILES_API Subtrees final * @brief A URI with embedded expressions that describes the resource that is associated with an implicit tile in an implicit tileset. Allowed expressions are `{level}`, `{x}`, `{y}`, and `{z}`. `{level}` is substituted with the level of the node, `{x}` is substituted with the x index of the node within the level, and `{y}` is substituted with the y index of the node within the level. `{z}` may only be given when the subdivision scheme is `OCTREE`, and it is substituted with the z index of the node within the level. */ std::string uri; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Subtrees)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t(this->uri.capacity() * sizeof(char)); + return accum; + } }; } // namespace Cesium3DTiles diff --git a/Cesium3DTiles/generated/include/Cesium3DTiles/Tile.h b/Cesium3DTiles/generated/include/Cesium3DTiles/Tile.h index 15cfc1f1a..25444dffe 100644 --- a/Cesium3DTiles/generated/include/Cesium3DTiles/Tile.h +++ b/Cesium3DTiles/generated/include/Cesium3DTiles/Tile.h @@ -107,5 +107,47 @@ struct CESIUM3DTILES_API Tile final : public CesiumUtility::ExtensibleObject { * tiles, there are no children, and this property may not be defined. */ std::vector children; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Tile)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += this->boundingVolume.getSizeBytes() - + int64_t(sizeof(Cesium3DTiles::BoundingVolume)); + if (this->viewerRequestVolume) { + accum += this->viewerRequestVolume->getSizeBytes() - + int64_t(sizeof(Cesium3DTiles::BoundingVolume)); + } + accum += int64_t(sizeof(double) * this->transform.capacity()); + if (this->content) { + accum += this->content->getSizeBytes() - + int64_t(sizeof(Cesium3DTiles::Content)); + } + accum += + int64_t(sizeof(Cesium3DTiles::Content) * this->contents.capacity()); + for (const Cesium3DTiles::Content& value : this->contents) { + accum += value.getSizeBytes() - int64_t(sizeof(Cesium3DTiles::Content)); + } + if (this->metadata) { + accum += this->metadata->getSizeBytes() - + int64_t(sizeof(Cesium3DTiles::MetadataEntity)); + } + if (this->implicitTiling) { + accum += this->implicitTiling->getSizeBytes() - + int64_t(sizeof(Cesium3DTiles::ImplicitTiling)); + } + accum += int64_t(sizeof(Cesium3DTiles::Tile) * this->children.capacity()); + for (const Cesium3DTiles::Tile& value : this->children) { + accum += value.getSizeBytes() - int64_t(sizeof(Cesium3DTiles::Tile)); + } + return accum; + } }; } // namespace Cesium3DTiles diff --git a/Cesium3DTiles/generated/include/Cesium3DTiles/Tileset.h b/Cesium3DTiles/generated/include/Cesium3DTiles/Tileset.h index 0b0b7ea1b..20958e393 100644 --- a/Cesium3DTiles/generated/include/Cesium3DTiles/Tileset.h +++ b/Cesium3DTiles/generated/include/Cesium3DTiles/Tileset.h @@ -87,5 +87,51 @@ struct CESIUM3DTILES_API Tileset final * Each element of this array shall also be contained in `extensionsUsed`. */ std::vector extensionsRequired; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Tileset)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += this->asset.getSizeBytes() - int64_t(sizeof(Cesium3DTiles::Asset)); + accum += int64_t( + this->properties.bucket_count() * + (sizeof(std::string) + sizeof(Cesium3DTiles::Properties))); + for (const auto& [k, v] : this->properties) { + accum += int64_t(k.capacity() * sizeof(char) - sizeof(std::string)); + accum += v.getSizeBytes() - int64_t(sizeof(Cesium3DTiles::Properties)); + } + if (this->schema) { + accum += + this->schema->getSizeBytes() - int64_t(sizeof(Cesium3DTiles::Schema)); + } + if (this->schemaUri) { + accum += int64_t(this->schemaUri->capacity() * sizeof(char)); + } + if (this->statistics) { + accum += this->statistics->getSizeBytes() - + int64_t(sizeof(Cesium3DTiles::Statistics)); + } + accum += + int64_t(sizeof(Cesium3DTiles::GroupMetadata) * this->groups.capacity()); + for (const Cesium3DTiles::GroupMetadata& value : this->groups) { + accum += + value.getSizeBytes() - int64_t(sizeof(Cesium3DTiles::GroupMetadata)); + } + if (this->metadata) { + accum += this->metadata->getSizeBytes() - + int64_t(sizeof(Cesium3DTiles::MetadataEntity)); + } + accum += this->root.getSizeBytes() - int64_t(sizeof(Cesium3DTiles::Tile)); + accum += int64_t(sizeof(std::string) * this->extensionsUsed.capacity()); + accum += int64_t(sizeof(std::string) * this->extensionsRequired.capacity()); + return accum; + } }; } // namespace Cesium3DTiles diff --git a/Cesium3DTilesContent/test/TestUpgradeBatchTableToExtStructuralMetadata.cpp b/Cesium3DTilesContent/test/TestUpgradeBatchTableToExtStructuralMetadata.cpp index 87781484f..3242e4036 100644 --- a/Cesium3DTilesContent/test/TestUpgradeBatchTableToExtStructuralMetadata.cpp +++ b/Cesium3DTilesContent/test/TestUpgradeBatchTableToExtStructuralMetadata.cpp @@ -176,7 +176,7 @@ static void createTestForNonArrayJson( model.getExtension(); REQUIRE(pMetadata); - const std::optional schema = pMetadata->schema; + const CesiumUtility::IntrusivePointer schema = pMetadata->schema; REQUIRE(schema); const std::unordered_map& classes = schema->classes; @@ -252,7 +252,7 @@ static void createTestForNonArrayJson( model.getExtension(); REQUIRE(pMetadata); - const std::optional schema = pMetadata->schema; + const CesiumUtility::IntrusivePointer schema = pMetadata->schema; REQUIRE(schema); const std::unordered_map& classes = schema->classes; @@ -332,7 +332,7 @@ static void createTestForArrayJson( model.getExtension(); REQUIRE(pMetadata); - const std::optional& schema = pMetadata->schema; + const CesiumUtility::IntrusivePointer& schema = pMetadata->schema; REQUIRE(schema); REQUIRE(schema->classes.find("default") != schema->classes.end()); @@ -591,7 +591,7 @@ TEST_CASE("Convert binary B3DM batch table to EXT_structural_metadata") { model.getExtension(); REQUIRE(metadata); - std::optional schema = metadata->schema; + CesiumUtility::IntrusivePointer schema = metadata->schema; REQUIRE(schema); const std::unordered_map& classes = schema->classes; @@ -1258,7 +1258,7 @@ TEST_CASE("Upgrade nested JSON metadata to string") { result.model->getExtension(); REQUIRE(pMetadata); - const std::optional& schema = pMetadata->schema; + const CesiumUtility::IntrusivePointer& schema = pMetadata->schema; REQUIRE(schema); const std::unordered_map& classes = schema->classes; @@ -1350,7 +1350,7 @@ TEST_CASE("Upgrade JSON booleans to binary") { model.getExtension(); REQUIRE(pMetadata); - const std::optional& schema = pMetadata->schema; + const CesiumUtility::IntrusivePointer& schema = pMetadata->schema; REQUIRE(schema); const std::unordered_map& classes = schema->classes; @@ -1952,7 +1952,7 @@ TEST_CASE("Defaults to string if no sentinel values are available") { model.getExtension(); REQUIRE(pMetadata); - const std::optional schema = pMetadata->schema; + const CesiumUtility::IntrusivePointer schema = pMetadata->schema; REQUIRE(schema); const std::unordered_map& classes = schema->classes; @@ -2038,7 +2038,7 @@ TEST_CASE("Defaults to string if no sentinel values are available") { model.getExtension(); REQUIRE(pMetadata); - const std::optional schema = pMetadata->schema; + const CesiumUtility::IntrusivePointer schema = pMetadata->schema; REQUIRE(schema); const std::unordered_map& classes = schema->classes; diff --git a/Cesium3DTilesWriter/generated/src/TilesetJsonWriter.cpp b/Cesium3DTilesWriter/generated/src/TilesetJsonWriter.cpp index e9d7d71e3..e6da3da26 100644 --- a/Cesium3DTilesWriter/generated/src/TilesetJsonWriter.cpp +++ b/Cesium3DTilesWriter/generated/src/TilesetJsonWriter.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include namespace Cesium3DTilesWriter { @@ -171,6 +172,14 @@ template CesiumJsonWriter::JsonWriter& jsonWriter, const CesiumJsonWriter::ExtensionWriterContext& context); +template +[[maybe_unused]] void writeJson( + const CesiumUtility::IntrusivePointer& ptr, + CesiumJsonWriter::JsonWriter& jsonWriter, + const CesiumJsonWriter::ExtensionWriterContext& context) { + writeJson(*ptr, jsonWriter, context); +} + [[maybe_unused]] void writeJson( const std::string& str, CesiumJsonWriter::JsonWriter& jsonWriter, @@ -279,6 +288,14 @@ void writeExtensibleObject( } } +template +void writeSharedAsset( + const T& obj, + CesiumJsonWriter::JsonWriter& jsonWriter, + const CesiumJsonWriter::ExtensionWriterContext& context) { + writeExtensibleObject(obj, jsonWriter, context); +} + template void writeNamedObject( const T& obj, diff --git a/CesiumGltf/generated/include/CesiumGltf/AccessorSparse.h b/CesiumGltf/generated/include/CesiumGltf/AccessorSparse.h index ab390fbb3..c56c008ae 100644 --- a/CesiumGltf/generated/include/CesiumGltf/AccessorSparse.h +++ b/CesiumGltf/generated/include/CesiumGltf/AccessorSparse.h @@ -36,5 +36,23 @@ struct CESIUMGLTF_API AccessorSparse final * accessor values. */ CesiumGltf::AccessorSparseValues values; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(AccessorSparse)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += this->indices.getSizeBytes() - + int64_t(sizeof(CesiumGltf::AccessorSparseIndices)); + accum += this->values.getSizeBytes() - + int64_t(sizeof(CesiumGltf::AccessorSparseValues)); + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/AccessorSparseIndices.h b/CesiumGltf/generated/include/CesiumGltf/AccessorSparseIndices.h index 770ff5e44..cf797c1b8 100644 --- a/CesiumGltf/generated/include/CesiumGltf/AccessorSparseIndices.h +++ b/CesiumGltf/generated/include/CesiumGltf/AccessorSparseIndices.h @@ -49,5 +49,20 @@ struct CESIUMGLTF_API AccessorSparseIndices final * */ int32_t componentType = ComponentType::UNSIGNED_BYTE; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(AccessorSparseIndices)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/AccessorSparseValues.h b/CesiumGltf/generated/include/CesiumGltf/AccessorSparseValues.h index 07d0d831d..09c068f50 100644 --- a/CesiumGltf/generated/include/CesiumGltf/AccessorSparseValues.h +++ b/CesiumGltf/generated/include/CesiumGltf/AccessorSparseValues.h @@ -31,5 +31,20 @@ struct CESIUMGLTF_API AccessorSparseValues final * @brief The offset relative to the start of the bufferView in bytes. */ int64_t byteOffset = 0; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(AccessorSparseValues)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/AccessorSpec.h b/CesiumGltf/generated/include/CesiumGltf/AccessorSpec.h index a5cf56bca..b7e472fc6 100644 --- a/CesiumGltf/generated/include/CesiumGltf/AccessorSpec.h +++ b/CesiumGltf/generated/include/CesiumGltf/AccessorSpec.h @@ -154,6 +154,26 @@ struct CESIUMGLTF_API AccessorSpec : public CesiumGltf::NamedObject { */ std::optional sparse; + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(AccessorSpec)); + accum += CesiumGltf::NamedObject::getSizeBytes() - + int64_t(sizeof(CesiumGltf::NamedObject)); + accum += int64_t(sizeof(double) * this->max.capacity()); + accum += int64_t(sizeof(double) * this->min.capacity()); + if (this->sparse) { + accum += this->sparse->getSizeBytes() - + int64_t(sizeof(CesiumGltf::AccessorSparse)); + } + return accum; + } + private: /** * @brief This class is not meant to be instantiated directly. Use {@link Accessor} instead. diff --git a/CesiumGltf/generated/include/CesiumGltf/Animation.h b/CesiumGltf/generated/include/CesiumGltf/Animation.h index 8093deed0..7b0836b9f 100644 --- a/CesiumGltf/generated/include/CesiumGltf/Animation.h +++ b/CesiumGltf/generated/include/CesiumGltf/Animation.h @@ -29,5 +29,31 @@ struct CESIUMGLTF_API Animation final : public CesiumGltf::NamedObject { * algorithm. */ std::vector samplers; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Animation)); + accum += CesiumGltf::NamedObject::getSizeBytes() - + int64_t(sizeof(CesiumGltf::NamedObject)); + accum += int64_t( + sizeof(CesiumGltf::AnimationChannel) * this->channels.capacity()); + for (const CesiumGltf::AnimationChannel& value : this->channels) { + accum += + value.getSizeBytes() - int64_t(sizeof(CesiumGltf::AnimationChannel)); + } + accum += int64_t( + sizeof(CesiumGltf::AnimationSampler) * this->samplers.capacity()); + for (const CesiumGltf::AnimationSampler& value : this->samplers) { + accum += + value.getSizeBytes() - int64_t(sizeof(CesiumGltf::AnimationSampler)); + } + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/AnimationChannel.h b/CesiumGltf/generated/include/CesiumGltf/AnimationChannel.h index 5f6d48bfc..3f491cdd9 100644 --- a/CesiumGltf/generated/include/CesiumGltf/AnimationChannel.h +++ b/CesiumGltf/generated/include/CesiumGltf/AnimationChannel.h @@ -31,5 +31,21 @@ struct CESIUMGLTF_API AnimationChannel final * @brief The descriptor of the animated property. */ CesiumGltf::AnimationChannelTarget target; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(AnimationChannel)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += this->target.getSizeBytes() - + int64_t(sizeof(CesiumGltf::AnimationChannelTarget)); + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/AnimationChannelTarget.h b/CesiumGltf/generated/include/CesiumGltf/AnimationChannelTarget.h index 2a5feffd0..93bd43d69 100644 --- a/CesiumGltf/generated/include/CesiumGltf/AnimationChannelTarget.h +++ b/CesiumGltf/generated/include/CesiumGltf/AnimationChannelTarget.h @@ -54,5 +54,20 @@ struct CESIUMGLTF_API AnimationChannelTarget final * */ std::string path = Path::translation; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(AnimationChannelTarget)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/AnimationSampler.h b/CesiumGltf/generated/include/CesiumGltf/AnimationSampler.h index 9907eb0c1..3505fd9a9 100644 --- a/CesiumGltf/generated/include/CesiumGltf/AnimationSampler.h +++ b/CesiumGltf/generated/include/CesiumGltf/AnimationSampler.h @@ -50,5 +50,20 @@ struct CESIUMGLTF_API AnimationSampler final * @brief The index of an accessor, containing keyframe output values. */ int32_t output = -1; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(AnimationSampler)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/Asset.h b/CesiumGltf/generated/include/CesiumGltf/Asset.h index a233e355c..4462c671f 100644 --- a/CesiumGltf/generated/include/CesiumGltf/Asset.h +++ b/CesiumGltf/generated/include/CesiumGltf/Asset.h @@ -39,5 +39,29 @@ struct CESIUMGLTF_API Asset final : public CesiumUtility::ExtensibleObject { * version. */ std::optional minVersion; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Asset)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + if (this->copyright) { + accum += int64_t(this->copyright->capacity() * sizeof(char)); + } + if (this->generator) { + accum += int64_t(this->generator->capacity() * sizeof(char)); + } + accum += int64_t(this->version.capacity() * sizeof(char)); + if (this->minVersion) { + accum += int64_t(this->minVersion->capacity() * sizeof(char)); + } + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/BufferSpec.h b/CesiumGltf/generated/include/CesiumGltf/BufferSpec.h index 1b8170e8d..ec71013a6 100644 --- a/CesiumGltf/generated/include/CesiumGltf/BufferSpec.h +++ b/CesiumGltf/generated/include/CesiumGltf/BufferSpec.h @@ -29,6 +29,23 @@ struct CESIUMGLTF_API BufferSpec : public CesiumGltf::NamedObject { */ int64_t byteLength = int64_t(); + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(BufferSpec)); + accum += CesiumGltf::NamedObject::getSizeBytes() - + int64_t(sizeof(CesiumGltf::NamedObject)); + if (this->uri) { + accum += int64_t(this->uri->capacity() * sizeof(char)); + } + return accum; + } + private: /** * @brief This class is not meant to be instantiated directly. Use {@link Buffer} instead. diff --git a/CesiumGltf/generated/include/CesiumGltf/BufferView.h b/CesiumGltf/generated/include/CesiumGltf/BufferView.h index 9f15bd780..e6df3eaeb 100644 --- a/CesiumGltf/generated/include/CesiumGltf/BufferView.h +++ b/CesiumGltf/generated/include/CesiumGltf/BufferView.h @@ -57,5 +57,20 @@ struct CESIUMGLTF_API BufferView final : public CesiumGltf::NamedObject { * */ std::optional target; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(BufferView)); + accum += CesiumGltf::NamedObject::getSizeBytes() - + int64_t(sizeof(CesiumGltf::NamedObject)); + + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/Camera.h b/CesiumGltf/generated/include/CesiumGltf/Camera.h index 232402d4a..2b22d785d 100644 --- a/CesiumGltf/generated/include/CesiumGltf/Camera.h +++ b/CesiumGltf/generated/include/CesiumGltf/Camera.h @@ -53,5 +53,27 @@ struct CESIUMGLTF_API Camera final : public CesiumGltf::NamedObject { * **MUST** be defined. */ std::string type = Type::perspective; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Camera)); + accum += CesiumGltf::NamedObject::getSizeBytes() - + int64_t(sizeof(CesiumGltf::NamedObject)); + if (this->orthographic) { + accum += this->orthographic->getSizeBytes() - + int64_t(sizeof(CesiumGltf::CameraOrthographic)); + } + if (this->perspective) { + accum += this->perspective->getSizeBytes() - + int64_t(sizeof(CesiumGltf::CameraPerspective)); + } + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/CameraOrthographic.h b/CesiumGltf/generated/include/CesiumGltf/CameraOrthographic.h index f21b6aabc..35e49d94b 100644 --- a/CesiumGltf/generated/include/CesiumGltf/CameraOrthographic.h +++ b/CesiumGltf/generated/include/CesiumGltf/CameraOrthographic.h @@ -37,5 +37,20 @@ struct CESIUMGLTF_API CameraOrthographic final * @brief The floating-point distance to the near clipping plane. */ double znear = double(); + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(CameraOrthographic)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/CameraPerspective.h b/CesiumGltf/generated/include/CesiumGltf/CameraPerspective.h index d89cc0698..8e0b543c6 100644 --- a/CesiumGltf/generated/include/CesiumGltf/CameraPerspective.h +++ b/CesiumGltf/generated/include/CesiumGltf/CameraPerspective.h @@ -44,5 +44,20 @@ struct CESIUMGLTF_API CameraPerspective final * @brief The floating-point distance to the near clipping plane. */ double znear = double(); + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(CameraPerspective)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/Class.h b/CesiumGltf/generated/include/CesiumGltf/Class.h index ac548d150..ede29c1a4 100644 --- a/CesiumGltf/generated/include/CesiumGltf/Class.h +++ b/CesiumGltf/generated/include/CesiumGltf/Class.h @@ -34,5 +34,32 @@ struct CESIUMGLTF_API Class final : public CesiumUtility::ExtensibleObject { * matching the regular expression `^[a-zA-Z_][a-zA-Z0-9_]*$`. */ std::unordered_map properties; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Class)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + if (this->name) { + accum += int64_t(this->name->capacity() * sizeof(char)); + } + if (this->description) { + accum += int64_t(this->description->capacity() * sizeof(char)); + } + accum += int64_t( + this->properties.bucket_count() * + (sizeof(std::string) + sizeof(CesiumGltf::ClassProperty))); + for (const auto& [k, v] : this->properties) { + accum += int64_t(k.capacity() * sizeof(char) - sizeof(std::string)); + accum += v.getSizeBytes() - int64_t(sizeof(CesiumGltf::ClassProperty)); + } + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ClassProperty.h b/CesiumGltf/generated/include/CesiumGltf/ClassProperty.h index fe07dfca3..dd031834a 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ClassProperty.h +++ b/CesiumGltf/generated/include/CesiumGltf/ClassProperty.h @@ -187,5 +187,31 @@ struct CESIUMGLTF_API ClassProperty final * interpreted. The semantic cannot be used by other properties in the class. */ std::optional semantic; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ClassProperty)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + if (this->name) { + accum += int64_t(this->name->capacity() * sizeof(char)); + } + if (this->description) { + accum += int64_t(this->description->capacity() * sizeof(char)); + } + if (this->enumType) { + accum += int64_t(this->enumType->capacity() * sizeof(char)); + } + if (this->semantic) { + accum += int64_t(this->semantic->capacity() * sizeof(char)); + } + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/Enum.h b/CesiumGltf/generated/include/CesiumGltf/Enum.h index 2aac09e6a..e001f407c 100644 --- a/CesiumGltf/generated/include/CesiumGltf/Enum.h +++ b/CesiumGltf/generated/include/CesiumGltf/Enum.h @@ -62,5 +62,29 @@ struct CESIUMGLTF_API Enum final : public CesiumUtility::ExtensibleObject { * are not allowed. */ std::vector values; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Enum)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + if (this->name) { + accum += int64_t(this->name->capacity() * sizeof(char)); + } + if (this->description) { + accum += int64_t(this->description->capacity() * sizeof(char)); + } + accum += int64_t(sizeof(CesiumGltf::EnumValue) * this->values.capacity()); + for (const CesiumGltf::EnumValue& value : this->values) { + accum += value.getSizeBytes() - int64_t(sizeof(CesiumGltf::EnumValue)); + } + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/EnumValue.h b/CesiumGltf/generated/include/CesiumGltf/EnumValue.h index d1c505a4e..faae03ae7 100644 --- a/CesiumGltf/generated/include/CesiumGltf/EnumValue.h +++ b/CesiumGltf/generated/include/CesiumGltf/EnumValue.h @@ -31,5 +31,23 @@ struct CESIUMGLTF_API EnumValue final : public CesiumUtility::ExtensibleObject { * @brief The integer enum value. */ int64_t value = int64_t(); + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(EnumValue)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t(this->name.capacity() * sizeof(char)); + if (this->description) { + accum += int64_t(this->description->capacity() * sizeof(char)); + } + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ExtensionBufferExtMeshoptCompression.h b/CesiumGltf/generated/include/CesiumGltf/ExtensionBufferExtMeshoptCompression.h index 42ce3f174..efc4013ae 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ExtensionBufferExtMeshoptCompression.h +++ b/CesiumGltf/generated/include/CesiumGltf/ExtensionBufferExtMeshoptCompression.h @@ -22,5 +22,20 @@ struct CESIUMGLTF_API ExtensionBufferExtMeshoptCompression final * need to be loaded. */ bool fallback = false; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ExtensionBufferExtMeshoptCompression)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ExtensionBufferViewExtMeshoptCompression.h b/CesiumGltf/generated/include/CesiumGltf/ExtensionBufferViewExtMeshoptCompression.h index c6096b40a..f51a659c2 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ExtensionBufferViewExtMeshoptCompression.h +++ b/CesiumGltf/generated/include/CesiumGltf/ExtensionBufferViewExtMeshoptCompression.h @@ -83,5 +83,20 @@ struct CESIUMGLTF_API ExtensionBufferViewExtMeshoptCompression final * */ std::string filter = Filter::NONE; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ExtensionBufferViewExtMeshoptCompression)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ExtensionCesiumPrimitiveOutline.h b/CesiumGltf/generated/include/CesiumGltf/ExtensionCesiumPrimitiveOutline.h index 83bb9cd6d..4179e4562 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ExtensionCesiumPrimitiveOutline.h +++ b/CesiumGltf/generated/include/CesiumGltf/ExtensionCesiumPrimitiveOutline.h @@ -25,5 +25,20 @@ struct CESIUMGLTF_API ExtensionCesiumPrimitiveOutline final * the edge of this primitive's triangles. */ int32_t indices = -1; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ExtensionCesiumPrimitiveOutline)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ExtensionCesiumRTC.h b/CesiumGltf/generated/include/CesiumGltf/ExtensionCesiumRTC.h index fdd9580e2..8c16ce779 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ExtensionCesiumRTC.h +++ b/CesiumGltf/generated/include/CesiumGltf/ExtensionCesiumRTC.h @@ -21,5 +21,20 @@ struct CESIUMGLTF_API ExtensionCesiumRTC final * @brief Center that vertex positions are relative to. */ std::vector center; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ExtensionCesiumRTC)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t(sizeof(double) * this->center.capacity()); + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ExtensionCesiumTileEdges.h b/CesiumGltf/generated/include/CesiumGltf/ExtensionCesiumTileEdges.h index 33d4a5222..4558c0fed 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ExtensionCesiumTileEdges.h +++ b/CesiumGltf/generated/include/CesiumGltf/ExtensionCesiumTileEdges.h @@ -40,5 +40,20 @@ struct CESIUMGLTF_API ExtensionCesiumTileEdges final * edge. */ int32_t top = -1; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ExtensionCesiumTileEdges)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ExtensionExtInstanceFeatures.h b/CesiumGltf/generated/include/CesiumGltf/ExtensionExtInstanceFeatures.h index 7fa25d1ad..466c16ed9 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ExtensionExtInstanceFeatures.h +++ b/CesiumGltf/generated/include/CesiumGltf/ExtensionExtInstanceFeatures.h @@ -22,5 +22,28 @@ struct CESIUMGLTF_API ExtensionExtInstanceFeatures final * @brief An array of feature ID sets. */ std::vector featureIds; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ExtensionExtInstanceFeatures)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t( + sizeof(CesiumGltf::ExtensionExtInstanceFeaturesFeatureId) * + this->featureIds.capacity()); + for (const CesiumGltf::ExtensionExtInstanceFeaturesFeatureId& value : + this->featureIds) { + accum += + value.getSizeBytes() - + int64_t(sizeof(CesiumGltf::ExtensionExtInstanceFeaturesFeatureId)); + } + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ExtensionExtInstanceFeaturesFeatureId.h b/CesiumGltf/generated/include/CesiumGltf/ExtensionExtInstanceFeaturesFeatureId.h index b22161ba5..f6d22c8ff 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ExtensionExtInstanceFeaturesFeatureId.h +++ b/CesiumGltf/generated/include/CesiumGltf/ExtensionExtInstanceFeaturesFeatureId.h @@ -49,5 +49,22 @@ struct CESIUMGLTF_API ExtensionExtInstanceFeaturesFeatureId final * values. Only applicable when using the `EXT_structural_metadata` extension. */ std::optional propertyTable; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ExtensionExtInstanceFeaturesFeatureId)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + if (this->label) { + accum += int64_t(this->label->capacity() * sizeof(char)); + } + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ExtensionExtMeshFeatures.h b/CesiumGltf/generated/include/CesiumGltf/ExtensionExtMeshFeatures.h index 3d02adb86..fc8ba2ee5 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ExtensionExtMeshFeatures.h +++ b/CesiumGltf/generated/include/CesiumGltf/ExtensionExtMeshFeatures.h @@ -22,5 +22,24 @@ struct CESIUMGLTF_API ExtensionExtMeshFeatures final * @brief An array of feature ID sets. */ std::vector featureIds; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ExtensionExtMeshFeatures)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += + int64_t(sizeof(CesiumGltf::FeatureId) * this->featureIds.capacity()); + for (const CesiumGltf::FeatureId& value : this->featureIds) { + accum += value.getSizeBytes() - int64_t(sizeof(CesiumGltf::FeatureId)); + } + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ExtensionExtMeshGpuInstancing.h b/CesiumGltf/generated/include/CesiumGltf/ExtensionExtMeshGpuInstancing.h index 8cffbe096..4119688f1 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ExtensionExtMeshGpuInstancing.h +++ b/CesiumGltf/generated/include/CesiumGltf/ExtensionExtMeshGpuInstancing.h @@ -31,5 +31,26 @@ struct CESIUMGLTF_API ExtensionExtMeshGpuInstancing final * y, and z axes. */ std::unordered_map attributes; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ExtensionExtMeshGpuInstancing)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t( + this->attributes.bucket_count() * + (sizeof(std::string) + sizeof(int32_t))); + for (const auto& [k, v] : this->attributes) { + accum += int64_t(k.capacity() * sizeof(char) - sizeof(std::string)); + accum += int64_t(sizeof(int32_t)); + } + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ExtensionKhrDracoMeshCompression.h b/CesiumGltf/generated/include/CesiumGltf/ExtensionKhrDracoMeshCompression.h index 08a869177..436a4b35f 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ExtensionKhrDracoMeshCompression.h +++ b/CesiumGltf/generated/include/CesiumGltf/ExtensionKhrDracoMeshCompression.h @@ -30,5 +30,26 @@ struct CESIUMGLTF_API ExtensionKhrDracoMeshCompression final * its unique attribute id stored in the compressed geometry. */ std::unordered_map attributes; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ExtensionKhrDracoMeshCompression)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t( + this->attributes.bucket_count() * + (sizeof(std::string) + sizeof(int32_t))); + for (const auto& [k, v] : this->attributes) { + accum += int64_t(k.capacity() * sizeof(char) - sizeof(std::string)); + accum += int64_t(sizeof(int32_t)); + } + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ExtensionKhrMaterialsUnlit.h b/CesiumGltf/generated/include/CesiumGltf/ExtensionKhrMaterialsUnlit.h index 5b512e01d..4fcb48eed 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ExtensionKhrMaterialsUnlit.h +++ b/CesiumGltf/generated/include/CesiumGltf/ExtensionKhrMaterialsUnlit.h @@ -14,5 +14,20 @@ struct CESIUMGLTF_API ExtensionKhrMaterialsUnlit final : public CesiumUtility::ExtensibleObject { static inline constexpr const char* TypeName = "ExtensionKhrMaterialsUnlit"; static inline constexpr const char* ExtensionName = "KHR_materials_unlit"; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ExtensionKhrMaterialsUnlit)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ExtensionKhrTextureBasisu.h b/CesiumGltf/generated/include/CesiumGltf/ExtensionKhrTextureBasisu.h index 21d67df69..5cda446f4 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ExtensionKhrTextureBasisu.h +++ b/CesiumGltf/generated/include/CesiumGltf/ExtensionKhrTextureBasisu.h @@ -23,5 +23,20 @@ struct CESIUMGLTF_API ExtensionKhrTextureBasisu final * Universal supercompression. */ int32_t source = -1; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ExtensionKhrTextureBasisu)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ExtensionKhrTextureTransform.h b/CesiumGltf/generated/include/CesiumGltf/ExtensionKhrTextureTransform.h index 059a83989..7a571576e 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ExtensionKhrTextureTransform.h +++ b/CesiumGltf/generated/include/CesiumGltf/ExtensionKhrTextureTransform.h @@ -42,5 +42,21 @@ struct CESIUMGLTF_API ExtensionKhrTextureTransform final * extension is supported. */ std::optional texCoord; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ExtensionKhrTextureTransform)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t(sizeof(double) * this->offset.capacity()); + accum += int64_t(sizeof(double) * this->scale.capacity()); + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ExtensionMeshPrimitiveExtStructuralMetadata.h b/CesiumGltf/generated/include/CesiumGltf/ExtensionMeshPrimitiveExtStructuralMetadata.h index 4e6fa83f3..37995b55c 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ExtensionMeshPrimitiveExtStructuralMetadata.h +++ b/CesiumGltf/generated/include/CesiumGltf/ExtensionMeshPrimitiveExtStructuralMetadata.h @@ -30,5 +30,21 @@ struct CESIUMGLTF_API ExtensionMeshPrimitiveExtStructuralMetadata final * `EXT_structural_metadata` object. */ std::vector propertyAttributes; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ExtensionMeshPrimitiveExtStructuralMetadata)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t(sizeof(int32_t) * this->propertyTextures.capacity()); + accum += int64_t(sizeof(int32_t) * this->propertyAttributes.capacity()); + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ExtensionMeshPrimitiveKhrMaterialsVariants.h b/CesiumGltf/generated/include/CesiumGltf/ExtensionMeshPrimitiveKhrMaterialsVariants.h index 0b10bb312..6b93dd3a1 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ExtensionMeshPrimitiveKhrMaterialsVariants.h +++ b/CesiumGltf/generated/include/CesiumGltf/ExtensionMeshPrimitiveKhrMaterialsVariants.h @@ -28,5 +28,32 @@ struct CESIUMGLTF_API ExtensionMeshPrimitiveKhrMaterialsVariants final std::vector< CesiumGltf::ExtensionMeshPrimitiveKhrMaterialsVariantsMappingsValue> mappings; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ExtensionMeshPrimitiveKhrMaterialsVariants)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t( + sizeof(CesiumGltf:: + ExtensionMeshPrimitiveKhrMaterialsVariantsMappingsValue) * + this->mappings.capacity()); + for (const CesiumGltf:: + ExtensionMeshPrimitiveKhrMaterialsVariantsMappingsValue& value : + this->mappings) { + accum += + value.getSizeBytes() - + int64_t(sizeof( + CesiumGltf:: + ExtensionMeshPrimitiveKhrMaterialsVariantsMappingsValue)); + } + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ExtensionMeshPrimitiveKhrMaterialsVariantsMappingsValue.h b/CesiumGltf/generated/include/CesiumGltf/ExtensionMeshPrimitiveKhrMaterialsVariantsMappingsValue.h index c0bc7bc37..5d8e1799c 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ExtensionMeshPrimitiveKhrMaterialsVariantsMappingsValue.h +++ b/CesiumGltf/generated/include/CesiumGltf/ExtensionMeshPrimitiveKhrMaterialsVariantsMappingsValue.h @@ -42,5 +42,24 @@ struct CESIUMGLTF_API ExtensionMeshPrimitiveKhrMaterialsVariantsMappingsValue * not necessarily unique. */ std::optional name; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t( + sizeof(ExtensionMeshPrimitiveKhrMaterialsVariantsMappingsValue)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t(sizeof(int32_t) * this->variants.capacity()); + if (this->name) { + accum += int64_t(this->name->capacity() * sizeof(char)); + } + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ExtensionModelExtStructuralMetadata.h b/CesiumGltf/generated/include/CesiumGltf/ExtensionModelExtStructuralMetadata.h index f78ace942..39299acf7 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ExtensionModelExtStructuralMetadata.h +++ b/CesiumGltf/generated/include/CesiumGltf/ExtensionModelExtStructuralMetadata.h @@ -7,6 +7,7 @@ #include "CesiumGltf/PropertyTable.h" #include "CesiumGltf/PropertyTexture.h" #include "CesiumGltf/Schema.h" +#include "CesiumUtility/IntrusivePointer.h" #include @@ -28,7 +29,7 @@ struct CESIUMGLTF_API ExtensionModelExtStructuralMetadata final /** * @brief An object defining classes and enums. */ - std::optional schema; + CesiumUtility::IntrusivePointer schema; /** * @brief The URI (or IRI) of the external schema file. @@ -52,5 +53,44 @@ struct CESIUMGLTF_API ExtensionModelExtStructuralMetadata final * by index. */ std::vector propertyAttributes; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ExtensionModelExtStructuralMetadata)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += this->schema->getSizeBytes(); + if (this->schemaUri) { + accum += int64_t(this->schemaUri->capacity() * sizeof(char)); + } + accum += int64_t( + sizeof(CesiumGltf::PropertyTable) * this->propertyTables.capacity()); + for (const CesiumGltf::PropertyTable& value : this->propertyTables) { + accum += + value.getSizeBytes() - int64_t(sizeof(CesiumGltf::PropertyTable)); + } + accum += int64_t( + sizeof(CesiumGltf::PropertyTexture) * + this->propertyTextures.capacity()); + for (const CesiumGltf::PropertyTexture& value : this->propertyTextures) { + accum += + value.getSizeBytes() - int64_t(sizeof(CesiumGltf::PropertyTexture)); + } + accum += int64_t( + sizeof(CesiumGltf::PropertyAttribute) * + this->propertyAttributes.capacity()); + for (const CesiumGltf::PropertyAttribute& value : + this->propertyAttributes) { + accum += + value.getSizeBytes() - int64_t(sizeof(CesiumGltf::PropertyAttribute)); + } + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ExtensionModelKhrMaterialsVariants.h b/CesiumGltf/generated/include/CesiumGltf/ExtensionModelKhrMaterialsVariants.h index 768300cd6..4e1a87210 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ExtensionModelKhrMaterialsVariants.h +++ b/CesiumGltf/generated/include/CesiumGltf/ExtensionModelKhrMaterialsVariants.h @@ -23,5 +23,28 @@ struct CESIUMGLTF_API ExtensionModelKhrMaterialsVariants final * @brief variants */ std::vector variants; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ExtensionModelKhrMaterialsVariants)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t( + sizeof(CesiumGltf::ExtensionModelKhrMaterialsVariantsValue) * + this->variants.capacity()); + for (const CesiumGltf::ExtensionModelKhrMaterialsVariantsValue& value : + this->variants) { + accum += + value.getSizeBytes() - + int64_t(sizeof(CesiumGltf::ExtensionModelKhrMaterialsVariantsValue)); + } + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ExtensionModelKhrMaterialsVariantsValue.h b/CesiumGltf/generated/include/CesiumGltf/ExtensionModelKhrMaterialsVariantsValue.h index 5011ef0e4..a00b7fc70 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ExtensionModelKhrMaterialsVariantsValue.h +++ b/CesiumGltf/generated/include/CesiumGltf/ExtensionModelKhrMaterialsVariantsValue.h @@ -22,5 +22,20 @@ struct CESIUMGLTF_API ExtensionModelKhrMaterialsVariantsValue final * . */ std::string name; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ExtensionModelKhrMaterialsVariantsValue)); + accum += CesiumGltf::NamedObject::getSizeBytes() - + int64_t(sizeof(CesiumGltf::NamedObject)); + accum += int64_t(this->name.capacity() * sizeof(char)); + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ExtensionModelMaxarMeshVariants.h b/CesiumGltf/generated/include/CesiumGltf/ExtensionModelMaxarMeshVariants.h index 1d86be276..bf76bba9a 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ExtensionModelMaxarMeshVariants.h +++ b/CesiumGltf/generated/include/CesiumGltf/ExtensionModelMaxarMeshVariants.h @@ -31,5 +31,28 @@ struct CESIUMGLTF_API ExtensionModelMaxarMeshVariants final * @brief variants */ std::vector variants; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ExtensionModelMaxarMeshVariants)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t( + sizeof(CesiumGltf::ExtensionModelMaxarMeshVariantsValue) * + this->variants.capacity()); + for (const CesiumGltf::ExtensionModelMaxarMeshVariantsValue& value : + this->variants) { + accum += + value.getSizeBytes() - + int64_t(sizeof(CesiumGltf::ExtensionModelMaxarMeshVariantsValue)); + } + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ExtensionModelMaxarMeshVariantsValue.h b/CesiumGltf/generated/include/CesiumGltf/ExtensionModelMaxarMeshVariantsValue.h index c0f3489a1..e16abfc49 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ExtensionModelMaxarMeshVariantsValue.h +++ b/CesiumGltf/generated/include/CesiumGltf/ExtensionModelMaxarMeshVariantsValue.h @@ -20,5 +20,20 @@ struct CESIUMGLTF_API ExtensionModelMaxarMeshVariantsValue final * @brief The name of the mesh variant */ std::string name; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ExtensionModelMaxarMeshVariantsValue)); + accum += CesiumGltf::NamedObject::getSizeBytes() - + int64_t(sizeof(CesiumGltf::NamedObject)); + accum += int64_t(this->name.capacity() * sizeof(char)); + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ExtensionNodeMaxarMeshVariants.h b/CesiumGltf/generated/include/CesiumGltf/ExtensionNodeMaxarMeshVariants.h index eb4822b61..7e75a0d13 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ExtensionNodeMaxarMeshVariants.h +++ b/CesiumGltf/generated/include/CesiumGltf/ExtensionNodeMaxarMeshVariants.h @@ -23,5 +23,28 @@ struct CESIUMGLTF_API ExtensionNodeMaxarMeshVariants final * @brief A list of mesh to variant mappings */ std::vector mappings; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ExtensionNodeMaxarMeshVariants)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t( + sizeof(CesiumGltf::ExtensionNodeMaxarMeshVariantsMappingsValue) * + this->mappings.capacity()); + for (const CesiumGltf::ExtensionNodeMaxarMeshVariantsMappingsValue& value : + this->mappings) { + accum += value.getSizeBytes() - + int64_t(sizeof( + CesiumGltf::ExtensionNodeMaxarMeshVariantsMappingsValue)); + } + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ExtensionNodeMaxarMeshVariantsMappingsValue.h b/CesiumGltf/generated/include/CesiumGltf/ExtensionNodeMaxarMeshVariantsMappingsValue.h index afd9a7146..c1a8c8083 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ExtensionNodeMaxarMeshVariantsMappingsValue.h +++ b/CesiumGltf/generated/include/CesiumGltf/ExtensionNodeMaxarMeshVariantsMappingsValue.h @@ -34,5 +34,23 @@ struct CESIUMGLTF_API ExtensionNodeMaxarMeshVariantsMappingsValue final * @brief The user-defined name of this variant mesh mapping. */ std::optional name; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ExtensionNodeMaxarMeshVariantsMappingsValue)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t(sizeof(int32_t) * this->variants.capacity()); + if (this->name) { + accum += int64_t(this->name->capacity() * sizeof(char)); + } + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ExtensionTextureWebp.h b/CesiumGltf/generated/include/CesiumGltf/ExtensionTextureWebp.h index c9ee691e5..4951075a1 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ExtensionTextureWebp.h +++ b/CesiumGltf/generated/include/CesiumGltf/ExtensionTextureWebp.h @@ -21,5 +21,20 @@ struct CESIUMGLTF_API ExtensionTextureWebp final * @brief The index of the images node which points to a WebP image. */ int32_t source = -1; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ExtensionTextureWebp)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/FeatureId.h b/CesiumGltf/generated/include/CesiumGltf/FeatureId.h index 35e40ca9c..68cccd36c 100644 --- a/CesiumGltf/generated/include/CesiumGltf/FeatureId.h +++ b/CesiumGltf/generated/include/CesiumGltf/FeatureId.h @@ -53,5 +53,26 @@ struct CESIUMGLTF_API FeatureId final : public CesiumUtility::ExtensibleObject { * values. Only applicable when using the `EXT_structural_metadata` extension. */ int32_t propertyTable = -1; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(FeatureId)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + if (this->label) { + accum += int64_t(this->label->capacity() * sizeof(char)); + } + if (this->texture) { + accum += this->texture->getSizeBytes() - + int64_t(sizeof(CesiumGltf::FeatureIdTexture)); + } + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/FeatureIdTexture.h b/CesiumGltf/generated/include/CesiumGltf/FeatureIdTexture.h index 2ce9dc76e..a490f7341 100644 --- a/CesiumGltf/generated/include/CesiumGltf/FeatureIdTexture.h +++ b/CesiumGltf/generated/include/CesiumGltf/FeatureIdTexture.h @@ -22,5 +22,19 @@ struct CESIUMGLTF_API FeatureIdTexture final : public TextureInfo { * values are packed in little-endian order. */ std::vector channels = {0}; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(FeatureIdTexture)); + accum += TextureInfo::getSizeBytes() - int64_t(sizeof(TextureInfo)); + accum += int64_t(sizeof(int64_t) * this->channels.capacity()); + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ImageSpec.h b/CesiumGltf/generated/include/CesiumGltf/ImageSpec.h index b8ec52d2c..47a351a6b 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ImageSpec.h +++ b/CesiumGltf/generated/include/CesiumGltf/ImageSpec.h @@ -51,6 +51,23 @@ struct CESIUMGLTF_API ImageSpec : public CesiumGltf::NamedObject { */ int32_t bufferView = -1; + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ImageSpec)); + accum += CesiumGltf::NamedObject::getSizeBytes() - + int64_t(sizeof(CesiumGltf::NamedObject)); + if (this->uri) { + accum += int64_t(this->uri->capacity() * sizeof(char)); + } + return accum; + } + private: /** * @brief This class is not meant to be instantiated directly. Use {@link Image} instead. diff --git a/CesiumGltf/generated/include/CesiumGltf/Material.h b/CesiumGltf/generated/include/CesiumGltf/Material.h index 6936bbff0..035a78a0c 100644 --- a/CesiumGltf/generated/include/CesiumGltf/Material.h +++ b/CesiumGltf/generated/include/CesiumGltf/Material.h @@ -113,5 +113,36 @@ struct CESIUMGLTF_API Material final : public CesiumGltf::NamedObject { * equation is evaluated. */ bool doubleSided = false; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Material)); + accum += CesiumGltf::NamedObject::getSizeBytes() - + int64_t(sizeof(CesiumGltf::NamedObject)); + if (this->pbrMetallicRoughness) { + accum += this->pbrMetallicRoughness->getSizeBytes() - + int64_t(sizeof(CesiumGltf::MaterialPBRMetallicRoughness)); + } + if (this->normalTexture) { + accum += this->normalTexture->getSizeBytes() - + int64_t(sizeof(CesiumGltf::MaterialNormalTextureInfo)); + } + if (this->occlusionTexture) { + accum += this->occlusionTexture->getSizeBytes() - + int64_t(sizeof(CesiumGltf::MaterialOcclusionTextureInfo)); + } + if (this->emissiveTexture) { + accum += this->emissiveTexture->getSizeBytes() - + int64_t(sizeof(CesiumGltf::TextureInfo)); + } + accum += int64_t(sizeof(double) * this->emissiveFactor.capacity()); + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/MaterialNormalTextureInfo.h b/CesiumGltf/generated/include/CesiumGltf/MaterialNormalTextureInfo.h index 1bcf74477..040261cf2 100644 --- a/CesiumGltf/generated/include/CesiumGltf/MaterialNormalTextureInfo.h +++ b/CesiumGltf/generated/include/CesiumGltf/MaterialNormalTextureInfo.h @@ -22,5 +22,19 @@ struct CESIUMGLTF_API MaterialNormalTextureInfo final : public TextureInfo { * vec3(, , 1.0))`. */ double scale = 1; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(MaterialNormalTextureInfo)); + accum += TextureInfo::getSizeBytes() - int64_t(sizeof(TextureInfo)); + + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/MaterialOcclusionTextureInfo.h b/CesiumGltf/generated/include/CesiumGltf/MaterialOcclusionTextureInfo.h index 0800082d0..f7bc3d669 100644 --- a/CesiumGltf/generated/include/CesiumGltf/MaterialOcclusionTextureInfo.h +++ b/CesiumGltf/generated/include/CesiumGltf/MaterialOcclusionTextureInfo.h @@ -21,5 +21,19 @@ struct CESIUMGLTF_API MaterialOcclusionTextureInfo final : public TextureInfo { * texture value> - 1.0)`. */ double strength = 1; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(MaterialOcclusionTextureInfo)); + accum += TextureInfo::getSizeBytes() - int64_t(sizeof(TextureInfo)); + + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/MaterialPBRMetallicRoughness.h b/CesiumGltf/generated/include/CesiumGltf/MaterialPBRMetallicRoughness.h index b516f0ef5..f7afb6cdd 100644 --- a/CesiumGltf/generated/include/CesiumGltf/MaterialPBRMetallicRoughness.h +++ b/CesiumGltf/generated/include/CesiumGltf/MaterialPBRMetallicRoughness.h @@ -67,5 +67,28 @@ struct CESIUMGLTF_API MaterialPBRMetallicRoughness final * the texture **MUST** be sampled as having `1.0` in G and B components. */ std::optional metallicRoughnessTexture; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(MaterialPBRMetallicRoughness)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t(sizeof(double) * this->baseColorFactor.capacity()); + if (this->baseColorTexture) { + accum += this->baseColorTexture->getSizeBytes() - + int64_t(sizeof(CesiumGltf::TextureInfo)); + } + if (this->metallicRoughnessTexture) { + accum += this->metallicRoughnessTexture->getSizeBytes() - + int64_t(sizeof(CesiumGltf::TextureInfo)); + } + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/Mesh.h b/CesiumGltf/generated/include/CesiumGltf/Mesh.h index 77dd29775..cbb3dd0d0 100644 --- a/CesiumGltf/generated/include/CesiumGltf/Mesh.h +++ b/CesiumGltf/generated/include/CesiumGltf/Mesh.h @@ -26,5 +26,26 @@ struct CESIUMGLTF_API Mesh final : public CesiumGltf::NamedObject { * array elements **MUST** match the number of morph targets. */ std::vector weights; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Mesh)); + accum += CesiumGltf::NamedObject::getSizeBytes() - + int64_t(sizeof(CesiumGltf::NamedObject)); + accum += int64_t( + sizeof(CesiumGltf::MeshPrimitive) * this->primitives.capacity()); + for (const CesiumGltf::MeshPrimitive& value : this->primitives) { + accum += + value.getSizeBytes() - int64_t(sizeof(CesiumGltf::MeshPrimitive)); + } + accum += int64_t(sizeof(double) * this->weights.capacity()); + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/MeshPrimitive.h b/CesiumGltf/generated/include/CesiumGltf/MeshPrimitive.h index f8a72af60..eab710e2f 100644 --- a/CesiumGltf/generated/include/CesiumGltf/MeshPrimitive.h +++ b/CesiumGltf/generated/include/CesiumGltf/MeshPrimitive.h @@ -70,5 +70,29 @@ struct CESIUMGLTF_API MeshPrimitive final * @brief An array of morph targets. */ std::vector> targets; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(MeshPrimitive)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t( + this->attributes.bucket_count() * + (sizeof(std::string) + sizeof(int32_t))); + for (const auto& [k, v] : this->attributes) { + accum += int64_t(k.capacity() * sizeof(char) - sizeof(std::string)); + accum += int64_t(sizeof(int32_t)); + } + accum += int64_t( + sizeof(std::unordered_map) * + this->targets.capacity()); + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/ModelSpec.h b/CesiumGltf/generated/include/CesiumGltf/ModelSpec.h index b2cbf16b3..073c92844 100644 --- a/CesiumGltf/generated/include/CesiumGltf/ModelSpec.h +++ b/CesiumGltf/generated/include/CesiumGltf/ModelSpec.h @@ -137,6 +137,77 @@ struct CESIUMGLTF_API ModelSpec : public CesiumUtility::ExtensibleObject { */ std::vector textures; + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(ModelSpec)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t(sizeof(std::string) * this->extensionsUsed.capacity()); + accum += int64_t(sizeof(std::string) * this->extensionsRequired.capacity()); + accum += int64_t(sizeof(CesiumGltf::Accessor) * this->accessors.capacity()); + for (const CesiumGltf::Accessor& value : this->accessors) { + accum += value.getSizeBytes() - int64_t(sizeof(CesiumGltf::Accessor)); + } + accum += + int64_t(sizeof(CesiumGltf::Animation) * this->animations.capacity()); + for (const CesiumGltf::Animation& value : this->animations) { + accum += value.getSizeBytes() - int64_t(sizeof(CesiumGltf::Animation)); + } + accum += this->asset.getSizeBytes() - int64_t(sizeof(CesiumGltf::Asset)); + accum += int64_t(sizeof(CesiumGltf::Buffer) * this->buffers.capacity()); + for (const CesiumGltf::Buffer& value : this->buffers) { + accum += value.getSizeBytes() - int64_t(sizeof(CesiumGltf::Buffer)); + } + accum += + int64_t(sizeof(CesiumGltf::BufferView) * this->bufferViews.capacity()); + for (const CesiumGltf::BufferView& value : this->bufferViews) { + accum += value.getSizeBytes() - int64_t(sizeof(CesiumGltf::BufferView)); + } + accum += int64_t(sizeof(CesiumGltf::Camera) * this->cameras.capacity()); + for (const CesiumGltf::Camera& value : this->cameras) { + accum += value.getSizeBytes() - int64_t(sizeof(CesiumGltf::Camera)); + } + accum += int64_t(sizeof(CesiumGltf::Image) * this->images.capacity()); + for (const CesiumGltf::Image& value : this->images) { + accum += value.getSizeBytes() - int64_t(sizeof(CesiumGltf::Image)); + } + accum += int64_t(sizeof(CesiumGltf::Material) * this->materials.capacity()); + for (const CesiumGltf::Material& value : this->materials) { + accum += value.getSizeBytes() - int64_t(sizeof(CesiumGltf::Material)); + } + accum += int64_t(sizeof(CesiumGltf::Mesh) * this->meshes.capacity()); + for (const CesiumGltf::Mesh& value : this->meshes) { + accum += value.getSizeBytes() - int64_t(sizeof(CesiumGltf::Mesh)); + } + accum += int64_t(sizeof(CesiumGltf::Node) * this->nodes.capacity()); + for (const CesiumGltf::Node& value : this->nodes) { + accum += value.getSizeBytes() - int64_t(sizeof(CesiumGltf::Node)); + } + accum += int64_t(sizeof(CesiumGltf::Sampler) * this->samplers.capacity()); + for (const CesiumGltf::Sampler& value : this->samplers) { + accum += value.getSizeBytes() - int64_t(sizeof(CesiumGltf::Sampler)); + } + accum += int64_t(sizeof(CesiumGltf::Scene) * this->scenes.capacity()); + for (const CesiumGltf::Scene& value : this->scenes) { + accum += value.getSizeBytes() - int64_t(sizeof(CesiumGltf::Scene)); + } + accum += int64_t(sizeof(CesiumGltf::Skin) * this->skins.capacity()); + for (const CesiumGltf::Skin& value : this->skins) { + accum += value.getSizeBytes() - int64_t(sizeof(CesiumGltf::Skin)); + } + accum += int64_t(sizeof(CesiumGltf::Texture) * this->textures.capacity()); + for (const CesiumGltf::Texture& value : this->textures) { + accum += value.getSizeBytes() - int64_t(sizeof(CesiumGltf::Texture)); + } + return accum; + } + private: /** * @brief This class is not meant to be instantiated directly. Use {@link Model} instead. diff --git a/CesiumGltf/generated/include/CesiumGltf/Node.h b/CesiumGltf/generated/include/CesiumGltf/Node.h index ebae12e31..fe52f36ae 100644 --- a/CesiumGltf/generated/include/CesiumGltf/Node.h +++ b/CesiumGltf/generated/include/CesiumGltf/Node.h @@ -76,5 +76,25 @@ struct CESIUMGLTF_API Node final : public CesiumGltf::NamedObject { * When defined, `mesh` **MUST** also be defined. */ std::vector weights; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Node)); + accum += CesiumGltf::NamedObject::getSizeBytes() - + int64_t(sizeof(CesiumGltf::NamedObject)); + accum += int64_t(sizeof(int32_t) * this->children.capacity()); + accum += int64_t(sizeof(double) * this->matrix.capacity()); + accum += int64_t(sizeof(double) * this->rotation.capacity()); + accum += int64_t(sizeof(double) * this->scale.capacity()); + accum += int64_t(sizeof(double) * this->translation.capacity()); + accum += int64_t(sizeof(double) * this->weights.capacity()); + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/PropertyAttribute.h b/CesiumGltf/generated/include/CesiumGltf/PropertyAttribute.h index c7256721b..59c398b0b 100644 --- a/CesiumGltf/generated/include/CesiumGltf/PropertyAttribute.h +++ b/CesiumGltf/generated/include/CesiumGltf/PropertyAttribute.h @@ -39,5 +39,31 @@ struct CESIUMGLTF_API PropertyAttribute final */ std::unordered_map properties; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(PropertyAttribute)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + if (this->name) { + accum += int64_t(this->name->capacity() * sizeof(char)); + } + accum += int64_t(this->classProperty.capacity() * sizeof(char)); + accum += int64_t( + this->properties.bucket_count() * + (sizeof(std::string) + sizeof(CesiumGltf::PropertyAttributeProperty))); + for (const auto& [k, v] : this->properties) { + accum += int64_t(k.capacity() * sizeof(char) - sizeof(std::string)); + accum += v.getSizeBytes() - + int64_t(sizeof(CesiumGltf::PropertyAttributeProperty)); + } + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/PropertyAttributeProperty.h b/CesiumGltf/generated/include/CesiumGltf/PropertyAttributeProperty.h index 25c6391ff..914e40ff8 100644 --- a/CesiumGltf/generated/include/CesiumGltf/PropertyAttributeProperty.h +++ b/CesiumGltf/generated/include/CesiumGltf/PropertyAttributeProperty.h @@ -52,5 +52,20 @@ struct CESIUMGLTF_API PropertyAttributeProperty final * `scale` properties have been applied. */ std::optional min; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(PropertyAttributeProperty)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t(this->attribute.capacity() * sizeof(char)); + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/PropertyTable.h b/CesiumGltf/generated/include/CesiumGltf/PropertyTable.h index 4a4130cd6..ccf0a6563 100644 --- a/CesiumGltf/generated/include/CesiumGltf/PropertyTable.h +++ b/CesiumGltf/generated/include/CesiumGltf/PropertyTable.h @@ -44,5 +44,31 @@ struct CESIUMGLTF_API PropertyTable final * dictionary. */ std::unordered_map properties; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(PropertyTable)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + if (this->name) { + accum += int64_t(this->name->capacity() * sizeof(char)); + } + accum += int64_t(this->classProperty.capacity() * sizeof(char)); + accum += int64_t( + this->properties.bucket_count() * + (sizeof(std::string) + sizeof(CesiumGltf::PropertyTableProperty))); + for (const auto& [k, v] : this->properties) { + accum += int64_t(k.capacity() * sizeof(char) - sizeof(std::string)); + accum += + v.getSizeBytes() - int64_t(sizeof(CesiumGltf::PropertyTableProperty)); + } + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/PropertyTableProperty.h b/CesiumGltf/generated/include/CesiumGltf/PropertyTableProperty.h index 5b9cf839d..81d6af3fc 100644 --- a/CesiumGltf/generated/include/CesiumGltf/PropertyTableProperty.h +++ b/CesiumGltf/generated/include/CesiumGltf/PropertyTableProperty.h @@ -132,5 +132,20 @@ struct CESIUMGLTF_API PropertyTableProperty final * `scale` properties have been applied. */ std::optional min; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(PropertyTableProperty)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/PropertyTexture.h b/CesiumGltf/generated/include/CesiumGltf/PropertyTexture.h index 6ea853c30..4e1eeedb6 100644 --- a/CesiumGltf/generated/include/CesiumGltf/PropertyTexture.h +++ b/CesiumGltf/generated/include/CesiumGltf/PropertyTexture.h @@ -39,5 +39,31 @@ struct CESIUMGLTF_API PropertyTexture final */ std::unordered_map properties; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(PropertyTexture)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + if (this->name) { + accum += int64_t(this->name->capacity() * sizeof(char)); + } + accum += int64_t(this->classProperty.capacity() * sizeof(char)); + accum += int64_t( + this->properties.bucket_count() * + (sizeof(std::string) + sizeof(CesiumGltf::PropertyTextureProperty))); + for (const auto& [k, v] : this->properties) { + accum += int64_t(k.capacity() * sizeof(char) - sizeof(std::string)); + accum += v.getSizeBytes() - + int64_t(sizeof(CesiumGltf::PropertyTextureProperty)); + } + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/PropertyTextureProperty.h b/CesiumGltf/generated/include/CesiumGltf/PropertyTextureProperty.h index 04ec656fc..913d8f2c2 100644 --- a/CesiumGltf/generated/include/CesiumGltf/PropertyTextureProperty.h +++ b/CesiumGltf/generated/include/CesiumGltf/PropertyTextureProperty.h @@ -55,5 +55,19 @@ struct CESIUMGLTF_API PropertyTextureProperty final : public TextureInfo { * `scale` properties have been applied. */ std::optional min; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(PropertyTextureProperty)); + accum += TextureInfo::getSizeBytes() - int64_t(sizeof(TextureInfo)); + accum += int64_t(sizeof(int64_t) * this->channels.capacity()); + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/Sampler.h b/CesiumGltf/generated/include/CesiumGltf/Sampler.h index 70b98883e..dc3a8c000 100644 --- a/CesiumGltf/generated/include/CesiumGltf/Sampler.h +++ b/CesiumGltf/generated/include/CesiumGltf/Sampler.h @@ -95,5 +95,20 @@ struct CESIUMGLTF_API Sampler final : public CesiumGltf::NamedObject { * */ int32_t wrapT = WrapT::REPEAT; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Sampler)); + accum += CesiumGltf::NamedObject::getSizeBytes() - + int64_t(sizeof(CesiumGltf::NamedObject)); + + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/Scene.h b/CesiumGltf/generated/include/CesiumGltf/Scene.h index 48fce87cd..a68b3b84a 100644 --- a/CesiumGltf/generated/include/CesiumGltf/Scene.h +++ b/CesiumGltf/generated/include/CesiumGltf/Scene.h @@ -19,5 +19,20 @@ struct CESIUMGLTF_API Scene final : public CesiumGltf::NamedObject { * @brief The indices of each root node. */ std::vector nodes; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Scene)); + accum += CesiumGltf::NamedObject::getSizeBytes() - + int64_t(sizeof(CesiumGltf::NamedObject)); + accum += int64_t(sizeof(int32_t) * this->nodes.capacity()); + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/Schema.h b/CesiumGltf/generated/include/CesiumGltf/Schema.h index 7930d4f91..4fa10c26e 100644 --- a/CesiumGltf/generated/include/CesiumGltf/Schema.h +++ b/CesiumGltf/generated/include/CesiumGltf/Schema.h @@ -6,7 +6,7 @@ #include "CesiumGltf/Enum.h" #include "CesiumGltf/Library.h" -#include +#include #include #include @@ -16,7 +16,7 @@ namespace CesiumGltf { /** * @brief An object defining classes and enums. */ -struct CESIUMGLTF_API Schema final : public CesiumUtility::ExtensibleObject { +struct CESIUMGLTF_API Schema final : public CesiumUtility::SharedAsset { static inline constexpr const char* TypeName = "Schema"; /** @@ -53,5 +53,43 @@ struct CESIUMGLTF_API Schema final : public CesiumUtility::ExtensibleObject { * identifiers matching the regular expression `^[a-zA-Z_][a-zA-Z0-9_]*$`. */ std::unordered_map enums; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Schema)); + accum += CesiumUtility::SharedAsset::getSizeBytes() - + int64_t(sizeof(CesiumUtility::SharedAsset)); + accum += int64_t(this->id.capacity() * sizeof(char)); + if (this->name) { + accum += int64_t(this->name->capacity() * sizeof(char)); + } + if (this->description) { + accum += int64_t(this->description->capacity() * sizeof(char)); + } + if (this->version) { + accum += int64_t(this->version->capacity() * sizeof(char)); + } + accum += int64_t( + this->classes.bucket_count() * + (sizeof(std::string) + sizeof(CesiumGltf::Class))); + for (const auto& [k, v] : this->classes) { + accum += int64_t(k.capacity() * sizeof(char) - sizeof(std::string)); + accum += v.getSizeBytes() - int64_t(sizeof(CesiumGltf::Class)); + } + accum += int64_t( + this->enums.bucket_count() * + (sizeof(std::string) + sizeof(CesiumGltf::Enum))); + for (const auto& [k, v] : this->enums) { + accum += int64_t(k.capacity() * sizeof(char) - sizeof(std::string)); + accum += v.getSizeBytes() - int64_t(sizeof(CesiumGltf::Enum)); + } + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/Skin.h b/CesiumGltf/generated/include/CesiumGltf/Skin.h index 1900693d4..fa02cd686 100644 --- a/CesiumGltf/generated/include/CesiumGltf/Skin.h +++ b/CesiumGltf/generated/include/CesiumGltf/Skin.h @@ -37,5 +37,20 @@ struct CESIUMGLTF_API Skin final : public CesiumGltf::NamedObject { * @brief Indices of skeleton nodes, used as joints in this skin. */ std::vector joints; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Skin)); + accum += CesiumGltf::NamedObject::getSizeBytes() - + int64_t(sizeof(CesiumGltf::NamedObject)); + accum += int64_t(sizeof(int32_t) * this->joints.capacity()); + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/Texture.h b/CesiumGltf/generated/include/CesiumGltf/Texture.h index 0e914e0e1..5ac772285 100644 --- a/CesiumGltf/generated/include/CesiumGltf/Texture.h +++ b/CesiumGltf/generated/include/CesiumGltf/Texture.h @@ -26,5 +26,20 @@ struct CESIUMGLTF_API Texture final : public CesiumGltf::NamedObject { * otherwise behavior is undefined. */ int32_t source = -1; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(Texture)); + accum += CesiumGltf::NamedObject::getSizeBytes() - + int64_t(sizeof(CesiumGltf::NamedObject)); + + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/generated/include/CesiumGltf/TextureInfo.h b/CesiumGltf/generated/include/CesiumGltf/TextureInfo.h index f9f26c91e..d0e76dc5f 100644 --- a/CesiumGltf/generated/include/CesiumGltf/TextureInfo.h +++ b/CesiumGltf/generated/include/CesiumGltf/TextureInfo.h @@ -31,5 +31,20 @@ struct CESIUMGLTF_API TextureInfo : public CesiumUtility::ExtensibleObject { * coordinate attributes for the material to be applicable to it. */ int64_t texCoord = 0; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(TextureInfo)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/include/CesiumGltf/NamedObject.h b/CesiumGltf/include/CesiumGltf/NamedObject.h index 3f0a9997b..bef811450 100644 --- a/CesiumGltf/include/CesiumGltf/NamedObject.h +++ b/CesiumGltf/include/CesiumGltf/NamedObject.h @@ -20,5 +20,18 @@ struct CESIUMGLTF_API NamedObject : public CesiumUtility::ExtensibleObject { * the same name, or two accessors could even have the same name. */ std::string name; + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += sizeof(NamedObject); + accum += ExtensibleObject::getSizeBytes() - sizeof(ExtensibleObject); + accum += this->name.capacity() * sizeof(char); + return accum; + } }; } // namespace CesiumGltf diff --git a/CesiumGltf/src/PropertyTableView.cpp b/CesiumGltf/src/PropertyTableView.cpp index fb2ff97db..5d8999a8a 100644 --- a/CesiumGltf/src/PropertyTableView.cpp +++ b/CesiumGltf/src/PropertyTableView.cpp @@ -118,7 +118,7 @@ PropertyTableView::PropertyTableView( return; } - const std::optional& schema = pMetadata->schema; + const CesiumUtility::IntrusivePointer& schema = pMetadata->schema; if (!schema) { _status = PropertyTableViewStatus::ErrorMissingSchema; return; diff --git a/CesiumGltfReader/generated/src/GeneratedJsonHandlers.cpp b/CesiumGltfReader/generated/src/GeneratedJsonHandlers.cpp index 8c03be336..e39d3f372 100644 --- a/CesiumGltfReader/generated/src/GeneratedJsonHandlers.cpp +++ b/CesiumGltfReader/generated/src/GeneratedJsonHandlers.cpp @@ -3151,7 +3151,7 @@ namespace CesiumGltfReader { SchemaJsonHandler::SchemaJsonHandler( const CesiumJsonReader::JsonReaderOptions& options) noexcept - : CesiumJsonReader::ExtensibleObjectJsonHandler(options), + : CesiumJsonReader::SharedAssetJsonHandler(options), _id(), _name(), _description(), @@ -3162,7 +3162,7 @@ SchemaJsonHandler::SchemaJsonHandler( void SchemaJsonHandler::reset( CesiumJsonReader::IJsonHandler* pParentHandler, CesiumGltf::Schema* pObject) { - CesiumJsonReader::ExtensibleObjectJsonHandler::reset(pParentHandler, pObject); + CesiumJsonReader::SharedAssetJsonHandler::reset(pParentHandler, pObject); this->_pObject = pObject; } @@ -3194,7 +3194,7 @@ CesiumJsonReader::IJsonHandler* SchemaJsonHandler::readObjectKeySchema( if ("enums"s == str) return property("enums", this->_enums, o.enums); - return this->readObjectKeyExtensibleObject(objectType, str, *this->_pObject); + return this->readObjectKeySharedAsset(objectType, str, *this->_pObject); } SchemaReader::SchemaReader() { registerReaderExtensions(this->_options); } diff --git a/CesiumGltfReader/generated/src/SchemaJsonHandler.h b/CesiumGltfReader/generated/src/SchemaJsonHandler.h index a300ac5a4..ffbbdcd71 100644 --- a/CesiumGltfReader/generated/src/SchemaJsonHandler.h +++ b/CesiumGltfReader/generated/src/SchemaJsonHandler.h @@ -7,7 +7,7 @@ #include #include -#include +#include #include namespace CesiumJsonReader { @@ -15,7 +15,7 @@ class JsonReaderOptions; } namespace CesiumGltfReader { -class SchemaJsonHandler : public CesiumJsonReader::ExtensibleObjectJsonHandler { +class SchemaJsonHandler : public CesiumJsonReader::SharedAssetJsonHandler { public: using ValueType = CesiumGltf::Schema; diff --git a/CesiumGltfReader/include/CesiumGltfReader/GltfReader.h b/CesiumGltfReader/include/CesiumGltfReader/GltfReader.h index 62a496dcf..204abd48a 100644 --- a/CesiumGltfReader/include/CesiumGltfReader/GltfReader.h +++ b/CesiumGltfReader/include/CesiumGltfReader/GltfReader.h @@ -116,6 +116,12 @@ struct CESIUMGLTFREADER_API GltfReaderOptions { */ CesiumUtility::IntrusivePointer pSharedAssetSystem = GltfSharedAssetSystem::getDefault(); + + /** + * @brief Whether the `schemaUri` property of `EXT_structural_metadata` will + * be properly resolved. If false, any external schemas will be ignored. + */ + bool resolveExternalStructuralMetadata = true; }; /** diff --git a/CesiumGltfReader/include/CesiumGltfReader/GltfSharedAssetSystem.h b/CesiumGltfReader/include/CesiumGltfReader/GltfSharedAssetSystem.h index f28eaafa1..70d87e95c 100644 --- a/CesiumGltfReader/include/CesiumGltfReader/GltfSharedAssetSystem.h +++ b/CesiumGltfReader/include/CesiumGltfReader/GltfSharedAssetSystem.h @@ -2,6 +2,11 @@ #include #include +#include + +namespace CesiumGltf { +class Schema; +} namespace CesiumGltfReader { @@ -23,6 +28,14 @@ class GltfSharedAssetSystem * @brief The asset depot for images. */ CesiumUtility::IntrusivePointer pImage; + + using SchemaDepot = CesiumAsync:: + SharedAssetDepot; + + /** + * @brief The asset depot for schemas. + */ + CesiumUtility::IntrusivePointer pExternalMetadataSchema; }; } // namespace CesiumGltfReader diff --git a/CesiumGltfReader/include/CesiumGltfReader/NetworkSchemaAssetDescriptor.h b/CesiumGltfReader/include/CesiumGltfReader/NetworkSchemaAssetDescriptor.h new file mode 100644 index 000000000..9cd9a8df5 --- /dev/null +++ b/CesiumGltfReader/include/CesiumGltfReader/NetworkSchemaAssetDescriptor.h @@ -0,0 +1,48 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include + +namespace CesiumAsync { +class AsyncSystem; +} + +namespace CesiumGltfReader { + +/** + * @brief A description of a schema asset that can be loaded from the network + * using an {@link IAssetAccessor}. This includes a URL and any headers to be + * included in the request. + */ +struct NetworkSchemaAssetDescriptor + : public CesiumAsync::NetworkAssetDescriptor { + /** + * @brief Determines if this descriptor is identical to another one. + */ + bool operator==(const NetworkSchemaAssetDescriptor& rhs) const noexcept; + + /** + * @brief Request this asset from the network using the provided asset + * accessor and return the loaded {@link Schema}. + * + * @param asyncSystem The async system. + * @param pAssetAccessor The asset accessor. + * @return A future that resolves to the schema asset once the request is + * complete. + */ + CesiumAsync::Future> load( + const CesiumAsync::AsyncSystem& asyncSystem, + const std::shared_ptr& pAssetAccessor) const; +}; + +} // namespace CesiumGltfReader + +template <> struct std::hash { + std::size_t operator()( + const CesiumGltfReader::NetworkSchemaAssetDescriptor& key) const noexcept; +}; diff --git a/CesiumGltfReader/src/GltfReader.cpp b/CesiumGltfReader/src/GltfReader.cpp index 28a84b941..7f09a48fe 100644 --- a/CesiumGltfReader/src/GltfReader.cpp +++ b/CesiumGltfReader/src/GltfReader.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -473,6 +474,19 @@ void CesiumGltfReader::GltfReader::postprocessGltf( } } + { + // We need to obtain the extension to find out if we have another buffer we + // need to resolve. We can't use this pointer later since the result is + // moved, so we'll do it twice. + ExtensionModelExtStructuralMetadata* pStructuralMetadataTemp = + result.model->getExtension(); + + if (pStructuralMetadataTemp && + pStructuralMetadataTemp->schemaUri.has_value()) { + ++uriBuffersCount; + } + } + if (uriBuffersCount == 0) { return asyncSystem.createResolvedFuture(std::move(result)); } @@ -583,6 +597,60 @@ void CesiumGltfReader::GltfReader::postprocessGltf( } } + ExtensionModelExtStructuralMetadata* pStructuralMetadata = + pResult->model->getExtension(); + + if (options.resolveExternalStructuralMetadata && pStructuralMetadata && + pStructuralMetadata->schemaUri.has_value()) { + + auto getAsset = [&options]( + const AsyncSystem& asyncSystem, + const std::shared_ptr& pAssetAccessor, + const std::string& uri, + const std::vector& headers) + -> SharedFuture> { + NetworkSchemaAssetDescriptor assetKey{{uri, headers}}; + + if (options.pSharedAssetSystem == nullptr || + options.pSharedAssetSystem->pImage == nullptr) { + // We don't have a depot, so fetch this asset directly. + return assetKey.load(asyncSystem, pAssetAccessor).share(); + } else { + // We have a depot, so fetch this asset via that depot. + return options.pSharedAssetSystem->pExternalMetadataSchema->getOrCreate( + asyncSystem, + pAssetAccessor, + assetKey); + } + }; + + SharedFuture> future = getAsset( + asyncSystem, + pAssetAccessor, + *pStructuralMetadata->schemaUri, + tHeaders); + + resolvedBuffers.push_back(future.thenInWorkerThread( + [pStructuralMetadata = pStructuralMetadata]( + const ResultPointer& loadedSchema) { + std::string schemaUri = *pStructuralMetadata->schemaUri; + pStructuralMetadata->schemaUri = std::nullopt; + + if (loadedSchema.pValue) { + pStructuralMetadata->schema = loadedSchema.pValue; + return ExternalBufferLoadResult{ + true, + schemaUri, + loadedSchema.errors}; + } + + return ExternalBufferLoadResult{ + false, + schemaUri, + loadedSchema.errors}; + })); + } + return asyncSystem.all(std::move(resolvedBuffers)) .thenInWorkerThread( [pResult = std::move(pResult)]( diff --git a/CesiumGltfReader/src/GltfSharedAssetSystem.cpp b/CesiumGltfReader/src/GltfSharedAssetSystem.cpp index ffe97c6cd..494a41c58 100644 --- a/CesiumGltfReader/src/GltfSharedAssetSystem.cpp +++ b/CesiumGltfReader/src/GltfSharedAssetSystem.cpp @@ -1,3 +1,4 @@ +#include #include using namespace CesiumAsync; @@ -19,6 +20,14 @@ CesiumUtility::IntrusivePointer createDefault() { return key.load(asyncSystem, pAssetAccessor); })); + p->pExternalMetadataSchema.emplace(std::function( + [](const AsyncSystem& asyncSystem, + const std::shared_ptr& pAssetAccessor, + const NetworkSchemaAssetDescriptor& key) + -> Future> { + return key.load(asyncSystem, pAssetAccessor); + })); + return p; } diff --git a/CesiumGltfReader/src/NetworkSchemaAssetDescriptor.cpp b/CesiumGltfReader/src/NetworkSchemaAssetDescriptor.cpp new file mode 100644 index 000000000..19b14afe2 --- /dev/null +++ b/CesiumGltfReader/src/NetworkSchemaAssetDescriptor.cpp @@ -0,0 +1,50 @@ +#include +#include +#include +#include + +using namespace CesiumAsync; +using namespace CesiumGltf; +using namespace CesiumGltfReader; +using namespace CesiumUtility; + +namespace CesiumGltfReader { + +bool NetworkSchemaAssetDescriptor::operator==( + const NetworkSchemaAssetDescriptor& rhs) const noexcept { + return NetworkAssetDescriptor::operator==(rhs); +} + +Future> NetworkSchemaAssetDescriptor::load( + const AsyncSystem& asyncSystem, + const std::shared_ptr& pAssetAccessor) const { + return this->loadBytesFromNetwork(asyncSystem, pAssetAccessor) + .thenInWorkerThread([](Result>&& result) { + if (!result.value) { + return ResultPointer(result.errors); + } + + SchemaReader reader{}; + CesiumJsonReader::ReadJsonResult jsonReadResult = + reader.readFromJson(*result.value); + + CesiumUtility::IntrusivePointer pSchema; + if (result.value.has_value()) { + pSchema.emplace(std::move(*jsonReadResult.value)); + } + + result.errors.merge( + ErrorList{jsonReadResult.errors, jsonReadResult.warnings}); + + return ResultPointer(pSchema, std::move(result.errors)); + }); +} +} // namespace CesiumGltfReader + +std::size_t +std::hash::operator()( + const CesiumGltfReader::NetworkSchemaAssetDescriptor& key) const noexcept { + std::hash baseHash{}; + size_t result = baseHash(key); + return result; +} diff --git a/CesiumGltfReader/test/TestExtensionModelExtStructuralMetadata.cpp b/CesiumGltfReader/test/TestExtensionModelExtStructuralMetadata.cpp index d142b3cf2..493be8e6f 100644 --- a/CesiumGltfReader/test/TestExtensionModelExtStructuralMetadata.cpp +++ b/CesiumGltfReader/test/TestExtensionModelExtStructuralMetadata.cpp @@ -1,11 +1,17 @@ #include "CesiumGltfReader/GltfReader.h" #include +#include +#include +#include +#include +#include #include using namespace CesiumGltf; using namespace CesiumUtility; +using namespace CesiumNativeTests; TEST_CASE( "Can deserialize EXT_structural_metadata example with propertyTables") { @@ -75,7 +81,7 @@ TEST_CASE( readerResult.model->getExtension(); REQUIRE(pMetadata); - REQUIRE(pMetadata->schema.has_value()); + REQUIRE(pMetadata->schema != nullptr); REQUIRE(pMetadata->schema->classes.size() == 1); auto treesIt = pMetadata->schema->classes.find("tree"); @@ -89,3 +95,129 @@ TEST_CASE( REQUIRE(birdCountIt->second.min.has_value()); REQUIRE(birdCountIt->second.min->getSafeNumberOrDefault(-1) == 1); } + +TEST_CASE("Can load an external structural metadata schema from a URI") { + const std::string schema = R"( + { + "classes" : { + "exampleMetadataClass" : { + "name" : "Example metadata class", + "description" : "An example metadata class for property attributes", + "properties" : { + "intensity" : { + "name" : "Example intensity property", + "description" : "An example property for the intensity, with component type FLOAT32", + "type" : "SCALAR", + "componentType" : "FLOAT32" + }, + "classification" : { + "name" : "Example classification property", + "description" : "An example property for the classification, with the classificationEnumType", + "type" : "ENUM", + "enumType" : "classificationEnumType" + } + } + } + }, + "enums" : { + "classificationEnumType" : { + "valueType": "UINT16", + "values" : [ { + "name" : "MediumVegetation", + "value" : 0 + }, { + "name" : "Buildings", + "value" : 1 + } ] + } + } + } + )"; + + const std::string gltf = R"( + { + "extensions" : { + "EXT_structural_metadata" : { + "schemaUri" : "MetadataSchema.json", + "propertyAttributes" : [ { + "class" : "exampleMetadataClass", + "properties" : { + "intensity" : { + "attribute" : "_INTENSITY" + }, + "classification" : { + "attribute" : "_CLASSIFICATION" + } + } + } ] + } + }, + "extensionsUsed" : [ "EXT_structural_metadata" ], + "asset" : { + "version" : "2.0" + } + } + )"; + + auto pMockTaskProcessor = std::make_shared(); + CesiumAsync::AsyncSystem asyncSystem{pMockTaskProcessor}; + + auto pMockGltfBufferResponse = std::make_unique( + uint16_t(200), + "test.gltf", + CesiumAsync::HttpHeaders{}, + std::vector( + reinterpret_cast(gltf.c_str()), + reinterpret_cast(gltf.c_str() + gltf.size()))); + auto pMockGltfBufferRequest = std::make_unique( + "GET", + "test.gltf", + CesiumAsync::HttpHeaders{}, + std::move(pMockGltfBufferResponse)); + + auto pMockSchemaResponse = std::make_unique( + uint16_t(200), + "MetadataSchema.json", + CesiumAsync::HttpHeaders{}, + std::vector( + reinterpret_cast(schema.c_str()), + reinterpret_cast(schema.c_str() + schema.size()))); + auto pMockSchemaRequest = std::make_unique( + "GET", + "MetadataSchema.json", + CesiumAsync::HttpHeaders{}, + std::move(pMockSchemaResponse)); + + std::map> mapUrlToRequest{ + {"test.gltf", std::move(pMockGltfBufferRequest)}, + {"MetadataSchema.json", std::move(pMockSchemaRequest)}}; + auto pMockAssetAccessor = + std::make_shared(std::move(mapUrlToRequest)); + + CesiumGltfReader::GltfReaderOptions options; + options.resolveExternalStructuralMetadata = true; + options.pSharedAssetSystem = + CesiumGltfReader::GltfSharedAssetSystem::getDefault(); + CesiumGltfReader::GltfReader reader; + CesiumGltfReader::GltfReaderResult readerResult = + reader.loadGltf(asyncSystem, "test.gltf", {}, pMockAssetAccessor, options) + .waitInMainThread(); + + REQUIRE(readerResult.errors.empty()); + REQUIRE(readerResult.model.has_value()); + + ExtensionModelExtStructuralMetadata* pMetadata = + readerResult.model->getExtension(); + REQUIRE(pMetadata); + + REQUIRE(pMetadata->schema != nullptr); + REQUIRE(pMetadata->schema->classes.size() == 1); + auto it = pMetadata->schema->classes.find("exampleMetadataClass"); + REQUIRE(it != pMetadata->schema->classes.end()); + REQUIRE(it->second.properties.size() == 2); + + REQUIRE(pMetadata->schema->enums.size() == 1); + REQUIRE( + pMetadata->schema->enums.find("classificationEnumType") != + pMetadata->schema->enums.end()); +} diff --git a/CesiumGltfWriter/generated/src/ModelJsonWriter.cpp b/CesiumGltfWriter/generated/src/ModelJsonWriter.cpp index 242227122..073b8bd75 100644 --- a/CesiumGltfWriter/generated/src/ModelJsonWriter.cpp +++ b/CesiumGltfWriter/generated/src/ModelJsonWriter.cpp @@ -72,6 +72,7 @@ #include #include #include +#include #include namespace CesiumGltfWriter { @@ -412,6 +413,14 @@ template CesiumJsonWriter::JsonWriter& jsonWriter, const CesiumJsonWriter::ExtensionWriterContext& context); +template +[[maybe_unused]] void writeJson( + const CesiumUtility::IntrusivePointer& ptr, + CesiumJsonWriter::JsonWriter& jsonWriter, + const CesiumJsonWriter::ExtensionWriterContext& context) { + writeJson(*ptr, jsonWriter, context); +} + [[maybe_unused]] void writeJson( const std::string& str, CesiumJsonWriter::JsonWriter& jsonWriter, @@ -520,6 +529,14 @@ void writeExtensibleObject( } } +template +void writeSharedAsset( + const T& obj, + CesiumJsonWriter::JsonWriter& jsonWriter, + const CesiumJsonWriter::ExtensionWriterContext& context) { + writeExtensibleObject(obj, jsonWriter, context); +} + template void writeNamedObject( const T& obj, @@ -709,10 +726,8 @@ void writeJson( const CesiumJsonWriter::ExtensionWriterContext& context) { jsonWriter.StartObject(); - if (obj.schema.has_value()) { - jsonWriter.Key("schema"); - writeJson(obj.schema, jsonWriter, context); - } + jsonWriter.Key("schema"); + writeJson(obj.schema, jsonWriter, context); if (obj.schemaUri.has_value()) { jsonWriter.Key("schemaUri"); @@ -1272,7 +1287,7 @@ void writeJson( writeJson(obj.enums, jsonWriter, context); } - writeExtensibleObject(obj, jsonWriter, context); + writeSharedAsset(obj, jsonWriter, context); jsonWriter.EndObject(); } diff --git a/CesiumJsonReader/include/CesiumJsonReader/ObjectJsonHandler.h b/CesiumJsonReader/include/CesiumJsonReader/ObjectJsonHandler.h index d5d4e8923..51a11b77f 100644 --- a/CesiumJsonReader/include/CesiumJsonReader/ObjectJsonHandler.h +++ b/CesiumJsonReader/include/CesiumJsonReader/ObjectJsonHandler.h @@ -3,6 +3,8 @@ #include "JsonHandler.h" #include "Library.h" +#include + #include namespace CesiumJsonReader { @@ -25,6 +27,9 @@ class CESIUMJSONREADER_API ObjectJsonHandler : public JsonHandler { if constexpr (isOptional::value) { value.emplace(); accessor.reset(this, &value.value()); + } else if constexpr (isIntrusivePointer::value) { + value.emplace(); + accessor.reset(this, value.get()); } else { accessor.reset(this, &value); } @@ -50,6 +55,15 @@ class CESIUMJSONREADER_API ObjectJsonHandler : public JsonHandler { static constexpr bool value = true; }; + template struct isIntrusivePointer { + static constexpr bool value = false; + }; + + template + struct isIntrusivePointer> { + static constexpr bool value = true; + }; + int32_t _depth = 0; const char* _currentKey = nullptr; }; diff --git a/CesiumJsonReader/include/CesiumJsonReader/SharedAssetJsonHandler.h b/CesiumJsonReader/include/CesiumJsonReader/SharedAssetJsonHandler.h new file mode 100644 index 000000000..b2778fb6d --- /dev/null +++ b/CesiumJsonReader/include/CesiumJsonReader/SharedAssetJsonHandler.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include +#include + +#include + +namespace CesiumJsonReader { + +class SharedAssetJsonHandler + : public CesiumJsonReader::ExtensibleObjectJsonHandler { +public: + explicit SharedAssetJsonHandler( + const CesiumJsonReader::JsonReaderOptions& context) noexcept; + +protected: + void reset(IJsonHandler* pParent, CesiumUtility::ExtensibleObject* pObject); + IJsonHandler* readObjectKeySharedAsset( + const std::string& objectType, + const std::string_view& str, + CesiumUtility::ExtensibleObject& o); + +private: +}; +} // namespace CesiumJsonReader diff --git a/CesiumJsonReader/src/SharedAssetJsonHandler.cpp b/CesiumJsonReader/src/SharedAssetJsonHandler.cpp new file mode 100644 index 000000000..b8a36902a --- /dev/null +++ b/CesiumJsonReader/src/SharedAssetJsonHandler.cpp @@ -0,0 +1,26 @@ +#include "CesiumJsonReader/SharedAssetJsonHandler.h" + +#include "CesiumJsonReader/ExtensibleObjectJsonHandler.h" +#include "CesiumJsonReader/ExtensionsJsonHandler.h" +#include "CesiumJsonReader/JsonHandler.h" +#include "CesiumJsonReader/JsonReaderOptions.h" + +namespace CesiumJsonReader { +SharedAssetJsonHandler::SharedAssetJsonHandler( + const CesiumJsonReader::JsonReaderOptions& context) noexcept + : ExtensibleObjectJsonHandler(context) {} + +void SharedAssetJsonHandler::reset( + IJsonHandler* pParent, + CesiumUtility::ExtensibleObject* pObject) { + ExtensibleObjectJsonHandler::reset(pParent, pObject); +} + +CesiumJsonReader::IJsonHandler* +SharedAssetJsonHandler::readObjectKeySharedAsset( + const std::string& objectType, + const std::string_view& str, + CesiumUtility::ExtensibleObject& o) { + return this->readObjectKeyExtensibleObject(objectType, str, o); +} +} // namespace CesiumJsonReader diff --git a/CesiumQuantizedMeshTerrain/generated/include/CesiumQuantizedMeshTerrain/AvailabilityRectangle.h b/CesiumQuantizedMeshTerrain/generated/include/CesiumQuantizedMeshTerrain/AvailabilityRectangle.h index 396bd28d1..366c5498d 100644 --- a/CesiumQuantizedMeshTerrain/generated/include/CesiumQuantizedMeshTerrain/AvailabilityRectangle.h +++ b/CesiumQuantizedMeshTerrain/generated/include/CesiumQuantizedMeshTerrain/AvailabilityRectangle.h @@ -35,5 +35,20 @@ struct CESIUMQUANTIZEDMESHTERRAIN_API AvailabilityRectangle final * @brief The index of the end tile in the Y direction. */ int64_t endY = int64_t(); + + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(AvailabilityRectangle)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + + return accum; + } }; } // namespace CesiumQuantizedMeshTerrain diff --git a/CesiumQuantizedMeshTerrain/generated/include/CesiumQuantizedMeshTerrain/LayerSpec.h b/CesiumQuantizedMeshTerrain/generated/include/CesiumQuantizedMeshTerrain/LayerSpec.h index bd6680651..fe6565b01 100644 --- a/CesiumQuantizedMeshTerrain/generated/include/CesiumQuantizedMeshTerrain/LayerSpec.h +++ b/CesiumQuantizedMeshTerrain/generated/include/CesiumQuantizedMeshTerrain/LayerSpec.h @@ -102,6 +102,48 @@ struct CESIUMQUANTIZEDMESHTERRAIN_API LayerSpec */ std::string version = "1.0.0"; + /** + * @brief Calculates the size in bytes of this object, including the contents + * of all collections, pointers, and strings. This will NOT include the size + * of any extensions attached to the object. Calling this method may be slow + * as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(LayerSpec)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + accum += int64_t(this->attribution.capacity() * sizeof(char)); + accum += int64_t( + sizeof(std::vector) * + this->available.capacity()); + for (const std::vector& + valueOuter : this->available) { + accum += int64_t( + sizeof(CesiumQuantizedMeshTerrain::AvailabilityRectangle) * + valueOuter.capacity()); + for (const CesiumQuantizedMeshTerrain::AvailabilityRectangle& value : + valueOuter) { + accum += + value.getSizeBytes() - + int64_t(sizeof(CesiumQuantizedMeshTerrain::AvailabilityRectangle)); + } + } + accum += int64_t(sizeof(double) * this->bounds.capacity()); + accum += int64_t(this->description.capacity() * sizeof(char)); + accum += int64_t(sizeof(std::string) * this->extensionsProperty.capacity()); + accum += int64_t(this->format.capacity() * sizeof(char)); + accum += int64_t(this->name.capacity() * sizeof(char)); + if (this->parentUrl) { + accum += int64_t(this->parentUrl->capacity() * sizeof(char)); + } + accum += int64_t(this->projection.capacity() * sizeof(char)); + accum += int64_t(this->scheme.capacity() * sizeof(char)); + accum += int64_t(sizeof(std::string) * this->tiles.capacity()); + accum += int64_t(this->version.capacity() * sizeof(char)); + return accum; + } + private: /** * @brief This class is not meant to be instantiated directly. Use {@link Layer} instead. diff --git a/CesiumQuantizedMeshTerrain/generated/src/LayerJsonWriter.cpp b/CesiumQuantizedMeshTerrain/generated/src/LayerJsonWriter.cpp index b7fc40662..d4bd3c21d 100644 --- a/CesiumQuantizedMeshTerrain/generated/src/LayerJsonWriter.cpp +++ b/CesiumQuantizedMeshTerrain/generated/src/LayerJsonWriter.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include namespace CesiumQuantizedMeshTerrain { @@ -33,6 +34,14 @@ template CesiumJsonWriter::JsonWriter& jsonWriter, const CesiumJsonWriter::ExtensionWriterContext& context); +template +[[maybe_unused]] void writeJson( + const CesiumUtility::IntrusivePointer& ptr, + CesiumJsonWriter::JsonWriter& jsonWriter, + const CesiumJsonWriter::ExtensionWriterContext& context) { + writeJson(*ptr, jsonWriter, context); +} + [[maybe_unused]] void writeJson( const std::string& str, CesiumJsonWriter::JsonWriter& jsonWriter, @@ -141,6 +150,14 @@ void writeExtensibleObject( } } +template +void writeSharedAsset( + const T& obj, + CesiumJsonWriter::JsonWriter& jsonWriter, + const CesiumJsonWriter::ExtensionWriterContext& context) { + writeExtensibleObject(obj, jsonWriter, context); +} + template void writeNamedObject( const T& obj, diff --git a/CesiumUtility/include/CesiumUtility/ExtensibleObject.h b/CesiumUtility/include/CesiumUtility/ExtensibleObject.h index c8e56755b..90cc36dfc 100644 --- a/CesiumUtility/include/CesiumUtility/ExtensibleObject.h +++ b/CesiumUtility/include/CesiumUtility/ExtensibleObject.h @@ -118,5 +118,30 @@ struct CESIUMUTILITY_API ExtensibleObject { * experimental, or next-version properties. */ JsonValue::Object unknownProperties; + + /** + * @brief Calculates the size in bytes of this ExtensibleObject, including all + * of its extras but NOT including its extensions. Calling this method may be + * slow as it requires traversing the entire object. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += sizeof(ExtensibleObject); + + accum += this->extras.size() * (sizeof(std::string) + sizeof(JsonValue)); + for (const auto& [k, v] : this->extras) { + accum += k.capacity() * sizeof(char) - sizeof(std::string); + accum += v.getSizeBytes() - sizeof(JsonValue); + } + + accum += this->unknownProperties.size() * + (sizeof(std::string) + sizeof(JsonValue)); + for (const auto& [k, v] : this->unknownProperties) { + accum += k.capacity() * sizeof(char) - sizeof(std::string); + accum += v.getSizeBytes() - sizeof(JsonValue); + } + + return accum; + } }; } // namespace CesiumUtility diff --git a/CesiumUtility/include/CesiumUtility/JsonValue.h b/CesiumUtility/include/CesiumUtility/JsonValue.h index 833820141..5c8320973 100644 --- a/CesiumUtility/include/CesiumUtility/JsonValue.h +++ b/CesiumUtility/include/CesiumUtility/JsonValue.h @@ -620,6 +620,46 @@ class CESIUMUTILITY_API JsonValue final { return std::holds_alternative(this->value); } + /** + * @brief Returns the size in bytes of this `JsonValue`. + */ + int64_t getSizeBytes() const noexcept { + struct Operation { + int64_t operator()([[maybe_unused]] const Null& value) { return 0; } + int64_t operator()([[maybe_unused]] const double& value) { return 0; } + int64_t operator()([[maybe_unused]] const std::uint64_t& value) { + return 0; + } + int64_t operator()([[maybe_unused]] const std::int64_t& value) { + return 0; + } + int64_t operator()([[maybe_unused]] const Bool& value) { return 0; } + int64_t operator()(const String& value) { + return value.capacity() * sizeof(char); + } + int64_t operator()(const Object& value) { + int64_t accum = 0; + accum += value.size() * (sizeof(std::string) + sizeof(JsonValue)); + for (const auto& [k, v] : value) { + accum += k.capacity() * sizeof(char) - sizeof(std::string); + accum += v.getSizeBytes() - sizeof(JsonValue); + } + + return accum; + } + int64_t operator()(const Array& value) { + int64_t accum = 0; + accum += sizeof(JsonValue) * value.capacity(); + for (const JsonValue& v : value) { + accum += v.getSizeBytes() - sizeof(JsonValue); + } + return accum; + } + }; + + return sizeof(JsonValue) + std::visit(Operation{}, this->value); + } + /** * @brief The actual value. * diff --git a/package-lock.json b/package-lock.json index a11068450..27d899b13 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cesium-native", - "version": "0.40.1", + "version": "0.41.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "cesium-native", - "version": "0.40.1", + "version": "0.41.0", "license": "Apache-2.0", "devDependencies": { "clang-format": "^1.5.0", @@ -208,4 +208,4 @@ "dev": true } } -} +} \ No newline at end of file diff --git a/tools/generate-classes/NameFormatters.js b/tools/generate-classes/NameFormatters.js index 4a2a49516..f2a4872ff 100644 --- a/tools/generate-classes/NameFormatters.js +++ b/tools/generate-classes/NameFormatters.js @@ -1,4 +1,4 @@ -const qualifiedTypeNameRegex = /(?:(?.+)::)?(?.+)/; +const qualifiedTypeNameRegex = /(?:(?.+)::)?(?[^<]+)/; const NameFormatters = { getReaderNamespace: function getReaderNamespace(namespace, readerNamespace) { diff --git a/tools/generate-classes/generate.js b/tools/generate-classes/generate.js index 0f841a388..b5552a838 100644 --- a/tools/generate-classes/generate.js +++ b/tools/generate-classes/generate.js @@ -4,7 +4,7 @@ const indent = require("./indent"); const lodash = require("lodash"); const NameFormatters = require("./NameFormatters"); const path = require("path"); -const resolveProperty = require("./resolveProperty"); +const { resolveProperty, resolveSizeOfForProperty } = require("./resolveProperty"); const unindent = require("./unindent"); function generate(options, schema, writers) { @@ -37,7 +37,12 @@ function generate(options, schema, writers) { } let base = "CesiumUtility::ExtensibleObject"; - if (baseSchema !== undefined) { + if (config.classes[schema.title] && config.classes[schema.title].isAsset) { + if (baseSchema !== undefined && baseSchema.title !== 'glTF Property') { + throw new Error("An asset must inherit from ExtensibleObject."); + } + base = `CesiumUtility::SharedAsset<${baseName}>`; + } else if (baseSchema !== undefined) { base = getNameFromTitle(config, baseSchema.title); } @@ -98,12 +103,26 @@ function generate(options, schema, writers) { ${indent(localTypes.join("\n\n"), 16)} ${indent( - properties - .map((property) => formatProperty(property)) - .filter(propertyText => propertyText !== undefined) - .join("\n\n"), - 16 - )} + properties + .map((property) => formatProperty(property)) + .filter(propertyText => propertyText !== undefined) + .join("\n\n"), + 16 + )} + + /** + * @brief Calculates the size in bytes of this object, including the contents of all collections, pointers, and strings. + * This will NOT include the size of any extensions attached to the object. + * Calling this method may be slow as it requires traversing the object's entire structure. + */ + int64_t getSizeBytes() const { + int64_t accum = 0; + accum += int64_t(sizeof(${name}${thisConfig.toBeInherited ? "Spec" : ""})); + accum += ${base}::getSizeBytes() - int64_t(sizeof(${base})); + ${indent(properties.map(p => resolveSizeOfForProperty(p, "this->" + p.cppSafeName, "accum")).filter(p => p).join("\n"))} + return accum; + } + ${thisConfig.toBeInherited ? privateSpecConstructor(name) : ""} }; } @@ -181,11 +200,11 @@ function generate(options, schema, writers) { ${indent(readerLocalTypes.join("\n\n"), 12)} ${namespace}::${name}* _pObject = nullptr; ${indent( - properties - .map((property) => formatReaderProperty(property)) - .join("\n"), - 12 - )} + properties + .map((property) => formatReaderProperty(property)) + .join("\n"), + 12 + )} }; } `; @@ -304,8 +323,7 @@ function generate(options, schema, writers) { .filter((p) => p.readerType.toLowerCase().indexOf("jsonhandler") != -1) .map( (p) => - `_${p.cppSafeName}(${ - p.schemas && p.schemas.length > 0 ? varName : "" + `_${p.cppSafeName}(${p.schemas && p.schemas.length > 0 ? varName : "" })` ) .join(", "); @@ -356,11 +374,11 @@ function generate(options, schema, writers) { ${properties.length > 0 ? ` ${indent( - properties - .map((property) => formatReaderPropertyImpl(property)) - .join("\n"), - 10 - )}` : `(void)o;`} + properties + .map((property) => formatReaderPropertyImpl(property)) + .join("\n"), + 10 + )}` : `(void)o;`} return this->readObjectKey${NameFormatters.removeNamespace(base)}(objectType, str, *this->_pObject); } @@ -402,11 +420,10 @@ function generate(options, schema, writers) { struct ${name}JsonWriter { using ValueType = ${namespace}::${name}; - ${ - thisConfig.extensionName - ? `static inline constexpr const char* ExtensionName = "${thisConfig.extensionName}";` - : "" - } + ${thisConfig.extensionName + ? `static inline constexpr const char* ExtensionName = "${thisConfig.extensionName}";` + : "" + } static void write( const ${namespace}::${name}& obj, @@ -443,11 +460,11 @@ function generate(options, schema, writers) { const CesiumJsonWriter::ExtensionWriterContext& context) { ${indent( - properties - .map((property) => formatWriterPropertyImpl(property)) - .join("\n\n"), - 10 - )} + properties + .map((property) => formatWriterPropertyImpl(property)) + .join("\n\n"), + 10 + )} write${NameFormatters.getWriterName(base)}(obj, jsonWriter, context); } @@ -474,11 +491,11 @@ function generate(options, schema, writers) { jsonWriter.StartObject(); ${indent( - properties - .map((property) => formatWriterPropertyImpl(property)) - .join("\n\n"), - 10 - )} + properties + .map((property) => formatWriterPropertyImpl(property)) + .join("\n\n"), + 10 + )} write${NameFormatters.getWriterName(base)}(obj, jsonWriter, context); @@ -488,15 +505,14 @@ function generate(options, schema, writers) { } const writeExtensionsRegistration = ` - ${ - extensions[schema.title] - ? extensions[schema.title] - .map((extension) => { - return `context.registerExtension<${namespace}::${name}, ${extension.className}JsonWriter>();`; - }) - .join("\n") - : "" - } + ${extensions[schema.title] + ? extensions[schema.title] + .map((extension) => { + return `context.registerExtension<${namespace}::${name}, ${extension.className}JsonWriter>();`; + }) + .join("\n") + : "" + } `; writers.push({ diff --git a/tools/generate-classes/generateCombinedWriter.js b/tools/generate-classes/generateCombinedWriter.js index f91544993..7bca1d6d7 100644 --- a/tools/generate-classes/generateCombinedWriter.js +++ b/tools/generate-classes/generateCombinedWriter.js @@ -30,18 +30,18 @@ function generateCombinedWriter(options) { // forward declarations namespace ${namespace} { ${writers - .map((writer) => { - return writer.writeForwardDeclaration; - }) - .join("\n")} + .map((writer) => { + return writer.writeForwardDeclaration; + }) + .join("\n")} } // namespace ${namespace} namespace ${writerNamespace} { ${writers - .map((writer) => { - return writer.writeDeclaration; - }) - .join("\n")} + .map((writer) => { + return writer.writeDeclaration; + }) + .join("\n")} } // namespace ${writerNamespace} `; @@ -53,26 +53,27 @@ function generateCombinedWriter(options) { #include "${name}JsonWriter.h" #include + #include #include #include #include #include ${writers - .map((writer) => { - return writer.writeInclude; - }) - .join("\n")} + .map((writer) => { + return writer.writeInclude; + }) + .join("\n")} namespace ${writerNamespace} { namespace { ${writers - .map((writer) => { - return writer.writeJsonDeclaration; - }) - .join("\n")} + .map((writer) => { + return writer.writeJsonDeclaration; + }) + .join("\n")} // Forward declaration to avoid circular dependency since some properties // are vector of unordered_map and others are unordered_map of vector @@ -82,6 +83,14 @@ function generateCombinedWriter(options) { CesiumJsonWriter::JsonWriter& jsonWriter, const CesiumJsonWriter::ExtensionWriterContext& context); + template + [[maybe_unused]] void writeJson( + const CesiumUtility::IntrusivePointer& ptr, + CesiumJsonWriter::JsonWriter& jsonWriter, + const CesiumJsonWriter::ExtensionWriterContext& context) { + writeJson(*ptr, jsonWriter, context); + } + [[maybe_unused]] void writeJson( const std::string& str, CesiumJsonWriter::JsonWriter& jsonWriter, @@ -190,6 +199,14 @@ function generateCombinedWriter(options) { } } + template + void writeSharedAsset( + const T& obj, + CesiumJsonWriter::JsonWriter& jsonWriter, + const CesiumJsonWriter::ExtensionWriterContext& context) { + writeExtensibleObject(obj, jsonWriter, context); + } + template void writeNamedObject( const T& obj, @@ -205,24 +222,24 @@ function generateCombinedWriter(options) { } ${writers - .map((writer) => { - return writer.writeBaseJsonDefinition ? writer.writeBaseJsonDefinition : ""; - }) - .join("\n")} + .map((writer) => { + return writer.writeBaseJsonDefinition ? writer.writeBaseJsonDefinition : ""; + }) + .join("\n")} ${writers - .map((writer) => { - return writer.writeJsonDefinition; - }) - .join("\n")} + .map((writer) => { + return writer.writeJsonDefinition; + }) + .join("\n")} } // namespace ${writerNamespace} ${writers - .map((writer) => { - return writer.writeDefinition; - }) - .join("\n")} + .map((writer) => { + return writer.writeDefinition; + }) + .join("\n")} } // namespace ${writerNamespace} `; diff --git a/tools/generate-classes/glTF.json b/tools/generate-classes/glTF.json index ce5829da6..5a5f8fb28 100644 --- a/tools/generate-classes/glTF.json +++ b/tools/generate-classes/glTF.json @@ -97,7 +97,8 @@ "overrideName": "PropertyTexture" }, "Schema in EXT_structural_metadata": { - "overrideName": "Schema" + "overrideName": "Schema", + "isAsset": true }, "Any Value": { "overrideName": "CesiumUtility::JsonValue" diff --git a/tools/generate-classes/resolveProperty.js b/tools/generate-classes/resolveProperty.js index 20616cce9..ed2a2bcb8 100644 --- a/tools/generate-classes/resolveProperty.js +++ b/tools/generate-classes/resolveProperty.js @@ -5,6 +5,30 @@ const makeIdentifier = require("./makeIdentifier"); const NameFormatters = require("./NameFormatters"); const unindent = require("./unindent"); +function resolveSizeOfForProperty( + property, + propertyName, + accumName +) { + if (property.sizeOfFormatter) { + return property.sizeOfFormatter(propertyName, accumName); + } + + // If the property has schemas, a definition for its getSizeBytes method is already + // being generated. + if (property.schemas && property.schemas.length > 0) { + if (property.isOptional) { + return `if(${propertyName}) { + ${accumName} += ${propertyName}->getSizeBytes() - int64_t(sizeof(${property.originalType})); + }`; + } + + return `${accumName} += ${propertyName}.getSizeBytes() - int64_t(sizeof(${property.type}));`; + } + + return null; +} + function resolveProperty( schemaCache, config, @@ -28,7 +52,7 @@ function resolveProperty( // If we don't know what's required, act as if everything is. // Specifically this means we _don't_ make it optional. const isRequired = required === undefined || required.includes(propertyName); - const makeOptional = !isRequired && propertyDetails.default === undefined; + let makeOptional = !isRequired && propertyDetails.default === undefined; if (isEnum(propertyDetails)) { return resolveEnum( @@ -66,6 +90,8 @@ function resolveProperty( readerHeaders: [``], readerType: "CesiumJsonReader::IntegerJsonHandler", needsInitialization: !makeOptional, + isOptional: makeOptional, + originalType: "int64_t" }; } else if (propertyDetails.type == "number") { return { @@ -75,6 +101,8 @@ function resolveProperty( readerHeaders: [``], readerType: "CesiumJsonReader::DoubleJsonHandler", needsInitialization: !makeOptional, + isOptional: makeOptional, + originalType: "double" }; } else if (propertyDetails.type == "boolean") { return { @@ -84,6 +112,8 @@ function resolveProperty( readerHeaders: ``, readerType: "CesiumJsonReader::BoolJsonHandler", needsInitialization: ~makeOptional, + isOptional: makeOptional, + originalType: "bool" }; } else if (propertyDetails.type == "string") { return { @@ -92,10 +122,20 @@ function resolveProperty( headers: ["", ...(makeOptional ? [""] : [])], readerHeaders: [``], readerType: "CesiumJsonReader::StringJsonHandler", + isOptional: makeOptional, + originalType: "std::string", defaultValue: propertyDetails.default !== undefined ? `"${propertyDetails.default.toString()}"` : undefined, + sizeOfFormatter: (propertyName, accumName) => { + if (makeOptional) { + return `if(${propertyName}) { + ${accumName} += int64_t(${propertyName}->capacity() * sizeof(char)); + }`; + } + return `${accumName} += int64_t(${propertyName}.capacity() * sizeof(char));`; + }, }; } else if (propertyDetails.type === "object" && propertyDetails.properties) { // This is an anonymous, inline object definition @@ -106,11 +146,12 @@ function resolveProperty( sourcePath: parentSchema.sourcePath, }; const type = getNameFromTitle(config, schema.title); + const typeName = NameFormatters.getName(type, namespace); return { ...propertyDefaults(propertyName, cppSafeName, propertyDetails), type: makeOptional - ? `std::optional<${NameFormatters.getName(type, namespace)}>` - : `${NameFormatters.getName(type, namespace)}`, + ? `std::optional<${typeName}>` + : `${typeName}`, headers: [ NameFormatters.getIncludeFromName(type, namespace), ...(makeOptional ? [""] : []), @@ -120,6 +161,8 @@ function resolveProperty( NameFormatters.getJsonHandlerIncludeFromName(type, readerNamespace), ], schemas: [schema], + isOptional: makeOptional, + originalType: typeName }; } else if ( propertyDetails.type === "object" && @@ -189,20 +232,37 @@ function resolveProperty( makeOptional ); } else { + let propertyType = NameFormatters.getName(type, namespace); + let sizeOfFormatter = undefined; + let headers = [NameFormatters.getIncludeFromName(type, namespace)]; + let originalType = propertyType; + if (config.classes[itemSchema.title] && config.classes[itemSchema.title].isAsset) { + propertyType = `CesiumUtility::IntrusivePointer<${propertyType}>`; + // An optional IntrusivePointer will just be a nullptr. + makeOptional = false; + // Because every asset needs to inherit from ExtensibleObject, we can rely on it + // having a getSizeBytes method. + sizeOfFormatter = (propertyName, accumName) => { + return `${accumName} += ${propertyName}->getSizeBytes();`; + }; + headers.push(NameFormatters.getIncludeFromName("IntrusivePointer", "CesiumUtility")); + } else if (makeOptional) { + propertyType = `std::optional<${propertyType}>`; + headers.push(""); + } + return { ...propertyDefaults(propertyName, cppSafeName, propertyDetails), - type: makeOptional - ? `std::optional<${NameFormatters.getName(type, namespace)}>` - : `${NameFormatters.getName(type, namespace)}`, - headers: [ - NameFormatters.getIncludeFromName(type, namespace), - ...(makeOptional ? [""] : []), - ], + type: propertyType, + headers, readerType: NameFormatters.getJsonHandlerName(type, readerNamespace), readerHeaders: [ NameFormatters.getJsonHandlerIncludeFromName(type, readerNamespace), ], schemas: [itemSchema], + isOptional: makeOptional, + sizeOfFormatter, + originalType }; } } @@ -255,6 +315,8 @@ function makeJsonValueProperty( ], readerType: `CesiumJsonReader::JsonObjectJsonHandler`, readerHeaders: [``], + isOptional: makeOptional, + originalType: "CesiumUtility::JsonValue" }; } @@ -269,12 +331,12 @@ function toPascalCase(name) { function propertyDefaults(propertyName, cppSafeName, propertyDetails) { const fullDoc = propertyDetails.gltf_detailedDescription && - propertyDetails.gltf_detailedDescription.indexOf( - propertyDetails.description - ) === 0 + propertyDetails.gltf_detailedDescription.indexOf( + propertyDetails.description + ) === 0 ? propertyDetails.gltf_detailedDescription - .substr(propertyDetails.description.length) - .trim() + .substr(propertyDetails.description.length) + .trim() : propertyDetails.gltf_detailedDescription; return { name: propertyName, @@ -346,6 +408,24 @@ function resolveArray( ...itemProperty.readerHeaders, ], readerType: `CesiumJsonReader::ArrayJsonHandler<${itemProperty.type}, ${itemProperty.readerType}>`, + sizeOfFormatter: (propertyName, accumName) => { + if (!itemProperty.schemas || itemProperty.schemas.length == 0) { + return `${accumName} += int64_t(sizeof(${itemProperty.type}) * ${propertyName}.capacity());`; + } + + // We need to change the name of the variable we're iterating with if the contents are also a vector, + // as it will otherwise also generate code with `value` and cause a "hides previous local declaration" error. + // TODO: support more than two nested loops + let iterName = "value"; + if (itemProperty.type.indexOf("std::vector") == 0) { + iterName = "valueOuter"; + } + + return `${accumName} += int64_t(sizeof(${itemProperty.type}) * ${propertyName}.capacity()); + for(const ${itemProperty.type}& ${iterName} : ${propertyName}) { + ${resolveSizeOfForProperty(itemProperty, iterName, accumName)} + }`; + } }; } @@ -392,6 +472,13 @@ function resolveDictionary( ...additional.readerHeaders, ], readerType: `CesiumJsonReader::DictionaryJsonHandler<${additional.type}, ${additional.readerType}>`, + sizeOfFormatter: (propertyName, accumName) => { + return `${accumName} += int64_t(${propertyName}.bucket_count() * (sizeof(std::string) + sizeof(${additional.type}))); + for(const auto& [k, v] : ${propertyName}) { + ${accumName} += int64_t(k.capacity() * sizeof(char) - sizeof(std::string)); + ${resolveSizeOfForProperty(additional, "v", accumName) || `${accumName} += int64_t(sizeof(${additional.type}));`} + }`; + } }; } @@ -403,9 +490,8 @@ function resolveDictionary( * @return {String} The comment block */ function createEnumPropertyDoc(propertyValues) { - let propertyDoc = `/**\n * @brief Known values for ${ - propertyValues.briefDoc || propertyValues.name - }\n`; + let propertyDoc = `/**\n * @brief Known values for ${propertyValues.briefDoc || propertyValues.name + }\n`; propertyDoc += ` */`; return propertyDoc; } @@ -429,11 +515,11 @@ function findCommonEnumType(propertyName, enums) { if (element.type !== firstType) { console.warn( "Expected equal types for enum values in " + - propertyName + - ", but found " + - firstType + - " and " + - element.type + propertyName + + ", but found " + + firstType + + " and " + + element.type ); return undefined; } @@ -527,16 +613,17 @@ function resolveEnum( ${createEnumPropertyDoc(propertyDefaultValues)} struct ${enumName} { ${indent( - enums - .map((e) => createEnum(e)) - .filter((e) => e !== undefined) - .join(";\n\n") + ";", - 12 - )} + enums + .map((e) => createEnum(e)) + .filter((e) => e !== undefined) + .join(";\n\n") + ";", + 12 + )} }; `), ], type: makeOptional ? `std::optional<${enumRuntimeType}>` : enumRuntimeType, + originalType: enumRuntimeType, headers: makeOptional ? [""] : [], defaultValue: makeOptional ? undefined : enumDefaultValue, defaultValueWriter: makeOptional ? undefined : enumDefaultValueWriter, @@ -551,6 +638,7 @@ function resolveEnum( needsInitialization: !makeOptional, briefDoc: enumBriefDoc, requiredEnum: isRequired, + isOptional: makeOptional, }; if (enumType === "string") { @@ -706,19 +794,19 @@ function createEnumReaderTypeImpl(parentName, enumName, propertyName, enums) { assert(this->_pEnum); ${indent( - enums - .map((e) => { - const enumValue = getEnumValue(e); - return enumValue !== undefined - ? `if ("${enumValue}"s == str) *this->_pEnum = ${parentName}::${enumName}::${makeIdentifier( - enumValue - )};` - : undefined; - }) - .filter((s) => s !== undefined) - .join("\nelse "), - 6 - )} + enums + .map((e) => { + const enumValue = getEnumValue(e); + return enumValue !== undefined + ? `if ("${enumValue}"s == str) *this->_pEnum = ${parentName}::${enumName}::${makeIdentifier( + enumValue + )};` + : undefined; + }) + .filter((s) => s !== undefined) + .join("\nelse "), + 6 + )} else return nullptr; return this->parent(); @@ -753,4 +841,7 @@ function createAnonymousPropertyTypeTitle(parentName, propertyName) { return result; } -module.exports = resolveProperty; +module.exports = { + resolveProperty, + resolveSizeOfForProperty +};