Skip to content

Commit e879c93

Browse files
authored
Merge pull request #158 from resibots/deep_copy_shapes
[robot]: deep copy shapes when cloning
2 parents 8f17195 + 2a8c544 commit e879c93

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

docs/installation.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ sudo apt-get install liburdfdom-dev liburdfdom-headers-dev
5757
cd /path/to/tmp/folder
5858
git clone git://github.com/dartsim/dart.git
5959
cd dart
60-
git checkout v6.10.1
60+
git checkout v6.12.1
6161

6262
mkdir build
6363
cd build
@@ -84,7 +84,7 @@ brew install urdfdom
8484
cd /path/to/tmp/folder
8585
git clone git://github.com/dartsim/dart.git
8686
cd dart
87-
git checkout v6.10.1
87+
git checkout v6.12.1
8888

8989
mkdir build
9090
cd build

src/robot_dart/robot.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,20 @@ namespace robot_dart {
279279
#endif
280280
_skeleton->getMutex().unlock();
281281
auto robot = std::make_shared<Robot>(tmp_skel, _robot_name);
282+
283+
#if DART_VERSION_AT_LEAST(6, 13, 0)
284+
// Deep copy everything
285+
for (auto& bd : robot->skeleton()->getBodyNodes()) {
286+
auto& visual_shapes = bd->getShapeNodesWith<dart::dynamics::VisualAspect>();
287+
for (auto& shape : visual_shapes) {
288+
if (shape->getShape()->getType() != dart::dynamics::SoftMeshShape::getStaticType())
289+
shape->setShape(shape->getShape()->clone());
290+
}
291+
}
292+
#endif
293+
294+
robot->set_positions(this->positions());
295+
282296
robot->_model_filename = _model_filename;
283297
robot->_controllers.clear();
284298
for (auto& ctrl : _controllers) {
@@ -311,13 +325,26 @@ namespace robot_dart {
311325
shape->removeAspect<dart::dynamics::CollisionAspect>();
312326
}
313327

328+
// ghost robots do not have dynamics
329+
auto& dyn_shapes = bd->getShapeNodesWith<dart::dynamics::DynamicsAspect>();
330+
for (auto& shape : dyn_shapes) {
331+
shape->removeAspect<dart::dynamics::DynamicsAspect>();
332+
}
333+
314334
// ghost robots have a different color (same for all bodies)
315335
auto& visual_shapes = bd->getShapeNodesWith<dart::dynamics::VisualAspect>();
316336
for (auto& shape : visual_shapes) {
337+
#if DART_VERSION_AT_LEAST(6, 13, 0)
338+
if (shape->getShape()->getType() != dart::dynamics::SoftMeshShape::getStaticType())
339+
shape->setShape(shape->getShape()->clone());
340+
#endif
317341
shape->getVisualAspect()->setRGBA(ghost_color);
318342
}
319343
}
320344

345+
// set positions
346+
robot->set_positions(this->positions());
347+
321348
// ghost robots, by default, use the color from the VisualAspect
322349
robot->set_color_mode("aspect");
323350

0 commit comments

Comments
 (0)