Skip to content

Commit

Permalink
Merge pull request #443 from ignitionrobotics/iche033/heightmap_segme…
Browse files Browse the repository at this point in the history
…ntation_patch

Hide heightmaps in segmentation camera
  • Loading branch information
iche033 authored Sep 30, 2021
1 parent eb7d6ea commit 084516a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ogre2/include/ignition/rendering/ogre2/Ogre2Scene.hh
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,11 @@ namespace ignition
/// \param[in] _camera Camera about to be used for rendering
public: void UpdateAllHeightmaps(Ogre::Camera *_camera);

/// \internal
/// \brief Return all heightmaps in the scene
public: const std::vector<std::weak_ptr<Ogre2Heightmap>> &Heightmaps()
const;

/// \brief Create a compositor shadow node with the same number of shadow
/// textures as the number of shadow casting lights
protected: void UpdateShadowNode();
Expand Down
1 change: 1 addition & 0 deletions ogre2/src/Ogre2Heightmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class ignition::rendering::Ogre2HeightmapPrivate
/// \brief Size of the heightmap data.
public: unsigned int dataSize{0u};

/// \brief Pointer to ogre terra object
public: std::unique_ptr<Ogre::Terra> terra{nullptr};
};

Expand Down
6 changes: 6 additions & 0 deletions ogre2/src/Ogre2Scene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,12 @@ MaterialMapPtr Ogre2Scene::Materials() const
return this->materials;
}

//////////////////////////////////////////////////
const std::vector<std::weak_ptr<Ogre2Heightmap>> &Ogre2Scene::Heightmaps() const
{
return this->heightmaps;
}

//////////////////////////////////////////////////
DirectionalLightPtr Ogre2Scene::CreateDirectionalLightImpl(unsigned int _id,
const std::string &_name)
Expand Down
22 changes: 22 additions & 0 deletions ogre2/src/Ogre2SegmentationMaterialSwitcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <ignition/common/Console.hh>

#include "ignition/rendering/ogre2/Ogre2Heightmap.hh"
#include "ignition/rendering/ogre2/Ogre2Scene.hh"
#include "ignition/rendering/ogre2/Ogre2Visual.hh"
#include "ignition/rendering/RenderTypes.hh"
Expand Down Expand Up @@ -317,6 +318,18 @@ void Ogre2SegmentationMaterialSwitcher::cameraPreRenderScene(
this->instancesCount.clear();
this->takenColors.clear();
this->coloredLabel.clear();

// disable heightmaps in segmentation camera sensor
// until we support changing its material based on input label
// TODO(anyone) add support for heightmaps with the segmentation camera
// https://github.com/ignitionrobotics/ign-rendering/issues/444
auto heightmaps = this->scene->Heightmaps();
for (auto h : heightmaps)
{
auto heightmap = h.lock();
if (heightmap)
heightmap->Parent()->SetVisible(false);
}
}

////////////////////////////////////////////////
Expand All @@ -326,6 +339,15 @@ void Ogre2SegmentationMaterialSwitcher::cameraPostRenderScene(
// restore item to use pbs hlms material
for (const auto &[subItem, dataBlock] : this->datablockMap)
subItem->setDatablock(dataBlock);

// re-enable heightmaps
auto heightmaps = this->scene->Heightmaps();
for (auto h : heightmaps)
{
auto heightmap = h.lock();
if (heightmap)
heightmap->Parent()->SetVisible(true);
}
}

////////////////////////////////////////////////
Expand Down

0 comments on commit 084516a

Please sign in to comment.