scene3d-model-example.cpp 20.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651
/*
 * Copyright (c) 2023 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.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include <dali-scene3d/dali-scene3d.h>
#include <dali-toolkit/dali-toolkit.h>
#include <dali/dali.h>
#include <dali/devel-api/adaptor-framework/file-loader.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>
#include <dali/public-api/actors/camera-actor.h>
#include <cstring>

using namespace Dali;
using namespace Dali::Toolkit;

/*
 * This example shows how to create and display a Model control.
 * The application can load 5 different glTF model to Model control.
 * Each model has diffirent material. BoomBox shows glossy or matt plastic material.
 * DamagedHelmet shows a kind of reflective glass and metallic object.
 * Microphone shows a roughness of metallic objects.
 * and Lantern shows a realistic difference between wood object and metallic object.
 * Rotate the camera by swiping.
 * A double tap changes the model.
 */

namespace
{
struct ModelInfo
{
  const char*   name;      ///< The name of the model.
  const Vector2 size;      ///< The size of the model
  const float   yPosition; ///< The position of the model in the Y axis.
};

const ModelInfo gltf_list[] =
  {
    /**
     * For the BoxAnimated.glb
     * Donated by Cesium for glTF testing.
     * Take from https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/BoxAnimated
     */
    {"BoxAnimated.glb", Vector2(300.0f, 300.0f), 100.0f},
    /**
     * For the quantized Duck.gltf and its Assets
     * Created by Sony Computer Entertainment Inc.
     * Licensed under the SCEA Shared Source License, Version 1.0
     * Take from https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/Duck/glTF-Quantized
     */
    {"Duck.gltf", Vector2(600.0f, 600.0f), 300.0f},
    /**
     * For the Lantern.gltf and its Assets
     * Donated by Microsoft for glTF testing
     * Created by Ryan Martin
     * Take from https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/Lantern
     */
    {"Lantern.gltf", Vector2(600.0f, 600.0f), 0.0f},
    /**
     * For the BoomBox.gltf and its Assets
     * Donated by Microsoft for glTF testing
     * Created by Ryan Martin
     * Take from https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/BoomBox
     */
    {"BoomBox.gltf", Vector2(600.0f, 600.0f), 0.0f},
    /**
     * For the DamagedHelmet.glb
     * Battle Damaged Sci-fi Helmet - PBR by theblueturtle_, published under a
     * Creative Commons Attribution-NonCommercial license
     * https://sketchfab.com/models/b81008d513954189a063ff901f7abfe4
     */
    {"DamagedHelmet.glb", Vector2(600.0f, 600.0f), 0.0f},
    /**
     * For the microphone.gltf and its Assets
     * Microphone GXL 066 Bafhcteks by Gistold, published under a
     * Creative Commons Attribution-NonCommercial license
     * https://sketchfab.com/models/5172dbe9281a45f48cee8c15bdfa1831
     */
    {"microphone.gltf", Vector2(600.0f, 600.0f), 0.0f},
    /**
     * For the beer_model.dli and its Assets
     * This model includes a bottle of beer and cube box.
     */
    {"beer_model.dli", Vector2(600.0f, 600.0f), 0.0f},
    /**
     * For the exercise_model.dli and its Assets
     * This model includes a sportsman
     */
    {"exercise_model.dli", Vector2(600.0f, 600.0f), 0.0f},
};

const int32_t NUM_OF_GLTF_MODELS = sizeof(gltf_list) / sizeof(gltf_list[0]);

/**
 * For the diffuse and specular cube map texture.
 * These textures are based off version of Wave engine sample
 * Take from https://github.com/WaveEngine/Samples
 *
 * Copyright (c) 2016 Wave Coorporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

const std::string modeldir = DEMO_MODEL_DIR;
const std::string imagedir = DEMO_IMAGE_DIR;
const std::string uri_cube_diffuse_texture(imagedir + "forest_diffuse_cubemap.png");
const std::string uri_diffuse_texture(imagedir + "Studio/Irradiance.ktx");
const std::string uri_specular_texture(imagedir + "Studio/Radiance.ktx");

const int32_t cubeMap_index_x[6] = {2, 0, 1, 1, 1, 3};
const int32_t cubeMap_index_y[6] = {1, 1, 0, 2, 1, 1};

const char* VERTEX_SHADER_URL   = DEMO_SHADER_DIR "cube_shader.vsh";
const char* FRAGMENT_SHADER_URL = DEMO_SHADER_DIR "cube_shader.fsh";

/**
 * @brief Load a shader source file
 * @param[in] The path of the source file
 * @param[out] The contents of file
 * @return True if the source was read successfully
 */
bool LoadShaderCode(const std::string& fullpath, std::vector<char>& output)
{
  Dali::FileStream fileStream(fullpath, FileStream::READ | FileStream::BINARY);
  FILE*            file = fileStream.GetFile();
  if(nullptr == file)
  {
    return false;
  }

  bool retValue = false;
  if(!fseek(file, 0, SEEK_END))
  {
    long int size = ftell(file);

    if((size != -1L) &&
       (!fseek(file, 0, SEEK_SET)))
    {
      output.resize(size + 1);
      std::fill(output.begin(), output.end(), 0);
      ssize_t result = fread(output.data(), size, 1, file);

      retValue = (result >= 0);
    }
  }

  return retValue;
}

/**
 * @brief Load vertex and fragment shader source
 * @param[in] shaderVertexFileName is the filepath of Vertex shader
 * @param[in] shaderFragFileName is the filepath of Fragment shader
 * @return the Dali::Shader object
 */
Shader LoadShaders(const std::string& shaderVertexFileName, const std::string& shaderFragFileName)
{
  Shader            shader;
  std::vector<char> bufV, bufF;

  if(LoadShaderCode(shaderVertexFileName.c_str(), bufV))
  {
    if(LoadShaderCode(shaderFragFileName.c_str(), bufF))
    {
      shader = Shader::New(bufV.data(), bufF.data());
    }
  }
  return shader;
}

} // namespace

