[NUI] Add Directional Light
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Scene3D / src / public / Light / Light.cs
1 /*
2  * Copyright(c) 2023 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 using System;
19 using System.Runtime.InteropServices;
20 using System.ComponentModel;
21 using Tizen.NUI;
22 using Tizen.NUI.Binding;
23 using Tizen.NUI.BaseComponents;
24
25 namespace Tizen.NUI.Scene3D
26 {
27     /// <summary>
28     /// This class is to define 3D Light source.
29     /// Currently this Light class supports Directional Light that lights every position from the same direction. (e.g, Sun light)
30     /// If a Light object is added on SceneView, the 3D objects in the SceneView are shined the Light.
31     /// NUI Scene3D limits the maximum enabled light count per each SceneView.
32     /// Currently the maximum number is set to 5, and it can be retrieved by using <see cref="MaximumActivatedLightCount"/>.
33     /// If more than 5 enabled Light objects are added on SceneView, SceneView turns on only 5 lights in the order the lights were added.
34     /// This Light can be added to SceneView directly but also it can be added on other View.
35     /// When a parent actor is added to a SceneView, its Light behaves in the SceneView the same as if it were added directly to the SceneView.
36     /// </summary>
37     /// <remarks>
38     /// Light inherits View, so Light color and direction can be controlled by setting View's <see cref="View.Color"/> and <see cref="View.Orientation"/> Property.
39     /// <see cref="View.LookAt(Vector3, Vector3, Vector3, Vector3)"/> method can be used to set light direction easily.
40     /// </remarks>
41     /// <remarks>
42     /// Default light direction is to Z-axis
43     /// </remarks>
44     /// <example>
45     /// <code>
46     /// SceneView sceneView = new SceneView();
47     /// Light light = new Light();
48     /// light.Color = Color.Brown;
49     /// light.LookAt(new Vector3(1.0f, 1.0f, 1.0f));
50     /// sceneView.Add(light);
51     /// </code>
52     /// </example>
53     [EditorBrowsable(EditorBrowsableState.Never)]
54     public class Light : View
55     {
56         internal Light(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
57         {
58         }
59
60         /// <summary>
61         /// Create an initialized Light.
62         /// </summary>
63         [EditorBrowsable(EditorBrowsableState.Never)]
64         public Light() : this(Interop.Light.New(), true)
65         {
66             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
67         }
68
69         /// <summary>
70         /// Copy constructor.
71         /// </summary>
72         /// <param name="light">Source object to copy.</param>
73         [EditorBrowsable(EditorBrowsableState.Never)]
74         public Light(Light light) : this(Interop.Light.NewLight(Light.getCPtr(light)), true)
75         {
76             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
77         }
78
79         /// <summary>
80         /// Maximum Activated Light Count.
81         /// It is possible to add more Lights to the SceneView than the Maximum Activated Light Count,
82         /// but only up to the Maximum Activated Light Count Lights will work.
83         /// </summary>
84         /// <remarks>
85         /// This property is read only.
86         /// </remarks>
87         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
88         [EditorBrowsable(EditorBrowsableState.Never)]
89         public uint MaximumActivatedLightCount
90         {
91             get
92             {
93                 return Interop.Light.GetMaximumEnabledLightCount();
94             }
95         }
96
97         /// <summary>
98         /// The Light is turned on when the Light object is added on SceneView and enabled.
99         /// And checks whether this light is enabled or not.
100         /// </summary>
101         /// <remarks>
102         /// SceneView can turn on only up to maximum enabled light count that can be retrieved by GetMaximumEnabledLightCount().
103         /// </remarks>
104         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
105         [EditorBrowsable(EditorBrowsableState.Never)]
106         public bool IsLightEnabled
107         {
108             get
109             {
110
111                 bool isEnabled = Interop.Light.IsEnabled(SwigCPtr);
112                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
113                 return isEnabled;
114             }
115             set
116             {
117                 Interop.Light.Enable(SwigCPtr, value);
118                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
119             }
120         }
121     }
122 }