b778cbece0b33f4bbd4d33a2a1bb47acd38d8f08
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Scene3D / src / public / Controls / Model.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     /// 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.
31     /// </summary>
32     ///
33     /// <remarks>
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.
37     ///
38     /// Model also supports Physically Based Rendering(PBR) with Image Based Lighting(IBL).
39     /// For the IBL, two cube map textures(diffuse and specular) are required.
40     /// Model supports 4 types layout for Cube Map: Vertical/Horizontal Cross layouts, and Vertical/Horizontal Array layouts.
41     /// And also, ktx format with cube map is supported.
42     ///
43     /// The model and IBL textures start to be loaded asynchronously when the Model object is on Window.
44     /// ResourcesLoaded signal notifies that the loading of the model and IBL resources have been completed.
45     /// If Model or IBL is requested to be loaded before the other loading is completed, the ResourcesLoaded signal is called after all resources are loaded.
46     /// <see cref="GetAnimation(uint)"/> and <see cref="GetAnimation(string)"/> methods can be used after the model loading is finished.
47     ///
48     /// By default, the loaded mesh has its own size and <see cref="PivotPoint"/> inferred from position of vertices.
49     /// The <see cref="PivotPoint"/> can be modified after model loading is finished.
50     /// If user set size property, the mesh will be scaled to the input size.
51     /// Default value of <see cref="ParentOrigin"/> of the Model is Center.
52     /// </remarks>
53     ///
54     /// <example>
55     /// <code>
56     /// Model model = new Model(modelUrl)
57     /// {
58     ///     Size = new Size(width, height),
59     /// };
60     /// model.ResourcesLoaded += (s, e) =>
61     /// {
62     ///     model.PivotPoint = new Vector3(0.5f, 0.5f, 0.5f); // Use center as a Pivot.
63     ///
64     ///     int animationCount = model.GetAnimationCount();
65     ///     if(animationCount > 0)
66     ///     {
67     ///         // Play an Animation of index 0.
68     ///         model.GetAnimation(0).Play();
69     ///     }
70     /// };
71     /// model.SetImageBasedLightSource(diffuseUrl, specularUrl, scaleFactor);
72     /// window.Add(model);
73     ///
74     /// </code>
75     /// </example>
76     /// <since_tizen> 10 </since_tizen>
77     public partial class Model : View
78     {
79         internal Model(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
80         {
81         }
82
83         /// <summary>
84         /// Create an initialized Model.
85         /// </summary>
86         /// <param name="modelUrl">model file url.(e.g. glTF, and DLI).</param>
87         /// <param name="resourceDirectoryUrl"> The url to derectory containing resources: binary, image etc.</param>
88         /// <remarks>
89         /// If resourceDirectoryUrl is empty, the parent directory url of modelUrl is used for resource url.
90         ///
91         /// http://tizen.org/privilege/mediastorage for local files in media storage.
92         /// http://tizen.org/privilege/externalstorage for local files in external storage.
93         /// </remarks>
94         /// <since_tizen> 10 </since_tizen>
95         public Model(string modelUrl, string resourceDirectoryUrl = "") : this(Interop.Model.ModelNew(modelUrl, resourceDirectoryUrl), true)
96         {
97             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
98             this.PositionUsesPivotPoint = true;
99         }
100
101         /// <summary>
102         /// Create an initialized Model.
103         /// </summary>
104         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
105         [EditorBrowsable(EditorBrowsableState.Never)]
106         public Model() : this(Interop.Model.ModelNew(), true)
107         {
108             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
109             this.PositionUsesPivotPoint = true;
110         }
111
112         /// <summary>
113         /// Copy constructor.
114         /// </summary>
115         /// <param name="model">Source object to copy.</param>
116         /// <since_tizen> 10 </since_tizen>
117         public Model(Model model) : this(Interop.Model.NewModel(Model.getCPtr(model)), true)
118         {
119             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
120             this.PositionUsesPivotPoint = model.PositionUsesPivotPoint;
121         }
122
123         /// <summary>
124         /// Assignment operator.
125         /// </summary>
126         /// <param name="model">Source object to be assigned.</param>
127         /// <returns>Reference to this.</returns>
128         internal Model Assign(Model model)
129         {
130             Model ret = new Model(Interop.Model.ModelAssign(SwigCPtr, Model.getCPtr(model)), false);
131             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
132             ret.PositionUsesPivotPoint = model.PositionUsesPivotPoint;
133             return ret;
134         }
135
136         /// <summary>
137         /// Set/Get the ImageBasedLight ScaleFactor.
138         /// Scale factor controls light source intensity in [0.0f, 1.0f]
139         /// </summary>
140         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
141         [EditorBrowsable(EditorBrowsableState.Never)]
142         public float ImageBasedLightScaleFactor
143         {
144             set
145             {
146                 SetImageBasedLightScaleFactor(value);
147             }
148             get
149             {
150                 return GetImageBasedLightScaleFactor();
151             }
152         }
153
154         /// <summary>
155         /// Retrieves root ModelNode of this Model.
156         /// </summary>
157         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
158         [EditorBrowsable(EditorBrowsableState.Never)]
159         public ModelNode ModelRoot
160         {
161             get
162             {
163                 return GetModelRoot();
164             }
165         }
166
167         /// <summary>
168         /// Adds modelNode to this Model.
169         /// </summary>
170         /// <param name="modelNode">Root of a ModelNode tree</param>
171         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
172         [EditorBrowsable(EditorBrowsableState.Never)]
173         public void AddModelNode(ModelNode modelNode)
174         {
175             Interop.Model.AddModelNode(SwigCPtr, ModelNode.getCPtr(modelNode));
176             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
177         }
178
179         /// <summary>
180         /// Removes modelNode from this Model.
181         /// </summary>
182         /// <param name="modelNode">Root of a ModelNode tree to be removed</param>
183         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
184         [EditorBrowsable(EditorBrowsableState.Never)]
185         public void RemoveModelNode(ModelNode modelNode)
186         {
187             Interop.Model.RemoveModelNode(SwigCPtr, ModelNode.getCPtr(modelNode));
188             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
189         }
190
191         /// <summary>
192         /// Removes Returns a child ModelNode object with a name that matches nodeName.
193         /// </summary>
194         /// <param name="nodeName">The name of the child ModelNode object you want to find.</param>
195         /// <returns>Child ModelNode that has nodeName as name.</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 ModelNode FindChildModelNodeByName(string nodeName)
199         {
200             global::System.IntPtr cPtr = Interop.Model.FindChildModelNodeByName(SwigCPtr, nodeName);
201             ModelNode ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as ModelNode;
202             if (ret == null)
203             {
204                 // Store the value of PositionUsesAnchorPoint from dali object (Since View object automatically change PositionUsesPivotPoint value as false, we need to keep value.)
205                 HandleRef handle = new HandleRef(this, cPtr);
206                 bool originalPositionUsesAnchorPoint = Object.InternalGetPropertyBool(handle, View.Property.PositionUsesAnchorPoint);
207                 handle = new HandleRef(null, IntPtr.Zero);
208
209                 // Register new animatable into Registry.
210                 ret = new ModelNode(cPtr, true);
211                 ret.PositionUsesPivotPoint = originalPositionUsesAnchorPoint;
212             }
213             else
214             {
215                 // We found matched NUI animatable. Reduce cPtr reference count.
216                 HandleRef handle = new HandleRef(this, cPtr);
217                 Tizen.NUI.Interop.BaseHandle.DeleteBaseHandle(handle);
218                 handle = new HandleRef(null, IntPtr.Zero);
219             }
220             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
221             return ret;
222         }
223
224         /// <summary>
225         /// Changes Image Based Light according to the given input textures.
226         /// </summary>
227         /// <param name="diffuseUrl">The path of Cube map image that will be used as a diffuse IBL source.</param>
228         /// <param name="specularUrl">The path of Cube map image that will be used as a specular IBL source.</param>
229         /// <param name="scaleFactor">Scale factor that controls light source intensity in [0.0f, 1.0f]. Default value is 1.0f.</param>
230         /// <remarks>
231         /// http://tizen.org/privilege/mediastorage for local files in media storage.
232         /// http://tizen.org/privilege/externalstorage for local files in external storage.
233         /// </remarks>
234         /// <since_tizen> 10 </since_tizen>
235         public void SetImageBasedLightSource(string diffuseUrl, string specularUrl, float scaleFactor = 1.0f)
236         {
237             Interop.Model.SetImageBasedLightSource(SwigCPtr, diffuseUrl, specularUrl, scaleFactor);
238             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239         }
240
241         /// <summary>
242         /// Gets number of animations that has been loaded from model file.
243         /// </summary>
244         /// <remarks>
245         /// This method should be called after Model load has been finished.
246         /// </remarks>
247         /// <returns>The number of loaded animations.</returns>
248         /// <since_tizen> 10 </since_tizen>
249         public uint GetAnimationCount()
250         {
251             uint ret = Interop.Model.GetAnimationCount(SwigCPtr);
252             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
253             return ret;
254         }
255
256         /// <summary>
257         /// Gets animation at the index.
258         /// </summary>
259         /// <remarks>
260         /// This method should be called after Model load has been finished.
261         /// </remarks>
262         /// <param name="index">Index of animation to be retrieved.</param>
263         /// <returns>Animation at the index.</returns>
264         /// <since_tizen> 10 </since_tizen>
265         public Animation GetAnimation(uint index)
266         {
267             global::System.IntPtr cPtr = Interop.Model.GetAnimation(SwigCPtr, index);
268             Animation ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animation;
269             if (ret == null)
270             {
271                 // Register new animation into Registry.
272                 ret = new Animation(cPtr, true);
273             }
274             else
275             {
276                 // We found matched NUI animation. Reduce cPtr reference count.
277                 HandleRef handle = new HandleRef(this, cPtr);
278                 Tizen.NUI.Interop.Animation.DeleteAnimation(handle);
279                 handle = new HandleRef(null, IntPtr.Zero);
280             }
281             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
282             return ret;
283         }
284
285         /// <summary>
286         /// Retrieves animation with the given name.
287         /// Note: This method should be called after Model load finished.
288         /// </summary>
289         /// <param name="name">String name of animation to be retrieved.</param>
290         /// <returns>Animation that has the given name.</returns>
291         /// <since_tizen> 10 </since_tizen>
292         public Animation GetAnimation(string name)
293         {
294             global::System.IntPtr cPtr = Interop.Model.GetAnimation(SwigCPtr, name);
295             Animation ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animation;
296             if (ret == null)
297             {
298                 // Register new animation into Registry.
299                 ret = new Animation(cPtr, true);
300             }
301             else
302             {
303                 // We found matched NUI animation. Reduce cPtr reference count.
304                 HandleRef handle = new HandleRef(this, cPtr);
305                 Tizen.NUI.Interop.Animation.DeleteAnimation(handle);
306                 handle = new HandleRef(null, IntPtr.Zero);
307             }
308             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
309             return ret;
310         }
311
312         /// <summary>
313         /// Gets number of camera parameters that has been loaded from model file.
314         /// </summary>
315         /// <remarks>
316         /// This method should be called after Model load has been finished.
317         /// </remarks>
318         /// <returns>The number of loaded camera parameters.</returns>
319         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
320         [EditorBrowsable(EditorBrowsableState.Never)]
321         public uint GetCameraCount()
322         {
323             uint ret = Interop.Model.GetCameraCount(SwigCPtr);
324             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
325             return ret;
326         }
327
328         /// <summary>
329         /// Generate Camera using camera parameters at the index.
330         /// If camera parameter is valid, create new Camera.
331         /// Else, return empty Handle.
332         /// </summary>
333         /// <remarks>
334         /// This method should be called after Model load has been finished.
335         /// </remarks>
336         /// <param name="index">Index of camera to be generated.</param>
337         /// <returns>Generated Camera by the index, or empty Handle if generation failed.</returns>
338         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
339         [EditorBrowsable(EditorBrowsableState.Never)]
340         public Camera GenerateCamera(uint index)
341         {
342             global::System.IntPtr cPtr = Interop.Model.GenerateCamera(SwigCPtr, index);
343             Camera ret = new Camera(cPtr, true); // Always create new camera.
344             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
345             return ret;
346         }
347
348         /// <summary>
349         /// Apply camera parameters at the index to inputed Camera.
350         /// If camera parameter is valid and camera is not empty, apply parameters.
351         /// It will change camera's transform and near / far / fov or orthographic size / aspect ratio (if defined)
352         /// </summary>
353         /// <remarks>
354         /// This method should be called after Model load has been finished.
355         /// </remarks>
356         /// <param name="index">Index of camera to be retrieved.</param>
357         /// <param name="camera">Camera to be applied parameter.</param>
358         /// <returns>True if Apply successed. False otherwise.</returns>
359         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
360         [EditorBrowsable(EditorBrowsableState.Never)]
361         public bool ApplyCamera(uint index, Camera camera)
362         {
363             bool ret = false;
364             if (camera?.HasBody() == true)
365             {
366                 ret = Interop.Model.ApplyCamera(SwigCPtr, index, Camera.getCPtr(camera));
367                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
368             }
369             return ret;
370         }
371
372         /// <summary>
373         /// Load bvh animation and assign to model.
374         /// Scale is additional scale factor of bvh animation. It is possible that
375         /// Model's scale may not matched with bvh animation scale.
376         /// If scale is null, default use as Vector3.ONE
377         /// </summary>
378         /// <param name="bvhFilename">Name of bvh format file.</param>
379         /// <param name="scale">Scale value of bvh animation match with model.</param>
380         /// <param name="translateRootFromModelNode">Whether we should translate the bvh root from it's ModelNode position or not.</param>
381         /// <returns>Animaion of bvh</returns>
382         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
383         [EditorBrowsable(EditorBrowsableState.Never)]
384         [Obsolete("Do not use this LoadBvhAnimation. Use MotionData.LoadMotionCaptureAnimation and GenerateMotionDataAnimation instead.")]
385         public Animation LoadBvhAnimation(string bvhFilename, Vector3 scale = null, bool translateRootFromModelNode = true)
386         {
387             global::System.IntPtr cPtr = Interop.Model.LoadBvhAnimation(SwigCPtr, bvhFilename, Vector3.getCPtr(scale), translateRootFromModelNode);
388             Animation ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animation;
389             if (ret == null)
390             {
391                 // Register new animation into Registry.
392                 ret = new Animation(cPtr, true);
393             }
394             else
395             {
396                 // We found matched NUI animation. Reduce cPtr reference count.
397                 HandleRef handle = new HandleRef(this, cPtr);
398                 Tizen.NUI.Interop.Animation.DeleteAnimation(handle);
399                 handle = new HandleRef(null, IntPtr.Zero);
400             }
401             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
402             return ret;
403         }
404
405         /// <summary>
406         /// Load bvh animation and assign to model.
407         /// Scale is additional scale factor of bvh animation. It is possible that
408         /// Model's scale may not matched with bvh animation scale.
409         /// If scale is null, default use as Vector3.ONE
410         /// </summary>
411         /// <param name="bvhBuffer">Contents of bvh format file.</param>
412         /// <param name="scale">Scale value of bvh animation match with model.</param>
413         /// <param name="translateRootFromModelNode">Whether we should translate the bvh root from it's ModelNode position or not.</param>
414         /// <returns>Animaion of bvh</returns>
415         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
416         [EditorBrowsable(EditorBrowsableState.Never)]
417         [Obsolete("Do not use this LoadBvhAnimationFromBuffer. Use MotionData.LoadMotionCaptureAnimationFromBuffer and GenerateMotionDataAnimation instead.")]
418         public Animation LoadBvhAnimationFromBuffer(string bvhBuffer, Vector3 scale = null, bool translateRootFromModelNode = true)
419         {
420             global::System.IntPtr cPtr = Interop.Model.LoadBvhAnimationFromBuffer(SwigCPtr, bvhBuffer, bvhBuffer.Length, Vector3.getCPtr(scale), translateRootFromModelNode);
421             Animation ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animation;
422             if (ret == null)
423             {
424                 // Register new animation into Registry.
425                 ret = new Animation(cPtr, true);
426             }
427             else
428             {
429                 // We found matched NUI animation. Reduce cPtr reference count.
430                 HandleRef handle = new HandleRef(this, cPtr);
431                 Tizen.NUI.Interop.Animation.DeleteAnimation(handle);
432                 handle = new HandleRef(null, IntPtr.Zero);
433             }
434             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
435             return ret;
436         }
437
438         /// <summary>
439         /// Load facial animation and assign to model.
440         /// </summary>
441         /// <param name="facialFilename">Name of json format file what we predefined.</param>
442         /// <returns>Animaion of facial</returns>
443         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
444         [EditorBrowsable(EditorBrowsableState.Never)]
445         [Obsolete("Do not use this LoadFacialAnimation. Use MotionData.LoadBlendShapeAnimation and GenerateMotionDataAnimation instead.")]
446         public Animation LoadFacialAnimation(string facialFilename)
447         {
448             return LoadBlendShapeAnimation(facialFilename);
449         }
450
451         /// <summary>
452         /// Load facial animation and assign to model.
453         /// </summary>
454         /// <param name="facialBuffer">Contents of json format file what we predefined.</param>
455         /// <returns>Animaion of facial</returns>
456         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
457         [EditorBrowsable(EditorBrowsableState.Never)]
458         [Obsolete("Do not use this LoadFacialAnimationFromBuffer. Use MotionData.LoadBlendShapeAnimationFromBuffer and GenerateMotionDataAnimation instead.")]
459         public Animation LoadFacialAnimationFromBuffer(string facialBuffer)
460         {
461             return LoadBlendShapeAnimationFromBuffer(facialBuffer);
462         }
463
464         /// <summary>
465         /// Load blendshape animation and assign to model from json file.
466         /// </summary>
467         /// <param name="jsonFilename">Name of json format file what we predefined.</param>
468         /// <returns>Animaion of facial</returns>
469         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
470         [EditorBrowsable(EditorBrowsableState.Never)]
471         [Obsolete("Do not use this LoadBlendShapeAnimation. Use MotionData.LoadBlendShapeAnimation and GenerateMotionDataAnimation instead.")]
472         public Animation LoadBlendShapeAnimation(string jsonFilename)
473         {
474             global::System.IntPtr cPtr = Interop.Model.LoadBlendShapeAnimation(SwigCPtr, jsonFilename);
475             Animation ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animation;
476             if (ret == null)
477             {
478                 // Register new animation into Registry.
479                 ret = new Animation(cPtr, true);
480             }
481             else
482             {
483                 // We found matched NUI animation. Reduce cPtr reference count.
484                 HandleRef handle = new HandleRef(this, cPtr);
485                 Tizen.NUI.Interop.Animation.DeleteAnimation(handle);
486                 handle = new HandleRef(null, IntPtr.Zero);
487             }
488             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
489             return ret;
490         }
491
492         /// <summary>
493         /// Load morphing animation and assign to model from json string.
494         /// </summary>
495         /// <param name="jsonBuffer">Contents of json format file what we predefined.</param>
496         /// <returns>Animaion of facial</returns>
497         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
498         [EditorBrowsable(EditorBrowsableState.Never)]
499         [Obsolete("Do not use this LoadBlendShapeAnimationFromBuffer. Use MotionData.LoadBlendShapeAnimationFromBuffer and GenerateMotionDataAnimation instead.")]
500         public Animation LoadBlendShapeAnimationFromBuffer(string jsonBuffer)
501         {
502             global::System.IntPtr cPtr = Interop.Model.LoadBlendShapeAnimationFromBuffer(SwigCPtr, jsonBuffer, jsonBuffer.Length);
503             Animation ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animation;
504             if (ret == null)
505             {
506                 // Register new animation into Registry.
507                 ret = new Animation(cPtr, true);
508             }
509             else
510             {
511                 // We found matched NUI animation. Reduce cPtr reference count.
512                 HandleRef handle = new HandleRef(this, cPtr);
513                 Tizen.NUI.Interop.Animation.DeleteAnimation(handle);
514                 handle = new HandleRef(null, IntPtr.Zero);
515             }
516             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
517             return ret;
518         }
519
520         /// <summary>
521         /// Generate animation by MotionData.
522         /// If there is no animatable item for MotionData, return null.
523         /// </summary>
524         /// <param name="motionData">Source motion data.</param>
525         /// <returns>Generated animation from then given motion data, or null if there is no animatable item in <paramref name="motionData"/></returns>
526         /// <since_tizen> 11 </since_tizen>
527         public Animation GenerateMotionDataAnimation(MotionData motionData)
528         {
529             global::System.IntPtr cPtr = Interop.Model.GenerateMotionDataAnimation(SwigCPtr, MotionData.getCPtr(motionData));
530             Animation ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animation;
531             if (ret == null)
532             {
533                 // Register new animation into Registry.
534                 ret = new Animation(cPtr, true);
535             }
536             else
537             {
538                 // We found matched NUI animation. Reduce cPtr reference count.
539                 HandleRef handle = new HandleRef(this, cPtr);
540                 Tizen.NUI.Interop.Animation.DeleteAnimation(handle);
541                 handle = new HandleRef(null, IntPtr.Zero);
542             }
543             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
544
545             // It is possible if there is no animatable properties exist on inputed motionData.
546             // In this case, let we return null.
547             if (!ret.HasBody())
548             {
549                 ret.Dispose();
550                 ret = null;
551             }
552             return ret;
553         }
554
555         /// <summary>
556         /// Set values from MotionData.
557         /// Note that this method doesn not apply KeyFrames animation.
558         /// If you want to apply the animation, please use <see cref="GenerateMotionDataAnimation(MotionData)"/> and play the result.
559         /// </summary>
560         /// <param name="motionData">Source motion data.</param>
561         /// <since_tizen> 11 </since_tizen>
562         public void SetMotionData(MotionData motionData)
563         {
564             Interop.Model.SetMotionData(SwigCPtr, MotionData.getCPtr(motionData));
565             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
566         }
567
568         /// <summary>
569         /// Retrieves model root Actor.
570         /// </summary>
571         /// <returns>Root View of the model.</returns>
572         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
573         [EditorBrowsable(EditorBrowsableState.Never)]
574         private ModelNode GetModelRoot()
575         {
576             global::System.IntPtr cPtr = Interop.Model.GetModelRoot(SwigCPtr);
577             ModelNode ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as ModelNode;
578             if (ret == null)
579             {
580                 // Store the value of PositionUsesAnchorPoint from dali object (Since View object automatically change PositionUsesPivotPoint value as false, we need to keep value.)
581                 HandleRef handle = new HandleRef(this, cPtr);
582                 bool originalPositionUsesAnchorPoint = Object.InternalGetPropertyBool(handle, View.Property.PositionUsesAnchorPoint);
583                 handle = new HandleRef(null, IntPtr.Zero);
584
585                 // Register new animatable into Registry.
586                 ret = new ModelNode(cPtr, true);
587                 ret.PositionUsesPivotPoint = originalPositionUsesAnchorPoint;
588             }
589             else
590             {
591                 // We found matched NUI animatable. Reduce cPtr reference count.
592                 HandleRef handle = new HandleRef(this, cPtr);
593                 Tizen.NUI.Interop.BaseHandle.DeleteBaseHandle(handle);
594                 handle = new HandleRef(null, IntPtr.Zero);
595             }
596             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
597             return ret;
598         }
599
600         /// <summary>
601         /// Set the ImageBasedLight ScaleFactor.
602         /// </summary>
603         /// <param name="scaleFactor">Scale factor that controls light source intensity in [0.0f, 1.0f].</param>
604         private void SetImageBasedLightScaleFactor(float scaleFactor)
605         {
606             Interop.Model.SetImageBasedLightScaleFactor(SwigCPtr, scaleFactor);
607             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
608         }
609
610         /// <summary>
611         /// Get the ImageBasedLight ScaleFactor.
612         /// </summary>
613         /// <returns>ImageBasedLightScaleFactor that controls light source intensity.</returns>
614         private float GetImageBasedLightScaleFactor()
615         {
616             float scaleFactor = Interop.Model.GetImageBasedLightScaleFactor(SwigCPtr);
617             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
618             return scaleFactor;
619         }
620
621         /// <summary>
622         /// Release swigCPtr.
623         /// </summary>
624         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
625         [EditorBrowsable(EditorBrowsableState.Never)]
626         protected override void ReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr)
627         {
628             Interop.Model.DeleteModel(swigCPtr);
629         }
630     }
631 }