[Tizen] Backport tizen_7.5 for Scene3D 76/287976/2 accepted/tizen/7.0/unified/20230223.015621
authorEunki, Hong <eunkiki.hong@samsung.com>
Mon, 7 Nov 2022 11:39:44 +0000 (20:39 +0900)
committerEunki Hong <eunkiki.hong@samsung.com>
Mon, 13 Feb 2023 04:44:00 +0000 (13:44 +0900)
This is a combination of 5 commits.

Configure cameraParam by API

Let scene3d example camera configure cameraActor by API,
not the sample's own logic.

Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
Modify to use LoadEnvironmentMap to load skybox env map

Signed-off-by: seungho baek <sbsh.baek@samsung.com>
Fix to use async resource load in scene3d-model example

Signed-off-by: seungho baek <sbsh.baek@samsung.com>
Use Layer_3D in scene3d-model example

Signed-off-by: seungho baek <sbsh.baek@samsung.com>
Fix scene3d examples

Signed-off-by: seungho baek <sbsh.baek@samsung.com>
Change-Id: I818a05f443f62249bde40bcc3107e7969952d3bf
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
examples/scene3d-model/scene3d-model-example.cpp
examples/scene3d/scene3d-example.cpp
resources/models/exercise_model.dli

index e0535a6..1a08850 100644 (file)
@@ -25,6 +25,7 @@
 #include <cstring>
 
 #include <dali-scene3d/public-api/controls/model/model.h>
+#include <dali-scene3d/public-api/loader/environment-map-loader.h>
 
 using namespace Dali;
 using namespace Dali::Toolkit;
@@ -217,8 +218,6 @@ public:
     mWindow = application.GetWindow();
     mWindow.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
 
-    mWindow.GetRootLayer().SetProperty(Dali::Layer::Property::BEHAVIOR, Dali::Layer::Behavior::LAYER_3D);
-
     // Get a handle to the mWindow
     mWindow.SetBackgroundColor(Color::WHITE);
 
