2
0

EntityLatticeTestComponent.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <CommonSampleComponentBase.h>
  10. #include <Utils/Utils.h>
  11. #include <EntityLatticeTestComponent_Traits_Platform.h>
  12. #include <AzCore/Math/Aabb.h>
  13. struct ImGuiContext;
  14. namespace AtomSampleViewer
  15. {
  16. //! Common base class for test components that display a lattice of entities.
  17. class EntityLatticeTestComponent
  18. : public CommonSampleComponentBase
  19. {
  20. public:
  21. AZ_RTTI(EntityLatticeTestComponent, "{73C13F66-6F5B-43D3-B1F0-CB4F7BEA1334}", CommonSampleComponentBase)
  22. static void Reflect(AZ::ReflectContext* context);
  23. // AZ::Component overrides...
  24. void Activate() override;
  25. void Deactivate() override;
  26. protected:
  27. //! Returns total number of instances (width * height * depth)
  28. uint32_t GetInstanceCount() const;
  29. //! Returns world space Aabb for the lattice.
  30. //! The returned Aabb contains all the entity lattice positions. It does not include the mesh Aabb at each position.
  31. AZ::Aabb GetLatticeAabb() const;
  32. //! Call this to render ImGui controls for controlling the size of the lattice.
  33. void RenderImGuiLatticeControls();
  34. //! Destroys and rebuilds the lattice.
  35. virtual void RebuildLattice();
  36. void SetLatticeMaxDimension(uint32_t max);
  37. void SetLatticeDimensions(uint32_t width, uint32_t depth, uint32_t height);
  38. void SetLatticeSpacing(float spaceX, float spaceY, float spaceZ);
  39. void SetLatticeEntityScale(float scale);
  40. void SetIBLExposure(float exposure);
  41. private:
  42. //! Called once before CreateLatticeInstance() is called for each instance so the subclass can prepare for the total number of instances.
  43. virtual void PrepareCreateLatticeInstances(uint32_t instanceCount) = 0;
  44. //! This is called for each entity in the lattice when it is being built. The subclass should attach
  45. //! whatever components are necessary to achieve the desired result.
  46. virtual void CreateLatticeInstance(const AZ::Transform& transform) = 0;
  47. //! This is called after all the instances are created to any final work. Not required.
  48. virtual void FinalizeLatticeInstances() {};
  49. //! Called when the subclass should destroy all of its instances, either because of shutdown or recreation.
  50. virtual void DestroyLatticeInstances() = 0;
  51. void BuildLattice();
  52. protected:
  53. //! Contains the world space Aabb of the lattice positions. Doesn't include the mesh Aabb at each position.
  54. AZ::Aabb m_worldAabb;
  55. private:
  56. // These are signed to avoid casting with imgui controls.
  57. int32_t m_latticeWidth = ENTITY_LATTICE_TEST_COMPONENT_WIDTH;
  58. int32_t m_latticeHeight = ENTITY_LATTICE_TEST_COMPONENT_HEIGHT;
  59. int32_t m_latticeDepth = ENTITY_LATTICE_TEST_COMPONENT_DEPTH;
  60. int32_t m_latticeSizeMax = ENTITY_LATTEST_TEST_COMPONENT_MAX;
  61. float m_spacingX = 5.0f;
  62. float m_spacingY = 5.0f;
  63. float m_spacingZ = 5.0f;
  64. float m_entityScale = 1.0f;
  65. Utils::DefaultIBL m_defaultIbl;
  66. };
  67. } // namespace AtomSampleViewer