Deprecate camera plane distance setter + Allow to setup OrthographicSize. 41/283941/5
authorEunki, Hong <eunkiki.hong@samsung.com>
Mon, 7 Nov 2022 11:19:29 +0000 (20:19 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Tue, 15 Nov 2022 07:10:27 +0000 (16:10 +0900)
Set each Left/Right/Top/Bottom plane distance setter is deprecated.
Instead of that API, we make to use OrthographicSize.

Change-Id: I7da73713b112502f08820b78bfdf58cf999462e6
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali-scene3d/utc-Dali-CameraParameters.cpp
dali-scene3d/internal/controls/scene-view/scene-view-impl.cpp
dali-scene3d/public-api/loader/camera-parameters.cpp
dali-scene3d/public-api/loader/camera-parameters.h
dali-scene3d/public-api/loader/dli-loader.cpp
dali-scene3d/public-api/loader/gltf2-loader.cpp
dali-toolkit/internal/controls/scene3d-view/gltf-loader.cpp

index 15e575b..5fec8f2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 // Enable debug log for test coverage
 #define DEBUG_ENABLED 1
 
-#include "dali-scene3d/public-api/loader/camera-parameters.h"
 #include <dali-test-suite-utils.h>
+#include <dali/devel-api/actors/camera-actor-devel.h>
 #include <string_view>
+#include "dali-scene3d/public-api/loader/camera-parameters.h"
 
 using namespace Dali;
 using namespace Dali::Scene3D::Loader;
 
 int UtcDaliCameraParameters(void)
 {
-  Quaternion qView = Quaternion(Radian(Degree(180.f)), Vector3::YAXIS);
+  Quaternion       qView = Quaternion(Radian(Degree(180.f)), Vector3::YAXIS);
   CameraParameters camParams;
   camParams.matrix.SetTransformComponents(Vector3::ONE * 2.f,
-    qView,
-    Vector3::ZAXIS * -100.f);
-  camParams.orthographicSize = Vector4{ -1.f, 1.f, -1.f, 1.f };
-  camParams.yFov = Radian(M_PI * .5).radian;
-  camParams.zNear = 1.f;
-  camParams.zFar = 1000.f;
+                                          qView,
+                                          Vector3::ZAXIS * -100.f);
+  camParams.orthographicSize = 3.0f;
+  camParams.aspectRatio      = 1.0f;
+  camParams.yFov             = Degree(Radian(M_PI * .5)).degree;
+  camParams.zNear            = 1.f;
+  camParams.zFar             = 1000.f;
 
-  Vector3 scale;
+  Vector3    scale;
   Quaternion orientation;
-  Vector3 position;
+  Vector3    position;
   camParams.CalculateTransformComponents(position, orientation, scale);
   DALI_TEST_EQUAL(scale, Vector3::ONE * 2.f);
   DALI_TEST_EQUAL(orientation, Quaternion::IDENTITY); // 2 180 degrees rotations along y
   DALI_TEST_EQUAL(position, Vector3::ZAXIS * -100.f);
 
   TestApplication app;
-  CameraActor camera = CameraActor::New();
-  for (auto i : { false, true })
+  CameraActor     camera = CameraActor::New();
+  for(auto i : {false, true})
   {
     camParams.isPerspective = i;
 
-    auto viewProjection = camParams.GetViewProjection();
-    Matrix view{ false };
+    auto   viewProjection = camParams.GetViewProjection();
+    Matrix view{false};
     Matrix::Multiply(view, Matrix(qView), camParams.matrix);
     view.Invert();
     DALI_TEST_EQUAL(viewProjection.GetView(), view);
@@ -65,6 +67,15 @@ int UtcDaliCameraParameters(void)
     DALI_TEST_EQUAL(camera.GetProperty(Actor::Property::POSITION).Get<Vector3>(), position);
     DALI_TEST_EQUAL(camera.GetProperty(Actor::Property::ORIENTATION).Get<Quaternion>(), orientation);
     DALI_TEST_EQUAL(camera.GetProperty(Actor::Property::SCALE).Get<Vector3>(), scale);
+
+    if(camParams.isPerspective)
+    {
+      DALI_TEST_EQUAL(camera.GetProperty(Dali::CameraActor::Property::FIELD_OF_VIEW).Get<float>(), Radian(Degree(camParams.yFov)).radian);
+    }
+    else
+    {
+      DALI_TEST_EQUAL(camera.GetProperty(Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE).Get<float>(), camParams.orthographicSize);
+    }
   }
 
   END_TEST;
index 917842d..9cc2759 100644 (file)
@@ -118,15 +118,15 @@ Dali::Actor CreateSkybox(const std::string& skyboxUrl)
     {Vector3(-1.0f, -1.0f, 1.0f)},
     {Vector3(1.0f, -1.0f, 1.0f)}};
 
