17 #ifndef GZ_RENDERING_BASE_BASENODE_HH_
18 #define GZ_RENDERING_BASE_BASENODE_HH_
31 inline namespace GZ_RENDERING_VERSION_NAMESPACE {
42 public:
virtual NodePtr Parent()
const override = 0;
45 public:
virtual void RemoveParent()
override;
52 public:
virtual math::Pose3d InitialLocalPose()
const override;
54 public:
virtual void SetLocalPose(
const math::Pose3d &_pose)
override;
56 public:
virtual void SetLocalPosition(
double _x,
double _y,
double _z)
59 public:
virtual void SetLocalPosition(
const math::Vector3d &_position)
64 public:
virtual void SetLocalRotation(
double _r,
double _p,
double _y)
67 public:
virtual void SetLocalRotation(
double _w,
double _x,
double _y,
75 public:
virtual void SetWorldPose(
const math::Pose3d &_pose)
override;
79 public:
virtual void SetWorldPosition(
double _x,
double _y,
double _z)
82 public:
virtual void SetWorldPosition(
const math::Vector3d &_position)
87 public:
virtual void SetWorldRotation(
double _r,
double _p,
double _y)
90 public:
virtual void SetWorldRotation(
double _w,
double _x,
double _y,
101 public:
virtual void SetOrigin(
double _x,
double _y,
double _z)
override;
103 public:
virtual void SetOrigin(
const math::Vector3d &_origin)
override;
109 public:
virtual void SetLocalScale(
double _scale)
override;
112 public:
virtual void SetLocalScale(
double _x,
double _y,
double _z)
116 public:
virtual void SetLocalScale(
const math::Vector3d &_scale)
override;
122 public:
virtual void SetWorldScale(
double _scale)
override;
125 public:
virtual void SetWorldScale(
double _x,
double _y,
double _z)
129 public:
virtual void SetWorldScale(
const math::Vector3d &_scale)
override;
132 public:
virtual void Scale(
double _scale)
override;
135 public:
virtual void Scale(
double _x,
double _y,
double _z)
override;
138 public:
virtual void Scale(
const math::Vector3d &_scale)
override;
141 public:
virtual bool InheritScale()
const override = 0;
143 public:
virtual void Destroy()
override;
145 public:
virtual unsigned int ChildCount()
const override;
147 public:
virtual bool HasChild(
ConstNodePtr _child)
const override;
149 public:
virtual bool HasChildId(
unsigned int _id)
const override;
151 public:
virtual bool HasChildName(
const std::string &_name)
const
154 public:
virtual NodePtr ChildById(
unsigned int _id)
const override;
159 public:
virtual NodePtr ChildByIndex(
unsigned int _index)
const override;
161 public:
virtual void AddChild(
NodePtr _child)
override;
165 public:
virtual NodePtr RemoveChildById(
unsigned int _id)
override;
170 public:
virtual NodePtr RemoveChildByIndex(
unsigned int _index)
override;
172 public:
virtual void RemoveChildren()
override;
174 public:
virtual void PreRender()
override;
184 public:
virtual bool HasUserData(
const std::string &_key)
const override;
186 protected:
virtual void PreRenderChildren();
188 protected:
virtual math::Pose3d RawLocalPose()
const = 0;
190 protected:
virtual void SetRawLocalPose(
const math::Pose3d &_pose) = 0;
194 protected:
virtual bool AttachChild(
NodePtr _child) = 0;
196 protected:
virtual bool DetachChild(
NodePtr _child) = 0;
200 protected:
virtual void SetLocalScaleImpl(
207 protected:
bool initialLocalPoseSet =
false;
233 NodePtr parent = this->Parent();
237 auto baseShared = this->shared_from_this();
238 auto thisShared = std::dynamic_pointer_cast<BaseNode<T>>(baseShared);
239 parent->RemoveChild(thisShared);
248 if (_child->Id() == this->Id())
254 if (this->AttachChild(_child))
256 this->Children()->Add(_child);
264 NodePtr child = this->Children()->Remove(_child);
265 if (child) this->DetachChild(child);
273 NodePtr child = this->Children()->RemoveById(_id);
274 if (child) this->DetachChild(child);
282 NodePtr child = this->Children()->RemoveByName(_name);
283 if (child) this->DetachChild(child);
291 NodePtr child = this->Children()->RemoveByIndex(_index);
292 if (child) this->DetachChild(child);
300 for (
unsigned int i = this->ChildCount(); i > 0; --i)
302 this->RemoveChildByIndex(i - 1);
311 this->PreRenderChildren();
318 unsigned int count = this->ChildCount();
320 for (
unsigned int i = 0; i < count; ++i)
322 this->ChildByIndex(i)->PreRender();
331 pose.
Pos() += pose.
Rot() * this->origin;
341 gzerr <<
"Unable to set non-finite pose [" << _pose
342 <<
"] to node [" << this->Name() <<
"]" <<
std::endl;
347 pose.
Pos() = pose.
Pos() - pose.
Rot() * this->origin;
349 if (!initialLocalPoseSet)
351 this->initialLocalPose = pose;
352 this->initialLocalPoseSet =
true;
355 this->SetRawLocalPose(pose);
362 return this->initialLocalPose;
369 return this->LocalPose().Pos();
385 gzerr <<
"Unable to set non-finite position [" << _position
386 <<
"] to node [" << this->Name() <<
"]" <<
std::endl;
391 pose.
Pos() = _position;
392 this->SetLocalPose(pose);
399 return this->LocalPose().Rot();
423 gzerr <<
"Unable to set non-finite rotation [" << _rotation
424 <<
"] to node [" << this->Name() <<
"]" <<
std::endl;
429 pose.
Rot() = _rotation;
430 this->SetLocalPose(pose);
437 NodePtr parent = this->Parent();
445 return parent->WorldPose() * pose;
453 this->SetLocalPose(pose);
467 return this->WorldPose().Pos();
475 pose.
Pos() = _position;
476 this->SetWorldPose(pose);
483 return this->WorldPose().Rot();
506 pose.
Rot() = _rotation;
507 this->SetWorldPose(pose);
514 NodePtr parent = this->Parent();
521 return parent->WorldPose().Inverse() * _pose;
544 gzerr <<
"Unable to set non-finite origin [" << _origin
545 <<
"] to node [" << this->Name() <<
"]" <<
std::endl;
548 this->origin = _origin;
570 this->SetLocalScaleImpl(_scale);
571 this->SetLocalPose(rawPose);
580 if (!this->InheritScale() || !this->HasParent())
585 return scale * this->Parent()->WorldScale();
607 if (this->InheritScale() && this->HasParent())
608 toScale = this->Parent()->WorldScale();
610 this->SetLocalScale(_scale / toScale);
631 this->SetLocalScale(_scale * this->LocalScale());
639 this->RemoveParent();
646 return this->Children()->Size();
653 return this->Children()->Contains(_child);
660 return this->Children()->ContainsId(_id);
667 return this->Children()->ContainsName(_name);
674 return this->Children()->GetById(_id);
681 return this->Children()->GetByName(_name);
688 return this->Children()->GetByIndex(_index);
696 this->userData[_key] = _value;
704 auto it = this->userData.find(_key);
705 if (it != this->userData.end())
714 return this->userData.find(_key) != this->userData.end();