EntityLatticeTestComponent.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. * its licensors.
  4. *
  5. * For complete copyright and license terms please see the LICENSE at the root of this
  6. * distribution (the "License"). All use of this software is governed by the License,
  7. * or, if provided, by the license below or the license accompanying this file. Do not
  8. * remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. *
  11. */
  12. #pragma once
  13. #include <CommonSampleComponentBase.h>
  14. #include <Utils/Utils.h>
  15. struct ImGuiContext;
  16. namespace AtomSampleViewer
  17. {
  18. //! Common base class for test components that display a lattice of entities.
  19. class EntityLatticeTestComponent
  20. : public CommonSampleComponentBase
  21. {
  22. public:
  23. AZ_RTTI(EntityLatticeTestComponent, "{73C13F66-6F5B-43D3-B1F0-CB4F7BEA1334}", CommonSampleComponentBase)
  24. static void Reflect(AZ::ReflectContext* context);
  25. // AZ::Component overrides...
  26. void Activate() override;
  27. void Deactivate() override;
  28. protected:
  29. //! Returns total number of instances (width * height * depth)
  30. uint32_t GetInstanceCount() const;
  31. //! Call this to render ImGui controls for controlling the size of the lattice.
  32. void RenderImGuiLatticeControls();
  33. //! Destroys and rebuilds the lattice.
  34. virtual void RebuildLattice();
  35. void SetLatticeDimensions(uint32_t width, uint32_t depth, uint32_t height);
  36. private:
  37. //! Called once before CreateLatticeInstance() is called for each instance so the subclass can prepare for the total number of instances.
  38. virtual void PrepareCreateLatticeInstances(uint32_t instanceCount) = 0;
  39. //! This is called for each entity in the lattice when it is being built. The subclass should attach
  40. //! whatever components are necessary to achieve the desired result.
  41. virtual void CreateLatticeInstance(const AZ::Transform& transform) = 0;
  42. //! This is called after all the instances are created to any final work. Not required.
  43. virtual void FinalizeLatticeInstances() {};
  44. //! Called when the subclass should destroy all of its instances, either because of shutdown or recreation.
  45. virtual void DestroyLatticeInstances() = 0;
  46. void BuildLattice();
  47. // These are signed to avoid casting with imgui controls.
  48. int32_t m_latticeWidth = 5;
  49. int32_t m_latticeHeight = 5;
  50. int32_t m_latticeDepth = 5;
  51. Utils::DefaultIBL m_defaultIbl;
  52. };
  53. } // namespace AtomSampleViewer