[NUI.Scene3D] Backport API11 for Scene3D
authorEunki, Hong <eunkiki.hong@samsung.com>
Tue, 7 Feb 2023 09:33:08 +0000 (18:33 +0900)
committerEunki Hong <h.pichulia@gmail.com>
Thu, 16 Feb 2023 09:15:19 +0000 (18:15 +0900)
We might need to backport some properties so we can use Scene3D feature fully

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

index 5090d26..24c75ba 100755 (executable)
@@ -79,6 +79,23 @@ namespace Tizen.NUI.Scene3D
         });
 
         /// <summary>
+        /// OrthographicSizeProperty
+        /// </summary>
+        internal static readonly BindableProperty OrthographicSizeProperty = BindableProperty.Create(nameof(OrthographicSize), typeof(float), typeof(Tizen.NUI.Scene3D.Camera), default(float), propertyChanged: (bindable, oldValue, newValue) =>
+        {
+            var instance = (Tizen.NUI.Scene3D.Camera)bindable;
+            if (newValue != null)
+            {
+                instance.InternalOrthographicSize = (float)newValue;
+            }
+        },
+        defaultValueCreator: (bindable) =>
+        {
+            var instance = (Tizen.NUI.Scene3D.Camera)bindable;
+            return instance.InternalOrthographicSize;
+        });
+
+        /// <summary>
         /// AspectRatioProperty
         /// </summary>
         internal static readonly BindableProperty AspectRatioProperty = BindableProperty.Create(nameof(AspectRatio), typeof(float), typeof(Tizen.NUI.Scene3D.Camera), default(float), propertyChanged: (bindable, oldValue, newValue) =>
index acb0089..4976040 100755 (executable)
@@ -57,6 +57,9 @@ namespace Tizen.NUI.Scene3D
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_CameraActor_Property_INVERT_Y_AXIS_get")]
             public static extern int InvertYAxisGet();
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_CameraActor_Property_ORTHOGRAPHIC_SIZE_get")]
+            public static extern int OrthographicSizeGet();
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_CameraActor_Property_PROJECTION_DIRECTION_get")]
             public static extern int ProjectionDirectionGet();
 
index cb9ab3d..fa2a2ef 100755 (executable)
@@ -205,26 +205,11 @@ namespace Tizen.NUI.Scene3D
         {
             get
             {
-                return InternalProjectionDirection == ProjectionDirectionType.Vertical ? TopPlaneDistance : RightPlaneDistance;
+                return InternalOrthographicSize;
             }
             set
             {
-                float halfHeight;
-                float halfWidth;
-                if(InternalProjectionDirection == ProjectionDirectionType.Vertical)
-                {
-                    halfHeight = value;
-                    halfWidth = AspectRatio * value;
-                }
-                else
-                {
-                    halfHeight = value / AspectRatio;
-                    halfWidth = value;
-                }
-                SetValue(TopPlaneDistanceProperty, halfHeight);
-                SetValue(BottomPlaneDistanceProperty, -halfHeight);
-                SetValue(LeftPlaneDistanceProperty, -halfWidth);
-                SetValue(RightPlaneDistanceProperty, halfWidth);
+                SetValue(OrthographicSizeProperty, value);
                 NotifyPropertyChanged();
             }
         }
@@ -432,6 +417,24 @@ namespace Tizen.NUI.Scene3D
             }
         }
 
