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/public-api/actors/custom-actor-impl.h>
23 #include <dali/public-api/common/dali-common.h>
24 #include <memory> // for std::unique_ptr
27 #include <dali-scene3d/public-api/loader/mesh-definition.h>
28 #include <dali-scene3d/public-api/model-components/model-node.h>
29 #include <dali-scene3d/public-api/model-components/model-primitive.h>
36 * @addtogroup dali_toolkit_controls_model
43 * @brief This is the internal base class for custom node of model.
47 class DALI_SCENE3D_API ModelNode : public CustomActorImpl
50 // Creation & Destruction
52 * @brief Creates a new ModelNodeImpl instance that does not require touch by default.
54 * If touch is required, then the user can connect to this class' touch signal.
56 * @return A handle to the ModelNode instance
58 static Scene3D::ModelNode New();
62 * @brief Virtual destructor.
67 protected: // From CustomActorImpl
69 * @copydoc CustomActorImpl::OnSceneConnection()
70 * @note If overridden, then an up-call to ModelNode::OnSceneConnection MUST be made at the end.
72 void OnSceneConnection(int depth) override;
75 * @copydoc CustomActorImpl::OnSceneDisconnection()
76 * @note If overridden, then an up-call to ModelNode::OnSceneDisconnection MUST be made at the end.
78 void OnSceneDisconnection() override;
81 * @copydoc CustomActorImpl::OnChildAdd()
82 * @note If overridden, then an up-call to ModelNode::OnChildAdd MUST be made at the end.
84 void OnChildAdd(Actor& child) override;
87 * @copydoc CustomActorImpl::OnChildRemove()
88 * @note If overridden, then an up-call to ModelNode::OnChildRemove MUST be made at the end.
90 void OnChildRemove(Actor& child) override;
93 * @copydoc CustomActorImpl::OnPropertySet()
94 * @note If overridden, then an up-call to ModelNode::OnChildRemove MUST be made at the end.
96 void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
99 * @copydoc CustomActorImpl::OnSizeSet()
100 * @note If overridden, then an up-call to ModelNode::OnSizeSet MUST be made at the end.
102 void OnSizeSet(const Vector3& targetSize) override;
105 * @copydoc CustomActorImpl::OnSizeAnimation()
106 * @note If overridden, then an up-call to ModelNode::OnSizeAnimation MUST be made at the end.
108 void OnSizeAnimation(Animation& animation, const Vector3& targetSize) override;
111 * @copydoc CustomActorImpl::OnRelayout()
113 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
116 * @copydoc CustomActorImpl::OnSetResizePolicy()
118 void OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension) override;
121 * @copydoc CustomActorImpl::GetNaturalSize()
123 Vector3 GetNaturalSize() override;
126 * @copydoc CustomActorImpl::CalculateChildSize()
128 float CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension) override;
131 * @copydoc CustomActorImpl::GetHeightForWidth()
133 float GetHeightForWidth(float width) override;
136 * @copydoc CustomActorImpl::GetWidthForHeight()
138 float GetWidthForHeight(float height) override;
141 * @copydoc CustomActorImpl::RelayoutDependentOnChildren()
143 bool RelayoutDependentOnChildren(Dimension::Type dimension = Dimension::ALL_DIMENSIONS) override;
146 * @copydoc CustomActorImpl::OnCalculateRelayoutSize()
148 void OnCalculateRelayoutSize(Dimension::Type dimension) override;
151 * @copydoc CustomActorImpl::OnLayoutNegotiated()
153 void OnLayoutNegotiated(float size, Dimension::Type dimension) override;
159 * @brief ModelNode constructor.
166 * @brief Second phase initialization.
171 public: // API for derived classes to override
175 * @brief This method is called after the Node has been initialized.
177 * Derived classes should do any second phase initialization by overriding this method.
180 virtual void OnInitialize();
182 public: // Public Method
184 * @copydoc Dali::Scene3D::ModelNode::GetModelPrimitiveCount()
186 uint32_t GetModelPrimitiveCount() const;
189 * @copydoc Dali::Scene3D::ModelNode::AddModelPrimitive()
191 void AddModelPrimitive(Dali::Scene3D::ModelPrimitive modelPrimitive);
194 * @copydoc Dali::Scene3D::ModelNode::RemoveModelPrimitive(Dali::Scene3D::ModelPrimitive modelPrimitive)
196 void RemoveModelPrimitive(Dali::Scene3D::ModelPrimitive modelPrimitive);
199 * @copydoc Dali::Scene3D::ModelNode::RemoveModelPrimitive(uint32_t index)
201 void RemoveModelPrimitive(uint32_t index);
204 * @copydoc Dali::Scene3D::ModelNode::GetModelPrimitive()
206 Dali::Scene3D::ModelPrimitive GetModelPrimitive(uint32_t index) const;
209 * @copydoc Dali::Scene3D::ModelNode::FindChildModelNodeByName()
211 Scene3D::ModelNode FindChildModelNodeByName(std::string_view nodeName);
214 * @brief Sets the diffuse and specular image-based lighting textures for a ModelPrimitive.
216 * @param[in] diffuseTexture The diffuse texture.
217 * @param[in] specularTexture The specular texture.
218 * @param[in] iblScaleFactor The scale factor for the image-based lighting.
219 * @param[in] specularMipmapLevels The number of mipmap levels for the specular texture.
221 void SetImageBasedLightTexture(Dali::Texture diffuseTexture, Dali::Texture specularTexture, float iblScaleFactor, uint32_t specularMipmapLevels);
224 * @brief Sets the scale factor for image-based lighting.
226 * @param[in] iblScaleFactor The scale factor for image-based lighting.
228 void SetImageBasedLightScaleFactor(float iblScaleFactor);
231 * @brief Sets the blend shape data for a ModelPrimitive.
233 * @param[in] data The blend shape data.
234 * @param[in] primitive The ModelPrimitive to set the blend shape data for.
236 void SetBlendShapeData(Scene3D::Loader::BlendShapes::BlendShapeData& data, Scene3D::ModelPrimitive primitive);
239 * @brief Sets the bone matrix for a ModelPrimitive and bone index.
241 * @param[in] inverseMatrix The inverse matrix of the bone.
242 * @param[in] primitive The ModelPrimitive to set the bone matrix for.
243 * @param[in] boneIndex The index of the bone to set the matrix for.
245 void SetBoneMatrix(const Matrix& inverseMatrix, Scene3D::ModelPrimitive primitive, Scene3D::Loader::Index& boneIndex);
250 // Not copyable or movable
251 DALI_INTERNAL ModelNode(const ModelNode&) = delete; ///< Deleted copy constructor.
252 DALI_INTERNAL ModelNode(ModelNode&&) = delete; ///< Deleted move constructor.
253 DALI_INTERNAL ModelNode& operator=(const ModelNode&) = delete; ///< Deleted copy assignment operator.
254 DALI_INTERNAL ModelNode& operator=(ModelNode&&) = delete; ///< Deleted move assignment operator.
257 class DALI_INTERNAL Impl; // Class declaration is public so we can internally add devel API's to the ModelNode's Impl
260 const std::unique_ptr<Impl> mImpl;
265 * @brief Gets implementation from the handle.
269 * @return Implementation
270 * @pre handle is initialized and points to a node
272 DALI_SCENE3D_API Internal::ModelNode& GetImplementation(Dali::Scene3D::ModelNode& handle);
275 * @brief Gets implementation from the handle.
279 * @return Implementation
280 * @pre Handle is initialized and points to a node.
282 DALI_SCENE3D_API const Internal::ModelNode& GetImplementation(const Dali::Scene3D::ModelNode& handle);
284 } // namespace Internal
289 } // namespace Scene3D
293 #endif // DALI_SCENE3D_MODEL_COMPONENTS_MODEL_NODE_IMPL_H