2 * Copyright(c) 2021 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 Tizen.NUI.Binding;
22 using Tizen.NUI.BaseComponents;
24 namespace Tizen.NUI.Scene3D
27 /// ModelView is a View to show 3D model objects.
28 /// ModelView supports to load glTF 2.0 and DLI models for the input format
29 /// and also supports Physically Based Rendering with Image Based Lighting.
31 /// The Animations defined in the glTF or DLI models are also loaded and can be retrieved by using GetAnimation() method.
32 /// The number of animation is also retrieved by GetAnimationCount() method.
34 /// By default, The loaded model has it's own position and size which are defined in vertex buffer regardless of the View size.
35 /// The model can be resized and repositioned to fit to the ModelView with UseSizeOfView and UseCenterOfView properties.
38 /// ModelView modelView = new ModelView(modelUrl)
40 /// Size = new Size(width, height),
41 /// PositionUsesPivotPoint = true,
42 /// PivotPoint = PivotPoint.Center,
43 /// ParentOrigin = ParentOrigin.Center,
44 /// UseSizeOfView = true,
45 /// UseCenterOfView = true,
47 /// modelView.SetImageBasedLightSource(diffuseUrl, specularUrl, scaleFactor);
48 /// window.Add(modelView);
49 /// int animationCount = modelView.GetAnimationCount();
50 /// if(animationCount > 0)
52 /// modelView.GetAnimation(0).Play();
55 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
56 [EditorBrowsable(EditorBrowsableState.Never)]
57 public class ModelView : View
59 private bool useSizeOfView = false;
60 private bool useCenterOfView = false;
62 internal ModelView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
67 /// Create an initialized ModelView.
69 /// <param name="modelPath">model file path.(e.g., glTF, and DLI).</param>
70 /// <param name="resourcePath">resource file path that includes binary, image etc.</param>
71 /// <note> If resourcePath is empty, the parent directory path of modelPath is used for resource path. </note>
72 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
73 [EditorBrowsable(EditorBrowsableState.Never)]
74 public ModelView(string modelPath, string resourcePath = "") : this(Interop.ModelView.ModelViewNew(modelPath, resourcePath), true)
76 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
82 /// <param name="modelView">Handle to an object.</param>
83 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
84 [EditorBrowsable(EditorBrowsableState.Never)]
85 public ModelView(ModelView modelView) : this(Interop.ModelView.NewModelView(ModelView.getCPtr(modelView)), true)
87 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
91 /// Retrieves model root View.
94 /// This ModelRoot means a root View that contains 3D models to render.
95 /// The light source is only applied on the models under this ModelRoot.
97 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
98 [EditorBrowsable(EditorBrowsableState.Never)]
103 return GetModelRoot();
108 /// Fits the model to the View size.
109 /// If this property is true, the model is resized to fit the width or height of the View by scaling the ModelRoot.
111 /// This property only changes model size not the pivot.
114 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
115 [EditorBrowsable(EditorBrowsableState.Never)]
116 public bool UseSizeOfView
120 return useSizeOfView;
124 useSizeOfView = value;
125 Interop.ModelView.FitSize(SwigCPtr, useSizeOfView);
126 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
131 /// Moves the model to the center of ModelView.
132 /// If this property is true, the model moves so that the center is located at the center of the View by change PivotPoint of ModelRoot.
134 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
135 [EditorBrowsable(EditorBrowsableState.Never)]
136 public bool UseCenterOfView
140 return useCenterOfView;
144 useCenterOfView = value;
145 Interop.ModelView.FitCenter(SwigCPtr, useCenterOfView);
146 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
151 /// Assignment operator.
153 /// <param name="modelView">Handle to an object.</param>
154 /// <returns>Reference to this.</returns>
155 internal ModelView Assign(ModelView modelView)
157 ModelView ret = new ModelView(Interop.ModelView.ModelViewAssign(SwigCPtr, ModelView.getCPtr(modelView)), false);
158 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
163 /// Changes Image Based Light as the input textures.
165 /// <param name="diffuse">Cube map that can be used as a diffuse IBL source.</param>
166 /// <param name="specular">Cube map that can be used as a specular IBL source.</param>
167 /// <param name="scaleFactor">Scale factor that controls light source intensity in [0.0f, 1.0f]. Default value is 1.0f.</param>
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 SetImageBasedLightSource(string diffuse, string specular, float scaleFactor = 1.0f)
172 Interop.ModelView.SetImageBasedLightSource(SwigCPtr, diffuse, specular, scaleFactor);
173 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
177 /// Gets number of animations those loaded from model file.
178 /// Note: This method should be called after Model load finished.
180 /// <returns>The number of loaded animations.</returns>
181 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
182 [EditorBrowsable(EditorBrowsableState.Never)]
183 public uint GetAnimationCount()
185 uint ret = Interop.ModelView.GetAnimationCount(SwigCPtr);
186 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
191 /// Gets animation at the index.
192 /// Note: This method should be called after Model load finished.
194 /// <param name="index">Index of animation to be retrieved.</param>
195 /// <returns>Animation at the index.</returns>
196 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
197 [EditorBrowsable(EditorBrowsableState.Never)]
198 public Animation GetAnimation(uint index)
200 Animation ret = new Animation(Interop.ModelView.GetAnimation(SwigCPtr, index), false);
201 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
206 /// Retrieves animation with the given name.
207 /// Note: This method should be called after Model load finished.
209 /// <param name="name">String name of animation to be retrieved.</param>
210 /// <returns>Animation that has the given name.</returns>
211 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
212 [EditorBrowsable(EditorBrowsableState.Never)]
213 public Animation GetAnimation(string name)
215 Animation ret = new Animation(Interop.ModelView.GetAnimation(SwigCPtr, name), false);
216 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
221 /// Retrieves model root Actor.
223 /// <returns>Root View of the model.</returns>
224 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
225 [EditorBrowsable(EditorBrowsableState.Never)]
226 private View GetModelRoot()
228 View ret = new View(Interop.ModelView.GetModelRoot(SwigCPtr), false);
229 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
234 /// Release swigCPtr.
236 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
237 [EditorBrowsable(EditorBrowsableState.Never)]
238 protected override void ReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr)
240 Interop.ModelView.DeleteModelView(swigCPtr);