ModelComponent.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright (C) 2009-2023, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Scene/Components/SceneComponent.h>
  7. #include <AnKi/Scene/Spatial.h>
  8. #include <AnKi/Resource/Forward.h>
  9. #include <AnKi/Util/WeakArray.h>
  10. #include <AnKi/Renderer/RenderQueue.h>
  11. namespace anki {
  12. /// @addtogroup scene
  13. /// @{
  14. /// Holds geometry and material information.
  15. class ModelComponent final : public SceneComponent
  16. {
  17. ANKI_SCENE_COMPONENT(ModelComponent)
  18. public:
  19. ModelComponent(SceneNode* node);
  20. ~ModelComponent();
  21. void loadModelResource(CString filename);
  22. const ModelResourcePtr& getModelResource() const
  23. {
  24. return m_model;
  25. }
  26. Bool isEnabled() const
  27. {
  28. return m_model.isCreated();
  29. }
  30. Bool getCastsShadow() const
  31. {
  32. return m_castsShadow;
  33. }
  34. void setupRenderableQueueElements(U32 lod, RenderingTechnique technique, StackMemoryPool& tmpPool,
  35. WeakArray<RenderableQueueElement>& outRenderables) const;
  36. void setupRayTracingInstanceQueueElements(U32 lod, RenderingTechnique technique, StackMemoryPool& tmpPool,
  37. WeakArray<RayTracingInstanceQueueElement>& outRenderables) const;
  38. private:
  39. class PatchInfo
  40. {
  41. public:
  42. U32 m_gpuSceneUniformsOffset = kMaxU32;
  43. U32 m_gpuSceneMeshLodsIndex = kMaxU32;
  44. RenderingTechniqueBit m_techniques;
  45. };
  46. SceneNode* m_node = nullptr;
  47. SkinComponent* m_skinComponent = nullptr;
  48. Spatial m_spatial;
  49. ModelResourcePtr m_model;
  50. SegregatedListsGpuMemoryPoolToken m_gpuSceneUniforms;
  51. U32 m_gpuSceneTransformsIndex = kMaxU32;
  52. DynamicArray<PatchInfo> m_patchInfos;
  53. Bool m_dirty : 1 = true;
  54. Bool m_castsShadow : 1 = false;
  55. Bool m_movedLastFrame : 1 = true;
  56. Bool m_firstTimeUpdate : 1 = true; ///< Extra flag in case the component is added in a node that hasn't been moved.
  57. RenderingTechniqueBit m_presentRenderingTechniques = RenderingTechniqueBit::kNone;
  58. Error update(SceneComponentUpdateInfo& info, Bool& updated);
  59. void onOtherComponentRemovedOrAdded(SceneComponent* other, Bool added);
  60. };
  61. /// @}
  62. } // end namespace anki