[NUI] Changes ModelView to Model
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Scene3D / src / public / Controls / Model.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;
22 using Tizen.NUI.Binding;
23 using Tizen.NUI.BaseComponents;
24
25 namespace Tizen.NUI.Scene3D
26 {
27     /// <summary>
28     /// Model is a Class to show 3D mesh objects.
29     /// Model supports to load glTF 2.0 and DLI models for the input format
30     /// and also supports Physically Based Rendering with Image Based Lighting.
31     ///
32     /// The Animations defined in the glTF or DLI are also loaded and can be retrieved by using GetAnimation() method.
33     /// The number of animation is also retrieved by GetAnimationCount() method.
34     ///
35     /// By default, The loaded mesh has it's own size inferred from position of vertices.
36     /// If user set size property, the mesh will be scaled to the input size.
37     ///
38     /// Both of the default value of PivotPoint and ParentOrigin of the Model is Center.
39     ///
40     /// </summary>
41     /// <code>
42     /// Model model = new Model(modelUrl)
43     /// {
44     ///     Size = new Size(width, height),
45     /// };
46     /// model.SetImageBasedLightSource(diffuseUrl, specularUrl, scaleFactor);
47     /// window.Add(model);
48     ///
49     /// int animationCount = model.GetAnimationCount();
50     /// if(animationCount > 0)
51     /// {
52     ///     model.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 Model : View
58     {
59         internal Model(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
60         {
61         }
62
63         /// <summary>
64         /// Create an initialized Model.
65         /// </summary>
66         /// <param name="modelPath">model file path.(e.g., glTF, and DLI).</param>
67         /// <param name="resourcePath">resource file path that includes binary, image etc.</param>
68         /// <note> If resourcePath is empty, the parent directory path of modelPath is used for resource path. </note>
69         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
70         [EditorBrowsable(EditorBrowsableState.Never)]
71         public Model(string modelPath, string resourcePath = "") : this(Interop.Model.ModelNew(modelPath, resourcePath), true)
72         {
73             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
74             Interop.Model.FitSize(SwigCPtr, true);
75             this.ParentOrigin = Tizen.NUI.ParentOrigin.Center;
76             this.PivotPoint = Tizen.NUI.PivotPoint.Center;
77             this.PositionUsesAnchorPoint = true;
78         }
79
80         /// <summary>
81         /// Copy constructor.
82         /// </summary>
83         /// <param name="modelView">Handle to an object.</param>
84         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
85         [EditorBrowsable(EditorBrowsableState.Never)]
86         public Model(Model modelView) : this(Interop.Model.NewModel(Model.getCPtr(modelView)), true)
87         {
88             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
89         }
90
91         /// <summary>
92         /// Assignment operator.
93         /// </summary>
94         /// <param name="modelView">Handle to an object.</param>
95         /// <returns>Reference to this.</returns>
96         internal Model Assign(Model modelView)
97         {
98             Model ret = new Model(Interop.Model.ModelAssign(SwigCPtr, Model.getCPtr(modelView)), false);
99             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
100             return ret;
101         }
102
103         /// <summary>
104         /// Changes Image Based Light as the input textures.
105         /// </summary>
106         /// <param name="diffuseUrl">The path of Cube map image that can be used as a diffuse IBL source.</param>
107         /// <param name="specularUrl">The path of Cube map image that can be used as a specular IBL source.</param>
108         /// <param name="scaleFactor">Scale factor that controls light source intensity in [0.0f, 1.0f]. Default value is 1.0f.</param>
109         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
110         [EditorBrowsable(EditorBrowsableState.Never)]
111         public void SetImageBasedLightSource(string diffuseUrl, string specularUrl, float scaleFactor = 1.0f)
112         {
113             Interop.Model.SetImageBasedLightSource(SwigCPtr, diffuseUrl, specularUrl, scaleFactor);
114             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
115         }
116
117         /// <summary>
118         /// Gets number of animations those loaded from model file.
119         /// Note: This method should be called after Model load finished.
120         /// </summary>
121         /// <returns>The number of loaded animations.</returns>
122         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
123         [EditorBrowsable(EditorBrowsableState.Never)]
124         public uint GetAnimationCount()
125         {
126             uint ret = Interop.Model.GetAnimationCount(SwigCPtr);
127             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
128             return ret;
129         }
130
131         /// <summary>
132         /// Gets animation at the index.
133         /// Note: This method should be called after Model load finished.
134         /// </summary>
135         /// <param name="index">Index of animation to be retrieved.</param>
136         /// <returns>Animation at the index.</returns>
137         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
138         [EditorBrowsable(EditorBrowsableState.Never)]
139         public Animation GetAnimation(uint index)
140         {
141             Animation ret = new Animation(Interop.Model.GetAnimation(SwigCPtr, index), false);
142             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
143             return ret;
144         }
145
146         /// <summary>
147         /// Retrieves animation with the given name.
148         /// Note: This method should be called after Model load finished.
149         /// </summary>
150         /// <param name="name">String name of animation to be retrieved.</param>
151         /// <returns>Animation that has the given name.</returns>
152         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
153         [EditorBrowsable(EditorBrowsableState.Never)]
154         public Animation GetAnimation(string name)
155         {
156             Animation ret = new Animation(Interop.Model.GetAnimation(SwigCPtr, name), false);
157             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
158             return ret;
159         }
160
161         /// <summary>
162         /// Retrieves model root Actor.
163         /// </summary>
164         /// <returns>Root View of the model.</returns>
165         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
166         [EditorBrowsable(EditorBrowsableState.Never)]
167         private View GetModelRoot()
168         {
169             View ret = new View(Interop.Model.GetModelRoot(SwigCPtr), false);
170             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
171             return ret;
172         }
173
174         /// <summary>
175         /// Release swigCPtr.
176         /// </summary>
177         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
178         [EditorBrowsable(EditorBrowsableState.Never)]
179         protected override void ReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr)
180         {
181             Interop.Model.DeleteModel(swigCPtr);
182         }
183     }
184 }