@@ -263,6 +262,7 @@ public:
 
   void CreateSceneFromGLTF(uint32_t index)
   {
+    mReadyToLoad = false;
     if(mModel)
     {
       mWindow.GetRootLayer().Remove(mModel);
@@ -285,17 +285,19 @@ public:
     mModel.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
     mModel.SetImageBasedLightSource(uri_diffuse_texture, uri_specular_texture, 0.6f);
 
-    mWindow.Add(mModel);
+    mModel.ResourceReadySignal().Connect(this, &Scene3DModelExample::ResourceReady);
 
-    mModel.ResourceReadySignal().Connect(this, &Scene3DModelExample::ResourceReadySignal);
+    mWindow.Add(mModel);
   }
 
-  void ResourceReadySignal(Control control)
+  void ResourceReady(Control control)
   {
+    mReadyToLoad = true;
     if(mModel.GetAnimationCount() > 0)
     {
-      mModel.GetAnimation(0u).Play();
-      mModel.GetAnimation(0u).SetLoopCount(0);
+      Animation animation = (mCurrentGlTF == 0u) ? mModel.GetAnimation(0u) : mModel.GetAnimation("idleToSquatClip_0");
+      animation.Play();
+      animation.SetLoopCount(0);
     }
   }
 
@@ -375,15 +377,9 @@ public:
     mSkyboxGeometry.AddVertexBuffer(vertexBuffer);
     mSkyboxGeometry.SetType(Geometry::TRIANGLES);
 
-    // Diffuse Cube Map
-    Devel::PixelBuffer diffusePixelBuffer = LoadImageFromFile(uri_cube_diffuse_texture);
-    int32_t            diffuseFaceSize    = diffusePixelBuffer.GetWidth() / 4;
-    Texture            texture            = Texture::New(TextureType::TEXTURE_CUBE, diffusePixelBuffer.GetPixelFormat(), diffuseFaceSize, diffuseFaceSize);
-    for(int32_t i = 0; i < 6; ++i)
-    {
-      UploadTextureFace(texture, diffusePixelBuffer, i);
-    }
-    texture.GenerateMipmaps();
+    Dali::Scene3D::Loader::EnvironmentMapData environmentMapData;
+    Dali::Scene3D::Loader::LoadEnvironmentMap(uri_cube_diffuse_texture, environmentMapData);
+    Texture texture = environmentMapData.GetTexture();
 
     mSkyboxTextures = TextureSet::New();
     mSkyboxTextures.SetTexture(0, texture);
@@ -473,6 +469,11 @@ public:
 
   void ChangeModel(int32_t direction)
   {
+    if(!mReadyToLoad)
+    {
+      return;
+    }
+
     mCurrentGlTF += direction;
     if(mCurrentGlTF >= NUM_OF_GLTF_MODELS)
     {
@@ -632,6 +633,8 @@ private:
   float mWheelDelta{1.0f};
 
   int32_t mCurrentGlTF{0};
+
+  bool mReadyToLoad{true};
 };
 
 int32_t DALI_EXPORT_API main(int32_t argc, char** argv)
index 555143c..da9ea20 100644 (file)
@@ -125,41 +125,6 @@ Actor CreateErrorMessage(std::string msg)
   return label;\r
 }\r
 \r
-void ConfigureCamera(const CameraParameters& params, CameraActor camera)\r
-{\r
-  if(params.isPerspective)\r
-  {\r
-    camera.SetProjectionMode(Camera::PERSPECTIVE_PROJECTION);\r
-    camera.SetNearClippingPlane(params.zNear);\r
-    camera.SetFarClippingPlane(params.zFar);\r
-    camera.SetFieldOfView(Radian(Degree(params.yFov)));\r
-  }\r
-  else\r
-  {\r
-    camera.SetProjectionMode(Camera::ORTHOGRAPHIC_PROJECTION);\r
-    camera.SetOrthographicProjection(params.orthographicSize.x,\r
-                                     params.orthographicSize.y,\r
-                                     params.orthographicSize.z,\r
-                                     params.orthographicSize.w,\r
-                                     params.zNear,\r
-                                     params.zFar);\r
-  }\r
-\r
-  // model\r
-  Vector3    camTranslation;\r
-  Vector3    camScale;\r
-  Quaternion camOrientation;\r
-  params.CalculateTransformComponents(camTranslation, camOrientation, camScale);\r
-\r
-  SetActorCentered(camera);\r
-  camera.SetInvertYAxis(true);\r
-  camera.SetProperty(Actor::Property::POSITION, camTranslation);\r
-  camera.SetProperty(Actor::Property::ORIENTATION, camOrientation);\r
-  camera.SetProperty(Actor::Property::SCALE, camScale);\r
-\r
-  camOrientation.Conjugate();\r
-}\r
-\r
 void ConfigureBlendShapeShaders(ResourceBundle& resources, const SceneDefinition& scene, Actor root, std::vector<BlendshapeShaderConfigurationRequest>&& requests)\r
 {\r
   std::vector<std::string> errors;\r
@@ -232,7 +197,8 @@ Actor LoadScene(std::string sceneName, CameraActor camera, std::vector<Animation
     cameraParameters.push_back(CameraParameters());\r
     cameraParameters[0].matrix.SetTranslation(CAMERA_DEFAULT_POSITION);\r
   }\r
-  ConfigureCamera(cameraParameters[0], camera);\r
+  cameraParameters[0].ConfigureCamera(camera);\r
+  SetActorCentered(camera);\r
 \r
   ViewProjection viewProjection = cameraParameters[0].GetViewProjection();\r
   Transforms     xforms{\r
@@ -271,8 +237,22 @@ Actor LoadScene(std::string sceneName, CameraActor camera, std::vector<Animation
 \r
   if(!animations->empty())\r
   {\r
-    auto getActor = [&root](const Scene3D::Loader::AnimatedProperty& property) {\r
-      return root.FindChildByName(property.mNodeName);\r
+    auto getActor = [&](const Scene3D::Loader::AnimatedProperty& property)\r
+    {\r
+      Dali::Actor actor;\r
+      if(property.mNodeIndex != Scene3D::Loader::INVALID_INDEX)\r
+      {\r
+        auto* node = scene.GetNode(property.mNodeIndex);\r
+        if(node != nullptr)\r
+        {\r
+          actor = root.FindChildById(node->mNodeId);\r
+        }\r
+      }\r
+      else\r
+      {\r
+        actor = root.FindChildByName(property.mNodeName);\r
+      }\r
+      return actor;\r
     };\r
 \r
     animation = (*animations)[0].ReAnimate(getActor);\r
@@ -486,6 +466,7 @@ void Scene3DExample::OnTap(Dali::Actor actor, const Dali::TapGesture& tap)
 \r
   auto id = mItemView.GetItemId(actor);\r
 \r
+  Scene3D::Loader::InitializeGltfLoader();\r
   try\r
   {\r
     auto window      = mApp.GetWindow();\r
index 718162f..c20da2e 100644 (file)
         "uCubeMatrix" : [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ],
         "uMaxLOD" : 6
     }, {
-        "vertex" : "dli_images.vsh",
-        "fragment" : "dli_images.fsh",
+        "vertex" : "../shaders/dli_images.vsh",
+        "fragment" : "../shaders/dli_images.fsh",
         "rendererState" : "DEPTH_TEST|ALPHA_BLEND",
         "uCubeMatrix" : [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
         "uTilt" : [ 0.0, 0.0 ]