From c1236a21a2ddc2da56cb8d54b4ab7e7b1b6c2b50 Mon Sep 17 00:00:00 2001 From: seungho baek Date: Thu, 11 May 2023 17:36:55 +0900 Subject: [PATCH] Support model size change Change-Id: I78a7aa569ae164d07a7809bc7dd7106531face29 Signed-off-by: seungho baek --- .../src/dali-scene3d/utc-Dali-Model.cpp | 65 +++++++++++++++++++++- .../internal/controls/model/model-impl.cpp | 27 +++++++-- dali-scene3d/internal/controls/model/model-impl.h | 26 ++++++--- 3 files changed, 106 insertions(+), 12 deletions(-) diff --git a/automated-tests/src/dali-scene3d/utc-Dali-Model.cpp b/automated-tests/src/dali-scene3d/utc-Dali-Model.cpp index e931b3b..c219f93 100644 --- a/automated-tests/src/dali-scene3d/utc-Dali-Model.cpp +++ b/automated-tests/src/dali-scene3d/utc-Dali-Model.cpp @@ -1424,4 +1424,67 @@ int UtcDaliModelFindChildModelNodeByName(void) DALI_TEST_EQUALS(child2, modelNode2, TEST_LOCATION); END_TEST; -} \ No newline at end of file +} + +int UtcDaliModelSizeChange(void) +{ + tet_infoline(" UtcDaliModelSizeChange."); + + ToolkitTestApplication application; + + Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME); + model.SetProperty(Dali::Actor::Property::SIZE, Vector3(300, 300, 300)); + application.GetScene().Add(model); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(model.GetChildCount(), 1u, TEST_LOCATION); + Vector3 scale = model.GetChildAt(0u).GetProperty(Dali::Actor::Property::SCALE); + + model.SetProperty(Dali::Actor::Property::SIZE, Vector3(600, 600, 600)); + Vector3 scale2 = model.GetChildAt(0u).GetProperty(Dali::Actor::Property::SCALE); + + DALI_TEST_NOT_EQUALS(scale, scale2, 0.1f, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliModelSizeChange2(void) +{ + tet_infoline(" UtcDaliModelSizeChange2."); + + ToolkitTestApplication application; + + Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME); + model.SetProperty(Dali::Actor::Property::SIZE, Vector3(300, 300, 300)); + application.GetScene().Add(model); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(model.GetChildCount(), 1u, TEST_LOCATION); + Vector3 scale = model.GetChildAt(0u).GetProperty(Dali::Actor::Property::SCALE); + + Animation animation = Animation::New(0.5f); + animation.AnimateTo(Dali::Property(model, Dali::Actor::Property::SIZE), Vector3(600, 600, 600)); + animation.Play(); + + application.SendNotification(); + application.Render(250); + + application.SendNotification(); + + Vector3 scale2 = model.GetChildAt(0u).GetProperty(Dali::Actor::Property::SCALE); + DALI_TEST_NOT_EQUALS(scale, scale2, 0.1f, TEST_LOCATION); + + END_TEST; +} diff --git a/dali-scene3d/internal/controls/model/model-impl.cpp b/dali-scene3d/internal/controls/model/model-impl.cpp index be1b792..b0f8294 100644 --- a/dali-scene3d/internal/controls/model/model-impl.cpp +++ b/dali-scene3d/internal/controls/model/model-impl.cpp @@ -66,6 +66,7 @@ DALI_TYPE_REGISTRATION_BEGIN(Scene3D::Model, Toolkit::Control, Create); DALI_TYPE_REGISTRATION_END() static constexpr Vector3 Y_DIRECTION(1.0f, -1.0f, 1.0f); +static constexpr float SIZE_STEP_CONDITION = 0.1f; static constexpr bool DEFAULT_MODEL_CHILDREN_SENSITIVE = false; static constexpr bool DEFAULT_MODEL_CHILDREN_FOCUSABLE = false; @@ -501,6 +502,9 @@ void Model::OnSceneConnection(int depth) } NotifyResourceReady(); + + mSizeNotification = Self().AddPropertyNotification(Actor::Property::SIZE, StepCondition(SIZE_STEP_CONDITION)); + mSizeNotification.NotifySignal().Connect(this, &Model::OnSizeNotification); Control::OnSceneConnection(depth); } @@ -512,9 +516,19 @@ void Model::OnSceneDisconnection() GetImpl(sceneView).UnregisterSceneItem(this); mParentSceneView.Reset(); } + + mSizeNotification.NotifySignal().Disconnect(this, &Model::OnSizeNotification); + Self().RemovePropertyNotification(mSizeNotification); + mSizeNotification.Reset(); + Control::OnSceneDisconnection(); } +void Model::OnSizeSet(const Vector3& size) +{ + ScaleModel(false); +} + Vector3 Model::GetNaturalSize() { if(!mModelRoot) @@ -543,7 +557,7 @@ float Model::GetWidthForHeight(float height) void Model::OnRelayout(const Vector2& size, RelayoutContainer& container) { Control::OnRelayout(size, container); - ScaleModel(); + ScaleModel(false); } bool Model::IsResourceReady() const @@ -562,7 +576,7 @@ void Model::CreateModelRoot() Self().Add(mModelRoot); } -void Model::ScaleModel() +void Model::ScaleModel(bool useCurrentSize) { if(!mModelRoot) { @@ -570,7 +584,7 @@ void Model::ScaleModel() } float scale = 1.0f; - Vector3 size = Self().GetProperty(Dali::Actor::Property::SIZE); + Vector3 size = (useCurrentSize) ? Self().GetCurrentProperty(Dali::Actor::Property::SIZE) : Self().GetProperty(Dali::Actor::Property::SIZE); if(size.x > 0.0f && size.y > 0.0f) { scale = MAXFLOAT; @@ -797,6 +811,11 @@ void Model::OnIblLoadComplete() NotifyResourceReady(); } +void Model::OnSizeNotification(Dali::PropertyNotification& source) +{ + ScaleModel(true); +} + void Model::ResetResourceTasks() { if(!Dali::Adaptor::IsAvailable()) @@ -862,7 +881,7 @@ void Model::CreateModel() Self().SetProperty(Dali::Actor::Property::SIZE, mNaturalSize); } FitModelPosition(); - ScaleModel(); + ScaleModel(false); } void Model::CreateAnimations(Dali::Scene3D::Loader::SceneDefinition& scene) diff --git a/dali-scene3d/internal/controls/model/model-impl.h b/dali-scene3d/internal/controls/model/model-impl.h index 23aaf61..d7924bf 100644 --- a/dali-scene3d/internal/controls/model/model-impl.h +++ b/dali-scene3d/internal/controls/model/model-impl.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -172,6 +173,11 @@ private: void OnSceneDisconnection() override; /** + * @copydoc CustomActorImpl::OnSizeSet( const Vector3& size ) + */ + void OnSizeSet(const Vector3& size) override; + + /** * @copydoc Toolkit::Control::GetNaturalSize */ Vector3 GetNaturalSize() override; @@ -205,7 +211,7 @@ private: /** * @brief Scales the model to fit the control or to return to original size. */ - void ScaleModel(); + void ScaleModel(bool useCurrentSize); /** * @brief Changes model anchor point to set the model at center or returns to the original model pivot. @@ -274,6 +280,11 @@ private: void OnIblLoadComplete(); /** + * @brief Update model root scale when Model size property is updated. + */ + void OnSizeNotification(Dali::PropertyNotification& source); + + /** * @brief Reset Resource loading tasks. */ void ResetResourceTasks(); @@ -304,12 +315,13 @@ private: void ResetCameraParameters(); private: - std::string mModelUrl; - std::string mResourceDirectoryUrl; - Scene3D::ModelNode mModelRoot; - std::vector mAnimations; - std::vector mCameraParameters; - WeakHandle mParentSceneView; + std::string mModelUrl; + std::string mResourceDirectoryUrl; + Scene3D::ModelNode mModelRoot; + std::vector mAnimations; + std::vector mCameraParameters; + WeakHandle mParentSceneView; + Dali::PropertyNotification mSizeNotification; // Asynchronous loading variable ModelLoadTaskPtr mModelLoadTask; -- 2.7.4