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

Visualize wireframes #312

Closed
wants to merge 6 commits into from
Closed
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
8 changes: 8 additions & 0 deletions include/ignition/rendering/Visual.hh
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ namespace ignition
/// material will be returned.
public: virtual MaterialPtr Material() = 0;

/// \brief Enable or disable wireframe
/// \param[in] _show True to enable wireframe
public: virtual void SetWireframe(bool _show) = 0;

/// \brief Get whether wireframe is enabled for this visual.
/// \return True if wireframe is enabled for this visual.
public: virtual bool Wireframe() const = 0;

/// \brief Specify if this visual is visible
/// \param[in] _visible True if this visual should be made visible
public: virtual void SetVisible(bool _visible) = 0;
Expand Down
25 changes: 25 additions & 0 deletions include/ignition/rendering/base/BaseVisual.hh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ namespace ignition
// Documentation inherited.
public: virtual MaterialPtr Material() override;

// Documentation inherited.
public: virtual void SetWireframe(bool _show) override;

// Documentation inherited.
public: virtual bool Wireframe() const override;

// Documentation inherited.
public: virtual void SetVisible(bool _visible) override;

Expand Down Expand Up @@ -136,6 +142,9 @@ namespace ignition

/// \brief The bounding box of the visual
protected: ignition::math::AxisAlignedBox boundingBox;

/// \brief True if wireframe mode is enabled
protected: bool wireframe;
};

//////////////////////////////////////////////////
Expand Down Expand Up @@ -349,6 +358,22 @@ namespace ignition
}
}

//////////////////////////////////////////////////
template <class T>
bool BaseVisual<T>::Wireframe() const
{
return this->wireframe;
}

//////////////////////////////////////////////////
template <class T>
void BaseVisual<T>::SetWireframe(bool _show)
{
ignerr << "SetWireframe(" << _show << ") not supported for "
<< "render engine: " << this->Scene()->Engine()->Name()
<< std::endl;
}

//////////////////////////////////////////////////
template <class T>
void BaseVisual<T>::SetVisible(bool _visible)
Expand Down
13 changes: 13 additions & 0 deletions ogre/include/ignition/rendering/ogre/OgreVisual.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef IGNITION_RENDERING_OGRE_OGREVISUAL_HH_
#define IGNITION_RENDERING_OGRE_OGREVISUAL_HH_

#include <memory>
#include <vector>

#include "ignition/rendering/base/BaseVisual.hh"
Expand All @@ -29,13 +30,22 @@ namespace ignition
{
inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
//
// forward declaration
class OgreVisualPrivate;

class IGNITION_RENDERING_OGRE_VISIBLE OgreVisual :
public BaseVisual<OgreNode>
{
protected: OgreVisual();

public: virtual ~OgreVisual();

// Documentation inherited.
public: virtual void SetWireframe(bool _show) override;

// Documentation inherited.
public: virtual bool Wireframe() const override;

// Documentation inherited.
public: virtual void SetVisible(bool _visible) override;

Expand Down Expand Up @@ -83,6 +93,9 @@ namespace ignition

private: OgreVisualPtr SharedThis();

/// \brief Pointer to private data class
private: std::unique_ptr<OgreVisualPrivate> dataPtr;

private: friend class OgreScene;
};
}
Expand Down
63 changes: 63 additions & 0 deletions ogre/src/OgreVisual.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,79 @@
using namespace ignition;
using namespace rendering;

/// \brief Private data for the Ogre2Visual class
class ignition::rendering::OgreVisualPrivate
{
/// \brief True if wireframe mode is enabled
public: bool wireframe;
};

//////////////////////////////////////////////////
OgreVisual::OgreVisual()
: dataPtr(new OgreVisualPrivate)
{
this->dataPtr->wireframe = false;
}

//////////////////////////////////////////////////
OgreVisual::~OgreVisual()
{
}

