Add isExtensionUsed and isExtensionRequired methods.

This commit is contained in:
Kevin Ring 2024-04-08 17:38:33 +10:00
parent b9fe268f91
commit 71e567dc1f
3 changed files with 46 additions and 19 deletions

View File

@ -11,7 +11,7 @@
- Added `Uri::getPath` and `Uri::setPath`.
- Added `TileTransform::setTransform`.
- Added a new `CesiumLegacyTerrain` library and namespace, containing classes for working with terrain in the `quantized-mesh-1.0` format and its `layer.json` file.
- Added `addExtensionUsed` and `addExtensionRequired` methods to `CesiumGltf::Model`.
- Added `addExtensionUsed`, `addExtensionRequired`, `isExtensionUsed`, and `isExtensionRequired` methods to `CesiumGltf::Model`.
##### Fixes :wrench:

View File

@ -142,9 +142,9 @@ struct CESIUMGLTF_API Model : public ModelSpec {
* @brief Adds an extension to the {@link ModelSpec::extensionsUsed}
* property, if it is not already present.
*
* @param extensionUsed The name of the used extension.
* @param extensionName The name of the used extension.
*/
void addExtensionUsed(const std::string& extensionUsed);
void addExtensionUsed(const std::string& extensionName);
/**
* @brief Adds an extension to the {@link ModelSpec::extensionsRequired}
@ -153,8 +153,27 @@ struct CESIUMGLTF_API Model : public ModelSpec {
* Calling this function also adds the extension to `extensionsUsed`, if it's
* not already present.
*
* @param extensionRequired The name of the required extension.
* @param extensionName The name of the required extension.
*/
void addExtensionRequired(const std::string& extensionRequired);
void addExtensionRequired(const std::string& extensionName);
/**
* @brief Determines whether a given extension name is listed in the model's
* {@link ModelSpec::extensionsUsed} property.
*
* @param extensionName The extension name to check.
* @returns True if the extension is found in `extensionsUsed`; otherwise, false.
*/
bool isExtensionUsed(const std::string& extensionName) const noexcept;
/**
* @brief Determines whether a given extension name is listed in the model's
* {@link ModelSpec::extensionsRequired} property.
*
* @param extensionName The extension name to check.
* @returns True if the extension is found in `extensionsRequired`; otherwise, false.
*/
bool isExtensionRequired(const std::string& extensionName) const noexcept;
};
} // namespace CesiumGltf

View File

@ -665,25 +665,33 @@ void Model::generateMissingNormalsSmooth() {
});
}
void CesiumGltf::Model::addExtensionUsed(const std::string& extensionUsed) {
if (std::find(
this->extensionsUsed.begin(),
this->extensionsUsed.end(),
extensionUsed) == this->extensionsUsed.end()) {
this->extensionsUsed.emplace_back(extensionUsed);
void Model::addExtensionUsed(const std::string& extensionName) {
if (!this->isExtensionUsed(extensionName)) {
this->extensionsUsed.emplace_back(extensionName);
}
}
void CesiumGltf::Model::addExtensionRequired(
const std::string& extensionRequired) {
this->addExtensionUsed(extensionRequired);
void Model::addExtensionRequired(const std::string& extensionName) {
this->addExtensionUsed(extensionName);
if (std::find(
this->extensionsRequired.begin(),
this->extensionsRequired.end(),
extensionRequired) == this->extensionsRequired.end()) {
this->extensionsRequired.emplace_back(extensionRequired);
if (!this->isExtensionRequired(extensionName)) {
this->extensionsRequired.emplace_back(extensionName);
}
}
bool Model::isExtensionUsed(const std::string& extensionName) const noexcept {
return std::find(
this->extensionsUsed.begin(),
this->extensionsUsed.end(),
extensionName) != this->extensionsUsed.end();
}
bool Model::isExtensionRequired(
const std::string& extensionName) const noexcept {
return std::find(
this->extensionsRequired.begin(),
this->extensionsRequired.end(),
extensionName) != this->extensionsRequired.end();
}
} // namespace CesiumGltf