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

Expose ArticulatedObject creation_attributes #2259

Merged
merged 2 commits into from
Nov 7, 2023
Merged
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
5 changes: 5 additions & 0 deletions src/esp/bindings/PhysicsObjectBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ void declareArticulatedObjectWrapper(py::module& m,
AbstractManagedPhysicsObject<ArticulatedObject>,
std::shared_ptr<ManagedArticulatedObject>>(m,
classStrPrefix.c_str())
.def_property_readonly(
"creation_attributes",
&ManagedArticulatedObject::getInitializationAttributes,
("Get a copy of the attributes used to create this " + objType + ".")
.c_str())
.def_property_readonly(
"global_scale", &ManagedArticulatedObject::getGlobalScale,
R"(The uniform global scaling applied to this object during import.)")
Expand Down
11 changes: 11 additions & 0 deletions src/esp/metadata/URDFParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,17 @@ class Model {
return initializationAttributes_->getUserConfiguration();
}

/**
* @brief Get a copy of the template used to initialize this object.
*
* @return A copy of the @ref esp::metadata::attributes::ArticulatedObjectAttributes
* template used to create this object.
*/
std::shared_ptr<metadata::attributes::ArticulatedObjectAttributes>
getInitializationAttributes() const {
return initializationAttributes_;
};

protected:
/**
* @brief Json-based attributes defining characteristics of this model not
Expand Down
12 changes: 12 additions & 0 deletions src/esp/physics/ArticulatedObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,18 @@ class ArticulatedObject : public esp::physics::PhysicsObjectBase {
metadata::attributes::SceneAOInstanceAttributes>();
}

/**
* @brief Get a copy of the template used to initialize this object.
*
* @return A copy of the @ref esp::metadata::attributes::ArticulatedObjectAttributes
* template used to create this object.
*/
std::shared_ptr<metadata::attributes::ArticulatedObjectAttributes>
getInitializationAttributes() const {
return PhysicsObjectBase::getInitializationAttributes<
metadata::attributes::ArticulatedObjectAttributes>();
};

protected:
/**
* @brief Used to synchronize simulator's notion of the object state
Expand Down
20 changes: 20 additions & 0 deletions src/esp/physics/PhysicsObjectBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ class PhysicsObjectBase : public Magnum::SceneGraph::AbstractFeature3D {
return static_cast<const scene::SceneNode&>(
Magnum::SceneGraph::AbstractFeature3D::object());
}

/** @brief Get a copy of the template used to initialize this object
* or scene.
* @return A copy of the initialization template used to create this object
* instance or nullptr if no template exists.
*/
template <class T>
std::shared_ptr<T> getInitializationAttributes() const {
if (!initializationAttributes_) {
return nullptr;
}
return T::create(*(static_cast<T*>(initializationAttributes_.get())));
}

/**
* @brief Get the @ref MotionType of the object. See @ref
* setMotionType.
Expand Down Expand Up @@ -547,6 +561,12 @@ class PhysicsObjectBase : public Magnum::SceneGraph::AbstractFeature3D {
*/
core::config::Configuration::ptr userAttributes_ = nullptr;

/**
* @brief Saved attributes when the object was initialized.
*/
metadata::attributes::AbstractAttributes::ptr initializationAttributes_ =
nullptr;

private:
/**
* @brief This object's instancing attributes, if any were used during its
Expand Down
23 changes: 3 additions & 20 deletions src/esp/physics/RigidBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,19 +302,6 @@ class RigidBase : public esp::physics::PhysicsObjectBase {
metadata::attributes::SceneObjectInstanceAttributes>();
}

/** @brief Get a copy of the template used to initialize this object
* or scene.
* @return A copy of the initialization template used to create this object
* instance or nullptr if no template exists.
*/
template <class T>
std::shared_ptr<T> getInitializationAttributes() const {
if (!initializationAttributes_) {
return nullptr;
}
return T::create(*(static_cast<T*>(initializationAttributes_.get())));
}

/** @brief Get the scalar linear damping coefficient of the object. Only used
* for dervied dynamic implementations of @ref RigidObject.
* @return The scalar linear damping coefficient of the object.
Expand Down Expand Up @@ -378,7 +365,9 @@ class RigidBase : public esp::physics::PhysicsObjectBase {
* @return The scaling for the object relative to its initially loaded meshes.
*/
virtual Magnum::Vector3 getScale() const {
return initializationAttributes_->getScale();
return PhysicsObjectBase::getInitializationAttributes<
metadata::attributes::AbstractObjectAttributes>()
->getScale();
}

/**
Expand Down Expand Up @@ -451,12 +440,6 @@ class RigidBase : public esp::physics::PhysicsObjectBase {
*/
bool isCollidable_ = false;

/**
* @brief Saved attributes when the object was initialized.
*/
metadata::attributes::AbstractObjectAttributes::ptr
initializationAttributes_ = nullptr;

public:
ESP_SMART_POINTERS(RigidBase)
}; // class RigidBase
Expand Down
2 changes: 1 addition & 1 deletion src/esp/physics/RigidObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class RigidObject : public RigidBase {
*/
std::shared_ptr<metadata::attributes::ObjectAttributes>
getInitializationAttributes() const {
return RigidBase::getInitializationAttributes<
return PhysicsObjectBase::getInitializationAttributes<
metadata::attributes::ObjectAttributes>();
};

Expand Down
3 changes: 2 additions & 1 deletion src/esp/physics/RigidStage.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ class RigidStage : public RigidBase {
*/
std::shared_ptr<metadata::attributes::StageAttributes>
getInitializationAttributes() const {
return RigidBase::getInitializationAttributes<
return PhysicsObjectBase::getInitializationAttributes<
metadata::attributes::StageAttributes>();
};

/**
* @brief Finalize the creation of this @ref RigidStage
* @return whether successful finalization.
Expand Down
1 change: 1 addition & 0 deletions src/esp/physics/bullet/BulletArticulatedObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ void BulletArticulatedObject::initializeFromURDF(
}
// set user config attributes from model.
setUserAttributes(urdfModel->getUserConfiguration());
initializationAttributes_ = urdfModel->getInitializationAttributes();

// in case the base transform is not zero by default
syncPose();
Expand Down
7 changes: 4 additions & 3 deletions src/esp/physics/bullet/BulletRigidObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ bool BulletRigidObject::constructCollisionShape() {
//! Iterate through all mesh components for one object
//! The components are combined into a convex compound shape
bObjectShape_ = std::make_unique<btCompoundShape>();
auto initAttr = PhysicsObjectBase::getInitializationAttributes<
metadata::attributes::ObjectAttributes>();
// collision mesh/asset handle
const std::string collisionAssetHandle =
initializationAttributes_->getCollisionAssetHandle();
const std::string collisionAssetHandle = initAttr->getCollisionAssetHandle();

if (!initializationAttributes_->getUseMeshCollision()) {
if (!initAttr->getUseMeshCollision()) {
// if using prim collider get appropriate bullet collision primitive
// attributes and build bullet collision shape
auto primAttributes =
Expand Down
14 changes: 8 additions & 6 deletions src/esp/physics/bullet/BulletRigidStage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ void BulletRigidStage::setCollidable(bool collidable) {

void BulletRigidStage::constructAndAddCollisionObjects() {
if (bStaticCollisionObjects_.empty()) {
auto initAttr = PhysicsObjectBase::getInitializationAttributes<
metadata::attributes::StageAttributes>();
// construct the objects first time
const auto collisionAssetHandle =
initializationAttributes_->getCollisionAssetHandle();
const auto collisionAssetHandle = initAttr->getCollisionAssetHandle();

const std::vector<assets::CollisionMeshData>& meshGroup =
resMgr_.getCollisionMesh(collisionAssetHandle);
Expand All @@ -80,9 +81,8 @@ void BulletRigidStage::constructAndAddCollisionObjects() {
constructBulletSceneFromMeshes(Magnum::Matrix4{}, meshGroup, metaData.root);

for (auto& object : bStaticCollisionObjects_) {
object->setFriction(initializationAttributes_->getFrictionCoefficient());
object->setRestitution(
initializationAttributes_->getRestitutionCoefficient());
object->setFriction(initAttr->getFrictionCoefficient());
object->setRestitution(initAttr->getRestitutionCoefficient());
collisionObjToObjIds_->emplace(object.get(), objectId_);
}
}
Expand Down Expand Up @@ -141,7 +141,9 @@ void BulletRigidStage::constructBulletSceneFromMeshes(
std::unique_ptr<btBvhTriangleMeshShape> meshShape =
std::make_unique<btBvhTriangleMeshShape>(indexedVertexArray.get(),
true);
meshShape->setMargin(initializationAttributes_->getMargin());
auto initAttr = PhysicsObjectBase::getInitializationAttributes<
metadata::attributes::StageAttributes>();
meshShape->setMargin(initAttr->getMargin());
meshShape->setLocalScaling(
btVector3{transformFromLocalToWorld
.scaling()}); // scale is a property of the shape
Expand Down
8 changes: 8 additions & 0 deletions src/esp/physics/objectWrappers/ManagedArticulatedObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ class ManagedArticulatedObject
: AbstractManagedPhysicsObject<esp::physics::ArticulatedObject>(
classKey) {}

std::shared_ptr<metadata::attributes::ArticulatedObjectAttributes>
getInitializationAttributes() const {
if (auto sp = this->getObjectReference()) {
return sp->getInitializationAttributes();
}
return nullptr;
} // getInitializationAttributes()

float getGlobalScale() const {
if (auto sp = getObjectReference()) {
return sp->getGlobalScale();
Expand Down