[NUI] Use ModelNode for the child of Model
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Scene3D / src / public / ModelComponents / ModelPrimitive.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     /// Class for Model Primitives for 3D Geometry and Material.
29     /// </summary>
30     ///
31     /// <remarks>
32     /// This ModelPrimitive class is required to draw the mesh geometry defined by the user.
33     /// Users can set Geometry and Material to ModelPrimitive.
34     /// When ModelPrimitive added to ModelNode using ModelNode.AddModelPrimitive() method,
35     /// the Geometry is rendered on the screen according to the Material settings.
36     ///
37     /// If you load resources from 3D format files such as glTF using Model class,
38     /// ModelPrimitive is also created internally. In this case, blendShape morphing
39     /// or skeletal animation defined in the format can be used.
40     /// However, for the custom ModelPrimitive that is created by user, blendShape morphing or skeletal animation is not supported.
41     /// </remarks>
42     [EditorBrowsable(EditorBrowsableState.Never)]
43     public class ModelPrimitive : BaseHandle
44     {
45         internal ModelPrimitive(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
46         {
47         }
48
49         /// <summary>
50         /// Create an initialized ModelPrimitive.
51         /// </summary>
52         [EditorBrowsable(EditorBrowsableState.Never)]
53         public ModelPrimitive() : this(Interop.ModelPrimitive.ModelPrimitiveNew(), true)
54         {
55             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
56         }
57
58         /// <summary>
59         /// Copy constructor.
60         /// </summary>
61         /// <param name="modelPrimitive">Source object to copy.</param>
62         [EditorBrowsable(EditorBrowsableState.Never)]
63         public ModelPrimitive(ModelPrimitive modelPrimitive) : this(Interop.ModelPrimitive.NewModelPrimitive(ModelPrimitive.getCPtr(modelPrimitive)), true)
64         {
65             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
66         }
67
68         /// <summary>
69         /// Assignment operator.
70         /// </summary>
71         /// <param name="modelPrimitive">Source object to be assigned.</param>
72         /// <returns>Reference to this.</returns>
73         internal ModelPrimitive Assign(ModelPrimitive modelPrimitive)
74         {
75             ModelPrimitive ret = new ModelPrimitive(Interop.ModelPrimitive.ModelPrimitiveAssign(SwigCPtr, ModelPrimitive.getCPtr(modelPrimitive)), false);
76             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
77             return ret;
78         }
79
80         /// <summary>
81         /// The Geometry object of the ModelNode object.
82         /// </summary>
83         /// <remarks>
84         /// This Geometry object is for setting Geometry properties of 3D models. Also, Geometry can be shared with multiple ModelPrimitives and if the value is modified, the rendering results of all ModelPrimitives using this Geometry will be changed.
85         /// </remarks>
86         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
87         [EditorBrowsable(EditorBrowsableState.Never)]
88         public Geometry Geometry
89         {
90             set
91             {
92                 SetGeometry(value);
93             }
94             get
95             {
96                 return GetGeometry();
97             }
98         }
99
100         /// <summary>
101         /// The Material object of the ModelNode object.
102         /// </summary>
103         /// <remarks>
104         /// This Material object is for setting Material properties of 3D models. Also, Material can be shared with multiple ModelPrimitives and if the value is modified, the rendering results of all ModelPrimitives using this Material will be changed.
105         /// </remarks>
106         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
107         [EditorBrowsable(EditorBrowsableState.Never)]
108         public Material Material
109         {
110             set
111             {
112                 SetMaterial(value);
113             }
114             get
115             {
116                 return GetMaterial();
117             }
118         }
119
120         /// <summary>
121         /// Sets the geometry of the ModelPrimitive object.
122         /// </summary>
123         /// <param name="geometry">The Geometry object to set.</param>
124         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
125         [EditorBrowsable(EditorBrowsableState.Never)]
126         private void SetGeometry(Geometry geometry)
127         {
128             Interop.ModelPrimitive.SetGeometry(SwigCPtr, Geometry.getCPtr(geometry));
129             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
130         }
131
132         /// <summary>
133         /// Gets the geometry of the ModelPrimitive object.
134         /// </summary>
135         /// <returns>The Geometry object of the ModelPrimitive object.</returns>
136         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
137         [EditorBrowsable(EditorBrowsableState.Never)]
138         private Geometry GetGeometry()
139         {
140             IntPtr cPtr = Interop.ModelPrimitive.GetGeometry(SwigCPtr);
141             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
142             Geometry ret = (cPtr == IntPtr.Zero) ? null : Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Geometry;
143             return ret;
144         }
145
146         /// <summary>
147         /// Sets the material of the ModelPrimitive object.
148         /// </summary>
149         /// <param name="material">The Material object to set.</param>
150         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
151         [EditorBrowsable(EditorBrowsableState.Never)]
152         private void SetMaterial(Material material)
153         {
154             Interop.ModelPrimitive.SetMaterial(SwigCPtr, Material.getCPtr(material));
155             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
156         }
157
158         /// <summary>
159         /// Gets the material of the ModelPrimitive object.
160         /// </summary>
161         /// <returns>The Material object of the ModelPrimitive object.</returns>
162         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
163         [EditorBrowsable(EditorBrowsableState.Never)]
164         private Material GetMaterial()
165         {
166             IntPtr cPtr = Interop.ModelPrimitive.GetMaterial(SwigCPtr);
167             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
168             Material ret = (cPtr == IntPtr.Zero) ? null : Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Material;
169             return ret;
170         }
171
172         /// <summary>
173         /// Release swigCPtr.
174         /// </summary>
175         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
176         [EditorBrowsable(EditorBrowsableState.Never)]
177         protected override void ReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr)
178         {
179             Interop.ModelPrimitive.DeleteModelPrimitive(swigCPtr);
180         }
181     }
182 }