Skip to content

Commit

Permalink
--start of specifying materials as subconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
jturner65 committed Dec 27, 2024
1 parent b93a9d0 commit 1b017c7
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 19 deletions.
57 changes: 57 additions & 0 deletions src/esp/metadata/attributes/PrimitiveAssetAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Configuration>("materialDefinition");
} // ctor

AbstractPrimitiveAttributes::AbstractPrimitiveAttributes(
const AbstractPrimitiveAttributes& otr)
: AbstractAttributes(otr) {
materialConfig_ = editSubconfig<Configuration>("materialDefinition");

copySubconfigIntoMe<Configuration>(otr.materialConfig_, materialConfig_);
}

AbstractPrimitiveAttributes::AbstractPrimitiveAttributes(
AbstractPrimitiveAttributes&& otr)
: AbstractAttributes(std::move(static_cast<AbstractAttributes>(otr))) {
materialConfig_ = editSubconfig<Configuration>("materialDefinition");
}

AbstractPrimitiveAttributes& AbstractPrimitiveAttributes::operator=(
const AbstractPrimitiveAttributes& otr) {
if (this != &otr) {
this->AbstractAttributes::operator=(otr);
materialConfig_ = editSubconfig<Configuration>("materialDefinition");
copySubconfigIntoMe<Configuration>(otr.materialConfig_, materialConfig_);
}
return *this;
}

AbstractPrimitiveAttributes& AbstractPrimitiveAttributes::operator=(
AbstractPrimitiveAttributes&& otr) {
this->AbstractAttributes::operator=(static_cast<AbstractAttributes&&>(otr));
copySubconfigIntoMe<Configuration>(otr.materialConfig_, materialConfig_);
return *this;
}

CapsulePrimitiveAttributes::CapsulePrimitiveAttributes(
bool isWireframe,
int primObjType,
Expand Down
40 changes: 21 additions & 19 deletions src/esp/metadata/attributes/PrimitiveAssetAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<std::string>("materialStr");
}

/**
* @brief This will parse the passed candidate object template handle, treated
* as a configuration string, and populate the appropriate values.
Expand Down Expand Up @@ -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<Configuration> materialConfig_{};

private:
// Should never change, only set by ctor
void setPrimObjClassName(const std::string& primObjClassName) {
Expand Down

0 comments on commit 1b017c7

Please sign in to comment.