[dali_2.2.15] Merge branch 'devel/master'
[platform/core/uifw/dali-csharp-binder.git] / dali-csharp-binder / src / model-wrap.cpp
1 /*
2  * Copyright (c) 2022 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 // EXTERNAL INCLUDES
19 #include <dali-scene3d/public-api/controls/model/model.h>
20 #include <dali-scene3d/public-api/loader/bvh-loader.h>
21
22 // INTERNAL INCLUDES
23 #include "common.h"
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_New_SWIG_0(char* csModelPath, char* csResourcePath)
30 {
31   Dali::Scene3D::Model result;
32
33   if(!csModelPath)
34   {
35     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0);
36     return 0;
37   }
38   std::string modelPath(csModelPath);
39
40   if(!csResourcePath)
41   {
42     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0);
43     return 0;
44   }
45   std::string resourcePath(csResourcePath);
46
47   {
48     try
49     {
50       result = Dali::Scene3D::Model::New(modelPath, resourcePath);
51     }
52     CALL_CATCH_EXCEPTION(0);
53   }
54
55   return new Dali::Scene3D::Model((const Dali::Scene3D::Model&)result);
56 }
57
58 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_new_Model_SWIG_0()
59 {
60   Dali::Scene3D::Model* result = 0;
61
62   {
63     try
64     {
65       result = (Dali::Scene3D::Model*)new Dali::Scene3D::Model();
66     }
67     CALL_CATCH_EXCEPTION(0);
68   }
69
70   return (void*)result;
71 }
72
73 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_new_Model_SWIG_1(void* csModel)
74 {
75   Dali::Scene3D::Model* model  = (Dali::Scene3D::Model*)csModel;
76   Dali::Scene3D::Model* result = 0;
77
78   if(!model)
79   {
80     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Dali::Scene3D::Model const & type is null", 0);
81     return 0;
82   }
83   {
84     try
85     {
86       result = (Dali::Scene3D::Model*)new Dali::Scene3D::Model((Dali::Scene3D::Model const&)*model);
87     }
88     CALL_CATCH_EXCEPTION(0);
89   }
90
91   return (void*)result;
92 }
93
94 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_delete_Model(void* csModel)
95 {
96   Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
97   {
98     try
99     {
100       delete model;
101     }
102     CALL_CATCH_EXCEPTION();
103   }
104 }
105
106 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_Assign(void* csDestination, void* csSource)
107 {
108   Dali::Scene3D::Model* destination = (Dali::Scene3D::Model*)csDestination;
109   Dali::Scene3D::Model* source      = (Dali::Scene3D::Model*)csSource;
110   Dali::Scene3D::Model* result      = 0;
111
112   if(!source)
113   {
114     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Dali::Scene3D::Model const & type is null", 0);
115     return 0;
116   }
117   {
118     try
119     {
120       result = (Dali::Scene3D::Model*)&(destination)->operator=((Dali::Scene3D::Model const&)*source);
121     }
122     CALL_CATCH_EXCEPTION(0);
123   }
124
125   return (void*)result;
126 }
127
128 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_DownCast(void* csHandle)
129 {
130   Dali::BaseHandle*    handle = (Dali::BaseHandle*)csHandle;
131   Dali::Scene3D::Model result;
132
133   if(!handle)
134   {
135     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
136     return 0;
137   }
138   {
139     try
140     {
141       result = Dali::Scene3D::Model::DownCast(*handle);
142     }
143     CALL_CATCH_EXCEPTION(0);
144   }
145
146   return new Dali::Scene3D::Model((const Dali::Scene3D::Model&)result);
147 }
148
149 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_GetModelRoot(void* csModel)
150 {
151   Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
152   Dali::Actor           result;
153
154   if(!model)
155   {
156     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
157     return 0;
158   }
159   {
160     try
161     {
162       result = model->GetModelRoot();
163     }
164     CALL_CATCH_EXCEPTION(0);
165   }
166
167   return new Dali::Actor((const Dali::Actor&)result);
168 }
169
170 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_Model_SetChildrenSensitive(void* csModel, bool enable)
171 {
172   Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
173
174   if(!model)
175   {
176     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
177     return;
178   }
179   {
180     try
181     {
182       model->SetChildrenSensitive(enable);
183     }
184     CALL_CATCH_EXCEPTION();
185   }
186 }
187
188 SWIGEXPORT bool SWIGSTDCALL CSharp_Dali_Model_GetChildrenSensitive(void* csModel)
189 {
190   Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
191   bool                  result;
192
193   if(!model)
194   {
195     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
196     return false;
197   }
198   {
199     try
200     {
201       result = model->GetChildrenSensitive();
202     }
203     CALL_CATCH_EXCEPTION(0);
204   }
205   return result;
206 }
207
208 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_Model_SetImageBasedLightSource(void* csModel, char* csDiffuseUrl, char* csSpecularUrl, float scaleFactor)
209 {
210   Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
211
212   if(!model)
213   {
214     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
215     return;
216   }
217   if(!csDiffuseUrl)
218   {
219     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0);
220     return;
221   }
222   std::string diffuseUrl(csDiffuseUrl);
223   if(!csSpecularUrl)
224   {
225     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0);
226     return;
227   }
228   std::string specularUrl(csSpecularUrl);
229   {
230     try
231     {
232       model->SetImageBasedLightSource(diffuseUrl, specularUrl, scaleFactor);
233     }
234     CALL_CATCH_EXCEPTION();
235   }
236 }
237
238 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_Model_SetImageBasedLightScaleFactor(void* csModel, float scaleFactor)
239 {
240   Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
241
242   if(!model)
243   {
244     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
245     return;
246   }
247   {
248     try
249     {
250       model->SetImageBasedLightScaleFactor(scaleFactor);
251     }
252     CALL_CATCH_EXCEPTION();
253   }
254 }
255
256 SWIGEXPORT float SWIGSTDCALL CSharp_Dali_Model_GetImageBasedLightScaleFactor(void* csModel)
257 {
258   Dali::Scene3D::Model* model       = (Dali::Scene3D::Model*)csModel;
259   float                 scaleFactor = 1.0f;
260
261   if(!model)
262   {
263     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
264     return scaleFactor;
265   }
266   {
267     try
268     {
269       scaleFactor = model->GetImageBasedLightScaleFactor();
270     }
271     CALL_CATCH_EXCEPTION(0.0f);
272   }
273   return scaleFactor;
274 }
275
276 SWIGEXPORT unsigned int SWIGSTDCALL CSharp_Dali_Model_GetAnimationCount(void* csModel)
277 {
278   Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
279   unsigned int          result;
280
281   if(!model)
282   {
283     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
284     return 0;
285   }
286   {
287     try
288     {
289       result = model->GetAnimationCount();
290     }
291     CALL_CATCH_EXCEPTION(0);
292   }
293
294   return result;
295 }
296
297 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_GetAnimation_1(void* csModel, unsigned int index)
298 {
299   Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
300   Dali::Animation       result;
301
302   if(!model)
303   {
304     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
305     return 0;
306   }
307   {
308     try
309     {
310       result = model->GetAnimation(index);
311     }
312     CALL_CATCH_EXCEPTION(0);
313   }
314
315   return new Dali::Animation((const Dali::Animation&)result);
316 }
317
318 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_GetAnimation_2(void* csModel, char* csName)
319 {
320   Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
321   Dali::Animation       result;
322
323   if(!model)
324   {
325     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
326     return 0;
327   }
328   if(!csName)
329   {
330     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0);
331     return 0;
332   }
333   std::string name(csName);
334   {
335     try
336     {
337       result = model->GetAnimation(name);
338     }
339     CALL_CATCH_EXCEPTION(0);
340   }
341
342   return new Dali::Animation((const Dali::Animation&)result);
343 }
344
345 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_LoadBvhAnimation_1(void* csModel, char* csFileName, void* csScale)
346 {
347   Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
348   Dali::Animation       result;
349
350   if(!model)
351   {
352     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
353     return 0;
354   }
355   if(!csFileName)
356   {
357     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string for filename", 0);
358     return 0;
359   }
360
361   Dali::Vector3 scale = Dali::Vector3::ONE;
362   // csScale is option.
363   if(csScale != nullptr)
364   {
365     scale = Dali::Vector3(*static_cast<const Dali::Vector3 *>(csScale));
366   }
367   std::string filename(csFileName);
368   {
369     try
370     {
371       Dali::Scene3D::Loader::AnimationDefinition animationDefinition = Dali::Scene3D::Loader::LoadBvh(filename, "LoadedBvhAnimation", scale);
372       Dali::Scene3D::Loader::AnimatedProperty::GetActor getActor = [&model](const Dali::Scene3D::Loader::AnimatedProperty& property)->Dali::Actor{
373         return model->FindChildByName(property.mNodeName);
374       };
375       result = animationDefinition.ReAnimate(getActor);
376     }
377     CALL_CATCH_EXCEPTION(0);
378   }
379
380   return new Dali::Animation((const Dali::Animation&)result);
381 }
382
383 #ifdef __cplusplus
384 }
385 #endif