From 823cd8d0635808675dddd1319cbab80ddfef50d0 Mon Sep 17 00:00:00 2001 From: John Turner <7strbass@gmail.com> Date: Tue, 10 Oct 2023 10:53:13 -0400 Subject: [PATCH] --start of specifying materials as subconfig --- .../attributes/PrimitiveAssetAttributes.cpp | 57 +++++++++++++++++++ .../attributes/PrimitiveAssetAttributes.h | 40 ++++++------- 2 files changed, 78 insertions(+), 19 deletions(-) diff --git a/src/esp/metadata/attributes/PrimitiveAssetAttributes.cpp b/src/esp/metadata/attributes/PrimitiveAssetAttributes.cpp index 32778aad4f..0026bcc66f 100644 --- a/src/esp/metadata/attributes/PrimitiveAssetAttributes.cpp +++ b/src/esp/metadata/attributes/PrimitiveAssetAttributes.cpp @@ -8,6 +8,63 @@ namespace esp { namespace metadata { namespace attributes { +AbstractPrimitiveAttributes::AbstractPrimitiveAttributes( + bool isWireframe, + int primObjType, + const std::string& primObjClassName, + const std::string& attributesClassKey) + : AbstractAttributes(attributesClassKey, "") { + // clear handle that was set in base class constructor + AbstractAttributes::setHandle(""); + setIsWireframe(isWireframe); + setPrimObjType(primObjType); + setPrimObjClassName(primObjClassName); + setFileDirectory("none"); + // initialize so empty values are present + set("halfLength", 0.0); + set("segments", 0); + set("rings", 0); + if (!isWireframe) { // solid only + // do not call setters since they call buildHandle, which does not + // exist here - is abstract in base class + set("textureCoordinates", false); + set("tangents", false); + } + set("materialStr", "default"); + materialConfig_ = editSubconfig("materialDefinition"); +} // ctor + +AbstractPrimitiveAttributes::AbstractPrimitiveAttributes( + const AbstractPrimitiveAttributes& otr) + : AbstractAttributes(otr) { + materialConfig_ = editSubconfig("materialDefinition"); + + copySubconfigIntoMe(otr.materialConfig_, materialConfig_); +} + +AbstractPrimitiveAttributes::AbstractPrimitiveAttributes( + AbstractPrimitiveAttributes&& otr) + : AbstractAttributes(std::move(static_cast(otr))) { + materialConfig_ = editSubconfig("materialDefinition"); +} + +AbstractPrimitiveAttributes& AbstractPrimitiveAttributes::operator=( + const AbstractPrimitiveAttributes& otr) { + if (this != &otr) { + this->AbstractAttributes::operator=(otr); + materialConfig_ = editSubconfig("materialDefinition"); + copySubconfigIntoMe(otr.materialConfig_, materialConfig_); + } + return *this; +} + +AbstractPrimitiveAttributes& AbstractPrimitiveAttributes::operator=( + AbstractPrimitiveAttributes&& otr) { + this->AbstractAttributes::operator=(static_cast(otr)); + copySubconfigIntoMe(otr.materialConfig_, materialConfig_); + return *this; +} + CapsulePrimitiveAttributes::CapsulePrimitiveAttributes( bool isWireframe, int primObjType, diff --git a/src/esp/metadata/attributes/PrimitiveAssetAttributes.h b/src/esp/metadata/attributes/PrimitiveAssetAttributes.h index 511b128b68..f39775b7cf 100644 --- a/src/esp/metadata/attributes/PrimitiveAssetAttributes.h +++ b/src/esp/metadata/attributes/PrimitiveAssetAttributes.h @@ -21,26 +21,14 @@ class AbstractPrimitiveAttributes : public AbstractAttributes { AbstractPrimitiveAttributes(bool isWireframe, int primObjType, const std::string& primObjClassName, - const std::string& attributesClassKey) - : AbstractAttributes(attributesClassKey, "") { - // clear handle that was set in base class constructor - AbstractAttributes::setHandle(""); - setIsWireframe(isWireframe); - setPrimObjType(primObjType); - setPrimObjClassName(primObjClassName); - setFileDirectory("none"); - // initialize so empty values are present - set("halfLength", 0.0); - set("segments", 0); - set("rings", 0); - if (!isWireframe) { // solid - // do not call setters since they call buildHandle, which does not - // exist - is abstract in base class - set("textureCoordinates", false); - set("tangents", false); - } + const std::string& attributesClassKey); + + AbstractPrimitiveAttributes(const AbstractPrimitiveAttributes& otr); + AbstractPrimitiveAttributes(AbstractPrimitiveAttributes&& otr); - } // ctor + AbstractPrimitiveAttributes& operator=( + const AbstractPrimitiveAttributes& otr); + AbstractPrimitiveAttributes& operator=(AbstractPrimitiveAttributes&& otr); // necessary since abstract ~AbstractPrimitiveAttributes() override = default; @@ -120,6 +108,14 @@ class AbstractPrimitiveAttributes : public AbstractAttributes { set("handle", oHndlStrm.str()); } + /** + * @brief retrieve the string encoding of the material used for this + * primitive. + */ + std::string getMaterialString() const { + return get("materialStr"); + } + /** * @brief This will parse the passed candidate object template handle, treated * as a configuration string, and populate the appropriate values. @@ -231,6 +227,12 @@ class AbstractPrimitiveAttributes : public AbstractAttributes { virtual bool parseStringIntoConfigDetail(const std::string& configString) = 0; + /** + * @brief Smartpointer to created material configuration for primitive. The + * configuration is created on AbstractPrimitiveAttributes construction. + */ + std::shared_ptr materialConfig_{}; + private: // Should never change, only set by ctor void setPrimObjClassName(const std::string& primObjClassName) {