/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include namespace AtomSampleViewer { class CommonSampleComponentBase : public AZ::Component , public AZ::TransformNotificationBus::MultiHandler , public AZ::EntityBus::MultiHandler { public: AZ_TYPE_INFO(MaterialHotReloadTestComponent, "{7EECDF09-B774-46C1-AD6E-060CE5717C05}"); // AZ::Component overrides... bool ReadInConfig(const AZ::ComponentConfig* baseConfig) override; protected: //! Init and shut down should be called in derived components' Activate() and Deactivate(). //! @param loadDefaultLightingPresets if true, it will scan all lighting presets in the project and load them. void InitLightingPresets(bool loadDefaultLightingPresets = false); void ShutdownLightingPresets(); //! Add a drop down list to select lighting preset for this sample. //! Lighting presets must be loaded before calling this function, otherwise the list will be hide. //! It should be called between ImGui::Begin() and ImGui::End(). //! e.g. Calling it between ImGuiSidebar::Begin() and ImGuiSidebar::End() will embed this list into the side bar. void ImGuiLightingPreset(); //! Load lighting presets from an asset. //! It will clear any presets loaded previously. void LoadLightingPresetsFromAsset(const AZStd::string& assetPath); //! Load lighting presets from an asset. //! Append the presets to the current existing presets. void AppendLightingPresetsFromAsset(const AZStd::string& assetPath); //! Clear all lighting presets. void ClearLightingPresets(); //! Apply lighting presets to the scene. //! Derived samples can override this function to have custom behaviors. virtual void OnLightingPresetSelected(const AZ::Render::LightingPreset& preset); //! Return the AtomSampleViewer EntityContextId, retrieved from the ComponentConfig AzFramework::EntityContextId GetEntityContextId() const; //! Return the AtomSampleViewer camera EntityId, retrieved from the ComponentConfig AZ::EntityId GetCameraEntityId() const; AZ::Render::MeshFeatureProcessorInterface* GetMeshFeatureProcessor() const; void OnLightingPresetEntityShutdown(const AZ::EntityId& entityId); // Preload assets void PreloadAssets(const AZStd::vector& assetList); //! Async asset load AZ::AssetCollectionAsyncLoader m_assetLoadManager; //! Showing the loading progress of preload assets ImGuiProgressList m_imguiProgressList; // The callback might be called more than one time if there are more than one asset are ready in one frame. // Use this flag to prevent OnAllAssetsReadyActivate be called more than one time. bool m_isAllAssetsReady = false; AZStd::string m_sampleName; private: // AZ::TransformNotificationBus::MultiHandler overrides... void OnTransformChanged(const AZ::Transform&, const AZ::Transform&) override; // virtual call back function which is called when all preloaded assets are loaded. virtual void OnAllAssetsReadyActivate() {}; AzFramework::EntityContextId m_entityContextId; AZ::EntityId m_cameraEntityId; mutable AZ::Render::MeshFeatureProcessorInterface* m_meshFeatureProcessor = nullptr; //! All loaded lighting presets. AZStd::vector m_lightingPresets; //! Lights created by lighting presets. AZStd::vector m_lightHandles; //! Post process entity to handle ExposureControlSettings. AZ::Entity* m_postProcessEntity = nullptr; //! Dirty flag is set to true when m_lightingPresets is modified. bool m_lightingPresetsDirty = true; //! Current active lighting preset. constexpr static int32_t InvalidLightingPresetIndex = -1; int32_t m_currentLightingPresetIndex = InvalidLightingPresetIndex; }; } // namespace AtomSampleViewer