Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]--Support for Material Attributes using GLTF format. #1762

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/esp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/esp/bindings/AttributesBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
72 changes: 51 additions & 21 deletions src/esp/metadata/attributes/AttributesEnumMaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,39 @@ const std::map<std::string, esp::gfx::LightType> LightTypeNamesMap = {
{"directional", esp::gfx::LightType::Directional},
{"spot", esp::gfx::LightType::Spot}};

const std::map<std::string, esp::gfx::LightPositionModel>
LightPositionNamesMap = {{"global", esp::gfx::LightPositionModel::Global},
{"camera", esp::gfx::LightPositionModel::Camera},
{"object", esp::gfx::LightPositionModel::Object}};

const std::map<std::string, ObjectInstanceShaderType> ShaderTypeNamesMap = {
{"unspecified", ObjectInstanceShaderType::Unspecified},
{"material", ObjectInstanceShaderType::Material},
{"flat", ObjectInstanceShaderType::Flat},
{"phong", ObjectInstanceShaderType::Phong},
{"pbr", ObjectInstanceShaderType::PBR},
};

const std::map<std::string, MaterialAlphaMode> AlphaModeNamesMap = {
{"OPAQUE", MaterialAlphaMode::Opaque},
{"MASK", MaterialAlphaMode::Mask},
{"BLEND", MaterialAlphaMode::Blend}

};

const std::map<std::string, SceneInstanceTranslationOrigin>
InstanceTranslationOriginMap = {
{"asset_local", SceneInstanceTranslationOrigin::AssetLocal},
{"com", SceneInstanceTranslationOrigin::COM},
};

// All keys must be lowercase
const std::map<std::string, esp::physics::MotionType> 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
Expand All @@ -55,12 +88,6 @@ std::string getLightTypeName(esp::gfx::LightType lightTypeEnum) {
}
return "point";
}

const std::map<std::string, esp::gfx::LightPositionModel>
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
Expand Down Expand Up @@ -179,14 +206,6 @@ std::string getAORenderModeName(ArticulatedObjectRenderMode aoRenderMode) {
return "unspecified";
} // getAORenderModeName

const std::map<std::string, ObjectInstanceShaderType> 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
Expand All @@ -210,6 +229,24 @@ const std::map<std::string, SceneInstanceTranslationOrigin>
{"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) {
Expand All @@ -229,13 +266,6 @@ std::string getTranslationOriginName(
return "default";
} // getTranslationOriginName

// All keys must be lowercase
const std::map<std::string, esp::physics::MotionType> 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
Expand Down
38 changes: 38 additions & 0 deletions src/esp/metadata/attributes/AttributesEnumMaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -299,12 +323,26 @@ std::string getAORenderModeName(ArticulatedObjectRenderMode aoRenderMode);
*/
const extern std::map<std::string, ObjectInstanceShaderType> 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<std::string, MaterialAlphaMode> 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
Expand Down
Loading
Loading