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

--Add Configuration State Flags - Part 2 (Hidden file path fields) #2398

Merged
merged 14 commits into from
May 23, 2024
Merged
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
38 changes: 19 additions & 19 deletions src/esp/assets/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ bool ResourceManager::loadSemanticScene(
semanticAttr,
const std::string& activeSceneName) {
const std::string ssdFilename =
semanticAttr != nullptr ? semanticAttr->getSemanticDescriptorFilename()
semanticAttr != nullptr ? semanticAttr->getSemanticDescriptorFullPath()
: "";
semanticScene_ = nullptr;
if ((ssdFilename != "") || ((semanticAttr != nullptr) &&
Expand Down Expand Up @@ -600,11 +600,11 @@ ResourceManager::createStageAssetInfosFromAttributes(
// create render asset info
AssetType renderType = stageAttributes->getRenderAssetType();
AssetInfo renderInfo{
renderType, // type
stageAttributes->getRenderAssetHandle(), // file path
frame, // frame
virtualUnitToMeters, // virtualUnitToMeters
stageAttributes->getForceFlatShading() // forceFlatShading
renderType, // type
stageAttributes->getRenderAssetFullPath(), // file path
frame, // frame
virtualUnitToMeters, // virtualUnitToMeters
stageAttributes->getForceFlatShading() // forceFlatShading
};
renderInfo.shaderTypeToUse = stageAttributes->getShaderType();
std::string debugStr{};
Expand All @@ -619,11 +619,11 @@ ResourceManager::createStageAssetInfosFromAttributes(
// create collision asset info if requested
AssetType colType = stageAttributes->getCollisionAssetType();
AssetInfo collisionInfo{
colType, // type
stageAttributes->getCollisionAssetHandle(), // file path
frame, // frame
virtualUnitToMeters, // virtualUnitToMeters
true // forceFlatShading
colType, // type
stageAttributes->getCollisionAssetFullPath(), // file path
frame, // frame
virtualUnitToMeters, // virtualUnitToMeters
true // forceFlatShading
};
// Only construct debug string if debug logging level is enabled
if (ESP_LOG_LEVEL_ENABLED(logging::LoggingLevel::Debug)) {
Expand All @@ -647,11 +647,11 @@ ResourceManager::createStageAssetInfosFromAttributes(
stageAttributes->getOrigin());
}
AssetInfo semanticInfo{
semanticType, // type
stageAttributes->getSemanticAssetHandle(), // file path
frame, // frame
virtualUnitToMeters, // virtualUnitToMeters
true, // forceFlatShading
semanticType, // type
stageAttributes->getSemanticAssetFullPath(), // file path
frame, // frame
virtualUnitToMeters, // virtualUnitToMeters
true, // forceFlatShading
// only split semantic mesh if doing frustum culling
stageAttributes->getFrustumCulling() // splitInstanceMesh
};
Expand Down Expand Up @@ -2896,7 +2896,7 @@ bool ResourceManager::instantiateAssetsOnDemand(
}

// get render asset handle
std::string renderAssetHandle = objectAttributes->getRenderAssetHandle();
std::string renderAssetHandle = objectAttributes->getRenderAssetFullPath();
// whether attributes requires lighting
bool forceFlatShading = objectAttributes->getForceFlatShading();
bool renderMeshSuccess = false;
Expand Down Expand Up @@ -2930,7 +2930,7 @@ bool ResourceManager::instantiateAssetsOnDemand(
// Probably just need to check attr->isCollidable()
if (!objectAttributes->getCollisionAssetIsPrimitive()) {
const auto collisionAssetHandle =
objectAttributes->getCollisionAssetHandle();
objectAttributes->getCollisionAssetFullPath();
if (resourceDict_.count(collisionAssetHandle) == 0) {
bool collisionMeshSuccess = loadObjectMeshDataFromFile(
collisionAssetHandle, objectAttributes, "collision",
Expand Down Expand Up @@ -3022,7 +3022,7 @@ void ResourceManager::addObjectToDrawables(
//! Add mesh to rendering stack

const std::string& renderObjectName =
ObjectAttributes->getRenderAssetHandle();
ObjectAttributes->getRenderAssetFullPath();

RenderAssetInstanceCreationInfo::Flags flags;
flags |= RenderAssetInstanceCreationInfo::Flag::IsRGBD;
Expand Down
33 changes: 33 additions & 0 deletions src/esp/bindings/AttributesBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,12 +452,23 @@ void initAttributesBindings(py::module& m) {
&ArticulatedObjectAttributes::setURDFPath,
R"(Relative filepath of the URDF file used to create the Articulated Object
described by this template.)")
.def_property_readonly(
"urdf_fullpath", &ArticulatedObjectAttributes::getURDFFullPath,
R"(Fully qualified filepath of the URDF file used to create the Articulated Object
described by this template. This filepath will only be available/accurate
after the owning attributes is registered)")
.def_property(
"render_asset_handle",
&ArticulatedObjectAttributes::getRenderAssetHandle,
&ArticulatedObjectAttributes::setRenderAssetHandle,
R"(Handle of the asset used to render constructions built from
this articulated object template.)")
.def_property_readonly(
"render_asset_fullpath",
&ArticulatedObjectAttributes::getRenderAssetFullPath,
R"(Fully qualified filepath of the asset used to render constructions built from
this template. This filepath will only be available/accurate
after the owning attributes is registered)")
.def_property(
"semantic_id", &ArticulatedObjectAttributes::getSemanticId,
&ArticulatedObjectAttributes::setSemanticId,
Expand Down Expand Up @@ -572,6 +583,18 @@ void initAttributesBindings(py::module& m) {
&AbstractObjectAttributes::setCollisionAssetHandle,
R"(Handle of the asset used to calculate collsions for constructions
built from this template.)")
.def_property_readonly(
"render_asset_fullpath",
&AbstractObjectAttributes::getRenderAssetFullPath,
R"(Fully qualified filepath of the asset used to render constructions built from
this template. This filepath will only be available/accurate
after the owning attributes is registered)")
.def_property_readonly(
"collision_asset_fullpath",
&AbstractObjectAttributes::getCollisionAssetFullPath,
R"(Fully qualified filepath of the asset used to calculate collsions for constructions
built from this template. This filepath will only be available/accurate
after the owning attributes is registered)")
.def_property(
"shader_type", &AbstractObjectAttributes::getShaderType,
&AbstractObjectAttributes::setShaderType,
Expand Down Expand Up @@ -691,6 +714,11 @@ void initAttributesBindings(py::module& m) {
&StageAttributes::setSemanticAssetHandle,
R"(Handle of the asset used for semantic segmentation of stages
built from this template.)")
.def_property_readonly(
"semantic_asset_fullpath", &StageAttributes::getSemanticAssetFullPath,
R"(Fully qualified filepath of the asset used for semantic segmentation of stages
built from this template. This filepath will only be available/accurate after
the owning attributes is registered)")
.def_property_readonly(
"semantic_asset_type", &StageAttributes::getSemanticAssetType,
R"(Type of asset used for collision calculations for constructions
Expand All @@ -705,6 +733,11 @@ void initAttributesBindings(py::module& m) {
&StageAttributes::setSemanticDescriptorFilename,
R"(Handle for file containing semantic type maps and hierarchy for
constructions built from this template.)")
.def_property_readonly(
"house_fq_filename", &StageAttributes::getSemanticDescriptorFullPath,
R"(Fully qualified path of file containing semantic type maps and hierarchy for
constructions built from this template. This filepath will only be available/accurate
after the owning attributes is registered)")
.def_property(
"frustum_culling", &StageAttributes::getFrustumCulling,
&StageAttributes::setFrustumCulling,
Expand Down
9 changes: 7 additions & 2 deletions src/esp/bindings/AttributesManagersBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,7 @@ void declareBaseAttributesManager(py::module& m,
&MgrClass::getFirstMatchingObjectOrCopyByHandle),
("This returns a copy of the first " + attrType +
" template containing the passed handle substring if any exist, "
"and NULL "
"if none could be found.")
"and NULL if none could be found.")
.c_str(),
"handle_substr"_a)
.def("get_templates_by_handle_substring",
Expand All @@ -258,6 +257,12 @@ void declareBaseAttributesManager(py::module& m,
"on the value of boolean contains.")
.c_str(),
"search_str"_a = "", "contains"_a = true)
.def("filter_filepaths", &MgrClass::finalizeAttrPathsBeforeRegister,
("This attempts to filter any filenames in the passed " + attrType +
" template so that the fields that would be saved to file would "
"only contain relative paths.")
.c_str(),
"attributes"_a)
.def("save_template_by_handle",
static_cast<bool (MgrClass::*)(const std::string&, bool) const>(
&MgrClass::saveManagedObjectToFile),
Expand Down
6 changes: 3 additions & 3 deletions src/esp/metadata/MetadataMediator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ MetadataMediator::makeSceneAndReferenceStage(
// by the ref that the scene attributes will use.
std::pair<std::string, std::string> navmeshEntry =
datasetAttr->addNavmeshPathEntry(
sceneName, stageAttributes->getNavmeshAssetHandle(), false);
sceneName, stageAttributes->getNavmeshAssetFullPath(), false);
// navmeshEntry holds the navmesh key-value in the dataset to use by this
// scene instance. NOTE : the key may have changed from what was passed if a
// collision occurred with same key but different value, so we need to add
Expand All @@ -528,8 +528,8 @@ MetadataMediator::makeSceneAndReferenceStage(
// add a ref to scene instance attributes of SemanticAttributes if any
// Semantics info is specified in the passed stage stage, giving it an
// appropriately obvious name.
if ((stageAttributes->getSemanticDescriptorFilename() != "") ||
(stageAttributes->getSemanticAssetHandle() != "")) {
if ((stageAttributes->getSemanticDescriptorFullPath() != "") ||
(stageAttributes->getSemanticAssetFullPath() != "")) {
std::string sceneSemanticAttrHandle =
datasetAttr->addSemanticSceneDescrPathEntry(sceneName, stageAttributes);

Expand Down
4 changes: 3 additions & 1 deletion src/esp/metadata/attributes/AbstractObjectAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ AbstractObjectAttributes::AbstractObjectAttributes(
init("units_to_meters", 1.0);
init("render_asset", "");
init("collision_asset", "");

// initialize these so they exist in Configuration
setHidden("__renderAssetFullPath", "");
setHidden("__collisionAssetFullPath", "");
// This specifies that we want to investigate the state of the render and
// collision handles before we allow this attributes to be registered.
// Hidden field
Expand Down
36 changes: 36 additions & 0 deletions src/esp/metadata/attributes/AbstractObjectAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,25 @@ class AbstractObjectAttributes : public AbstractAttributes {
return get<std::string>("render_asset");
}

/**
* @brief Sets the fully-qualified filepath for the render asset to be used to
* render the construct this attributes describes. This is only used
* internally and should not be saved to disk.
*/
void setRenderAssetFullPath(const std::string& renderAssetHandle) {
setHidden("__renderAssetFullPath", renderAssetHandle);
setIsDirty();
}

/**
* @brief Gets the fully-qualified filepath for the render asset to be used to
* render the construct this attributes describes. This is only used
* internally and should not be saved to disk.
*/
std::string getRenderAssetFullPath() const {
return get<std::string>("__renderAssetFullPath");
}

/**
* @brief Sets the render asset type, as specified by @ref AssetType.
* This specification was generally intended for specifying certain criteria
Expand Down Expand Up @@ -265,7 +284,24 @@ class AbstractObjectAttributes : public AbstractAttributes {
std::string getCollisionAssetHandle() const {
return get<std::string>("collision_asset");
}
/**
* @brief Sets the fully-qualified filepath for the collision asset to be used
* for mesh collision detection for the construct this attributes describes.
* This is only used internally and should not be saved to disk.
*/
void setCollisionAssetFullPath(const std::string& collisionAssetHandle) {
setHidden("__collisionAssetFullPath", collisionAssetHandle);
setIsDirty();
}

/**
* @brief Gets the fully-qualified filepath for the collision asset to be used
* for mesh collision detection for the construct this attributes describes.
* This is only used internally and should not be saved to disk.
*/
std::string getCollisionAssetFullPath() const {
return get<std::string>("__collisionAssetFullPath");
}
/**
* @brief Sets the collision asset type, as specified by @ref AssetType.
* This specification was generally intended for specifying certain criteria
Expand Down
5 changes: 5 additions & 0 deletions src/esp/metadata/attributes/ArticulatedObjectAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ ArticulatedObjectAttributes::ArticulatedObjectAttributes(

init("uniform_scale", 1.0f);
init("mass_scale", 1.0);

// Initialize these so they exist in the configuration
setHidden("__urdfFullPath", "");
setHidden("__renderAssetFullPath", "");

// set up an existing subgroup for marker_sets attributes
addOrEditSubgroup<MarkerSets>("marker_sets");
} // ArticulatedObjectAttributes ctor
Expand Down
37 changes: 37 additions & 0 deletions src/esp/metadata/attributes/ArticulatedObjectAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ class ArticulatedObjectAttributes : public AbstractAttributes {
* @brief Gets the string name for the Articulated Object URDF relative path
*/
std::string getURDFPath() const { return get<std::string>("urdf_filepath"); }

/**
* @brief Sets the fully-qualified filepath for for the Articulated Object
* URDF to be used to create the articulated object this attributes describes.
* This is only used internally and should not be saved to disk.
*/
void setURDFFullPath(const std::string& urdfFilepath) {
setHidden("__urdfFullPath", urdfFilepath);
}

/**
* @brief Gets the fully-qualified filepath for for the Articulated Object
* URDF to be used to create the articulated object this attributes describes.
* This is only used internally and should not be saved to disk.
*/
std::string getURDFFullPath() const {
return get<std::string>("__urdfFullPath");
}

/**
* @brief Sets the string name for the render asset relative path
*/
Expand All @@ -42,6 +61,24 @@ class ArticulatedObjectAttributes : public AbstractAttributes {
return get<std::string>("render_asset");
}

/**
* @brief Sets the fully-qualified filepath for the render asset to be used to
* render the construct this attributes describes. This is only used
* internally and should not be saved to disk.
*/
void setRenderAssetFullPath(const std::string& renderAssetHandle) {
setHidden("__renderAssetFullPath", renderAssetHandle);
}

/**
* @brief Gets the fully-qualified filepath for the render asset to be used to
* render the construct this attributes describes. This is only used
* internally and should not be saved to disk.
*/
std::string getRenderAssetFullPath() const {
return get<std::string>("__renderAssetFullPath");
}

/**
* @brief Set uniform scaling of the articulated object.
*/
Expand Down
22 changes: 16 additions & 6 deletions src/esp/metadata/attributes/SceneDatasetAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,12 @@ void SceneDatasetAttributes::createSemanticAttribsFromDS(
std::string SceneDatasetAttributes::addSemanticSceneDescrPathEntry(
const std::string& semanticHandle,
const attributes::StageAttributes::ptr& stageAttributes) {
const auto ssdFilename = stageAttributes->getSemanticDescriptorFilename();
const auto semanticAssetFilename = stageAttributes->getSemanticAssetHandle();
bool setSemanticAssetData = (semanticAssetFilename != "");
bool setSSDFilename = (ssdFilename != "");
const auto stageSSDFilename =
stageAttributes->getSemanticDescriptorFilename();
const auto stageSemanticAssetFilename =
stageAttributes->getSemanticAssetHandle();
bool setSemanticAssetData = (stageSemanticAssetFilename != "");
bool setSSDFilename = (stageSSDFilename != "");
// create a semantic attributes if DNE with given handle
this->createSemanticAttribsFromDS(semanticHandle, "Stage Attributes");

Expand All @@ -166,7 +168,9 @@ std::string SceneDatasetAttributes::addSemanticSceneDescrPathEntry(

if (setSemanticAssetData && semanticAttr->getSemanticAssetHandle().empty()) {
// asset handle specified, get all stage-specified data
semanticAttr->setSemanticAssetHandle(semanticAssetFilename);
semanticAttr->setSemanticAssetHandle(stageSemanticAssetFilename);
semanticAttr->setSemanticAssetFullPath(
stageAttributes->getSemanticAssetFullPath());
semanticAttr->setSemanticAssetTypeEnum(
stageAttributes->getSemanticAssetType());
semanticAttr->setSemanticOrientUp(stageAttributes->getSemanticOrientUp());
Expand All @@ -176,8 +180,12 @@ std::string SceneDatasetAttributes::addSemanticSceneDescrPathEntry(
if (setSSDFilename && semanticAttr->getSemanticDescriptorFilename().empty()) {
// scene descriptor filename specified in stage, set in semantic
// attributes.
semanticAttr->setSemanticDescriptorFilename(ssdFilename);
semanticAttr->setSemanticDescriptorFilename(stageSSDFilename);
semanticAttr->setSemanticDescriptorFullPath(
stageAttributes->getSemanticDescriptorFullPath());
}
// Save changes and make sure appropriate filtering happens
semanticAttributesManager_->registerObject(semanticAttr, semanticHandle);
return semanticAttr->getHandle();
} // SceneDatasetAttributes::addSemanticSceneDescrPathEntry

Expand All @@ -194,6 +202,8 @@ void SceneDatasetAttributes::setSemanticAttrSSDFilenames(
auto semanticAttr =
semanticAttributesManager_->getObjectByHandle(semanticHandle);
semanticAttr->setSemanticDescriptorFilename(ssdFilename);
// Save changes and make sure appropriate filtering happens
semanticAttributesManager_->registerObject(semanticAttr, semanticHandle);
}

} // SceneDatasetAttributes::setSemanticAttrSSDFilenames
Expand Down
5 changes: 4 additions & 1 deletion src/esp/metadata/attributes/SemanticAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ void SemanticVolumeAttributes::writeValuesToJson(
// SemanticAttributes
SemanticAttributes::SemanticAttributes(const std::string& handle)
: AbstractAttributes("SemanticAttributes", handle) {
// set empty defaults for handles
init("semantic_descriptor_filename", "");
setHidden("__semanticDescriptorFullPath", "");
init("semantic_asset", "");
setHidden("__semanticAssetFullPath", "");
init("semantic_up", Mn::Vector3{0.0, 1.0, 0.0});
init("semantic_front", Mn::Vector3{0.0, 0.0, -1.0});
init("use_semantic_frame", false);
Expand Down Expand Up @@ -178,7 +181,7 @@ std::string SemanticAttributes::getObjectInfoInternal() const {
// std::string res = "";
// TODO do this for any SemanticAttributes level values
std::string res = Cr::Utility::formatString(
"\nSemantic Scene Descriptor Filename,Semantic Mesh Assset,\n{},{}\n",
"\nSemantic Scene Descriptor Filename,Semantic Mesh Asset,\n{},{}\n",
getSemanticDescriptorFilename(), getSemanticAssetHandle());

int iter = 0;
Expand Down
Loading