ModelComponent.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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/RenderStateBucket.h>
  8. #include <AnKi/Scene/Spatial.h>
  9. #include <AnKi/Resource/Forward.h>
  10. #include <AnKi/Util/WeakArray.h>
  11. #include <AnKi/Renderer/RenderQueue.h>
  12. namespace anki {
  13. /// @addtogroup scene
  14. /// @{
  15. /// Holds geometry and material information.
  16. class ModelComponent final : public SceneComponent
  17. {
  18. ANKI_SCENE_COMPONENT(ModelComponent)
  19. public:
  20. ModelComponent(SceneNode* node);
  21. ~ModelComponent();
  22. void loadModelResource(CString filename);
  23. const ModelResourcePtr& getModelResource() const
  24. {
  25. return m_model;
  26. }
  27. Bool isEnabled() const
  28. {
  29. return m_model.isCreated();
  30. }
  31. Bool getCastsShadow() const
  32. {
  33. return m_castsShadow;
  34. }
  35. void setupRenderableQueueElements(U32 lod, RenderingTechnique technique, WeakArray<RenderableQueueElement>& outRenderables) const;
  36. void setupRayTracingInstanceQueueElements(U32 lod, RenderingTechnique technique, WeakArray<RayTracingInstanceQueueElement>& outRenderables) const;
  37. private:
  38. class PatchInfo
  39. {
  40. public:
  41. U32 m_gpuSceneUniformsOffset = kMaxU32;
  42. GpuSceneArrays::MeshLod::Allocation m_gpuSceneMeshLods;
  43. GpuSceneArrays::Renderable::Allocation m_gpuSceneRenderable;
  44. GpuSceneArrays::RenderableAabbGBuffer::Allocation m_gpuSceneRenderableAabbGBuffer;
  45. GpuSceneArrays::RenderableAabbDepth::Allocation m_gpuSceneRenderableAabbDepth;
  46. GpuSceneArrays::RenderableAabbForward::Allocation m_gpuSceneRenderableAabbForward;
  47. Array<RenderStateBucketIndex, U32(RenderingTechnique::kCount)> m_renderStateBucketIndices;
  48. RenderingTechniqueBit m_techniques;
  49. };
  50. SceneNode* m_node = nullptr;
  51. SkinComponent* m_skinComponent = nullptr;
  52. Spatial m_spatial;
  53. ModelResourcePtr m_model;
  54. GpuSceneBufferAllocation m_gpuSceneUniforms;
  55. GpuSceneArrays::Transform::Allocation m_gpuSceneTransforms;
  56. SceneDynamicArray<PatchInfo> m_patchInfos;
  57. Bool m_resourceChanged : 1 = true;
  58. Bool m_castsShadow : 1 = false;
  59. Bool m_movedLastFrame : 1 = true;
  60. Bool m_firstTimeUpdate : 1 = true; ///< Extra flag in case the component is added in a node that hasn't been moved.
  61. RenderingTechniqueBit m_presentRenderingTechniques = RenderingTechniqueBit::kNone;
  62. void freeGpuScene();
  63. Error update(SceneComponentUpdateInfo& info, Bool& updated);
  64. void onOtherComponentRemovedOrAdded(SceneComponent* other, Bool added);
  65. };
  66. /// @}
  67. } // end namespace anki