[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / model-components / model-node.cpp
1 /*
2  * Copyright (c) 2024 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 // CLASS HEADER
19 #include <dali-scene3d/public-api/model-components/model-node.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23 #include <dali/public-api/actors/custom-actor.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-scene3d/internal/model-components/model-node-impl.h>
27
28 namespace Dali
29 {
30 namespace Scene3D
31 {
32 ModelNode ModelNode::New()
33 {
34   return Scene3D::Internal::ModelNode::New();
35 }
36
37 ModelNode::ModelNode()
38 {
39 }
40
41 ModelNode::ModelNode(const ModelNode& modelNode) = default;
42
43 ModelNode::ModelNode(ModelNode&& rhs) noexcept = default;
44
45 ModelNode::~ModelNode()
46 {
47 }
48
49 ModelNode& ModelNode::operator=(const ModelNode& handle) = default;
50
51 ModelNode& ModelNode::operator=(ModelNode&& rhs) noexcept = default;
52
53 ModelNode ModelNode::DownCast(BaseHandle handle)
54 {
55   ModelNode result;
56
57   CustomActor custom = Dali::CustomActor::DownCast(handle);
58   if(custom)
59   {
60     CustomActorImpl& customImpl = custom.GetImplementation();
61
62     Internal::ModelNode* impl = dynamic_cast<Internal::ModelNode*>(&customImpl);
63
64     if(impl)
65     {
66       result = ModelNode(customImpl.GetOwner());
67     }
68   }
69
70   return result;
71 }
72
73 ModelNode::ModelNode(Internal::ModelNode& implementation)
74 : Control(implementation)
75 {
76 }
77
78 ModelNode::ModelNode(Dali::Internal::CustomActor* internal)
79 : Control(internal)
80 {
81   // Can have a NULL pointer so we only need to check if the internal implementation is our class
82   // when there is a value.
83   if(internal)
84   {
85     DALI_ASSERT_DEBUG(dynamic_cast<Internal::ModelNode*>(&CustomActor(internal).GetImplementation()));
86   }
87 }
88
89 // Public Method
90
91 uint32_t ModelNode::GetModelPrimitiveCount() const
92 {
93   return Internal::GetImplementation(*this).GetModelPrimitiveCount();
94 }
95
96 void ModelNode::AddModelPrimitive(ModelPrimitive modelPrimitive)
97 {
98   Internal::GetImplementation(*this).AddModelPrimitive(modelPrimitive, 0u);
99 }
100
101 void ModelNode::RemoveModelPrimitive(Dali::Scene3D::ModelPrimitive modelPrimitive)
102 {
103   Internal::GetImplementation(*this).RemoveModelPrimitive(modelPrimitive);
104 }
105
106 void ModelNode::RemoveModelPrimitive(uint32_t index)
107 {
108   Internal::GetImplementation(*this).RemoveModelPrimitive(index);
109 }
110
111 ModelPrimitive ModelNode::GetModelPrimitive(uint32_t index) const
112 {
113   return Internal::GetImplementation(*this).GetModelPrimitive(index);
114 }
115
116 ModelNode ModelNode::FindChildModelNodeByName(std::string_view nodeName)
117 {
118   return Internal::GetImplementation(*this).FindChildModelNodeByName(nodeName);
119 }
120
121 void ModelNode::RetrieveBlendShapeNames(std::vector<std::string>& blendShapeNames) const
122 {
123   return Internal::GetImplementation(*this).RetrieveBlendShapeNames(blendShapeNames);
124 }
125
126 Loader::BlendShapes::Index ModelNode::GetBlendShapeIndexByName(std::string_view blendShapeName) const
127 {
128   return Internal::GetImplementation(*this).GetBlendShapeIndexByName(blendShapeName);
129 }
130
131 void ModelNode::SetColliderMesh(std::unique_ptr<Algorithm::ColliderMesh>&& colliderMesh)
132 {
133   Internal::GetImplementation(*this).SetColliderMesh(std::move(colliderMesh));
134 }
135
136 const Algorithm::ColliderMesh& ModelNode::GetColliderMesh()
137 {
138   return Internal::GetImplementation(*this).GetColliderMesh();
139 }
140
141 bool ModelNode::HasColliderMesh() const
142 {
143   return Internal::GetImplementation(*this).HasColliderMesh();
144 }
145
146 void ModelNode::CastShadow(bool castShadow)
147 {
148   Internal::GetImplementation(*this).CastShadow(castShadow);
149 }
150
151 bool ModelNode::IsShadowCasting() const
152 {
153   return Internal::GetImplementation(*this).IsShadowCasting();
154 }
155
156 void ModelNode::ReceiveShadow(bool receiveShadow)
157 {
158   Internal::GetImplementation(*this).ReceiveShadow(receiveShadow);
159 }
160
161 bool ModelNode::IsShadowReceiving() const
162 {
163   return Internal::GetImplementation(*this).IsShadowReceiving();
164 }
165
166 } // namespace Scene3D
167
168 } // namespace Dali