Support model size change 85/292685/3
authorseungho baek <sbsh.baek@samsung.com>
Thu, 11 May 2023 08:36:55 +0000 (17:36 +0900)
committerseungho baek <sbsh.baek@samsung.com>
Fri, 12 May 2023 02:07:24 +0000 (11:07 +0900)
Change-Id: I78a7aa569ae164d07a7809bc7dd7106531face29
Signed-off-by: seungho baek <sbsh.baek@samsung.com>
automated-tests/src/dali-scene3d/utc-Dali-Model.cpp
dali-scene3d/internal/controls/model/model-impl.cpp
dali-scene3d/internal/controls/model/model-impl.h

index e931b3b..c219f93 100644 (file)
@@ -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<Vector3>(Dali::Actor::Property::SCALE);
+
+  model.SetProperty(Dali::Actor::Property::SIZE, Vector3(600, 600, 600));
+  Vector3 scale2 = model.GetChildAt(0u).GetProperty<Vector3>(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<Vector3>(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<Vector3>(Dali::Actor::Property::SCALE);
+  DALI_TEST_NOT_EQUALS(scale, scale2, 0.1f, TEST_LOCATION);
+
+  END_TEST;
+}
index be1b792..b0f8294 100644 (file)
@@ -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<Vector3>(Dali::Actor::Property::SIZE);
+  Vector3 size  = (useCurrentSize) ? Self().GetCurrentProperty<Vector3>(Dali::Actor::Property::SIZE) : Self().GetProperty<Vector3>(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)
index 23aaf61..d7924bf 100644 (file)
@@ -23,6 +23,7 @@
 #include <dali/public-api/actors/camera-actor.h>
 #include <dali/public-api/actors/layer.h>
 #include <dali/public-api/animation/animation.h>
+#include <dali/public-api/object/property-notification.h>
 #include <dali/public-api/object/weak-handle.h>
 #include <dali/public-api/rendering/texture.h>
 
@@ -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<AnimationData>                  mAnimations;
-  std::vector<CameraData>                     mCameraParameters;
-  WeakHandle<Scene3D::SceneView>              mParentSceneView;
+  std::string                    mModelUrl;
+  std::string                    mResourceDirectoryUrl;
+  Scene3D::ModelNode             mModelRoot;
+  std::vector<AnimationData>     mAnimations;
+  std::vector<CameraData>        mCameraParameters;
+  WeakHandle<Scene3D::SceneView> mParentSceneView;
+  Dali::PropertyNotification     mSizeNotification;
 
   // Asynchronous loading variable
   ModelLoadTaskPtr          mModelLoadTask;