Binder for ModelNode, ModelPrimitive, Material
[platform/core/uifw/dali-csharp-binder.git] / dali-csharp-binder / src / model-wrap.cpp
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 // EXTERNAL INCLUDES
19 #include <dali-scene3d/public-api/controls/model/model.h>
20 #include <dali-scene3d/public-api/loader/bvh-loader.h>
21 #include <dali-scene3d/public-api/loader/facial-animation-loader.h>
22
23 // INTERNAL INCLUDES
24 #include "common.h"
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_New_SWIG_0(char* csModelPath, char* csResourcePath)
31 {
32   Dali::Scene3D::Model result;
33
34   if(!csModelPath)
35   {
36     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0);
37     return 0;
38   }
39   std::string modelPath(csModelPath);
40
41   if(!csResourcePath)
42   {
43     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0);
44     return 0;
45   }
46   std::string resourcePath(csResourcePath);
47
48   {
49     try
50     {
51       result = Dali::Scene3D::Model::New(modelPath, resourcePath);
52     }
53     CALL_CATCH_EXCEPTION(0);
54   }
55
56   return new Dali::Scene3D::Model((const Dali::Scene3D::Model&)result);
57 }
58
59 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_New_SWIG_1()
60 {
61   Dali::Scene3D::Model result;
62
63   {
64     try
65     {
66       result = Dali::Scene3D::Model::New();
67     }
68     CALL_CATCH_EXCEPTION(0);
69   }
70
71   return new Dali::Scene3D::Model((const Dali::Scene3D::Model&)result);
72 }
73
74 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_new_Model_SWIG_0()
75 {
76   Dali::Scene3D::Model* result = 0;
77
78   {
79     try
80     {
81       result = (Dali::Scene3D::Model*)new Dali::Scene3D::Model();
82     }
83     CALL_CATCH_EXCEPTION(0);
84   }
85
86   return (void*)result;
87 }
88
89 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_new_Model_SWIG_1(void* csModel)
90 {
91   Dali::Scene3D::Model* model  = (Dali::Scene3D::Model*)csModel;
92   Dali::Scene3D::Model* result = 0;
93
94   if(!model)
95   {
96     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Dali::Scene3D::Model const & type is null", 0);
97     return 0;
98   }
99   {
100     try
101     {
102       result = (Dali::Scene3D::Model*)new Dali::Scene3D::Model((Dali::Scene3D::Model const&)*model);
103     }
104     CALL_CATCH_EXCEPTION(0);
105   }
106
107   return (void*)result;
108 }
109
110 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_delete_Model(void* csModel)
111 {
112   Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
113   {
114     try
115     {
116       delete model;
117     }
118     CALL_CATCH_EXCEPTION();
119   }
120 }
121
122 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_Assign(void* csDestination, void* csSource)
123 {
124   Dali::Scene3D::Model* destination = (Dali::Scene3D::Model*)csDestination;
125   Dali::Scene3D::Model* source      = (Dali::Scene3D::Model*)csSource;
126   Dali::Scene3D::Model* result      = 0;
127
128   if(!source)
129   {
130     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Dali::Scene3D::Model const & type is null", 0);
131     return 0;
132   }
133   {
134     try
135     {
136       result = (Dali::Scene3D::Model*)&(destination)->operator=((Dali::Scene3D::Model const&)*source);
137     }
138     CALL_CATCH_EXCEPTION(0);
139   }
140
141   return (void*)result;
142 }
143
144 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_DownCast(void* csHandle)
145 {
146   Dali::BaseHandle*    handle = (Dali::BaseHandle*)csHandle;
147   Dali::Scene3D::Model result;
148
149   if(!handle)
150   {
151     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
152     return 0;
153   }
154   {
155     try
156     {
157       result = Dali::Scene3D::Model::DownCast(*handle);
158     }
159     CALL_CATCH_EXCEPTION(0);
160   }
161
162   return new Dali::Scene3D::Model((const Dali::Scene3D::Model&)result);
163 }
164
165 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_GetModelRoot(void* csModel)
166 {
167   Dali::Scene3D::Model*    model = (Dali::Scene3D::Model*)csModel;
168   Dali::Scene3D::ModelNode result;
169
170   if(!model)
171   {
172     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
173     return 0;
174   }
175   {
176     try
177     {
178       result = model->GetModelRoot();
179     }
180     CALL_CATCH_EXCEPTION(0);
181   }
182
183   return new Dali::Scene3D::ModelNode((const Dali::Scene3D::ModelNode&)result);
184 }
185
186 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_Model_AddModelNode(void* csModel, void* csModelNode)
187 {
188   Dali::Scene3D::Model*     model     = (Dali::Scene3D::Model*)csModel;
189   Dali::Scene3D::ModelNode* modelNode = (Dali::Scene3D::ModelNode*)csModelNode;
190
191   if(!model)
192   {
193     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
194     return;
195   }
196
197   try
198   {
199     model->AddModelNode(*modelNode);
200   }
201   CALL_CATCH_EXCEPTION();
202 }
203
204 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_Model_RemoveModelNode(void* csModel, void* csModelNode)
205 {
206   Dali::Scene3D::Model*     model     = (Dali::Scene3D::Model*)csModel;
207   Dali::Scene3D::ModelNode* modelNode = (Dali::Scene3D::ModelNode*)csModelNode;
208
209   if(!model)
210   {
211     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
212     return;
213   }
214
215   try
216   {
217     model->RemoveModelNode(*modelNode);
218   }
219   CALL_CATCH_EXCEPTION();
220 }
221
222 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_Model_SetChildrenSensitive(void* csModel, bool enable)
223 {
224   Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
225
226   if(!model)
227   {
228     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
229     return;
230   }
231   {
232     try
233     {
234       model->SetChildrenSensitive(enable);
235     }
236     CALL_CATCH_EXCEPTION();
237   }
238 }
239
240 SWIGEXPORT bool SWIGSTDCALL CSharp_Dali_Model_GetChildrenSensitive(void* csModel)
241 {
242   Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
243   bool                  result;
244
245   if(!model)
246   {
247     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
248     return false;
249   }
250   {
251     try
252     {
253       result = model->GetChildrenSensitive();
254     }
255     CALL_CATCH_EXCEPTION(0);
256   }
257   return result;
258 }
259
260 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_Model_SetImageBasedLightSource(void* csModel, char* csDiffuseUrl, char* csSpecularUrl, float scaleFactor)
261 {
262   Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
263
264   if(!model)
265   {
266     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
267     return;
268   }
269   if(!csDiffuseUrl)
270   {
271     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0);
272     return;
273   }
274   std::string diffuseUrl(csDiffuseUrl);
275   if(!csSpecularUrl)
276   {
277     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0);
278     return;
279   }
280   std::string specularUrl(csSpecularUrl);
281   {
282     try
283     {
284       model->SetImageBasedLightSource(diffuseUrl, specularUrl, scaleFactor);
285     }
286     CALL_CATCH_EXCEPTION();
287   }
288 }
289
290 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_Model_SetImageBasedLightScaleFactor(void* csModel, float scaleFactor)
291 {
292   Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
293
294   if(!model)
295   {
296     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
297     return;
298   }
299   {
300     try
301     {
302       model->SetImageBasedLightScaleFactor(scaleFactor);
303     }
304     CALL_CATCH_EXCEPTION();
305   }
306 }
307
308 SWIGEXPORT float SWIGSTDCALL CSharp_Dali_Model_GetImageBasedLightScaleFactor(void* csModel)
309 {
310   Dali::Scene3D::Model* model       = (Dali::Scene3D::Model*)csModel;
311   float                 scaleFactor = 1.0f;
312
313   if(!model)
314   {
315     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
316     return scaleFactor;
317   }
318   {
319     try
320     {
321       scaleFactor = model->GetImageBasedLightScaleFactor();
322     }
323     CALL_CATCH_EXCEPTION(0.0f);
324   }
325   return scaleFactor;
326 }
327
328 SWIGEXPORT unsigned int SWIGSTDCALL CSharp_Dali_Model_GetAnimationCount(void* csModel)
329 {
330   Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
331   unsigned int          result;
332
333   if(!model)
334   {
335     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
336     return 0;
337   }
338   {
339     try
340     {
341       result = model->GetAnimationCount();
342     }
343     CALL_CATCH_EXCEPTION(0);
344   }
345
346   return result;
347 }
348
349 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_GetAnimation_1(void* csModel, unsigned int index)
350 {
351   Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
352   Dali::Animation       result;
353
354   if(!model)
355   {
356     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
357     return 0;
358   }
359   {
360     try
361     {
362       result = model->GetAnimation(index);
363     }
364     CALL_CATCH_EXCEPTION(0);
365   }
366
367   return new Dali::Animation((const Dali::Animation&)result);
368 }
369
370 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_GetAnimation_2(void* csModel, char* csName)
371 {
372   Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
373   Dali::Animation       result;
374
375   if(!model)
376   {
377     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
378     return 0;
379   }
380   if(!csName)
381   {
382     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0);
383     return 0;
384   }
385   std::string name(csName);
386   {
387     try
388     {
389       result = model->GetAnimation(name);
390     }
391     CALL_CATCH_EXCEPTION(0);
392   }
393
394   return new Dali::Animation((const Dali::Animation&)result);
395 }
396
397 SWIGEXPORT unsigned int SWIGSTDCALL CSharp_Dali_Model_GetCameraCount(void* csModel)
398 {
399   Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
400   unsigned int          result;
401
402   if(!model)
403   {
404     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
405     return 0;
406   }
407   {
408     try
409     {
410       result = model->GetCameraCount();
411     }
412     CALL_CATCH_EXCEPTION(0);
413   }
414
415   return result;
416 }
417
418 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_GenerateCamera(void* csModel, unsigned int index)
419 {
420   Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
421   Dali::CameraActor     result;
422
423   if(!model)
424   {
425     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
426     return 0;
427   }
428   {
429     try
430     {
431       result = model->GenerateCamera(index);
432     }
433     CALL_CATCH_EXCEPTION(0);
434   }
435
436   return new Dali::CameraActor((const Dali::CameraActor&)result);
437 }
438
439 SWIGEXPORT bool SWIGSTDCALL CSharp_Dali_Model_ApplyCamera(void* csModel, unsigned int index, void* csCameraActor)
440 {
441   Dali::Scene3D::Model* model       = (Dali::Scene3D::Model*)csModel;
442   Dali::CameraActor*    cameraActor = (Dali::CameraActor*)csCameraActor;
443   bool                  result;
444
445   if(!model)
446   {
447     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
448     return 0;
449   }
450   if(!cameraActor)
451   {
452     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::CameraActor", 0);
453     return 0;
454   }
455   {
456     try
457     {
458       result = model->ApplyCamera(index, *cameraActor);
459     }
460     CALL_CATCH_EXCEPTION(0);
461   }
462
463   return result;
464 }
465
466 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_FindChildModelNodeByName(void* csModel, char* nodeName)
467 {
468   Dali::Scene3D::Model*    model = (Dali::Scene3D::Model*)csModel;
469   Dali::Scene3D::ModelNode result;
470
471   if(!model)
472   {
473     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
474     return nullptr;
475   }
476
477   try
478   {
479     result = model->FindChildModelNodeByName(std::string_view(nodeName));
480   }
481   CALL_CATCH_EXCEPTION(nullptr);
482
483   return new Dali::Scene3D::ModelNode((const Dali::Scene3D::ModelNode&)result);
484 }
485
486 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_LoadBvhAnimation_1(void* csModel, char* csFileName, void* csScale)
487 {
488   Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
489   Dali::Animation       result;
490
491   if(!model)
492   {
493     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
494     return 0;
495   }
496   if(!csFileName)
497   {
498     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string for filename", 0);
499     return 0;
500   }
501
502   Dali::Vector3 scale = Dali::Vector3::ONE;
503   // csScale is option.
504   if(csScale != nullptr)
505   {
506     scale = Dali::Vector3(*static_cast<const Dali::Vector3*>(csScale));
507   }
508   std::string filename(csFileName);
509   {
510     try
511     {
512       Dali::Scene3D::Loader::AnimationDefinition        animationDefinition = Dali::Scene3D::Loader::LoadBvh(filename, "LoadedBvhAnimation", scale);
513       Dali::Scene3D::Loader::AnimatedProperty::GetActor getActor            = [&model](const Dali::Scene3D::Loader::AnimatedProperty& property) -> Dali::Actor {
514         return model->FindChildByName(property.mNodeName);
515       };
516       result = animationDefinition.ReAnimate(getActor);
517     }
518     CALL_CATCH_EXCEPTION(0);
519   }
520
521   return new Dali::Animation((const Dali::Animation&)result);
522 }
523
524 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_LoadFacialAnimation_1(void* csModel, char* csFileName)
525 {
526   Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
527   Dali::Animation       result;
528
529   if(!model)
530   {
531     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
532     return 0;
533   }
534   if(!csFileName)
535   {
536     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string for filename", 0);
537     return 0;
538   }
539
540   std::string filename(csFileName);
541   {
542     try
543     {
544       Dali::Scene3D::Loader::AnimationDefinition        animationDefinition = Dali::Scene3D::Loader::LoadFacialAnimation(filename);
545       Dali::Scene3D::Loader::AnimatedProperty::GetActor getActor            = [&model](const Dali::Scene3D::Loader::AnimatedProperty& property) -> Dali::Actor {
546         return model->FindChildByName(property.mNodeName);
547       };
548       result = animationDefinition.ReAnimate(getActor);
549     }
550     CALL_CATCH_EXCEPTION(0);
551   }
552
553   return new Dali::Animation((const Dali::Animation&)result);
554 }
555
556 #ifdef __cplusplus
557 }
558 #endif