Merge "Use ModelNode / ModelPrimitive / Material instead of Actor / Renderer" into...
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / internal / model-components / model-node-impl.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 // CLASS HEADER
19 #include <dali-scene3d/internal/model-components/model-node-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-scene3d/internal/model-components/model-node-data-impl.h>
26
27 namespace Dali
28 {
29 namespace Scene3D
30 {
31 namespace Internal
32 {
33 Dali::Scene3D::ModelNode ModelNode::New()
34 {
35   // Create the implementation, temporarily owned on stack
36   IntrusivePtr<ModelNode> nodeImpl = new ModelNode();
37
38   // Pass ownership to handle
39   Scene3D::ModelNode handle(*nodeImpl);
40
41   // Second-phase init of the implementation
42   // This can only be done after the CustomActor connection has been made...
43   nodeImpl->Initialize();
44
45   return handle;
46 }
47
48 ModelNode::ModelNode()
49 : CustomActorImpl(ActorFlags::DISABLE_SIZE_NEGOTIATION),
50   mImpl(new Impl(*this))
51 {
52 }
53
54 ModelNode::~ModelNode()
55 {
56 }
57
58 void ModelNode::Initialize()
59 {
60   OnInitialize();
61 }
62
63 void ModelNode::OnInitialize()
64 {
65 }
66
67 void ModelNode::OnSceneConnection(int depth)
68 {
69   mImpl->OnSceneConnection(depth);
70 }
71
72 void ModelNode::OnSceneDisconnection()
73 {
74   mImpl->OnSceneDisconnection();
75 }
76
77 void ModelNode::OnChildAdd(Actor& child)
78 {
79 }
80
81 void ModelNode::OnChildRemove(Actor& child)
82 {
83 }
84
85 void ModelNode::OnPropertySet(Property::Index index, const Property::Value& propertyValue)
86 {
87 }
88
89 void ModelNode::OnSizeSet(const Vector3& targetSize)
90 {
91 }
92
93 void ModelNode::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
94 {
95   // @todo size negotiate background to new size, animate as well?
96 }
97
98 void ModelNode::OnRelayout(const Vector2& size, RelayoutContainer& container)
99 {
100 }
101
102 void ModelNode::OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension)
103 {
104 }
105
106 Vector3 ModelNode::GetNaturalSize()
107 {
108   return Vector3::ZERO;
109 }
110
111 float ModelNode::CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension)
112 {
113   return 0.0f;
114 }
115
116 float ModelNode::GetHeightForWidth(float width)
117 {
118   return 0.0f;
119 }
120
121 float ModelNode::GetWidthForHeight(float height)
122 {
123   return 0.0f;
124 }
125
126 bool ModelNode::RelayoutDependentOnChildren(Dimension::Type dimension)
127 {
128   return false;
129 }
130
131 void ModelNode::OnCalculateRelayoutSize(Dimension::Type dimension)
132 {
133 }
134
135 void ModelNode::OnLayoutNegotiated(float size, Dimension::Type dimension)
136 {
137 }
138
139 ModelNode& GetImplementation(Dali::Scene3D::ModelNode& handle)
140 {
141   CustomActorImpl& customInterface = handle.GetImplementation();
142   ModelNode& impl = dynamic_cast<Internal::ModelNode&>(customInterface);
143   return impl;
144 }
145
146 const ModelNode& GetImplementation(const Dali::Scene3D::ModelNode& handle)
147 {
148   const CustomActorImpl& customInterface = handle.GetImplementation();
149   // downcast to control
150   const ModelNode& impl = dynamic_cast<const Internal::ModelNode&>(customInterface);
151   return impl;
152 }
153
154 // Public Method
155
156 uint32_t ModelNode::GetModelPrimitiveCount() const
157 {
158   return mImpl->GetModelPrimitiveCount();
159 }
160
161 void ModelNode::AddModelPrimitive(Dali::Scene3D::ModelPrimitive modelPrimitive)
162 {
163   mImpl->AddModelPrimitive(modelPrimitive);
164 }
165
166 void ModelNode::RemoveModelPrimitive(Dali::Scene3D::ModelPrimitive modelPrimitive)
167 {
168   mImpl->RemoveModelPrimitive(modelPrimitive);
169 }
170
171 void ModelNode::RemoveModelPrimitive(uint32_t index)
172 {
173   mImpl->RemoveModelPrimitive(index);
174 }
175
176 Dali::Scene3D::ModelPrimitive ModelNode::GetModelPrimitive(uint32_t index) const
177 {
178   return mImpl->GetModelPrimitive(index);
179 }
180
181 Scene3D::ModelNode ModelNode::FindChildModelNodeByName(std::string_view nodeName)
182 {
183   Actor childActor = Self().FindChildByName(nodeName);
184   return Scene3D::ModelNode::DownCast(childActor);
185 }
186
187 void ModelNode::SetImageBasedLightTexture(Dali::Texture diffuseTexture, Dali::Texture specularTexture, float iblScaleFactor, uint32_t specularMipmapLevels)
188 {
189   mImpl->SetImageBasedLightTexture(diffuseTexture, specularTexture, iblScaleFactor, specularMipmapLevels);
190 }
191
192 void ModelNode::SetImageBasedLightScaleFactor(float iblScaleFactor)
193 {
194   mImpl->SetImageBasedLightScaleFactor(iblScaleFactor);
195 }
196
197 void ModelNode::SetBlendShapeData(Scene3D::Loader::BlendShapes::BlendShapeData& data, Scene3D::ModelPrimitive primitive)
198 {
199   mImpl->SetBlendShapeData(data, primitive);
200 }
201
202 void ModelNode::SetBoneMatrix(const Matrix& inverseMatrix, Scene3D::ModelPrimitive primitive, Scene3D::Loader::Index& boneIndex)
203 {
204   mImpl->SetBoneMatrix(inverseMatrix, primitive, boneIndex);
205 }
206
207 } // namespace Internal
208
209 } // namespace Scene3D
210
211 } // namespace Dali