Skip to content

Commit

Permalink
Suggestions to capsule (#200)
Browse files Browse the repository at this point in the history
Signed-off-by: Louise Poubel <[email protected]>
  • Loading branch information
chapulina committed Mar 19, 2021
1 parent 32c501e commit a7e6bc1
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 139 deletions.
5 changes: 2 additions & 3 deletions include/ignition/rendering/Capsule.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ namespace ignition
{
inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {

/// \class CapsuleVisual CapsuleVisual.hh ignition/rendering/CapsuleVisual
/// \brief A CapsuleVisual geometry class. The visual appearance is based
/// on the type specified.
/// \class Capsule Capsule.hh ignition/rendering/Capsule
/// \brief Geometry for a capsule shape.
class IGNITION_RENDERING_VISIBLE Capsule :
public virtual Geometry
{
Expand Down
4 changes: 2 additions & 2 deletions ogre/include/ignition/rendering/ogre/OgreCapsule.hh
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ namespace ignition
public: virtual void
SetMaterial(MaterialPtr _material, bool _unique) override;

/// \brief Create the Capsule geometry in ogre
private: void Create();
/// \brief Update the capsule geometry in ogre
private: void Update();

/// \brief Capsule should only be created by scene.
private: friend class OgreScene;
Expand Down
85 changes: 42 additions & 43 deletions ogre/src/OgreCapsule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,34 +52,31 @@ OgreCapsule::~OgreCapsule()
// no ops
}

//////////////////////////////////////////////////
Ogre::MovableObject *OgreCapsule::OgreObject() const
{
return this->dataPtr->ogreMesh->OgreObject();
}

//////////////////////////////////////////////////
void OgreCapsule::PreRender()
{
if (this->capsuleDirty)
{
this->Create();
this->Update();
this->capsuleDirty = false;
}
}

//////////////////////////////////////////////////
Ogre::MovableObject *OgreCapsule::OgreObject() const
{
return this->dataPtr->ogreMesh->OgreObject();
}

//////////////////////////////////////////////////
void OgreCapsule::Init()
{
this->Create();
this->Update();
}

//////////////////////////////////////////////////
void OgreCapsule::Destroy()
{
if (!this->Scene())
return;

if (this->dataPtr->ogreMesh)
{
this->dataPtr->ogreMesh->Destroy();
Expand All @@ -94,48 +91,49 @@ void OgreCapsule::Destroy()
}

//////////////////////////////////////////////////
void OgreCapsule::Create()
void OgreCapsule::Update()
{
common::MeshManager *meshMgr = common::MeshManager::Instance();
std::string capsuleMeshName = this->Name() + "_capsule_mesh"
+ "_" + std::to_string(this->radius)
+ "_" + std::to_string(this->length);

// Create new mesh if needed
if (!meshMgr->HasMesh(capsuleMeshName))
{
meshMgr->CreateCapsule(capsuleMeshName, this->radius, this->length, 32, 32);
MeshDescriptor meshDescriptor;
meshDescriptor.mesh = meshMgr->MeshByName(capsuleMeshName);
if (meshDescriptor.mesh == nullptr)
{
ignerr << "Capsule mesh is unavailable in the Mesh Manager" << std::endl;
return;
}
else
}

MeshDescriptor meshDescriptor;
meshDescriptor.mesh = meshMgr->MeshByName(capsuleMeshName);
if (meshDescriptor.mesh == nullptr)
{
ignerr << "Capsule mesh is unavailable in the Mesh Manager" << std::endl;
return;
}

auto visual = std::dynamic_pointer_cast<OgreVisual>(this->Parent());

// clear geom if needed
if (this->dataPtr->ogreMesh)
{
if (visual)
{
auto visual = std::dynamic_pointer_cast<OgreVisual>(this->Parent());
// clear geom if needed
if (this->dataPtr->ogreMesh)
{
if (visual)
{
visual->RemoveGeometry(
std::dynamic_pointer_cast<Geometry>(shared_from_this()));
}
this->dataPtr->ogreMesh->Destroy();
}
this->dataPtr->ogreMesh =
std::dynamic_pointer_cast<OgreMesh>(
this->Scene()->CreateMesh(meshDescriptor));
if (this->dataPtr->material != nullptr)
{
this->dataPtr->ogreMesh->SetMaterial(this->dataPtr->material, false);
}
if (visual)
{
visual->AddGeometry(
std::dynamic_pointer_cast<Geometry>(shared_from_this()));
}
visual->RemoveGeometry(
std::dynamic_pointer_cast<Geometry>(shared_from_this()));
}
this->dataPtr->ogreMesh->Destroy();
}
this->dataPtr->ogreMesh = std::dynamic_pointer_cast<OgreMesh>(
this->Scene()->CreateMesh(meshDescriptor));
if (this->dataPtr->material != nullptr)
{
this->dataPtr->ogreMesh->SetMaterial(this->dataPtr->material, false);
}
if (visual)
{
visual->AddGeometry(
std::dynamic_pointer_cast<Geometry>(shared_from_this()));
}
}

Expand All @@ -155,6 +153,7 @@ void OgreCapsule::SetMaterial(MaterialPtr _material, bool _unique)
return;
}

// Set material for the underlying dynamic renderable
this->dataPtr->ogreMesh->SetMaterial(derived, false);
this->dataPtr->material = derived;
}
Expand Down
8 changes: 2 additions & 6 deletions ogre2/include/ignition/rendering/ogre2/Ogre2Capsule.hh
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,8 @@ namespace ignition
public: virtual void
SetMaterial(MaterialPtr _material, bool _unique) override;

/// \brief Set material to capsule geometry.
/// \param[in] _material Ogre material.
protected: virtual void SetMaterialImpl(Ogre2MaterialPtr _material);

/// \brief Create the Capsule geometry in ogre
private: void Create();
/// \brief Update the capsule geometry in ogre
private: void Update();

/// \brief Capsule should only be created by scene.
private: friend class Ogre2Scene;
Expand Down
87 changes: 39 additions & 48 deletions ogre2/src/Ogre2Capsule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,20 @@ void Ogre2Capsule::PreRender()
{
if (this->capsuleDirty)
{
this->Create();
this->Update();
this->capsuleDirty = false;
}
}

//////////////////////////////////////////////////
void Ogre2Capsule::Init()
{
this->Create();
this->Update();
}

//////////////////////////////////////////////////
void Ogre2Capsule::Destroy()
{
if (!this->Scene())
return;

if (this->dataPtr->ogreMesh)
{
this->dataPtr->ogreMesh->Destroy();
Expand All @@ -93,50 +90,50 @@ void Ogre2Capsule::Destroy()
}
}

////////////////////////////////////////////////
void Ogre2Capsule::Create()
//////////////////////////////////////////////////
void Ogre2Capsule::Update()
{
common::MeshManager *meshMgr = common::MeshManager::Instance();
std::string capsuleMeshName = this->Name() + "_capsule_mesh"
+ "_" + std::to_string(this->radius)
+ "_" + std::to_string(this->length);

// Create new mesh if needed
if (!meshMgr->HasMesh(capsuleMeshName))
{
meshMgr->CreateCapsule(capsuleMeshName, this->radius, this->length, 12, 32);
MeshDescriptor meshDescriptor;
meshDescriptor.mesh = meshMgr->MeshByName(capsuleMeshName);
if (meshDescriptor.mesh == nullptr)
{
ignerr << "Capsule mesh is unavailable in the Mesh Manager" << std::endl;
return;
}
else
meshMgr->CreateCapsule(capsuleMeshName, this->radius, this->length, 32, 32);
}

MeshDescriptor meshDescriptor;
meshDescriptor.mesh = meshMgr->MeshByName(capsuleMeshName);
if (meshDescriptor.mesh == nullptr)
{
ignerr << "Capsule mesh is unavailable in the Mesh Manager" << std::endl;
return;
}

auto visual = std::dynamic_pointer_cast<Ogre2Visual>(this->Parent());

// clear geom if needed
if (this->dataPtr->ogreMesh)
{
if (visual)
{
auto visual = std::dynamic_pointer_cast<Ogre2Visual>(this->Parent());

// clear geom if needed
if (this->dataPtr->ogreMesh)
{
if (visual)
{
visual->RemoveGeometry(
std::dynamic_pointer_cast<Geometry>(shared_from_this()));
}
this->dataPtr->ogreMesh->Destroy();
}
this->dataPtr->ogreMesh =
std::dynamic_pointer_cast<Ogre2Mesh>(
this->Scene()->CreateMesh(meshDescriptor));
if (this->dataPtr->material != nullptr)
{
this->dataPtr->ogreMesh->SetMaterial(this->dataPtr->material, false);
}
if (visual)
{
visual->AddGeometry(
std::dynamic_pointer_cast<Geometry>(shared_from_this()));
}
visual->RemoveGeometry(
std::dynamic_pointer_cast<Geometry>(shared_from_this()));
}
this->dataPtr->ogreMesh->Destroy();
}
this->dataPtr->ogreMesh = std::dynamic_pointer_cast<Ogre2Mesh>(
this->Scene()->CreateMesh(meshDescriptor));
if (this->dataPtr->material != nullptr)
{
this->dataPtr->ogreMesh->SetMaterial(this->dataPtr->material, false);
}
if (visual)
{
visual->AddGeometry(
std::dynamic_pointer_cast<Geometry>(shared_from_this()));
}
}

Expand All @@ -157,14 +154,8 @@ void Ogre2Capsule::SetMaterial(MaterialPtr _material, bool _unique)
}

// Set material for the underlying dynamic renderable
this->dataPtr->ogreMesh->SetMaterial(_material, false);
this->SetMaterialImpl(derived);
}