+        private float InternalOrthographicSize
+        {
+            get
+            {
+                float returnValue = 0.0f;
+                PropertyValue orthographicSize = GetProperty(Interop.Camera.OrthographicSizeGet());
+                orthographicSize?.Get(out returnValue);
+                orthographicSize?.Dispose();
+                return returnValue;
+            }
+            set
+            {
+                PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
+                SetProperty(Interop.Camera.OrthographicSizeGet(), setValue);
+                setValue.Dispose();
+            }
+        }
+
         private float InternalAspectRatio
         {
             get
@@ -659,13 +662,13 @@ namespace Tizen.NUI.Scene3D
         /// </summary>
         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public static Radian ConvertFovFromVerticalToHorizontal(float aspect, Radian verticalFov)
+        public static void ConvertFovFromVerticalToHorizontal(float aspect, ref Radian fov)
         {
-            if(verticalFov == null)
+            if(fov == null)
             {
-                return null;
+                return;
             }
-            return new Radian(2.0f * (float)Math.Atan(Math.Tan(verticalFov.ConvertToFloat() * 0.5f) * aspect));
+            fov.Value = 2.0f * (float)Math.Atan(Math.Tan(fov.ConvertToFloat() * 0.5f) * aspect);
         }
 
         /// <summary>
@@ -673,13 +676,13 @@ namespace Tizen.NUI.Scene3D
         /// </summary>
         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public static Radian ConvertFovFromHorizontalToVertical(float aspect, Radian horizontalFov)
+        public static void ConvertFovFromHorizontalToVertical(float aspect, ref Radian fov)
         {
-            if(horizontalFov == null)
+            if(fov == null)
             {
-                return null;
+                return;
             }
-            return new Radian(2.0f * (float)Math.Atan(Math.Tan(horizontalFov.ConvertToFloat() * 0.5f) / aspect));
+            fov.Value = 2.0f * (float)Math.Atan(Math.Tan(fov.ConvertToFloat() * 0.5f) / aspect);
         }
 
         /// <summary>
index 40289ef..5a34f04 100755 (executable)
@@ -18,6 +18,7 @@
 using System;
 using System.Runtime.InteropServices;
 using System.ComponentModel;
+using System.Diagnostics.CodeAnalysis;
 using Tizen.NUI;
 using Tizen.NUI.Binding;
 using Tizen.NUI.BaseComponents;
@@ -327,6 +328,7 @@ namespace Tizen.NUI.Scene3D
         /// <param name="durationMilliSeconds">The duration in milliseconds.</param>
         /// <param name="alphaFunction">The alpha function to apply.</param>
         /// <since_tizen> 10 </since_tizen>
+        [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))
@@ -352,6 +354,7 @@ namespace Tizen.NUI.Scene3D
         /// <param name="durationMilliSeconds">The duration in milliseconds.</param>
         /// <param name="alphaFunction">The alpha function to apply.</param>
         /// <since_tizen> 10 </since_tizen>
+        [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))
@@ -459,25 +462,9 @@ namespace Tizen.NUI.Scene3D
 
             Position sourcePosition = sourceCamera.Position;
             Rotation sourceOrientation = sourceCamera.Orientation;
-            Radian   sourceFieldOfView = sourceCamera.FieldOfView;
 
             Position destinationPosition = destinationCamera.Position;
             Rotation destinationOrientation = destinationCamera.Orientation;
-            Radian   destinationFieldOfView = destinationCamera.FieldOfView;
-
-            // If ProjectionDirection is not equal, match the value.
-            if (sourceCamera.ProjectionDirection != destinationCamera.ProjectionDirection)
-            {
-                float aspect = destinationCamera.AspectRatio;
-                if (destinationCamera.ProjectionDirection == Camera.ProjectionDirectionType.Vertical)
-                {
-                    sourceFieldOfView = Camera.ConvertFovFromHorizontalToVertical(aspect, sourceFieldOfView);
-                }
-                else
-                {
-                    sourceFieldOfView = Camera.ConvertFovFromVerticalToHorizontal(aspect, sourceFieldOfView);
-                }
-            }
 
             cameraTransition = new Animation(durationMilliSeconds);
 
@@ -489,13 +476,63 @@ namespace Tizen.NUI.Scene3D
             orientationKeyFrames.Add(0.0f, sourceOrientation);
             orientationKeyFrames.Add(1.0f, destinationOrientation);
 
