From 9d87388a15869b289e73ec66f3f9544a09228bd1 Mon Sep 17 00:00:00 2001 From: Ashton Larkin Date: Mon, 20 Sep 2021 17:10:26 -0400 Subject: [PATCH] trying to clone capsule geometries Signed-off-by: Ashton Larkin --- .../ignition/rendering/base/BaseCapsule.hh | 26 +++++++++++++++++++ .../ignition/rendering/base/BaseGeometry.hh | 2 ++ include/ignition/rendering/base/BaseMesh.hh | 2 +- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/ignition/rendering/base/BaseCapsule.hh b/include/ignition/rendering/base/BaseCapsule.hh index 463c1a61c..02e80db28 100644 --- a/include/ignition/rendering/base/BaseCapsule.hh +++ b/include/ignition/rendering/base/BaseCapsule.hh @@ -18,6 +18,8 @@ #ifndef IGNITION_RENDERING_BASECAPSULE_HH_ #define IGNITION_RENDERING_BASECAPSULE_HH_ +#include + #include "ignition/rendering/Capsule.hh" #include "ignition/rendering/base/BaseObject.hh" @@ -50,6 +52,9 @@ namespace ignition // Documentation inherited public: virtual double Length() const override; + // Documentation inherited + public: virtual GeometryPtr Clone() const override; + /// \brief Radius of the capsule protected: double radius = 0.5; @@ -103,6 +108,27 @@ namespace ignition { return this->length; } + + ///////////////////////////////////////////////// + template + GeometryPtr BaseCapsule::Clone() const + { + if (!this->Scene()) + { + ignerr << "Cloning a Capsule failed because the capsule to be " + << "cloned does not belong to a scene.\n"; + return nullptr; + } + + auto result = this->Scene()->CreateCapsule(); + if (result) + { + result->SetRadius(this->Radius()); + result->SetLength(this->Length()); + } + + return result; + } } } } diff --git a/include/ignition/rendering/base/BaseGeometry.hh b/include/ignition/rendering/base/BaseGeometry.hh index 8d5cf685e..337262037 100644 --- a/include/ignition/rendering/base/BaseGeometry.hh +++ b/include/ignition/rendering/base/BaseGeometry.hh @@ -51,6 +51,7 @@ namespace ignition public: virtual void SetMaterial(MaterialPtr _material, bool _unique = true) override = 0; + // Documentation inherited public: virtual GeometryPtr Clone() const override; // Documentation inherited @@ -98,6 +99,7 @@ namespace ignition template GeometryPtr BaseGeometry::Clone() const { + ignwarn << "Clone functionality for Geometry does not exist yet.\n"; return nullptr; } diff --git a/include/ignition/rendering/base/BaseMesh.hh b/include/ignition/rendering/base/BaseMesh.hh index ca0858a5f..b3c0b9f2a 100644 --- a/include/ignition/rendering/base/BaseMesh.hh +++ b/include/ignition/rendering/base/BaseMesh.hh @@ -329,7 +329,7 @@ namespace ignition { if (!this->Scene()) { - ignerr << "Cloning a geometry failed because the geometry to be " + ignerr << "Cloning a mesh failed because the mesh to be " << "cloned does not belong to a scene.\n"; return nullptr; }