2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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 #include <dali-scene3d/public-api/model-motion/motion-data.h>
23 #include <dali/devel-api/animation/key-frames-devel.h>
26 #include <dali-csharp-binder/common/common.h>
32 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_New_SWIG_0(char* csModelPath, char* csResourcePath)
34 Dali::Scene3D::Model result;
38 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0);
41 std::string modelPath(csModelPath);
45 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0);
48 std::string resourcePath(csResourcePath);
53 result = Dali::Scene3D::Model::New(modelPath, resourcePath);
55 CALL_CATCH_EXCEPTION(0);
58 return new Dali::Scene3D::Model((const Dali::Scene3D::Model&)result);
61 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_New_SWIG_1()
63 Dali::Scene3D::Model result;
68 result = Dali::Scene3D::Model::New();
70 CALL_CATCH_EXCEPTION(0);
73 return new Dali::Scene3D::Model((const Dali::Scene3D::Model&)result);
76 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_new_Model_SWIG_0()
78 Dali::Scene3D::Model* result = 0;
83 result = (Dali::Scene3D::Model*)new Dali::Scene3D::Model();
85 CALL_CATCH_EXCEPTION(0);
91 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_new_Model_SWIG_1(void* csModel)
93 Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
94 Dali::Scene3D::Model* result = 0;
98 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Dali::Scene3D::Model const & type is null", 0);
104 result = (Dali::Scene3D::Model*)new Dali::Scene3D::Model((Dali::Scene3D::Model const&)*model);
106 CALL_CATCH_EXCEPTION(0);
109 return (void*)result;
112 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_delete_Model(void* csModel)
114 Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
120 CALL_CATCH_EXCEPTION();
124 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_Assign(void* csDestination, void* csSource)
126 Dali::Scene3D::Model* destination = (Dali::Scene3D::Model*)csDestination;
127 Dali::Scene3D::Model* source = (Dali::Scene3D::Model*)csSource;
128 Dali::Scene3D::Model* result = 0;
132 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Dali::Scene3D::Model const & type is null", 0);
138 result = (Dali::Scene3D::Model*)&(destination)->operator=((Dali::Scene3D::Model const&)*source);
140 CALL_CATCH_EXCEPTION(0);
143 return (void*)result;
146 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_DownCast(void* csHandle)
148 Dali::BaseHandle* handle = (Dali::BaseHandle*)csHandle;
149 Dali::Scene3D::Model result;
153 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
159 result = Dali::Scene3D::Model::DownCast(*handle);
161 CALL_CATCH_EXCEPTION(0);
164 return new Dali::Scene3D::Model((const Dali::Scene3D::Model&)result);
167 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_GetModelRoot(void* csModel)
169 Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
170 Dali::Scene3D::ModelNode result;
174 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
180 result = model->GetModelRoot();
182 CALL_CATCH_EXCEPTION(0);
185 return new Dali::Scene3D::ModelNode((const Dali::Scene3D::ModelNode&)result);
188 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_Model_AddModelNode(void* csModel, void* csModelNode)
190 Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
191 Dali::Scene3D::ModelNode* modelNode = (Dali::Scene3D::ModelNode*)csModelNode;
195 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
201 model->AddModelNode(*modelNode);
203 CALL_CATCH_EXCEPTION();
206 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_Model_RemoveModelNode(void* csModel, void* csModelNode)
208 Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
209 Dali::Scene3D::ModelNode* modelNode = (Dali::Scene3D::ModelNode*)csModelNode;
213 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
219 model->RemoveModelNode(*modelNode);
221 CALL_CATCH_EXCEPTION();
224 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_Model_SetChildrenSensitive(void* csModel, bool enable)
226 Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
230 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
236 model->SetChildrenSensitive(enable);
238 CALL_CATCH_EXCEPTION();
242 SWIGEXPORT bool SWIGSTDCALL CSharp_Dali_Model_GetChildrenSensitive(void* csModel)
244 Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
249 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
255 result = model->GetChildrenSensitive();
257 CALL_CATCH_EXCEPTION(0);
262 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_Model_SetImageBasedLightSource(void* csModel, char* csDiffuseUrl, char* csSpecularUrl, float scaleFactor)
264 Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
268 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
273 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0);
276 std::string diffuseUrl(csDiffuseUrl);
279 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0);
282 std::string specularUrl(csSpecularUrl);
286 model->SetImageBasedLightSource(diffuseUrl, specularUrl, scaleFactor);
288 CALL_CATCH_EXCEPTION();
292 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_Model_SetImageBasedLightScaleFactor(void* csModel, float scaleFactor)
294 Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
298 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
304 model->SetImageBasedLightScaleFactor(scaleFactor);
306 CALL_CATCH_EXCEPTION();
310 SWIGEXPORT float SWIGSTDCALL CSharp_Dali_Model_GetImageBasedLightScaleFactor(void* csModel)
312 Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
313 float scaleFactor = 1.0f;
317 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
323 scaleFactor = model->GetImageBasedLightScaleFactor();
325 CALL_CATCH_EXCEPTION(0.0f);
330 SWIGEXPORT unsigned int SWIGSTDCALL CSharp_Dali_Model_GetAnimationCount(void* csModel)
332 Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
337 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
343 result = model->GetAnimationCount();
345 CALL_CATCH_EXCEPTION(0);
351 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_GetAnimation_1(void* csModel, unsigned int index)
353 Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
354 Dali::Animation result;
358 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
364 result = model->GetAnimation(index);
366 CALL_CATCH_EXCEPTION(0);
369 return new Dali::Animation((const Dali::Animation&)result);
372 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_GetAnimation_2(void* csModel, char* csName)
374 Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
375 Dali::Animation result;
379 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
384 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0);
387 std::string name(csName);
391 result = model->GetAnimation(name);
393 CALL_CATCH_EXCEPTION(0);
396 return new Dali::Animation((const Dali::Animation&)result);
399 SWIGEXPORT unsigned int SWIGSTDCALL CSharp_Dali_Model_GetCameraCount(void* csModel)
401 Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
406 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
412 result = model->GetCameraCount();
414 CALL_CATCH_EXCEPTION(0);
420 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_GenerateCamera(void* csModel, unsigned int index)
422 Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
423 Dali::CameraActor result;
427 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
433 result = model->GenerateCamera(index);
435 CALL_CATCH_EXCEPTION(0);
438 return new Dali::CameraActor((const Dali::CameraActor&)result);
441 SWIGEXPORT bool SWIGSTDCALL CSharp_Dali_Model_ApplyCamera(void* csModel, unsigned int index, void* csCameraActor)
443 Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
444 Dali::CameraActor* cameraActor = (Dali::CameraActor*)csCameraActor;
449 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
454 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::CameraActor", 0);
460 result = model->ApplyCamera(index, *cameraActor);
462 CALL_CATCH_EXCEPTION(0);
468 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_FindChildModelNodeByName(void* csModel, char* nodeName)
470 Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
471 Dali::Scene3D::ModelNode result;
475 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
481 result = model->FindChildModelNodeByName(std::string_view(nodeName));
483 CALL_CATCH_EXCEPTION(nullptr);
485 return new Dali::Scene3D::ModelNode((const Dali::Scene3D::ModelNode&)result);
488 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_GenerateMotionDataAnimation(void* csModel, void* csMotionData)
490 Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
491 Dali::Scene3D::MotionData* motionData = (Dali::Scene3D::MotionData*)csMotionData;
492 Dali::Animation result;
496 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
501 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::MotionData", 0);
507 result = model->GenerateMotionDataAnimation(*motionData);
509 CALL_CATCH_EXCEPTION(nullptr);
511 return new Dali::Animation((const Dali::Animation&)result);
514 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_Model_SetMotionData(void* csModel, void* csMotionData)
516 Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
517 Dali::Scene3D::MotionData* motionData = (Dali::Scene3D::MotionData*)csMotionData;
521 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
526 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::MotionData", 0);
532 model->SetMotionData(*motionData);
534 CALL_CATCH_EXCEPTION();
537 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_LoadBvhAnimation_1(void* csModel, char* csFileName, void* csScale, bool csUseRootNodeTranslate)
539 Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
540 Dali::Animation result;
544 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
549 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string for filename", 0);
553 Dali::Vector3 scale = Dali::Vector3::ONE;
554 // csScale is option.
555 if(csScale != nullptr)
557 scale = Dali::Vector3(*static_cast<const Dali::Vector3*>(csScale));
560 std::string filename(csFileName);
564 Dali::Scene3D::Loader::AnimationDefinition animationDefinition = Dali::Scene3D::Loader::LoadBvh(filename, "LoadedBvhAnimation", scale);
566 if(csUseRootNodeTranslate && animationDefinition.GetPropertyCount() > 0u)
568 // We can assume that 0's property is for root translate
569 auto& property = animationDefinition.GetPropertyAt(0u);
570 auto& keyFrames = property.mKeyFrames;
572 // Let we check that we can change animatable property
573 // TODO : If AnimateBetweenBy feature prepared, we can remove below logic.
576 auto rootNode = model->FindChildByName(property.mNodeName);
579 // Get root node's current position and apply it into property animation.
580 auto rootNodePosition = rootNode.GetProperty<Dali::Vector3>(Dali::Actor::Property::POSITION);
582 auto frameCount = Dali::DevelKeyFrames::GetKeyFrameCount(keyFrames);
583 for(auto i = 0u; i < frameCount; ++i)
585 float keyFrameProgress;
586 Dali::Property::Value keyFrameValue;
587 Dali::Vector3 valuePosition;
589 Dali::DevelKeyFrames::GetKeyFrame(keyFrames, i, keyFrameProgress, keyFrameValue);
590 if(DALI_LIKELY(keyFrameValue.Get(valuePosition)))
592 Dali::DevelKeyFrames::SetKeyFrameValue(keyFrames, i, rootNodePosition + valuePosition);
599 Dali::Scene3D::Loader::AnimatedProperty::GetActor getActor = [&model](const Dali::Scene3D::Loader::AnimatedProperty& property) -> Dali::Actor {
600 return model->FindChildByName(property.mNodeName);
602 result = animationDefinition.ReAnimate(getActor);
604 CALL_CATCH_EXCEPTION(0);
607 return new Dali::Animation((const Dali::Animation&)result);
610 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_LoadBvhAnimation_2(void* csModel, char* csBuffer, int csBufferLength, void* csScale, bool csUseRootNodeTranslate)
612 Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
613 Dali::Animation result;
617 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
622 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string for buffer", 0);
626 Dali::Vector3 scale = Dali::Vector3::ONE;
627 // csScale is option.
628 if(csScale != nullptr)
630 scale = Dali::Vector3(*static_cast<const Dali::Vector3*>(csScale));
633 const uint8_t* rawBuffer = reinterpret_cast<const uint8_t*>(csBuffer);
637 Dali::Scene3D::Loader::AnimationDefinition animationDefinition = Dali::Scene3D::Loader::LoadBvhFromBuffer(rawBuffer, csBufferLength, "LoadedBvhAnimation", scale);
639 if(csUseRootNodeTranslate && animationDefinition.GetPropertyCount() > 0u)
641 // We can assume that 0's property is for root translate
642 auto& property = animationDefinition.GetPropertyAt(0u);
643 auto& keyFrames = property.mKeyFrames;
645 // Let we check that we can change animatable property
646 // TODO : If AnimateBetweenBy feature prepared, we can remove below logic.
649 auto rootNode = model->FindChildByName(property.mNodeName);
652 // Get root node's current position and apply it into property animation.
653 auto rootNodePosition = rootNode.GetProperty<Dali::Vector3>(Dali::Actor::Property::POSITION);
655 auto frameCount = Dali::DevelKeyFrames::GetKeyFrameCount(keyFrames);
656 for(auto i = 0u; i < frameCount; ++i)
658 float keyFrameProgress;
659 Dali::Property::Value keyFrameValue;
660 Dali::Vector3 valuePosition;
661 Dali::DevelKeyFrames::GetKeyFrame(keyFrames, i, keyFrameProgress, keyFrameValue);
662 if(DALI_LIKELY(keyFrameValue.Get(valuePosition)))
664 Dali::DevelKeyFrames::SetKeyFrameValue(keyFrames, i, rootNodePosition + valuePosition);
671 Dali::Scene3D::Loader::AnimatedProperty::GetActor getActor = [&model](const Dali::Scene3D::Loader::AnimatedProperty& property) -> Dali::Actor {
672 return model->FindChildByName(property.mNodeName);
674 result = animationDefinition.ReAnimate(getActor);
676 CALL_CATCH_EXCEPTION(0);
679 return new Dali::Animation((const Dali::Animation&)result);
682 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_LoadFacialAnimation_1(void* csModel, char* csFileName)
684 Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
685 Dali::Animation result;
689 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
694 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string for filename", 0);
698 std::string filename(csFileName);
702 Dali::Scene3D::Loader::AnimationDefinition animationDefinition = Dali::Scene3D::Loader::LoadFacialAnimation(filename);
703 Dali::Scene3D::Loader::AnimatedProperty::GetActor getActor = [&model](const Dali::Scene3D::Loader::AnimatedProperty& property) -> Dali::Actor {
704 return model->FindChildByName(property.mNodeName);
706 result = animationDefinition.ReAnimate(getActor);
708 CALL_CATCH_EXCEPTION(0);
711 return new Dali::Animation((const Dali::Animation&)result);
714 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Model_LoadFacialAnimation_2(void* csModel, char* csBuffer, int csBufferLength)
716 Dali::Scene3D::Model* model = (Dali::Scene3D::Model*)csModel;
717 Dali::Animation result;
721 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::Scene3D::Model", 0);
726 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string for buffer", 0);
730 const uint8_t* rawBuffer = reinterpret_cast<const uint8_t*>(csBuffer);
734 Dali::Scene3D::Loader::AnimationDefinition animationDefinition = Dali::Scene3D::Loader::LoadFacialAnimationFromBuffer(rawBuffer, csBufferLength);
735 Dali::Scene3D::Loader::AnimatedProperty::GetActor getActor = [&model](const Dali::Scene3D::Loader::AnimatedProperty& property) -> Dali::Actor {
736 return model->FindChildByName(property.mNodeName);
738 result = animationDefinition.ReAnimate(getActor);
740 CALL_CATCH_EXCEPTION(0);
743 return new Dali::Animation((const Dali::Animation&)result);
746 GENERATE_SIGNAL(Dali::Scene3D::Model*, bool (*)(Dali::Scene3D::Model, Dali::Scene3D::ModelNode), Dali_Model, MeshHitSignal);