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;
22 using Tizen.NUI.Binding;
23 using Tizen.NUI.BaseComponents;
25 namespace Tizen.NUI.Scene3D
28 /// Model is a Class to show 3D mesh objects.
29 /// Model supports to load glTF 2.0 and DLI models for the input format
30 /// and also supports Physically Based Rendering with Image Based Lighting.
32 /// The Animations defined in the glTF or DLI are also loaded and can be retrieved by using GetAnimation() method.
33 /// The number of animation is also retrieved by GetAnimationCount() method.
35 /// By default, The loaded mesh has it's own size inferred from position of vertices.
36 /// If user set size property, the mesh will be scaled to the input size.
38 /// Both of the default value of PivotPoint and ParentOrigin of the Model is Center.
42 /// Model model = new Model(modelUrl)
44 /// Size = new Size(width, height),
46 /// model.SetImageBasedLightSource(diffuseUrl, specularUrl, scaleFactor);
47 /// window.Add(model);
49 /// int animationCount = model.GetAnimationCount();
50 /// if(animationCount > 0)
52 /// model.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 Model : View
59 internal Model(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
64 /// Create an initialized Model.
66 /// <param name="modelPath">model file path.(e.g., glTF, and DLI).</param>
67 /// <param name="resourcePath">resource file path that includes binary, image etc.</param>
68 /// <note> If resourcePath is empty, the parent directory path of modelPath is used for resource path. </note>
69 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
70 [EditorBrowsable(EditorBrowsableState.Never)]
71 public Model(string modelPath, string resourcePath = "") : this(Interop.Model.ModelNew(modelPath, resourcePath), true)
73 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
74 Interop.Model.FitSize(SwigCPtr, true);
75 this.ParentOrigin = Tizen.NUI.ParentOrigin.Center;
76 this.PivotPoint = Tizen.NUI.PivotPoint.Center;
77 this.PositionUsesAnchorPoint = true;
83 /// <param name="modelView">Handle to an object.</param>
84 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
85 [EditorBrowsable(EditorBrowsableState.Never)]
86 public Model(Model modelView) : this(Interop.Model.NewModel(Model.getCPtr(modelView)), true)
88 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
92 /// Assignment operator.
94 /// <param name="modelView">Handle to an object.</param>
95 /// <returns>Reference to this.</returns>
96 internal Model Assign(Model modelView)
98 Model ret = new Model(Interop.Model.ModelAssign(SwigCPtr, Model.getCPtr(modelView)), false);
99 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
104 /// Changes Image Based Light as the input textures.
106 /// <param name="diffuseUrl">The path of Cube map image that can be used as a diffuse IBL source.</param>
107 /// <param name="specularUrl">The path of Cube map image that can be used as a specular IBL source.</param>
108 /// <param name="scaleFactor">Scale factor that controls light source intensity in [0.0f, 1.0f]. Default value is 1.0f.</param>
109 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
110 [EditorBrowsable(EditorBrowsableState.Never)]
111 public void SetImageBasedLightSource(string diffuseUrl, string specularUrl, float scaleFactor = 1.0f)
113 Interop.Model.SetImageBasedLightSource(SwigCPtr, diffuseUrl, specularUrl, scaleFactor);
114 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
118 /// Gets number of animations those loaded from model file.
119 /// Note: This method should be called after Model load finished.
121 /// <returns>The number of loaded animations.</returns>
122 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
123 [EditorBrowsable(EditorBrowsableState.Never)]
124 public uint GetAnimationCount()
126 uint ret = Interop.Model.GetAnimationCount(SwigCPtr);
127 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
132 /// Gets animation at the index.
133 /// Note: This method should be called after Model load finished.
135 /// <param name="index">Index of animation to be retrieved.</param>
136 /// <returns>Animation at the index.</returns>
137 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
138 [EditorBrowsable(EditorBrowsableState.Never)]
139 public Animation GetAnimation(uint index)
141 Animation ret = new Animation(Interop.Model.GetAnimation(SwigCPtr, index), false);
142 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
147 /// Retrieves animation with the given name.
148 /// Note: This method should be called after Model load finished.
150 /// <param name="name">String name of animation to be retrieved.</param>
151 /// <returns>Animation that has the given name.</returns>
152 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
153 [EditorBrowsable(EditorBrowsableState.Never)]
154 public Animation GetAnimation(string name)
156 Animation ret = new Animation(Interop.Model.GetAnimation(SwigCPtr, name), false);
157 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
162 /// Retrieves model root Actor.
164 /// <returns>Root View of the model.</returns>
165 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
166 [EditorBrowsable(EditorBrowsableState.Never)]
167 private View GetModelRoot()
169 View ret = new View(Interop.Model.GetModelRoot(SwigCPtr), false);
170 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
175 /// Release swigCPtr.
177 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
178 [EditorBrowsable(EditorBrowsableState.Never)]
179 protected override void ReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr)
181 Interop.Model.DeleteModel(swigCPtr);