[NUI.Scene3D] Do not dispose camera internally
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Scene3D / src / public / Controls / SceneView.cs
index 8449447..e3aa23a 100755 (executable)
@@ -107,6 +107,13 @@ namespace Tizen.NUI.Scene3D
         }
 
         /// <summary>
+        /// An event emitted when Camera Transition is finished.
+        /// </summary>
+        // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event EventHandler CameraTransitionFinished;
+
+        /// <summary>
         /// Set/Get the ImageBasedLight ScaleFactor.
         /// Scale factor controls light source intensity in [0.0f, 1.0f]
         /// </summary>
@@ -148,6 +155,28 @@ namespace Tizen.NUI.Scene3D
         }
 
         /// <summary>
+        /// Set/Get the Framebuffer's MultiSamplingLevel.
+        /// Only has effects if UseFramebuffer is true, and Framebuffer MultiSampling is supported.
+        /// Default is 0.
+        /// </summary>
+        /// <remarks>
+        /// Getter didn't consider Framebuffer MultiSampling is supported or not.
+        /// </remarks>
+        // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public uint FramebufferMultiSamplingLevel
+        {
+            set
+            {
+                SetFramebufferMultiSamplingLevel(value);
+            }
+            get
+            {
+                return GetFramebufferMultiSamplingLevel();
+            }
+        }
+
+        /// <summary>
         /// Set/Get SkyboxUrl.
         /// If SkyboxUrl is set, the cube map image is loaded and skybox is attached on scene.
         /// Skybox texture is asynchronously loaded. When loading is finished, ResourcesLoaded is emitted.
@@ -348,8 +377,9 @@ namespace Tizen.NUI.Scene3D
         /// Camera Position, Orientation and FieldOfView are smoothly animated.
         /// </summary>
         /// <remarks>
-        /// The selected camera is switched when the transition is started.
-        /// During camera transition, Selected Camera cannot be changed by using SelectCamera() or CameraTransition() method.
+        /// The selected camera is switched to the Camera of the index when the transition is started.
+        /// During camera transition, Selected Camera should not be changed by using SelectCamera() or CameraTransition() method.
+        /// During camera transition, Camera properties of Selected Camera should not be changed.
         /// </remarks>
         /// <param name="index"> Index of destination Camera of Camera transition.</param>
         /// <param name="durationMilliSeconds">The duration in milliseconds.</param>
@@ -357,7 +387,7 @@ namespace Tizen.NUI.Scene3D
         /// <since_tizen> 10 </since_tizen>
         public void CameraTransition(uint index, int durationMilliSeconds, AlphaFunction alphaFunction = null)
         {
-            if(inCameraTransition)
+            if(inCameraTransition || GetSelectedCamera() == GetCamera(index))
             {
                 return;
             }
@@ -365,8 +395,6 @@ namespace Tizen.NUI.Scene3D
             SelectCamera(index);
             Camera destination = GetSelectedCamera();
             CameraTransition(source, destination, durationMilliSeconds, alphaFunction);
-            source.Dispose();
-            destination.Dispose();
         }
 
         /// <summary>
@@ -374,8 +402,9 @@ namespace Tizen.NUI.Scene3D
         /// Camera Position, Orientation and FieldOfView are smoothly animated.
         /// </summary>
         /// <remarks>
-        /// The selected camera is switched when the transition is started.
-        /// During camera transition, Selected Camera cannot be changed by using SelectCamera() or CameraTransition() method.
+        /// The selected camera is switched to the Camera of the input name when the transition is started.
+        /// During camera transition, Selected Camera should not be changed by using SelectCamera() or CameraTransition() method.
+        /// During camera transition, Camera properties of Selected Camera should not be changed.
         /// </remarks>
         /// <param name="name"> string keyword of destination Camera of Camera transition.</param>
         /// <param name="durationMilliSeconds">The duration in milliseconds.</param>
@@ -383,7 +412,7 @@ namespace Tizen.NUI.Scene3D
         /// <since_tizen> 10 </since_tizen>
         public void CameraTransition(string name, int durationMilliSeconds, AlphaFunction alphaFunction = null)
         {
-            if(inCameraTransition)
+            if(inCameraTransition || GetSelectedCamera() == GetCamera(name))
             {
                 return;
             }
@@ -391,8 +420,6 @@ namespace Tizen.NUI.Scene3D
             SelectCamera(name);
             Camera destination = GetSelectedCamera();
             CameraTransition(source, destination, durationMilliSeconds, alphaFunction);
-            source.Dispose();
-            destination.Dispose();
         }
 
         /// <summary>
@@ -450,6 +477,19 @@ namespace Tizen.NUI.Scene3D
             return result;
         }
 
+        internal void SetFramebufferMultiSamplingLevel(uint multiSamplingLevel)
+        {
+            Interop.SceneView.SetFramebufferMultiSamplingLevel(SwigCPtr, multiSamplingLevel);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        internal uint GetFramebufferMultiSamplingLevel()
+        {
+            uint result = Interop.SceneView.GetFramebufferMultiSamplingLevel(SwigCPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return result;
+        }
+
         /// <summary>
         /// Set the ImageBasedLight ScaleFactor.
         /// </summary>
@@ -524,7 +564,7 @@ namespace Tizen.NUI.Scene3D
         private Rotation GetSkyboxOrientation()
         {
             global::System.IntPtr cPtr = Interop.SceneView.GetSkyboxOrientation(SwigCPtr);
-            Rotation ret = (cPtr == global::System.IntPtr.Zero) ? null : new Rotation(cPtr, false);
+            Rotation ret = (cPtr == global::System.IntPtr.Zero) ? null : new Rotation(cPtr, true);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -535,25 +575,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);
 
@@ -565,24 +589,80 @@ 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)
+                    {
+                        sourceFieldOfView = Camera.ConvertFovFromHorizontalToVertical(aspect, sourceFieldOfView);
+                    }
+                    else
+                    {
+                        sourceFieldOfView = Camera.ConvertFovFromVerticalToHorizontal(aspect, 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;
+            destinationCamera.NearPlaneDistance = Math.Min(sourceCamera.NearPlaneDistance, destinationCamera.NearPlaneDistance);
+            destinationCamera.FarPlaneDistance = Math.Max(sourceCamera.FarPlaneDistance, destinationCamera.FarPlaneDistance);
 
             cameraTransition.Finished += (s, e) =>
             {
+                this.GetSelectedCamera().NearPlaneDistance = destinationNearPlaneDistance;
+                this.GetSelectedCamera().FarPlaneDistance = destinationFarPlaneDistance;
                 inCameraTransition = false;
+                CameraTransitionFinished?.Invoke(this, EventArgs.Empty);
             };
             cameraTransition.Play();
 
-            sourceFieldOfView.Dispose();
             positionKeyFrames.Dispose();
             orientationKeyFrames.Dispose();
-            orientationKeyFrames.Dispose();
         }
 
         /// <summary>