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;
+}
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;
}
NotifyResourceReady();
+
+ mSizeNotification = Self().AddPropertyNotification(Actor::Property::SIZE, StepCondition(SIZE_STEP_CONDITION));
+ mSizeNotification.NotifySignal().Connect(this, &Model::OnSizeNotification);
Control::OnSceneConnection(depth);
}
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)
void Model::OnRelayout(const Vector2& size, RelayoutContainer& container)
{
Control::OnRelayout(size, container);
- ScaleModel();
+ ScaleModel(false);
}
bool Model::IsResourceReady() const
Self().Add(mModelRoot);
}
-void Model::ScaleModel()
+void Model::ScaleModel(bool useCurrentSize)
{
if(!mModelRoot)
{
}
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;
NotifyResourceReady();
}
+void Model::OnSizeNotification(Dali::PropertyNotification& source)
+{
+ ScaleModel(true);
+}
+
void Model::ResetResourceTasks()
{
if(!Dali::Adaptor::IsAvailable())
Self().SetProperty(Dali::Actor::Property::SIZE, mNaturalSize);
}
FitModelPosition();
- ScaleModel();
+ ScaleModel(false);
}
void Model::CreateAnimations(Dali::Scene3D::Loader::SceneDefinition& scene)
#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>
void OnSceneDisconnection() override;
/**
+ * @copydoc CustomActorImpl::OnSizeSet( const Vector3& size )
+ */
+ void OnSizeSet(const Vector3& size) override;
+
+ /**
* @copydoc Toolkit::Control::GetNaturalSize
*/
Vector3 GetNaturalSize() override;
/**
* @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.
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();
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;