Skip to content

Commit 9ecbd34

Browse files
authored
Merge pull request #130 from resibots/remove_gui
Allow for removals of robots in GUI
2 parents 0c2dccd + 3b6a742 commit 9ecbd34

File tree

4 files changed

+49
-9
lines changed

4 files changed

+49
-9
lines changed

src/robot_dart/gui/magnum/base_application.cpp

+41-1
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,47 @@ namespace robot_dart {
315315
/* Refresh the graphical models */
316316
_dart_world->refresh();
317317

318+
/* Remove unused/deleted objects */
319+
auto& unused = _dart_world->unusedObjects();
320+
for (auto& p : unused) {
321+
auto obj = &p->object();
322+
auto it = _drawable_objects.begin();
323+
while (it != _drawable_objects.end()) {
324+
auto obj2 = (it->second->drawable->object().parent());
325+
if (obj == obj2) {
326+
// Update variables
327+
if (_transparent_shadows) {
328+
/* Check if it was transparent */
329+
auto& mats = it->second->drawable->materials();
330+
bool any = false;
331+
for (size_t j = 0; j < mats.size(); j++) {
332+
// Assume textures are transparent objects so that everything gets drawn better
333+
// TO-DO: Check if this is okay to do?
334+
bool isTextured = mats[j].has_diffuse_texture();
335+
if (isTextured || mats[j].diffuse_color().a() != 1.f) {
336+
any = true;
337+
break;
338+
}
339+
}
340+
341+
if (any)
342+
_transparentSize--;
343+
}
344+
// Remove it from the drawable lists
345+
_drawables.remove(*it->second->drawable);
346+
_shadowed_drawables.remove(*it->second->shadowed);
347+
_shadowed_color_drawables.remove(*it->second->shadowed_color);
348+
_cubemap_drawables.remove(*it->second->cubemapped);
349+
_cubemap_color_drawables.remove(*it->second->cubemapped_color);
350+
// Delete it completely
351+
delete it->second;
352+
_drawable_objects.erase(it);
353+
break;
354+
}
355+
it++;
356+
}
357+
}
358+
318359
/* For each update object */
319360
for (Magnum::DartIntegration::Object& object : _dart_world->updatedShapeObjects()) {
320361
/* Get material information */
@@ -688,7 +729,6 @@ namespace robot_dart {
688729
for (auto& it : _drawable_objects)
689730
delete it.second;
690731
_drawable_objects.clear();
691-
_dart_objects.clear();
692732
_lights.clear();
693733
_shadow_data.clear();
694734
}

src/robot_dart/gui/magnum/base_application.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ namespace robot_dart {
210210
RobotDARTSimu* _simu;
211211
std::unique_ptr<Magnum::DartIntegration::World> _dart_world;
212212
std::unordered_map<Magnum::DartIntegration::Object*, ObjectStruct*> _drawable_objects;
213-
std::vector<Object3D*> _dart_objects;
214213
std::vector<gs::Light> _lights;
215214

216215
/* Shadows */

src/robot_dart/gui/magnum/drawables.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace robot_dart {
2424

2525
namespace gui {
2626
namespace magnum {
27-
class DrawableObject : public Object3D, Magnum::SceneGraph::Drawable3D {
27+
class DrawableObject : public Object3D, public Magnum::SceneGraph::Drawable3D {
2828
public:
2929
explicit DrawableObject(
3030
RobotDARTSimu* simu,
@@ -66,7 +66,7 @@ namespace robot_dart {
6666
bool _isTransparent;
6767
};
6868

69-
class ShadowedObject : public Object3D, Magnum::SceneGraph::Drawable3D {
69+
class ShadowedObject : public Object3D, public Magnum::SceneGraph::Drawable3D {
7070
public:
7171
explicit ShadowedObject(
7272
RobotDARTSimu* simu,
@@ -95,7 +95,7 @@ namespace robot_dart {
9595
std::vector<Magnum::Vector3> _scalings;
9696
};
9797

98-
class ShadowedColorObject : public Object3D, Magnum::SceneGraph::Drawable3D {
98+
class ShadowedColorObject : public Object3D, public Magnum::SceneGraph::Drawable3D {
9999
public:
100100
explicit ShadowedColorObject(
101101
RobotDARTSimu* simu,
@@ -124,7 +124,7 @@ namespace robot_dart {
124124
std::vector<Magnum::Vector3> _scalings;
125125
};
126126

127-
class CubeMapShadowedObject : public Object3D, Magnum::SceneGraph::Drawable3D {
127+
class CubeMapShadowedObject : public Object3D, public Magnum::SceneGraph::Drawable3D {
128128
public:
129129
explicit CubeMapShadowedObject(
130130
RobotDARTSimu* simu,
@@ -153,7 +153,7 @@ namespace robot_dart {
153153
std::vector<Magnum::Vector3> _scalings;
154154
};
155155

156-
class CubeMapShadowedColorObject : public Object3D, Magnum::SceneGraph::Drawable3D {
156+
class CubeMapShadowedColorObject : public Object3D, public Magnum::SceneGraph::Drawable3D {
157157
public:
158158
explicit CubeMapShadowedColorObject(
159159
RobotDARTSimu* simu,

src/robot_dart/robot_dart_simu.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -369,23 +369,24 @@ namespace robot_dart {
369369
{
370370
auto it = std::find(_robots.begin(), _robots.end(), robot);
371371
if (it != _robots.end()) {
372+
_gui_data->remove_robot(robot);
372373
_world->removeSkeleton(robot->skeleton());
373374
_robots.erase(it);
374-
375-
_gui_data->remove_robot(robot);
376375
}
377376
}
378377

379378
void RobotDARTSimu::remove_robot(size_t index)
380379
{
381380
ROBOT_DART_ASSERT(index < _robots.size(), "Robot index out of bounds", );
381+
_gui_data->remove_robot(_robots[index]);
382382
_world->removeSkeleton(_robots[index]->skeleton());
383383
_robots.erase(_robots.begin() + index);
384384
}
385385

386386
void RobotDARTSimu::clear_robots()
387387
{
388388
for (auto& robot : _robots) {
389+
_gui_data->remove_robot(robot);
389390
_world->removeSkeleton(robot->skeleton());
390391
}
391392
_robots.clear();

0 commit comments

Comments
 (0)