Skip to content

Commit

Permalink
--improve AssetType attributes internal handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jturner65 committed May 13, 2024
1 parent d7c3fd6 commit 7cbf717
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/esp/metadata/attributes/StageAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ StageAttributes::StageAttributes(const std::string& handle)
// TODO remove this once ShaderType support is complete
setForceFlatShading(true);
// AssetType::Unknown->treated as general mesh
initCollisionAssetType(getAssetTypeName(AssetType::Unknown));
initCollisionAssetTypeEnum(AssetType::Unknown);
// AssetType::InstanceMesh->standard semantic mesh handling
initSemanticAssetType(getAssetTypeName(AssetType::InstanceMesh));
initSemanticAssetTypeEnum(AssetType::InstanceMesh);
// set empty defaults for handles
init("nav_asset", "");
init("semantic_asset", "");
Expand Down
18 changes: 9 additions & 9 deletions src/esp/metadata/managers/AbstractObjectAttributesManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class AbstractObjectAttributesManager : public AttributesManager<T, Access> {
const char* jsonMeshTypeTag,
const char* jsonMeshHandleTag,
std::string& assetName,
const std::function<void(const std::string&)>& meshTypeSetter);
const std::function<void(AssetType)>& meshTypeSetter);

/**
* @brief Perform asset-name-based attributes initialization. This is to
Expand All @@ -200,7 +200,7 @@ class AbstractObjectAttributesManager : public AttributesManager<T, Access> {
AbsObjAttrPtr attributes,
bool setFrame,
const std::string& assetName,
const std::function<void(const std::string&)>& assetTypeSetter) = 0;
const std::function<void(AssetType)>& assetTypeSetter) = 0;

// ======== Typedefs and Instance Variables ========

Expand Down Expand Up @@ -331,17 +331,17 @@ auto AbstractObjectAttributesManager<T, Access>::
// is true if mesh name is found in JSON and different than current value
std::string rndrFName = setJSONAssetHandleAndType(
attributes, jsonDoc, "render_asset_type", "render_asset", rTmpFName,
[attributes](const std::string& render_asset_type) {
attributes->setRenderAssetType(render_asset_type);
[attributes](AssetType render_asset_type) {
attributes->setRenderAssetTypeEnum(render_asset_type);
});

// current value - also place holder for json read result
std::string cTmpFName = attributes->getCollisionAssetHandle();
// is true if mesh name is found in JSON and different than current value
std::string colFName = setJSONAssetHandleAndType(
attributes, jsonDoc, "collision_asset_type", "collision_asset", cTmpFName,
[attributes](const std::string& collision_asset_type) {
attributes->setCollisionAssetType(collision_asset_type);
[attributes](AssetType collision_asset_type) {
attributes->setCollisionAssetTypeEnum(collision_asset_type);
});
// use non-empty result if either result is empty
attributes->setRenderAssetHandle(rndrFName.empty() ? colFName : rndrFName);
Expand Down Expand Up @@ -380,7 +380,7 @@ AbstractObjectAttributesManager<T, Access>::setJSONAssetHandleAndType(
const char* jsonMeshTypeTag,
const char* jsonMeshHandleTag,
std::string& assetName,
const std::function<void(const std::string&)>& meshTypeSetter) {
const std::function<void(AssetType)>& meshTypeSetter) {
// save current file name
std::string oldFName(assetName);
// clear var to get new value - if returns true use this as new value
Expand All @@ -390,13 +390,13 @@ AbstractObjectAttributesManager<T, Access>::setJSONAssetHandleAndType(
std::string tmpVal = "";
bool typeFound = false;
if (io::readMember<std::string>(jsonDoc, jsonMeshTypeTag, tmpVal)) {
std::string typeVal = attributes::getAssetTypeName(AssetType::Unknown);
AssetType typeVal = AssetType::Unknown;
// tag was found, perform check
std::string strToLookFor = Cr::Utility::String::lowercase(tmpVal);

auto found = attributes::AssetTypeNamesMap.find(strToLookFor);
if (found != attributes::AssetTypeNamesMap.end()) {
typeVal = strToLookFor;
typeVal = found->second;
typeFound = true;
} else {
ESP_WARNING(Mn::Debug::Flag::NoSpace)
Expand Down
19 changes: 9 additions & 10 deletions src/esp/metadata/managers/ObjectAttributesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ ObjectAttributesManager::createPrimBasedAttributesTemplate(
primObjectAttributes->setScale({0.1, 0.1, 0.1});

// set render mesh handle
const std::string primType = getAssetTypeName(AssetType::Primitive);
primObjectAttributes->setRenderAssetType(primType);
primObjectAttributes->setRenderAssetTypeEnum(AssetType::Primitive);
// set collision mesh/primitive handle and default for primitives to not use
// mesh collisions
primObjectAttributes->setCollisionAssetType(primType);
primObjectAttributes->setCollisionAssetTypeEnum(AssetType::Primitive);
primObjectAttributes->setUseMeshCollision(false);
// NOTE to eventually use mesh collisions with primitive objects, a
// collision primitive mesh needs to be configured and set in MeshMetaData
Expand Down Expand Up @@ -176,14 +175,14 @@ ObjectAttributes::ptr ObjectAttributesManager::initNewObjectInternal(
// set defaults for passed render asset handles
this->setDefaultAssetNameBasedAttributes(
newAttributes, true, newAttributes->getRenderAssetHandle(),
[newAttributes](const std::string& render_asset_type) {
newAttributes->initRenderAssetType(render_asset_type);
[newAttributes](AssetType render_asset_type) {
newAttributes->initRenderAssetTypeEnum(render_asset_type);
});
// set defaults for passed collision asset handles
this->setDefaultAssetNameBasedAttributes(
newAttributes, false, newAttributes->getCollisionAssetHandle(),
[newAttributes](const std::string& collision_asset_type) {
newAttributes->initCollisionAssetType(collision_asset_type);
[newAttributes](AssetType collision_asset_type) {
newAttributes->initCollisionAssetTypeEnum(collision_asset_type);
});
}
return newAttributes;
Expand All @@ -195,13 +194,13 @@ void ObjectAttributesManager::setDefaultAssetNameBasedAttributes(
ObjectAttributes::ptr attributes,
bool setFrame,
const std::string& meshHandle,
const std::function<void(const std::string&)>& assetTypeSetter) {
const std::function<void(AssetType)>& assetTypeSetter) {
if (this->isValidPrimitiveAttributes(meshHandle)) {
// value is valid primitive, and value is different than existing value
assetTypeSetter(getAssetTypeName(AssetType::Primitive));
assetTypeSetter(AssetType::Primitive);
} else {
// use unknown for object mesh types of non-primitives
assetTypeSetter(getAssetTypeName(AssetType::Unknown));
assetTypeSetter(AssetType::Unknown);
}
if (setFrame) {
attributes->init("up", Mn::Vector3{0.0, 1.0, 0.0});
Expand Down
2 changes: 1 addition & 1 deletion src/esp/metadata/managers/ObjectAttributesManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class ObjectAttributesManager
attributes::ObjectAttributes::ptr attributes,
bool setFrame,
const std::string& meshHandle,
const std::function<void(const std::string&)>& assetTypeSetter) override;
const std::function<void(AssetType)>& assetTypeSetter) override;

/**
* @brief Used Internally. Create and configure newly-created attributes
Expand Down
22 changes: 12 additions & 10 deletions src/esp/metadata/managers/StageAttributesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ StageAttributesManager::preRegisterObjectFinalize(
stageAttributes->setRenderAssetIsPrimitive(false);
} else if (std::string::npos != stageAttributesHandle.find("NONE")) {
// Render asset handle will be NONE as well - force type to be unknown
stageAttributes->setRenderAssetType(getAssetTypeName(AssetType::Unknown));
stageAttributes->setRenderAssetTypeEnum(AssetType::Unknown);
stageAttributes->setRenderAssetIsPrimitive(false);
} else if (forceRegistration) {
ESP_WARNING()
Expand Down Expand Up @@ -288,21 +288,22 @@ StageAttributes::ptr StageAttributesManager::initNewObjectInternal(
StageAttributesManager::setDefaultAssetNameBasedAttributes(
newAttributes, createNewAttributes,
newAttributes->getRenderAssetHandle(), [newAttributes](auto&& PH1) {
newAttributes->initRenderAssetType(std::forward<decltype(PH1)>(PH1));
newAttributes->initRenderAssetTypeEnum(
std::forward<decltype(PH1)>(PH1));
});
// set defaults for passed collision asset handles
StageAttributesManager::setDefaultAssetNameBasedAttributes(
newAttributes, false, newAttributes->getCollisionAssetHandle(),
[newAttributes](auto&& PH1) {
newAttributes->initCollisionAssetType(
newAttributes->initCollisionAssetTypeEnum(
std::forward<decltype(PH1)>(PH1));
});

// set defaults for passed semantic asset handles
StageAttributesManager::setDefaultAssetNameBasedAttributes(
newAttributes, false, newAttributes->getSemanticAssetHandle(),
[newAttributes](auto&& PH1) {
newAttributes->initSemanticAssetType(
newAttributes->initSemanticAssetTypeEnum(
std::forward<decltype(PH1)>(PH1));
});
// TODO : get rid of this once the hardcoded mesh-type handling is removed,
Expand All @@ -327,7 +328,7 @@ void StageAttributesManager::setDefaultAssetNameBasedAttributes(
StageAttributes::ptr attributes,
bool setFrame,
const std::string& fileName,
const std::function<void(const std::string&)>& assetTypeSetter) {
const std::function<void(AssetType)>& assetTypeSetter) {
// TODO : support future mesh-name specific type setting?
using Corrade::Utility::String::endsWith;

Expand All @@ -339,18 +340,18 @@ void StageAttributesManager::setDefaultAssetNameBasedAttributes(
up = up1;
fwd = fwd1;
if (endsWith(fileName, "_semantic.ply")) {
assetTypeSetter(getAssetTypeName(AssetType::InstanceMesh));
assetTypeSetter(AssetType::InstanceMesh);
} else if (endsWith(fileName, ".glb")) {
// assumes MP3D glb with gravity = -Z
assetTypeSetter(getAssetTypeName(AssetType::Mp3dMesh));
assetTypeSetter(AssetType::Mp3dMesh);
// Create a coordinate for the mesh by rotating the default ESP
// coordinate frame to -Z gravity
up = up2;
fwd = fwd2;
} else if (StageAttributesManager::isValidPrimitiveAttributes(fileName)) {
assetTypeSetter(getAssetTypeName(AssetType::Primitive));
assetTypeSetter(AssetType::Primitive);
} else {
assetTypeSetter(getAssetTypeName(AssetType::Unknown));
assetTypeSetter(AssetType::Unknown);
}
if (setFrame) {
attributes->init("up", up);
Expand Down Expand Up @@ -411,7 +412,8 @@ void StageAttributesManager::setValsFromJSONDoc(
semanticFName = this->setJSONAssetHandleAndType(
stageAttributes, jsonConfig, "semantic_asset_type", "semantic_asset",
semanticFName, [stageAttributes](auto&& PH1) {
stageAttributes->setSemanticAssetType(std::forward<decltype(PH1)>(PH1));
stageAttributes->setSemanticAssetTypeEnum(
std::forward<decltype(PH1)>(PH1));
});
// if "semantic mesh" is specified in stage json to non-empty value, set
// value (override default).
Expand Down
2 changes: 1 addition & 1 deletion src/esp/metadata/managers/StageAttributesManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class StageAttributesManager
attributes::StageAttributes::ptr attributes,
bool setFrame,
const std::string& meshHandle,
const std::function<void(const std::string&)>& assetTypeSetter) override;
const std::function<void(AssetType)>& assetTypeSetter) override;
/**
* @brief Used Internally. Create and configure newly-created attributes with
* any default values, before any specific values are set.
Expand Down

0 comments on commit 7cbf717

Please sign in to comment.