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;
22 using Tizen.NUI.Binding;
23 using Tizen.NUI.BaseComponents;
25 namespace Tizen.NUI.Scene3D
28 /// SceneView is a Class to show multiple 3D objects in a single 2D sreen.
29 /// Each SceneView has its own 3D space, and 3D objects added to SceneView are positioned in the space.
30 /// SceneView uses left-handed coordinate system same as NUI. X as right, Y as down, and Z as forward.
32 /// SceneView has internal root container to control inner rendering process like depth test.
33 /// When a View is added to the SceneView with <see cref="View.Add(View)"/> method, it is actually added on the root container.
34 /// Therefore, the added Views exist in the sub tree of SceneView, but are not direct children.
35 /// The sub tree of Views will be rendered with the SceneView's own Camera.
37 /// SceneView has one built-in camera by default.
38 /// The default Camera is not removed by using <see cref="RemoveCamera(Camera)"/> method.
39 /// <see cref="GetCamera(uint)"/> method with index "0" returns the default camera,
40 /// and the minimum value returned by <see cref="GetCameraCount()"/> method is 1.
42 /// SceneView also provides multiple Camera and one of them can be used to render the multiple objects.
43 /// <see cref="AddCamera(Camera)"/>, <see cref="RemoveCamera(Camera)"/>, <see cref="GetCamera(uint)"/>,
44 /// and <see cref="SelectCamera(uint)"/> are methods to manage Cameras of the SceneView.
45 /// User can place multiple cameras in a scene to display the entire scene or to display individual objects.
46 /// User can use the <see cref="SelectCamera(uint)"/> method to select the currently required camera.
48 /// When the SceneView's size changes, some camera properties that depend on its size may also change.
49 /// The changing properties are as follows: ProjectionMode, AspectRatio, LeftPlaneDistance, RightPlaneDistance, TopPlaneDistance, and BottomPlaneDistance.
50 /// Position, Near/FarPlaneDistance, and FieldOfView are maintained even if the size of the SceneView is changed.
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 /// If a model already has an IBL, it is batch overridden with the IBL of the SceneView.
55 /// If the SceneView has IBL, the IBL of newly added models is also overridden.
57 /// SceneView provides an option to use FBO for rendering result with <see cref="UseFramebuffer"/> property.
58 /// If it is false, SceneView is always drawn in the form of a rectangle on the default window surface directly.
59 /// It improves performance, but the SceneView is always drawn on top of other 2D objects regardless of rendering order.
61 /// If FBO is used, the rendering result of SceneView is drawn on the FBO and it is mapped on the plane of the SceneView.
62 /// It could decreases performance slightly, but it is useful to show SceneView according to the rendering order with other Views.
64 /// And since SceneView is a View, it can be placed together with other 2D UI components in the NUI window.
68 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
69 [EditorBrowsable(EditorBrowsableState.Never)]
70 public class SceneView : View
72 internal SceneView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
77 /// Create an initialized SceneView.
79 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
80 [EditorBrowsable(EditorBrowsableState.Never)]
81 public SceneView() : this(Interop.SceneView.SceneNew(), true)
83 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
89 /// <param name="sceneView">Handle to an object.</param>
90 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
91 [EditorBrowsable(EditorBrowsableState.Never)]
92 public SceneView(SceneView sceneView) : this(Interop.SceneView.NewScene(SceneView.getCPtr(sceneView)), true)
94 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
98 /// Assignment operator.
100 /// <param name="sceneView">Handle to an object.</param>
101 /// <returns>Reference to this.</returns>
102 internal SceneView Assign(SceneView sceneView)
104 SceneView ret = new SceneView(Interop.SceneView.SceneAssign(SwigCPtr, SceneView.getCPtr(sceneView)), false);
105 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
110 /// Set/Get the UseFramebuffer.
111 /// If this property is true, rendering result of SceneView is drawn on FBO and it is mapping on this SceneView plane.
112 /// If this property is false, each item in SceneView is rendered on window directly.
113 /// Default is false.
116 /// If useFramebuffer is true, it could decrease performance but entire rendering order is satisfied.
117 /// If useFramebuffer is false, the performance becomes better but SceneView is rendered on the top of the other 2D components regardless tree order.
119 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
120 [EditorBrowsable(EditorBrowsableState.Never)]
121 public bool UseFramebuffer
125 SetUseFramebuffer(value);
129 return IsUsingFramebuffer();
134 /// Adds a Camera to the SceneView
135 /// The Camera can be used as a selected camera to render the scene by using <see cref="SelectCamera(uint)"/> or <see cref="SelectCamera(string)"/>
137 /// <param name="camera">Camera added on this SceneView.</param>
139 /// Some properties of the Camera will be change depending on the Size of this SceneView.
140 /// Those properties are as follows:
141 /// aspectRatio, nearPlaneDistance, farPlaneDistance, leftPlaneDistance, rightPlaneDistance, topPlaneDistance, and bottomPlaneDistance.
143 /// The FieldOfView of Camera is for vertical fov.
144 /// When the size of the SceneView is changed, the vertical fov is maintained
145 /// and the horizontal fov is automatically calculated according to the SceneView's aspect ratio.
147 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
148 [EditorBrowsable(EditorBrowsableState.Never)]
149 public void AddCamera(Camera camera)
153 Interop.SceneView.AddCamera(SwigCPtr, camera.SwigCPtr);
154 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
159 /// Removes a Camera from this SceneView.
160 /// If removed Camera is selected Camera,
161 /// first camera in the list is set to selected Camera.
163 /// <param name="camera"> camera Camera to be removed from this Camera.</param>
165 /// Camera.Dispose() don't automatically release memory. We should call this API if we want to release memory.
166 /// We cannot remove default camera. If we try to remove default camera, ignored.
168 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
169 [EditorBrowsable(EditorBrowsableState.Never)]
170 public void RemoveCamera(Camera camera)
174 Interop.SceneView.RemoveCamera(SwigCPtr, camera.SwigCPtr);
175 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
180 /// Retrieves the number of cameras.
182 /// <returns>The number of Cameras.</returns>
183 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
184 [EditorBrowsable(EditorBrowsableState.Never)]
185 public uint GetCameraCount()
187 uint count = Interop.SceneView.GetCameraCount(SwigCPtr);
188 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
193 /// Retrieves a Camera of the index.
195 /// <param name="index"> Index of Camera to be retrieved.</param>
196 /// <returns>Camera of the index.</returns>
197 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
198 [EditorBrowsable(EditorBrowsableState.Never)]
199 public Camera GetCamera(uint index)
201 global::System.IntPtr cPtr = Interop.SceneView.GetCamera(SwigCPtr, index);
202 Camera camera = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Camera;
205 // Register new camera into Registry.
206 camera = new Camera(cPtr, true);
210 // We found matched NUI camera. Reduce cPtr reference count.
211 HandleRef handle = new HandleRef(this, cPtr);
212 Interop.Camera.DeleteCameraProperty(handle);
213 handle = new HandleRef(null, IntPtr.Zero);
215 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
220 /// Retrieves a Camera of the index.
222 /// <param name="name"> string keyword of Camera to be retrieved.</param>
223 /// <returns>Camera that has the name as a View.Name property</returns>
224 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
225 [EditorBrowsable(EditorBrowsableState.Never)]
226 public Camera GetCamera(string name)
228 global::System.IntPtr cPtr = Interop.SceneView.GetCamera(SwigCPtr, name);
229 Camera camera = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Camera;
232 // Register new camera into Registry.
233 camera = new Camera(cPtr, true);
237 // We found matched NUI camera. Reduce cPtr reference count.
238 HandleRef handle = new HandleRef(this, cPtr);
239 Interop.Camera.DeleteCameraProperty(handle);
240 handle = new HandleRef(null, IntPtr.Zero);
242 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
247 /// Makes SceneView use a Camera of index as a selected camera.
249 /// <param name="index"> Index of Camera to be used as a selected camera.</param>
250 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
251 [EditorBrowsable(EditorBrowsableState.Never)]
252 public void SelectCamera(uint index)
254 Interop.SceneView.SelectCamera(SwigCPtr, index);
255 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259 /// Makes SceneView use a Camera of a name as a selected camera.
261 /// <param name="name"> string keyword of Camera to be used as a selected camera.</param>
262 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
263 [EditorBrowsable(EditorBrowsableState.Never)]
264 public void SelectCamera(string name)
266 Interop.SceneView.SelectCamera(SwigCPtr, name);
267 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
271 /// Retrieves selected Camera.
273 /// <returns> Camera currently used in SceneView as a selected Camera.</returns>
274 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
275 [EditorBrowsable(EditorBrowsableState.Never)]
276 public Camera GetSelectedCamera()
278 global::System.IntPtr cPtr = Interop.SceneView.GetSelectedCamera(SwigCPtr);
279 Camera camera = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Camera;
282 // Register new camera into Registry.
283 camera = new Camera(cPtr, true);
287 // We found matched NUI camera. Reduce cPtr reference count.
288 HandleRef handle = new HandleRef(this, cPtr);
289 Interop.Camera.DeleteCameraProperty(handle);
290 handle = new HandleRef(null, IntPtr.Zero);
292 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
297 /// Changes Image Based Light as the input textures.
299 /// <param name="diffuseUrl">The path of Cube map image that can be used as a diffuse IBL source.</param>
300 /// <param name="specularUrl">The path of Cube map image that can be used as a specular IBL source.</param>
301 /// <param name="scaleFactor">Scale factor that controls light source intensity in [0.0f, 1.0f]. Default value is 1.0f.</param>
302 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
303 [EditorBrowsable(EditorBrowsableState.Never)]
304 public void SetImageBasedLightSource(string diffuseUrl, string specularUrl, float scaleFactor = 1.0f)
306 Interop.SceneView.SetImageBasedLightSource(SwigCPtr, diffuseUrl, specularUrl, scaleFactor);
307 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
310 internal void SetUseFramebuffer(bool useFramebuffer)
312 Interop.SceneView.UseFramebuffer(SwigCPtr, useFramebuffer);
313 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
316 internal bool IsUsingFramebuffer()
318 bool result = Interop.SceneView.IsUsingFramebuffer(SwigCPtr);
319 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
324 /// Release swigCPtr.
326 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
327 [EditorBrowsable(EditorBrowsableState.Never)]
328 protected override void ReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr)
330 Interop.SceneView.DeleteScene(swigCPtr);