2 * Copyright(c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using System.Runtime.InteropServices;
20 using System.ComponentModel;
21 using System.Diagnostics.CodeAnalysis;
23 using Tizen.NUI.Binding;
24 using Tizen.NUI.BaseComponents;
26 namespace Tizen.NUI.Scene3D
29 /// SceneView is a Class to show multiple 3D objects in a single 2D screen.
30 /// Each SceneView has its own 3D space, and 3D objects added to SceneView are positioned in the space.
31 /// SceneView uses left-handed coordinate system same as NUI. X as right, Y as down, and Z as forward.
33 /// SceneView has internal root container to control inner rendering process like depth test.
34 /// When a View is added to the SceneView with <see cref="View.Add(View)"/> method, it is actually added on the root container.
35 /// Therefore, the added Views exist in the sub tree of SceneView, but are not direct children.
36 /// The sub tree of Views will be rendered with the SceneView's own Camera.
38 /// SceneView has one built-in camera by default.
39 /// The default Camera is not removed by using <see cref="RemoveCamera(Camera)"/> method.
40 /// <see cref="GetCamera(uint)"/> method with index "0" returns the default camera,
41 /// and the minimum value returned by <see cref="GetCameraCount()"/> method is 1.
43 /// SceneView also provides multiple Camera and one of them can be used to render multiple objects.
44 /// <see cref="AddCamera(Camera)"/>, <see cref="RemoveCamera(Camera)"/>, <see cref="GetCamera(uint)"/>,
45 /// and <see cref="SelectCamera(uint)"/> are methods to manage Cameras of the SceneView.
46 /// User can place multiple cameras in a scene to display the entire scene or to display individual objects.
47 /// User can use the <see cref="SelectCamera(uint)"/> method to select the currently required camera.
49 /// When the SceneView's size changes, some camera properties that depend on its size may also change.
50 /// The changing properties are as follows: AspectRatio, LeftPlaneDistance, RightPlaneDistance, TopPlaneDistance, and BottomPlaneDistance.
51 /// The Camera's FieldOfView is vertical fov. The horizontal fov is updated internally according to the SceneView size.
53 /// The <see cref="SetImageBasedLightSource(string, string, float)"/> method sets the same IBL to all Model objects added to the SceneView.
54 /// For the IBL, two cube map textures(diffuse and specular) are required.
55 /// SceneView supports 4 types layout for Cube Map: Vertical/Horizontal Cross layouts, and Vertical/Horizontal Array layouts.
56 /// And also, ktx format with cube map is supported.
57 /// If a model already has an IBL, it is batch overridden with the IBL of the SceneView.
58 /// If the SceneView has IBL, the IBL of newly added models is also overridden.
60 /// The IBL textures start to be loaded asynchronously when <see cref="SetImageBasedLightSource(string, string, float)"/> method is called.
61 /// ResourcesLoaded signal notifies that the loading of the IBL resources have been completed.
63 /// If FBO is used, the rendering result of SceneView is drawn on the FBO and it is mapped on the plane of the SceneView.
64 /// It could decreases performance slightly, but it is useful to show SceneView according to the rendering order with other Views.
66 /// And since SceneView is a View, it can be placed together with other 2D UI components in the NUI window.
68 /// <since_tizen> 10 </since_tizen>
69 public class SceneView : View
71 private bool inCameraTransition = false;
72 private Animation cameraTransition;
73 private string skyboxUrl;
75 internal SceneView(global::System.IntPtr cPtr, bool cMemoryOwn) : this(cPtr, cMemoryOwn, cMemoryOwn)
79 internal SceneView(global::System.IntPtr cPtr, bool cMemoryOwn, bool cRegister) : base(cPtr, cMemoryOwn, true, cRegister)
84 /// Create an initialized SceneView.
86 /// <since_tizen> 10 </since_tizen>
87 public SceneView() : this(Interop.SceneView.SceneNew(), true)
89 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
95 /// <param name="sceneView">The source object.</param>
96 /// <since_tizen> 10 </since_tizen>
97 public SceneView(SceneView sceneView) : this(Interop.SceneView.NewScene(SceneView.getCPtr(sceneView)), true, false)
99 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
103 /// Assignment operator.
105 /// <param name="sceneView">Handle to an object.</param>
106 /// <returns>Reference to this.</returns>
107 internal SceneView Assign(SceneView sceneView)
109 SceneView ret = new SceneView(Interop.SceneView.SceneAssign(SwigCPtr, SceneView.getCPtr(sceneView)), false);
110 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
115 /// An event emitted when Camera Transition is finished.
117 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
118 [EditorBrowsable(EditorBrowsableState.Never)]
119 public event EventHandler CameraTransitionFinished;
122 /// Set/Get the ImageBasedLight ScaleFactor.
123 /// Scale factor controls light source intensity in [0.0f, 1.0f]
125 /// <since_tizen> 10 </since_tizen>
126 public float ImageBasedLightScaleFactor
130 SetImageBasedLightScaleFactor(value);
134 return GetImageBasedLightScaleFactor();
139 /// Set/Get the UseFramebuffer.
140 /// If this property is true, rendering result of SceneView is drawn on FBO and it is mapping on this SceneView plane.
141 /// If this property is false, each item in SceneView is rendered on window directly.
142 /// Default is false.
145 /// If UseFramebuffer is true, it could decrease performance but entire rendering order is satisfied.
146 /// If UseFramebuffer is false, the performance becomes better but SceneView is rendered on the top of the other 2D components regardless tree order.
148 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
149 [EditorBrowsable(EditorBrowsableState.Never)]
150 public bool UseFramebuffer
154 SetUseFramebuffer(value);
158 return IsUsingFramebuffer();
163 /// Set/Get the Framebuffer's MultiSamplingLevel.
164 /// Only has effects if UseFramebuffer is true, and Framebuffer MultiSampling is supported.
168 /// Getter didn't consider Framebuffer MultiSampling is supported or not.
170 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
171 [EditorBrowsable(EditorBrowsableState.Never)]
172 public uint FramebufferMultiSamplingLevel
176 SetFramebufferMultiSamplingLevel(value);
180 return GetFramebufferMultiSamplingLevel();
185 /// Set/Get SkyboxUrl.
186 /// If SkyboxUrl is set, the cube map image is loaded and skybox is attached on scene.
187 /// Skybox texture is asynchronously loaded. When loading is finished, ResourcesLoaded is emitted.
189 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
190 [EditorBrowsable(EditorBrowsableState.Never)]
191 public string SkyboxUrl
204 /// Set/Get Skybox intensity.
205 /// The skybox intensity is multiplied to the color of skybox texture.
206 /// Default value is 1.0f.
208 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
209 [EditorBrowsable(EditorBrowsableState.Never)]
210 public float SkyboxIntensity
214 SetSkyboxIntensity(value);
218 return GetSkyboxIntensity();
223 /// Set/Get angle of orientation of the skybox.
224 /// If orientation is set, the skybox will be rotate by the Radian orientation along YAxis.
225 /// Default value is 0.0f.
227 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
228 [EditorBrowsable(EditorBrowsableState.Never)]
229 public Rotation SkyboxOrientation
233 SetSkyboxOrientation(value);
237 return GetSkyboxOrientation();
242 /// Adds a Camera to the SceneView at the end of the camera list of SceneView.
243 /// The Camera can be used as a selected camera to render the scene by using <see cref="SelectCamera(uint)"/> or <see cref="SelectCamera(string)"/>
245 /// <param name="camera">Camera added on this SceneView.</param>
247 /// Some properties of the Camera will be change depending on the Size of this SceneView.
248 /// Those properties are as follows:
249 /// AspectRatio, LeftPlaneDistance, RightPlaneDistance, TopPlaneDistance, and BottomPlaneDistance.
251 /// The FieldOfView of Camera is for vertical fov.
252 /// When the size of the SceneView is changed, the vertical fov is maintained
253 /// and the horizontal fov is automatically calculated according to the SceneView's AspectRatio.
255 /// <since_tizen> 10 </since_tizen>
256 public void AddCamera(Camera camera)
260 Interop.SceneView.AddCamera(SwigCPtr, camera.SwigCPtr);
261 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
266 /// Removes a Camera from this SceneView.
267 /// If removed Camera is selected Camera,
268 /// first camera in the list becomes the selected Camera.
270 /// <param name="camera"> camera Camera to be removed from this Camera.</param>
272 /// When Camera.Dispose() is called, the NUI object is disposed, but camera information is maintained internally.
273 /// Therefore, even if Camera.Dispose() is called, RemoveCamera() or RemoveCamera() methods can be used.
274 /// If RemoveCamera() is called too, all information is deleted together.
276 /// <since_tizen> 10 </since_tizen>
277 public void RemoveCamera(Camera camera)
281 Interop.SceneView.RemoveCamera(SwigCPtr, camera.SwigCPtr);
282 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
287 /// Retrieves the number of cameras.
289 /// <returns>The number of Cameras.</returns>
290 /// <since_tizen> 10 </since_tizen>
291 public uint GetCameraCount()
293 uint count = Interop.SceneView.GetCameraCount(SwigCPtr);
294 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
299 /// Retrieves a Camera of the index.
301 /// <param name="index"> Index of Camera to be retrieved.</param>
302 /// <returns>Camera of the index.</returns>
303 /// <since_tizen> 10 </since_tizen>
304 public Camera GetCamera(uint index)
306 global::System.IntPtr cPtr = Interop.SceneView.GetCamera(SwigCPtr, index);
307 Camera camera = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Camera;
310 // Register new camera into Registry.
311 camera = new Camera(cPtr, true);
315 // We found matched NUI camera. Reduce cPtr reference count.
316 HandleRef handle = new HandleRef(this, cPtr);
317 Interop.Camera.DeleteCameraProperty(handle);
318 handle = new HandleRef(null, IntPtr.Zero);
320 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
325 /// Retrieves a Camera of the input name.
327 /// <param name="name"> string keyword of Camera to be retrieved.</param>
328 /// <returns>Camera that has the name as a View.Name property</returns>
329 /// <since_tizen> 10 </since_tizen>
330 public Camera GetCamera(string name)
332 global::System.IntPtr cPtr = Interop.SceneView.GetCamera(SwigCPtr, name);
333 Camera camera = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Camera;
336 // Register new camera into Registry.
337 camera = new Camera(cPtr, true);
341 // We found matched NUI camera. Reduce cPtr reference count.
342 HandleRef handle = new HandleRef(this, cPtr);
343 Interop.Camera.DeleteCameraProperty(handle);
344 handle = new HandleRef(null, IntPtr.Zero);
346 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
351 /// Makes SceneView use a Camera of index as a selected camera.
353 /// <param name="index"> Index of Camera to be used as a selected camera.</param>
354 /// <since_tizen> 10 </since_tizen>
355 public void SelectCamera(uint index)
357 if (inCameraTransition)
361 this.GetSelectedCamera()?.Unparent();
362 Interop.SceneView.SelectCamera(SwigCPtr, index);
363 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
367 /// Makes SceneView use a Camera of a name as a selected camera.
369 /// <param name="name"> string keyword of Camera to be used as a selected camera.</param>
370 /// <since_tizen> 10 </since_tizen>
371 public void SelectCamera(string name)
373 if (inCameraTransition)
377 this.GetSelectedCamera()?.Unparent();
378 Interop.SceneView.SelectCamera(SwigCPtr, name);
379 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
383 /// Starts camera transition from currently selected camera to a camera of index.
384 /// Camera Position, Orientation and FieldOfView are smoothly animated.
387 /// The selected camera is switched to the Camera of the index when the transition is started.
388 /// During camera transition, Selected Camera should not be changed by using SelectCamera() or CameraTransition() method.
389 /// During camera transition, Camera properties of Selected Camera should not be changed.
391 /// <param name="index"> Index of destination Camera of Camera transition.</param>
392 /// <param name="durationMilliSeconds">The duration in milliseconds.</param>
393 /// <param name="alphaFunction">The alpha function to apply.</param>
394 /// <since_tizen> 10 </since_tizen>
395 [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "The ownership of camera object is not owned by this class.")]
396 public void CameraTransition(uint index, int durationMilliSeconds, AlphaFunction alphaFunction = null)
398 if (inCameraTransition || GetSelectedCamera() == GetCamera(index))
402 Camera source = GetSelectedCamera();
404 Camera destination = GetSelectedCamera();
405 CameraTransition(source, destination, durationMilliSeconds, alphaFunction);
409 /// Starts camera transition from currently selected camera to a camera of input name.
410 /// Camera Position, Orientation and FieldOfView are smoothly animated.
413 /// The selected camera is switched to the Camera of the input name when the transition is started.
414 /// During camera transition, Selected Camera should not be changed by using SelectCamera() or CameraTransition() method.
415 /// During camera transition, Camera properties of Selected Camera should not be changed.
417 /// <param name="name"> string keyword of destination Camera of Camera transition.</param>
418 /// <param name="durationMilliSeconds">The duration in milliseconds.</param>
419 /// <param name="alphaFunction">The alpha function to apply.</param>
420 /// <since_tizen> 10 </since_tizen>
421 [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "The ownership of camera object is not owned by this class.")]
422 public void CameraTransition(string name, int durationMilliSeconds, AlphaFunction alphaFunction = null)
424 if (inCameraTransition || GetSelectedCamera() == GetCamera(name))
428 Camera source = GetSelectedCamera();
430 Camera destination = GetSelectedCamera();
431 CameraTransition(source, destination, durationMilliSeconds, alphaFunction);
435 /// Retrieves selected Camera.
437 /// <returns> Camera currently used in SceneView as a selected Camera.</returns>
438 /// <since_tizen> 10 </since_tizen>
439 public Camera GetSelectedCamera()
441 global::System.IntPtr cPtr = Interop.SceneView.GetSelectedCamera(SwigCPtr);
442 Camera camera = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Camera;
445 // Register new camera into Registry.
446 camera = new Camera(cPtr, true);
450 // We found matched NUI camera. Reduce cPtr reference count.
451 HandleRef handle = new HandleRef(this, cPtr);
452 Interop.Camera.DeleteCameraProperty(handle);
453 handle = new HandleRef(null, IntPtr.Zero);
455 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
460 /// Changes Image Based Light as the input textures.
462 /// <param name="diffuseUrl">The path of Cube map image that can be used as a diffuse IBL source.</param>
463 /// <param name="specularUrl">The path of Cube map image that can be used as a specular IBL source.</param>
464 /// <param name="scaleFactor">Scale factor that controls light source intensity in [0.0f, 1.0f]. Default value is 1.0f.</param>
466 /// http://tizen.org/privilege/mediastorage for local files in media storage.
467 /// http://tizen.org/privilege/externalstorage for local files in external storage.
469 /// <since_tizen> 10 </since_tizen>
470 public void SetImageBasedLightSource(string diffuseUrl, string specularUrl, float scaleFactor = 1.0f)
472 Interop.SceneView.SetImageBasedLightSource(SwigCPtr, diffuseUrl, specularUrl, scaleFactor);
473 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
477 /// Add Lights to this SceneView.
479 /// <param name="light">The light what we want to add</param>
480 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
481 [EditorBrowsable(EditorBrowsableState.Never)]
482 public void AddLight(Light light)
484 Interop.SceneView.AddLight(SwigCPtr, Light.getCPtr(light));
485 NDalicPINVOKE.ThrowExceptionIfExists();
489 /// Remove Lights from this SceneView.
491 /// <param name="light">The light what we want to remove</param>
492 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
493 [EditorBrowsable(EditorBrowsableState.Never)]
494 public void RemoveLight(Light light)
496 Interop.SceneView.RemoveLight(SwigCPtr, Light.getCPtr(light));
497 NDalicPINVOKE.ThrowExceptionIfExists();
501 /// Sets SceneView's resolution manually.
503 /// <param name="width">The input width.</param>
504 /// <param name="height">The input height.</param>
506 /// This manual resolution is only available when the SceneView uses FBO for rendering by using FBO (UseFrameBuffer is true).
507 /// If the aspect ratio of input width/height is different with SceneView's aspect ratio, the rendered result is stretched to fill SceneView's area.
509 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
510 [EditorBrowsable(EditorBrowsableState.Never)]
511 public void SetResolution(uint width, uint height)
513 Interop.SceneView.SetResolution(SwigCPtr, width, height);
514 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
518 /// Retrieves width of resolution of the SceneView.
521 /// If the SceneView not uses FBO, this method returns SceneView's width.
523 /// <returns> Camera currently used in SceneView as a selected Camera.</returns>
524 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
525 [EditorBrowsable(EditorBrowsableState.Never)]
526 public uint GetResolutionWidth()
528 uint result = Interop.SceneView.GetResolutionWidth(SwigCPtr);
529 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
534 /// Retrieves height of resolution of the SceneView.
537 /// If the SceneView not uses FBO, this method returns SceneView's height.
539 /// <returns> Camera currently used in SceneView as a selected Camera.</returns>
540 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
541 [EditorBrowsable(EditorBrowsableState.Never)]
542 public uint GetResolutionHeight()
544 uint result = Interop.SceneView.GetResolutionHeight(SwigCPtr);
545 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
550 /// Resets SceneView's resolution to the current size of SceneView.
552 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
553 [EditorBrowsable(EditorBrowsableState.Never)]
554 public void ResetResolution()
556 Interop.SceneView.ResetResolution(SwigCPtr);
557 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
560 internal void SetUseFramebuffer(bool useFramebuffer)
562 Interop.SceneView.UseFramebuffer(SwigCPtr, useFramebuffer);
563 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
566 internal bool IsUsingFramebuffer()
568 bool result = Interop.SceneView.IsUsingFramebuffer(SwigCPtr);
569 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
573 internal void SetFramebufferMultiSamplingLevel(uint multiSamplingLevel)
575 Interop.SceneView.SetFramebufferMultiSamplingLevel(SwigCPtr, multiSamplingLevel);
576 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
579 internal uint GetFramebufferMultiSamplingLevel()
581 uint result = Interop.SceneView.GetFramebufferMultiSamplingLevel(SwigCPtr);
582 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
587 /// Set the ImageBasedLight ScaleFactor.
589 /// <param name="scaleFactor">Scale factor that controls light source intensity in [0.0f, 1.0f].</param>
590 private void SetImageBasedLightScaleFactor(float scaleFactor)
592 Interop.SceneView.SetImageBasedLightScaleFactor(SwigCPtr, scaleFactor);
593 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
597 /// Get the ImageBasedLight ScaleFactor.
599 /// <returns>ImageBasedLightScaleFactor that controls light source intensity.</returns>
600 private float GetImageBasedLightScaleFactor()
602 float scaleFactor = Interop.SceneView.GetImageBasedLightScaleFactor(SwigCPtr);
603 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
608 /// Set the Skybox from cube map image.
609 /// Skybox texture is asynchronously loaded. When loading is finished, ResourcesLoaded is emitted.
611 /// <param name="skyboxUrl">Cube map image url for skybox.</param>
612 private void SetSkybox(string skyboxUrl)
614 this.skyboxUrl = skyboxUrl;
615 Interop.SceneView.SetSkybox(SwigCPtr, skyboxUrl);
616 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
620 /// Sets Skybox intensity.
621 /// The skybox intensity is multiplied to the color of skybox texture.
622 /// Default value is 1.0f.
624 /// <param name="intensity">Intensity value to be multiplied to the cube map color.</param>
625 private void SetSkyboxIntensity(float intensity)
627 Interop.SceneView.SetSkyboxIntensity(SwigCPtr, intensity);
628 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
632 /// Gets Skybox intensity.
633 /// Default value is 1.0f.
635 /// <returns>skybox intensity.</returns>
636 private float GetSkyboxIntensity()
638 float intensity = Interop.SceneView.GetSkyboxIntensity(SwigCPtr);
639 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
644 /// Sets orientation of the skybox.
646 /// <param name="orientation">Rotation angle of the skybox along YAxis.</param>
647 private void SetSkyboxOrientation(Rotation orientation)
649 Interop.SceneView.SetSkyboxOrientation(SwigCPtr, Rotation.getCPtr(orientation));
650 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
654 /// Gets Skybox orientation.
656 /// <returns>skybox orientation.</returns>
657 private Rotation GetSkyboxOrientation()
659 global::System.IntPtr cPtr = Interop.SceneView.GetSkyboxOrientation(SwigCPtr);
660 Rotation ret = (cPtr == global::System.IntPtr.Zero) ? null : new Rotation(cPtr, true);
661 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
665 private void CameraTransition(Camera sourceCamera, Camera destinationCamera, int durationMilliSeconds, AlphaFunction alphaFunction)
667 inCameraTransition = true;
669 Position sourcePosition = sourceCamera.Position;
670 Rotation sourceOrientation = sourceCamera.Orientation;
672 Position destinationPosition = destinationCamera.Position;
673 Rotation destinationOrientation = destinationCamera.Orientation;
675 cameraTransition = new Animation(durationMilliSeconds);
677 KeyFrames positionKeyFrames = new KeyFrames();
678 positionKeyFrames.Add(0.0f, sourcePosition);
679 positionKeyFrames.Add(1.0f, destinationPosition);
681 KeyFrames orientationKeyFrames = new KeyFrames();
682 orientationKeyFrames.Add(0.0f, sourceOrientation);
683 orientationKeyFrames.Add(1.0f, destinationOrientation);
685 cameraTransition.AnimateBetween(destinationCamera, "Position", positionKeyFrames, Animation.Interpolation.Linear, alphaFunction);
686 cameraTransition.AnimateBetween(destinationCamera, "Orientation", orientationKeyFrames, Animation.Interpolation.Linear, alphaFunction);
688 if (destinationCamera.ProjectionMode == Camera.ProjectionModeType.Perspective)
690 Radian sourceFieldOfView = sourceCamera.FieldOfView;
691 Radian destinationFieldOfView = destinationCamera.FieldOfView;
693 // If ProjectionDirection is not equal, match the value.
694 if (sourceCamera.ProjectionDirection != destinationCamera.ProjectionDirection)
696 float aspect = destinationCamera.AspectRatio;
697 if (destinationCamera.ProjectionDirection == Camera.ProjectionDirectionType.Vertical)
699 Camera.ConvertFovFromHorizontalToVertical(aspect, ref sourceFieldOfView);
703 Camera.ConvertFovFromVerticalToHorizontal(aspect, ref sourceFieldOfView);
707 KeyFrames fieldOfViewKeyFrames = new KeyFrames();
708 fieldOfViewKeyFrames.Add(0.0f, sourceFieldOfView.ConvertToFloat());
709 fieldOfViewKeyFrames.Add(1.0f, destinationFieldOfView.ConvertToFloat());
710 cameraTransition.AnimateBetween(destinationCamera, "FieldOfView", fieldOfViewKeyFrames, Animation.Interpolation.Linear, alphaFunction);
712 sourceFieldOfView.Dispose();
713 destinationFieldOfView.Dispose();
714 fieldOfViewKeyFrames.Dispose();
718 float sourceOrthographicSize = sourceCamera.OrthographicSize;
719 float destinationOrthographicSize = destinationCamera.OrthographicSize;
721 // If ProjectionDirection is not equal, match the value.
722 if (sourceCamera.ProjectionDirection != destinationCamera.ProjectionDirection)
724 float aspect = destinationCamera.AspectRatio;
725 if (destinationCamera.ProjectionDirection == Camera.ProjectionDirectionType.Vertical)
727 sourceOrthographicSize = sourceOrthographicSize / aspect;
731 sourceOrthographicSize = sourceOrthographicSize * aspect;
735 KeyFrames orthographicSizeKeyFrames = new KeyFrames();
736 orthographicSizeKeyFrames.Add(0.0f, sourceOrthographicSize);
737 orthographicSizeKeyFrames.Add(1.0f, destinationOrthographicSize);
738 cameraTransition.AnimateBetween(destinationCamera, "OrthographicSize", orthographicSizeKeyFrames, Animation.Interpolation.Linear, alphaFunction);
740 orthographicSizeKeyFrames.Dispose();
743 float destinationNearPlaneDistance = destinationCamera.NearPlaneDistance;
744 float destinationFarPlaneDistance = destinationCamera.FarPlaneDistance;
745 destinationCamera.NearPlaneDistance = Math.Min(sourceCamera.NearPlaneDistance, destinationCamera.NearPlaneDistance);
746 destinationCamera.FarPlaneDistance = Math.Max(sourceCamera.FarPlaneDistance, destinationCamera.FarPlaneDistance);
748 cameraTransition.Finished += (s, e) =>
750 this.GetSelectedCamera().NearPlaneDistance = destinationNearPlaneDistance;
751 this.GetSelectedCamera().FarPlaneDistance = destinationFarPlaneDistance;
752 inCameraTransition = false;
753 CameraTransitionFinished?.Invoke(this, EventArgs.Empty);
755 cameraTransition.Play();
757 positionKeyFrames.Dispose();
758 orientationKeyFrames.Dispose();
762 /// Release swigCPtr.
764 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
765 [EditorBrowsable(EditorBrowsableState.Never)]
766 protected override void ReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr)
768 Interop.SceneView.DeleteScene(swigCPtr);