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