2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-scene3d/internal/common/model-load-task.h>
22 #include <dali/integration-api/debug.h>
33 static constexpr Vector3 Y_DIRECTION(1.0f, -1.0f, 1.0f);
36 ModelLoadTask::ModelLoadTask(const std::string& modelUrl, const std::string& resourceDirectoryUrl, CallbackBase* callback)
37 : AsyncTask(callback),
39 mResourceDirectoryUrl(resourceDirectoryUrl),
40 mModelCacheManager(Scene3D::Internal::ModelCacheManager::Get()),
41 mLoadResult(mModelCacheManager.GetModelLoadResult(mModelUrl)),
46 ModelLoadTask::~ModelLoadTask()
50 void ModelLoadTask::Process()
52 if(mResourceDirectoryUrl.empty())
54 std::filesystem::path modelUrl(mModelUrl);
55 mResourceDirectoryUrl = std::string(modelUrl.parent_path()) + "/";
58 Dali::Scene3D::Loader::ResourceBundle::PathProvider pathProvider = [&](Dali::Scene3D::Loader::ResourceType::Value type) {
59 return mResourceDirectoryUrl;
62 mModelLoader = std::make_shared<Dali::Scene3D::Loader::ModelLoader>(mModelUrl, mResourceDirectoryUrl, mLoadResult);
64 bool loadSucceeded = false;
65 Dali::ConditionalWait& loadSceneConditionalWait = mModelCacheManager.GetLoadSceneConditionalWaitInstance(mModelUrl);
67 ConditionalWait::ScopedLock lock(loadSceneConditionalWait);
68 if(mModelCacheManager.IsSceneLoaded(mModelUrl))
74 mModelCacheManager.SetSceneLoading(mModelUrl, true);
76 loadSucceeded = mModelLoader->LoadModel(pathProvider, true);
78 // Mesh of glTF and dli is defined in right hand coordinate system, with positive Y for Up direction.
79 // Because DALi uses left hand system, Y direciton will be flipped for environment map sampling.
80 for(auto&& env : GetResources().mEnvironmentMaps)
82 env.first.mYDirection = Y_DIRECTION;
85 mModelCacheManager.SetSceneLoading(mModelUrl, false);
86 mModelCacheManager.SetSceneLoaded(mModelUrl, loadSucceeded);
92 DALI_LOG_ERROR("Failed to load scene from '%s'\n", mModelUrl.c_str());
99 bool ModelLoadTask::IsReady()
104 bool ModelLoadTask::HasSucceeded() const
106 return mHasSucceeded;
109 Dali::Scene3D::Loader::SceneDefinition& ModelLoadTask::GetScene() const
111 return mModelLoader->GetScene();
114 Dali::Scene3D::Loader::ResourceBundle& ModelLoadTask::GetResources() const
116 return mModelLoader->GetResources();
119 std::vector<Dali::Scene3D::Loader::AnimationDefinition>& ModelLoadTask::GetAnimations() const
121 return mModelLoader->GetAnimations();
124 std::vector<Dali::Scene3D::Loader::CameraParameters>& ModelLoadTask::GetCameras() const
126 return mModelLoader->GetCameras();
129 Dali::Scene3D::Loader::Customization::Choices& ModelLoadTask::GetResourceChoices()
131 return mModelLoader->GetResourceChoices();
134 } // namespace Internal
136 } // namespace Scene3D