//////////////////////////////////////////////////
void OgreVisual::SetWireframe(bool _show)
{
if (this->dataPtr->wireframe == _show)
return;

this->dataPtr->wireframe = _show;
for (unsigned int i = 0; i < this->ogreNode->numAttachedObjects();
i++)
{
Ogre::Entity *entity = nullptr;
Ogre::MovableObject *obj = this->ogreNode->getAttachedObject(i);

entity = dynamic_cast<Ogre::Entity*>(obj);

if (!entity)
continue;

for (unsigned int j = 0; j < entity->getNumSubEntities(); j++)
{
Ogre::SubEntity *subEntity = entity->getSubEntity(j);
Ogre::MaterialPtr entityMaterial = subEntity->getMaterial();
if (entityMaterial.isNull())
continue;

unsigned int techniqueCount, passCount;
Ogre::Technique *technique;
Ogre::Pass *pass;

for (techniqueCount = 0;
techniqueCount < entityMaterial->getNumTechniques();
++techniqueCount)
{
technique = entityMaterial->getTechnique(techniqueCount);

for (passCount = 0; passCount < technique->getNumPasses(); passCount++)
{
pass = technique->getPass(passCount);
if (_show)
pass->setPolygonMode(Ogre::PM_WIREFRAME);
else
pass->setPolygonMode(Ogre::PM_SOLID);
}
}
}
}
}

//////////////////////////////////////////////////
bool OgreVisual::Wireframe() const
{
return this->dataPtr->wireframe;
}

//////////////////////////////////////////////////
void OgreVisual::SetVisible(bool _visible)
{
Expand Down
6 changes: 6 additions & 0 deletions ogre2/include/ignition/rendering/ogre2/Ogre2Visual.hh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ namespace ignition
/// \brief Destructor
public: virtual ~Ogre2Visual();

// Documentation inherited
public: virtual void SetWireframe(bool _show) override;

// Documentation inherited
public: virtual bool Wireframe() const override;

// Documentation inherited.
public: virtual void SetVisible(bool _visible) override;

Expand Down
44 changes: 44 additions & 0 deletions ogre2/src/Ogre2Visual.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,63 @@ using namespace rendering;
/// \brief Private data for the Ogre2Visual class
class ignition::rendering::Ogre2VisualPrivate
{
/// \brief True if wireframe mode is enabled
public: bool wireframe;
};

//////////////////////////////////////////////////
Ogre2Visual::Ogre2Visual()
: dataPtr(new Ogre2VisualPrivate)
{
this->dataPtr->wireframe = false;
}

//////////////////////////////////////////////////
Ogre2Visual::~Ogre2Visual()
{
}

//////////////////////////////////////////////////
void Ogre2Visual::SetWireframe(bool _show)
{
if (this->dataPtr->wireframe == _show)
return;

this->dataPtr->wireframe = _show;
for (unsigned int i = 0; i < this->ogreNode->numAttachedObjects();
i++)
{
Ogre::Item *item = nullptr;
Ogre::MovableObject *obj = this->ogreNode->getAttachedObject(i);

item = dynamic_cast<Ogre::Item*>(obj);

if (!item)
continue;

for (unsigned int j = 0; j < item->getNumSubItems(); j++)
{
Ogre::SubItem *subItem = item->getSubItem(j);
auto datablock = subItem->getDatablock();
auto macroblock = *(datablock->getMacroblock());

if (_show)
macroblock.mPolygonMode = Ogre::PM_WIREFRAME;
else
macroblock.mPolygonMode = Ogre::PM_SOLID;

datablock->setMacroblock(macroblock);
}
}
}

//////////////////////////////////////////////////
bool Ogre2Visual::Wireframe() const
{
return this->dataPtr->wireframe;
}


//////////////////////////////////////////////////
void Ogre2Visual::SetVisible(bool _visible)
{
Expand Down
31 changes: 31 additions & 0 deletions src/Visual_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class VisualTest : public testing::Test,

/// \brief Test getting setting bounding boxes
public: void BoundingBox(const std::string &_renderEngine);

/// \brief Test changing to wireframe
public: void Wireframe(const std::string &_renderEngine);
};

/////////////////////////////////////////////////
Expand Down Expand Up @@ -548,6 +551,34 @@ TEST_P(VisualTest, BoundingBox)
BoundingBox(GetParam());
}

/////////////////////////////////////////////////
void VisualTest::Wireframe(const std::string &_renderEngine)
{
RenderEngine *engine = rendering::engine(_renderEngine);
if (!engine)
{
igndbg << "Engine '" << _renderEngine
<< "' is not supported" << std::endl;
return;
}

ScenePtr scene = engine->CreateScene("scene6");

// create visual
VisualPtr visual = scene->CreateVisual();
ASSERT_NE(nullptr, visual);

// set wireframe
visual->SetWireframe(true);
EXPECT_EQ(true, visual->Wireframe());
}

/////////////////////////////////////////////////
TEST_P(VisualTest, Wireframe)
{
Wireframe(GetParam());
}


INSTANTIATE_TEST_CASE_P(Visual, VisualTest,
RENDER_ENGINE_VALUES,
Expand Down