1 #ifndef DALI_SCENE3D_MODEL_COMPONENTS_MODEL_NODE_IMPL_H
2 #define DALI_SCENE3D_MODEL_COMPONENTS_MODEL_NODE_IMPL_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/devel-api/common/map-wrapper.h>
23 #include <dali/public-api/actors/custom-actor-impl.h>
24 #include <dali/public-api/common/dali-common.h>
25 #include <memory> // for std::unique_ptr
29 #include <dali-scene3d/internal/model-components/model-primitive-modify-observer.h>
30 #include <dali-scene3d/public-api/light/light.h>
31 #include <dali-scene3d/public-api/loader/mesh-definition.h>
32 #include <dali-scene3d/public-api/loader/skinning-details.h>
33 #include <dali-scene3d/public-api/model-components/model-node.h>
34 #include <dali-scene3d/public-api/model-components/model-primitive.h>
41 * @addtogroup dali_toolkit_controls_model
48 * @brief This is the internal base class for custom node of model.
52 class DALI_SCENE3D_API ModelNode : public CustomActorImpl, public ModelPrimitiveModifyObserver
55 using ModelPrimitiveContainer = std::vector<Scene3D::ModelPrimitive>;
56 using BoneDataContainer = std::vector<Dali::Scene3D::Loader::Skinning::BoneData>;
57 using BlendShapeIndexMap = std::map<std::string, Loader::BlendShapes::Index>;
59 // Creation & Destruction
61 * @brief Creates a new ModelNodeImpl instance that does not require touch by default.
63 * If touch is required, then the user can connect to this class' touch signal.
65 * @return A handle to the ModelNode instance
67 static Scene3D::ModelNode New();
71 * @brief Virtual destructor.
76 protected: // From CustomActorImpl
78 * @copydoc CustomActorImpl::OnSceneConnection()
79 * @note If overridden, then an up-call to ModelNode::OnSceneConnection MUST be made at the end.
81 void OnSceneConnection(int depth) override;
84 * @copydoc CustomActorImpl::OnSceneDisconnection()
85 * @note If overridden, then an up-call to ModelNode::OnSceneDisconnection MUST be made at the end.
87 void OnSceneDisconnection() override;
90 * @copydoc CustomActorImpl::OnChildAdd()
91 * @note If overridden, then an up-call to ModelNode::OnChildAdd MUST be made at the end.
93 void OnChildAdd(Actor& child) override;
96 * @copydoc CustomActorImpl::OnChildRemove()
97 * @note If overridden, then an up-call to ModelNode::OnChildRemove MUST be made at the end.
99 void OnChildRemove(Actor& child) override;
102 * @copydoc CustomActorImpl::OnPropertySet()
103 * @note If overridden, then an up-call to ModelNode::OnChildRemove MUST be made at the end.
105 void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
108 * @copydoc CustomActorImpl::OnSizeSet()
109 * @note If overridden, then an up-call to ModelNode::OnSizeSet MUST be made at the end.
111 void OnSizeSet(const Vector3& targetSize) override;
114 * @copydoc CustomActorImpl::OnSizeAnimation()
115 * @note If overridden, then an up-call to ModelNode::OnSizeAnimation MUST be made at the end.
117 void OnSizeAnimation(Animation& animation, const Vector3& targetSize) override;
120 * @copydoc CustomActorImpl::OnRelayout()
122 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
125 * @copydoc CustomActorImpl::OnSetResizePolicy()
127 void OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension) override;
130 * @copydoc CustomActorImpl::GetNaturalSize()
132 Vector3 GetNaturalSize() override;
135 * @copydoc CustomActorImpl::CalculateChildSize()
137 float CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension) override;
140 * @copydoc CustomActorImpl::GetHeightForWidth()
142 float GetHeightForWidth(float width) override;
145 * @copydoc CustomActorImpl::GetWidthForHeight()
147 float GetWidthForHeight(float height) override;
150 * @copydoc CustomActorImpl::RelayoutDependentOnChildren()
152 bool RelayoutDependentOnChildren(Dimension::Type dimension = Dimension::ALL_DIMENSIONS) override;
155 * @copydoc CustomActorImpl::OnCalculateRelayoutSize()
157 void OnCalculateRelayoutSize(Dimension::Type dimension) override;
160 * @copydoc CustomActorImpl::OnLayoutNegotiated()
162 void OnLayoutNegotiated(float size, Dimension::Type dimension) override;
168 * @brief ModelNode constructor.
175 * @brief Second phase initialization.
180 public: // API for derived classes to override
184 * @brief This method is called after the Node has been initialized.
186 * Derived classes should do any second phase initialization by overriding this method.
189 virtual void OnInitialize();
191 public: // Public Method
193 * @copydoc Dali::Scene3D::ModelNode::GetModelPrimitiveCount()
195 uint32_t GetModelPrimitiveCount() const;
198 * @copydoc Dali::Scene3D::ModelNode::AddModelPrimitive()
200 void AddModelPrimitive(Dali::Scene3D::ModelPrimitive modelPrimitive);
203 * @copydoc Dali::Scene3D::ModelNode::RemoveModelPrimitive(Dali::Scene3D::ModelPrimitive modelPrimitive)
205 void RemoveModelPrimitive(Dali::Scene3D::ModelPrimitive modelPrimitive);
208 * @copydoc Dali::Scene3D::ModelNode::RemoveModelPrimitive(uint32_t index)
210 void RemoveModelPrimitive(uint32_t index);
213 * @copydoc Dali::Scene3D::ModelNode::GetModelPrimitive()
215 Dali::Scene3D::ModelPrimitive GetModelPrimitive(uint32_t index) const;
218 * @copydoc Dali::Scene3D::ModelNode::FindChildModelNodeByName()
220 Scene3D::ModelNode FindChildModelNodeByName(std::string_view nodeName);
223 * @copydoc Dali::Scene3D::ModelNode::RetrieveBlendShapeNames()
225 void RetrieveBlendShapeNames(std::vector<std::string>& blendShapeNames) const;
228 * @copydoc Dali::Scene3D::ModelNode::GetBlendShapeIndexByName()
230 Loader::BlendShapes::Index GetBlendShapeIndexByName(std::string_view blendShapeName) const;
233 * @brief Sets the diffuse and specular image-based lighting textures for a ModelPrimitive.
235 * @param[in] diffuseTexture The diffuse texture.
236 * @param[in] specularTexture The specular texture.
237 * @param[in] iblScaleFactor The scale factor for the image-based lighting.
238 * @param[in] specularMipmapLevels The number of mipmap levels for the specular texture.
240 void SetImageBasedLightTexture(Dali::Texture diffuseTexture, Dali::Texture specularTexture, float iblScaleFactor, uint32_t specularMipmapLevels);
243 * @brief Sets the scale factor for image-based lighting.
245 * @param[in] iblScaleFactor The scale factor for image-based lighting.
247 void SetImageBasedLightScaleFactor(float iblScaleFactor);
249 void AddLight(Scene3D::Light light, uint32_t lightIndex);
250 void RemoveLight(uint32_t lightIndex);
253 * @brief Sets the blend shape data for a ModelPrimitive.
255 * @param[in] data The blend shape data.
256 * @param[in] primitive The ModelPrimitive to set the blend shape data for.
258 void SetBlendShapeData(Scene3D::Loader::BlendShapes::BlendShapeData& data, Scene3D::ModelPrimitive primitive);
261 * @brief Sets the bone matrix for a ModelPrimitive and bone index.
263 * @param[in] inverseMatrix The inverse matrix of the bone.
264 * @param[in] primitive The ModelPrimitive to set the bone matrix for.
265 * @param[in] boneIndex The index of the bone to set the matrix for.
267 void SetBoneMatrix(const Matrix& inverseMatrix, Scene3D::ModelPrimitive primitive, Scene3D::Loader::Index& boneIndex);
270 * @brief Called when a Renderer of ModelPrimitive is created.
272 * @param[in] renderer The Renderer that is created.
274 void OnRendererCreated(Renderer renderer) override;
278 * @brief Updates the bone matrix for a ModelPrimitive.
280 * @param[in] primitive The ModelPrimitive to set the bone matrix for.
282 void UpdateBoneMatrix(Scene3D::ModelPrimitive primitive);
287 // Not copyable or movable
288 DALI_INTERNAL ModelNode(const ModelNode&) = delete; ///< Deleted copy constructor.
289 DALI_INTERNAL ModelNode(ModelNode&&) = delete; ///< Deleted move constructor.
290 DALI_INTERNAL ModelNode& operator=(const ModelNode&) = delete; ///< Deleted copy assignment operator.
291 DALI_INTERNAL ModelNode& operator=(ModelNode&&) = delete; ///< Deleted move assignment operator.
294 ModelPrimitiveContainer mModelPrimitiveContainer; ///< List of model primitives
295 BoneDataContainer mBoneDataContainer;
296 BlendShapeIndexMap mBlendShapeIndexMap; ///< Index of blend shape by name
297 Dali::Texture mSpecularTexture;
298 Dali::Texture mDiffuseTexture;
299 float mIblScaleFactor{1.0f};
300 uint32_t mSpecularMipmapLevels{1u};
303 std::vector<Scene3D::Light> mLights;
308 * @brief Gets implementation from the handle.
312 * @return Implementation
313 * @pre handle is initialized and points to a node
315 DALI_SCENE3D_API Internal::ModelNode& GetImplementation(Dali::Scene3D::ModelNode& handle);
318 * @brief Gets implementation from the handle.
322 * @return Implementation
323 * @pre Handle is initialized and points to a node.
325 DALI_SCENE3D_API const Internal::ModelNode& GetImplementation(const Dali::Scene3D::ModelNode& handle);
327 } // namespace Internal
332 } // namespace Scene3D
336 #endif // DALI_SCENE3D_MODEL_COMPONENTS_MODEL_NODE_IMPL_H