/**
 * This example shows how to render glTF model with Model
 * How to test
 *  - Input UP or DOWN key to make the model rotate or stop.
 *  - Input LEFT or RIGHT key to change glTF model
 *  - Double Touch also changes glTF model.
 */
class Scene3DModelExample : public ConnectionTracker
{
public:
  Scene3DModelExample(Application& application)
  : mApplication(application),
    mModelOrientation(),
    mAnimationStop(false)
  {
    // Connect to the Application's Init signal
    mApplication.InitSignal().Connect(this, &Scene3DModelExample::Create);
  }

  ~Scene3DModelExample()
  {
    mAnimation.Stop();
  }

  // The Init signal is received once (only) during the Application lifetime
  void Create(Application& application)
  {
    mWindow = application.GetWindow();
    mWindow.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);

    // Get a handle to the mWindow
    mWindow.SetBackgroundColor(Color::WHITE);

    RenderTask renderTask = mWindow.GetRenderTaskList().GetTask(0);
    renderTask.SetCullMode(false);

    mCurrentGlTF = 0u;
    CreateSceneFromGLTF(mCurrentGlTF);
    SetCameraActor();
    CreateSkybox();
    SetAnimation();

    // Respond to a click anywhere on the mWindow
    mWindow.GetRootLayer().TouchedSignal().Connect(this, &Scene3DModelExample::OnTouch);
    mWindow.KeyEventSignal().Connect(this, &Scene3DModelExample::OnKeyEvent);
    mWindow.GetRootLayer().WheelEventSignal().Connect(this, &Scene3DModelExample::OnWheel);

