• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SCENE_SRC_CORE_ECS_H
17 #define SCENE_SRC_CORE_ECS_H
18 
19 #include <ComponentTools/component_query.h>
20 #include <scene/base/types.h>
21 #include <scene/ext/intf_ecs_context.h>
22 #include <text_3d/ecs/components/text_component.h>
23 #include <3d/ecs/components/animation_component.h>
24 #include <3d/ecs/components/animation_state_component.h>
25 #include <3d/ecs/components/camera_component.h>
26 #include <3d/ecs/components/environment_component.h>
27 #include <3d/ecs/components/layer_component.h>
28 #include <3d/ecs/components/light_component.h>
29 #include <3d/ecs/components/local_matrix_component.h>
30 #include <3d/ecs/components/material_component.h>
31 #include <3d/ecs/components/mesh_component.h>
32 #include <3d/ecs/components/name_component.h>
33 #include <3d/ecs/components/node_component.h>
34 #include <3d/ecs/components/post_process_component.h>
35 #include <3d/ecs/components/render_configuration_component.h>
36 #include <3d/ecs/components/render_handle_component.h>
37 #include <3d/ecs/components/render_mesh_component.h>
38 #include <3d/ecs/components/transform_component.h>
39 #include <3d/ecs/components/uri_component.h>
40 #include <3d/ecs/components/world_matrix_component.h>
41 #include <3d/ecs/systems/intf_node_system.h>
42 #include <3d/util/intf_picking.h>
43 #include <core/ecs/intf_ecs.h>
44 #include <core/intf_engine.h>
45 #include <render/intf_render_context.h>
46 
47 #include "../ecs_component/entity_owner_component_info.h"
48 #include "ecs_listener.h"
49 
50 SCENE_BEGIN_NAMESPACE()
51 
52 class InternalScene;
53 
54 class Ecs : public META_NS::IntroduceInterfaces<IEcsContext>, private EcsListener {
55 public:
56     bool Initialize(const BASE_NS::shared_ptr<IInternalScene>& scene);
57     void Uninitialize();
58 
59     CORE3D_NS::ISceneNode* GetNode(CORE_NS::Entity ent);
60     const CORE3D_NS::ISceneNode* GetNode(CORE_NS::Entity ent) const;
61 
62     const CORE3D_NS::ISceneNode* FindNode(BASE_NS::string_view path) const;
63     const CORE3D_NS::ISceneNode* FindNodeParent(BASE_NS::string_view path) const;
64 
65     bool SetNodeParentAndName(CORE_NS::Entity ent, BASE_NS::string_view name, const CORE3D_NS::ISceneNode* parent);
66 
67     BASE_NS::string GetPath(const CORE3D_NS::ISceneNode* node) const;
68     bool IsNodeEntity(CORE_NS::Entity ent) const;
69     bool RemoveEntity(CORE_NS::Entity ent);
70 
71 public:
72     bool CreateUnnamedRootNode() override;
73 
74     CORE_NS::IComponentManager* FindComponent(BASE_NS::string_view name) const override;
GetNativeEcs()75     CORE_NS::IEcs::Ptr GetNativeEcs() const override
76     {
77         return ecs;
78     }
79 
80     void AddDefaultComponents(CORE_NS::Entity ent) const override;
81     BASE_NS::string GetPath(CORE_NS::Entity ent) const override;
82     IEcsObject::Ptr GetEcsObject(CORE_NS::Entity) override;
83     void RemoveEcsObject(const IEcsObject::ConstPtr&) override;
84     CORE_NS::Entity GetRootEntity() const override;
85     CORE_NS::EntityReference GetEntityReference(CORE_NS::Entity) override;
86 
87 public:
88     CORE_NS::IEcs::Ptr ecs;
89 
90     CORE3D_NS::IAnimationComponentManager* animationComponentManager {};
91     CORE3D_NS::IAnimationStateComponentManager* animationStateComponentManager {};
92     CORE3D_NS::ICameraComponentManager* cameraComponentManager {};
93 
94     CORE3D_NS::IEnvironmentComponentManager* envComponentManager {};
95     CORE3D_NS::ILayerComponentManager* layerComponentManager {};
96     CORE3D_NS::ILightComponentManager* lightComponentManager {};
97     CORE3D_NS::IMaterialComponentManager* materialComponentManager {};
98     CORE3D_NS::IMeshComponentManager* meshComponentManager {};
99     CORE3D_NS::INameComponentManager* nameComponentManager {};
100     CORE3D_NS::INodeComponentManager* nodeComponentManager {};
101     CORE3D_NS::IRenderMeshComponentManager* renderMeshComponentManager {};
102     CORE3D_NS::IRenderHandleComponentManager* rhComponentManager {};
103     CORE3D_NS::ITransformComponentManager* transformComponentManager {};
104     CORE3D_NS::IUriComponentManager* uriComponentManager {};
105     CORE3D_NS::IRenderConfigurationComponentManager* renderConfigComponentManager {};
106     CORE3D_NS::IPostProcessComponentManager* postProcessComponentManager {};
107     CORE3D_NS::ILocalMatrixComponentManager* localMatrixComponentManager {};
108     CORE3D_NS::IWorldMatrixComponentManager* worldMatrixComponentManager {};
109 
110     SCENE_NS::IEntityOwnerComponentManager* entityOwnerComponentManager {};
111     TEXT3D_NS::ITextComponentManager* textComponentManager {};
112     BASE_NS::unique_ptr<CORE_NS::ComponentQuery> meshQuery {};
113     BASE_NS::unique_ptr<CORE_NS::ComponentQuery> materialQuery {};
114     BASE_NS::unique_ptr<CORE_NS::ComponentQuery> animationQuery {};
115 
116     CORE3D_NS::INodeSystem* nodeSystem {};
117     CORE3D_NS::IPicking* picking {};
118 
119 private:
120     template<typename Manager>
121     Manager* GetCoreManager();
122 
123 private:
124     BASE_NS::weak_ptr<IInternalScene> scene_;
125     CORE3D_NS::ISceneNode* rootNode_ {};
126     BASE_NS::unordered_map<BASE_NS::string, CORE_NS::IComponentManager*> components_;
127 };
128 
129 CORE_NS::Entity CopyExternalAsChild(const IEcsObject& parent, const IEcsObject& extChild);
130 CORE_NS::Entity CopyExternalAsChild(const IEcsObject& parent, const IScene& extScene);
131 
132 SCENE_END_NAMESPACE()
133 
134 #endif