//////////////////////////////////////////////////
void Ogre2Capsule::SetMaterialImpl(Ogre2MaterialPtr _material)
{
this->dataPtr->material = _material;
this->dataPtr->ogreMesh->SetMaterial(derived, false);
this->dataPtr->material = derived;
}

//////////////////////////////////////////////////
Expand Down
36 changes: 2 additions & 34 deletions ogre2/src/Ogre2Marker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,40 +245,8 @@ void Ogre2Marker::SetType(MarkerType _markerType)
newMesh = this->scene->CreateBox();
break;
case MT_CAPSULE:
{
common::MeshManager *meshMgr = common::MeshManager::Instance();
std::string capsuleMeshName = std::string("marker_capsule_mesh")
+ "_" + std::to_string(0.5)
+ "_" + std::to_string(1.0);
if (!meshMgr->HasMesh(capsuleMeshName))
{
meshMgr->CreateCapsule(capsuleMeshName, 0.5, 1.0, 12, 32);
MeshDescriptor meshDescriptor;
meshDescriptor.mesh = meshMgr->MeshByName(capsuleMeshName);
if (meshDescriptor.mesh == nullptr)
{
ignerr << "Capsule mesh is unavailable in the Mesh Manager"
<< std::endl;
return;
}
else
{
this->dataPtr->mesh =
std::dynamic_pointer_cast<Ogre2Mesh>(
this->Scene()->CreateMesh(meshDescriptor));
if (this->dataPtr->material != nullptr)
{
this->dataPtr->mesh->SetMaterial(this->dataPtr->material, false);
}
if (visual)
{
visual->AddGeometry(
std::dynamic_pointer_cast<Geometry>(shared_from_this()));
}
}
}
}
return;
newMesh = this->scene->CreateCapsule();
break;
case MT_CYLINDER:
newMesh = this->scene->CreateCylinder();
break;
Expand Down
6 changes: 3 additions & 3 deletions src/Capsule_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ void CapsuleTest::Capsule(const std::string &_renderEngine)
capsule->SetMaterial(mat);
MaterialPtr capsuleMat = capsule->Material();
ASSERT_NE(nullptr, capsuleMat);
EXPECT_EQ(math::Color(0.6, 0.7, 0.8), capsuleMat->Ambient());
EXPECT_EQ(math::Color(0.3, 0.8, 0.2), capsuleMat->Diffuse());
EXPECT_EQ(math::Color(0.4, 0.9, 1.0), capsuleMat->Specular());
EXPECT_EQ(math::Color(0.6f, 0.7f, 0.8f), capsuleMat->Ambient());
EXPECT_EQ(math::Color(0.3f, 0.8f, 0.2f), capsuleMat->Diffuse());
EXPECT_EQ(math::Color(0.4f, 0.9f, 1.0f), capsuleMat->Specular());

// Clean up
engine->DestroyScene(scene);
Expand Down
1 change: 1 addition & 0 deletions src/Marker_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ void MarkerTest::Marker(const std::string &_renderEngine)

marker->SetType(MarkerType::MT_CYLINDER);
EXPECT_EQ(MarkerType::MT_CYLINDER, marker->Type());

marker->SetType(MarkerType::MT_NONE);
EXPECT_EQ(MarkerType::MT_NONE, marker->Type());

Expand Down

0 comments on commit a7e6bc1

Please sign in to comment.