17 #ifndef GZ_RENDERING_BASE_BASEMESH_HH_
18 #define GZ_RENDERING_BASE_BASEMESH_HH_
22 #include <unordered_map>
32 inline namespace GZ_RENDERING_VERSION_NAMESPACE {
45 public:
virtual bool HasSkeleton()
const override;
49 SkeletonLocalTransforms()
const override;
52 public:
virtual void SetSkeletonLocalTransforms(
61 public:
virtual void SetSkeletonWeights(
66 public:
virtual void SetSkeletonAnimationEnabled(
const std::string &_name,
67 bool _enabled,
bool _loop =
true,
float _weight = 1.0)
override;
70 public:
virtual bool SkeletonAnimationEnabled(
const std::string &_name)
74 public:
virtual void UpdateSkeletonAnimation(
75 std::chrono::steady_clock::duration _time)
override;
77 public:
virtual unsigned int SubMeshCount()
const override;
79 public:
virtual bool HasSubMesh(
ConstSubMeshPtr _subMesh)
const override;
81 public:
virtual bool HasSubMeshName(
const std::string &_name)
const
87 public:
virtual SubMeshPtr SubMeshByIndex(
unsigned int _index)
const
94 public:
virtual void SetMaterial(
const std::string &_name,
95 bool _unique =
true)
override;
98 public:
virtual void SetMaterial(
MaterialPtr _material,
99 bool _unique =
true)
override;
101 public:
virtual void PreRender()
override;
104 public:
virtual GeometryPtr Clone()
const override;
113 public:
virtual void Destroy()
override;
119 protected:
bool ownsMaterial =
false;
142 public:
virtual void SetMaterial(
const std::string &_name,
143 bool _unique =
true)
override;
146 public:
virtual void SetMaterial(
MaterialPtr _material,
147 bool _unique =
true)
override;
151 public:
virtual void SetMaterialImpl(
MaterialPtr _material) = 0;
153 public:
virtual void PreRender()
override;
156 public:
virtual void Destroy()
override;
160 protected:
bool ownsMaterial =
false;
216 gzerr <<
"SetSkeletonWeights not supported for render engine: "
237 std::chrono::steady_clock::duration)
245 return this->SubMeshes()->Size();
252 return this->SubMeshes()->Contains(_subMesh);
259 return this->SubMeshes()->ContainsName(_name);
266 return this->SubMeshes()->GetByName(_name);
273 return this->SubMeshes()->GetByIndex(_index);
280 unsigned int count = this->SubMeshCount();
281 return (count > 0) ? this->SubMeshByIndex(0)->Material() :
290 if (mat) this->SetMaterial(mat, _unique);
299 unsigned int count = this->SubMeshCount();
300 _material = (_unique && count > 0) ? _material->Clone() : _material;
302 for (
unsigned int i = 0; i < count; ++i)
305 subMesh->SetMaterial(_material,
false);
308 if (this->material && this->ownsMaterial)
311 this->ownsMaterial = _unique;
312 this->material = _material;
319 unsigned int count = this->SubMeshCount();
321 for (
unsigned int i = 0; i < count; ++i)
324 subMesh->PreRender();
336 gzerr <<
"Cloning a mesh failed because the mesh to be "
337 <<
"cloned does not belong to a scene.\n";
340 else if (this->meshDescriptor.meshName.empty())
342 gzerr <<
"Cloning a geometry failed because the name of the mesh is "
353 result->SetMaterial(this->
Material());
359 for (
unsigned int i = 0; i < this->SubMeshCount(); ++i)
361 auto existingSubMeshMaterial = this->SubMeshByIndex(i)->Material();
362 if (existingSubMeshMaterial)
363 result->SubMeshByIndex(i)->SetMaterial(existingSubMeshMaterial);
375 return this->meshDescriptor;
382 this->meshDescriptor = _desc;
390 this->SubMeshes()->DestroyAll();
391 if (this->material && this->ownsMaterial)
393 this->material.reset();
416 if (this->material && this->ownsMaterial)
418 this->material.reset();
427 if (mat) this->SetMaterial(mat, _unique);
434 _material = (_unique) ? _material->Clone() : _material;
437 bool origUnique = this->ownsMaterial;
439 this->SetMaterialImpl(_material);
441 if (origMaterial && origUnique)
444 this->material = _material;
445 this->ownsMaterial = _unique;
452 return this->material;