    mDoubleTap     = false;
    mDoubleTapTime = Timer::New(150);
    mDoubleTapTime.TickSignal().Connect(this, &Scene3DModelExample::OnDoubleTapTime);
  }

  bool OnWheel(Actor actor, const WheelEvent& wheelEvent)
  {
    mWheelDelta -= wheelEvent.GetDelta() * 0.025f;
    mWheelDelta = std::max(0.5f, mWheelDelta);
    mWheelDelta = std::min(2.0f, mWheelDelta);

    if(mModel)
    {
      mModel.SetProperty(Actor::Property::SCALE, mWheelDelta);
    }

    return true;
  }

  bool OnDoubleTapTime()
  {
    mDoubleTap = false;
    return true;
  }

  void CreateSceneFromGLTF(uint32_t index)
  {
    mReadyToLoad = false;
    if(mModel)
    {
      mWindow.GetRootLayer().Remove(mModel);
    }

    std::string gltfUrl = modeldir;
    gltfUrl += gltf_list[index].name;

    mModel = Dali::Scene3D::Model::New(gltfUrl);
    mModel.SetProperty(Dali::Actor::Property::SIZE, gltf_list[index].size);
    mModel.SetProperty(Dali::Actor::Property::POSITION_Y, gltf_list[index].yPosition);
    mModel.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
    mModel.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
    mModel.SetImageBasedLightSource(uri_diffuse_texture, uri_specular_texture, 0.6f);

    mModel.ResourceReadySignal().Connect(this, &Scene3DModelExample::ResourceReady);

    mWindow.Add(mModel);
  }

  void ResourceReady(Control control)
  {
    mReadyToLoad = true;
    if(mModel.GetAnimationCount() > 0)
    {
      Animation animation = (std::string("exercise_model.dli") == gltf_list[mCurrentGlTF].name) ? mModel.GetAnimation("idleToSquatClip_0") : mModel.GetAnimation(0u);
      animation.Play();
      animation.SetLoopCount(0);
    }
  }

  void SetCameraActor()
  {
    mCameraActor    = mWindow.GetRenderTaskList().GetTask(0).GetCameraActor();
    mCameraPosition = mCameraActor.GetProperty<Vector3>(Dali::Actor::Property::POSITION);
    mCameraActor.SetType(Dali::Camera::LOOK_AT_TARGET);
  }

  void CreateSkybox()
  {
    struct Vertex
    {
      Vector3 aPosition;
    };

    Vertex skyboxVertices[] = {
      // back
      {Vector3(-1.0f, 1.0f, -1.0f)},
      {Vector3(-1.0f, -1.0f, -1.0f)},
      {Vector3(1.0f, -1.0f, -1.0f)},
      {Vector3(1.0f, -1.0f, -1.0f)},
      {Vector3(1.0f, 1.0f, -1.0f)},
      {Vector3(-1.0f, 1.0f, -1.0f)},

      // left
      {Vector3(-1.0f, -1.0f, 1.0f)},
      {Vector3(-1.0f, -1.0f, -1.0f)},
      {Vector3(-1.0f, 1.0f, -1.0f)},
      {Vector3(-1.0f, 1.0f, -1.0f)},
      {Vector3(-1.0f, 1.0f, 1.0f)},
      {Vector3(-1.0f, -1.0f, 1.0f)},

      // right
      {Vector3(1.0f, -1.0f, -1.0f)},
      {Vector3(1.0f, -1.0f, 1.0f)},
      {Vector3(1.0f, 1.0f, 1.0f)},
      {Vector3(1.0f, 1.0f, 1.0f)},
      {Vector3(1.0f, 1.0f, -1.0f)},
      {Vector3(1.0f, -1.0f, -1.0f)},

      // front
      {Vector3(-1.0f, -1.0f, 1.0f)},
      {Vector3(-1.0f, 1.0f, 1.0f)},
      {Vector3(1.0f, 1.0f, 1.0f)},
      {Vector3(1.0f, 1.0f, 1.0f)},
      {Vector3(1.0f, -1.0f, 1.0f)},
      {Vector3(-1.0f, -1.0f, 1.0f)},

      // botton
      {Vector3(-1.0f, 1.0f, -1.0f)},
      {Vector3(1.0f, 1.0f, -1.0f)},
      {Vector3(1.0f, 1.0f, 1.0f)},
      {Vector3(1.0f, 1.0f, 1.0f)},
      {Vector3(-1.0f, 1.0f, 1.0f)},
      {Vector3(-1.0f, 1.0f, -1.0f)},

      // top
      {Vector3(-1.0f, -1.0f, -1.0f)},
      {Vector3(-1.0f, -1.0f, 1.0f)},
      {Vector3(1.0f, -1.0f, -1.0f)},
      {Vector3(1.0f, -1.0f, -1.0f)},
      {Vector3(-1.0f, -1.0f, 1.0f)},
      {Vector3(1.0f, -1.0f, 1.0f)}};

    const std::string currentVShaderFile(VERTEX_SHADER_URL);
    const std::string currentFShaderFile(FRAGMENT_SHADER_URL);

    mShaderSkybox = LoadShaders(currentVShaderFile, currentFShaderFile);

    Dali::VertexBuffer vertexBuffer = Dali::VertexBuffer::New(Property::Map()
                                                                .Add("aPosition", Property::VECTOR3));
    vertexBuffer.SetData(skyboxVertices, sizeof(skyboxVertices) / sizeof(Vertex));

    mSkyboxGeometry = Geometry::New();
    mSkyboxGeometry.AddVertexBuffer(vertexBuffer);
    mSkyboxGeometry.SetType(Geometry::TRIANGLES);

    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);

    mSkyboxRenderer = Renderer::New(mSkyboxGeometry, mShaderSkybox);
    mSkyboxRenderer.SetTextures(mSkyboxTextures);
    mSkyboxRenderer.SetProperty(Renderer::Property::DEPTH_INDEX, 2.0f);

    // Enables the depth test.
    mSkyboxRenderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::ON);

    // The fragment shader will run only is those pixels that have the max depth value.
    mSkyboxRenderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);

    mSkyboxActor = Actor::New();
    mSkyboxActor.SetProperty(Dali::Actor::Property::NAME, "SkyBox");
    mSkyboxActor.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
    mSkyboxActor.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
    mSkyboxActor.SetProperty(Dali::Actor::Property::POSITION, mCameraPosition);
    mSkyboxActor.AddRenderer(mSkyboxRenderer);
    mWindow.Add(mSkyboxActor);
  }

  void SetAnimation()
  {
    /**
     * Rotate object Actor along Y axis.
     * Animation duration is 8 seconds.
     * Five keyframes are set for each 90 degree. i.e., 0, 90, 180, 270, and 360.
     * Each keyframes are interpolated by linear interpolator.
     */
    mAnimation                = Animation::New(8.0);
    KeyFrames keyframes       = KeyFrames::New();
    float     lengthAnimation = 0.25;
    for(int32_t i = 0; i < 5; ++i)
    {
      keyframes.Add(i * lengthAnimation, Quaternion(Degree(i * 90.0), Vector3::YAXIS));
    }
    mAnimation.AnimateBetween(Property(mModel, Dali::Actor::Property::ORIENTATION), keyframes, Animation::Interpolation::LINEAR);
    mAnimation.SetLooping(true);
    mAnimation.Play();
  }

  uint8_t* CropBuffer(uint8_t* sourceBuffer, uint32_t bytesPerPixel, uint32_t width, uint32_t height, uint32_t xOffset, uint32_t yOffset, uint32_t xFaceSize, uint32_t yFaceSize)
  {
    if(xOffset + xFaceSize > width || yOffset + yFaceSize > height)
    {
      DALI_LOG_ERROR("Can not crop outside of texture area.\n");
      return nullptr;
    }
    uint32_t byteSize   = bytesPerPixel * xFaceSize * yFaceSize;
    uint8_t* destBuffer = reinterpret_cast<uint8_t*>(malloc(byteSize + 4u));

    int32_t srcStride  = width * bytesPerPixel;
    int32_t destStride = xFaceSize * bytesPerPixel;
    int32_t srcOffset  = xOffset * bytesPerPixel + yOffset * srcStride;
    int32_t destOffset = 0;
    for(uint16_t row = yOffset; row < yOffset + yFaceSize; ++row)
    {
      memcpy(destBuffer + destOffset, sourceBuffer + srcOffset, destStride);
      srcOffset += srcStride;
      destOffset += destStride;
    }

    return destBuffer;
  }

  void UploadTextureFace(Texture& texture, Devel::PixelBuffer pixelBuffer, int32_t faceIndex)
  {
    uint8_t* imageBuffer   = pixelBuffer.GetBuffer();
    uint32_t bytesPerPixel = Pixel::GetBytesPerPixel(pixelBuffer.GetPixelFormat());
    uint32_t imageWidth    = pixelBuffer.GetWidth();
    uint32_t imageHeight   = pixelBuffer.GetHeight();

    int32_t faceSize = imageWidth / 4;

    uint32_t xOffset = cubeMap_index_x[faceIndex] * faceSize;
    uint32_t yOffset = cubeMap_index_y[faceIndex] * faceSize;

    uint8_t* tempImageBuffer = CropBuffer(imageBuffer, bytesPerPixel, imageWidth, imageHeight, xOffset, yOffset, faceSize, faceSize);
    if(tempImageBuffer)
    {
      PixelData pixelData = PixelData::New(tempImageBuffer, faceSize * faceSize * bytesPerPixel, faceSize, faceSize, pixelBuffer.GetPixelFormat(), PixelData::FREE);
      texture.Upload(pixelData, CubeMapLayer::POSITIVE_X + faceIndex, 0, 0, 0, faceSize, faceSize);
    }
  }

  void ChangeModel(int32_t direction)
  {
    if(!mReadyToLoad)
    {
      return;
    }

    mCurrentGlTF += direction;
    if(mCurrentGlTF >= NUM_OF_GLTF_MODELS)
    {
      mCurrentGlTF = 0;
    }
    if(mCurrentGlTF < 0)
    {
      mCurrentGlTF = NUM_OF_GLTF_MODELS - 1;
    }
    CreateSceneFromGLTF(mCurrentGlTF);
    SetAnimation();
    mAnimationStop = false;
    mWheelDelta    = 1.0f;
  }

  /**
   * This function will change the material Roughness, Metalness or the model orientation when touched
   */
  bool OnTouch(Actor actor, const TouchEvent& touch)
  {
    const PointState::Type state = touch.GetState(0);

    switch(state)
    {
      case PointState::DOWN:
      {
        if(mDoubleTap)
        {
          ChangeModel(1);
        }
        mDoubleTapTime.Stop();

        mPointZ = touch.GetScreenPosition(0);
        if(!mAnimationStop)
        {
          mAnimation.Pause();
        }
        break;
      }

      case PointState::MOTION:
      {
        const Size    size   = mWindow.GetSize();
        const float   scaleX = size.width;
        const float   scaleY = size.height;
        const Vector2 point  = touch.GetScreenPosition(0);
        mProcess             = false;
        // If the touch is not processed above, then change the model orientation
        if(!mProcess)
        {
          /**
           * This is the motion for the swipe to rotate camera that targeting Vector3::ZERO.
           * Each quaternion is used to rotate camera by Pitch and Yaw respectively.
           * Final Orientation of camera is combination of Pitch and Yaw quaternion.
           * For the natural rendering, Skybox also relocated at the new camera position.
           */
          mProcess           = true;
          const float angle1 = ((mPointZ.y - point.y) / scaleY);
          const float angle2 = ((mPointZ.x - point.x) / scaleX);

          Quaternion pitch(Radian(Degree(angle1 * -200.0f)), (mCameraPosition.z >= 0) ? Vector3::XAXIS : -Vector3::XAXIS);
          Quaternion yaw(Radian(Degree(angle2 * -200.0f)), -Vector3::YAXIS);

          Quaternion newModelOrientation = yaw * pitch;
          mCameraPosition                = newModelOrientation.Rotate(mCameraPosition);
          mCameraActor.SetProperty(Dali::Actor::Property::POSITION, mCameraPosition);
          mSkyboxActor.SetProperty(Dali::Actor::Property::POSITION, mCameraPosition);

          mPointZ = point;
        }
        break;
      }

      case PointState::UP:
      {
        mDoubleTapTime.Start();
        mDoubleTap = true;
        if(!mAnimationStop)
        {
          mAnimation.Play();
        }
        mProcess = false;
        break;
      }

      default:
      {
        break;
      }
    }
    return true;
  }

  void OnKeyEvent(const KeyEvent& event)
  {
    if(event.GetState() == KeyEvent::DOWN)
    {
      if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK))
      {
        mApplication.Quit();
      }
      if(event.GetKeyName() == "Down" ||
         event.GetKeyName() == "Up")
      {
        if(!mProcess)
        {
          if(mAnimationStop)
          {
            mAnimation.Play();
          }
          else
          {
            mAnimation.Pause();
          }
          mAnimationStop = !mAnimationStop;
        }
      }

      if(IsKey(event, Dali::DALI_KEY_CURSOR_RIGHT))
      {
        ChangeModel(1);
      }

      if(IsKey(event, Dali::DALI_KEY_CURSOR_LEFT))
      {
        ChangeModel(-1);
      }
    }
  }

private:
  Window       mWindow;
  Layer        mLayer3D;
  Application& mApplication;
  CameraActor  mCameraActor;
  Dali::Timer  mTimer;

  Vector3              mCameraPosition;
  Dali::Scene3D::Model mModel;

  Vector2    mPointZ;
  Quaternion mModelOrientation;

  Shader     mShaderSkybox;
  Geometry   mSkyboxGeometry;
  TextureSet mSkyboxTextures;
  Renderer   mSkyboxRenderer;
  Actor      mSkyboxActor;

  Animation mAnimation;
  bool      mProcess{false};
  bool      mAnimationStop;

  Timer mDoubleTapTime;
  bool  mDoubleTap{false};

  float mWheelDelta{1.0f};

  int32_t mCurrentGlTF{0};

  bool mReadyToLoad{true};
};

int32_t DALI_EXPORT_API main(int32_t argc, char** argv)
{
  Application         application = Application::New(&argc, &argv);
  Scene3DModelExample test(application);
  application.MainLoop();
  return 0;
}