[NUI] Change directory of Tizen.NUI.Scene3D ModelView
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Scene3D / src / public / Controls / ModelView.cs
1 /*
2  * Copyright(c) 2021 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.Binding;
22 using Tizen.NUI.BaseComponents;
23
24 namespace Tizen.NUI.Scene3D
25 {
26     /// <summary>
27     /// ModelView is a View to show 3D model objects.
28     /// ModelView supports to load glTF 2.0 and DLI models for the input format
29     /// and also supports Physically Based Rendering with Image Based Lighting.
30     ///
31     /// The Animations defined in the glTF or DLI models are also loaded and can be retrieved by using GetAnimation() method.
32     /// The number of animation is also retrieved by GetAnimationCount() method.
33     ///
34     /// By default, The loaded model has it's own position and size which are defined in vertex buffer regardless of the View size.
35     /// The model can be resized and repositioned to fit to the ModelView with UseSizeOfView and UseCenterOfView properties.
36     /// </summary>
37     /// <code>
38     /// ModelView modelView = new ModelView(modelUrl)
39     /// {
40     ///     Size = new Size(width, height),
41     ///     PositionUsesPivotPoint = true,
42     ///     PivotPoint = PivotPoint.Center,
43     ///     ParentOrigin = ParentOrigin.Center,
44     ///     UseSizeOfView = true,
45     ///     UseCenterOfView = true,
46     /// };
47     /// modelView.SetImageBasedLightSource(diffuseUrl, specularUrl, scaleFactor);
48     /// window.Add(modelView);
49     /// int animationCount = modelView.GetAnimationCount();
50     /// if(animationCount > 0)
51     /// {
52     ///     modelView.GetAnimation(0).Play();
53     /// }
54     /// </code>
55     // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
56     [EditorBrowsable(EditorBrowsableState.Never)]
57     public class ModelView : View
58     {
59         private bool useSizeOfView = false;
60         private bool useCenterOfView = false;
61
62         internal ModelView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
63         {
64         }
65
66         /// <summary>
67         /// Create an initialized ModelView.
68         /// </summary>
69         /// <param name="modelPath">model file path.(e.g., glTF, and DLI).</param>
70         /// <param name="resourcePath">resource file path that includes binary, image etc.</param>
71         /// <note> If resourcePath is empty, the parent directory path of modelPath is used for resource path. </note>
72         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
73         [EditorBrowsable(EditorBrowsableState.Never)]
74         public ModelView(string modelPath, string resourcePath = "") : this(Interop.ModelView.ModelViewNew(modelPath, resourcePath), true)
75         {
76             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
77         }
78
79         /// <summary>
80         /// Copy constructor.
81         /// </summary>
82         /// <param name="modelView">Handle to an object.</param>
83         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
84         [EditorBrowsable(EditorBrowsableState.Never)]
85         public ModelView(ModelView modelView) : this(Interop.ModelView.NewModelView(ModelView.getCPtr(modelView)), true)
86         {
87             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
88         }
89
90         /// <summary>
91         /// Retrieves model root View.
92         /// </summary>
93         /// <note>
94         /// This ModelRoot means a root View that contains 3D models to render.
95         /// The light source is only applied on the models under this ModelRoot.
96         /// </note>
97         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
98         [EditorBrowsable(EditorBrowsableState.Never)]
99         public View ModelRoot
100         {
101             get
102             {
103                 return GetModelRoot();
104             }
105         }
106
107         /// <summary>
108         /// Fits the model to the View size.
109         /// If this property is true, the model is resized to fit the width or height of the View by scaling the ModelRoot.
110         /// <note>
111         /// This property only changes model size not the pivot.
112         /// </note>
113         /// </summary>
114         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
115         [EditorBrowsable(EditorBrowsableState.Never)]
116         public bool UseSizeOfView
117         {
118             get
119             {
120                 return useSizeOfView;
121             }
122             set
123             {
124                 useSizeOfView = value;
125                 Interop.ModelView.FitSize(SwigCPtr, useSizeOfView);
126                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
127             }
128         }
129
130         /// <summary>
131         /// Moves the model to the center of ModelView.
132         /// If this property is true, the model moves so that the center is located at the center of the View by change PivotPoint of ModelRoot.
133         /// </summary>
134         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
135         [EditorBrowsable(EditorBrowsableState.Never)]
136         public bool UseCenterOfView
137         {
138             get
139             {
140                 return useCenterOfView;
141             }
142             set
143             {
144                 useCenterOfView = value;
145                 Interop.ModelView.FitCenter(SwigCPtr, useCenterOfView);
146                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
147             }
148         }
149
150         /// <summary>
151         /// Assignment operator.
152         /// </summary>
153         /// <param name="modelView">Handle to an object.</param>
154         /// <returns>Reference to this.</returns>
155         internal ModelView Assign(ModelView modelView)
156         {
157             ModelView ret = new ModelView(Interop.ModelView.ModelViewAssign(SwigCPtr, ModelView.getCPtr(modelView)), false);
158             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
159             return ret;
160         }
161
162         /// <summary>
163         /// Changes Image Based Light as the input textures.
164         /// </summary>
165         /// <param name="diffuse">Cube map that can be used as a diffuse IBL source.</param>
166         /// <param name="specular">Cube map that can be used as a specular IBL source.</param>
167         /// <param name="scaleFactor">Scale factor that controls light source intensity in [0.0f, 1.0f]. Default value is 1.0f.</param>
168         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
169         [EditorBrowsable(EditorBrowsableState.Never)]
170         public void SetImageBasedLightSource(string diffuse, string specular, float scaleFactor = 1.0f)
171         {
172             Interop.ModelView.SetImageBasedLightSource(SwigCPtr, diffuse, specular, scaleFactor);
173             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
174         }
175
176         /// <summary>
177         /// Gets number of animations those loaded from model file.
178         /// Note: This method should be called after Model load finished.
179         /// </summary>
180         /// <returns>The number of loaded animations.</returns>
181         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
182         [EditorBrowsable(EditorBrowsableState.Never)]
183         public uint GetAnimationCount()
184         {
185             uint ret = Interop.ModelView.GetAnimationCount(SwigCPtr);
186             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
187             return ret;
188         }
189
190         /// <summary>
191         /// Gets animation at the index.
192         /// Note: This method should be called after Model load finished.
193         /// </summary>
194         /// <param name="index">Index of animation to be retrieved.</param>
195         /// <returns>Animation at the index.</returns>
196         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
197         [EditorBrowsable(EditorBrowsableState.Never)]
198         public Animation GetAnimation(uint index)
199         {
200             Animation ret = new Animation(Interop.ModelView.GetAnimation(SwigCPtr, index), false);
201             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
202             return ret;
203         }
204
205         /// <summary>
206         /// Retrieves animation with the given name.
207         /// Note: This method should be called after Model load finished.
208         /// </summary>
209         /// <param name="name">String name of animation to be retrieved.</param>
210         /// <returns>Animation that has the given name.</returns>
211         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
212         [EditorBrowsable(EditorBrowsableState.Never)]
213         public Animation GetAnimation(string name)
214         {
215             Animation ret = new Animation(Interop.ModelView.GetAnimation(SwigCPtr, name), false);
216             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
217             return ret;
218         }
219
220         /// <summary>
221         /// Retrieves model root Actor.
222         /// </summary>
223         /// <returns>Root View of the model.</returns>
224         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
225         [EditorBrowsable(EditorBrowsableState.Never)]
226         private View GetModelRoot()
227         {
228             View ret = new View(Interop.ModelView.GetModelRoot(SwigCPtr), false);
229             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
230             return ret;
231         }
232
233         /// <summary>
234         /// Release swigCPtr.
235         /// </summary>
236         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
237         [EditorBrowsable(EditorBrowsableState.Never)]
238         protected override void ReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr)
239         {
240             Interop.ModelView.DeleteModelView(swigCPtr);
241         }
242     }
243 }