1f23f10aa20e6c5028c687ea867cbb90c067336b
[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.PositionUsesPivotPoint = 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             ret.PositionUsesPivotPoint = modelNode.PositionUsesPivotPoint;
84             return ret;
85         }
86
87         /// <summary>
88         /// Get the number of ModelPrimitive of this ModelNode.
89         /// </summary>
90         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
91         [EditorBrowsable(EditorBrowsableState.Never)]
92         public uint ModelPrimitiveCount
93         {
94             get
95             {
96                 return GetModelPrimitiveCount();
97             }
98         }
99
100         /// <summary>
101         /// Adds a ModelPrimitive object to the ModelNode object.
102         /// </summary>
103         /// <param name="modelPrimitive">The ModelPrimitive object to add.</param>
104         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
105         [EditorBrowsable(EditorBrowsableState.Never)]
106         public void AddModelPrimitive(ModelPrimitive modelPrimitive)
107         {
108             Interop.ModelNode.AddModelPrimitive(SwigCPtr, ModelPrimitive.getCPtr(modelPrimitive));
109             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
110         }
111
112         /// <summary>
113         /// Removes a ModelPrimitive object from the ModelNode object.
114         /// </summary>
115         /// <param name="modelPrimitive">The ModelPrimitive object to remove.</param>
116         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
117         [EditorBrowsable(EditorBrowsableState.Never)]
118         public void RemoveModelPrimitive(ModelPrimitive modelPrimitive)
119         {
120             Interop.ModelNode.RemoveModelPrimitive(SwigCPtr, ModelPrimitive.getCPtr(modelPrimitive));
121             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
122         }
123
124         /// <summary>
125         /// Removes a ModelPrimitive object from the ModelNode object at the specified index.
126         /// </summary>
127         /// <param name="index">The index of the ModelPrimitive object to remove.</param>
128         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
129         [EditorBrowsable(EditorBrowsableState.Never)]
130         public void RemoveModelPrimitive(uint index)
131         {
132             Interop.ModelNode.RemoveModelPrimitive(SwigCPtr, index);
133             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
134         }
135
136         /// <summary>
137         /// Gets the ModelPrimitive object at the specified index.
138         /// </summary>
139         /// <param name="index">The index of the ModelPrimitive object to get.</param>
140         /// <returns>The ModelPrimitive object at the specified index.</returns>
141         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
142         [EditorBrowsable(EditorBrowsableState.Never)]
143         public ModelPrimitive GetModelPrimitive(uint index)
144         {
145             global::System.IntPtr cPtr = Interop.ModelNode.GetModelPrimitive(SwigCPtr, index);
146             ModelPrimitive ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as ModelPrimitive;
147             if (ret == null)
148             {
149                 // Register new animatable into Registry.
150                 ret = new ModelPrimitive(cPtr, true);
151             }
152             else
153             {
154                 // We found matched NUI animatable. Reduce cPtr reference count.
155                 HandleRef handle = new HandleRef(this, cPtr);
156                 Tizen.NUI.Interop.BaseHandle.DeleteBaseHandle(handle);
157                 handle = new HandleRef(null, IntPtr.Zero);
158             }
159             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
160             return ret;
161         }
162
163         /// <summary>
164         /// Removes Returns a child ModelNode object with a name that matches nodeName.
165         /// </summary>
166         /// <param name="nodeName">The name of the child ModelNode object you want to find.</param>
167         /// <returns>Child ModelNode that has nodeName as name.</returns>
168         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
169         [EditorBrowsable(EditorBrowsableState.Never)]
170         public ModelNode FindChildModelNodeByName(string nodeName)
171         {
172             global::System.IntPtr cPtr = Interop.Model.FindChildModelNodeByName(SwigCPtr, nodeName);
173             ModelNode ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as ModelNode;
174             if (ret == null)
175             {
176                 // Store the value of PositionUsesAnchorPoint from dali object (Since View object automatically change PositionUsesPivotPoint value as false, we need to keep value.)
177                 HandleRef handle = new HandleRef(this, cPtr);
178                 bool originalPositionUsesAnchorPoint = Object.InternalGetPropertyBool(handle, View.Property.PositionUsesAnchorPoint);
179                 handle = new HandleRef(null, IntPtr.Zero);
180
181                 // Register new animatable into Registry.
182                 ret = new ModelNode(cPtr, true);
183                 ret.PositionUsesPivotPoint = originalPositionUsesAnchorPoint;
184             }
185             else
186             {
187                 // We found matched NUI animatable. Reduce cPtr reference count.
188                 HandleRef handle = new HandleRef(this, cPtr);
189                 Tizen.NUI.Interop.BaseHandle.DeleteBaseHandle(handle);
190                 handle = new HandleRef(null, IntPtr.Zero);
191             }
192             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
193             return ret;
194         }
195
196         /// <summary>
197         /// Gets the number of ModelPrimitive objects in the ModelNode object.
198         /// </summary>
199         /// <returns>The number of ModelPrimitive objects in the ModelNode object.</returns>
200         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
201         [EditorBrowsable(EditorBrowsableState.Never)]
202         private uint GetModelPrimitiveCount()
203         {
204             uint ret = Interop.ModelNode.GetModelPrimitiveCount(SwigCPtr);
205             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
206             return ret;
207         }
208
209         /// <summary>
210         /// Release swigCPtr.
211         /// </summary>
212         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
213         [EditorBrowsable(EditorBrowsableState.Never)]
214         protected override void ReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr)
215         {
216             Interop.ModelNode.DeleteModelNode(swigCPtr);
217         }
218     }
219 }