2 * Copyright(c) 2023 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.Collections.Generic;
20 using System.Runtime.InteropServices;
21 using System.ComponentModel;
23 using Tizen.NUI.Binding;
24 using Tizen.NUI.BaseComponents;
26 namespace Tizen.NUI.Scene3D
29 /// ModelNode is a class for representing the Node of Model in Scene3D.
33 /// ModelNode contains multiple ModelPrimitives and allows easy access and
34 /// modification of Material information that ModelPrimitive has. If a 3D
35 /// format file is loaded by Model, ModelNode is created internally to
36 /// construct the model. In addition, you can create a Custom ModelNode
37 /// using ModelPrimitive and Material directly and add it to Model.
40 /// ModelNode modelNode = new ModelNode();
41 /// ModelPrimitive modelPrimitive = new ModelPrimitive();
42 /// modelNode.AddModelPrimitive(modelPrimitive);
44 /// Material material = new Material;
45 /// modelPrimitive.Material = material;
48 [EditorBrowsable(EditorBrowsableState.Never)]
49 public class ModelNode : View
51 internal ModelNode(global::System.IntPtr cPtr, bool cMemoryOwn) : this(cPtr, cMemoryOwn, cMemoryOwn)
55 internal ModelNode(global::System.IntPtr cPtr, bool cMemoryOwn, bool cRegister) : base(cPtr, cMemoryOwn, true, cRegister)
60 /// Create an initialized ModelNode.
62 [EditorBrowsable(EditorBrowsableState.Never)]
63 public ModelNode() : this(Interop.ModelNode.ModelNodeNew(), true)
65 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
66 this.PositionUsesPivotPoint = true;
72 /// <param name="modelNode">Source object to copy.</param>
73 [EditorBrowsable(EditorBrowsableState.Never)]
74 public ModelNode(ModelNode modelNode) : this(Interop.ModelNode.NewModelNode(ModelNode.getCPtr(modelNode)), true, false)
76 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
80 /// Assignment operator.
82 /// <param name="modelNode">Source object to be assigned.</param>
83 /// <returns>Reference to this.</returns>
84 internal ModelNode Assign(ModelNode modelNode)
86 ModelNode ret = new ModelNode(Interop.ModelNode.ModelNodeAssign(SwigCPtr, ModelNode.getCPtr(modelNode)), false);
87 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
88 ret.PositionUsesPivotPoint = modelNode.PositionUsesPivotPoint;
93 /// Get the number of ModelPrimitive of this ModelNode.
95 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
96 [EditorBrowsable(EditorBrowsableState.Never)]
97 public uint ModelPrimitiveCount
101 return GetModelPrimitiveCount();
106 /// Adds a ModelPrimitive object to the ModelNode object.
108 /// <param name="modelPrimitive">The ModelPrimitive object to add.</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 AddModelPrimitive(ModelPrimitive modelPrimitive)
113 Interop.ModelNode.AddModelPrimitive(SwigCPtr, ModelPrimitive.getCPtr(modelPrimitive));
114 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
118 /// Removes a ModelPrimitive object from the ModelNode object.
120 /// <param name="modelPrimitive">The ModelPrimitive object to remove.</param>
121 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
122 [EditorBrowsable(EditorBrowsableState.Never)]
123 public void RemoveModelPrimitive(ModelPrimitive modelPrimitive)
125 Interop.ModelNode.RemoveModelPrimitive(SwigCPtr, ModelPrimitive.getCPtr(modelPrimitive));
126 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
130 /// Removes a ModelPrimitive object from the ModelNode object at the specified index.
132 /// <param name="index">The index of the ModelPrimitive object to remove.</param>
133 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
134 [EditorBrowsable(EditorBrowsableState.Never)]
135 public void RemoveModelPrimitive(uint index)
137 Interop.ModelNode.RemoveModelPrimitive(SwigCPtr, index);
138 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
142 /// Gets the ModelPrimitive object at the specified index.
144 /// <param name="index">The index of the ModelPrimitive object to get.</param>
145 /// <returns>The ModelPrimitive object at the specified index.</returns>
146 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
147 [EditorBrowsable(EditorBrowsableState.Never)]
148 public ModelPrimitive GetModelPrimitive(uint index)
150 global::System.IntPtr cPtr = Interop.ModelNode.GetModelPrimitive(SwigCPtr, index);
151 ModelPrimitive ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as ModelPrimitive;
154 // Register new animatable into Registry.
155 ret = new ModelPrimitive(cPtr, true);
159 // We found matched NUI animatable. Reduce cPtr reference count.
160 HandleRef handle = new HandleRef(this, cPtr);
161 Tizen.NUI.Interop.BaseHandle.DeleteBaseHandle(handle);
162 handle = new HandleRef(null, IntPtr.Zero);
164 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
169 /// Returns a child ModelNode object with a name that matches nodeName.
171 /// <param name="nodeName">The name of the child ModelNode object you want to find.</param>
172 /// <returns>Child ModelNode that has nodeName as name.</returns>
173 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
174 [EditorBrowsable(EditorBrowsableState.Never)]
175 public ModelNode FindChildModelNodeByName(string nodeName)
177 global::System.IntPtr cPtr = Interop.Model.FindChildModelNodeByName(SwigCPtr, nodeName);
178 ModelNode ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as ModelNode;
181 // Store the value of PositionUsesAnchorPoint from dali object (Since View object automatically change PositionUsesPivotPoint value as false, we need to keep value.)
182 HandleRef handle = new HandleRef(this, cPtr);
184 // Use original value as 'true' if we got invalid ModelNode.
185 bool originalPositionUsesAnchorPoint = (cPtr == global::System.IntPtr.Zero || !Tizen.NUI.Interop.BaseHandle.HasBody(handle)) || Object.InternalGetPropertyBool(handle, View.Property.PositionUsesAnchorPoint);
186 handle = new HandleRef(null, IntPtr.Zero);
188 // Register new animatable into Registry.
189 ret = new ModelNode(cPtr, true);
192 ret.PositionUsesPivotPoint = originalPositionUsesAnchorPoint;
197 // We found matched NUI animatable. Reduce cPtr reference count.
198 HandleRef handle = new HandleRef(this, cPtr);
199 Tizen.NUI.Interop.BaseHandle.DeleteBaseHandle(handle);
200 handle = new HandleRef(null, IntPtr.Zero);
202 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
207 /// Sets collider mesh on current node
209 /// <param name="vertexList">List of vertices</param>
210 /// <param name="normalList">List of vertex normals</param>
211 /// <param name="indexList">List of mesh indices</param>
212 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
213 [EditorBrowsable(EditorBrowsableState.Never)]
214 public void SetColliderMesh(List<Vector3> vertexList, List<Vector3> normalList, List<int> indexList)
216 var vertices = new Interop.ModelNode.Vec3[vertexList.Count];
218 foreach (var vertex in vertexList)
220 vertices[idx].x = vertex.X;
221 vertices[idx].y = vertex.Y;
222 vertices[idx].z = vertex.Z;
226 var normals = new Interop.ModelNode.Vec3[normalList.Count];
228 foreach (var normal in normalList)
230 normals[idx].x = normal.X;
231 normals[idx].y = normal.Y;
232 normals[idx].z = normal.Z;
236 Interop.ModelNode.SetColliderMesh(SwigCPtr,vertices, normals, vertexList.Count, indexList.ToArray(), indexList.Count);
237 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
241 /// Gets the number of ModelPrimitive objects in the ModelNode object.
243 /// <returns>The number of ModelPrimitive objects in the ModelNode object.</returns>
244 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
245 [EditorBrowsable(EditorBrowsableState.Never)]
246 private uint GetModelPrimitiveCount()
248 uint ret = Interop.ModelNode.GetModelPrimitiveCount(SwigCPtr);
249 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
254 /// Build C# ModelNode Tree
256 [EditorBrowsable(EditorBrowsableState.Never)]
257 internal void Build()
259 List<ModelNode> childModelNodes = new List<ModelNode>();
260 uint childModelNodeCount = GetChildModelNodeCount();
261 for (uint i = 0; i < childModelNodeCount; ++i)
263 ModelNode modelNode = GetChildModelNodeAt(i);
264 if (modelNode != null)
266 childModelNodes.Add(modelNode);
271 foreach (ModelNode node in childModelNodes)
278 /// Gets the number of child objects in the ModelNode object.
280 /// <returns>The number of childchild objects in the ModelNode object.</returns>
281 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
282 [EditorBrowsable(EditorBrowsableState.Never)]
283 private uint GetChildModelNodeCount()
285 uint ret = Interop.ModelNode.GetChildModelNodeCount(SwigCPtr);
286 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
291 /// Returns a child ModelNode object at the index.
293 /// <param name="index">The index of child ModelNode object you want to find.</param>
294 /// <returns>Child ModelNode</returns>
295 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
296 [EditorBrowsable(EditorBrowsableState.Never)]
297 private ModelNode GetChildModelNodeAt(uint index)
299 global::System.IntPtr cPtr = Interop.ModelNode.GetChildModelNodeAt(SwigCPtr, index);
300 ModelNode ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as ModelNode;
303 // Store the value of PositionUsesAnchorPoint from dali object (Since View object automatically change PositionUsesPivotPoint value as false, we need to keep value.)
304 HandleRef handle = new HandleRef(this, cPtr);
306 // Use original value as 'true' if we got invalid ModelNode.
307 bool originalPositionUsesAnchorPoint = (cPtr == global::System.IntPtr.Zero || !Tizen.NUI.Interop.BaseHandle.HasBody(handle)) || Object.InternalGetPropertyBool(handle, View.Property.PositionUsesAnchorPoint);
308 handle = new HandleRef(null, IntPtr.Zero);
310 // Register new animatable into Registry.
311 ret = new ModelNode(cPtr, true);
314 ret.PositionUsesPivotPoint = originalPositionUsesAnchorPoint;
319 // We found matched NUI animatable. Reduce cPtr reference count.
320 HandleRef handle = new HandleRef(this, cPtr);
321 Tizen.NUI.Interop.BaseHandle.DeleteBaseHandle(handle);
322 handle = new HandleRef(null, IntPtr.Zero);
324 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
329 /// Release swigCPtr.
331 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
332 [EditorBrowsable(EditorBrowsableState.Never)]
333 protected override void ReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr)
335 Interop.ModelNode.DeleteModelNode(swigCPtr);