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

--[WIP] - Articulated Object Non-Uniform Scale #2448

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
6 changes: 3 additions & 3 deletions docs/pages/attributesJSON.rst
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,9 @@ Below are the handles and descriptors for the source URDF file and the render as
Articulated Object Configuration And Rendering
----------------------------------------------

"uniform_scale"
- double
- The uniform scaling to apply to this articulated object after load (defaults to 1.0). This is modifiable by the scene instance specification.
"scale"
- 3-vector
- 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.
"mass_scale"
- double
- 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.
Expand Down
2 changes: 1 addition & 1 deletion src/esp/bindings/PhysicsObjectBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ void declareArticulatedObjectWrapper(py::module& m,
.c_str())
.def_property_readonly(
"global_scale", &ManagedArticulatedObject::getGlobalScale,
R"(The uniform global scaling applied to this object during import.)")
R"(The global scaling vector applied to this object during import.)")
.def("get_link_scene_node", &ManagedArticulatedObject::getLinkSceneNode,
("Get the scene node for this " + objType +
"'s articulated link specified by the passed "
Expand Down
14 changes: 7 additions & 7 deletions src/esp/metadata/URDFParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,17 @@ namespace esp {
namespace metadata {
namespace URDF {

void Model::scaleShape(Shape& shape, float scale) {
void Model::scaleShape(Shape& shape, const Mn::Vector3& scale) {
shape.m_linkLocalFrame.translation() *= scale;
switch (shape.m_geometry.m_type) {
case GEOM_SPHERE:
case GEOM_MESH: {
shape.m_geometry.m_meshScale *= scale;
} break;
case GEOM_BOX: {
shape.m_geometry.m_boxSize *= scale;
} break;
case GEOM_SPHERE: {
shape.m_geometry.m_sphereRadius *= double(scale);
} break;

case GEOM_CAPSULE:
case GEOM_CYLINDER: {
shape.m_geometry.m_capsuleRadius *= double(scale);
Expand All @@ -51,14 +50,14 @@ void Model::scaleShape(Shape& shape, float scale) {
}
}

void Model::setGlobalScaling(float scaling) {
void Model::setGlobalScaling(const Mn::Vector3& scaling) {
if (scaling == m_globalScaling) {
// do nothing
return;
}

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

// scale all transforms' translations
for (const auto& link : m_links) {
Expand Down Expand Up @@ -453,7 +452,8 @@ bool Parser::parseLink(const std::shared_ptr<Model>& model,
ESP_VERY_VERBOSE() << link.m_name;
return false;
}
link.m_inertia.m_mass *= static_cast<double>(model->getGlobalScaling());
link.m_inertia.m_mass *=
static_cast<double>(model->getGlobalScaling().product());
} else {
if ((strlen(linkName) == 5) && (strncmp(linkName, "world", 5)) == 0) {
link.m_inertia.m_mass = 0.0;
Expand Down
31 changes: 14 additions & 17 deletions src/esp/metadata/URDFParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,12 @@ class Model {
* @brief Set global scaling and re-scale an existing model. Modifies various
* internal parameters.
*
* @param scaling The new absolute uniform scale.
* @param scaling The new absolute scale.
*/
void setGlobalScaling(float scaling);
void setGlobalScaling(const Mn::Vector3& scaling);

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

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

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

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

/**
* @brief Functional class for parsing URDF files into a URDF::Model
* representation.
*/
class Parser {
// URDF file path of last load call
std::string sourceFilePath_;
public:
Parser() = default;

// parse a loaded URDF string into relevant general data structures
// return false if the string is not a valid urdf or other error causes abort
bool parseURDF(const std::string& filename, std::shared_ptr<Model>& model);

private:
/**
* @brief Parse a transform into a Matrix4.
*
Expand Down Expand Up @@ -522,16 +527,8 @@ class Parser {
*/
bool validateMeshFile(std::string& filename);

public:
Parser() = default;

// parse a loaded URDF string into relevant general data structures
// return false if the string is not a valid urdf or other error causes abort
bool parseURDF(const std::string& filename, std::shared_ptr<Model>& model);

// This is no longer used, instead set the urdf and physics subsystem to
// veryverbose, i.e. export HABITAT_SIM_LOG="urdf,physics=veryverbose" bool
// logMessages = false;
// URDF file path of last load call
std::string sourceFilePath_;
};

} // namespace URDF
Expand Down
28 changes: 20 additions & 8 deletions src/esp/metadata/attributes/AbstractObjectAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,42 @@ class AbstractObjectAttributes : public AbstractAttributes {
~AbstractObjectAttributes() override = default;

/**
* @brief Scale of the ojbect
* @brief Set the scale of the object
*/
void setScale(const Magnum::Vector3& scale) { set("scale", scale); }
/**
* @brief Get the scale of the object
*/
Magnum::Vector3 getScale() const { return get<Magnum::Vector3>("scale"); }

/**
* @brief collision shape inflation margin
* @brief Set the collision shape inflation margin
*/
void setMargin(double margin) { set("margin", margin); }
/**
* @brief Get the collision shape inflation margin
*/
double getMargin() const { return get<double>("margin"); }

// if object should be checked for collisions - if other objects can collide
// with this object
/**
* @brief Set if object should be checked for collisions - if other objects
* can collide with this object
*/
void setIsCollidable(bool isCollidable) {
set("is_collidable", isCollidable);
}
/**
* @brief Get if object should be checked for collisions - if other objects
* can collide with this object
*/
bool getIsCollidable() const { return get<bool>("is_collidable"); }

/**
* @brief Set default up orientation for object/stage mesh
*/
void setOrientUp(const Magnum::Vector3& orientUp) { set("up", orientUp); }
/**
* @brief get default up orientation for object/stage mesh
* @brief Get default up orientation for object/stage mesh
*/
Magnum::Vector3 getOrientUp() const { return get<Magnum::Vector3>("up"); }
/**
Expand All @@ -59,7 +71,7 @@ class AbstractObjectAttributes : public AbstractAttributes {
set("front", orientFront);
}
/**
* @brief get default forward orientation for object/stage mesh
* @brief Get default forward orientation for object/stage mesh
*/
Magnum::Vector3 getOrientFront() const {
return get<Magnum::Vector3>("front");
Expand Down Expand Up @@ -576,7 +588,7 @@ class AbstractObjectAttributes : public AbstractAttributes {

std::string getObjectInfoHeaderInternal() const override;
/**
* @brief get AbstractObject specific info header
* @brief Get AbstractObject specific info header
*/
virtual std::string getAbstractObjectInfoHeaderInternal() const {
return "";
Expand All @@ -588,7 +600,7 @@ class AbstractObjectAttributes : public AbstractAttributes {
*/
std::string getObjectInfoInternal() const override;
/**
* @brief get AbstractObject specific info for csv string
* @brief Get AbstractObject specific info for csv string
*/
virtual std::string getAbstractObjectInfoInternal() const { return ""; };

Expand Down
10 changes: 5 additions & 5 deletions src/esp/metadata/attributes/ArticulatedObjectAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ArticulatedObjectAttributes::ArticulatedObjectAttributes(
initTranslated("shader_type",
getShaderTypeName(ObjectInstanceShaderType::Material));

init("uniform_scale", 1.0f);
init("scale", Mn::Vector3{1.0, 1.0, 1.0});
init("mass_scale", 1.0);

// Initialize these so they exist in the configuration
Expand All @@ -56,8 +56,8 @@ void ArticulatedObjectAttributes::writeValuesToJson(
writeValueToJson("urdf_filepath", jsonObj, allocator);
writeValueToJson("render_asset", jsonObj, allocator);
writeValueToJson("semantic_id", jsonObj, allocator);
if (getUniformScale() != 1.0f) {
writeValueToJson("uniform_scale", jsonObj, allocator);
if (getScale() != Mn::Vector3(1.0, 1.0, 1.0)) {
writeValueToJson("scale", jsonObj, allocator);
}
if (getMassScale() != 1.0) {
writeValueToJson("mass_scale", jsonObj, allocator);
Expand All @@ -70,14 +70,14 @@ void ArticulatedObjectAttributes::writeValuesToJson(
} // ArticulatedObjectAttributes::writeValuesToJson

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

std::string ArticulatedObjectAttributes::getObjectInfoInternal() const {
return Cr::Utility::formatString(
"{},{},{},{},{},{},{},{},{},{}", getURDFPath(), getRenderAssetHandle(),
getAsString("semantic_id"), getAsString("uniform_scale"),
getAsString("semantic_id"), getAsString("scale"),
getAsString("mass_scale"), getAOBaseTypeName(getBaseType()),
getAOInertiaSourceName(getInertiaSource()),
getAOLinkOrderName(getLinkOrder()), getAORenderModeName(getRenderMode()),
Expand Down
10 changes: 4 additions & 6 deletions src/esp/metadata/attributes/ArticulatedObjectAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,13 @@ class ArticulatedObjectAttributes : public AbstractAttributes {
}

/**
* @brief Set uniform scaling of the articulated object.
* @brief Set scaling vector of the articulated object.
*/
void setUniformScale(float scale) { set("uniform_scale", scale); }
void setScale(const Magnum::Vector3& scale) { set("scale", scale); }
/**
* @brief Get uniform scaling of the articulated object.
* @brief Get the scale vector of the articulated object.
*/
float getUniformScale() const {
return static_cast<float>(get<double>("uniform_scale"));
}
Magnum::Vector3 getScale() const { return get<Magnum::Vector3>("scale"); }

/**
* @brief Set mass scaling of the articulated object.
Expand Down
8 changes: 4 additions & 4 deletions src/esp/metadata/managers/AOAttributesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ void AOAttributesManager::setValsFromJSONDoc(
aoAttr->setSemanticId(semantic_id);
});

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

// load the mass scaling
io::jsonIntoSetter<double>(jsonConfig, "mass_scale", [aoAttr](double scale) {
Expand Down
4 changes: 2 additions & 2 deletions src/esp/physics/ArticulatedObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class ArticulatedObject : public esp::physics::PhysicsObjectBase {
* @brief Get the uniform global scaling applied to this object during import.
* @return The global scaling applied to the object.
*/
float getGlobalScale() const { return globalScale_; }
Mn::Vector3 getGlobalScale() const { return globalScale_; }

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

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

//! Cache the cumulative bounding box of the AO heirarchy in root local space.
//! This is necessary because the child links are not children of the root
Expand Down
17 changes: 11 additions & 6 deletions src/esp/physics/PhysicsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ int PhysicsManager::addArticulatedObjectFromURDF(
const std::string& filepath,
DrawableGroup* drawables,
bool fixedBase,
float globalScale,
const Mn::Vector3& globalScale,
float massScale,
bool forceReload,
bool maintainLinkOrder,
Expand All @@ -453,7 +453,7 @@ int PhysicsManager::addArticulatedObjectFromURDF(
true);

// Set pertinent values
artObjAttributes->setUniformScale(globalScale);
artObjAttributes->setScale(globalScale);
artObjAttributes->setMassScale(static_cast<double>(massScale));

artObjAttributes->setBaseType(metadata::attributes::getAOBaseTypeName(
Expand Down Expand Up @@ -532,16 +532,21 @@ int PhysicsManager::addArticulatedObjectInstance(
artObjAttributes->setShaderType(getShaderTypeName(artObjShaderType));
}

// set uniform scale
artObjAttributes->setUniformScale(artObjAttributes->getUniformScale() *
aObjInstAttributes->getUniformScale());
// set scaling values for this instance of articulated object attributes -
// first uniform scaling
artObjAttributes->setScale(artObjAttributes->getScale() *
aObjInstAttributes->getUniformScale());
// set scaling values for this instance of object attributes - next
// non-uniform scaling
artObjAttributes->setScale(artObjAttributes->getScale() *
aObjInstAttributes->getNonUniformScale());

// If boolean specifies to do so, apply geometric scaling to mass (product of
// scale values)
if (aObjInstAttributes->getApplyScaleToMass()) {
artObjAttributes->setMassScale(
artObjAttributes->getMassScale() *
static_cast<double>(artObjAttributes->getUniformScale()));
static_cast<double>(artObjAttributes->getScale().product()));
}

// set scaled mass
Expand Down
6 changes: 3 additions & 3 deletions src/esp/physics/PhysicsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,8 @@ class PhysicsManager : public std::enable_shared_from_this<PhysicsManager> {
* query Simulator to retrieve a group.
* @param fixedBase Whether the base of the @ref ArticulatedObject should be
* fixed.
* @param globalScale A scale multiplier to be applied uniformly in 3
* dimensions to the entire @ref ArticulatedObject.
* @param globalScale A scale multiplier to be applied in 3 dimensions to the
* entire @ref ArticulatedObject.
* @param massScale A scale multiplier to be applied to the mass of the all
* the components of the @ref ArticulatedObject.
* @param forceReload If true, reload the source URDF from file, replacing the
Expand All @@ -541,7 +541,7 @@ class PhysicsManager : public std::enable_shared_from_this<PhysicsManager> {
const std::string& filepath,
DrawableGroup* drawables = nullptr,
bool fixedBase = false,
float globalScale = 1.0,
const Mn::Vector3& globalScale = {1.0, 1.0, 1.0},
float massScale = 1.0,
bool forceReload = false,
bool maintainLinkOrder = false,
Expand Down
2 changes: 1 addition & 1 deletion src/esp/physics/URDFImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ void URDFImporter::importURDFAssets(
return;
}
// re-scale the cached model
activeModel_->setGlobalScaling(artObjAttributes->getUniformScale());
activeModel_->setGlobalScaling(artObjAttributes->getScale());
activeModel_->setMassScaling(artObjAttributes->getMassScale());

for (size_t linkIx = 0; linkIx < activeModel_->m_links.size(); ++linkIx) {
Expand Down
5 changes: 2 additions & 3 deletions src/esp/physics/bullet/BulletPhysicsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ bool BulletPhysicsManager::attachLinkGeometry(
visualMeshInfo.type = AssetType::Primitive;
// default sphere prim is already constructed w/ radius 1
visualMeshInfo.filepath = "icosphereSolid_subdivs_1";
scale = Mn::Vector3(visual.m_geometry.m_sphereRadius);
scale = visual.m_geometry.m_meshScale;
} break;
case metadata::URDF::GEOM_MESH: {
scale = visual.m_geometry.m_meshScale;
Expand Down Expand Up @@ -950,8 +950,7 @@ void BulletPhysicsManager::instantiateSkinnedModel(
assets::RenderAssetInstanceCreationInfo creationInfo;
creationInfo.filepath = renderAssetPath;
creationInfo.lightSetupKey = lightSetupKey;
creationInfo.scale =
artObjAttributes->getUniformScale() * Mn::Vector3(1.f, 1.f, 1.f);
creationInfo.scale = artObjAttributes->getScale();
esp::assets::RenderAssetInstanceCreationInfo::Flags flags;
flags |= esp::assets::RenderAssetInstanceCreationInfo::Flag::IsRGBD;
flags |= esp::assets::RenderAssetInstanceCreationInfo::Flag::IsSemantic;
Expand Down
Loading
Loading