Skip to content

Commit

Permalink
--[BUGFIX] - Properly set instance user config from base passed base …
Browse files Browse the repository at this point in the history
…config. (#2407)

* --properly set instance user config from base passed base config.
* --fix handle (template name) not being saved to scene obj/ao instance json
* --use simplified handle to avoid embedding paths in template names
In the future we may need to revisit this naming decision to be more robust.
  • Loading branch information
jturner65 authored Jun 13, 2024
1 parent 8961cb0 commit ca1494b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
26 changes: 19 additions & 7 deletions src/esp/metadata/attributes/SceneInstanceAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,23 @@ SceneObjectInstanceAttributes::SceneObjectInstanceAttributes(
const std::string& handle,
const std::shared_ptr<AbstractObjectAttributes>& baseObjAttribs)
: SceneObjectInstanceAttributes(handle) {
// This constructor is for internally generated SceneObjectInstanceAttributes,
// to correspond to an object that is being created programmatically and saved
// to a scene instance.
// Handle is set via init in base class, which would not be written out to
// file if we did not explicitly set it.
setHandle(handle);
// set appropriate fields from abstract object attributes
// Not initialize, since these are not default values
set("shader_type", getShaderTypeName(baseObjAttribs->getShaderType()));
// set to match attributes setting
set("is_instance_visible", (baseObjAttribs->getIsVisible() ? 1 : 0));

// set nonuniform scale to match attributes scale
setNonUniformScale(baseObjAttribs->getScale());
// Prepopulate user config to match baseObjAttribs' user config.
overwriteWithConfig(baseObjAttribs->getUserConfiguration());
editUserConfiguration()->overwriteWithConfig(
baseObjAttribs->getUserConfiguration());
}

std::string SceneObjectInstanceAttributes::getObjectInfoHeaderInternal() const {
Expand Down Expand Up @@ -180,9 +188,13 @@ SceneAOInstanceAttributes::SceneAOInstanceAttributes(const std::string& handle)
SceneAOInstanceAttributes::SceneAOInstanceAttributes(
const std::string& handle,
const std::shared_ptr<ArticulatedObjectAttributes>& aObjAttribs)
: SceneObjectInstanceAttributes(handle, "SceneAOInstanceAttributes") {
// initialize default auto clamp values (only used for articulated object)
init("auto_clamp_joint_limits", false);
: SceneAOInstanceAttributes(handle) {
// This constructor is for internally generated SceneAOInstanceAttributes, to
// correspond to an object that is being created programmatically and saved to
// a scene instance.
// Handle is set via init in base class, which would not be written out to
// file if we did not explicitly set it.
setHandle(handle);

// Should not initialize these values but set them, since these are not
// default values, but from an existing AO attributes.
Expand All @@ -197,10 +209,10 @@ SceneAOInstanceAttributes::SceneAOInstanceAttributes(
setLinkOrder(getAOLinkOrderName(aObjAttribs->getLinkOrder()));
// Set render mode to use aObjAttribs value
setRenderMode(getAORenderModeName(aObjAttribs->getRenderMode()));
// set appropriate values to match values in aObjAttribs
setMassScale(aObjAttribs->getMassScale());

// Prepopulate user config to match attribs' user config.
overwriteWithConfig(aObjAttribs->getUserConfiguration());
editUserConfiguration()->overwriteWithConfig(
aObjAttribs->getUserConfiguration());
editSubconfig<Configuration>("initial_joint_pose");
editSubconfig<Configuration>("initial_joint_velocities");
}
Expand Down
18 changes: 18 additions & 0 deletions src/esp/metadata/attributes/SceneInstanceAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,24 @@ class SceneObjectInstanceAttributes : public AbstractAttributes {
void writeValuesToJson(io::JsonGenericValue& jsonObj,
io::JsonAllocator& allocator) const override;

/**
* @brief Retrieve a comma-separated string holding the header values for the
* info returned for this managed object.
*/
std::string getObjectInfoHeader() const override {
return Cr::Utility::formatString("Template Name, ID, {}",
getObjectInfoHeaderInternal());
}

/**
* @brief Retrieve a comma-separated informational string about the contents
* of this managed object.
*/
std::string getObjectInfo() const override {
return Cr::Utility::formatString(
"{},{},{}", getHandle(), getAsString("__ID"), getObjectInfoInternal());
}

protected:
friend class esp::metadata::managers::SceneInstanceAttributesManager;
/**
Expand Down
20 changes: 14 additions & 6 deletions src/esp/physics/PhysicsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,14 @@ int PhysicsManager::addObjectAndSaveAttributes(
}

if (objInstAttributes == nullptr) {
// Create objInstAttributes and populate with start values from
objInstAttributes = resourceManager_.getSceneInstanceAttributesManager()
->createEmptyInstanceAttributes(
objAttributes->getHandle(), objAttributes);
// Create objInstAttributes and populate with start values from config
// attributes.
// Use simplified handle to reference attributes
// TODO : probably need something more specific eventually
objInstAttributes =
resourceManager_.getSceneInstanceAttributesManager()
->createEmptyInstanceAttributes(
objAttributes->getSimplifiedHandle(), objAttributes);
}

// create and add object using provided object attributes
Expand Down Expand Up @@ -528,10 +532,14 @@ int PhysicsManager::addArticulatedObjectAndSaveAttributes(
return ID_UNDEFINED;
}
if (aObjInstAttributes == nullptr) {
// Create aObjInstAttributes and populate with start values from config
// attributes.
// Use simplified handle to reference attributes
// TODO : probably need something more specific eventually
aObjInstAttributes =
resourceManager_.getSceneInstanceAttributesManager()
->createEmptyAOInstanceAttributes(artObjAttributes->getHandle(),
artObjAttributes);
->createEmptyAOInstanceAttributes(
artObjAttributes->getSimplifiedHandle(), artObjAttributes);
// TODO do we need to save this to curSceneInstanceAttributes responsible
// for this scene?
}
Expand Down

0 comments on commit ca1494b

Please sign in to comment.