From 0ca122b418297183d5c88774b55d02bebdbb5282 Mon Sep 17 00:00:00 2001 From: John Turner <7strbass@gmail.com> Date: Thu, 28 Apr 2022 14:41:04 -0400 Subject: [PATCH 1/6] --stub out Material attributes and manager --- .../attributes/MaterialAttributes.cpp | 47 ++++++ .../metadata/attributes/MaterialAttributes.h | 54 +++++++ .../managers/MaterialAttributesManager.cpp | 76 ++++++++++ .../managers/MaterialAttributesManager.h | 135 ++++++++++++++++++ 4 files changed, 312 insertions(+) create mode 100644 src/esp/metadata/attributes/MaterialAttributes.cpp create mode 100644 src/esp/metadata/attributes/MaterialAttributes.h create mode 100644 src/esp/metadata/managers/MaterialAttributesManager.cpp create mode 100644 src/esp/metadata/managers/MaterialAttributesManager.h diff --git a/src/esp/metadata/attributes/MaterialAttributes.cpp b/src/esp/metadata/attributes/MaterialAttributes.cpp new file mode 100644 index 0000000000..c5d8e29179 --- /dev/null +++ b/src/esp/metadata/attributes/MaterialAttributes.cpp @@ -0,0 +1,47 @@ +// Copyright (c) Facebook, Inc. and its affiliates. +// This source code is licensed under the MIT license found in the +// LICENSE file in the root directory of this source tree. + +#include "MaterialAttributes.h" + +namespace esp { +namespace metadata { +namespace attributes { + +MaterialAttributes::MaterialAttributes(const std::string& handle) + : AbstractAttributes("MaterialAttributes", handle) {} +MaterialAttributes::MaterialAttributes(const MaterialAttributes& otr) + : AbstractAttributes(otr) {} +MaterialAttributes::MaterialAttributes(MaterialAttributes&& otr) noexcept + : AbstractAttributes(std::move(static_cast(otr))) {} + +void MaterialAttributes::writeValuesToJson(io::JsonGenericValue& jsonObj, + io::JsonAllocator& allocator) const { +} // MaterialAttributes::writeValuesToJson + +MaterialAttributes& MaterialAttributes::operator=( + const MaterialAttributes& otr) { + if (this != &otr) { + this->AbstractAttributes::operator=(otr); + } + return *this; +} +MaterialAttributes& MaterialAttributes::operator=( + MaterialAttributes&& otr) noexcept { + this->AbstractAttributes::operator=( + std::move(static_cast(otr))); + return *this; +} + +std::string MaterialAttributes::getObjectInfoHeaderInternal() const { + return ""; +} +std::string MaterialAttributes::getObjectInfoInternal() const { + std::string res = "\n"; + + return res; +} + +} // namespace attributes +} // namespace metadata +} // namespace esp diff --git a/src/esp/metadata/attributes/MaterialAttributes.h b/src/esp/metadata/attributes/MaterialAttributes.h new file mode 100644 index 0000000000..34ed874169 --- /dev/null +++ b/src/esp/metadata/attributes/MaterialAttributes.h @@ -0,0 +1,54 @@ +// Copyright (c) Facebook, Inc. and its affiliates. +// This source code is licensed under the MIT license found in the +// LICENSE file in the root directory of this source tree. + +#ifndef ESP_METADATA_ATTRIBUTES_MATERIALATTRIBUTES_H_ +#define ESP_METADATA_ATTRIBUTES_MATERIALATTRIBUTES_H_ + +#include "AttributesBase.h" + +namespace esp { +namespace metadata { +namespace attributes { + +class MaterialAttributes : public AbstractAttributes { + public: + explicit MaterialAttributes(const std::string& handle = ""); + + MaterialAttributes(const MaterialAttributes& otr); + MaterialAttributes(MaterialAttributes&& otr) noexcept; + + MaterialAttributes& operator=(const MaterialAttributes& otr); + MaterialAttributes& operator=(MaterialAttributes&& otr) noexcept; + + /** + * @brief Populate a json object with all the first-level values held in this + * configuration. Default is overridden to handle special cases for + * MaterialAttributes. + */ + void writeValuesToJson(io::JsonGenericValue& jsonObj, + io::JsonAllocator& allocator) const override; + + protected: + /** + * @brief Retrieve a comma-separated string holding the header values for the + * info returned for this managed object, type-specific. The individual light + * instances return a header for this. + */ + std::string getObjectInfoHeaderInternal() const override; + + /** + * @brief Retrieve a comma-separated informational string about the contents + * of this managed object. + */ + std::string getObjectInfoInternal() const override; + + public: + ESP_SMART_POINTERS(MaterialAttributes) +}; // class MaterialAttributes + +} // namespace attributes +} // namespace metadata +} // namespace esp + +#endif // ESP_METADATA_ATTRIBUTES_MATERIALATTRIBUTES_H_ diff --git a/src/esp/metadata/managers/MaterialAttributesManager.cpp b/src/esp/metadata/managers/MaterialAttributesManager.cpp new file mode 100644 index 0000000000..b9423e0e68 --- /dev/null +++ b/src/esp/metadata/managers/MaterialAttributesManager.cpp @@ -0,0 +1,76 @@ +// Copyright (c) Facebook, Inc. and its affiliates. +// This source code is licensed under the MIT license found in the +// LICENSE file in the root directory of this source tree. + +#include "MaterialAttributesManager.h" +#include "esp/io/Io.h" +#include "esp/io/Json.h" + +namespace Cr = Corrade; + +namespace esp { +namespace metadata { +using attributes::MaterialAttributes; +namespace managers { +using core::managedContainers::ManagedFileBasedContainer; +using core::managedContainers::ManagedObjectAccess; + +MaterialAttributes::ptr MaterialAttributesManager::createObject( + const std::string& materialConfigName, + bool registerTemplate) { + std::string msg; + bool doRegister = registerTemplate; + // File based attributes are automatically registered. + std::string jsonAttrFileName = getFormattedJSONFileName(materialConfigName); + bool jsonFileExists = (Cr::Utility::Path::exists(jsonAttrFileName)); + if (jsonFileExists) { + // if exists, force registration to be true. + doRegister = true; + } + // build attributes + MaterialAttributes::ptr attrs = this->createFromJsonOrDefaultInternal( + materialConfigName, msg, doRegister); + + if (nullptr != attrs) { + ESP_DEBUG() << msg << "material attributes created" + << (doRegister ? "and registered." : "."); + } + return attrs; +} // MaterialAttributesManager::createObject + +void MaterialAttributesManager::setValsFromJSONDoc( + attributes::MaterialAttributes::ptr materialAttribs, + const io::JsonGenericValue& jsonConfig) { +} // MaterialAttributesManager::setValsFromJSONDoc + +MaterialAttributes::ptr MaterialAttributesManager::initNewObjectInternal( + const std::string& handleName, + bool) { + attributes::MaterialAttributes::ptr newAttributes = + this->constructFromDefault(handleName); + // if no default then create new. + bool createNewAttributes = (nullptr == newAttributes); + if (createNewAttributes) { + newAttributes = attributes::MaterialAttributes::create(handleName); + } + // set the attributes source filedirectory, from the attributes name + this->setFileDirectoryFromHandle(newAttributes); + return newAttributes; +} // MaterialAttributesManager::initNewObjectInternal + +int MaterialAttributesManager::registerObjectFinalize( + MaterialAttributes::ptr materialAttribs, + const std::string& materialAttribsHandle, + bool) { + // adds template to library, and returns either the ID of the existing + // template referenced by MaterialAttributesHandle, or the next available + // ID if not found. + int MaterialAttributesID = + this->addObjectToLibrary(materialAttribs, materialAttribsHandle); + + return MaterialAttributesID; +} // MaterialAttributesManager::registerObjectFinalize + +} // namespace managers +} // namespace metadata +} // namespace esp diff --git a/src/esp/metadata/managers/MaterialAttributesManager.h b/src/esp/metadata/managers/MaterialAttributesManager.h new file mode 100644 index 0000000000..d57af84722 --- /dev/null +++ b/src/esp/metadata/managers/MaterialAttributesManager.h @@ -0,0 +1,135 @@ +// Copyright (c) Facebook, Inc. and its affiliates. +// This source code is licensed under the MIT license found in the +// LICENSE file in the root directory of this source tree. + +#ifndef ESP_METADATA_MANAGERS_MATERIALATTRIBUTEMANAGER_H_ +#define ESP_METADATA_MANAGERS_MATERIALATTRIBUTEMANAGER_H_ + +#include "AttributesManagerBase.h" + +#include "esp/metadata/attributes/MaterialAttributes.h" + +namespace Cr = Corrade; + +namespace esp { +namespace metadata { +namespace managers { + +using core::managedContainers::ManagedFileBasedContainer; +using core::managedContainers::ManagedObjectAccess; + +class MaterialAttributesManager + : public AttributesManager { + public: + MaterialAttributesManager() + : AttributesManager:: + AttributesManager("Material", "material_config.json") { + // build this manager's copy constructor map + this->copyConstructorMap_["MaterialAttributes"] = + &MaterialAttributesManager::createObjectCopy< + attributes::MaterialAttributes>; + } + + /** + * @brief Creates one or more instances of MaterialAttributes based on the + * whether @p materialConfigName is a file or a not. If it is a file it will + * consider the contents of that file a layout and will use the file name as + * the layout name and load all the attributes described and assign them to + * that layout. File-based loads will automatically register, regardless of + * what @p registerTemplate is. + * + * If a template/layout exists with this handle, this existing template/layout + * will be overwritten with the newly created one if registerTemplate is true. + * + * @param materialConfigName The configuration file to parse, or the name of + * the single material's attributes to create. + * @param registerTemplate whether to add this template to the library. + * Defaults to false - overridden if @p materialConfigName is a JSON file. + * @return a reference to the created material attributes. + */ + attributes::MaterialAttributes::ptr createObject( + const std::string& materialConfigName, + bool registerTemplate = false) override; + + /** + * @brief Function to take an existing MaterialAttributes and set its + * values from passed json config file. + * @param materialAttribs (out) an existing attributes to be modified. + * @param jsonConfig json document to parse + */ + void setValsFromJSONDoc(attributes::MaterialAttributes::ptr materialAttribs, + const io::JsonGenericValue& jsonConfig) override; + + protected: + /** + * @brief Used Internally. Create and configure newly-created attributes + * with any default values, before any specific values are set. + * + * @param handleName handle name to be assigned to attributes\ + * @param builtFromConfig whether this MaterialAttributes is being + * built from a config file, or from some other source (i.e. handleName + * contains config file name) + * @return Newly created but unregistered MaterialAttributes pointer, + * with only default values set. + */ + attributes::MaterialAttributes::ptr initNewObjectInternal( + const std::string& handleName, + bool builtFromConfig) override; + + /** + * @brief This method will perform any necessary updating that is + * attributesManager-specific upon template removal. This should only be + * called from @ref esp::core::managedContainers::ManagedContainerBase. + * + * @param templateID the ID of the template to remove + * @param templateHandle the string key of the attributes desired. + */ + void deleteObjectInternalFinalize( + CORRADE_UNUSED int templateID, + CORRADE_UNUSED const std::string& templateHandle) override {} + + /** + * @brief Add a copy of the @ref + * esp::metadata::attributes::MaterialAttributes shared_ptr object to + * the @ref objectLibrary_. + * + * @param materialAttributesTemplate The attributes template. + * @param materialAttributesHandle The key for referencing the template in + * the + * @ref objectLibrary_. + * @return The index in the @ref objectLibrary_ of object + * template. + */ + int registerObjectFinalize( + attributes::MaterialAttributes::ptr materialAttributesTemplate, + const std::string& materialAttributesHandle, + CORRADE_UNUSED bool forceRegistration) override; + + /** + * @brief Any MaterialAttributes-specific resetting that needs to happen on + * reset. + */ + void resetFinalize() override {} + + /** + * @brief Material Attributes has no reason to check this value + * @param handle String name of primitive asset attributes desired + * @return whether handle exists or not in asset attributes library + */ + bool isValidPrimitiveAttributes( + CORRADE_UNUSED const std::string& handle) override { + return false; + } + + public: + ESP_SMART_POINTERS(MaterialAttributesManager) + +}; // MaterialAttributesManager + +} // namespace managers +} // namespace metadata +} // namespace esp + +#endif // ESP_METADATA_MANAGERS_MATERIALATTRIBUTEMANAGER_H_ From ef21b9c3b7581a6dd75fbdc5bb1c445a81d58f8f Mon Sep 17 00:00:00 2001 From: John Turner <7strbass@gmail.com> Date: Wed, 25 May 2022 15:11:46 -0400 Subject: [PATCH 2/6] --add MaterialAttributes --- .../attributes/AttributesEnumMaps.cpp | 51 ++ .../metadata/attributes/AttributesEnumMaps.h | 38 ++ .../attributes/MaterialAttributes.cpp | 254 +++++++++- .../metadata/attributes/MaterialAttributes.h | 457 +++++++++++++++++- 4 files changed, 774 insertions(+), 26 deletions(-) diff --git a/src/esp/metadata/attributes/AttributesEnumMaps.cpp b/src/esp/metadata/attributes/AttributesEnumMaps.cpp index f8407811bf..06c6497e26 100644 --- a/src/esp/metadata/attributes/AttributesEnumMaps.cpp +++ b/src/esp/metadata/attributes/AttributesEnumMaps.cpp @@ -39,6 +39,39 @@ const std::map LightTypeNamesMap = { {"directional", esp::gfx::LightType::Directional}, {"spot", esp::gfx::LightType::Spot}}; +const std::map + LightPositionNamesMap = {{"global", esp::gfx::LightPositionModel::Global}, + {"camera", esp::gfx::LightPositionModel::Camera}, + {"object", esp::gfx::LightPositionModel::Object}}; + +const std::map ShaderTypeNamesMap = { + {"unspecified", ObjectInstanceShaderType::Unspecified}, + {"material", ObjectInstanceShaderType::Material}, + {"flat", ObjectInstanceShaderType::Flat}, + {"phong", ObjectInstanceShaderType::Phong}, + {"pbr", ObjectInstanceShaderType::PBR}, +}; + +const std::map AlphaModeNamesMap = { + {"OPAQUE", MaterialAlphaMode::Opaque}, + {"MASK", MaterialAlphaMode::Mask}, + {"BLEND", MaterialAlphaMode::Blend} + +}; + +const std::map + InstanceTranslationOriginMap = { + {"asset_local", SceneInstanceTranslationOrigin::AssetLocal}, + {"com", SceneInstanceTranslationOrigin::COM}, +}; + +// All keys must be lowercase +const std::map MotionTypeNamesMap = { + {"static", esp::physics::MotionType::STATIC}, + {"kinematic", esp::physics::MotionType::KINEMATIC}, + {"dynamic", esp::physics::MotionType::DYNAMIC}, +}; + std::string getLightTypeName(esp::gfx::LightType lightTypeEnum) { // this verifies that enum value being checked is supported by string-keyed // map. The values below should be the minimum and maximum enums supported by @@ -210,6 +243,24 @@ const std::map {"asset_local", SceneInstanceTranslationOrigin::AssetLocal}, {"com", SceneInstanceTranslationOrigin::COM}, }; +std::string getMaterialAlphaModeName(MaterialAlphaMode materialAlphaMode) { + // this verifies that enum value being checked is supported by string-keyed + // map. The values below should be the minimum and maximum enums supported by + // AlphaModeNamesMap. OPAQUE is default, so resort to this if unsupported. + if (materialAlphaMode <= MaterialAlphaMode::Opaque || + materialAlphaMode >= MaterialAlphaMode::Blend) { + return "OPAQUE"; + } + + // Must always be valid value + for (const auto& it : AlphaModeNamesMap) { + if (it.second == materialAlphaMode) { + return it.first; + } + } + // OPAQUE is default, so resort to this if unsupported. + return "OPAQUE"; +} // getMaterialAlphaModeName std::string getTranslationOriginName( SceneInstanceTranslationOrigin translationOrigin) { diff --git a/src/esp/metadata/attributes/AttributesEnumMaps.h b/src/esp/metadata/attributes/AttributesEnumMaps.h index 26a6032f80..6faa7b949d 100644 --- a/src/esp/metadata/attributes/AttributesEnumMaps.h +++ b/src/esp/metadata/attributes/AttributesEnumMaps.h @@ -186,6 +186,30 @@ enum class ObjectInstanceShaderType { EndShaderType, }; +/** + * @brief This enum class describes the Material alphaMode specified in a + * MaterialAttributes. + */ +enum class MaterialAlphaMode { + /** + * The alpha value is ignored, and the rendered output is fully opaque. + */ + Opaque, + /** + * The rendered output is either fully opaque or fully transparent depending + * on the alpha value and the specified alphaCutoff value; the exact + * appearance of the edges MAY be subject to implementation-specific + * techniques such as “Alpha-to-Coverage”. + */ + Mask, + /** + * The alpha value is used to composite the source and destination areas. The + * rendered output is combined with the background using the normal painting + * operation (i.e. the Porter and Duff over operator). + */ + Blend +}; + /** * @brief This enum class describes whether an object instance position is * relative to its COM or the asset's local origin. Depending on this value, we @@ -299,12 +323,26 @@ std::string getAORenderModeName(ArticulatedObjectRenderMode aoRenderMode); */ const extern std::map ShaderTypeNamesMap; +/** + * @brief Constant map to provide mappings from string tags to @ref + * MaterialAlphaMode values. This will be used to map values set + * in json for alphaMode to @ref MaterialAlphaMode. Keys + * must be UPPERCASE. + */ +const extern std::map AlphaModeNamesMap; + /** * @brief This method will convert a @ref ObjectInstanceShaderType value to the * string key that maps to it in the ShaderTypeNamesMap */ std::string getShaderTypeName(ObjectInstanceShaderType shaderTypeVal); +/** + * @brief This method will convert a @ref MaterialAlphaMode value to the + * string key that maps to it in the AlphaModeNamesMap + */ +std::string getMaterialAlphaModeName(MaterialAlphaMode materialAlphaMode); + /** * @brief Constant map to provide mappings from string tags to @ref * SceneInstanceTranslationOrigin values. This will be used to map string values diff --git a/src/esp/metadata/attributes/MaterialAttributes.cpp b/src/esp/metadata/attributes/MaterialAttributes.cpp index c5d8e29179..f3d403beeb 100644 --- a/src/esp/metadata/attributes/MaterialAttributes.cpp +++ b/src/esp/metadata/attributes/MaterialAttributes.cpp @@ -8,36 +8,250 @@ namespace esp { namespace metadata { namespace attributes { +MaterialTextureAttributes::MaterialTextureAttributes(int index, + const std::string& handle, + const std::string& type) + : AbstractAttributes(type, handle) { + // index is required + setIndex(index); + // set defaults as defined in spec + setTexCoord(0); +} + +void MaterialTextureAttributes::writeValuesToJson( + io::JsonGenericValue& jsonObj, + io::JsonAllocator& allocator) const { + // write MaterialTextureAttributes values to json + writeValueToJson("index", jsonObj, allocator); + writeValueToJson("texCoord", jsonObj, allocator); + // handle instance-class specific writing + writeValuesToJsonInternal(jsonObj, allocator); +} + +std::string MaterialTextureAttributes::getObjectInfoHeaderInternal() const { + return "Texture Index,texCoord Index," + + getMaterialTextureInfoHeaderInternal(); +} + +std::string MaterialTextureAttributes::getObjectInfoInternal() const { + return Cr::Utility::formatString("{},{},{}", getAsString("index"), + getAsString("texCoord"), + getMaterialTextureInfoInternal()); +} // MaterialTextureAttributes::getObjectInfoInternal() + +NormalTextureAttributes::NormalTextureAttributes(int index, + const std::string& handle) + : MaterialTextureAttributes(index, handle, "NormalTextureAttributes") { + // set defaults as defined in spec + // normalTexture attributes scale of texture normals + setScale(1.0); +} + +OcclusionTextureAttributes::OcclusionTextureAttributes( + int index, + const std::string& handle) + : MaterialTextureAttributes(index, handle, "OcclusionTextureAttributes") { + // set defaults as defined in spec + // Ignored except for occlusionTexture attributes - scales red channel of + // occlusion texture + setStrength(1.0); +} + +PBRMetallicRoughnessAttributes::PBRMetallicRoughnessAttributes( + const std::string& handle) + : AbstractAttributes("PBRMetallicRoughnessAttributes", handle) { + // set defaults + setBaseColorFactor({1.0f, 1.0f, 1.0f, 1.0f}); + setMetallicFactor(1.0f); + setRoughnessFactor(1.0f); +} + +void PBRMetallicRoughnessAttributes::writeValuesToJson( + io::JsonGenericValue& jsonObj, + io::JsonAllocator& allocator) const { + if (hasSubconfig("baseColorTexture")) { + MaterialTextureAttributes::cptr bctSubConfig = + getSubconfigCopy("baseColorTexture"); + auto bctJsonObj = bctSubConfig->writeToJsonObject(allocator); + jsonObj.AddMember("baseColorTexture", bctJsonObj, allocator); + } + writeValueToJson("baseColorFactor", jsonObj, allocator); + if (hasSubconfig("metallicRoughnessTexture")) { + MaterialTextureAttributes::cptr mrSubConfig = + getSubconfigCopy( + "metallicRoughnessTexture"); + auto mrJsonObj = mrSubConfig->writeToJsonObject(allocator); + jsonObj.AddMember("metallicRoughnessTexture", mrJsonObj, allocator); + } + writeValueToJson("metallicFactor", jsonObj, allocator); + writeValueToJson("roughnessFactor", jsonObj, allocator); +} // PBRMetallicRoughnessAttributes::writeValuesToJson + +std::string PBRMetallicRoughnessAttributes::getObjectInfoInternal() const { + std::string res(""); + if (hasSubconfig("baseColorTexture")) { + MaterialTextureAttributes::cptr bctSubConfig = + getSubconfigCopy("baseColorTexture"); + Cr::Utility::formatInto(res, res.size(), "{},", + bctSubConfig->getObjectInfo()); + } + Cr::Utility::formatInto(res, res.size(), "{},", + getAsString("baseColorFactor")); + if (hasSubconfig("metallicRoughnessTexture")) { + MaterialTextureAttributes::cptr mrSubConfig = + getSubconfigCopy( + "metallicRoughnessTexture"); + Cr::Utility::formatInto(res, res.size(), "{},", + mrSubConfig->getObjectInfo()); + } + Cr::Utility::formatInto(res, res.size(), "{},{}", + getAsString("metallicFactor"), + getAsString("roughnessFactor")); + return res; +} // PBRMetallicRoughnessAttributes::getObjectInfoInternal + +std::string PBRMetallicRoughnessAttributes::getObjectInfoHeaderInternal() + const { + std::string res(""); + if (hasSubconfig("baseColorTexture")) { + MaterialTextureAttributes::cptr bctSubConfig = + getSubconfigCopy("baseColorTexture"); + Cr::Utility::formatInto(res, res.size(), "{},", + bctSubConfig->getObjectInfoHeader()); + } + Cr::Utility::formatInto(res, res.size(), "Base Color Factor,"); + if (hasSubconfig("metallicRoughnessTexture")) { + MaterialTextureAttributes::cptr mrSubConfig = + getSubconfigCopy( + "metallicRoughnessTexture"); + Cr::Utility::formatInto(res, res.size(), "{},", + mrSubConfig->getObjectInfoHeader()); + } + Cr::Utility::formatInto(res, res.size(), "Metallic Factor, Roughness Factor"); + return res; +} // PBRMetallicRoughnessAttributes::getObjectInfoHeaderInternal + MaterialAttributes::MaterialAttributes(const std::string& handle) - : AbstractAttributes("MaterialAttributes", handle) {} -MaterialAttributes::MaterialAttributes(const MaterialAttributes& otr) - : AbstractAttributes(otr) {} -MaterialAttributes::MaterialAttributes(MaterialAttributes&& otr) noexcept - : AbstractAttributes(std::move(static_cast(otr))) {} + : AbstractAttributes("MaterialAttributes", handle) { + // set defaults + setAlphaCutoff(0.5); + setDoubleSided(false); + setAlphaMode("OPAQUE"); + setEmissiveFactor({0.0f, 0.0f, 0.0f}); +} void MaterialAttributes::writeValuesToJson(io::JsonGenericValue& jsonObj, io::JsonAllocator& allocator) const { -} // MaterialAttributes::writeValuesToJson + if (hasSubconfig("pbrMetallicRoughness")) { + PBRMetallicRoughnessAttributes::cptr pbrMetRoughAttr = + getSubconfigCopy( + "pbrMetallicRoughness"); + auto pbrJsonObj = pbrMetRoughAttr->writeToJsonObject(allocator); + jsonObj.AddMember("pbrMetallicRoughness", pbrJsonObj, allocator); + } + if (hasSubconfig("normalTexture")) { + NormalTextureAttributes::cptr nrmlTxtrAttr = + getSubconfigCopy("normalTexture"); -MaterialAttributes& MaterialAttributes::operator=( - const MaterialAttributes& otr) { - if (this != &otr) { - this->AbstractAttributes::operator=(otr); + auto nrmlTxtrJsonObj = nrmlTxtrAttr->writeToJsonObject(allocator); + jsonObj.AddMember("normalTexture", nrmlTxtrJsonObj, allocator); } - return *this; -} -MaterialAttributes& MaterialAttributes::operator=( - MaterialAttributes&& otr) noexcept { - this->AbstractAttributes::operator=( - std::move(static_cast(otr))); - return *this; -} + if (hasSubconfig("occlusionTexture")) { + OcclusionTextureAttributes::cptr occlTxtrAttr = + getSubconfigCopy("occlusionTexture"); + + auto oclTxtrJsonObj = occlTxtrAttr->writeToJsonObject(allocator); + jsonObj.AddMember("occlusionTexture", oclTxtrJsonObj, allocator); + } + if (hasSubconfig("emissiveTexture")) { + MaterialTextureAttributes::cptr emmTxtrAttr = + getSubconfigCopy("emissiveTexture"); + + auto emmTxtrJsonObj = emmTxtrAttr->writeToJsonObject(allocator); + jsonObj.AddMember("emissiveTexture", emmTxtrJsonObj, allocator); + } + + writeValueToJson("emissiveFactor", jsonObj, allocator); + writeValueToJson("alphaMode", jsonObj, allocator); + writeValueToJson("alphaCutoff", jsonObj, allocator); + writeValueToJson("doubleSided", jsonObj, allocator); + +} // MaterialAttributes::writeValuesToJson std::string MaterialAttributes::getObjectInfoHeaderInternal() const { - return ""; + std::string res(""); + + if (hasSubconfig("pbrMetallicRoughness")) { + PBRMetallicRoughnessAttributes::cptr pbrMetRoughAttr = + getSubconfigCopy( + "pbrMetallicRoughness"); + Cr::Utility::formatInto(res, res.size(), "{},", + pbrMetRoughAttr->getObjectInfoHeader()); + } + if (hasSubconfig("normalTexture")) { + NormalTextureAttributes::cptr nrmlTxtrAttr = + getSubconfigCopy("normalTexture"); + + Cr::Utility::formatInto(res, res.size(), "{},", + nrmlTxtrAttr->getObjectInfoHeader()); + } + if (hasSubconfig("occlusionTexture")) { + OcclusionTextureAttributes::cptr occlTxtrAttr = + getSubconfigCopy("occlusionTexture"); + + Cr::Utility::formatInto(res, res.size(), "{},", + occlTxtrAttr->getObjectInfoHeader()); + } + if (hasSubconfig("emissiveTexture")) { + MaterialTextureAttributes::cptr emmTxtrAttr = + getSubconfigCopy("emissiveTexture"); + + Cr::Utility::formatInto(res, res.size(), "{},", + emmTxtrAttr->getObjectInfoHeader()); + } + + Cr::Utility::formatInto( + res, res.size(), + "Emissive Factor, Alpha Mode, Alpha Cutoff, Double Sided"); + + return res; } std::string MaterialAttributes::getObjectInfoInternal() const { - std::string res = "\n"; + std::string res = ""; + + if (hasSubconfig("pbrMetallicRoughness")) { + PBRMetallicRoughnessAttributes::cptr pbrMetRoughAttr = + getSubconfigCopy( + "pbrMetallicRoughness"); + Cr::Utility::formatInto(res, res.size(), "{},", + pbrMetRoughAttr->getObjectInfo()); + } + if (hasSubconfig("normalTexture")) { + NormalTextureAttributes::cptr nrmlTxtrAttr = + getSubconfigCopy("normalTexture"); + + Cr::Utility::formatInto(res, res.size(), "{},", + nrmlTxtrAttr->getObjectInfo()); + } + if (hasSubconfig("occlusionTexture")) { + OcclusionTextureAttributes::cptr occlTxtrAttr = + getSubconfigCopy("occlusionTexture"); + + Cr::Utility::formatInto(res, res.size(), "{},", + occlTxtrAttr->getObjectInfo()); + } + if (hasSubconfig("emissiveTexture")) { + MaterialTextureAttributes::cptr emmTxtrAttr = + getSubconfigCopy("emissiveTexture"); + + Cr::Utility::formatInto(res, res.size(), "{},", + emmTxtrAttr->getObjectInfo()); + } + + Cr::Utility::formatInto(res, res.size(), "{},{},{},{}", + getAsString("emissiveFactor"), + getAsString("alphaMode"), getAsString("alphaCutoff"), + getAsString("doubleSided")); return res; } diff --git a/src/esp/metadata/attributes/MaterialAttributes.h b/src/esp/metadata/attributes/MaterialAttributes.h index 34ed874169..d2c7dc9050 100644 --- a/src/esp/metadata/attributes/MaterialAttributes.h +++ b/src/esp/metadata/attributes/MaterialAttributes.h @@ -11,18 +11,463 @@ namespace esp { namespace metadata { namespace attributes { +/** + * @brief This class describes the texture references within a particular + * material definition. This follows the gltf 2.0 spec. + */ +class MaterialTextureAttributes : public AbstractAttributes { + public: + explicit MaterialTextureAttributes( + int index, + const std::string& handle, + const std::string& type = "MaterialTextureAttributes"); + + /** @brief Set the index of this texture. */ + void setIndex(int index) { set("index", index); } + + /** @brief Get the index of this texture. */ + int getIndex() const { return get("index"); } + + /** @brief Set the texCoord mesh attribute index of this texture. */ + void setTexCoord(int texCoord) { set("texCoord", texCoord); } + + /** @brief Get the texCoord mesh attribute index of this texture. */ + int getTexCoord() const { return get("texCoord"); } + + /** + * @brief Populate a Json object with all the first-level values held in this + * MaterialTextureAttributes. Default is overridden to handle special + * cases for MaterialTextureAttributes. + */ + void writeValuesToJson(io::JsonGenericValue& jsonObj, + io::JsonAllocator& allocator) const override; + + protected: + /** + * @brief Retrieve a comma-separated informational string about the contents + * of this managed object. + */ + std::string getObjectInfoInternal() const override; + /** + * @brief Retrieve a comma-separated string holding the header values for + * the info returned for this managed object, type-specific. + */ + std::string getObjectInfoHeaderInternal() const override; + + /** + * @brief Write child-class-specific Json data. + */ + virtual void writeValuesToJsonInternal(io::JsonGenericValue& jsonObj, + io::JsonAllocator& allocator) const {} + + /** + * @brief Retrieve a comma-separated informational string about the contents + * of this managed object. To support normal and occlusion texture attributes + */ + virtual std::string getMaterialTextureInfoInternal() const { return ""; } + + /** + * @brief Retrieve a comma-separated informational string about the contents + * of this managed object. To support normal and occlusion texture attributes + */ + virtual std::string getMaterialTextureInfoHeaderInternal() const { + return ""; + } + + public: + ESP_SMART_POINTERS(MaterialTextureAttributes) +}; + +/** + * @brief This class describes the normalTexture references within a particular + * material definition. This follows the gltf 2.0 spec. + */ +class NormalTextureAttributes : public MaterialTextureAttributes { + public: + explicit NormalTextureAttributes(int index, const std::string& handle); + + /** @brief Set the scale to be used for this (normal) texture. + * Texture-defined normals are scaled following this eq : + * `scaledNormal = + * normalize(( * 2.0 - 1.0) * + * vec3(, , 1.0))` + */ + void setScale(double scale) { set("scale", scale); } + + /** @brief Get the scale to be used for this (normal) texture. + * Texture-defined normals are scaled following this eq : + * `scaledNormal = + * normalize(( * 2.0 - 1.0) * + * vec3(, , 1.0))` + */ + double getScale() const { return get("scale"); } + + protected: + /** + * @brief Retrieve a comma-separated informational string about the contents + * of this managed object. To support normal and occlusion texture attributes + */ + std::string getMaterialTextureInfoInternal() const override { + return Cr::Utility::formatString("{},", getAsString("scale")); + } + + /** + * @brief Retrieve a comma-separated informational string about the contents + * of this managed object. To support normal and occlusion texture attributes + */ + std::string getMaterialTextureInfoHeaderInternal() const override { + return "Normal XY Scale,"; + } + + /** + * @brief Write NormalTextureAttributes-specific Json data. + */ + void writeValuesToJsonInternal(io::JsonGenericValue& jsonObj, + io::JsonAllocator& allocator) const override { + writeValueToJson("scale", jsonObj, allocator); + } + + public: + ESP_SMART_POINTERS(NormalTextureAttributes) +}; // class NormalTextureAttributes + +/** + * @brief This class describes the occlusionTexture references within a + * particular material definition. This follows the gltf 2.0 spec. + */ +class OcclusionTextureAttributes : public MaterialTextureAttributes { + public: + explicit OcclusionTextureAttributes(int index, const std::string& handle); + + /** @brief Set the strength to be used for this (occlusion) texture. + * The occlusion values are linearly sampled from the R channel of the + * texture. Higher values indicate areas that receive full indirect lighting + * and lower values indicate no indirect lighting. Values in texture are + * scaled by strength using this EQ : + * + * `1.0 + strength * ( - 1.0)` + */ + void setStrength(double strength) { set("strength", strength); } + + /** @brief Get the strength to be used for this (occlusion) texture. + * The occlusion values are linearly sampled from the R channel of the + * texture. Higher values indicate areas that receive full indirect lighting + * and lower values indicate no indirect lighting.Values in texture are + * scaled by strength using this EQ : + * + * `1.0 + strength * ( - 1.0)` + */ + double getStrength() const { return get("strength"); } + + protected: + /** + * @brief Retrieve a comma-separated informational string about the contents + * of this managed object. To support normal and occlusion texture attributes + */ + std::string getMaterialTextureInfoInternal() const override { + return Cr::Utility::formatString("{},", getAsString("strength")); + } + + /** + * @brief Retrieve a comma-separated informational string about the contents + * of this managed object. To support normal and occlusion texture attributes + */ + std::string getMaterialTextureInfoHeaderInternal() const override { + return "Occlusion Strength,"; + } + + /** + * @brief Write OcclusionTextureAttributes-specific Json data. + */ + void writeValuesToJsonInternal(io::JsonGenericValue& jsonObj, + io::JsonAllocator& allocator) const override { + writeValueToJson("strength", jsonObj, allocator); + } + + public: + ESP_SMART_POINTERS(OcclusionTextureAttributes) +}; // class OcclusionTextureAttributes + +/** + * @brief This class defines the component of the material attributes relating + * to the bpr base color, metalness, and roughness. This corresponds to the + * pbrMetallicRoughness Json object in the gltf 2.0 spec. + */ +class PBRMetallicRoughnessAttributes : public AbstractAttributes { + public: + explicit PBRMetallicRoughnessAttributes(const std::string& handle); + + /** + * @brief Set the description of the @ref MaterialTextureAttributes for + * the BaseColorTexture for this material. There will be only one + * specified. + */ + void setBaseColorTexture(MaterialTextureAttributes::ptr _baseColorTexture) { + // force ID to be 0, there will be only 1 baseColorTexture defined for any + // PBRMetallicRoughnessAttributes object. + _baseColorTexture->setID(0); + setSubconfigPtr("baseColorTexture", + _baseColorTexture); + } + + /** + * @brief Get a shared_pointer to the @ref MaterialTextureAttributes + * descibing the BaseColorTexture specified for this material. + */ + MaterialTextureAttributes::cptr getBaseColorTexture() const { + return getSubconfigCopy( + "baseColorTexture"); + } + + /** + * @brief Set the description of the @ref MaterialTextureAttributes for the + * MetallicRoughtnessTexture for this material. There will be only one + * specified. + */ + void setMetallicRoughnessTexture( + MaterialTextureAttributes::ptr _metallicRoughnessTexture) { + // force ID to be 0, there will be only 1 metallicRoughnessTexture defined + // for any PBRMetallicRoughnessAttributes object. + _metallicRoughnessTexture->setID(0); + setSubconfigPtr("metallicRoughnessTexture", + _metallicRoughnessTexture); + } + + /** + * @brief Get a shared_pointer to the @ref MaterialTextureAttributes + * descibing the MetallicRoughtnessTexture specified for this material. + */ + MaterialTextureAttributes::cptr getMetallicRoughnessTexture() const { + return getSubconfigCopy( + "metallicRoughnessTexture"); + } + + /** + * @brief Set the base color factor for this PBRMetallicRoughnessAttributes. + * Default : [1.0f,1.0f,1.0f,1.0f] + * @param baseColorFactor Linear multiplier of baseColorTexture. Treated as + * object color if no texture exists + */ + void setBaseColorFactor(const Mn::Color4& baseColorFactor) { + set("baseColorFactor", baseColorFactor); + } + + /** + * @brief Get the base color factor for this PBRMetallicRoughnessAttributes. + * Default : [1.0f,1.0f,1.0f,1.0f] + * @return Linear multiplier of baseColorTexture. Treated as + * object color if no texture exists + */ + Mn::Color4 getBaseColorFactor() const { + return get("baseColorFactor"); + } + + /** + * Set factor for the metalness of the material. This value defines a linear + * multiplier for the sampled metalness values of the metallic-roughness + * texture, if present. DEFAULT: 1.0 + */ + void setMetallicFactor(double metallicFactor) { + set("metallicFactor", metallicFactor); + } + + /** + * Get factor for the metalness of the material. This value defines a linear + * multiplier for the sampled metalness values of the metallic-roughness + * texture, if present. DEFAULT: 1.0 + */ + double getMetallicFactor() const { return get("metallicFactor"); } + + /** + * Set factor for the roughness of the material. This value defines a linear + * multiplier for the sampled roughness values of the metallic-roughness + * texture, if present. DEFAULT: 1.0 + */ + void setRoughnessFactor(double roughnessFactor) { + set("roughnessFactor", roughnessFactor); + } + + /** + * Get factor for the roughness of the material. This value defines a linear + * multiplier for the sampled roughness values of the metallic-roughness + * texture. DEFAULT: 1.0 + */ + double getRoughnessFactor() const { return get("roughnessFactor"); } + + /** + * @brief Populate a Json object with all the first-level values held in this + * PBRMetallicRoughnessAttributes. Default is overridden to handle special + * cases for PBRMetallicRoughnessAttributes. + */ + void writeValuesToJson(io::JsonGenericValue& jsonObj, + io::JsonAllocator& allocator) const override; + + protected: + /** + * @brief Retrieve a comma-separated informational string about the contents + * of this managed object. + */ + std::string getObjectInfoInternal() const override; + /** + * @brief Retrieve a comma-separated string holding the header values for + * the info returned for this managed object, type-specific. + */ + std::string getObjectInfoHeaderInternal() const override; + + public: + ESP_SMART_POINTERS(PBRMetallicRoughnessAttributes) +}; // class PBRMetallicRoughnessAttributes + class MaterialAttributes : public AbstractAttributes { public: explicit MaterialAttributes(const std::string& handle = ""); - MaterialAttributes(const MaterialAttributes& otr); - MaterialAttributes(MaterialAttributes&& otr) noexcept; + /** + * @brief Set the description of the @ref PBRMetallicRoughnessAttributes for + * this material. There will be only one specified. + */ + void setPBRMetallicRoughness( + PBRMetallicRoughnessAttributes::ptr _pbrMetallicRoughness) { + _pbrMetallicRoughness->setID(0); + setSubconfigPtr("pbrMetallicRoughness", + _pbrMetallicRoughness); + } + + /** + * @brief Get a shared_pointer to the @ref PBRMetallicRoughnessAttributes + * descibing the set of parameters describing the color and metallic-roughness + * for this material. + */ + PBRMetallicRoughnessAttributes::cptr getPBRMetallicRoughness() const { + return getSubconfigCopy( + "pbrMetallicRoughness"); + } + + /** + * @brief Set the description of the @ref OcclusionTextureAttributes for this + * material. There will be only one specified. + */ + void setOcclusionTexture(OcclusionTextureAttributes::ptr _occlusionTexture) { + _occlusionTexture->setID(0); + setSubconfigPtr("occlusionTexture", + _occlusionTexture); + } + /** + * @brief Get a shared_pointer to the @ref OcclusionTextureAttributes + * descibing the nature of the occlusionTexture for this material. + */ + OcclusionTextureAttributes::cptr getOcclusionTexture() const { + return getSubconfigCopy( + "occlusionTexture"); + } + + /** + * @brief Set the description of the @ref NormalTextureAttributes for this + * material. There will be only one specified. + */ + void setNormalTexture(NormalTextureAttributes::ptr _normalTexture) { + _normalTexture->setID(0); + setSubconfigPtr("normalTexture", _normalTexture); + } + /** + * @brief Get a shared_pointer to the @ref NormalTextureAttributes + * descibing the nature of the occlusionTexture for this material. + */ + NormalTextureAttributes::cptr getNormalTexture() const { + return getSubconfigCopy("normalTexture"); + } + + /** + * @brief Set the description of the emissiveTexture @ref + * MaterialTextureAttributes for this material. There will be only one + * specified. + */ + void setEmissiveTexture(MaterialTextureAttributes::ptr _emissiveTexture) { + _emissiveTexture->setID(0); + setSubconfigPtr("emissiveTexture", + _emissiveTexture); + } + /** + * @brief Get a shared_pointer to the emissiveTexture @ref + * MaterialTextureAttributes descibing the nature of the emissiveTexture for + * this material. + */ + MaterialTextureAttributes::cptr getEmissiveTexture() const { + return getSubconfigCopy("emissiveTexture"); + } + + /** + * @brief Set a value representing the alphaMode value for this material. This + * value should correspond to an enum value defined in MaterialAlphaMode. + */ + void setAlphaMode(const std::string& alphaMode) { + // force to uppercase before setting + const std::string alphaModeUC = Cr::Utility::String::uppercase(alphaMode); + + auto mapIter = AlphaModeNamesMap.find(alphaModeUC); - MaterialAttributes& operator=(const MaterialAttributes& otr); - MaterialAttributes& operator=(MaterialAttributes&& otr) noexcept; + ESP_CHECK(mapIter != AlphaModeNamesMap.end(), + "Illegal alphaMode value" + << alphaMode << "attempted to be set in MaterialAttributes :" + << getHandle() << ". Aborting."); + set("alphaMode", alphaModeUC); + } // setAlphaMode + + /** + * @brief Get the value representing the alphaMode value for this material. + * Should map to an enum value in AlphaModeNamesMap + */ + MaterialAlphaMode getAlphaMode() const { + const std::string val = + Cr::Utility::String::uppercase(get("alphaMode")); + auto mapIter = AlphaModeNamesMap.find(val); + if (mapIter != AlphaModeNamesMap.end()) { + return mapIter->second; + } + // Opaque is default value + return MaterialAlphaMode::Opaque; + } // getAlphaMode + + /** + * Set cutoff when alphaMode == MASK. Ignored otherwise. DEFAULT: [0,0,0] + */ + void setEmissiveFactor(const Mn::Vector3& emissiveFactor) { + set("emissiveFactor", emissiveFactor); + } + + /** + * Get cutoff when alphaMode == MASK. Ignored otherwise. DEFAULT: [0,0,0] + */ + Mn::Vector3 getEmissiveFactor() const { + return get("emissiveFactor"); + } + + /** + * Set cutoff when alphaMode == MASK. Ignored otherwise. DEFAULT: 0.5 + */ + void setAlphaCutoff(double alphaCutoff) { set("alphaCutoff", alphaCutoff); } + + /** + * Get cutoff when alphaMode == MASK. Ignored otherwise. DEFAULT: 0.5 + */ + double getAlphaCutoff() const { return get("alphaCutoff"); } + + /** + * Set whether material is double sided, when false, back-face culling is + * enabled, otherwise back-face culling is disabled, 2x-sided lighting is + * enabled. + */ + void setDoubleSided(bool doubleSided) { set("doubleSided", doubleSided); } + + /** + * Get whether material is double sided, when false, back-face culling is + * enabled, otherwise back-face culling is disabled, 2x-sided lighting is + * enabled. + */ + bool getDoubleSided() const { return get("doubleSided"); } /** - * @brief Populate a json object with all the first-level values held in this + * @brief Populate a Json object with all the first-level values held in this * configuration. Default is overridden to handle special cases for * MaterialAttributes. */ @@ -45,7 +490,7 @@ class MaterialAttributes : public AbstractAttributes { public: ESP_SMART_POINTERS(MaterialAttributes) -}; // class MaterialAttributes +}; // namespace attributes } // namespace attributes } // namespace metadata From f07c353c0221af3f61de6af77b6d967595a1af92 Mon Sep 17 00:00:00 2001 From: John Turner <7strbass@gmail.com> Date: Thu, 26 May 2022 12:54:26 -0400 Subject: [PATCH 3/6] --add ref to MaterialAttributesManager;Simplify --- src/esp/bindings/AttributesBindings.cpp | 1 + .../attributes/MaterialAttributes.cpp | 21 ++++++------------- .../managers/MaterialAttributesManager.h | 10 --------- 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/src/esp/bindings/AttributesBindings.cpp b/src/esp/bindings/AttributesBindings.cpp index e0a5404e0b..ec65113b47 100644 --- a/src/esp/bindings/AttributesBindings.cpp +++ b/src/esp/bindings/AttributesBindings.cpp @@ -13,6 +13,7 @@ #include "esp/metadata/attributes/AttributesEnumMaps.h" #include "esp/metadata/attributes/LightLayoutAttributes.h" #include "esp/metadata/attributes/MarkerSets.h" +#include "esp/metadata/attributes/MaterialAttributes.h" #include "esp/metadata/attributes/ObjectAttributes.h" #include "esp/metadata/attributes/PbrShaderAttributes.h" #include "esp/metadata/attributes/PhysicsManagerAttributes.h" diff --git a/src/esp/metadata/attributes/MaterialAttributes.cpp b/src/esp/metadata/attributes/MaterialAttributes.cpp index f3d403beeb..dd6ccdf4a2 100644 --- a/src/esp/metadata/attributes/MaterialAttributes.cpp +++ b/src/esp/metadata/attributes/MaterialAttributes.cpp @@ -70,16 +70,13 @@ void PBRMetallicRoughnessAttributes::writeValuesToJson( io::JsonGenericValue& jsonObj, io::JsonAllocator& allocator) const { if (hasSubconfig("baseColorTexture")) { - MaterialTextureAttributes::cptr bctSubConfig = - getSubconfigCopy("baseColorTexture"); + MaterialTextureAttributes::cptr bctSubConfig = getBaseColorTexture(); auto bctJsonObj = bctSubConfig->writeToJsonObject(allocator); jsonObj.AddMember("baseColorTexture", bctJsonObj, allocator); } writeValueToJson("baseColorFactor", jsonObj, allocator); if (hasSubconfig("metallicRoughnessTexture")) { - MaterialTextureAttributes::cptr mrSubConfig = - getSubconfigCopy( - "metallicRoughnessTexture"); + MaterialTextureAttributes::cptr mrSubConfig = getMetallicRoughnessTexture(); auto mrJsonObj = mrSubConfig->writeToJsonObject(allocator); jsonObj.AddMember("metallicRoughnessTexture", mrJsonObj, allocator); } @@ -90,17 +87,14 @@ void PBRMetallicRoughnessAttributes::writeValuesToJson( std::string PBRMetallicRoughnessAttributes::getObjectInfoInternal() const { std::string res(""); if (hasSubconfig("baseColorTexture")) { - MaterialTextureAttributes::cptr bctSubConfig = - getSubconfigCopy("baseColorTexture"); + MaterialTextureAttributes::cptr bctSubConfig = getBaseColorTexture(); Cr::Utility::formatInto(res, res.size(), "{},", bctSubConfig->getObjectInfo()); } Cr::Utility::formatInto(res, res.size(), "{},", getAsString("baseColorFactor")); if (hasSubconfig("metallicRoughnessTexture")) { - MaterialTextureAttributes::cptr mrSubConfig = - getSubconfigCopy( - "metallicRoughnessTexture"); + MaterialTextureAttributes::cptr mrSubConfig = getMetallicRoughnessTexture(); Cr::Utility::formatInto(res, res.size(), "{},", mrSubConfig->getObjectInfo()); } @@ -114,16 +108,13 @@ std::string PBRMetallicRoughnessAttributes::getObjectInfoHeaderInternal() const { std::string res(""); if (hasSubconfig("baseColorTexture")) { - MaterialTextureAttributes::cptr bctSubConfig = - getSubconfigCopy("baseColorTexture"); + MaterialTextureAttributes::cptr bctSubConfig = getBaseColorTexture(); Cr::Utility::formatInto(res, res.size(), "{},", bctSubConfig->getObjectInfoHeader()); } Cr::Utility::formatInto(res, res.size(), "Base Color Factor,"); if (hasSubconfig("metallicRoughnessTexture")) { - MaterialTextureAttributes::cptr mrSubConfig = - getSubconfigCopy( - "metallicRoughnessTexture"); + MaterialTextureAttributes::cptr mrSubConfig = getMetallicRoughnessTexture(); Cr::Utility::formatInto(res, res.size(), "{},", mrSubConfig->getObjectInfoHeader()); } diff --git a/src/esp/metadata/managers/MaterialAttributesManager.h b/src/esp/metadata/managers/MaterialAttributesManager.h index d57af84722..cfb0465ebb 100644 --- a/src/esp/metadata/managers/MaterialAttributesManager.h +++ b/src/esp/metadata/managers/MaterialAttributesManager.h @@ -113,16 +113,6 @@ class MaterialAttributesManager */ void resetFinalize() override {} - /** - * @brief Material Attributes has no reason to check this value - * @param handle String name of primitive asset attributes desired - * @return whether handle exists or not in asset attributes library - */ - bool isValidPrimitiveAttributes( - CORRADE_UNUSED const std::string& handle) override { - return false; - } - public: ESP_SMART_POINTERS(MaterialAttributesManager) From 972a51ce5260fcc880170cbf2bc21c88f87d6bd0 Mon Sep 17 00:00:00 2001 From: John Turner <7strbass@gmail.com> Date: Tue, 21 Feb 2023 10:24:15 -0500 Subject: [PATCH 4/6] --remove dupe defs --- .../attributes/AttributesEnumMaps.cpp | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/src/esp/metadata/attributes/AttributesEnumMaps.cpp b/src/esp/metadata/attributes/AttributesEnumMaps.cpp index 06c6497e26..8c9f28f6cd 100644 --- a/src/esp/metadata/attributes/AttributesEnumMaps.cpp +++ b/src/esp/metadata/attributes/AttributesEnumMaps.cpp @@ -88,12 +88,6 @@ std::string getLightTypeName(esp::gfx::LightType lightTypeEnum) { } return "point"; } - -const std::map - LightPositionNamesMap = {{"global", esp::gfx::LightPositionModel::Global}, - {"camera", esp::gfx::LightPositionModel::Camera}, - {"object", esp::gfx::LightPositionModel::Object}}; - std::string getLightPositionModelName( esp::gfx::LightPositionModel lightPositionEnum) { // this verifies that enum value being checked is supported by string-keyed @@ -212,14 +206,6 @@ std::string getAORenderModeName(ArticulatedObjectRenderMode aoRenderMode) { return "unspecified"; } // getAORenderModeName -const std::map ShaderTypeNamesMap = { - {"unspecified", ObjectInstanceShaderType::Unspecified}, - {"material", ObjectInstanceShaderType::Material}, - {"flat", ObjectInstanceShaderType::Flat}, - {"phong", ObjectInstanceShaderType::Phong}, - {"pbr", ObjectInstanceShaderType::PBR}, -}; - std::string getShaderTypeName(ObjectInstanceShaderType shaderTypeVal) { // this verifies that enum value being checked is supported by string-keyed // map. The values below should be the minimum and maximum enums supported by @@ -280,13 +266,6 @@ std::string getTranslationOriginName( return "default"; } // getTranslationOriginName -// All keys must be lowercase -const std::map MotionTypeNamesMap = { - {"static", esp::physics::MotionType::STATIC}, - {"kinematic", esp::physics::MotionType::KINEMATIC}, - {"dynamic", esp::physics::MotionType::DYNAMIC}, -}; - std::string getMotionTypeName(esp::physics::MotionType motionTypeEnum) { // this verifies that enum value being checked is supported by string-keyed // map. The values below should be the minimum and maximum enums supported by From 7d94b4a4a9320798f05d155da4425f8a4cb641fa Mon Sep 17 00:00:00 2001 From: John Turner <7strbass@gmail.com> Date: Tue, 10 Oct 2023 10:53:13 -0400 Subject: [PATCH 5/6] --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 62bba4eaa8..633e640c7a 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) { From 6276ac9ef367b1a7314fbd6f025efc24f870a84c Mon Sep 17 00:00:00 2001 From: John Turner <7strbass@gmail.com> Date: Wed, 4 Dec 2024 10:12:47 -0500 Subject: [PATCH 6/6] --update cmakelists --- src/esp/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/esp/CMakeLists.txt b/src/esp/CMakeLists.txt index b878364cfd..38f878bab1 100644 --- a/src/esp/CMakeLists.txt +++ b/src/esp/CMakeLists.txt @@ -295,6 +295,8 @@ set( metadata/attributes/LightLayoutAttributes.h metadata/attributes/LightLayoutAttributes.cpp metadata/attributes/MarkerSets.h + metadata/attributes/MaterialAttributes.h + metadata/attributes/MaterialAttributes.cpp metadata/attributes/ObjectAttributes.h metadata/attributes/ObjectAttributes.cpp metadata/attributes/PhysicsManagerAttributes.h @@ -319,6 +321,8 @@ set( metadata/managers/AssetAttributesManager.cpp metadata/managers/LightLayoutAttributesManager.h metadata/managers/LightLayoutAttributesManager.cpp + metadata/managers/MaterialAttributesManager.h + metadata/managers/MaterialAttributesManager.cpp metadata/managers/ObjectAttributesManager.h metadata/managers/ObjectAttributesManager.cpp metadata/managers/PbrShaderAttributesManager.h