Skip to content

Commit ca1494b

Browse files
authored
--[BUGFIX] - Properly set instance user config from base passed base 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.
1 parent 8961cb0 commit ca1494b

File tree

3 files changed

+51
-13
lines changed

3 files changed

+51
-13
lines changed

src/esp/metadata/attributes/SceneInstanceAttributes.cpp

+19-7
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,23 @@ SceneObjectInstanceAttributes::SceneObjectInstanceAttributes(
4545
const std::string& handle,
4646
const std::shared_ptr<AbstractObjectAttributes>& baseObjAttribs)
4747
: SceneObjectInstanceAttributes(handle) {
48+
// This constructor is for internally generated SceneObjectInstanceAttributes,
49+
// to correspond to an object that is being created programmatically and saved
50+
// to a scene instance.
51+
// Handle is set via init in base class, which would not be written out to
52+
// file if we did not explicitly set it.
53+
setHandle(handle);
4854
// set appropriate fields from abstract object attributes
4955
// Not initialize, since these are not default values
5056
set("shader_type", getShaderTypeName(baseObjAttribs->getShaderType()));
5157
// set to match attributes setting
5258
set("is_instance_visible", (baseObjAttribs->getIsVisible() ? 1 : 0));
59+
5360
// set nonuniform scale to match attributes scale
5461
setNonUniformScale(baseObjAttribs->getScale());
5562
// Prepopulate user config to match baseObjAttribs' user config.
56-
overwriteWithConfig(baseObjAttribs->getUserConfiguration());
63+
editUserConfiguration()->overwriteWithConfig(
64+
baseObjAttribs->getUserConfiguration());
5765
}
5866

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

187199
// Should not initialize these values but set them, since these are not
188200
// default values, but from an existing AO attributes.
@@ -197,10 +209,10 @@ SceneAOInstanceAttributes::SceneAOInstanceAttributes(
197209
setLinkOrder(getAOLinkOrderName(aObjAttribs->getLinkOrder()));
198210
// Set render mode to use aObjAttribs value
199211
setRenderMode(getAORenderModeName(aObjAttribs->getRenderMode()));
200-
// set appropriate values to match values in aObjAttribs
201-
setMassScale(aObjAttribs->getMassScale());
212+
202213
// Prepopulate user config to match attribs' user config.
203-
overwriteWithConfig(aObjAttribs->getUserConfiguration());
214+
editUserConfiguration()->overwriteWithConfig(
215+
aObjAttribs->getUserConfiguration());
204216
editSubconfig<Configuration>("initial_joint_pose");
205217
editSubconfig<Configuration>("initial_joint_velocities");
206218
}

src/esp/metadata/attributes/SceneInstanceAttributes.h

+18
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,24 @@ class SceneObjectInstanceAttributes : public AbstractAttributes {
225225
void writeValuesToJson(io::JsonGenericValue& jsonObj,
226226
io::JsonAllocator& allocator) const override;
227227

228+
/**
229+
* @brief Retrieve a comma-separated string holding the header values for the
230+
* info returned for this managed object.
231+
*/
232+
std::string getObjectInfoHeader() const override {
233+
return Cr::Utility::formatString("Template Name, ID, {}",
234+
getObjectInfoHeaderInternal());
235+
}
236+
237+
/**
238+
* @brief Retrieve a comma-separated informational string about the contents
239+
* of this managed object.
240+
*/
241+
std::string getObjectInfo() const override {
242+
return Cr::Utility::formatString(
243+
"{},{},{}", getHandle(), getAsString("__ID"), getObjectInfoInternal());
244+
}
245+
228246
protected:
229247
friend class esp::metadata::managers::SceneInstanceAttributesManager;
230248
/**

src/esp/physics/PhysicsManager.cpp

+14-6
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,14 @@ int PhysicsManager::addObjectAndSaveAttributes(
202202
}
203203

204204
if (objInstAttributes == nullptr) {
205-
// Create objInstAttributes and populate with start values from
206-
objInstAttributes = resourceManager_.getSceneInstanceAttributesManager()
207-
->createEmptyInstanceAttributes(
208-
objAttributes->getHandle(), objAttributes);
205+
// Create objInstAttributes and populate with start values from config
206+
// attributes.
207+
// Use simplified handle to reference attributes
208+
// TODO : probably need something more specific eventually
209+
objInstAttributes =
210+
resourceManager_.getSceneInstanceAttributesManager()
211+
->createEmptyInstanceAttributes(
212+
objAttributes->getSimplifiedHandle(), objAttributes);
209213
}
210214

211215
// create and add object using provided object attributes
@@ -528,10 +532,14 @@ int PhysicsManager::addArticulatedObjectAndSaveAttributes(
528532
return ID_UNDEFINED;
529533
}
530534
if (aObjInstAttributes == nullptr) {
535+
// Create aObjInstAttributes and populate with start values from config
536+
// attributes.
537+
// Use simplified handle to reference attributes
538+
// TODO : probably need something more specific eventually
531539
aObjInstAttributes =
532540
resourceManager_.getSceneInstanceAttributesManager()
533-
->createEmptyAOInstanceAttributes(artObjAttributes->getHandle(),
534-
artObjAttributes);
541+
->createEmptyAOInstanceAttributes(
542+
artObjAttributes->getSimplifiedHandle(), artObjAttributes);
535543
// TODO do we need to save this to curSceneInstanceAttributes responsible
536544
// for this scene?
537545
}

0 commit comments

Comments
 (0)