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 OHOS_RENDER_3D_LIGHT_JS_H
17 #define OHOS_RENDER_3D_LIGHT_JS_H
18 #include <meta/interface/intf_object.h>
19 
20 #include "BaseObjectJS.h"
21 #include "ColorProxy.h"
22 #include "NodeJS.h"
23 
24 class BaseLight : public NodeImpl {
25 public:
26     static constexpr uint32_t ID = 10;
27     enum LightType {
28         /**
29          * Directional light.
30          */
31         DIRECTIONAL = 1,
32         /**
33          * Spotlight.
34          */
35         SPOT = 2,
36         /**
37          * Point light.
38          */
39         POINT = 3,
40     };
41     static void Init(const char* name, napi_env env, napi_value exports,
42         BASE_NS::vector<napi_property_descriptor>& node_props, napi_callback ctor);
43     BaseLight(LightType lt);
44     ~BaseLight() override;
45     static void RegisterEnums(NapiApi::Object exports);
46 
47 protected:
48     void Create(napi_env e, napi_callback_info i);
49     void* GetInstanceImpl(uint32_t id);
50     void DisposeNative(TrueRootObject*);
51     void Finalize(napi_env env, TrueRootObject*);
52 
53 private:
54     napi_value GetlightType(NapiApi::FunctionContext<>& ctx);
55     napi_value GetEnabled(NapiApi::FunctionContext<>& ctx);
56     void SetEnabled(NapiApi::FunctionContext<bool>& ctx);
57 
58     napi_value GetColor(NapiApi::FunctionContext<>& ctx);
59     void SetColor(NapiApi::FunctionContext<NapiApi::Object>& ctx);
60 
61     napi_value GetShadowEnabled(NapiApi::FunctionContext<>& ctx);
62     void SetShadowEnabled(NapiApi::FunctionContext<bool>& ctx);
63 
64     napi_value GetIntensity(NapiApi::FunctionContext<>& ctx);
65     void SetIntensity(NapiApi::FunctionContext<float>& ctx);
66 
67     LightType lightType_;
68     BASE_NS::unique_ptr<ColorProxy> colorProxy_;
69 };
70 
71 class SpotLightJS : BaseObject<SpotLightJS>, BaseLight {
72 public:
73     static constexpr uint32_t ID = 11;
74     static void Init(napi_env env, napi_value exports);
75     SpotLightJS(napi_env, napi_callback_info);
76 
77 private:
78     void* GetInstanceImpl(uint32_t id);
79     void DisposeNative();
80     void Finalize(napi_env env);
81 };
82 
83 class DirectionalLightJS : BaseObject<DirectionalLightJS>, BaseLight {
84 public:
85     static constexpr uint32_t ID = 12;
86     static void Init(napi_env env, napi_value exports);
87     DirectionalLightJS(napi_env, napi_callback_info);
88 
89 private:
90     void* GetInstanceImpl(uint32_t id);
91     void DisposeNative();
92     void Finalize(napi_env env);
93     napi_value GetNear(NapiApi::FunctionContext<>& ctx);
94     void SetNear(NapiApi::FunctionContext<float>& ctx);
95 };
96 class PointLightJS : BaseObject<PointLightJS>, BaseLight {
97 public:
98     static constexpr uint32_t ID = 13;
99     static void Init(napi_env env, napi_value exports);
100     PointLightJS(napi_env, napi_callback_info);
101 
102 private:
103     void* GetInstanceImpl(uint32_t id);
104     void DisposeNative();
105     void Finalize(napi_env env);
106 };
107 
108 #endif // OHOS_RENDER_3D_LIGHT_JS_H
109