• 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 // clang-format off
17 #include <meta/interface/object_macros.h>
18 #include <meta/interface/intf_object_registry.h>
19 // clang-format on
20 
21 #include <scene/base/namespace.h>
22 
23 #include <3d/implementation_uids.h>
24 #include <core/intf_engine.h>
25 #include <core/plugin/intf_plugin.h>
26 #include <core/plugin/intf_plugin_register.h>
27 #include <render/implementation_uids.h>
28 
29 #include <meta/base/plugin.h>
30 
31 #include "application_context.h"
32 #include "asset/asset_object.h"
33 #include "component/animation_component.h"
34 #include "component/camera_component.h"
35 #include "component/environment_component.h"
36 #include "component/generic_component.h"
37 #include "component/layer_component.h"
38 #include "component/light_component.h"
39 #include "component/material_component.h"
40 #include "component/mesh_component.h"
41 #include "component/node_component.h"
42 #include "component/postprocess_component.h"
43 #include "component/text_component.h"
44 #include "component/transform_component.h"
45 #include "core/ecs_object.h"
46 #include "ecs_component/entity_owner_component_info.h"
47 #include "mesh/mesh.h"
48 #include "mesh/mesh_creator.h"
49 #include "mesh/mesh_resource.h"
50 #include "mesh/sampler.h"
51 #include "mesh/submesh.h"
52 #include "mesh/texture.h"
53 #include "node/camera_node.h"
54 #include "node/light_node.h"
55 #include "node/mesh_node.h"
56 #include "node/node.h"
57 #include "node/text_node.h"
58 #include "postprocess/bloom.h"
59 #include "postprocess/postprocess.h"
60 #include "postprocess/tonemap.h"
61 #include "render_configuration.h"
62 #include "render_context.h"
63 #include "resource/ecs_animation.h"
64 #include "resource/environment.h"
65 #include "resource/image.h"
66 #include "resource/material.h"
67 #include "resource/render_resource_manager.h"
68 #include "resource/shader.h"
69 #include "resource/types/animation_type.h"
70 #include "resource/types/environment_type.h"
71 #include "resource/types/gltf_scene_type.h"
72 #include "resource/types/image_type.h"
73 #include "resource/types/material_type.h"
74 #include "resource/types/postprocess_type.h"
75 #include "resource/types/scene_type.h"
76 #include "resource/types/shader_type.h"
77 #include "scene.h"
78 #include "scene_manager.h"
79 #include "serialization/external_node.h"
80 #include "serialization/scene_exporter.h"
81 #include "serialization/scene_importer.h"
82 #include "serialization/scene_ser.h"
83 
84 static CORE_NS::IPluginRegister* gPluginRegistry { nullptr };
85 
CORE_BEGIN_NAMESPACE()86 CORE_BEGIN_NAMESPACE()
87 IPluginRegister& GetPluginRegister()
88 {
89     return *gPluginRegistry;
90 }
91 CORE_END_NAMESPACE()
92 
93 SCENE_BEGIN_NAMESPACE()
94 
95 namespace Internal {
96 void RegisterEngineAccess();
97 void UnregisterEngineAccess();
98 void RegisterAnys();
99 void UnRegisterAnys();
100 void RegisterSerializers();
101 void UnRegisterSerializers();
102 } // namespace Internal
103 
104 using namespace CORE_NS;
105 
RegisterInterfaces(IPluginRegister & pluginRegistry)106 static PluginToken RegisterInterfaces(IPluginRegister& pluginRegistry)
107 {
108     // Initializing dynamic plugin.
109     // Plugin registry access via the provided registry instance which is saved here.
110     gPluginRegistry = &pluginRegistry;
111 
112     pluginRegistry.RegisterTypeInfo(ENTITY_OWNER_COMPONENT_TYPE_INFO);
113 
114     Internal::RegisterAnys();
115     Internal::RegisterEngineAccess();
116     Internal::RegisterSerializers();
117 
118     META_NS::RegisterObjectType<SceneManager>();
119     META_NS::RegisterObjectType<SceneObject>();
120 
121     META_NS::RegisterObjectType<Node>();
122     META_NS::RegisterObjectType<CameraNode>();
123     META_NS::RegisterObjectType<LightNode>();
124     META_NS::RegisterObjectType<MeshNode>();
125     META_NS::RegisterObjectType<TextNode>();
126 
127     META_NS::RegisterObjectType<GenericComponent>();
128     META_NS::RegisterObjectType<CameraComponent>();
129     META_NS::RegisterObjectType<TransformComponent>();
130     META_NS::RegisterObjectType<PostProcessComponent>();
131     META_NS::RegisterObjectType<AnimationComponent>();
132     META_NS::RegisterObjectType<EnvironmentComponent>();
133     META_NS::RegisterObjectType<LayerComponent>();
134     META_NS::RegisterObjectType<LightComponent>();
135     META_NS::RegisterObjectType<MaterialComponent>();
136     META_NS::RegisterObjectType<MeshComponent>();
137     META_NS::RegisterObjectType<RenderMeshComponent>();
138     META_NS::RegisterObjectType<NodeComponent>();
139     META_NS::RegisterObjectType<TextComponent>();
140     META_NS::RegisterObjectType<MorphComponent>();
141 
142     META_NS::RegisterObjectType<EcsObject>();
143     META_NS::RegisterObjectType<Image>();
144     META_NS::RegisterObjectType<Bloom>();
145     META_NS::RegisterObjectType<Tonemap>();
146     META_NS::RegisterObjectType<PostProcess>();
147 
148     META_NS::RegisterObjectType<Environment>();
149     META_NS::RegisterObjectType<EcsAnimation>();
150     META_NS::RegisterObjectType<RenderConfiguration>();
151     META_NS::RegisterObjectType<Material>();
152     META_NS::RegisterObjectType<Shader>();
153     META_NS::RegisterObjectType<SubMesh>();
154     META_NS::RegisterObjectType<Mesh>();
155     META_NS::RegisterObjectType<MeshCreator>();
156     META_NS::RegisterObjectType<MeshResource>();
157     META_NS::RegisterObjectType<Texture>();
158     META_NS::RegisterObjectType<Sampler>();
159 
160     META_NS::RegisterObjectType<AssetObject>();
161 
162     META_NS::RegisterObjectType<AnimationResourceType>();
163     META_NS::RegisterObjectType<SceneResourceType>();
164     META_NS::RegisterObjectType<GltfSceneResourceType>();
165     META_NS::RegisterObjectType<ImageResourceType>();
166     META_NS::RegisterObjectType<ShaderResourceType>();
167     META_NS::RegisterObjectType<EnvironmentResourceType>();
168     META_NS::RegisterObjectType<MaterialResourceType>();
169     META_NS::RegisterObjectType<PostProcessResourceType>();
170     META_NS::RegisterObjectType<SceneNodeSer>();
171     META_NS::RegisterObjectType<SceneExternalNodeSer>();
172     META_NS::RegisterObjectType<ExternalAttachment>();
173     META_NS::RegisterObjectType<SceneExporter>();
174     META_NS::RegisterObjectType<SceneImporter>();
175     META_NS::RegisterObjectType<RenderResourceManager>();
176     META_NS::RegisterObjectType<ExternalNode>();
177 
178     META_NS::RegisterObjectType<ApplicationContext>();
179     META_NS::RegisterObjectType<RenderContext>();
180 
181     return {};
182 }
UnregisterInterfaces(PluginToken)183 static void UnregisterInterfaces(PluginToken)
184 {
185     META_NS::UnregisterObjectType<SceneManager>();
186     META_NS::UnregisterObjectType<SceneObject>();
187 
188     META_NS::UnregisterObjectType<Node>();
189     META_NS::UnregisterObjectType<CameraNode>();
190     META_NS::UnregisterObjectType<LightNode>();
191     META_NS::UnregisterObjectType<MeshNode>();
192     META_NS::UnregisterObjectType<TextNode>();
193 
194     META_NS::UnregisterObjectType<GenericComponent>();
195     META_NS::UnregisterObjectType<CameraComponent>();
196     META_NS::UnregisterObjectType<TransformComponent>();
197     META_NS::UnregisterObjectType<PostProcessComponent>();
198     META_NS::UnregisterObjectType<AnimationComponent>();
199     META_NS::UnregisterObjectType<EnvironmentComponent>();
200     META_NS::UnregisterObjectType<LayerComponent>();
201     META_NS::UnregisterObjectType<LightComponent>();
202     META_NS::UnregisterObjectType<MaterialComponent>();
203     META_NS::UnregisterObjectType<MeshComponent>();
204     META_NS::UnregisterObjectType<RenderMeshComponent>();
205     META_NS::UnregisterObjectType<NodeComponent>();
206     META_NS::UnregisterObjectType<TextComponent>();
207     META_NS::UnregisterObjectType<MorphComponent>();
208 
209     META_NS::UnregisterObjectType<EcsObject>();
210     META_NS::UnregisterObjectType<Image>();
211     META_NS::UnregisterObjectType<Bloom>();
212     META_NS::UnregisterObjectType<Tonemap>();
213     META_NS::UnregisterObjectType<PostProcess>();
214 
215     META_NS::UnregisterObjectType<Environment>();
216     META_NS::UnregisterObjectType<EcsAnimation>();
217     META_NS::UnregisterObjectType<RenderConfiguration>();
218     META_NS::UnregisterObjectType<Material>();
219     META_NS::UnregisterObjectType<Shader>();
220     META_NS::UnregisterObjectType<SubMesh>();
221     META_NS::UnregisterObjectType<Mesh>();
222     META_NS::UnregisterObjectType<MeshCreator>();
223     META_NS::UnregisterObjectType<MeshResource>();
224     META_NS::UnregisterObjectType<Texture>();
225     META_NS::UnregisterObjectType<Sampler>();
226 
227     META_NS::UnregisterObjectType<AssetObject>();
228 
229     META_NS::UnregisterObjectType<AnimationResourceType>();
230     META_NS::UnregisterObjectType<SceneResourceType>();
231     META_NS::UnregisterObjectType<GltfSceneResourceType>();
232     META_NS::UnregisterObjectType<ImageResourceType>();
233     META_NS::UnregisterObjectType<ShaderResourceType>();
234     META_NS::UnregisterObjectType<EnvironmentResourceType>();
235     META_NS::UnregisterObjectType<MaterialResourceType>();
236     META_NS::UnregisterObjectType<PostProcessResourceType>();
237     META_NS::UnregisterObjectType<SceneNodeSer>();
238     META_NS::UnregisterObjectType<SceneExternalNodeSer>();
239     META_NS::UnregisterObjectType<ExternalAttachment>();
240     META_NS::UnregisterObjectType<SceneExporter>();
241     META_NS::UnregisterObjectType<SceneImporter>();
242     META_NS::UnregisterObjectType<RenderResourceManager>();
243     META_NS::UnregisterObjectType<ExternalNode>();
244 
245     META_NS::UnregisterObjectType<ApplicationContext>();
246     META_NS::UnregisterObjectType<RenderContext>();
247 
248     Internal::UnRegisterSerializers();
249     Internal::UnregisterEngineAccess();
250     Internal::UnRegisterAnys();
251 
252     // remove all weak refs still in the object registry referring to scene
253     META_NS::GetObjectRegistry().Purge();
254 
255     GetPluginRegister().UnregisterTypeInfo(ENTITY_OWNER_COMPONENT_TYPE_INFO);
256 }
VersionString()257 static const char* VersionString()
258 {
259     return "2.0";
260 }
261 
262 const BASE_NS::Uid plugin_deps[] { RENDER_NS::UID_RENDER_PLUGIN, CORE3D_NS::UID_3D_PLUGIN,
263     META_NS::META_OBJECT_PLUGIN_UID };
264 
SCENE_END_NAMESPACE()265 SCENE_END_NAMESPACE()
266 
267 extern "C" {
268 #if _MSC_VER
269 _declspec(dllexport)
270 #else
271 __attribute__((visibility("default")))
272 #endif
273     CORE_NS::IPlugin gPluginData { { CORE_NS::IPlugin::UID }, "Scene",
274         /** Version information of the plugin. */
275         CORE_NS::Version { SCENE_NS::UID_SCENE_PLUGIN, SCENE_NS::VersionString }, SCENE_NS::RegisterInterfaces,
276         SCENE_NS::UnregisterInterfaces, SCENE_NS::plugin_deps };
277 }
278