1 /*
2  * Copyright (c) 2023 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MODEL_MODEL_LIGHT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MODEL_MODEL_LIGHT_H
18 
19 #include "base/geometry/animatable_float.h"
20 #include "base/geometry/quaternion.h"
21 #include "base/geometry/vec3.h"
22 #include "base/memory/ace_type.h"
23 #include "core/pipeline/pipeline_context.h"
24 #include "model_position.h"
25 
26 namespace OHOS::Ace::NG {
27 enum ModelLightType {
28     INVALID_LIGHT = 0,
29     DIRECTIONAL_LIGHT = 1,
30     POINT_LIGHT = 2,
31     SPOT_LIGHT = 3
32 };
33 
34 class ModelLight : public virtual AceType {
DECLARE_ACE_TYPE(ModelLight,AceType)35     DECLARE_ACE_TYPE(ModelLight, AceType)
36 public:
37     ModelLight(ModelLightType type, const Vec3& color, const AnimatableFloat& intensity,
38         bool shadow, const ModelPosition& position, const Quaternion& rotation)
39         : type_(type), shadow_(shadow), color_(color), intensity_(intensity),
40         position_(position), rotation_(rotation) {};
41     ~ModelLight() override = default;
42 
43     using RenderNodeAnimationCallback = std::function<void()>;
SetContextAndCallback(const WeakPtr<PipelineBase> & context,RenderNodeAnimationCallback && callback)44     void SetContextAndCallback(
45         const WeakPtr<PipelineBase>& context,
46         RenderNodeAnimationCallback&& callback)
47     {
48         intensity_.SetContextAndCallback(context, std::forward<RenderNodeAnimationCallback>(callback));
49         color_.SetContextAndCallbacks(context, std::forward<RenderNodeAnimationCallback>(callback));
50         position_.SetContextAndCallbacks(context, std::forward<RenderNodeAnimationCallback>(callback));
51     }
52 
SetLightType(ModelLightType type)53     void SetLightType(ModelLightType type)
54     {
55         type_ = type;
56     }
57 
SetColor(const OHOS::Ace::Vec3 & color)58     void SetColor(const OHOS::Ace::Vec3& color)
59     {
60         color_ = color;
61     }
62 
SetIntensity(const OHOS::Ace::AnimatableFloat & intensity)63     void SetIntensity(const OHOS::Ace::AnimatableFloat& intensity)
64     {
65         intensity_ = intensity;
66     }
67 
SetLightShadow(bool shadow)68     void SetLightShadow(bool shadow)
69     {
70         shadow_ = shadow;
71     }
72 
SetPosition(const ModelPosition & position)73     void SetPosition(const ModelPosition& position)
74     {
75         position_.SetPosition(position.GetPosition());
76         position_.SetDistance(position.GetDistance());
77         position_.SetIsAngular(position.GetIsAngular());
78     }
79 
SetRotation(const Quaternion & rotation)80     void SetRotation(const Quaternion& rotation)
81     {
82         rotation_ = rotation;
83     }
84 
GetLightType()85     ModelLightType GetLightType() const
86     {
87         return type_;
88     }
89 
GetLightColor()90     const Vec3& GetLightColor() const
91     {
92         return color_;
93     }
94 
GetLightIntensity()95     const AnimatableFloat& GetLightIntensity() const
96     {
97         return intensity_;
98     }
99 
GetLightShadow()100     bool GetLightShadow() const
101     {
102         return shadow_;
103     }
104 
GetPosition()105     const ModelPosition& GetPosition() const
106     {
107         return position_;
108     }
109 
GetRotation()110     const Quaternion& GetRotation() const
111     {
112         return rotation_;
113     }
114 
Print()115     void Print() {}
116 
117 private:
118     ModelLightType type_ = ModelLightType::DIRECTIONAL_LIGHT;
119     bool shadow_ = false;
120     Vec3 color_ { 1.0f, 1.0f, 1.0f };
121     AnimatableFloat intensity_ { 10.0f };
122     ModelPosition position_;
123     Quaternion rotation_;
124 };
125 } // OHOS::Ace::NG
126 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MODEL_MODEL_LIGHT_H
127