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

Attach SceneNode to simulation #492

Merged
merged 11 commits into from
Mar 4, 2020
Merged

Attach SceneNode to simulation #492

merged 11 commits into from
Mar 4, 2020

Conversation

aclegg3
Copy link
Contributor

@aclegg3 aclegg3 commented Feb 13, 2020

Motivation and Context

This change enables an existing SceneNode to be attached to a newly instanced physics object. Also enables removal of objects from simulation while deleting either the object's full SceneNode structure, the visual component only, or nothing.

This enables rendering of embodied agents (#332) and continuous control of an Agent's state via PhysicsManager functions.

Added python bindings for this functionality.

How Has This Been Tested

C++ and python unit tests and new viewer demo option to attach/detach the agent to/from physics with 'p'. While attached to an object, 'w','a','s','d' command dynamic linear velocity of the attached object (instead of navmesh discrete control of the agent) and LEFT|RIGHT command local angular velocity (+-Y axis). Edit: viewer demo shown below removed to keep things clean, but functionality is the same.

Example - agent attachment to a can with user controlled rolling:
attach_agent_can_small

Example - agent attachment to a locobot with user control:
attach_agent_locobot_small

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@aclegg3 aclegg3 self-assigned this Feb 13, 2020
@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Feb 13, 2020
@codecov
Copy link

codecov bot commented Feb 13, 2020

Codecov Report

Merging #492 into master will increase coverage by 0.19%.
The diff coverage is 96.36%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #492      +/-   ##
==========================================
+ Coverage   61.04%   61.23%   +0.19%     
==========================================
  Files         164      164              
  Lines        7500     7538      +38     
  Branches       84       84              
==========================================
+ Hits         4578     4616      +38     
  Misses       2922     2922
Flag Coverage Δ
#CPP 56.04% <95.45%> (+0.32%) ⬆️
#JavaScript 10% <ø> (ø) ⬆️
#Python 80.78% <100%> (+0.04%) ⬆️
Impacted Files Coverage Δ
src/esp/sim/Simulator.h 100% <ø> (ø) ⬆️
src/esp/physics/RigidObject.h 10.34% <ø> (ø) ⬆️
src/esp/physics/PhysicsManager.h 70% <ø> (ø) ⬆️
tests/test_physics.py 100% <100%> (ø) ⬆️
src/esp/physics/bullet/BulletRigidObject.cpp 70.2% <100%> (ø) ⬆️
habitat_sim/simulator.py 95.29% <100%> (ø) ⬆️
src/esp/physics/RigidObject.cpp 34.9% <100%> (ø) ⬆️
src/tests/SimTest.cpp 100% <100%> (ø) ⬆️
src/tests/PhysicsTest.cpp 97.63% <100%> (+0.33%) ⬆️
src/esp/physics/bullet/BulletPhysicsManager.cpp 58.11% <77.77%> (+0.97%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f261f07...8fb4280. Read the comment docs.

src/esp/physics/PhysicsManager.cpp Show resolved Hide resolved
src/esp/physics/PhysicsManager.cpp Show resolved Hide resolved
src/esp/physics/PhysicsManager.cpp Outdated Show resolved Hide resolved
src/esp/physics/RigidObject.cpp Outdated Show resolved Hide resolved
src/esp/physics/RigidObject.cpp Outdated Show resolved Hide resolved
/**
* @brief All Drawable components are children of this node.
*/
scene::SceneNode* visualNode_ = nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason this is public versus having a getter (like node())?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reasoning: Currently, PhysicsManager needs access to these pointers and they can be null, so references aren't ideal. The getters would then be for raw pointer anyway. Users should not be getting direct access to a RigidObject to manipulate these, so I left them at public.

@@ -408,3 +408,52 @@ TEST_F(PhysicsManagerTest, TestVelocityControl) {
ASSERT_EQ(physicsManager_->getAngularVelocity(objectId), Magnum::Vector3{});
}
}

TEST_F(PhysicsManagerTest, TestSceneNodeAttachment) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From now on, suggest using Corrade::TestSuite.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but definitely in a separate PR :)

The new test doesn't do anything that would strongly benefit from switching to TestSuite, so I'm fine with keeping it in gtest and rewriting with TestSuite later.


esp::assets::PhysicsObjectAttributes physicsObjectAttributes;
physicsObjectAttributes.setString("renderMeshHandle", objectFile);
resourceManager_.loadObject(physicsObjectAttributes, objectFile);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Underscore is not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a call to PhysicsManagerTest::resourceManager_, so underscore is needed. Did I miss your meaning?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. This is the member variable of the class PhysicsManagerTest.

My bad.

src/utils/viewer/viewer.cpp Outdated Show resolved Hide resolved
@@ -88,21 +91,27 @@ int PhysicsManager::addObject(const int objectLibIndex,

int PhysicsManager::addObject(const std::string& configFile,
DrawableGroup* drawables,
scene::SceneNode* attachmentNode,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I understand why this argument is a must have?
Can we just create a scene object within addObject(...), and thus hide this detail to the user?
I did not see any usage case in this PR that leverage this argument. The only caller (in Simulator.cpp) just passed a nullptr.

Did I miss the big picture here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed this into python and wrote a test case in test_physics.py to demonstrate the usage. This PR is really to address the visual/simulated agent problems. An Agent SceneNode can be passed to addObject to use that node instead of generating a new one.

@aclegg3 aclegg3 requested a review from bigbike March 4, 2020 17:43

esp::assets::PhysicsObjectAttributes physicsObjectAttributes;
physicsObjectAttributes.setString("renderMeshHandle", objectFile);
resourceManager_.loadObject(physicsObjectAttributes, objectFile);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. This is the member variable of the class PhysicsManagerTest.

My bad.

@aclegg3 aclegg3 merged commit eb700cd into master Mar 4, 2020
@aclegg3 aclegg3 deleted the attach-agent branch March 4, 2020 19:04
@aclegg3 aclegg3 mentioned this pull request Mar 19, 2020
Ram81 pushed a commit to Ram81/habitat-web-sim that referenced this pull request Dec 10, 2020
* Add SceneNode attachment option to addObject and makeRigidObject.

* Added RigidObject::visualNode_ to clearly separate Drawable branch of a physical object's SceneNode hierarchy. 

* Enabled optional deletion of visualNode_ and object SceneNode hierarchy when removing objects from PhysicsManager.

* Added python bindings and unit tests in python and C++.
luoj1 pushed a commit to luoj1/habitat-sim that referenced this pull request Aug 16, 2022
* typed Habitat Core

* Fix more habitat typing issues

* Fix objnav typecheck

* Fix incorrect config type

* complete habitat lab mypy conversion

* Migrate mypy config to mypy.ini

* Remove unused mypy config values

* Re-enable episodes setter

* Finish typing habitat_baselines

* Stricten type hints in habitat.core.simulator

* Fix registry type add constructor to Simulator

* Fix import error

* Make max singleton

* Remove list copy

* Update mypy with global ignores

* Do better list casting

* Update pre-commit hooks

* unify pre-commit style

* Add check-yaml pre-commit hook

* Bugfix and optimize ci tests

* Remove one more type ignore

* Update habitat_baselines/rl/ppo/ppo.py

* Fix ppo imports

* remove dead code

* Revert "remove dead code"

This reverts commit acf9fd8c3e7f7989137ad54eaacab158c23dd1b4.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants