Skip to content

Commit

Permalink
Merge from update-ext-structural-metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
azrogers committed Dec 11, 2024
2 parents f91818e + f1ae8bd commit 10b3464
Show file tree
Hide file tree
Showing 12 changed files with 450 additions and 55 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Added `offset` getter to `AccessorView`.
- Added `stride`, `offset`, and `data` getters to `AccessorWriter`.
- Added `value_type` typedef to `AccessorWriter`.
- Updates generated classes for `EXT_structural_metadata`. See https://github.com/CesiumGS/glTF/pull/71.

##### Fixes :wrench:

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// This file was generated by generate-classes.
// DO NOT EDIT THIS FILE!
#pragma once

#include <CesiumGltf/Library.h>
#include <CesiumUtility/ExtensibleObject.h>
#include <CesiumUtility/JsonValue.h>

#include <optional>
#include <string>
#include <unordered_map>

namespace CesiumGltf {
/**
* @brief Structural metadata about a glTF element.
*/
struct CESIUMGLTF_API ExtensionExtStructuralMetadata final
: public CesiumUtility::ExtensibleObject {
/**
* @brief The original name of this type.
*/
static constexpr const char* TypeName = "ExtensionExtStructuralMetadata";
/** @brief The official name of the extension. This should be the same as its
* key in the `extensions` object. */
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<std::string> 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<std::string, CesiumUtility::JsonValue> 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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ namespace CesiumGltf {
*/
struct CESIUMGLTF_API ExtensionModelExtStructuralMetadata final
: public CesiumUtility::ExtensibleObject {
/**
* @brief The original name of this type.
*/
static constexpr const char* TypeName = "ExtensionModelExtStructuralMetadata";
/** @brief The official name of the extension. This should be the same as its
* key in the `extensions` object. */
static constexpr const char* ExtensionName = "EXT_structural_metadata";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// This file was generated by generate-classes.
// DO NOT EDIT THIS FILE!
#pragma once

#include <CesiumGltf/ExtensionExtStructuralMetadata.h>
#include <CesiumGltfReader/Library.h>
#include <CesiumJsonReader/JsonReader.h>
#include <CesiumJsonReader/JsonReaderOptions.h>

#include <rapidjson/fwd.h>

#include <span>
#include <vector>

namespace CesiumGltf {
struct ExtensionExtStructuralMetadata;
} // namespace CesiumGltf

namespace CesiumGltfReader {

/**
* @brief Reads \ref CesiumGltf::ExtensionExtStructuralMetadata
* "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<CesiumGltf::ExtensionExtStructuralMetadata>
readFromJson(const std::span<const std::byte>& data) const;

/**
* @brief Reads an instance of ExtensionExtStructuralMetadata from a
* rapidJson::Value.
*
* @param value The value from which to read the instance.
* @return The result of reading the instance.
*/
CesiumJsonReader::ReadJsonResult<CesiumGltf::ExtensionExtStructuralMetadata>
readFromJson(const rapidjson::Value& value) const;

/**
* @brief Reads an array of instances of ExtensionExtStructuralMetadata from a
* rapidJson::Value.
*
* @param value The value from which to read the array of instances.
* @return The result of reading the array of instances.
*/
CesiumJsonReader::ReadJsonResult<
std::vector<CesiumGltf::ExtensionExtStructuralMetadata>>
readArrayFromJson(const rapidjson::Value& value) const;

private:
CesiumJsonReader::JsonReaderOptions _options;
};

} // namespace CesiumGltfReader
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ struct ExtensionModelExtStructuralMetadata;
namespace CesiumGltfReader {

/**
* @brief Reads {@link ExtensionModelExtStructuralMetadata} instances from JSON.
* @brief Reads \ref CesiumGltf::ExtensionModelExtStructuralMetadata
* "ExtensionModelExtStructuralMetadata" instances from JSON.
*/
class CESIUMGLTFREADER_API ExtensionModelExtStructuralMetadataReader {
public:
Expand Down Expand Up @@ -53,7 +54,7 @@ class CESIUMGLTFREADER_API ExtensionModelExtStructuralMetadataReader {
* @brief Reads an instance of ExtensionModelExtStructuralMetadata from a
* rapidJson::Value.
*
* @param data The buffer from which to read the instance.
* @param value The value from which to read the instance.
* @return The result of reading the instance.
*/
CesiumJsonReader::ReadJsonResult<
Expand All @@ -64,7 +65,7 @@ class CESIUMGLTFREADER_API ExtensionModelExtStructuralMetadataReader {
* @brief Reads an array of instances of ExtensionModelExtStructuralMetadata
* from a rapidJson::Value.
*
* @param data The buffer from which to read the array of instances.
* @param value The value from which to read the array of instances.
* @return The result of reading the array of instances.
*/
CesiumJsonReader::ReadJsonResult<
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// This file was generated by generate-classes.
// DO NOT EDIT THIS FILE!
#pragma once

#include <CesiumGltf/ExtensionExtStructuralMetadata.h>
#include <CesiumJsonReader/DictionaryJsonHandler.h>
#include <CesiumJsonReader/ExtensibleObjectJsonHandler.h>
#include <CesiumJsonReader/JsonObjectJsonHandler.h>
#include <CesiumJsonReader/StringJsonHandler.h>

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
Loading

0 comments on commit 10b3464

Please sign in to comment.