-  Dali::Shader       shaderSkybox  = Shader::New(SHADER_SKYBOX_SHADER_VERT.data(), SHADER_SKYBOX_SHADER_FRAG.data());
-  Dali::VertexBuffer vertexBuffer  = Dali::VertexBuffer::New(Property::Map().Add("aPosition", Property::VECTOR3));
+  Dali::Shader       shaderSkybox = Shader::New(SHADER_SKYBOX_SHADER_VERT.data(), SHADER_SKYBOX_SHADER_FRAG.data());
+  Dali::VertexBuffer vertexBuffer = Dali::VertexBuffer::New(Property::Map().Add("aPosition", Property::VECTOR3));
   vertexBuffer.SetData(skyboxVertices, sizeof(skyboxVertices) / sizeof(Vertex));
 
   Dali::Geometry skyboxGeometry = Geometry::New();
   skyboxGeometry.AddVertexBuffer(vertexBuffer);
   skyboxGeometry.SetType(Geometry::TRIANGLES);
 
-  Dali::Texture    skyboxTexture   = Dali::Scene3D::Loader::LoadCubeMap(skyboxUrl);
+  Dali::Texture    skyboxTexture  = Dali::Scene3D::Loader::LoadCubeMap(skyboxUrl);
   Dali::TextureSet skyboxTextures = TextureSet::New();
   skyboxTextures.SetTexture(0, skyboxTexture);
 
@@ -519,18 +519,6 @@ void SceneView::UpdateRenderTask()
     Vector3     size        = Self().GetProperty<Vector3>(Dali::Actor::Property::SIZE);
     const float aspectRatio = size.width / size.height;
     mSelectedCamera.SetAspectRatio(aspectRatio);
