From 92a2055c09f94282500ef8f2c58439a9257980ac Mon Sep 17 00:00:00 2001 From: Adam Bialogonski Date: Thu, 30 Nov 2023 10:27:06 +0000 Subject: [PATCH] [Tizen] Fixed ColliderMesh issue for NUI The collider mesh was not registered correctly upon adding the node to the Model. Change-Id: Id9ca71070d892017915f610b79c4ab13447b7d51 Signed-off-by: Adam Bialogonski --- .../src/dali-scene3d/utc-Dali-NavigationMesh.cpp | 40 ++++++++++++++++++++++ .../internal/controls/model/model-impl.cpp | 4 ++- .../internal/model-components/model-node-impl.h | 6 ++-- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/automated-tests/src/dali-scene3d/utc-Dali-NavigationMesh.cpp b/automated-tests/src/dali-scene3d/utc-Dali-NavigationMesh.cpp index 5df30be..b2ccb7f 100644 --- a/automated-tests/src/dali-scene3d/utc-Dali-NavigationMesh.cpp +++ b/automated-tests/src/dali-scene3d/utc-Dali-NavigationMesh.cpp @@ -813,3 +813,43 @@ int UtcDaliColliderMeshModelNodeSetup(void) END_TEST; } + +int UtcDaliColliderMeshModelNodeRemoveModelNode(void) +{ + tet_infoline("UtcDaliColliderMeshModelNodeRemoveModelNode: Test removing model node when there is collider mesh attached"); + + ToolkitTestApplication application; + Dali::Scene3D::ModelNode node = Dali::Scene3D::ModelNode::New(); + Dali::Scene3D::Model model = Dali::Scene3D::Model::New(); + model.AddModelNode(node); + + application.GetWindow().Add(model); + application.SendNotification(); + application.Render(); + + auto colliderMesh = NavigationMeshFactory::CreateFromBuffer(GetTestColliderMesh(0)); + + // Redundant setup test + DALI_TEST_EQUALS(node.HasColliderMesh(), false, TEST_LOCATION); + node.SetColliderMesh(nullptr); + DALI_TEST_EQUALS(node.HasColliderMesh(), false, TEST_LOCATION); + node.SetColliderMesh(std::move(colliderMesh)); + DALI_TEST_EQUALS(node.HasColliderMesh(), true, TEST_LOCATION); + + model.RemoveModelNode(node); + DALI_TEST_EQUALS(node.HasColliderMesh(), true, TEST_LOCATION); + + // Reset collider mesh + node.SetColliderMesh(nullptr); + DALI_TEST_EQUALS(node.HasColliderMesh(), false, TEST_LOCATION); + + auto colliderMesh1 = NavigationMeshFactory::CreateFromBuffer(GetTestColliderMesh(0)); + + node.SetColliderMesh(std::move(colliderMesh1)); + DALI_TEST_EQUALS(node.HasColliderMesh(), true, TEST_LOCATION); + + model.AddModelNode(node); + DALI_TEST_EQUALS(node.HasColliderMesh(), true, TEST_LOCATION); + + END_TEST; +} \ No newline at end of file diff --git a/dali-scene3d/internal/controls/model/model-impl.cpp b/dali-scene3d/internal/controls/model/model-impl.cpp index 0171b1e..d2b1e9f 100644 --- a/dali-scene3d/internal/controls/model/model-impl.cpp +++ b/dali-scene3d/internal/controls/model/model-impl.cpp @@ -313,11 +313,12 @@ void Model::AddModelNode(Scene3D::ModelNode modelNode) UpdateImageBasedLightScaleFactor(); } - GetImplementation(modelNode).SetRootModel(*this); + GetImplementation(modelNode).SetRootModel(this); // If model has a collider mesh set, add it to the container if(modelNode.HasColliderMesh()) { + RegisterColliderMesh(modelNode, modelNode.GetColliderMesh()); Scene3D::ColliderMeshProcessor::Get().ColliderMeshChanged(Scene3D::Model::DownCast(Self())); } @@ -353,6 +354,7 @@ void Model::RemoveModelNode(Scene3D::ModelNode modelNode) if(modelNode.HasColliderMesh()) { RemoveColliderMesh(modelNode); + GetImplementation(modelNode).SetRootModel(nullptr); } if(mModelRoot) diff --git a/dali-scene3d/internal/model-components/model-node-impl.h b/dali-scene3d/internal/model-components/model-node-impl.h index 35f1c12..f36e218 100644 --- a/dali-scene3d/internal/model-components/model-node-impl.h +++ b/dali-scene3d/internal/model-components/model-node-impl.h @@ -306,11 +306,11 @@ public: // Public Method /** * @brief Sets a root model for the ModelNode - * @param[in] model Valid Model to set + * @param[in] model Valid Model or nullptr to disconnect node from tree */ - void SetRootModel(Dali::Scene3D::Internal::Model& model) + void SetRootModel(Dali::Scene3D::Internal::Model* model) { - mParentModel = &model; + mParentModel = model; } private: -- 2.7.4