[NUI] Load facial blendshape animation
authorEunki, Hong <eunkiki.hong@samsung.com>
Tue, 14 Mar 2023 05:06:40 +0000 (14:06 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Fri, 17 Mar 2023 09:12:44 +0000 (18:12 +0900)
Load facial blendshape animation from json format.

Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.Model.cs
src/Tizen.NUI.Scene3D/src/public/Controls/Camera.cs
src/Tizen.NUI.Scene3D/src/public/Controls/Model.cs
src/Tizen.NUI.Scene3D/src/public/Controls/SceneView.cs

index 53b3866..d9b5d4b 100755 (executable)
@@ -79,6 +79,9 @@ namespace Tizen.NUI.Scene3D
 
             [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_Model_LoadBvhAnimation_1")]
             public static extern global::System.IntPtr LoadBvhAnimation(global::System.Runtime.InteropServices.HandleRef model, string bvhFilename, global::System.Runtime.InteropServices.HandleRef scale);
+
+            [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_Model_LoadFacialAnimation_1")]
+            public static extern global::System.IntPtr LoadFacialAnimation(global::System.Runtime.InteropServices.HandleRef model, string facialFilename);
         }
     }
 }
index fa2a2ef..afc0747 100755 (executable)
@@ -664,7 +664,7 @@ namespace Tizen.NUI.Scene3D
         [EditorBrowsable(EditorBrowsableState.Never)]
         public static void ConvertFovFromVerticalToHorizontal(float aspect, ref Radian fov)
         {
-            if(fov == null)
+            if (fov == null)
             {
                 return;
             }
@@ -678,7 +678,7 @@ namespace Tizen.NUI.Scene3D
         [EditorBrowsable(EditorBrowsableState.Never)]
         public static void ConvertFovFromHorizontalToVertical(float aspect, ref Radian fov)
         {
-            if(fov == null)
+            if (fov == null)
             {
                 return;
             }
index aba7368..ad360a0 100755 (executable)
@@ -183,7 +183,7 @@ namespace Tizen.NUI.Scene3D
         {
             global::System.IntPtr cPtr = Interop.Model.GetAnimation(SwigCPtr, index);
             Animation ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animation;
-            if(ret == null)
+            if (ret == null)
             {
                 // Register new animation into Registry.
                 ret = new Animation(cPtr, true);
@@ -210,7 +210,7 @@ namespace Tizen.NUI.Scene3D
         {
             global::System.IntPtr cPtr = Interop.Model.GetAnimation(SwigCPtr, name);
             Animation ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animation;
-            if(ret == null)
+            if (ret == null)
             {
                 // Register new animation into Registry.
                 ret = new Animation(cPtr, true);
@@ -250,6 +250,7 @@ namespace Tizen.NUI.Scene3D
         /// <remarks>
         /// This method should be called after Model load has been finished.
         /// </remarks>
+        /// <param name="index">Index of camera to be generated.</param>
         /// <returns>Generated Camera by the index, or empty Handle if generation failed.</returns>
         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
         [EditorBrowsable(EditorBrowsableState.Never)]
@@ -260,7 +261,7 @@ namespace Tizen.NUI.Scene3D
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
-        
+
         /// <summary>
         /// Apply camera parameters at the index to inputed Camera.
         /// If camera parameter is valid and camera is not empty, apply parameters.
@@ -269,13 +270,15 @@ namespace Tizen.NUI.Scene3D
         /// <remarks>
         /// This method should be called after Model load has been finished.
         /// </remarks>
+        /// <param name="index">Index of camera to be retrieved.</param>
+        /// <param name="camera">Camera to be applied parameter.</param>
         /// <returns>True if Apply successed. False otherwise.</returns>
         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
         [EditorBrowsable(EditorBrowsableState.Never)]
         public bool ApplyCamera(uint index, Camera camera)
         {
             bool ret = false;
-            if(camera?.HasBody() == true)
+            if (camera?.HasBody() == true)
             {
                 ret = Interop.Model.ApplyCamera(SwigCPtr, index, Camera.getCPtr(camera));
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -289,6 +292,8 @@ namespace Tizen.NUI.Scene3D
         /// Model's scale may not matched with bvh animation scale.
         /// If scale is null, default use as Vector3.ONE
         /// </summary>
+        /// <param name="bvhFilename">Name of bvh format file.</param>
+        /// <param name="scale">Scale value of bvh animation match with model.</param>
         /// <returns>Animaion of bvh</returns>
         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
         [EditorBrowsable(EditorBrowsableState.Never)]
@@ -296,7 +301,34 @@ namespace Tizen.NUI.Scene3D
         {
             global::System.IntPtr cPtr = Interop.Model.LoadBvhAnimation(SwigCPtr, bvhFilename, Vector3.getCPtr(scale));
             Animation ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animation;
-            if(ret == null)
+            if (ret == null)
+            {
+                // Register new animation into Registry.
+                ret = new Animation(cPtr, true);
+            }
+            else
+            {
+                // We found matched NUI animation. Reduce cPtr reference count.
+                HandleRef handle = new HandleRef(this, cPtr);
+                Tizen.NUI.Interop.Animation.DeleteAnimation(handle);
+                handle = new HandleRef(null, IntPtr.Zero);
+            }
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        /// <summary>
+        /// Load facial animation and assign to model.
+        /// </summary>
+        /// <param name="facialFilename">Name of json format file what we predefined.</param>
+        /// <returns>Animaion of facial</returns>
+        // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Animation LoadFacialAnimation(string facialFilename)
+        {
+            global::System.IntPtr cPtr = Interop.Model.LoadFacialAnimation(SwigCPtr, facialFilename);
+            Animation ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animation;
+            if (ret == null)
             {
                 // Register new animation into Registry.
                 ret = new Animation(cPtr, true);
@@ -322,7 +354,7 @@ namespace Tizen.NUI.Scene3D
         {
             global::System.IntPtr cPtr = Interop.Model.GetModelRoot(SwigCPtr);
             Animatable ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animatable;
-            if(ret == null)
+            if (ret == null)
             {
                 // Register new animatable into Registry.
                 ret = new Animatable(cPtr, true);
index d7df9da..10eada0 100755 (executable)
@@ -251,7 +251,7 @@ namespace Tizen.NUI.Scene3D
         /// <since_tizen> 10 </since_tizen>
         public void AddCamera(Camera camera)
         {
-            if(camera != null)
+            if (camera != null)
             {
                 Interop.SceneView.AddCamera(SwigCPtr, camera.SwigCPtr);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -272,7 +272,7 @@ namespace Tizen.NUI.Scene3D
         /// <since_tizen> 10 </since_tizen>
         public void RemoveCamera(Camera camera)
         {
-            if(camera != null)
+            if (camera != null)
             {
                 Interop.SceneView.RemoveCamera(SwigCPtr, camera.SwigCPtr);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -301,7 +301,7 @@ namespace Tizen.NUI.Scene3D
         {
             global::System.IntPtr cPtr = Interop.SceneView.GetCamera(SwigCPtr, index);
             Camera camera = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Camera;
-            if(camera == null)
+            if (camera == null)
             {
                 // Register new camera into Registry.
                 camera = new Camera(cPtr, true);
@@ -327,7 +327,7 @@ namespace Tizen.NUI.Scene3D
         {
             global::System.IntPtr cPtr = Interop.SceneView.GetCamera(SwigCPtr, name);
             Camera camera = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Camera;
-            if(camera == null)
+            if (camera == null)
             {
                 // Register new camera into Registry.
                 camera = new Camera(cPtr, true);
@@ -350,7 +350,7 @@ namespace Tizen.NUI.Scene3D
         /// <since_tizen> 10 </since_tizen>
         public void SelectCamera(uint index)
         {
-            if(inCameraTransition)
+            if (inCameraTransition)
             {
                 return;
             }
@@ -365,7 +365,7 @@ namespace Tizen.NUI.Scene3D
         /// <since_tizen> 10 </since_tizen>
         public void SelectCamera(string name)
         {
-            if(inCameraTransition)
+            if (inCameraTransition)
             {
                 return;
             }
@@ -389,7 +389,7 @@ namespace Tizen.NUI.Scene3D
         [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "The ownership of camera object is not owned by this class.")]
         public void CameraTransition(uint index, int durationMilliSeconds, AlphaFunction alphaFunction = null)
         {
-            if(inCameraTransition || GetSelectedCamera() == GetCamera(index))
+            if (inCameraTransition || GetSelectedCamera() == GetCamera(index))
             {
                 return;
             }
@@ -415,7 +415,7 @@ namespace Tizen.NUI.Scene3D
         [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "The ownership of camera object is not owned by this class.")]
         public void CameraTransition(string name, int durationMilliSeconds, AlphaFunction alphaFunction = null)
         {
-            if(inCameraTransition || GetSelectedCamera() == GetCamera(name))
+            if (inCameraTransition || GetSelectedCamera() == GetCamera(name))
             {
                 return;
             }
@@ -434,7 +434,7 @@ namespace Tizen.NUI.Scene3D
         {
             global::System.IntPtr cPtr = Interop.SceneView.GetSelectedCamera(SwigCPtr);
             Camera camera = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Camera;
-            if(camera == null)
+            if (camera == null)
             {
                 // Register new camera into Registry.
                 camera = new Camera(cPtr, true);
@@ -595,7 +595,7 @@ namespace Tizen.NUI.Scene3D
             cameraTransition.AnimateBetween(destinationCamera, "Position", positionKeyFrames, Animation.Interpolation.Linear, alphaFunction);
             cameraTransition.AnimateBetween(destinationCamera, "Orientation", orientationKeyFrames, Animation.Interpolation.Linear, alphaFunction);
 
-            if(destinationCamera.ProjectionMode == Camera.ProjectionModeType.Perspective)
+            if (destinationCamera.ProjectionMode == Camera.ProjectionModeType.Perspective)
             {
                 Radian sourceFieldOfView = sourceCamera.FieldOfView;
                 Radian destinationFieldOfView = destinationCamera.FieldOfView;