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

[robot]: deep copy shapes when cloning #158

Merged
merged 6 commits into from
Dec 16, 2021
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
4 changes: 2 additions & 2 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ sudo apt-get install liburdfdom-dev liburdfdom-headers-dev
cd /path/to/tmp/folder
git clone git://github.com/dartsim/dart.git
cd dart
git checkout v6.10.1
git checkout v6.12.1

mkdir build
cd build
Expand All @@ -84,7 +84,7 @@ brew install urdfdom
cd /path/to/tmp/folder
git clone git://github.com/dartsim/dart.git
cd dart
git checkout v6.10.1
git checkout v6.12.1

mkdir build
cd build
Expand Down
27 changes: 27 additions & 0 deletions src/robot_dart/robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,20 @@ namespace robot_dart {
#endif
_skeleton->getMutex().unlock();
auto robot = std::make_shared<Robot>(tmp_skel, _robot_name);

#if DART_VERSION_AT_LEAST(6, 13, 0)
// Deep copy everything
for (auto& bd : robot->skeleton()->getBodyNodes()) {
auto& visual_shapes = bd->getShapeNodesWith<dart::dynamics::VisualAspect>();
for (auto& shape : visual_shapes) {
if (shape->getShape()->getType() != dart::dynamics::SoftMeshShape::getStaticType())
shape->setShape(shape->getShape()->clone());
}
}
#endif

robot->set_positions(this->positions());

robot->_model_filename = _model_filename;
robot->_controllers.clear();
for (auto& ctrl : _controllers) {
Expand Down Expand Up @@ -311,13 +325,26 @@ namespace robot_dart {
shape->removeAspect<dart::dynamics::CollisionAspect>();
}

// ghost robots do not have dynamics
auto& dyn_shapes = bd->getShapeNodesWith<dart::dynamics::DynamicsAspect>();
for (auto& shape : dyn_shapes) {
shape->removeAspect<dart::dynamics::DynamicsAspect>();
}

// ghost robots have a different color (same for all bodies)
auto& visual_shapes = bd->getShapeNodesWith<dart::dynamics::VisualAspect>();
for (auto& shape : visual_shapes) {
#if DART_VERSION_AT_LEAST(6, 13, 0)
if (shape->getShape()->getType() != dart::dynamics::SoftMeshShape::getStaticType())
shape->setShape(shape->getShape()->clone());
#endif
shape->getVisualAspect()->setRGBA(ghost_color);
}
}

// set positions
robot->set_positions(this->positions());

// ghost robots, by default, use the color from the VisualAspect
robot->set_color_mode("aspect");

Expand Down