2 * Copyright(c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using System.Runtime.InteropServices;
20 using System.ComponentModel;
22 using Tizen.NUI.Binding;
23 using Tizen.NUI.BaseComponents;
25 namespace Tizen.NUI.Scene3D
28 /// Model is a Class to show 3D mesh objects.
29 /// Model supports glTF 2.0 and DLI model formats.
30 /// Physically Based Rendering with Image Based Lighting is also supported.
34 /// Since NUI uses a left-handed coordinate system, loaded models are transformed into a left-handed coordinate system with Y pointing down.
35 /// The Animations defined in the glTF or DLI are also loaded and can be retrieved by using <see cref="GetAnimation(uint)"/> and <see cref="GetAnimation(string)"/> methods.
36 /// The number of animation is also retrieved by GetAnimationCount() method.
38 /// By default, the loaded mesh has its own size and <see cref="PivotPoint"/> inferred from position of vertices.
39 /// If user set size property, the mesh will be scaled to the input size.
40 /// Default value of <see cref="ParentOrigin"/> of the Model is Center.
42 /// The model starts to be loaded synchronously when the Model object is on Window.
43 /// So, <see cref="GetAnimation(uint)"/> and <see cref="GetAnimation(string)"/> methods should be called after the Model object is added on Window.
48 /// Model model = new Model(modelUrl)
50 /// Size = new Size(width, height),
52 /// model.SetImageBasedLightSource(diffuseUrl, specularUrl, scaleFactor);
53 /// window.Add(model);
55 /// int animationCount = model.GetAnimationCount();
56 /// if(animationCount > 0)
58 /// // Play an Animation of index 0.
59 /// model.GetAnimation(0).Play();
63 /// <since_tizen> 10 </since_tizen>
64 public class Model : View
66 internal Model(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
71 /// Create an initialized Model.
73 /// <param name="modelUrl">model file url.(e.g. glTF, and DLI).</param>
74 /// <param name="resourceDirectoryUrl"> The url to derectory containing resources: binary, image etc.</param>
76 /// If resourceDirectoryUrl is empty, the parent directory url of modelUrl is used for resource url.
78 /// http://tizen.org/privilege/mediastorage for local files in media storage.
79 /// http://tizen.org/privilege/externalstorage for local files in external storage.
81 /// <since_tizen> 10 </since_tizen>
82 public Model(string modelUrl, string resourceDirectoryUrl = "") : this(Interop.Model.ModelNew(modelUrl, resourceDirectoryUrl), true)
84 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
85 this.PositionUsesAnchorPoint = true;
91 /// <param name="model">Source object to copy.</param>
92 /// <since_tizen> 10 </since_tizen>
93 public Model(Model model) : this(Interop.Model.NewModel(Model.getCPtr(model)), true)
95 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
99 /// Assignment operator.
101 /// <param name="model">Source object to be assigned.</param>
102 /// <returns>Reference to this.</returns>
103 internal Model Assign(Model model)
105 Model ret = new Model(Interop.Model.ModelAssign(SwigCPtr, Model.getCPtr(model)), false);
106 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
111 /// Changes Image Based Light according to the given input textures.
113 /// <param name="diffuseUrl">The path of Cube map image that will be used as a diffuse IBL source.</param>
114 /// <param name="specularUrl">The path of Cube map image that will be used as a specular IBL source.</param>
115 /// <param name="scaleFactor">Scale factor that controls light source intensity in [0.0f, 1.0f]. Default value is 1.0f.</param>
117 /// http://tizen.org/privilege/mediastorage for local files in media storage.
118 /// http://tizen.org/privilege/externalstorage for local files in external storage.
120 /// <since_tizen> 10 </since_tizen>
121 public void SetImageBasedLightSource(string diffuseUrl, string specularUrl, float scaleFactor = 1.0f)
123 Interop.Model.SetImageBasedLightSource(SwigCPtr, diffuseUrl, specularUrl, scaleFactor);
124 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
128 /// Gets number of animations that has been loaded from model file.
131 /// This method should be called after Model load has been finished.
133 /// <returns>The number of loaded animations.</returns>
134 /// <since_tizen> 10 </since_tizen>
135 public uint GetAnimationCount()
137 uint ret = Interop.Model.GetAnimationCount(SwigCPtr);
138 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
143 /// Gets animation at the index.
146 /// This method should be called after Model load has been finished.
148 /// <param name="index">Index of animation to be retrieved.</param>
149 /// <returns>Animation at the index.</returns>
150 /// <since_tizen> 10 </since_tizen>
151 public Animation GetAnimation(uint index)
153 Animation ret = new Animation(Interop.Model.GetAnimation(SwigCPtr, index), false);
154 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
159 /// Retrieves animation with the given name.
160 /// Note: This method should be called after Model load finished.
162 /// <param name="name">String name of animation to be retrieved.</param>
163 /// <returns>Animation that has the given name.</returns>
164 /// <since_tizen> 10 </since_tizen>
165 public Animation GetAnimation(string name)
167 Animation ret = new Animation(Interop.Model.GetAnimation(SwigCPtr, name), false);
168 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
173 /// Retrieves model root Actor.
175 /// <returns>Root View of the model.</returns>
176 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
177 [EditorBrowsable(EditorBrowsableState.Never)]
178 private View GetModelRoot()
180 View ret = new View(Interop.Model.GetModelRoot(SwigCPtr), false);
181 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
186 /// Release swigCPtr.
188 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
189 [EditorBrowsable(EditorBrowsableState.Never)]
190 protected override void ReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr)
192 Interop.Model.DeleteModel(swigCPtr);