1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef CORE_ECS_MORPHINGSYSTEM_H 17 #define CORE_ECS_MORPHINGSYSTEM_H 18 19 #include <ComponentTools/component_query.h> 20 #include <PropertyTools/property_api_impl.h> 21 22 #include <3d/ecs/components/morph_component.h> 23 #include <3d/ecs/systems/intf_morphing_system.h> 24 #include <3d/render/intf_render_data_store_morph.h> 25 #include <base/containers/array_view.h> 26 #include <base/containers/unordered_map.h> 27 #include <base/containers/vector.h> 28 #include <core/ecs/intf_ecs.h> 29 #include <core/namespace.h> 30 #include <render/namespace.h> 31 32 RENDER_BEGIN_NAMESPACE() 33 class IRenderContext; 34 RENDER_END_NAMESPACE() 35 36 CORE3D_BEGIN_NAMESPACE() 37 class IRenderHandleComponentManager; 38 class INodeComponentManager; 39 class IMeshComponentManager; 40 class IMorphComponentManager; 41 class IRenderMeshComponentManager; 42 struct MeshComponent; 43 struct MorphComponent; 44 45 class MorphingSystem final : public IMorphingSystem, 46 private CORE_NS::IEcs::EntityListener, 47 private CORE_NS::IEcs::ComponentListener { 48 public: 49 explicit MorphingSystem(CORE_NS::IEcs& ecs); 50 ~MorphingSystem() override; 51 BASE_NS::string_view GetName() const override; 52 BASE_NS::Uid GetUid() const override; 53 CORE_NS::IPropertyHandle* GetProperties() override; 54 const CORE_NS::IPropertyHandle* GetProperties() const override; 55 void SetProperties(const CORE_NS::IPropertyHandle&) override; 56 57 bool IsActive() const override; 58 void SetActive(bool state) override; 59 60 void Initialize() override; 61 void Uninitialize() override; 62 bool Update(bool frameRenderingQueued, uint64_t time, uint64_t delta) override; 63 const CORE_NS::IEcs& GetECS() const override; 64 65 private: 66 void OnEntityEvent( 67 CORE_NS::IEntityManager::EventType type, BASE_NS::array_view<const CORE_NS::Entity> entities) override; 68 void OnComponentEvent(ComponentListener::EventType type, const CORE_NS::IComponentManager& componentManager, 69 BASE_NS::array_view<const CORE_NS::Entity> entities) override; 70 71 bool Morph(const MeshComponent& mesh, const MorphComponent& mc, bool dirty); 72 void SetDataStore(RENDER_NS::IRenderDataStoreManager& manager, const BASE_NS::string_view name); 73 bool active_; 74 CORE_NS::IEcs& ecs_; 75 RENDER_NS::IRenderContext* renderContext_ = nullptr; 76 IRenderDataStoreMorph* dataStore_; 77 INodeComponentManager& nodeManager_; 78 IMeshComponentManager& meshManager_; 79 IMorphComponentManager& morphManager_; 80 IRenderMeshComponentManager& renderMeshManager_; 81 IRenderHandleComponentManager& gpuHandleManager_; 82 83 IMorphingSystem::Properties properties_; 84 CORE_NS::PropertyApiImpl<IMorphingSystem::Properties> MORPHING_SYSTEM_PROPERTIES; 85 uint32_t lastGeneration_ { 0 }; 86 BASE_NS::unordered_map<CORE_NS::Entity, bool> dirty_; 87 BASE_NS::vector<CORE_NS::Entity> reset_; 88 CORE_NS::ComponentQuery nodeQuery_; 89 RenderDataMorph::Submesh currentMorphSubmesh_; 90 }; 91 CORE3D_END_NAMESPACE() 92 #endif // CORE_ECS_MORPHINGSYSTEM_H 93