Skip to content

Commit e4f5610

Browse files
committed
--Convert AO scale to vector;
1 parent d858741 commit e4f5610

19 files changed

+98
-78
lines changed

docs/pages/attributesJSON.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,9 @@ Below are the handles and descriptors for the source URDF file and the render as
370370
Articulated Object Configuration And Rendering
371371
----------------------------------------------
372372

373-
"uniform_scale"
374-
- double
375-
- The uniform scaling to apply to this articulated object after load (defaults to 1.0). This is modifiable by the scene instance specification.
373+
"scale"
374+
- 3-vector
375+
- The scaling to apply to this articulated object after load (defaults to [1.0,1.0,1.0]). This is modifiable by the scene instance specification.
376376
"mass_scale"
377377
- double
378378
- The amount the mass of the articulated object should be scaled upon load (defaults to 1.0). This is modifiable by the scene instance specification.

src/esp/bindings/PhysicsObjectBindings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ void declareArticulatedObjectWrapper(py::module& m,
443443
.c_str())
444444
.def_property_readonly(
445445
"global_scale", &ManagedArticulatedObject::getGlobalScale,
446-
R"(The uniform global scaling applied to this object during import.)")
446+
R"(The global scaling vector applied to this object during import.)")
447447
.def("get_link_scene_node", &ManagedArticulatedObject::getLinkSceneNode,
448448
("Get the scene node for this " + objType +
449449
"'s articulated link specified by the passed "

src/esp/metadata/URDFParser.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,17 @@ namespace esp {
2929
namespace metadata {
3030
namespace URDF {
3131

32-
void Model::scaleShape(Shape& shape, float scale) {
32+
void Model::scaleShape(Shape& shape, const Mn::Vector3& scale) {
3333
shape.m_linkLocalFrame.translation() *= scale;
3434
switch (shape.m_geometry.m_type) {
35+
case GEOM_SPHERE:
3536
case GEOM_MESH: {
3637
shape.m_geometry.m_meshScale *= scale;
3738
} break;
3839
case GEOM_BOX: {
3940
shape.m_geometry.m_boxSize *= scale;
4041
} break;
41-
case GEOM_SPHERE: {
42-
shape.m_geometry.m_sphereRadius *= double(scale);
43-
} break;
42+
4443
case GEOM_CAPSULE:
4544
case GEOM_CYLINDER: {
4645
shape.m_geometry.m_capsuleRadius *= double(scale);
@@ -51,14 +50,14 @@ void Model::scaleShape(Shape& shape, float scale) {
5150
}
5251
}
5352

54-
void Model::setGlobalScaling(float scaling) {
53+
void Model::setGlobalScaling(const Mn::Vector3& scaling) {
5554
if (scaling == m_globalScaling) {
5655
// do nothing
5756
return;
5857
}
5958

6059
// Need to re-scale model, so use the ratio of new to current scale
61-
float scaleCorrection = scaling / m_globalScaling;
60+
auto scaleCorrection = scaling / m_globalScaling;
6261

6362
// scale all transforms' translations
6463
for (const auto& link : m_links) {
@@ -453,7 +452,7 @@ bool Parser::parseLink(const std::shared_ptr<Model>& model,
453452
ESP_VERY_VERBOSE() << link.m_name;
454453
return false;
455454
}
456-
link.m_inertia.m_mass *= model->getGlobalScaling();
455+
link.m_inertia.m_mass *= model->getGlobalScaling().product();
457456
} else {
458457
if ((strlen(linkName) == 5) && (strncmp(linkName, "world", 5)) == 0) {
459458
link.m_inertia.m_mass = 0.f;

src/esp/metadata/URDFParser.h

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -345,12 +345,12 @@ class Model {
345345
* @brief Set global scaling and re-scale an existing model. Modifies various
346346
* internal parameters.
347347
*
348-
* @param scaling The new absolute uniform scale.
348+
* @param scaling The new absolute scale.
349349
*/
350-
void setGlobalScaling(float scaling);
350+
void setGlobalScaling(const Mn::Vector3& scaling);
351351

352352
//! Get the currently configured global model scaling
353-
float getGlobalScaling() const { return m_globalScaling; }
353+
Mn::Vector3 getGlobalScaling() const { return m_globalScaling; }
354354

355355
/**
356356
* @brief Set scaling for mass from initial values configured in URDF.
@@ -369,23 +369,28 @@ class Model {
369369
// scaling values which can be applied to the model after parsing
370370
//! Global euclidean scaling applied to the model's transforms, asset scales,
371371
//! and prismatic joint limits. Does not affect mass.
372-
float m_globalScaling = 1.0;
372+
Mn::Vector3 m_globalScaling = Mn::Vector3(1.0);
373373

374374
//! Mass scaling of the model's Link inertias.
375375
float m_massScaling = 1.0;
376376

377377
//! Scale the transformation and parameters of a Shape
378-
void scaleShape(Shape& shape, float scale);
378+
void scaleShape(Shape& shape, const Mn::Vector3& scale);
379379
}; // class model
380380

381381
/**
382382
* @brief Functional class for parsing URDF files into a URDF::Model
383383
* representation.
384384
*/
385385
class Parser {
386-
// URDF file path of last load call
387-
std::string sourceFilePath_;
386+
public:
387+
Parser() = default;
388388

389+
// parse a loaded URDF string into relevant general data structures
390+
// return false if the string is not a valid urdf or other error causes abort
391+
bool parseURDF(const std::string& filename, std::shared_ptr<Model>& model);
392+
393+
private:
389394
/**
390395
* @brief Parse a transform into a Matrix4.
391396
*
@@ -522,16 +527,8 @@ class Parser {
522527
*/
523528
bool validateMeshFile(std::string& filename);
524529

525-
public:
526-
Parser() = default;
527-
528-
// parse a loaded URDF string into relevant general data structures
529-
// return false if the string is not a valid urdf or other error causes abort
530-
bool parseURDF(const std::string& filename, std::shared_ptr<Model>& model);
531-
532-
// This is no longer used, instead set the urdf and physics subsystem to
533-
// veryverbose, i.e. export HABITAT_SIM_LOG="urdf,physics=veryverbose" bool
534-
// logMessages = false;
530+
// URDF file path of last load call
531+
std::string sourceFilePath_;
535532
};
536533

537534
} // namespace URDF

src/esp/metadata/attributes/AbstractObjectAttributes.h

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,42 @@ class AbstractObjectAttributes : public AbstractAttributes {
2626
~AbstractObjectAttributes() override = default;
2727

2828
/**
29-
* @brief Scale of the ojbect
29+
* @brief Set the scale of the object
3030
*/
3131
void setScale(const Magnum::Vector3& scale) { set("scale", scale); }
32+
/**
33+
* @brief Get the scale of the object
34+
*/
3235
Magnum::Vector3 getScale() const { return get<Magnum::Vector3>("scale"); }
3336

3437
/**
35-
* @brief collision shape inflation margin
38+
* @brief Set the collision shape inflation margin
3639
*/
3740
void setMargin(double margin) { set("margin", margin); }
41+
/**
42+
* @brief Get the collision shape inflation margin
43+
*/
3844
double getMargin() const { return get<double>("margin"); }
3945

40-
// if object should be checked for collisions - if other objects can collide
41-
// with this object
46+
/**
47+
* @brief Set if object should be checked for collisions - if other objects
48+
* can collide with this object
49+
*/
4250
void setIsCollidable(bool isCollidable) {
4351
set("is_collidable", isCollidable);
4452
}
53+
/**
54+
* @brief Get if object should be checked for collisions - if other objects
55+
* can collide with this object
56+
*/
4557
bool getIsCollidable() const { return get<bool>("is_collidable"); }
4658

4759
/**
4860
* @brief Set default up orientation for object/stage mesh
4961
*/
5062
void setOrientUp(const Magnum::Vector3& orientUp) { set("up", orientUp); }
5163
/**
52-
* @brief get default up orientation for object/stage mesh
64+
* @brief Get default up orientation for object/stage mesh
5365
*/
5466
Magnum::Vector3 getOrientUp() const { return get<Magnum::Vector3>("up"); }
5567
/**
@@ -59,7 +71,7 @@ class AbstractObjectAttributes : public AbstractAttributes {
5971
set("front", orientFront);
6072
}
6173
/**
62-
* @brief get default forward orientation for object/stage mesh
74+
* @brief Get default forward orientation for object/stage mesh
6375
*/
6476
Magnum::Vector3 getOrientFront() const {
6577
return get<Magnum::Vector3>("front");
@@ -572,7 +584,7 @@ class AbstractObjectAttributes : public AbstractAttributes {
572584

573585
std::string getObjectInfoHeaderInternal() const override;
574586
/**
575-
* @brief get AbstractObject specific info header
587+
* @brief Get AbstractObject specific info header
576588
*/
577589
virtual std::string getAbstractObjectInfoHeaderInternal() const {
578590
return "";
@@ -584,7 +596,7 @@ class AbstractObjectAttributes : public AbstractAttributes {
584596
*/
585597
std::string getObjectInfoInternal() const override;
586598
/**
587-
* @brief get AbstractObject specific info for csv string
599+
* @brief Get AbstractObject specific info for csv string
588600
*/
589601
virtual std::string getAbstractObjectInfoInternal() const { return ""; };
590602
void setIsDirty() { setHidden("__isDirty", true); }

src/esp/metadata/attributes/ArticulatedObjectAttributes.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ ArticulatedObjectAttributes::ArticulatedObjectAttributes(
3535
initTranslated("shader_type",
3636
getShaderTypeName(ObjectInstanceShaderType::Material));
3737

38-
init("uniform_scale", 1.0f);
38+
init("scale", Mn::Vector3{1.0, 1.0, 1.0});
3939
init("mass_scale", 1.0);
4040

4141
// Initialize these so they exist in the configuration
@@ -52,8 +52,8 @@ void ArticulatedObjectAttributes::writeValuesToJson(
5252
writeValueToJson("urdf_filepath", jsonObj, allocator);
5353
writeValueToJson("render_asset", jsonObj, allocator);
5454
writeValueToJson("semantic_id", jsonObj, allocator);
55-
if (getUniformScale() != 1.0f) {
56-
writeValueToJson("uniform_scale", jsonObj, allocator);
55+
if (getScale() != Mn::Vector3(1.0, 1.0, 1.0)) {
56+
writeValueToJson("scale", jsonObj, allocator);
5757
}
5858
if (getMassScale() != 1.0) {
5959
writeValueToJson("mass_scale", jsonObj, allocator);
@@ -66,14 +66,14 @@ void ArticulatedObjectAttributes::writeValuesToJson(
6666
} // ArticulatedObjectAttributes::writeValuesToJson
6767

6868
std::string ArticulatedObjectAttributes::getObjectInfoHeaderInternal() const {
69-
return "URDF Filepath,Render Asset,Semantic ID,Uniform Scale,Mass Scale,Base "
69+
return "URDF Filepath,Render Asset,Semantic ID,Scale,Mass Scale,Base "
7070
"Type,Inertia Source,Link Order,Render Mode,Current Shader Type,";
7171
} // ArticulatedObjectAttributes::getObjectInfoHeaderInternal
7272

7373
std::string ArticulatedObjectAttributes::getObjectInfoInternal() const {
7474
return Cr::Utility::formatString(
7575
"{},{},{},{},{},{},{},{},{},{}", getURDFPath(), getRenderAssetHandle(),
76-
getAsString("semantic_id"), getAsString("uniform_scale"),
76+
getAsString("semantic_id"), getAsString("scale"),
7777
getAsString("mass_scale"), getAOBaseTypeName(getBaseType()),
7878
getAOInertiaSourceName(getInertiaSource()),
7979
getAOLinkOrderName(getLinkOrder()), getAORenderModeName(getRenderMode()),

src/esp/metadata/attributes/ArticulatedObjectAttributes.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,13 @@ class ArticulatedObjectAttributes : public AbstractAttributes {
8080
}
8181

8282
/**
83-
* @brief Set uniform scaling of the articulated object.
83+
* @brief Set scaling vector of the articulated object.
8484
*/
85-
void setUniformScale(float scale) { set("uniform_scale", scale); }
85+
void setScale(const Magnum::Vector3& scale) { set("scale", scale); }
8686
/**
87-
* @brief Get uniform scaling of the articulated object.
87+
* @brief Get the scale vector of the articulated object.
8888
*/
89-
float getUniformScale() const {
90-
return static_cast<float>(get<double>("uniform_scale"));
91-
}
89+
Magnum::Vector3 getScale() const { return get<Magnum::Vector3>("scale"); }
9290

9391
/**
9492
* @brief Set mass scaling of the articulated object.

src/esp/metadata/managers/AOAttributesManager.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ void AOAttributesManager::setValsFromJSONDoc(
6161
aoAttr->setSemanticId(semantic_id);
6262
});
6363

64-
// load the uniform scaling
65-
io::jsonIntoSetter<double>(
66-
jsonConfig, "uniform_scale",
67-
[aoAttr](double scale) { aoAttr->setUniformScale(scale); });
64+
// scale
65+
io::jsonIntoConstSetter<Magnum::Vector3>(
66+
jsonConfig, "scale",
67+
[aoAttr](const Magnum::Vector3& scale) { aoAttr->setScale(scale); });
6868

6969
// load the mass scaling
7070
io::jsonIntoSetter<double>(jsonConfig, "mass_scale", [aoAttr](double scale) {

src/esp/physics/ArticulatedObject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ class ArticulatedObject : public esp::physics::PhysicsObjectBase {
322322
* @brief Get the uniform global scaling applied to this object during import.
323323
* @return The global scaling applied to the object.
324324
*/
325-
float getGlobalScale() const { return globalScale_; }
325+
Mn::Vector3 getGlobalScale() const { return globalScale_; }
326326

327327
/**
328328
* @brief Get a const reference to an ArticulatedLink SceneNode for
@@ -1092,7 +1092,7 @@ class ArticulatedObject : public esp::physics::PhysicsObjectBase {
10921092
bool autoClampJointLimits_ = false;
10931093

10941094
//! Cache the global scaling from the source model. Set during import.
1095-
float globalScale_ = 1.0;
1095+
Mn::Vector3 globalScale_ = Mn::Vector3(1.0);
10961096

10971097
//! Cache the cumulative bounding box of the AO heirarchy in root local space.
10981098
//! This is necessary because the child links are not children of the root

src/esp/physics/PhysicsManager.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ int PhysicsManager::addArticulatedObjectFromURDF(
426426
const std::string& filepath,
427427
DrawableGroup* drawables,
428428
bool fixedBase,
429-
float globalScale,
429+
const Mn::Vector3& globalScale,
430430
float massScale,
431431
bool forceReload,
432432
bool maintainLinkOrder,
@@ -447,7 +447,7 @@ int PhysicsManager::addArticulatedObjectFromURDF(
447447
true);
448448

449449
// Set pertinent values
450-
artObjAttributes->setUniformScale(globalScale);
450+
artObjAttributes->setScale(globalScale);
451451
artObjAttributes->setMassScale(static_cast<double>(massScale));
452452

453453
artObjAttributes->setBaseType(metadata::attributes::getAOBaseTypeName(
@@ -526,16 +526,21 @@ int PhysicsManager::addArticulatedObjectInstance(
526526
artObjAttributes->setShaderType(getShaderTypeName(artObjShaderType));
527527
}
528528

529-
// set uniform scale
530-
artObjAttributes->setUniformScale(artObjAttributes->getUniformScale() *
531-
aObjInstAttributes->getUniformScale());
529+
// set scaling values for this instance of articulated object attributes -
530+
// first uniform scaling
531+
artObjAttributes->setScale(artObjAttributes->getScale() *
532+
aObjInstAttributes->getUniformScale());
533+
// set scaling values for this instance of object attributes - next
534+
// non-uniform scaling
535+
artObjAttributes->setScale(artObjAttributes->getScale() *
536+
aObjInstAttributes->getNonUniformScale());
532537

533538
// If boolean specifies to do so, apply geometric scaling to mass (product of
534539
// scale values)
535540
if (aObjInstAttributes->getApplyScaleToMass()) {
536541
artObjAttributes->setMassScale(
537542
artObjAttributes->getMassScale() *
538-
static_cast<double>(artObjAttributes->getUniformScale()));
543+
static_cast<double>(artObjAttributes->getScale().product()));
539544
}
540545

541546
// set scaled mass

src/esp/physics/PhysicsManager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,8 @@ class PhysicsManager : public std::enable_shared_from_this<PhysicsManager> {
511511
* query Simulator to retrieve a group.
512512
* @param fixedBase Whether the base of the @ref ArticulatedObject should be
513513
* fixed.
514-
* @param globalScale A scale multiplier to be applied uniformly in 3
515-
* dimensions to the entire @ref ArticulatedObject.
514+
* @param globalScale A scale multiplier to be applied in 3 dimensions to the
515+
* entire @ref ArticulatedObject.
516516
* @param massScale A scale multiplier to be applied to the mass of the all
517517
* the components of the @ref ArticulatedObject.
518518
* @param forceReload If true, reload the source URDF from file, replacing the
@@ -532,7 +532,7 @@ class PhysicsManager : public std::enable_shared_from_this<PhysicsManager> {
532532
const std::string& filepath,
533533
DrawableGroup* drawables = nullptr,
534534
bool fixedBase = false,
535-
float globalScale = 1.0,
535+
const Mn::Vector3& globalScale = {1.0, 1.0, 1.0},
536536
float massScale = 1.0,
537537
bool forceReload = false,
538538
bool maintainLinkOrder = false,

src/esp/physics/URDFImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ void URDFImporter::importURDFAssets(
249249
return;
250250
}
251251
// re-scale the cached model
252-
activeModel_->setGlobalScaling(artObjAttributes->getUniformScale());
252+
activeModel_->setGlobalScaling(artObjAttributes->getScale());
253253
activeModel_->setMassScaling(artObjAttributes->getMassScale());
254254

255255
for (size_t linkIx = 0; linkIx < activeModel_->m_links.size(); ++linkIx) {

src/esp/physics/bullet/BulletPhysicsManager.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ bool BulletPhysicsManager::attachLinkGeometry(
330330
visualMeshInfo.type = AssetType::Primitive;
331331
// default sphere prim is already constructed w/ radius 1
332332
visualMeshInfo.filepath = "icosphereSolid_subdivs_1";
333-
scale = Mn::Vector3(visual.m_geometry.m_sphereRadius);
333+
scale = visual.m_geometry.m_meshScale;
334334
} break;
335335
case metadata::URDF::GEOM_MESH: {
336336
scale = visual.m_geometry.m_meshScale;
@@ -935,8 +935,7 @@ void BulletPhysicsManager::instantiateSkinnedModel(
935935
assets::RenderAssetInstanceCreationInfo creationInfo;
936936
creationInfo.filepath = renderAssetPath;
937937
creationInfo.lightSetupKey = lightSetupKey;
938-
creationInfo.scale =
939-
artObjAttributes->getUniformScale() * Mn::Vector3(1.f, 1.f, 1.f);
938+
creationInfo.scale = artObjAttributes->getScale();
940939
esp::assets::RenderAssetInstanceCreationInfo::Flags flags;
941940
flags |= esp::assets::RenderAssetInstanceCreationInfo::Flag::IsRGBD;
942941
flags |= esp::assets::RenderAssetInstanceCreationInfo::Flag::IsSemantic;

0 commit comments

Comments
 (0)