[NUI] Use ModelNode for the child of Model
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Scene3D / src / public / ModelComponents / ModelNode.cs
1 /*
2  * Copyright(c) 2023 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 using System;
19 using System.Runtime.InteropServices;
20 using System.ComponentModel;
21 using Tizen.NUI;
22 using Tizen.NUI.Binding;
23 using Tizen.NUI.BaseComponents;
24
25 namespace Tizen.NUI.Scene3D
26 {
27     /// <summary>
28     /// ModelNode is a class for representing the Node of Model in Scene3D.
29     /// </summary>
30     ///
31     /// <remarks>
32     /// ModelNode contains multiple ModelPrimitives and allows easy access and
33     /// modification of Material information that ModelPrimitive has. If a 3D
34     /// format file is loaded by Model, ModelNode is created internally to
35     /// construct the model. In addition, you can create a Custom ModelNode
36     /// using ModelPrimitive and Material directly and add it to Model.
37     ///
38     /// <code>
39     /// ModelNode modelNode = new ModelNode();
40     /// ModelPrimitive modelPrimitive = new ModelPrimitive();
41     /// modelNode.AddModelPrimitive(modelPrimitive);
42     ///
43     /// Material material = new Material;
44     /// modelPrimitive.Material = material;
45     /// </code>
46     /// </remarks>
47     [EditorBrowsable(EditorBrowsableState.Never)]
48     public class ModelNode : View
49     {
50         internal ModelNode(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
51         {
52         }
53
54         /// <summary>
55         /// Create an initialized ModelNode.
56         /// </summary>
57         [EditorBrowsable(EditorBrowsableState.Never)]
58         public ModelNode() : this(Interop.ModelNode.ModelNodeNew(), true)
59         {
60             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
61             this.PositionUsesAnchorPoint = true;
62         }
63
64         /// <summary>
65         /// Copy constructor.
66         /// </summary>
67         /// <param name="modelNode">Source object to copy.</param>
68         [EditorBrowsable(EditorBrowsableState.Never)]
69         public ModelNode(ModelNode modelNode) : this(Interop.ModelNode.NewModelNode(ModelNode.getCPtr(modelNode)), true)
70         {
71             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
72         }
73
74         /// <summary>
75         /// Assignment operator.
76         /// </summary>
77         /// <param name="modelNode">Source object to be assigned.</param>
78         /// <returns>Reference to this.</returns>
79         internal ModelNode Assign(ModelNode modelNode)
80         {
81             ModelNode ret = new ModelNode(Interop.ModelNode.ModelNodeAssign(SwigCPtr, ModelNode.getCPtr(modelNode)), false);
82             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
83             return ret;
84         }
85
86         /// <summary>
87         /// Get the number of ModelPrimitive of this ModelNode.
88         /// </summary>
89         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
90         [EditorBrowsable(EditorBrowsableState.Never)]
91         public uint ModelPrimitiveCount
92         {
93             get
94             {
95                 return GetModelPrimitiveCount();
96             }
97         }
98
99         /// <summary>
100         /// Adds a ModelPrimitive object to the ModelNode object.
101         /// </summary>
102         /// <param name="modelPrimitive">The ModelPrimitive object to add.</param>
103         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
104         [EditorBrowsable(EditorBrowsableState.Never)]
105         public void AddModelPrimitive(ModelPrimitive modelPrimitive)
106         {
107             Interop.ModelNode.AddModelPrimitive(SwigCPtr, ModelPrimitive.getCPtr(modelPrimitive));
108             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
109         }
110
111         /// <summary>
112         /// Removes a ModelPrimitive object from the ModelNode object.
113         /// </summary>
114         /// <param name="modelPrimitive">The ModelPrimitive object to remove.</param>
115         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
116         [EditorBrowsable(EditorBrowsableState.Never)]
117         public void RemoveModelPrimitive(ModelPrimitive modelPrimitive)
118         {
119             Interop.ModelNode.RemoveModelPrimitive(SwigCPtr, ModelPrimitive.getCPtr(modelPrimitive));
120             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
121         }
122
123         /// <summary>
124         /// Removes a ModelPrimitive object from the ModelNode object at the specified index.
125         /// </summary>
126         /// <param name="index">The index of the ModelPrimitive object to remove.</param>
127         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
128         [EditorBrowsable(EditorBrowsableState.Never)]
129         public void RemoveModelPrimitive(uint index)
130         {
131             Interop.ModelNode.RemoveModelPrimitive(SwigCPtr, index);
132             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
133         }
134
135         /// <summary>
136         /// Gets the ModelPrimitive object at the specified index.
137         /// </summary>
138         /// <param name="index">The index of the ModelPrimitive object to get.</param>
139         /// <returns>The ModelPrimitive object at the specified index.</returns>
140         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
141         [EditorBrowsable(EditorBrowsableState.Never)]
142         public ModelPrimitive GetModelPrimitive(uint index)
143         {
144             global::System.IntPtr cPtr = Interop.ModelNode.GetModelPrimitive(SwigCPtr, index);
145             ModelPrimitive ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as ModelPrimitive;
146             if (ret == null)
147             {
148                 // Register new animatable into Registry.
149                 ret = new ModelPrimitive(cPtr, true);
150             }
151             else
152             {
153                 // We found matched NUI animatable. Reduce cPtr reference count.
154                 HandleRef handle = new HandleRef(this, cPtr);
155                 Tizen.NUI.Interop.BaseHandle.DeleteBaseHandle(handle);
156                 handle = new HandleRef(null, IntPtr.Zero);
157             }
158             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
159             return ret;
160         }
161
162         /// <summary>
163         /// Removes Returns a child ModelNode object with a name that matches nodeName.
164         /// </summary>
165         /// <param name="nodeName">The name of the child ModelNode object you want to find.</param>
166         /// <returns>Child ModelNode that has nodeName as name.</returns>
167         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
168         [EditorBrowsable(EditorBrowsableState.Never)]
169         public ModelNode FindChildModelNodeByName(string nodeName)
170         {
171             global::System.IntPtr cPtr = Interop.Model.FindChildModelNodeByName(SwigCPtr, nodeName);
172             ModelNode ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as ModelNode;
173             if (ret == null)
174             {
175                 // Register new animatable into Registry.
176                 ret = new ModelNode(cPtr, true);
177             }
178             else
179             {
180                 // We found matched NUI animatable. Reduce cPtr reference count.
181                 HandleRef handle = new HandleRef(this, cPtr);
182                 Tizen.NUI.Interop.BaseHandle.DeleteBaseHandle(handle);
183                 handle = new HandleRef(null, IntPtr.Zero);
184             }
185             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
186             return ret;
187         }
188
189         /// <summary>
190         /// Gets the number of ModelPrimitive objects in the ModelNode object.
191         /// </summary>
192         /// <returns>The number of ModelPrimitive objects in the ModelNode object.</returns>
193         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
194         [EditorBrowsable(EditorBrowsableState.Never)]
195         private uint GetModelPrimitiveCount()
196         {
197             uint ret = Interop.ModelNode.GetModelPrimitiveCount(SwigCPtr);
198             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
199             return ret;
200         }
201
202         /// <summary>
203         /// Release swigCPtr.
204         /// </summary>
205         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
206         [EditorBrowsable(EditorBrowsableState.Never)]
207         protected override void ReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr)
208         {
209             Interop.ModelNode.DeleteModelNode(swigCPtr);
210         }
211     }
212 }