-            KeyFrames fieldOfViewKeyFrames = new KeyFrames();
-            fieldOfViewKeyFrames.Add(0.0f, sourceFieldOfView.ConvertToFloat());
-            fieldOfViewKeyFrames.Add(1.0f, destinationFieldOfView.ConvertToFloat());
-
             cameraTransition.AnimateBetween(destinationCamera, "Position", positionKeyFrames, Animation.Interpolation.Linear, alphaFunction);
             cameraTransition.AnimateBetween(destinationCamera, "Orientation", orientationKeyFrames, Animation.Interpolation.Linear, alphaFunction);
-            cameraTransition.AnimateBetween(destinationCamera, "FieldOfView", fieldOfViewKeyFrames, Animation.Interpolation.Linear, alphaFunction);
+
+            if(destinationCamera.ProjectionMode == Camera.ProjectionModeType.Perspective)
+            {
+                Radian sourceFieldOfView = sourceCamera.FieldOfView;
+                Radian destinationFieldOfView = destinationCamera.FieldOfView;
+
+                // If ProjectionDirection is not equal, match the value.
+                if (sourceCamera.ProjectionDirection != destinationCamera.ProjectionDirection)
+                {
+                    float aspect = destinationCamera.AspectRatio;
+                    if (destinationCamera.ProjectionDirection == Camera.ProjectionDirectionType.Vertical)
+                    {
+                        Camera.ConvertFovFromHorizontalToVertical(aspect, ref sourceFieldOfView);
+                    }
+                    else
+                    {
+                        Camera.ConvertFovFromVerticalToHorizontal(aspect, ref sourceFieldOfView);
+                    }
+                }
+
+                KeyFrames fieldOfViewKeyFrames = new KeyFrames();
+                fieldOfViewKeyFrames.Add(0.0f, sourceFieldOfView.ConvertToFloat());
+                fieldOfViewKeyFrames.Add(1.0f, destinationFieldOfView.ConvertToFloat());
+                cameraTransition.AnimateBetween(destinationCamera, "FieldOfView", fieldOfViewKeyFrames, Animation.Interpolation.Linear, alphaFunction);
+
+                sourceFieldOfView.Dispose();
+                destinationFieldOfView.Dispose();
+                fieldOfViewKeyFrames.Dispose();
+            }
+            else
+            {
+                float sourceOrthographicSize = sourceCamera.OrthographicSize;
+                float destinationOrthographicSize = destinationCamera.OrthographicSize;
+
+                // If ProjectionDirection is not equal, match the value.
+                if (sourceCamera.ProjectionDirection != destinationCamera.ProjectionDirection)
+                {
+                    float aspect = destinationCamera.AspectRatio;
+                    if (destinationCamera.ProjectionDirection == Camera.ProjectionDirectionType.Vertical)
+                    {
+                        sourceOrthographicSize = sourceOrthographicSize / aspect;
+                    }
+                    else
+                    {
+                        sourceOrthographicSize = sourceOrthographicSize * aspect;
+                    }
+                }
+
+                KeyFrames orthographicSizeKeyFrames = new KeyFrames();
+                orthographicSizeKeyFrames.Add(0.0f, sourceOrthographicSize);
+                orthographicSizeKeyFrames.Add(1.0f, destinationOrthographicSize);
+                cameraTransition.AnimateBetween(destinationCamera, "OrthographicSize", orthographicSizeKeyFrames, Animation.Interpolation.Linear, alphaFunction);
+
+                orthographicSizeKeyFrames.Dispose();
+            }
 
             float destinationNearPlaneDistance = destinationCamera.NearPlaneDistance;
             float destinationFarPlaneDistance = destinationCamera.FarPlaneDistance;
@@ -511,10 +548,8 @@ namespace Tizen.NUI.Scene3D
             };
             cameraTransition.Play();
 
-            sourceFieldOfView.Dispose();
             positionKeyFrames.Dispose();
             orientationKeyFrames.Dispose();
-            fieldOfViewKeyFrames.Dispose();
         }
 
         /// <summary>