From: Eunki, Hong Date: Tue, 7 Feb 2023 09:33:08 +0000 (+0900) Subject: [NUI.Scene3D] Backport API11 for Scene3D X-Git-Tag: submit/tizen_7.0/20230216.150906~1^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a62d5e040f679b6cdfab6529d55ac3701b584aa8;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI.Scene3D] Backport API11 for Scene3D We might need to backport some properties so we can use Scene3D feature fully Signed-off-by: Eunki, Hong --- diff --git a/src/Tizen.NUI.Scene3D/src/internal/CameraBindableProperty.cs b/src/Tizen.NUI.Scene3D/src/internal/CameraBindableProperty.cs index 5090d26..24c75ba 100755 --- a/src/Tizen.NUI.Scene3D/src/internal/CameraBindableProperty.cs +++ b/src/Tizen.NUI.Scene3D/src/internal/CameraBindableProperty.cs @@ -79,6 +79,23 @@ namespace Tizen.NUI.Scene3D }); /// + /// OrthographicSizeProperty + /// + 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; + }); + + /// /// AspectRatioProperty /// internal static readonly BindableProperty AspectRatioProperty = BindableProperty.Create(nameof(AspectRatio), typeof(float), typeof(Tizen.NUI.Scene3D.Camera), default(float), propertyChanged: (bindable, oldValue, newValue) => diff --git a/src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.Camera.cs b/src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.Camera.cs index acb0089..4976040 100755 --- a/src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.Camera.cs +++ b/src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.Camera.cs @@ -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(); diff --git a/src/Tizen.NUI.Scene3D/src/public/Controls/Camera.cs b/src/Tizen.NUI.Scene3D/src/public/Controls/Camera.cs index cb9ab3d..fa2a2ef 100755 --- a/src/Tizen.NUI.Scene3D/src/public/Controls/Camera.cs +++ b/src/Tizen.NUI.Scene3D/src/public/Controls/Camera.cs @@ -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 /// // 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); } /// @@ -673,13 +676,13 @@ namespace Tizen.NUI.Scene3D /// // 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); } /// diff --git a/src/Tizen.NUI.Scene3D/src/public/Controls/SceneView.cs b/src/Tizen.NUI.Scene3D/src/public/Controls/SceneView.cs index 40289ef..5a34f04 100755 --- a/src/Tizen.NUI.Scene3D/src/public/Controls/SceneView.cs +++ b/src/Tizen.NUI.Scene3D/src/public/Controls/SceneView.cs @@ -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 /// The duration in milliseconds. /// The alpha function to apply. /// 10 + [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 /// The duration in milliseconds. /// The alpha function to apply. /// 10 + [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(); } ///