// EXTERNAL INCLUDES
#include <dali-toolkit/dali-toolkit.h>
-#include <dali-toolkit/devel-api/controls/control-devel.h>
#include <dali-toolkit/internal/controls/control/control-data-impl.h>
#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
#include <dali/integration-api/debug.h>
#include <filesystem>
// INTERNAL INCLUDES
-#include <dali-scene3d/public-api/controls/model-view/model-view.h>
#include <dali-scene3d/internal/controls/scene-view/scene-view-impl.h>
+#include <dali-scene3d/public-api/controls/model-view/model-view.h>
#include <dali-scene3d/public-api/loader/animation-definition.h>
#include <dali-scene3d/public-api/loader/camera-parameters.h>
#include <dali-scene3d/public-api/loader/cube-map-loader.h>
} // anonymous namespace
ModelView::ModelView(const std::string& modelPath, const std::string& resourcePath)
-: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
+: Control(ControlBehaviour(DISABLE_SIZE_NEGOTIATION | DISABLE_STYLE_CHANGE_SIGNALS)),
mModelPath(modelPath),
mResourcePath(resourcePath),
- mModelLayer(),
mModelRoot(),
mNaturalSize(Vector3::ZERO),
mModelPivot(AnchorPoint::CENTER),
mIblScaleFactor(1.0f),
- mFitSize(false),
- mFitCenter(false)
+ mFitSize(true),
+ mFitCenter(true),
+ mModelResourceReady(false),
+ mIBLResourceReady(true)
{
}
void ModelView::SetImageBasedLightSource(const std::string& diffuse, const std::string& specular, float scaleFactor)
{
+ mIBLResourceReady = false;
Texture diffuseTexture = Dali::Scene3D::Loader::LoadCubeMap(diffuse);
Texture specularTexture = Dali::Scene3D::Loader::LoadCubeMap(specular);
SetImageBasedLightTexture(diffuseTexture, specularTexture, scaleFactor);
+ mIBLResourceReady = true;
+
+ // If Model resource is already ready, then set resource ready.
+ // If Model resource is still not ready, wait for model resource ready.
+ if(IsResourceReady())
+ {
+ SetResourceReady(false);
+ }
}
void ModelView::SetImageBasedLightTexture(Dali::Texture diffuse, Dali::Texture specular, float scaleFactor)
Control::OnSceneDisconnection();
}
-void ModelView::OnInitialize()
-{
- Actor self = Self();
- mModelLayer = Layer::New();
- mModelLayer.SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
- mModelLayer.SetProperty(Layer::Property::DEPTH_TEST, true);
- mModelLayer.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
- mModelLayer.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
- mModelLayer.SetResizePolicy(ResizePolicy::FILL_TO_PARENT,
- Dimension::ALL_DIMENSIONS);
-
- // Models in glTF and dli are defined as right hand coordinate system.
- // DALi uses left hand coordinate system. Scaling negative is for change winding order.
- mModelLayer.SetProperty(Dali::Actor::Property::SCALE_Y, -1.0f);
- self.Add(mModelLayer);
-}
-
Vector3 ModelView::GetNaturalSize()
{
if(!mModelRoot)
ScaleModel();
}
+bool ModelView::IsResourceReady() const
+{
+ return mModelResourceReady && mIBLResourceReady;
+}
+
void ModelView::LoadModel()
{
std::filesystem::path modelPath(mModelPath);
mNaturalSize = AABB.CalculateSize();
mModelPivot = AABB.CalculatePivot();
mModelRoot.SetProperty(Dali::Actor::Property::SIZE, mNaturalSize);
+ Vector3 controlSize = Self().GetProperty<Vector3>(Dali::Actor::Property::SIZE);
+ if(controlSize.x == 0.0f || controlSize.y == 0.0f)
+ {
+ Self().SetProperty(Dali::Actor::Property::SIZE, mNaturalSize);
+ }
FitModelPosition();
ScaleModel();
- mModelLayer.Add(mModelRoot);
+ Self().Add(mModelRoot);
+
+ Self().SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+ Self().SetProperty(Dali::Actor::Property::ANCHOR_POINT, Vector3(mModelPivot.x, 1.0f - mModelPivot.y, mModelPivot.z));
+
+ mModelResourceReady = true;
+
+ Control::SetResourceReady(false);
}
void ModelView::ScaleModel()
{
if(mModelRoot)
{
- if(mFitSize)
+ Vector3 size = Self().GetProperty<Vector3>(Dali::Actor::Property::SIZE);
+ if(mFitSize && size.x > 0.0f && size.y > 0.0f)
{
- Vector3 size = Self().GetProperty<Vector3>(Dali::Actor::Property::SIZE);
- if(size.x > 0.0f && size.y > 0.0f)
- {
- float scaleFactor = MAXFLOAT;
- scaleFactor = std::min(size.x / mNaturalSize.x, scaleFactor);
- scaleFactor = std::min(size.y / mNaturalSize.y, scaleFactor);
- mModelRoot.SetProperty(Dali::Actor::Property::SCALE, scaleFactor);
- }
- else
- {
- DALI_LOG_ERROR("ModelView size is wrong.");
- }
+ float scaleFactor = MAXFLOAT;
+ scaleFactor = std::min(size.x / mNaturalSize.x, scaleFactor);
+ scaleFactor = std::min(size.y / mNaturalSize.y, scaleFactor);
+ // Models in glTF and dli are defined as right hand coordinate system.
+ // DALi uses left hand coordinate system. Scaling negative is for change winding order.
+ mModelRoot.SetProperty(Dali::Actor::Property::SCALE, Y_DIRECTION * scaleFactor);
}
else
{
- mModelRoot.SetProperty(Dali::Actor::Property::SCALE, 1.0f);
+ // Models in glTF and dli are defined as right hand coordinate system.
+ // DALi uses left hand coordinate system. Scaling negative is for change winding order.
+ mModelRoot.SetProperty(Dali::Actor::Property::SCALE, Y_DIRECTION);
}
}
}