-    const bool projectionVertical = mSelectedCamera.GetProperty<int>(Dali::DevelCameraActor::Property::PROJECTION_DIRECTION) == Dali::DevelCameraActor::VERTICAL;
-
-    // if projectionVertical, Top / Bottom is +-ve to keep consistency with orthographic values
-    // else, Left / Right is +-ve to keep consistency with orthographic values
-    const float orthographicSize = DALI_LIKELY(projectionVertical) ? mSelectedCamera[Dali::CameraActor::Property::TOP_PLANE_DISTANCE] : mSelectedCamera[Dali::CameraActor::Property::RIGHT_PLANE_DISTANCE];
-    const float halfHeight       = DALI_LIKELY(projectionVertical) ? orthographicSize : orthographicSize / aspectRatio;
-    const float halfWidth        = DALI_LIKELY(projectionVertical) ? orthographicSize * aspectRatio : orthographicSize;
-
-    mSelectedCamera[Dali::CameraActor::Property::LEFT_PLANE_DISTANCE]   = -halfWidth;
-    mSelectedCamera[Dali::CameraActor::Property::RIGHT_PLANE_DISTANCE]  = halfWidth;
-    mSelectedCamera[Dali::CameraActor::Property::TOP_PLANE_DISTANCE]    = halfHeight;
-    mSelectedCamera[Dali::CameraActor::Property::BOTTOM_PLANE_DISTANCE] = -halfHeight;
 
     if(mUseFrameBuffer)
     {
index 5207a27..270f84b 100644 (file)
@@ -16,6 +16,7 @@
  */
 #include "dali-scene3d/public-api/loader/camera-parameters.h"
 #include "dali-scene3d/public-api/loader/utils.h"
+#include "dali/devel-api/actors/camera-actor-devel.h"
 #include "dali/integration-api/debug.h"
 #include "dali/public-api/actors/camera-actor.h"
 #include "dali/public-api/math/quaternion.h"
@@ -155,10 +156,10 @@ ViewProjection CameraParameters::GetViewProjection() const
   else
   {
     Orthographic(viewProjection.GetProjection(),
-                 orthographicSize.x,
-                 orthographicSize.y,
-                 orthographicSize.z,
-                 orthographicSize.w,
+                 -orthographicSize * aspectRatio,
+                 orthographicSize * aspectRatio,
+                 orthographicSize,
+                 -orthographicSize,
                  zNear,
                  zFar,
                  true);
@@ -204,12 +205,10 @@ void CameraParameters::ConfigureCamera(CameraActor& camera) const
   else
   {
     camera.SetProjectionMode(Camera::ORTHOGRAPHIC_PROJECTION);
-    camera.SetOrthographicProjection(orthographicSize.x,
-                                     orthographicSize.y,
-                                     orthographicSize.z,
-                                     orthographicSize.w,
-                                     zNear,
-                                     zFar);
+    camera.SetNearClippingPlane(zNear);
+    camera.SetFarClippingPlane(zFar);
+    camera.SetAspectRatio(aspectRatio);
+    camera.SetProperty(Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE, orthographicSize);
   }
 
   // model
index 74d6eec..70060e5 100644 (file)
@@ -35,12 +35,13 @@ namespace Loader
 {
 struct DALI_SCENE3D_API CameraParameters
 {
-  Matrix  matrix           = Matrix::IDENTITY;
-  Vector4 orthographicSize = Vector4{-1.f, 1.f, 1.f, -1.f};
-  float   yFov             = 60.f;
-  float   zNear            = 0.1f;
-  float   zFar             = 1000.f;
-  bool    isPerspective    = true;
+  Matrix matrix           = Matrix::IDENTITY;
+  float  orthographicSize = 1.f;
+  float  aspectRatio      = 1.f;
+  float  yFov             = 60.f;
+  float  zNear            = 0.1f;
+  float  zFar             = 1000.f;
+  bool   isPerspective    = true;
 
   /**
    * @return The view-projection matrix of the camera.
index 8eb596d..133e62c 100644 (file)
@@ -485,8 +485,7 @@ void DliLoader::Impl::ParseScene(LoadParams& params)
 
 void DliLoader::Impl::ParseSceneInternal(Index iScene, const Toolkit::TreeNode* tnScenes, const Toolkit::TreeNode* tnNodes, LoadParams& params)
 {
-  auto getSceneRootIdx = [tnScenes, tnNodes](Index iScene)
-  {
+  auto getSceneRootIdx = [tnScenes, tnNodes](Index iScene) {
     auto tn = GetNthChild(tnScenes, iScene); // now a "scene" object
     if(!tn)
     {
@@ -1728,6 +1727,8 @@ void DliLoader::Impl::GetCameraParameters(std::vector<CameraParameters>& cameras
   {
     if(const TreeNode* jsonCameras = mParser.GetRoot()->GetChild("cameras"))
     {
+      float dummyFloatArray[4];
+
       cameras.resize(jsonCameras->Size());
       auto iCamera = cameras.begin();
       for(auto i0 = jsonCameras->CBegin(), i1 = jsonCameras->CEnd(); i0 != i1; ++i0)
@@ -1737,9 +1738,12 @@ void DliLoader::Impl::GetCameraParameters(std::vector<CameraParameters>& cameras
         ReadFloat(jsonCamera.GetChild("fov"), iCamera->yFov);
         ReadFloat(jsonCamera.GetChild("near"), iCamera->zNear);
         ReadFloat(jsonCamera.GetChild("far"), iCamera->zFar);
-        if(ReadVector(jsonCamera.GetChild("orthographic"), iCamera->orthographicSize.AsFloat(), 4u))
+        if(ReadVector(jsonCamera.GetChild("orthographic"), dummyFloatArray, 4u))
         {
           iCamera->isPerspective = false;
+
+          iCamera->orthographicSize = dummyFloatArray[2] * 0.5f;
+          iCamera->aspectRatio      = dummyFloatArray[1] / dummyFloatArray[2];
         }
 
         if(auto jsonMatrix = jsonCamera.GetChild("matrix"))
index 316803d..60f6970 100644 (file)
@@ -718,7 +718,8 @@ void ConvertCamera(const gt::Camera& camera, CameraParameters& camParams)
   else
   {
     auto& ortho                = camera.mOrthographic;
-    camParams.orthographicSize = Vector4(-ortho.mXMag, ortho.mXMag, ortho.mYMag, -ortho.mYMag) * .5f;
+    camParams.orthographicSize = ortho.mYMag * .5f;
+    camParams.aspectRatio      = ortho.mXMag / ortho.mYMag;
     camParams.zNear            = ortho.mZNear;
     camParams.zFar             = ortho.mZFar;
   }
index 55dfd8d..0f5f792 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
 
 // EXTERNAL INCLUDES
 #include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
+#include <dali/devel-api/actors/camera-actor-devel.h>
 #include <dali/devel-api/adaptor-framework/file-stream.h>
 #include <dali/devel-api/adaptor-framework/image-loading.h>
 #include <dali/integration-api/debug.h>
@@ -231,7 +232,7 @@ void FitBuffer(Dali::Vector<Vector4>& bufferDestination, Dali::Vector<T>& buffer
 template<typename T>
 bool ReadBinFile(Vector<T>& dataBuffer, std::string url, int32_t offset, int32_t count)
 {
-  size_t readCount = 0;
+  size_t           readCount = 0;
   Dali::FileStream fileStream(url, FileStream::READ | FileStream::BINARY);
   FILE*            fp = fileStream.GetFile();
   if(fp)
@@ -1300,9 +1301,22 @@ void Loader::LoadCamera(Scene3dView& scene3dView)
     if(cameraInfo.type == "orthographic")
     {
       LoadOrthoGraphic((*cameraIter).second, cameraInfo);
-      float xMag_2 = cameraInfo.orthographic.xmag / 2.0;
-      float yMag_2 = cameraInfo.orthographic.ymag / 2.0;
-      cameraActor.SetOrthographicProjection(-xMag_2, xMag_2, yMag_2, -yMag_2, cameraInfo.orthographic.znear, cameraInfo.orthographic.zfar);
+      float       xMag_2 = cameraInfo.orthographic.xmag / 2.0;
+      float       yMag_2 = cameraInfo.orthographic.ymag / 2.0;
+      const float aspect = xMag_2 / yMag_2;
+
+      cameraActor.SetProjectionMode(Dali::Camera::ORTHOGRAPHIC_PROJECTION);
+      cameraActor.SetProperty(Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE, yMag_2);
+
+      cameraActor.SetNearClippingPlane(cameraInfo.orthographic.znear);
+      if(cameraInfo.orthographic.zfar > 0.0)
+      {
+        cameraActor.SetFarClippingPlane(cameraInfo.orthographic.zfar);
+      }
+      if(aspect > 0.0f) // Avoid divide-by-zero logic
+      {
+        cameraActor.SetAspectRatio(aspect);
+      }
     }
     else if(cameraInfo.type == "perspective")
     {
@@ -1593,7 +1607,7 @@ Actor Loader::AddNode(Scene3dView& scene3dView, uint32_t index)
     actor.SetProperty(Actor::Property::POSITION, translation);
 
     float hasLightSource = static_cast<float>(!!(scene3dView.GetLightType() & (Toolkit::Scene3dView::LightType::POINT_LIGHT | Toolkit::Scene3dView::LightType::DIRECTIONAL_LIGHT)));
-    float isPointLight = static_cast<float>(!!(scene3dView.GetLightType() & Toolkit::Scene3dView::LightType::POINT_LIGHT));
+    float isPointLight   = static_cast<float>(!!(scene3dView.GetLightType() & Toolkit::Scene3dView::LightType::POINT_LIGHT));
     shader.RegisterProperty("uHasLightSource", hasLightSource);
     shader.RegisterProperty("uIsPointLight", isPointLight);
     shader.RegisterProperty("uLightVector", scene3dView.GetLightVector());