From f1ae8bd16c9c18bd5228a76e4c2ed761e61ff79e Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Mon, 9 Dec 2024 18:29:20 -0500 Subject: [PATCH] Update generated classes for EXT_structural_metadata --- CHANGES.md | 4 + .../ExtensionExtStructuralMetadata.h | 64 +++++++++ .../ExtensionExtStructuralMetadataReader.h | 76 +++++++++++ ...xtensionExtStructuralMetadataJsonHandler.h | 53 ++++++++ .../generated/src/GeneratedJsonHandlers.cpp | 121 ++++++++++++++++++ .../src/registerReaderExtensions.cpp | 7 + .../generated/src/ModelJsonWriter.cpp | 34 +++++ .../generated/src/ModelJsonWriter.h | 12 ++ .../src/registerWriterExtensions.cpp | 7 + tools/generate-classes/glTF.json | 11 ++ 10 files changed, 389 insertions(+) create mode 100644 CesiumGltf/generated/include/CesiumGltf/ExtensionExtStructuralMetadata.h create mode 100644 CesiumGltfReader/generated/include/CesiumGltfReader/ExtensionExtStructuralMetadataReader.h create mode 100644 CesiumGltfReader/generated/src/ExtensionExtStructuralMetadataJsonHandler.h diff --git a/CHANGES.md b/CHANGES.md index 26d28e96c..2a255d443 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,10 @@ ### ? - ? +##### Additions :tada: + +- Updates generated classes for `EXT_structural_metadata`. See https://github.com/CesiumGS/glTF/pull/71. + ##### Fixes :wrench: - Fixed a bug in `thenPassThrough` that caused a compiler error when given a value by r-value refrence. diff --git a/CesiumGltf/generated/include/CesiumGltf/ExtensionExtStructuralMetadata.h b/CesiumGltf/generated/include/CesiumGltf/ExtensionExtStructuralMetadata.h new file mode 100644 index 000000000..3dd5cfe11 --- /dev/null +++ b/CesiumGltf/generated/include/CesiumGltf/ExtensionExtStructuralMetadata.h @@ -0,0 +1,64 @@ +// This file was generated by generate-classes. +// DO NOT EDIT THIS FILE! +#pragma once + +#include +#include +#include + +#include +#include +#include + +namespace CesiumGltf { +/** + * @brief Structural metadata about a glTF element. + */ +struct CESIUMGLTF_API ExtensionExtStructuralMetadata final + : public CesiumUtility::ExtensibleObject { + static constexpr const char* TypeName = "ExtensionExtStructuralMetadata"; + static constexpr const char* ExtensionName = "EXT_structural_metadata"; + + /** + * @brief The class that property values conform to. The value shall be a + * class ID declared in the `classes` dictionary of the metadata schema. + */ + std::optional classProperty; + + /** + * @brief A dictionary, where each key corresponds to a property ID in the + * class' `properties` dictionary and each value contains the property values. + * The type of the value shall match the property definition: For `BOOLEAN` + * use `true` or `false`. For `STRING` use a JSON string. For numeric types + * use a JSON number. For `ENUM` use a valid enum `name`, not an integer + * value. For `ARRAY`, `VECN`, and `MATN` types use a JSON array containing + * values matching the `componentType`. Required properties shall be included + * 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(ExtensionExtStructuralMetadata)); + accum += CesiumUtility::ExtensibleObject::getSizeBytes() - + int64_t(sizeof(CesiumUtility::ExtensibleObject)); + if (this->classProperty) { + 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 CesiumGltf diff --git a/CesiumGltfReader/generated/include/CesiumGltfReader/ExtensionExtStructuralMetadataReader.h b/CesiumGltfReader/generated/include/CesiumGltfReader/ExtensionExtStructuralMetadataReader.h new file mode 100644 index 000000000..091cc9bb8 --- /dev/null +++ b/CesiumGltfReader/generated/include/CesiumGltfReader/ExtensionExtStructuralMetadataReader.h @@ -0,0 +1,76 @@ +// This file was generated by generate-classes. +// DO NOT EDIT THIS FILE! +#pragma once + +#include +#include +#include +#include + +#include + +#include +#include + +namespace CesiumGltf { +struct ExtensionExtStructuralMetadata; +} // namespace CesiumGltf + +namespace CesiumGltfReader { + +/** + * @brief Reads {@link ExtensionExtStructuralMetadata} instances from JSON. + */ +class CESIUMGLTFREADER_API ExtensionExtStructuralMetadataReader { +public: + /** + * @brief Constructs a new instance. + */ + ExtensionExtStructuralMetadataReader(); + + /** + * @brief Gets the options controlling how the JSON is read. + */ + CesiumJsonReader::JsonReaderOptions& getOptions(); + + /** + * @brief Gets the options controlling how the JSON is read. + */ + const CesiumJsonReader::JsonReaderOptions& getOptions() const; + + /** + * @brief Reads an instance of ExtensionExtStructuralMetadata from a byte + * buffer. + * + * @param data The buffer from which to read the instance. + * @return The result of reading the instance. + */ + CesiumJsonReader::ReadJsonResult + readFromJson(const std::span& data) const; + + /** + * @brief Reads an instance of ExtensionExtStructuralMetadata from a + * rapidJson::Value. + * + * @param data The buffer from which to read the instance. + * @return The result of reading the instance. + */ + CesiumJsonReader::ReadJsonResult + readFromJson(const rapidjson::Value& value) const; + + /** + * @brief Reads an array of instances of ExtensionExtStructuralMetadata from a + * rapidJson::Value. + * + * @param data The buffer from which to read the array of instances. + * @return The result of reading the array of instances. + */ + CesiumJsonReader::ReadJsonResult< + std::vector> + readArrayFromJson(const rapidjson::Value& value) const; + +private: + CesiumJsonReader::JsonReaderOptions _options; +}; + +} // namespace CesiumGltfReader diff --git a/CesiumGltfReader/generated/src/ExtensionExtStructuralMetadataJsonHandler.h b/CesiumGltfReader/generated/src/ExtensionExtStructuralMetadataJsonHandler.h new file mode 100644 index 000000000..c939de2b5 --- /dev/null +++ b/CesiumGltfReader/generated/src/ExtensionExtStructuralMetadataJsonHandler.h @@ -0,0 +1,53 @@ +// This file was generated by generate-classes. +// DO NOT EDIT THIS FILE! +#pragma once + +#include +#include +#include +#include +#include + +namespace CesiumJsonReader { +class JsonReaderOptions; +} // namespace CesiumJsonReader + +namespace CesiumGltfReader { +class ExtensionExtStructuralMetadataJsonHandler + : public CesiumJsonReader::ExtensibleObjectJsonHandler, + public CesiumJsonReader::IExtensionJsonHandler { +public: + using ValueType = CesiumGltf::ExtensionExtStructuralMetadata; + + static constexpr const char* ExtensionName = "EXT_structural_metadata"; + + explicit ExtensionExtStructuralMetadataJsonHandler( + const CesiumJsonReader::JsonReaderOptions& options) noexcept; + void reset( + IJsonHandler* pParentHandler, + CesiumGltf::ExtensionExtStructuralMetadata* pObject); + + IJsonHandler* readObjectKey(const std::string_view& str) override; + + void reset( + IJsonHandler* pParentHandler, + CesiumUtility::ExtensibleObject& o, + const std::string_view& extensionName) override; + + IJsonHandler& getHandler() override { return *this; } + +protected: + IJsonHandler* readObjectKeyExtensionExtStructuralMetadata( + const std::string& objectType, + const std::string_view& str, + CesiumGltf::ExtensionExtStructuralMetadata& o); + +private: + CesiumGltf::ExtensionExtStructuralMetadata* _pObject = nullptr; + CesiumJsonReader::StringJsonHandler _classProperty; + CesiumJsonReader::DictionaryJsonHandler< + CesiumUtility::JsonValue, + CesiumJsonReader::JsonObjectJsonHandler> + _properties; +}; +} // namespace CesiumGltfReader diff --git a/CesiumGltfReader/generated/src/GeneratedJsonHandlers.cpp b/CesiumGltfReader/generated/src/GeneratedJsonHandlers.cpp index e3e26fa95..5532d65ac 100644 --- a/CesiumGltfReader/generated/src/GeneratedJsonHandlers.cpp +++ b/CesiumGltfReader/generated/src/GeneratedJsonHandlers.cpp @@ -853,6 +853,127 @@ ExtensionBufferViewExtMeshoptCompressionReader::readArrayFromJson( return CesiumJsonReader::JsonReader::readJson(value, handler); } +} // namespace CesiumGltfReader +// This file was generated by generate-classes. +// DO NOT EDIT THIS FILE! +// NOLINTBEGIN(readability-duplicate-include) +#include "ExtensionExtStructuralMetadataJsonHandler.h" +#include "registerReaderExtensions.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +// NOLINTEND(readability-duplicate-include) + +namespace CesiumGltfReader { + +ExtensionExtStructuralMetadataJsonHandler:: + ExtensionExtStructuralMetadataJsonHandler( + const CesiumJsonReader::JsonReaderOptions& options) noexcept + : CesiumJsonReader::ExtensibleObjectJsonHandler(options), + _classProperty(), + _properties() {} + +void ExtensionExtStructuralMetadataJsonHandler::reset( + CesiumJsonReader::IJsonHandler* pParentHandler, + CesiumGltf::ExtensionExtStructuralMetadata* pObject) { + CesiumJsonReader::ExtensibleObjectJsonHandler::reset(pParentHandler, pObject); + this->_pObject = pObject; +} + +CesiumJsonReader::IJsonHandler* +ExtensionExtStructuralMetadataJsonHandler::readObjectKey( + const std::string_view& str) { + CESIUM_ASSERT(this->_pObject); + return this->readObjectKeyExtensionExtStructuralMetadata( + CesiumGltf::ExtensionExtStructuralMetadata::TypeName, + str, + *this->_pObject); +} + +void ExtensionExtStructuralMetadataJsonHandler::reset( + CesiumJsonReader::IJsonHandler* pParentHandler, + CesiumUtility::ExtensibleObject& o, + const std::string_view& extensionName) { + std::any& value = + o.extensions + .emplace(extensionName, CesiumGltf::ExtensionExtStructuralMetadata()) + .first->second; + this->reset( + pParentHandler, + &std::any_cast(value)); +} + +CesiumJsonReader::IJsonHandler* ExtensionExtStructuralMetadataJsonHandler:: + readObjectKeyExtensionExtStructuralMetadata( + const std::string& objectType, + const std::string_view& str, + CesiumGltf::ExtensionExtStructuralMetadata& o) { + using namespace std::string_literals; + + if ("class"s == str) { + return property("class", this->_classProperty, o.classProperty); + } + if ("properties"s == str) { + return property("properties", this->_properties, o.properties); + } + + return this->readObjectKeyExtensibleObject(objectType, str, *this->_pObject); +} + +ExtensionExtStructuralMetadataReader::ExtensionExtStructuralMetadataReader() { + registerReaderExtensions(this->_options); +} + +CesiumJsonReader::JsonReaderOptions& +ExtensionExtStructuralMetadataReader::getOptions() { + return this->_options; +} + +const CesiumJsonReader::JsonReaderOptions& +ExtensionExtStructuralMetadataReader::getOptions() const { + return this->_options; +} + +CesiumJsonReader::ReadJsonResult +ExtensionExtStructuralMetadataReader::readFromJson( + const std::span& data) const { + ExtensionExtStructuralMetadataJsonHandler handler(this->_options); + return CesiumJsonReader::JsonReader::readJson(data, handler); +} + +CesiumJsonReader::ReadJsonResult +ExtensionExtStructuralMetadataReader::readFromJson( + const rapidjson::Value& value) const { + ExtensionExtStructuralMetadataJsonHandler handler(this->_options); + return CesiumJsonReader::JsonReader::readJson(value, handler); +} + +CesiumJsonReader::ReadJsonResult< + std::vector> +ExtensionExtStructuralMetadataReader::readArrayFromJson( + const rapidjson::Value& value) const { + CesiumJsonReader::ArrayJsonHandler< + CesiumGltf::ExtensionExtStructuralMetadata, + ExtensionExtStructuralMetadataJsonHandler> + handler(this->_options); + return CesiumJsonReader::JsonReader::readJson(value, handler); +} + } // namespace CesiumGltfReader // This file was generated by generate-classes. // DO NOT EDIT THIS FILE! diff --git a/CesiumGltfReader/generated/src/registerReaderExtensions.cpp b/CesiumGltfReader/generated/src/registerReaderExtensions.cpp index a7fd0aa62..34d2b855c 100644 --- a/CesiumGltfReader/generated/src/registerReaderExtensions.cpp +++ b/CesiumGltfReader/generated/src/registerReaderExtensions.cpp @@ -11,6 +11,7 @@ #include "ExtensionExtInstanceFeaturesJsonHandler.h" #include "ExtensionExtMeshFeaturesJsonHandler.h" #include "ExtensionExtMeshGpuInstancingJsonHandler.h" +#include "ExtensionExtStructuralMetadataJsonHandler.h" #include "ExtensionKhrDracoMeshCompressionJsonHandler.h" #include "ExtensionKhrMaterialsUnlitJsonHandler.h" #include "ExtensionKhrTextureBasisuJsonHandler.h" @@ -75,6 +76,9 @@ void registerReaderExtensions(CesiumJsonReader::JsonReaderOptions& options) { options.registerExtension< CesiumGltf::Node, ExtensionExtMeshGpuInstancingJsonHandler>(); + options.registerExtension< + CesiumGltf::Node, + ExtensionExtStructuralMetadataJsonHandler>(); options.registerExtension< CesiumGltf::Node, ExtensionNodeMaxarMeshVariantsJsonHandler>(); @@ -84,6 +88,9 @@ void registerReaderExtensions(CesiumJsonReader::JsonReaderOptions& options) { options.registerExtension< CesiumGltf::BufferView, ExtensionBufferViewExtMeshoptCompressionJsonHandler>(); + options.registerExtension< + CesiumGltf::Material, + ExtensionExtStructuralMetadataJsonHandler>(); options.registerExtension< CesiumGltf::Material, ExtensionKhrMaterialsUnlitJsonHandler>(); diff --git a/CesiumGltfWriter/generated/src/ModelJsonWriter.cpp b/CesiumGltfWriter/generated/src/ModelJsonWriter.cpp index eb90d3792..731c7e282 100644 --- a/CesiumGltfWriter/generated/src/ModelJsonWriter.cpp +++ b/CesiumGltfWriter/generated/src/ModelJsonWriter.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -122,6 +123,11 @@ void writeJson( CesiumJsonWriter::JsonWriter& jsonWriter, const CesiumJsonWriter::ExtensionWriterContext& context); +void writeJson( + const CesiumGltf::ExtensionExtStructuralMetadata& obj, + CesiumJsonWriter::JsonWriter& jsonWriter, + const CesiumJsonWriter::ExtensionWriterContext& context); + void writeJson( const CesiumGltf::ExtensionModelExtStructuralMetadata& obj, CesiumJsonWriter::JsonWriter& jsonWriter, @@ -728,6 +734,27 @@ void writeJson( jsonWriter.EndObject(); } +void writeJson( + const CesiumGltf::ExtensionExtStructuralMetadata& obj, + CesiumJsonWriter::JsonWriter& jsonWriter, + const CesiumJsonWriter::ExtensionWriterContext& context) { + jsonWriter.StartObject(); + + if (obj.classProperty) { + jsonWriter.Key("class"); + writeJson(obj.classProperty, jsonWriter, context); + } + + if (!obj.properties.empty()) { + jsonWriter.Key("properties"); + writeJson(obj.properties, jsonWriter, context); + } + + writeExtensibleObject(obj, jsonWriter, context); + + jsonWriter.EndObject(); +} + void writeJson( const CesiumGltf::ExtensionModelExtStructuralMetadata& obj, CesiumJsonWriter::JsonWriter& jsonWriter, @@ -2419,6 +2446,13 @@ void ExtensionBufferViewExtMeshoptCompressionJsonWriter::write( writeJson(obj, jsonWriter, context); } +void ExtensionExtStructuralMetadataJsonWriter::write( + const CesiumGltf::ExtensionExtStructuralMetadata& obj, + CesiumJsonWriter::JsonWriter& jsonWriter, + const CesiumJsonWriter::ExtensionWriterContext& context) { + writeJson(obj, jsonWriter, context); +} + void ExtensionModelExtStructuralMetadataJsonWriter::write( const CesiumGltf::ExtensionModelExtStructuralMetadata& obj, CesiumJsonWriter::JsonWriter& jsonWriter, diff --git a/CesiumGltfWriter/generated/src/ModelJsonWriter.h b/CesiumGltfWriter/generated/src/ModelJsonWriter.h index 8dccf43b9..0262f519e 100644 --- a/CesiumGltfWriter/generated/src/ModelJsonWriter.h +++ b/CesiumGltfWriter/generated/src/ModelJsonWriter.h @@ -17,6 +17,7 @@ struct ExtensionExtMeshFeatures; struct ExtensionExtMeshGpuInstancing; struct ExtensionBufferExtMeshoptCompression; struct ExtensionBufferViewExtMeshoptCompression; +struct ExtensionExtStructuralMetadata; struct ExtensionModelExtStructuralMetadata; struct ExtensionMeshPrimitiveExtStructuralMetadata; struct ExtensionKhrDracoMeshCompression; @@ -156,6 +157,17 @@ struct ExtensionBufferViewExtMeshoptCompressionJsonWriter { const CesiumJsonWriter::ExtensionWriterContext& context); }; +struct ExtensionExtStructuralMetadataJsonWriter { + using ValueType = CesiumGltf::ExtensionExtStructuralMetadata; + + static constexpr const char* ExtensionName = "EXT_structural_metadata"; + + static void write( + const CesiumGltf::ExtensionExtStructuralMetadata& obj, + CesiumJsonWriter::JsonWriter& jsonWriter, + const CesiumJsonWriter::ExtensionWriterContext& context); +}; + struct ExtensionModelExtStructuralMetadataJsonWriter { using ValueType = CesiumGltf::ExtensionModelExtStructuralMetadata; diff --git a/CesiumGltfWriter/generated/src/registerWriterExtensions.cpp b/CesiumGltfWriter/generated/src/registerWriterExtensions.cpp index 49a388aca..d0b0ab627 100644 --- a/CesiumGltfWriter/generated/src/registerWriterExtensions.cpp +++ b/CesiumGltfWriter/generated/src/registerWriterExtensions.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -80,6 +81,9 @@ void registerWriterExtensions( context.registerExtension< CesiumGltf::Node, ExtensionExtMeshGpuInstancingJsonWriter>(); + context.registerExtension< + CesiumGltf::Node, + ExtensionExtStructuralMetadataJsonWriter>(); context.registerExtension< CesiumGltf::Node, ExtensionNodeMaxarMeshVariantsJsonWriter>(); @@ -89,6 +93,9 @@ void registerWriterExtensions( context.registerExtension< CesiumGltf::BufferView, ExtensionBufferViewExtMeshoptCompressionJsonWriter>(); + context.registerExtension< + CesiumGltf::Material, + ExtensionExtStructuralMetadataJsonWriter>(); context.registerExtension< CesiumGltf::Material, ExtensionKhrMaterialsUnlitJsonWriter>(); diff --git a/tools/generate-classes/glTF.json b/tools/generate-classes/glTF.json index 5a5f8fb28..10e6609ca 100644 --- a/tools/generate-classes/glTF.json +++ b/tools/generate-classes/glTF.json @@ -61,6 +61,9 @@ "overrideName": "ExtensionBufferViewExtMeshoptCompression" }, "EXT_structural_metadata glTF extension": { + "overrideName": "ExtensionExtStructuralMetadata" + }, + "EXT_structural_metadata glTF Document extension": { "overrideName": "ExtensionModelExtStructuralMetadata" }, "EXT_structural_metadata glTF Mesh Primitive extension": { @@ -169,6 +172,14 @@ "extensionName": "EXT_meshopt_compression", "schema": "Vendor/EXT_meshopt_compression/schema/bufferView.EXT_meshopt_compression.schema.json" }, + { + "extensionName": "EXT_structural_metadata", + "schema": "Vendor/EXT_structural_metadata/schema/EXT_structural_metadata.schema.json", + "attachTo": [ + "node", + "material" + ] + }, { "extensionName": "EXT_structural_metadata", "schema": "Vendor/EXT_structural_metadata/schema/glTF.EXT_structural_metadata.schema.json"