Skip to content

Commit 3a04dd2

Browse files
committed
--Convert AO scale to vector;
Incomplete conversion, does not compile.
1 parent 2398455 commit 3a04dd2

19 files changed

+99
-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: 7 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,8 @@ 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 *= static_cast<double>(model->getGlobalScaling());
455+
link.m_inertia.m_mass *=
456+
static_cast<double>(model->getGlobalScaling().product());
457457
} else {
458458
if ((strlen(linkName) == 5) && (strncmp(linkName, "world", 5)) == 0) {
459459
link.m_inertia.m_mass = 0.0;

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");
@@ -576,7 +588,7 @@ class AbstractObjectAttributes : public AbstractAttributes {
576588

577589
std::string getObjectInfoHeaderInternal() const override;
578590
/**
579-
* @brief get AbstractObject specific info header
591+
* @brief Get AbstractObject specific info header
580592
*/
581593
virtual std::string getAbstractObjectInfoHeaderInternal() const {
582594
return "";
@@ -588,7 +600,7 @@ class AbstractObjectAttributes : public AbstractAttributes {
588600
*/
589601
std::string getObjectInfoInternal() const override;
590602
/**
591-
* @brief get AbstractObject specific info for csv string
603+
* @brief Get AbstractObject specific info for csv string
592604
*/
593605
virtual std::string getAbstractObjectInfoInternal() const { return ""; };
594606

src/esp/metadata/attributes/ArticulatedObjectAttributes.cpp

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

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

4242
// Initialize these so they exist in the configuration
@@ -56,8 +56,8 @@ void ArticulatedObjectAttributes::writeValuesToJson(
5656
writeValueToJson("urdf_filepath", jsonObj, allocator);
5757
writeValueToJson("render_asset", jsonObj, allocator);
5858
writeValueToJson("semantic_id", jsonObj, allocator);
59-
if (getUniformScale() != 1.0f) {
60-
writeValueToJson("uniform_scale", jsonObj, allocator);
59+
if (getScale() != Mn::Vector3(1.0, 1.0, 1.0)) {
60+
writeValueToJson("scale", jsonObj, allocator);
6161
}
6262
if (getMassScale() != 1.0) {
6363
writeValueToJson("mass_scale", jsonObj, allocator);
@@ -70,14 +70,14 @@ void ArticulatedObjectAttributes::writeValuesToJson(
7070
} // ArticulatedObjectAttributes::writeValuesToJson
7171

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

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

src/esp/metadata/attributes/ArticulatedObjectAttributes.h

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

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

9593
/**
9694
* @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
@@ -166,7 +166,7 @@ class ArticulatedObject : public esp::physics::PhysicsObjectBase {
166166
* @brief Get the uniform global scaling applied to this object during import.
167167
* @return The global scaling applied to the object.
168168
*/
169-
float getGlobalScale() const { return globalScale_; }
169+
Mn::Vector3 getGlobalScale() const { return globalScale_; }
170170

171171
/**
172172
* @brief Get a const reference to an ArticulatedLink SceneNode for
@@ -982,7 +982,7 @@ class ArticulatedObject : public esp::physics::PhysicsObjectBase {
982982
bool autoClampJointLimits_ = false;
983983

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

987987
//! Cache the cumulative bounding box of the AO heirarchy in root local space.
988988
//! 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
@@ -432,7 +432,7 @@ int PhysicsManager::addArticulatedObjectFromURDF(
432432
const std::string& filepath,
433433
DrawableGroup* drawables,
434434
bool fixedBase,
435-
float globalScale,
435+
const Mn::Vector3& globalScale,
436436
float massScale,
437437
bool forceReload,
438438
bool maintainLinkOrder,
@@ -453,7 +453,7 @@ int PhysicsManager::addArticulatedObjectFromURDF(
453453
true);
454454

455455
// Set pertinent values
456-
artObjAttributes->setUniformScale(globalScale);
456+
artObjAttributes->setScale(globalScale);
457457
artObjAttributes->setMassScale(static_cast<double>(massScale));
458458

459459
artObjAttributes->setBaseType(metadata::attributes::getAOBaseTypeName(
@@ -532,16 +532,21 @@ int PhysicsManager::addArticulatedObjectInstance(
532532
artObjAttributes->setShaderType(getShaderTypeName(artObjShaderType));
533533
}
534534

535-
// set uniform scale
536-
artObjAttributes->setUniformScale(artObjAttributes->getUniformScale() *
537-
aObjInstAttributes->getUniformScale());
535+
// set scaling values for this instance of articulated object attributes -
536+
// first uniform scaling
537+
artObjAttributes->setScale(artObjAttributes->getScale() *
538+
aObjInstAttributes->getUniformScale());
539+
// set scaling values for this instance of object attributes - next
540+
// non-uniform scaling
541+
artObjAttributes->setScale(artObjAttributes->getScale() *
542+
aObjInstAttributes->getNonUniformScale());
538543

539544
// If boolean specifies to do so, apply geometric scaling to mass (product of
540545
// scale values)
541546
if (aObjInstAttributes->getApplyScaleToMass()) {
542547
artObjAttributes->setMassScale(
543548
artObjAttributes->getMassScale() *
544-
static_cast<double>(artObjAttributes->getUniformScale()));
549+
static_cast<double>(artObjAttributes->getScale().product()));
545550
}
546551

547552
// set scaled mass

0 commit comments

Comments
 (0)