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 #include <napi_api.h>
17 
18 #include <base/containers/string.h>
19 #include <base/containers/vector.h>
20 #include <base/util/uid_util.h>
21 #include <core/log.h>
22 #include <core/os/platform_create_info.h>
23 
24 #include <meta/interface/intf_task_queue.h>
25 #include <meta/interface/intf_task_queue_registry.h>
26 
27 #include <scene_plugin/interface/intf_scene.h>
28 
29 #include "CameraJS.h"
30 #include "EnvironmentJS.h"
31 #include "GeometryJS.h"
32 #include "ImageJS.h"
33 #include "LightJS.h"
34 #include "MaterialJS.h"
35 #include "MeshJS.h"
36 #include "NodeJS.h"
37 #include "PostProcJS.h"
38 #include "SceneJS.h"
39 #include "ShaderJS.h"
40 #include "SubMeshJS.h"
41 #include "ToneMapJS.h"
42 #include "AnimationJS.h"
43 
44 #include "scene_adapter/scene_adapter.h"
45 #include "3d_widget_adapter_log.h"
46 
47 void RegisterClasses(napi_env env, napi_value exports);
48 
49 namespace OHOS::Render3D {
50 /*
51  * Function registering all props and functions of ohos.medialibrary module
52  */
Export(napi_env env,napi_value exports)53 static napi_value Export(napi_env env, napi_value exports)
54 {
55     auto sceneAdapter_ = std::make_shared<OHOS::Render3D::SceneAdapter>();
56     sceneAdapter_->LoadPluginsAndInit();
57 
58     napi_value Storage;
59     napi_create_object(env, &Storage);
60 
61     NapiApi::MyInstanceState* mis = new NapiApi::MyInstanceState(env, Storage);
62 
63     auto status = napi_set_instance_data(
64         env,
65         mis,
66         [](napi_env env, void *finalize_data, void *finalize_hint) {
67             auto d = static_cast<NapiApi::MyInstanceState *>(finalize_data);
68             delete d;
69         },
70         nullptr);
71 
72     RegisterClasses(env, exports);
73 
74     return exports;
75 }
76 
77 /*
78  * module define
79  */
80 static napi_module g_module = {
81     .nm_version = 1,
82     .nm_flags = 0,
83     .nm_filename = nullptr,
84     .nm_register_func = Export,
85     .nm_modname = "scene.napi",
86     .nm_priv = (reinterpret_cast<void *>(0)),
87     .reserved = {0}
88 };
89 
90 /*
91  * module register
92  */
Graphics3dKitRegisterModule(void)93 extern "C" __attribute__((constructor)) void Graphics3dKitRegisterModule(void)
94 {
95     WIDGET_LOGD("graphics 3d register");
96     napi_module_register(&g_module);
97 }
98 } // namespace OHOS::Render3D