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