- Like glb, we need to add some new type of model.
- This abstraction can make easy to add new model file format.
Change-Id: Ib84dd28c082903295ff1295a5c2d4da9a74ef8ca
# List of test case sources (Only these get parsed for test cases)
SET(TC_SOURCES
+ utc-Dali-DliLoaderImpl.cpp
utc-Dali-Gltf2Asset.cpp
+ utc-Dali-Gltf2LoaderImpl.cpp
utc-Dali-Hash.cpp
utc-Dali-JsonReader.cpp
utc-Dali-JsonUtil.cpp
/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * 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.
// Enable debug log for test coverage
#define DEBUG_ENABLED 1
+#include <dali-scene3d/internal/loader/dli-loader-impl.h>
#include <dali-scene3d/internal/loader/json-util.h>
-#include <dali-scene3d/public-api/loader/dli-loader.h>
#include <dali-scene3d/public-api/loader/load-result.h>
#include <dali-scene3d/public-api/loader/resource-bundle.h>
#include <dali-scene3d/public-api/loader/scene-definition.h>
void ConfigureBlendShapeShaders(ResourceBundle& resources, const SceneDefinition& scene, Actor root, std::vector<BlendshapeShaderConfigurationRequest>&& requests)
{
std::vector<std::string> errors;
- auto onError = [&errors](const std::string& msg) {
+ auto onError = [&errors](const std::string& msg)
+ {
errors.push_back(msg);
};
struct Context
{
- ResourceBundle::PathProvider pathProvider = [](ResourceType::Value type) {
+ ResourceBundle::PathProvider pathProvider = [](ResourceType::Value type)
+ {
return TEST_RESOURCE_DIR "/";
};
cameraParameters,
lights};
- DliLoader::InputParams input{
- pathProvider(ResourceType::Mesh),
- nullptr,
- {},
- {},
- nullptr,
- };
- DliLoader::LoadParams loadParams{input, output};
-
- std::vector<std::string> errors;
- DliLoader loader;
+ Dali::Scene3D::Loader::DliInputParameter input;
+ std::vector<std::string> errors;
+ Dali::Scene3D::Loader::Internal::DliLoaderImpl loader;
- StringCallback onError = [this](const std::string& error) {
+ StringCallback onError = [this](const std::string& error)
+ {
errors.push_back(error);
printf("%s\n", error.c_str());
};
Context()
{
+ input.mAnimationsPath = pathProvider(ResourceType::Mesh);
loader.SetErrorCallback(onError);
+ loader.SetInputParameter(input);
}
};
{
Context ctx;
- DALI_TEST_EQUAL(ctx.loader.LoadScene("does_not_exist.dli", ctx.loadParams), false);
+ DALI_TEST_EQUAL(ctx.loader.LoadModel("does_not_exist.dli", ctx.output), false);
auto error = ctx.loader.GetParseError();
DALI_TEST_CHECK(StringHasTokens(error.c_str(), {"Empty source buffer to parse."}));
Context ctx;
auto path = ctx.pathProvider(ResourceType::Mesh) + "invalid.gltf";
- DALI_TEST_EQUAL(ctx.loader.LoadScene(path, ctx.loadParams), false);
+ DALI_TEST_EQUAL(ctx.loader.LoadModel(path, ctx.output), false);
auto error = ctx.loader.GetParseError();
DALI_TEST_CHECK(StringHasTokens(error.c_str(), {"Unexpected character."}));
auto path = ctx.pathProvider(ResourceType::Mesh) + "dli/" + i.first + ".dli";
printf("\n\n%s: %s\n", path.c_str(), i.second.c_str());
- DALI_TEST_ASSERTION(ctx.loader.LoadScene(path, ctx.loadParams), i.second.c_str());
+ DALI_TEST_ASSERTION(ctx.loader.LoadModel(path, ctx.output), i.second.c_str());
}
END_TEST;
Context ctx;
auto path = ctx.pathProvider(ResourceType::Mesh) + "exercise.dli";
- DALI_TEST_CHECK(ctx.loader.LoadScene(path, ctx.loadParams));
+ DALI_TEST_CHECK(ctx.loader.LoadModel(path, ctx.output));
DALI_TEST_CHECK(ctx.errors.empty());
auto& scene = ctx.scene;
{
auto resourceRefs = resources.CreateRefCounter();
scene.CountResourceRefs(iRoot, choices, resourceRefs);
- resources.CountEnvironmentReferences(resourceRefs);
- resources.LoadResources(resourceRefs, ctx.pathProvider);
+ resources.mReferenceCounts = std::move(resourceRefs);
+ resources.CountEnvironmentReferences();
+ resources.LoadResources(ctx.pathProvider);
if(auto actor = scene.CreateNodes(iRoot, choices, nodeParams))
{
scene.ConfigureSkeletonJoints(iRoot, resources.mSkeletons, actor);
std::vector<std::string> metadata;
uint32_t metadataCount = 0;
ctx.input.mPreNodeCategoryProcessors.push_back({"metadata",
- [&](const Property::Array& array, StringCallback) {
+ [&](const Property::Array& array, StringCallback)
+ {
std::string key, value;
for(uint32_t i0 = 0, i1 = array.Count(); i0 < i1; ++i0)
{
std::vector<std::string> behaviors;
uint32_t behaviorCount = 0;
ctx.input.mPostNodeCategoryProcessors.push_back({"behaviors",
- [&](const Property::Array& array, StringCallback) {
+ [&](const Property::Array& array, StringCallback)
+ {
for(uint32_t i0 = 0, i1 = array.Count(); i0 < i1; ++i0)
{
auto& data = array.GetElementAt(i0);
}});
size_t numNodes = 0;
- ctx.input.mNodePropertyProcessor = [&](const NodeDefinition&, const Property::Map&, StringCallback) {
+ ctx.input.mNodePropertyProcessor = [&](const NodeDefinition&, const Property::Map&, StringCallback)
+ {
++numNodes;
};
auto path = ctx.pathProvider(ResourceType::Mesh) + "morph.dli";
- DALI_TEST_CHECK(ctx.loader.LoadScene(path, ctx.loadParams));
+ DALI_TEST_CHECK(ctx.loader.LoadModel(path, ctx.output));
DALI_TEST_CHECK(ctx.errors.empty());
auto& scene = ctx.scene;
{
auto resourceRefs = resources.CreateRefCounter();
scene.CountResourceRefs(iRoot, choices, resourceRefs);
- resources.CountEnvironmentReferences(resourceRefs);
- resources.LoadResources(resourceRefs, ctx.pathProvider);
+ resources.mReferenceCounts = std::move(resourceRefs);
+ resources.CountEnvironmentReferences();
+ resources.LoadResources(ctx.pathProvider);
if(auto actor = scene.CreateNodes(iRoot, choices, nodeParams))
{
scene.ConfigureSkeletonJoints(iRoot, resources.mSkeletons, actor);
Context ctx;
auto path = ctx.pathProvider(ResourceType::Mesh) + "arc.dli";
- DALI_TEST_CHECK(ctx.loader.LoadScene(path, ctx.loadParams));
+ DALI_TEST_CHECK(ctx.loader.LoadModel(path, ctx.output));
DALI_TEST_CHECK(ctx.errors.empty());
auto& scene = ctx.scene;
{
auto resourceRefs = resources.CreateRefCounter();
scene.CountResourceRefs(iRoot, choices, resourceRefs);
- resources.CountEnvironmentReferences(resourceRefs);
- resources.LoadResources(resourceRefs, ctx.pathProvider);
+ resources.mReferenceCounts = std::move(resourceRefs);
+ resources.CountEnvironmentReferences();
+ resources.LoadResources(ctx.pathProvider);
if(auto actor = scene.CreateNodes(iRoot, choices, nodeParams))
{
scene.ConfigureSkeletonJoints(iRoot, resources.mSkeletons, actor);
Context ctx;
auto path = ctx.pathProvider(ResourceType::Mesh) + "dli/shader-uniforms.dli";
- DALI_TEST_CHECK(ctx.loader.LoadScene(path, ctx.loadParams));
+ DALI_TEST_CHECK(ctx.loader.LoadModel(path, ctx.output));
DALI_TEST_EQUAL(ctx.errors.size(), 1u);
DALI_TEST_CHECK(ctx.errors[0].find("failed to infer type") != std::string::npos);
Context ctx;
auto path = ctx.pathProvider(ResourceType::Mesh) + "dli/extras.dli";
- DALI_TEST_CHECK(ctx.loader.LoadScene(path, ctx.loadParams));
+ DALI_TEST_CHECK(ctx.loader.LoadModel(path, ctx.output));
DALI_TEST_EQUAL(ctx.errors.size(), 3u);
DALI_TEST_CHECK(ctx.errors[0].find("already defined; overriding") != std::string::npos);
DALI_TEST_CHECK(ctx.errors[1].find("empty string is invalid for name") != std::string::npos);
Context ctx;
auto path = ctx.pathProvider(ResourceType::Mesh) + "dli/constraints.dli";
- DALI_TEST_CHECK(ctx.loader.LoadScene(path, ctx.loadParams));
+ DALI_TEST_CHECK(ctx.loader.LoadModel(path, ctx.output));
DALI_TEST_EQUAL(ctx.errors.size(), 1u);
DALI_TEST_CHECK(ctx.errors[0].find("invalid", ctx.errors[0].find("node ID")) != std::string::npos);
Context ctx;
std::vector<Property::Map> nodeMaps;
- ctx.input.mNodePropertyProcessor = [&](const NodeDefinition&, Property::Map&& map, StringCallback) {
+ ctx.input.mNodePropertyProcessor = [&](const NodeDefinition&, Property::Map&& map, StringCallback)
+ {
nodeMaps.push_back(map);
};
auto path = ctx.pathProvider(ResourceType::Mesh) + "dli/node-processor.dli";
- DALI_TEST_CHECK(ctx.loader.LoadScene(path, ctx.loadParams));
+ DALI_TEST_CHECK(ctx.loader.LoadModel(path, ctx.output));
DALI_TEST_EQUAL(nodeMaps.size(), 2u);
DALI_TEST_EQUAL(nodeMaps[0].Count(), 5u);
Context ctx;
auto path = ctx.pathProvider(ResourceType::Mesh) + "coverageTest.dli";
- DALI_TEST_CHECK(ctx.loader.LoadScene(path, ctx.loadParams));
+ DALI_TEST_CHECK(ctx.loader.LoadModel(path, ctx.output));
DALI_TEST_CHECK(ctx.errors.empty());
auto& scene = ctx.scene;
{
auto resourceRefs = resources.CreateRefCounter();
scene.CountResourceRefs(iRoot, choices, resourceRefs);
- resources.CountEnvironmentReferences(resourceRefs);
- resources.LoadResources(resourceRefs, ctx.pathProvider);
+ resources.mReferenceCounts = std::move(resourceRefs);
+ resources.CountEnvironmentReferences();
+ resources.LoadResources(ctx.pathProvider);
if(auto actor = scene.CreateNodes(iRoot, choices, nodeParams))
{
scene.ConfigureSkeletonJoints(iRoot, resources.mSkeletons, actor);
// Enable debug log for test coverage
#define DEBUG_ENABLED 1
-#include <dali-scene3d/public-api/loader/gltf2-loader.h>
+#include <dali-scene3d/internal/loader/gltf2-loader-impl.h>
#include <dali-scene3d/public-api/loader/load-result.h>
#include <dali-scene3d/public-api/loader/resource-bundle.h>
#include <dali-scene3d/public-api/loader/scene-definition.h>
animationGroups,
cameras,
lights};
+
+ Dali::Scene3D::Loader::Internal::Gltf2LoaderImpl loader;
};
struct ExceptionMessageStartsWith
{
Context ctx;
- ShaderDefinitionFactory sdf;
- sdf.SetResources(ctx.resources);
-
- InitializeGltfLoader();
- DALI_TEST_THROW(LoadGltfScene("non-existent.gltf", sdf, ctx.loadResult),
- std::runtime_error,
- ExceptionMessageStartsWith{"Failed to load"});
+ DALI_TEST_EQUAL(ctx.loader.LoadModel("non-existent.gltf", ctx.loadResult), false);
DALI_TEST_EQUAL(0, ctx.scene.GetRoots().size());
DALI_TEST_EQUAL(0, ctx.scene.GetNodeCount());
ShaderDefinitionFactory sdf;
sdf.SetResources(ctx.resources);
- InitializeGltfLoader();
- DALI_TEST_THROW(LoadGltfScene(TEST_RESOURCE_DIR "/invalid.gltf", sdf, ctx.loadResult),
- std::runtime_error,
- ExceptionMessageStartsWith{"Failed to parse"});
+ DALI_TEST_EQUAL(ctx.loader.LoadModel(TEST_RESOURCE_DIR "/invalid.gltf", ctx.loadResult), false);
DALI_TEST_EQUAL(0, ctx.scene.GetRoots().size());
DALI_TEST_EQUAL(0, ctx.scene.GetNodeCount());
++metaData;
}
- ShaderDefinitionFactory sdf;
- sdf.SetResources(ctx.resources);
-
- InitializeGltfLoader();
- LoadGltfScene(TEST_RESOURCE_DIR "/AnimatedCube.gltf", sdf, ctx.loadResult);
+ ctx.loader.LoadModel(TEST_RESOURCE_DIR "/AnimatedCube.gltf", ctx.loadResult);
DALI_TEST_EQUAL(1u, ctx.scene.GetRoots().size());
DALI_TEST_EQUAL(9u, ctx.scene.GetNodeCount());
{
auto resourceRefs = ctx.resources.CreateRefCounter();
ctx.scene.CountResourceRefs(iRoot, choices, resourceRefs);
- ctx.resources.CountEnvironmentReferences(resourceRefs);
- ctx.resources.LoadResources(resourceRefs, ctx.pathProvider);
+ ctx.resources.mReferenceCounts = std::move(resourceRefs);
+ ctx.resources.CountEnvironmentReferences();
+ ctx.resources.LoadResources(ctx.pathProvider);
}
auto& materials = ctx.resources.mMaterials;
ShaderDefinitionFactory sdf;
sdf.SetResources(ctx.resources);
- InitializeGltfLoader();
- LoadGltfScene(TEST_RESOURCE_DIR "/AnimatedCubeStride.gltf", sdf, ctx.loadResult);
+ ctx.loader.LoadModel(TEST_RESOURCE_DIR "/AnimatedCubeStride.gltf", ctx.loadResult);
DALI_TEST_EQUAL(1u, ctx.scene.GetRoots().size());
DALI_TEST_EQUAL(1u, ctx.scene.GetNodeCount());
{
auto resourceRefs = ctx.resources.CreateRefCounter();
ctx.scene.CountResourceRefs(iRoot, choices, resourceRefs);
- ctx.resources.LoadResources(resourceRefs, ctx.pathProvider);
+ ctx.resources.mReferenceCounts = std::move(resourceRefs);
+ ctx.resources.LoadResources(ctx.pathProvider);
}
DALI_TEST_EQUAL(true, ctx.resources.mMeshes[0u].first.mPositions.IsDefined());
{
Context ctx;
- ShaderDefinitionFactory sdf;
-
auto& resources = ctx.resources;
resources.mEnvironmentMaps.push_back({});
- sdf.SetResources(resources);
-
printf("%s\n", modelName);
- InitializeGltfLoader();
- LoadGltfScene(resourcePath + modelName + ".gltf", sdf, ctx.loadResult);
+ ctx.loader.LoadModel(resourcePath + modelName + ".gltf", ctx.loadResult);
DALI_TEST_CHECK(ctx.scene.GetNodeCount() > 0);
auto& scene = ctx.scene;
sdf.SetResources(ctx.resources);
auto& resources = ctx.resources;
- InitializeGltfLoader();
- LoadGltfScene(TEST_RESOURCE_DIR "/MRendererTest.gltf", sdf, ctx.loadResult);
+ ctx.loader.LoadModel(TEST_RESOURCE_DIR "/MRendererTest.gltf", ctx.loadResult);
auto& scene = ctx.scene;
auto& roots = scene.GetRoots();
{
auto resourceRefs = resources.CreateRefCounter();
scene.CountResourceRefs(iRoot, choices, resourceRefs);
- resources.CountEnvironmentReferences(resourceRefs);
- resources.LoadResources(resourceRefs, ctx.pathProvider);
+ ctx.resources.mReferenceCounts = std::move(resourceRefs);
+ ctx.resources.CountEnvironmentReferences();
+ ctx.resources.LoadResources(ctx.pathProvider);
if(auto actor = scene.CreateNodes(iRoot, choices, nodeParams))
{
scene.ConfigureSkeletonJoints(iRoot, resources.mSkeletons, actor);
{
Context ctx;
- ShaderDefinitionFactory sdf;
- sdf.SetResources(ctx.resources);
auto& resources = ctx.resources;
- InitializeGltfLoader();
- LoadGltfScene(TEST_RESOURCE_DIR "/CesiumMan_e.gltf", sdf, ctx.loadResult);
+ ctx.loader.LoadModel(TEST_RESOURCE_DIR "/CesiumMan_e.gltf", ctx.loadResult);
auto& scene = ctx.scene;
auto& roots = scene.GetRoots();
{
auto resourceRefs = resources.CreateRefCounter();
scene.CountResourceRefs(iRoot, choices, resourceRefs);
- resources.CountEnvironmentReferences(resourceRefs);
- resources.LoadResources(resourceRefs, ctx.pathProvider);
+ resources.mReferenceCounts = std::move(resourceRefs);
+ resources.CountEnvironmentReferences();
+ resources.LoadResources(ctx.pathProvider);
if(auto actor = scene.CreateNodes(iRoot, choices, nodeParams))
{
scene.ConfigureSkeletonJoints(iRoot, resources.mSkeletons, actor);
sdf.SetResources(ctx.resources);
auto& resources = ctx.resources;
- InitializeGltfLoader();
- LoadGltfScene(TEST_RESOURCE_DIR "/EnvironmentTest_b.gltf", sdf, ctx.loadResult);
+ ctx.loader.LoadModel(TEST_RESOURCE_DIR "/EnvironmentTest_b.gltf", ctx.loadResult);
auto& scene = ctx.scene;
auto& roots = scene.GetRoots();
{
auto resourceRefs = resources.CreateRefCounter();
scene.CountResourceRefs(iRoot, choices, resourceRefs);
- resources.CountEnvironmentReferences(resourceRefs);
- resources.LoadResources(resourceRefs, ctx.pathProvider);
+ resources.mReferenceCounts = std::move(resourceRefs);
+ resources.CountEnvironmentReferences();
+ resources.LoadResources(ctx.pathProvider);
if(auto actor = scene.CreateNodes(iRoot, choices, nodeParams))
{
scene.ConfigureSkeletonJoints(iRoot, resources.mSkeletons, actor);
{
Context ctx;
- ShaderDefinitionFactory sdf;
- sdf.SetResources(ctx.resources);
auto& resources = ctx.resources;
- InitializeGltfLoader();
- LoadGltfScene(TEST_RESOURCE_DIR "/AlphaBlendModeTest.gltf", sdf, ctx.loadResult);
+ ctx.loader.LoadModel(TEST_RESOURCE_DIR "/AlphaBlendModeTest.gltf", ctx.loadResult);
auto& scene = ctx.scene;
auto& roots = scene.GetRoots();
{
auto resourceRefs = resources.CreateRefCounter();
scene.CountResourceRefs(iRoot, choices, resourceRefs);
- resources.CountEnvironmentReferences(resourceRefs);
- resources.LoadResources(resourceRefs, ctx.pathProvider);
+ resources.mReferenceCounts = std::move(resourceRefs);
+ resources.CountEnvironmentReferences();
+ resources.LoadResources(ctx.pathProvider);
if(auto actor = scene.CreateNodes(iRoot, choices, nodeParams))
{
scene.ConfigureSkeletonJoints(iRoot, resources.mSkeletons, actor);
utc-Dali-BvhLoader.cpp
utc-Dali-CameraParameters.cpp
utc-Dali-EnvironmentMapLoader.cpp
- utc-Dali-DliLoader.cpp
utc-Dali-EnvironmentDefinition.cpp
utc-Dali-FacialAnimation.cpp
- utc-Dali-Gltf2Loader.cpp
utc-Dali-KtxLoader.cpp
utc-Dali-Model.cpp
utc-Dali-SceneView.cpp
// Enable debug log for test coverage
#define DEBUG_ENABLED 1
-#include "dali-scene3d/public-api/loader/resource-bundle.h"
-#include "dali-scene3d/public-api/loader/utils.h"
#include <dali-test-suite-utils.h>
#include <string_view>
+#include "dali-scene3d/public-api/loader/resource-bundle.h"
+#include "dali-scene3d/public-api/loader/utils.h"
using namespace Dali;
using namespace Dali::Scene3D::Loader;
resourceBundle.mMeshes.resize(17);
resourceBundle.mMaterials.resize(19);
- int i = 0;
+ int i = 0;
std::vector<int> testEnvironmentReferences(resourceBundle.mEnvironmentMaps.size());
- for (auto& m : resourceBundle.mMaterials)
+ for(auto& m : resourceBundle.mMaterials)
{
Index iEnv = 0;
iEnv += (i % 3) == 0;
DALI_TEST_EQUAL(counter[ResourceType::Material].Size(), resourceBundle.mMaterials.size());
std::fill(counter[ResourceType::Material].begin(), counter[ResourceType::Material].end(), 1u);
- resourceBundle.CountEnvironmentReferences(counter);
- i = 0;
- for (auto& er: counter[ResourceType::Environment])
+ resourceBundle.mReferenceCounts = std::move(counter);
+ resourceBundle.CountEnvironmentReferences();
+
+ const ResourceRefCounts& referenceCounts = resourceBundle.mReferenceCounts;
+ i = 0;
+ for(auto& er : referenceCounts[ResourceType::Environment])
{
DALI_TEST_EQUAL(er, testEnvironmentReferences[i]);
++i;
#include <dali-test-suite-utils.h>
#include <set>
#include <string_view>
-#include "dali-scene3d/public-api/loader/gltf2-loader.h"
#include "dali-scene3d/public-api/loader/node-definition.h"
#include "dali-scene3d/public-api/loader/resource-bundle.h"
#include "dali-scene3d/public-api/loader/shader-definition-factory.h"
return cache.loadSceneConditionalWait;
}
- Dali::ConditionalWait& GetLoadRawResourceConditionalWaitInstance(std::string modelUri)
- {
- ModelCache& cache = mModelCache[modelUri];
- return cache.loadRawResourceConditionalWait;
- }
-
void ReferenceModelCache(std::string modelUri)
{
ModelCache& cache = mModelCache[modelUri];
uint32_t refCount{0}; ///< The reference count of this model cache.
Dali::ConditionalWait loadSceneConditionalWait{}; ///< The conditionalWait instance used to synchronise the loading of the scene for the same model in different threads.
- Dali::ConditionalWait loadRawResourceConditionalWait{}; ///< The conditionalWait instance used to synchronise the loading of the shared raw resources for the same model in different threads.
bool isSceneLoaded{false}; ///< Whether the scene of the model has been loaded.
bool isSceneLoading{false}; ///< Whether the scene loading of the model is in progress.
return impl.GetLoadSceneConditionalWaitInstance(modelUri);
}
-Dali::ConditionalWait& ModelCacheManager::GetLoadRawResourceConditionalWaitInstance(std::string modelUri)
-{
- ModelCacheManager::Impl& impl = static_cast<ModelCacheManager::Impl&>(GetBaseObject());
- return impl.GetLoadRawResourceConditionalWaitInstance(modelUri);
-}
-
void ModelCacheManager::ReferenceModelCache(std::string modelUri)
{
ModelCacheManager::Impl& impl = static_cast<ModelCacheManager::Impl&>(GetBaseObject());
Dali::ConditionalWait& GetLoadSceneConditionalWaitInstance(std::string modelUri);
/**
- * @brief Retrieves the ConditionalWait object to synchronize the raw resources loading of the
- * model with the given URI between multiple threads.
- * @param[in] modelUri The unique model URI with its absolute path.
- * @return The ConditionalWait object.
- */
- Dali::ConditionalWait& GetLoadRawResourceConditionalWaitInstance(std::string modelUri);
-
- /**
* @brief Reference the cache of the model with the given URI.
* This will increment the reference count of the load result by 1.
* @param[in] modelUri The model URI.
#include <dali/integration-api/debug.h>
#include <filesystem>
-// INTERNAL INCLUDES
-#include <dali-scene3d/internal/common/model-cache-manager.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/dli-loader.h>
-#include <dali-scene3d/public-api/loader/gltf2-loader.h>
-#include <dali-scene3d/public-api/loader/light-parameters.h>
-#include <dali-scene3d/public-api/loader/node-definition.h>
-#include <dali-scene3d/public-api/loader/shader-definition-factory.h>
-
namespace Dali
{
namespace Scene3D
namespace
{
static constexpr Vector3 Y_DIRECTION(1.0f, -1.0f, 1.0f);
-
-static constexpr std::string_view OBJ_EXTENSION = ".obj";
-static constexpr std::string_view GLTF_EXTENSION = ".gltf";
-static constexpr std::string_view DLI_EXTENSION = ".dli";
-static constexpr std::string_view METADATA_EXTENSION = "metadata";
} // namespace
ModelLoadTask::ModelLoadTask(const std::string& modelUrl, const std::string& resourceDirectoryUrl, CallbackBase* callback)
: AsyncTask(callback),
mModelUrl(modelUrl),
mResourceDirectoryUrl(resourceDirectoryUrl),
- mHasSucceeded(false),
- mModelCacheManager(ModelCacheManager::Get()),
- mLoadResult(mModelCacheManager.GetModelLoadResult(modelUrl))
+ mModelCacheManager(Scene3D::Internal::ModelCacheManager::Get()),
+ mLoadResult(mModelCacheManager.GetModelLoadResult(mModelUrl)),
+ mHasSucceeded(false)
{
}
void ModelLoadTask::Process()
{
- uint32_t cacheRefCount = mModelCacheManager.GetModelCacheRefCount(mModelUrl);
- Dali::ConditionalWait& loadSceneConditionalWait = mModelCacheManager.GetLoadSceneConditionalWaitInstance(mModelUrl);
- Dali::ConditionalWait& loadRawResourceConditionalWait = mModelCacheManager.GetLoadRawResourceConditionalWaitInstance(mModelUrl);
-
- std::filesystem::path modelUrl(mModelUrl);
if(mResourceDirectoryUrl.empty())
{
+ std::filesystem::path modelUrl(mModelUrl);
mResourceDirectoryUrl = std::string(modelUrl.parent_path()) + "/";
}
- std::string extension = modelUrl.extension();
- std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
- Dali::Scene3D::Loader::ResourceBundle::PathProvider pathProvider = [&](Dali::Scene3D::Loader::ResourceType::Value type) {
+ Dali::Scene3D::Loader::ResourceBundle::PathProvider pathProvider = [&](Dali::Scene3D::Loader::ResourceType::Value type)
+ {
return mResourceDirectoryUrl;
};
+ mModelLoader = std::make_shared<Dali::Scene3D::Loader::ModelLoader>(mModelUrl, mResourceDirectoryUrl, mLoadResult);
+
+ bool loadSucceeded = false;
+ Dali::ConditionalWait& loadSceneConditionalWait = mModelCacheManager.GetLoadSceneConditionalWaitInstance(mModelUrl);
{
ConditionalWait::ScopedLock lock(loadSceneConditionalWait);
-
- while(cacheRefCount > 1 && mModelCacheManager.IsSceneLoading(mModelUrl))
+ if(mModelCacheManager.IsSceneLoaded(mModelUrl))
{
- loadSceneConditionalWait.Wait();
+ loadSucceeded = true;
}
- }
-
- {
- ConditionalWait::ScopedLock lock(loadSceneConditionalWait);
-
- if(!mModelCacheManager.IsSceneLoaded(mModelUrl))
+ else
{
mModelCacheManager.SetSceneLoading(mModelUrl, true);
- std::filesystem::path metaDataUrl = modelUrl;
- metaDataUrl.replace_extension(METADATA_EXTENSION.data());
-
- Dali::Scene3D::Loader::LoadSceneMetadata(metaDataUrl.c_str(), mLoadResult.mSceneMetadata);
-
- mLoadResult.mAnimationDefinitions.clear();
+ loadSucceeded = mModelLoader->LoadModel(pathProvider, true);
- if(extension == DLI_EXTENSION)
+ // Mesh of glTF and dli is defined in right hand coordinate system, with positive Y for Up direction.
+ // Because DALi uses left hand system, Y direciton will be flipped for environment map sampling.
+ for(auto&& env : GetResources().mEnvironmentMaps)
{
- Dali::Scene3D::Loader::DliLoader loader;
- Dali::Scene3D::Loader::DliLoader::InputParams input{
- pathProvider(Dali::Scene3D::Loader::ResourceType::Mesh),
- nullptr,
- {},
- {},
- nullptr,
- {}};
- Dali::Scene3D::Loader::DliLoader::LoadParams loadParams{input, mLoadResult};
- if(!loader.LoadScene(mModelUrl, loadParams))
- {
- DALI_LOG_ERROR("Failed to load scene from '%s': %s\n", mModelUrl.c_str(), loader.GetParseError().c_str());
-
- mModelCacheManager.SetSceneLoaded(mModelUrl, false);
- mModelCacheManager.SetSceneLoading(mModelUrl, false);
- mModelCacheManager.UnreferenceModelCache(mModelUrl);
-
- return;
- }
+ env.first.mYDirection = Y_DIRECTION;
}
- else if(extension == GLTF_EXTENSION)
- {
- Dali::Scene3D::Loader::ShaderDefinitionFactory sdf;
- sdf.SetResources(mLoadResult.mResources);
- Dali::Scene3D::Loader::LoadGltfScene(mModelUrl, sdf, mLoadResult);
- }
- else
- {
- DALI_LOG_ERROR("Unsupported model type.\n");
-
- mModelCacheManager.SetSceneLoaded(mModelUrl, false);
- mModelCacheManager.SetSceneLoading(mModelUrl, false);
- mModelCacheManager.UnreferenceModelCache(mModelUrl);
- return;
- }
-
- mModelCacheManager.SetSceneLoaded(mModelUrl, true);
mModelCacheManager.SetSceneLoading(mModelUrl, false);
+ mModelCacheManager.SetSceneLoaded(mModelUrl, loadSucceeded);
}
}
- loadSceneConditionalWait.Notify();
-
+ if(!loadSucceeded)
{
- ConditionalWait::ScopedLock lock(loadRawResourceConditionalWait);
-
- while(cacheRefCount > 1 && mLoadResult.mResources.mRawResourcesLoading)
- {
- loadRawResourceConditionalWait.Wait();
- }
+ DALI_LOG_ERROR("Failed to load scene from '%s'\n", mModelUrl.c_str());
+ return;
}
- {
- ConditionalWait::ScopedLock lock(loadRawResourceConditionalWait);
-
- mResourceRefCount = std::move(mLoadResult.mResources.CreateRefCounter());
-
- for(auto iRoot : mLoadResult.mScene.GetRoots())
- {
- mLoadResult.mScene.CountResourceRefs(iRoot, mResourceChoices, mResourceRefCount);
- }
-
- mLoadResult.mResources.CountEnvironmentReferences(mResourceRefCount);
-
- mLoadResult.mResources.LoadRawResources(mResourceRefCount, pathProvider);
-
- // glTF Mesh is defined in right hand coordinate system, with positive Y for Up direction.
- // Because DALi uses left hand system, Y direciton will be flipped for environment map sampling.
- for(auto&& env : mLoadResult.mResources.mEnvironmentMaps)
- {
- env.first.mYDirection = Y_DIRECTION;
- }
- }
-
- loadRawResourceConditionalWait.Notify();
-
mHasSucceeded = true;
}
return mHasSucceeded;
}
+Dali::Scene3D::Loader::SceneDefinition& ModelLoadTask::GetScene() const
+{
+ return mModelLoader->GetScene();
+}
+
+Dali::Scene3D::Loader::ResourceBundle& ModelLoadTask::GetResources() const
+{
+ return mModelLoader->GetResources();
+}
+
+std::vector<Dali::Scene3D::Loader::AnimationDefinition>& ModelLoadTask::GetAnimations() const
+{
+ return mModelLoader->GetAnimations();
+}
+
+std::vector<Dali::Scene3D::Loader::CameraParameters>& ModelLoadTask::GetCameras() const
+{
+ return mModelLoader->GetCameras();
+}
+
+Dali::Scene3D::Loader::Customization::Choices& ModelLoadTask::GetResourceChoices()
+{
+ return mModelLoader->GetResourceChoices();
+}
+
} // namespace Internal
} // namespace Scene3D
*/
// EXTERNAL INCLUDES
+#include <dali/public-api/adaptor-framework/async-task-manager.h>
#include <dali/public-api/common/intrusive-ptr.h>
#include <dali/public-api/common/vector-wrapper.h>
#include <dali/public-api/images/pixel-data.h>
// INTERNAL INCLUDES
#include <dali-scene3d/internal/common/model-cache-manager.h>
#include <dali-scene3d/public-api/loader/load-result.h>
+#include <dali-scene3d/public-api/loader/model-loader.h>
#include <dali-scene3d/public-api/loader/scene-definition.h>
#include <dali/devel-api/threading/conditional-wait.h>
-#include <dali/public-api/adaptor-framework/async-task-manager.h>
namespace Dali
{
*/
bool HasSucceeded() const;
+ /**
+ * @brief Retrieves loaded scene
+ * @return SceneDefinition that is loaded from file
+ */
+ Dali::Scene3D::Loader::SceneDefinition& GetScene() const;
+
+ /**
+ * @brief Retrieves resource bunder that includes resource information
+ * @return ResourceBundle for model resources
+ */
+ Dali::Scene3D::Loader::ResourceBundle& GetResources() const;
+
+ /**
+ * @brief Retrieves loaded AnimationDefinition
+ * @return AnimationDefinition that is loaded from file
+ */
+ std::vector<Dali::Scene3D::Loader::AnimationDefinition>& GetAnimations() const;
+
+ /**
+ * @brief Retrieves loaded CameraParameters
+ * @return CameraParameters list that is loaded from file
+ */
+ std::vector<Dali::Scene3D::Loader::CameraParameters>& GetCameras() const;
+
+ /**
+ * @brief Retrieves ResourceChoices
+ * @return Choices for loaded Resources
+ */
+ Dali::Scene3D::Loader::Customization::Choices& GetResourceChoices();
+
private:
// Undefined
ModelLoadTask(const ModelLoadTask& task) = delete;
// Undefined
ModelLoadTask& operator=(const ModelLoadTask& task) = delete;
-public:
- std::string mModelUrl;
- std::string mResourceDirectoryUrl;
-
- Dali::Scene3D::Loader::Customization::Choices mResourceChoices;
- Dali::Scene3D::Loader::ResourceRefCounts mResourceRefCount;
- bool mHasSucceeded;
-
- ModelCacheManager mModelCacheManager;
- Dali::Scene3D::Loader::LoadResult mLoadResult;
+ std::string mModelUrl;
+ std::string mResourceDirectoryUrl;
+ std::shared_ptr<Dali::Scene3D::Loader::ModelLoader> mModelLoader;
+ ModelCacheManager mModelCacheManager;
+ Dali::Scene3D::Loader::LoadResult mLoadResult;
+ bool mHasSucceeded;
};
} // namespace Internal
#include <dali-scene3d/public-api/controls/model/model.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/dli-loader.h>
-#include <dali-scene3d/public-api/loader/gltf2-loader.h>
#include <dali-scene3d/public-api/loader/light-parameters.h>
#include <dali-scene3d/public-api/loader/load-result.h>
#include <dali-scene3d/public-api/loader/node-definition.h>
Dali::Scene3D::Loader::ResourceBundle& resources, const Dali::Scene3D::Loader::SceneDefinition& scene, Actor root, std::vector<Dali::Scene3D::Loader::BlendshapeShaderConfigurationRequest>&& requests)
{
std::vector<std::string> errors;
- auto onError = [&errors](const std::string& msg) { errors.push_back(msg); };
+ auto onError = [&errors](const std::string& msg)
+ { errors.push_back(msg); };
if(!scene.ConfigureBlendshapeShaders(resources, root, std::move(requests), onError))
{
Dali::Scene3D::Loader::ExceptionFlinger flinger(ASSERT_LOCATION);
{
ModelCacheManager::Get().ReferenceModelCache(mModelUrl);
}
-
- Scene3D::Loader::InitializeGltfLoader();
mModelLoadTask = new ModelLoadTask(mModelUrl, mResourceDirectoryUrl, MakeCallback(this, &Model::OnModelLoadComplete));
Dali::AsyncTaskManager::Get().AddTask(mModelLoadTask);
}
mRenderableActors.clear();
CollectRenderableActor(mModelRoot);
- CreateAnimations(mModelLoadTask->mLoadResult.mScene);
+ auto& resources = mModelLoadTask->GetResources();
+ auto& scene = mModelLoadTask->GetScene();
+ CreateAnimations(scene);
ResetCameraParameters();
-
- if(!mModelLoadTask->mLoadResult.mResources.mEnvironmentMaps.empty())
+ if(!resources.mEnvironmentMaps.empty())
{
- mDefaultDiffuseTexture = mModelLoadTask->mLoadResult.mResources.mEnvironmentMaps.front().second.mDiffuse;
- mDefaultSpecularTexture = mModelLoadTask->mLoadResult.mResources.mEnvironmentMaps.front().second.mSpecular;
+ mDefaultDiffuseTexture = resources.mEnvironmentMaps.front().second.mDiffuse;
+ mDefaultSpecularTexture = resources.mEnvironmentMaps.front().second.mSpecular;
}
UpdateImageBasedLightTexture();
mModelRoot.SetProperty(Actor::Property::COLOR_MODE, ColorMode::USE_OWN_MULTIPLY_PARENT_COLOR);
BoundingVolume AABB;
+ auto& resources = mModelLoadTask->GetResources();
+ auto& scene = mModelLoadTask->GetScene();
+ auto& resourceChoices = mModelLoadTask->GetResourceChoices();
Dali::Scene3D::Loader::Transforms xforms{Dali::Scene3D::Loader::MatrixStack{}, Dali::Scene3D::Loader::ViewProjection{}};
- Dali::Scene3D::Loader::NodeDefinition::CreateParams nodeParams{mModelLoadTask->mLoadResult.mResources, xforms, {}, {}, {}};
+ Dali::Scene3D::Loader::NodeDefinition::CreateParams nodeParams{resources, xforms, {}, {}, {}};
// Generate Dali handles from resource bundle. Note that we generate all scene's resouce immediatly.
- mModelLoadTask->mLoadResult.mResources.GenerateResources(mModelLoadTask->mResourceRefCount);
-
- for(auto iRoot : mModelLoadTask->mLoadResult.mScene.GetRoots())
+ resources.GenerateResources();
+ for(auto iRoot : scene.GetRoots())
{
- if(auto actor = mModelLoadTask->mLoadResult.mScene.CreateNodes(iRoot, mModelLoadTask->mResourceChoices, nodeParams))
+ if(auto actor = scene.CreateNodes(iRoot, resourceChoices, nodeParams))
{
- mModelLoadTask->mLoadResult.mScene.ConfigureSkeletonJoints(iRoot, mModelLoadTask->mLoadResult.mResources.mSkeletons, actor);
- mModelLoadTask->mLoadResult.mScene.ConfigureSkinningShaders(mModelLoadTask->mLoadResult.mResources, actor, std::move(nodeParams.mSkinnables));
- ConfigureBlendShapeShaders(mModelLoadTask->mLoadResult.mResources, mModelLoadTask->mLoadResult.mScene, actor, std::move(nodeParams.mBlendshapeRequests));
+ scene.ConfigureSkeletonJoints(iRoot, resources.mSkeletons, actor);
+ scene.ConfigureSkinningShaders(resources, actor, std::move(nodeParams.mSkinnables));
+ ConfigureBlendShapeShaders(resources, scene, actor, std::move(nodeParams.mBlendshapeRequests));
- mModelLoadTask->mLoadResult.mScene.ApplyConstraints(actor, std::move(nodeParams.mConstrainables));
+ scene.ApplyConstraints(actor, std::move(nodeParams.mConstrainables));
mModelRoot.Add(actor);
}
- AddModelTreeToAABB(AABB, mModelLoadTask->mLoadResult.mScene, mModelLoadTask->mResourceChoices, iRoot, nodeParams, Matrix::IDENTITY);
+ AddModelTreeToAABB(AABB, scene, resourceChoices, iRoot, nodeParams, Matrix::IDENTITY);
}
mNaturalSize = AABB.CalculateSize();
void Model::CreateAnimations(Dali::Scene3D::Loader::SceneDefinition& scene)
{
mAnimations.clear();
- if(!mModelLoadTask->mLoadResult.mAnimationDefinitions.empty())
+ if(!mModelLoadTask->GetAnimations().empty())
{
- auto getActor = [&](const Scene3D::Loader::AnimatedProperty& property) {
+ auto getActor = [&](const Scene3D::Loader::AnimatedProperty& property)
+ {
if(property.mNodeIndex == Scene3D::Loader::INVALID_INDEX)
{
return mModelRoot.FindChildByName(property.mNodeName);
return mModelRoot.FindChildById(node->mNodeId);
};
- for(auto&& animation : mModelLoadTask->mLoadResult.mAnimationDefinitions)
+ for(auto&& animation : mModelLoadTask->GetAnimations())
{
Dali::Animation anim = animation.ReAnimate(getActor);
mAnimations.push_back({animation.mName, anim});
void Model::ResetCameraParameters()
{
mCameraParameters.clear();
- if(!mModelLoadTask->mLoadResult.mCameraParameters.empty())
+ if(!mModelLoadTask->GetCameras().empty())
{
// Copy camera parameters.
- std::copy(mModelLoadTask->mLoadResult.mCameraParameters.begin(), mModelLoadTask->mLoadResult.mCameraParameters.end(), std::back_inserter(mCameraParameters));
+ std::copy(mModelLoadTask->GetCameras().begin(), mModelLoadTask->GetCameras().end(), std::back_inserter(mCameraParameters));
}
}
void ResetResourceTask(IntrusivePtr<AsyncTask> asyncTask);
/**
- * @brief Request to load a Ibl texture asynchronously
- */
- void RequestLoadIblTexture(EnvironmentMapLoadTaskPtr asyncLoadTask, const std::string& url);
-
- /**
* @brief Notify Resource Ready signal.
*/
void NotifyResourceReady();
${scene3d_internal_dir}/common/model-load-task.cpp
${scene3d_internal_dir}/controls/model/model-impl.cpp
${scene3d_internal_dir}/controls/scene-view/scene-view-impl.cpp
+ ${scene3d_internal_dir}/loader/dli-loader-impl.cpp
${scene3d_internal_dir}/loader/gltf2-asset.cpp
+ ${scene3d_internal_dir}/loader/gltf2-loader-impl.cpp
${scene3d_internal_dir}/loader/hash.cpp
${scene3d_internal_dir}/loader/json-reader.cpp
${scene3d_internal_dir}/loader/json-util.cpp
*/
// CLASS HEADER
-#include "dali-scene3d/public-api/loader/dli-loader.h"
+#include <dali-scene3d/internal/loader/dli-loader-impl.h>
// EXTERNAL INCLUDES
#include <algorithm>
#include <cmath>
+#include <filesystem>
#include <fstream>
#include <limits>
#include <memory>
#include "dali/public-api/object/property-array.h"
// INTERNAL INCLUDES
-#include "dali-scene3d/internal/loader/json-util.h"
-#include "dali-scene3d/public-api/loader/alpha-function-helper.h"
-#include "dali-scene3d/public-api/loader/animation-definition.h"
-#include "dali-scene3d/public-api/loader/blend-shape-details.h"
-#include "dali-scene3d/public-api/loader/camera-parameters.h"
-#include "dali-scene3d/public-api/loader/ktx-loader.h"
-#include "dali-scene3d/public-api/loader/light-parameters.h"
-#include "dali-scene3d/public-api/loader/load-result.h"
-#include "dali-scene3d/public-api/loader/parse-renderer-state.h"
-#include "dali-scene3d/public-api/loader/scene-definition.h"
-#include "dali-scene3d/public-api/loader/skinning-details.h"
-#include "dali-scene3d/public-api/loader/utils.h"
+#include <dali-scene3d/internal/loader/json-util.h>
+#include <dali-scene3d/public-api/loader/alpha-function-helper.h>
+#include <dali-scene3d/public-api/loader/animation-definition.h>
+#include <dali-scene3d/public-api/loader/blend-shape-details.h>
+#include <dali-scene3d/public-api/loader/camera-parameters.h>
+#include <dali-scene3d/public-api/loader/ktx-loader.h>
+#include <dali-scene3d/public-api/loader/light-parameters.h>
+#include <dali-scene3d/public-api/loader/load-result.h>
+#include <dali-scene3d/public-api/loader/parse-renderer-state.h>
+#include <dali-scene3d/public-api/loader/scene-definition.h>
+#include <dali-scene3d/public-api/loader/skinning-details.h>
+#include <dali-scene3d/public-api/loader/utils.h>
#define DLI_0_1_COMPATIBILITY
{
namespace Loader
{
+namespace Internal
+{
namespace rs = RendererState;
namespace
return ReadBlob(node, accessor.mBlob.mOffset, accessor.mBlob.mLength);
}
-bool ReadColorCode(const TreeNode* node, Vector4& color, DliLoader::ConvertColorCode convertColorCode)
+bool ReadColorCode(const TreeNode* node, Vector4& color, DliInputParameter::ConvertColorCode convertColorCode)
{
if(!node || !convertColorCode)
{
return true;
}
-bool ReadColorCodeOrColor(const TreeNode* node, Vector4& color, DliLoader::ConvertColorCode convertColorCode)
+bool ReadColorCodeOrColor(const TreeNode* node, Vector4& color, DliInputParameter::ConvertColorCode convertColorCode)
{
return ReadColorCode(node->GetChild("colorCode"), color, convertColorCode) ||
ReadColor(node->GetChild("color"), color);
} // namespace
-struct DliLoader::Impl
+struct DliLoaderImpl::Impl
{
StringCallback mOnError = DefaultErrorCallback;
Toolkit::JsonParser mParser;
*/
void ParseSceneInternal(Index iScene, const Toolkit::TreeNode* tnScenes, const Toolkit::TreeNode* tnNodes, LoadParams& params);
- void ParseSkeletons(const Toolkit::TreeNode* skeletons, SceneDefinition& scene, ResourceBundle& resources);
- void ParseEnvironments(const Toolkit::TreeNode* environments, ResourceBundle& resources);
- void ParseMaterials(const Toolkit::TreeNode* materials, ConvertColorCode convertColorCode, ResourceBundle& resources);
+ void ParseSkeletons(const Toolkit::TreeNode* skeletons, Dali::Scene3D::Loader::SceneDefinition& scene, Dali::Scene3D::Loader::ResourceBundle& resources);
+ void ParseEnvironments(const Toolkit::TreeNode* environments, Dali::Scene3D::Loader::ResourceBundle& resources);
+ void ParseMaterials(const Toolkit::TreeNode* materials, DliInputParameter::ConvertColorCode convertColorCode, Dali::Scene3D::Loader::ResourceBundle& resources);
void ParseNodes(const Toolkit::TreeNode* nodes, Index index, LoadParams& params);
void ParseNodesInternal(const Toolkit::TreeNode* nodes, Index index, std::vector<Index>& inOutParentStack, LoadParams& params, IIndexMapper& indexMapper);
void ParseAnimations(const Toolkit::TreeNode* animations, LoadParams& params);
void ParseAnimationGroups(const Toolkit::TreeNode* animationGroups, LoadParams& params);
- void ParseShaders(const Toolkit::TreeNode* shaders, ResourceBundle& resources);
- void ParseMeshes(const Toolkit::TreeNode* meshes, ResourceBundle& resources);
+ void ParseShaders(const Toolkit::TreeNode* shaders, Dali::Scene3D::Loader::ResourceBundle& resources);
+ void ParseMeshes(const Toolkit::TreeNode* meshes, Dali::Scene3D::Loader::ResourceBundle& resources);
- void GetCameraParameters(std::vector<CameraParameters>& cameras) const;
- void GetLightParameters(std::vector<LightParameters>& lights) const;
+ void GetCameraParameters(std::vector<Dali::Scene3D::Loader::CameraParameters>& cameras) const;
+ void GetLightParameters(std::vector<Dali::Scene3D::Loader::LightParameters>& lights) const;
};
-DliLoader::DliLoader()
+DliLoaderImpl::DliLoaderImpl()
: mImpl{new Impl}
{
}
-DliLoader::~DliLoader() = default;
+DliLoaderImpl::~DliLoaderImpl() = default;
-void DliLoader::SetErrorCallback(StringCallback onError)
+void DliLoaderImpl::SetErrorCallback(StringCallback onError)
{
mImpl->mOnError = onError;
}
-bool DliLoader::LoadScene(const std::string& uri, LoadParams& params)
+bool DliLoaderImpl::LoadModel(const std::string& uri, Dali::Scene3D::Loader::LoadResult& result)
{
std::string daliBuffer = LoadTextFile(uri.c_str());
return false;
}
- mImpl->ParseScene(params);
+ std::filesystem::path modelPath(uri);
+ Dali::Scene3D::Loader::DliInputParameter input;
+ LoadParams loadParams;
+ if(mInputParameter)
+ {
+ loadParams.input = static_cast<DliInputParameter*>(mInputParameter);
+ }
+ else
+ {
+ input.mAnimationsPath = std::string(modelPath.parent_path()) + "/";
+ loadParams.input = &input;
+ }
+ loadParams.output = &result;
+
+ mImpl->ParseScene(loadParams);
return true;
}
-std::string DliLoader::GetParseError() const
+std::string DliLoaderImpl::GetParseError() const
{
std::stringstream stream;
return stream.str();
}
-void DliLoader::Impl::ParseScene(LoadParams& params)
+void DliLoaderImpl::Impl::ParseScene(LoadParams& params)
{
- auto& input = params.input;
- auto& output = params.output;
+ auto& input = *params.input;
+ auto& output = *params.output;
// get index of root node.
auto docRoot = mParser.GetRoot();
}
}
-void DliLoader::Impl::ParseSceneInternal(Index iScene, const Toolkit::TreeNode* tnScenes, const Toolkit::TreeNode* tnNodes, LoadParams& params)
+void DliLoaderImpl::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)
{
Index iRootNode = getSceneRootIdx(iScene);
ParseNodes(tnNodes, iRootNode, params);
- auto& scene = params.output.mScene;
+ auto& scene = params.output->mScene;
scene.AddRootNode(0);
for(Index i = 0; i < iScene; ++i)
}
}
-void DliLoader::Impl::ParseSkeletons(const TreeNode* skeletons, SceneDefinition& scene, ResourceBundle& resources)
+void DliLoaderImpl::Impl::ParseSkeletons(const TreeNode* skeletons, Dali::Scene3D::Loader::SceneDefinition& scene, Dali::Scene3D::Loader::ResourceBundle& resources)
{
if(skeletons)
{
uint32_t jointCount = 0;
std::function<void(Index)> visitFn;
auto& ibms = mInverseBindMatrices;
- visitFn = [&](Index id) {
+ visitFn = [&](Index id)
+ {
auto node = scene.GetNode(id);
jointCount += ibms.find(id) != ibms.end();
skeleton.mJoints.reserve(jointCount);
- visitFn = [&](Index id) {
+ visitFn = [&](Index id)
+ {
auto iFind = ibms.find(id);
if(iFind != ibms.end() && skeleton.mJoints.size() < Skinning::MAX_JOINTS)
{
}
}
-void DliLoader::Impl::ParseEnvironments(const TreeNode* environments, ResourceBundle& resources)
+void DliLoaderImpl::Impl::ParseEnvironments(const TreeNode* environments, Dali::Scene3D::Loader::ResourceBundle& resources)
{
Matrix cubeOrientation(Matrix::IDENTITY);
}
}
-void DliLoader::Impl::ParseShaders(const TreeNode* shaders, ResourceBundle& resources)
+void DliLoaderImpl::Impl::ParseShaders(const TreeNode* shaders, Dali::Scene3D::Loader::ResourceBundle& resources)
{
uint32_t iShader = 0;
for(auto i0 = shaders->CBegin(), i1 = shaders->CEnd(); i0 != i1; ++i0, ++iShader)
}
}
-void DliLoader::Impl::ParseMeshes(const TreeNode* meshes, ResourceBundle& resources)
+void DliLoaderImpl::Impl::ParseMeshes(const TreeNode* meshes, Dali::Scene3D::Loader::ResourceBundle& resources)
{
for(auto i0 = meshes->CBegin(), i1 = meshes->CEnd(); i0 != i1; ++i0)
{
}
}
-void DliLoader::Impl::ParseMaterials(const TreeNode* materials, ConvertColorCode convertColorCode, ResourceBundle& resources)
+void DliLoaderImpl::Impl::ParseMaterials(const TreeNode* materials, DliInputParameter::ConvertColorCode convertColorCode, Dali::Scene3D::Loader::ResourceBundle& resources)
{
for(auto i0 = materials->CBegin(), i1 = materials->CEnd(); i0 != i1; ++i0)
{
}
}
-void DliLoader::Impl::ParseNodes(const TreeNode* const nodes, Index index, LoadParams& params)
+void DliLoaderImpl::Impl::ParseNodes(const TreeNode* const nodes, Index index, LoadParams& params)
{
std::vector<Index> parents;
parents.reserve(8);
virtual unsigned int Resolve(Index iDli) override
{
- auto iFind = std::lower_bound(mIndices.begin(), mIndices.end(), iDli, [](const Entry& idx, Index iDli) { return idx.iDli < iDli; });
+ auto iFind = std::lower_bound(mIndices.begin(), mIndices.end(), iDli, [](const Entry& idx, Index iDli)
+ { return idx.iDli < iDli; });
DALI_ASSERT_ALWAYS(iFind != mIndices.end());
return iFind->iScene;
}
} mapper(nodes->Size());
ParseNodesInternal(nodes, index, parents, params, mapper);
- auto& scene = params.output.mScene;
+ auto& scene = params.output->mScene;
for(size_t i0 = 0, i1 = scene.GetNodeCount(); i0 < i1; ++i0)
{
for(auto& c : scene.GetNode(i0)->mConstraints)
}
}
-void DliLoader::Impl::ParseNodesInternal(const TreeNode* const nodes, Index index, std::vector<Index>& inOutParentStack, LoadParams& params, IIndexMapper& mapper)
+void DliLoaderImpl::Impl::ParseNodesInternal(const TreeNode* const nodes, Index index, std::vector<Index>& inOutParentStack, LoadParams& params, IIndexMapper& mapper)
{
// Properties that may be resolved from a JSON value with ReadInt() -- or default to 0.
struct IndexProperty
if(auto node = GetNthChild(nodes, index))
{
- NodeDefinition nodeDef;
+ Dali::Scene3D::Loader::NodeDefinition nodeDef;
nodeDef.mParentIdx = inOutParentStack.empty() ? INVALID_INDEX : inOutParentStack.back();
// name
std::string tag;
if(ReadString(eCustomization->GetChild("tag"), tag))
{
- nodeDef.mCustomization.reset(new NodeDefinition::CustomizationDefinition{tag});
+ nodeDef.mCustomization.reset(new Dali::Scene3D::Loader::NodeDefinition::CustomizationDefinition{tag});
}
}
else // something renderable maybe
{
- std::unique_ptr<NodeDefinition::Renderable> renderable;
- ModelRenderable* modelRenderable = nullptr; // no ownership, aliasing renderable for the right type.
+ std::unique_ptr<Dali::Scene3D::Loader::NodeDefinition::Renderable> renderable;
+ ModelRenderable* modelRenderable = nullptr; // no ownership, aliasing renderable for the right type.
const TreeNode* eRenderable = nullptr;
if((eRenderable = node->GetChild("model")))
resourceIds.push_back({ResourceType::Material, eMaterial, modelRenderable->mMaterialIdx});
}
- if(!ReadColorCodeOrColor(eRenderable, modelRenderable->mColor, params.input.mConvertColorCode))
+ if(!ReadColorCodeOrColor(eRenderable, modelRenderable->mColor, params.input->mConvertColorCode))
{
- ReadColorCodeOrColor(node, modelRenderable->mColor, params.input.mConvertColorCode);
+ ReadColorCodeOrColor(node, modelRenderable->mColor, params.input->mConvertColorCode);
}
}
switch(idRes.type)
{
case ResourceType::Shader:
- iCheck = output.mResources.mShaders.size();
+ iCheck = output->mResources.mShaders.size();
break;
case ResourceType::Mesh:
- iCheck = output.mResources.mMeshes.size();
+ iCheck = output->mResources.mMeshes.size();
break;
case ResourceType::Material:
- iCheck = output.mResources.mMaterials.size();
+ iCheck = output->mResources.mMaterials.size();
break;
default:
for(auto i0 = eExtras->CBegin(), i1 = eExtras->CEnd(); i0 != i1; ++i0)
{
- NodeDefinition::Extra e;
+ Dali::Scene3D::Loader::NodeDefinition::Extra e;
auto eExtra = *i0;
e.mKey = eExtra.first;
}
// Determine index for mapping
- const unsigned int myIndex = output.mScene.GetNodeCount();
+ const unsigned int myIndex = output->mScene.GetNodeCount();
if(!mapper.Map(index, myIndex))
{
mOnError(FormatString("node %d: error mapping dli index %d: node has multiple parents. Ignoring subtree.", index, myIndex));
}
// Register nodeDef
- auto rawDef = output.mScene.AddNode(std::make_unique<NodeDefinition>(std::move(nodeDef)));
+ auto rawDef = output->mScene.AddNode(std::make_unique<Dali::Scene3D::Loader::NodeDefinition>(std::move(nodeDef)));
if(rawDef) // NOTE: no ownership. Guaranteed to stay in scope.
{
// ...And only then parse children.
mOnError(FormatString("node %d: not an actual customization without children.", index));
}
- if(auto proc = params.input.mNodePropertyProcessor) // optional processing
+ if(auto proc = params.input->mNodePropertyProcessor) // optional processing
{
// WARNING: constraint IDs are not resolved at this point.
Property::Map nodeData;
}
}
-void DliLoader::Impl::ParseAnimations(const TreeNode* tnAnimations, LoadParams& params)
+void DliLoaderImpl::Impl::ParseAnimations(const TreeNode* tnAnimations, LoadParams& params)
{
- auto& definitions = params.output.mAnimationDefinitions;
+ auto& definitions = params.output->mAnimationDefinitions;
definitions.reserve(definitions.size() + tnAnimations->Size());
for(TreeNode::ConstIterator iAnim = tnAnimations->CBegin(), iAnimEnd = tnAnimations->CEnd();
AnimationDefinition animDef;
ReadString(tnAnim.GetChild(NAME), animDef.mName);
- auto iFind = std::lower_bound(definitions.begin(), definitions.end(), animDef, [](const AnimationDefinition& ad0, const AnimationDefinition& ad1) { return ad0.mName < ad1.mName; });
+ auto iFind = std::lower_bound(definitions.begin(), definitions.end(), animDef, [](const AnimationDefinition& ad0, const AnimationDefinition& ad1)
+ { return ad0.mName < ad1.mName; });
const bool overwrite = iFind != definitions.end() && iFind->mName == animDef.mName;
if(overwrite)
{
std::string animationFilename;
if(ReadString(tnKeyFramesBin->GetChild(URL), animationFilename))
{
- std::string animationFullPath = params.input.mAnimationsPath + animationFilename;
+ std::string animationFullPath = params.input->mAnimationsPath + animationFilename;
binAniFile.open(animationFullPath, std::ios::binary);
if(binAniFile.fail())
{
iFind = definitions.insert(iFind, std::move(animDef));
}
- if(auto proc = params.input.mAnimationPropertyProcessor) // optional processing
+ if(auto proc = params.input->mAnimationPropertyProcessor) // optional processing
{
Property::Map map;
ParseProperties(tnAnim, map);
}
}
-void DliLoader::Impl::ParseAnimationGroups(const Toolkit::TreeNode* tnAnimationGroups, LoadParams& params)
+void DliLoaderImpl::Impl::ParseAnimationGroups(const Toolkit::TreeNode* tnAnimationGroups, LoadParams& params)
{
- auto& animGroups = params.output.mAnimationGroupDefinitions;
+ auto& animGroups = params.output->mAnimationGroupDefinitions;
int numGroups = 0;
for(auto iGroups = tnAnimationGroups->CBegin(), iGroupsEnd = tnAnimationGroups->CEnd();
continue;
}
- auto iFind = std::lower_bound(animGroups.begin(), animGroups.end(), groupName, [](const AnimationGroupDefinition& group, const std::string& name) { return group.mName < name; });
+ auto iFind = std::lower_bound(animGroups.begin(), animGroups.end(), groupName, [](const AnimationGroupDefinition& group, const std::string& name)
+ { return group.mName < name; });
if(iFind != animGroups.end() && iFind->mName == groupName)
{
mOnError(FormatString("Animation group with name '%s' already exists; new entries will be merged.", groupName.c_str()));
}
}
-void DliLoader::Impl::GetCameraParameters(std::vector<CameraParameters>& cameras) const
+void DliLoaderImpl::Impl::GetCameraParameters(std::vector<Dali::Scene3D::Loader::CameraParameters>& cameras) const
{
if(mParser.GetRoot())
{
}
}
-void DliLoader::Impl::GetLightParameters(std::vector<LightParameters>& lights) const
+void DliLoaderImpl::Impl::GetLightParameters(std::vector<Dali::Scene3D::Loader::LightParameters>& lights) const
{
if(mParser.GetRoot())
{
}
}
+} // namespace Internal
} // namespace Loader
} // namespace Scene3D
} // namespace Dali
--- /dev/null
+#ifndef DALI_SCENE3D_LOADER_DLI_LOADER_IMPL_H
+#define DALI_SCENE3D_LOADER_DLI_LOADER_IMPL_H
+/*
+ * 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.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali-scene3d/internal/loader/model-loader-impl.h>
+#include <dali-scene3d/public-api/api.h>
+#include <dali-scene3d/public-api/loader/animation-definition.h>
+#include <dali-scene3d/public-api/loader/customization.h>
+#include <dali-scene3d/public-api/loader/dli-input-parameter.h>
+#include <dali-scene3d/public-api/loader/index.h>
+#include <dali-scene3d/public-api/loader/node-definition.h>
+#include <dali-scene3d/public-api/loader/string-callback.h>
+
+// EXTERNAL INCLUDES
+#include "dali/public-api/common/vector-wrapper.h"
+
+namespace Dali
+{
+namespace Scene3D
+{
+namespace Loader
+{
+namespace Internal
+{
+typedef std::pair<std::string, std::string> Metadata;
+
+// Forward declarations
+struct LoadResult;
+
+class DliLoaderImpl : public ModelLoaderImpl
+{
+public:
+ struct LoadParams
+ {
+ Dali::Scene3D::Loader::DliInputParameter* input;
+ Dali::Scene3D::Loader::LoadResult* output;
+ };
+
+ DliLoaderImpl();
+ ~DliLoaderImpl();
+
+ /**
+ * @brief Sets the callback that messages from non-fatal errors get posted to.
+ * Uses DefaultErrorCallback by default.
+ */
+ void SetErrorCallback(StringCallback onError);
+
+ /**
+ * @copydoc Dali::Scene3D::Loader::Internal::ModelLoaderImpl()
+ */
+ bool LoadModel(const std::string& uri, Dali::Scene3D::Loader::LoadResult& result) override;
+
+ /**
+ * @return The error string describing how the parse has failed, if any.
+ */
+ std::string GetParseError() const;
+
+private:
+ struct Impl;
+ const std::unique_ptr<Impl> mImpl;
+};
+
+} // namespace Internal
+} // namespace Loader
+} // namespace Scene3D
+} // namespace Dali
+
+#endif // DALI_SCENE3D_LOADER_DLI_LOADER_IMPL_H
*/
// FILE HEADER
-#include <dali-scene3d/public-api/loader/gltf2-loader.h>
+#include <dali-scene3d/internal/loader/gltf2-loader-impl.h>
// EXTERNAL INCLUDES
-#include <dali/devel-api/threading/mutex.h>
#include <dali/integration-api/debug.h>
#include <dali/public-api/images/image-operations.h>
#include <dali/public-api/math/quaternion.h>
{
namespace Loader
{
+namespace Internal
+{
namespace
{
-Dali::Mutex gInitializeMutex;
-Dali::Mutex gReadMutex;
const std::string POSITION_PROPERTY("position");
const std::string ORIENTATION_PROPERTY("orientation");
class NodeIndexMapper
{
public:
- NodeIndexMapper() = default;
- NodeIndexMapper(const NodeIndexMapper&) = delete;
+ NodeIndexMapper() = default;
+ NodeIndexMapper(const NodeIndexMapper&) = delete;
NodeIndexMapper& operator=(const NodeIndexMapper&) = delete;
///@brief Registers a mapping of the @a gltfIdx of a node to its @a runtimeIdx .
void ConvertMaterial(const gt::Material& material, const std::unordered_map<std::string, ImageMetadata>& imageMetaData, decltype(ResourceBundle::mMaterials)& outMaterials, ConversionContext& context)
{
- auto getTextureMetaData = [](const std::unordered_map<std::string, ImageMetadata>& metaData, const gt::TextureInfo& info) {
+ auto getTextureMetaData = [](const std::unordered_map<std::string, ImageMetadata>& metaData, const gt::TextureInfo& info)
+ {
if(!info.mTexture->mSource->mUri.empty())
{
if(auto search = metaData.find(info.mTexture->mSource->mUri.data()); search != metaData.end())
auto& resources = output.mResources;
const auto idx = scene.GetNodeCount();
- auto weakNode = scene.AddNode([&]() {
+ auto weakNode = scene.AddNode([&]()
+ {
std::unique_ptr<NodeDefinition> nodeDef{new NodeDefinition()};
nodeDef->mParentIdx = parentIdx;
}
}
- return nodeDef;
- }());
+ return nodeDef; }());
if(!weakNode)
{
ExceptionFlinger(ASSERT_LOCATION) << "Node name '" << node.mName << "' is not unique; scene is invalid.";
} // namespace
-void InitializeGltfLoader()
+void Gltf2LoaderImpl::InitializeGltfLoader()
{
+ static Dali::Mutex mInitializeMutex;
// Set ObjectReader only once (for all gltf loading).
static bool setObjectReadersRequired = true;
{
- Mutex::ScopedLock lock(gInitializeMutex);
+ Mutex::ScopedLock lock(mInitializeMutex);
if(setObjectReadersRequired)
{
// NOTE: only referencing own, anonymous namespace, const objects; the pointers will never need to change.
}
}
-void LoadGltfScene(const std::string& url, ShaderDefinitionFactory& shaderFactory, LoadResult& params)
+bool Gltf2LoaderImpl::LoadModel(const std::string& url, Dali::Scene3D::Loader::LoadResult& result)
{
bool failed = false;
auto js = LoadTextFile(url.c_str(), &failed);
if(failed)
{
- throw std::runtime_error("Failed to load " + url);
+ DALI_LOG_ERROR("Failed to load %s\n", url.c_str());
+ return false;
}
json::unique_ptr root(json_parse(js.c_str(), js.size()));
if(!root)
{
- throw std::runtime_error("Failed to parse " + url);
+ DALI_LOG_ERROR("Failed to parse %s\n", url.c_str());
+ return false;
}
gt::Document doc;
+ Dali::Scene3D::Loader::ShaderDefinitionFactory shaderFactory;
+ shaderFactory.SetResources(result.mResources);
+
auto& rootObj = js::Cast<json_object_s>(*root);
auto jsAsset = js::FindObjectChild("asset", rootObj);
isMRendererModel = (doc.mAsset.mGenerator.find(MRENDERER_MODEL_IDENTIFICATION) != std::string_view::npos);
}
+ InitializeGltfLoader();
{
- Mutex::ScopedLock lock(gReadMutex);
+ static Dali::Mutex mReadMutex;
+ Mutex::ScopedLock lock(mReadMutex);
gt::SetRefReaderObject(doc);
DOCUMENT_READER.Read(rootObj, doc);
}
auto path = url.substr(0, url.rfind('/') + 1);
- ConversionContext context{params, path, INVALID_INDEX};
+ ConversionContext context{result, path, INVALID_INDEX};
ConvertBuffers(doc, context);
ConvertMaterials(doc, context);
ConvertNodes(doc, context, isMRendererModel);
ConvertAnimations(doc, context);
ProcessSkins(doc, context);
- ProduceShaders(shaderFactory, params.mScene);
- params.mScene.EnsureUniqueSkinningShaderInstances(params.mResources);
+ ProduceShaders(shaderFactory, result.mScene);
+ result.mScene.EnsureUniqueSkinningShaderInstances(result.mResources);
// Set Default Environment map
SetDefaultEnvironmentMap(doc, context);
+
+ return true;
}
+} // namespace Internal
} // namespace Loader
} // namespace Scene3D
} // namespace Dali
--- /dev/null
+#ifndef DALI_SCENE3D_LOADER_GLTF2_LOADER_IMPL_H
+#define DALI_SCENE3D_LOADER_GLTF2_LOADER_IMPL_H
+/*
+ * 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.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali-scene3d/internal/loader/model-loader-impl.h>
+#include <dali-scene3d/public-api/api.h>
+
+// EXTERNAL INCLUDES
+#include <dali/devel-api/threading/mutex.h>
+#include <string>
+
+namespace Dali
+{
+namespace Scene3D
+{
+namespace Loader
+{
+namespace Internal
+{
+
+class Gltf2LoaderImpl : public ModelLoaderImpl
+{
+public:
+
+ /**
+ * @copydoc Dali::Scene3D::Loader::Internal::ModelLoaderImpl()
+ */
+ bool LoadModel(const std::string& url, Dali::Scene3D::Loader::LoadResult& result) override;
+
+private:
+ /**
+ * @brief Initialize glTF Loader.
+ * @note This method should be called once before LoadGltfScene() is called.
+ */
+ void InitializeGltfLoader();
+};
+
+} // namespace Internal
+} // namespace Loader
+} // namespace Scene3D
+} // namespace Dali
+
+#endif // DALI_SCENE3D_LOADER_GLTF2_LOADER_IMPL_H
--- /dev/null
+#ifndef DALI_SCENE3D_LOADER_MODEL_LOADER_IMPL_H
+#define DALI_SCENE3D_LOADER_MODEL_LOADER_IMPL_H
+/*
+ * 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.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali-scene3d/public-api/api.h>
+#include <dali-scene3d/public-api/loader/load-result.h>
+#include <dali-scene3d/public-api/loader/model-loader.h>
+#include <dali-scene3d/public-api/loader/resource-bundle.h>
+
+// EXTERNAL INCLUDES
+#include <string>
+
+namespace Dali
+{
+namespace Scene3D
+{
+namespace Loader
+{
+namespace Internal
+{
+class ModelLoaderImpl
+{
+public:
+ ModelLoaderImpl() = default;
+
+ /**
+ * @brief Set InputParameter.
+ * Thie method store only a pointer of InputParameter.
+ * The object of InputParameter should not be deleted until it is no longer used.
+ * @param[in] inputParameter Input parameters those can be used for model loading.
+ */
+ void SetInputParameter(Dali::Scene3D::Loader::ModelLoader::InputParameter& inputParameter)
+ {
+ mInputParameter = &inputParameter;
+ }
+
+ /**
+ * @brief Request to load model from url.
+ * @param[in] url model file url.
+ * @param[out] result loaded model data.
+ * @return True if model loading is successfully finished.
+ */
+ virtual bool LoadModel(const std::string& url, Dali::Scene3D::Loader::LoadResult& result) = 0;
+
+protected:
+ Dali::Scene3D::Loader::ModelLoader::InputParameter* mInputParameter{nullptr};
+};
+} // namespace Internal
+} // namespace Loader
+} // namespace Scene3D
+} // namespace Dali
+
+#endif // DALI_SCENE3D_LOADER_MODEL_LOADER_IMPL_H
${scene3d_public_api_dir}/loader/environment-map-data.cpp
${scene3d_public_api_dir}/loader/environment-map-loader.cpp
${scene3d_public_api_dir}/loader/customization.cpp
- ${scene3d_public_api_dir}/loader/dli-loader.cpp
${scene3d_public_api_dir}/loader/environment-definition.cpp
${scene3d_public_api_dir}/loader/facial-animation-loader.cpp
- ${scene3d_public_api_dir}/loader/gltf2-loader.cpp
${scene3d_public_api_dir}/loader/ktx-loader.cpp
${scene3d_public_api_dir}/loader/load-scene-metadata.cpp
${scene3d_public_api_dir}/loader/material-definition.cpp
${scene3d_public_api_dir}/loader/matrix-stack.cpp
${scene3d_public_api_dir}/loader/mesh-definition.cpp
+ ${scene3d_public_api_dir}/loader/model-loader.cpp
${scene3d_public_api_dir}/loader/node-definition.cpp
${scene3d_public_api_dir}/loader/parse-renderer-state.cpp
${scene3d_public_api_dir}/loader/renderer-state.cpp
--- /dev/null
+#ifndef DALI_SCENE3D_LOADER_DLI_INPUT_PARAMETER_H
+#define DALI_SCENE3D_LOADER_DLI_INPUT_PARAMETER_H
+/*
+ * 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.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali-scene3d/public-api/api.h>
+#include <dali-scene3d/public-api/loader/model-loader.h>
+
+// EXTERNAL INCLUDES
+#include <string>
+
+namespace Dali
+{
+namespace Scene3D
+{
+namespace Loader
+{
+
+class DliInputParameter : public ModelLoader::InputParameter
+{
+public:
+ using ConvertFontCode = void (*)(const std::string& code, std::string& fontFamily, std::string& slant, std::string& weight, float& size);
+ using ConvertColorCode = Vector4 (*)(const std::string& code);
+ using CategoryProcessor = std::function<void(Property::Array&& categoryData, StringCallback onError)>;
+ using CategoryProcessorVector = std::vector<std::pair<std::string /*name*/, CategoryProcessor>>;
+ using NodeProcessor = std::function<void(const Dali::Scene3D::Loader::NodeDefinition& nodeDef,
+ Property::Map&& nodeData,
+ StringCallback onError)>;
+ using AnimationProcessor = std::function<void(const AnimationDefinition& animDef,
+ Property::Map&& animData,
+ StringCallback onError)>;
+
+public:
+ /**
+ * @brief The absolute path of animation binaries referenced in the .dli.
+ */
+ std::string mAnimationsPath;
+
+ /**
+ * @brief Provides a facility to determine a color from a code instead of RGB(A) values.
+ */
+ ConvertColorCode mConvertColorCode{nullptr};
+
+ /**
+ * @brief A collection of handlers, mapped to the names of the top level (i.e. below
+ * root) element, whom they will attempt to process. This will take place before
+ * the parsing of scene Nodes and Animations, but after skeletons, environment, mesh,
+ * shader and material resources.
+ */
+ CategoryProcessorVector mPreNodeCategoryProcessors;
+
+ /**
+ * @brief A collection of handlers, mapped to the names of the top level (i.e. below
+ * root) element, whom they will attempt to process. This will take place after
+ * the parsing of the scene Nodes and Animations.
+ */
+ CategoryProcessorVector mPostNodeCategoryProcessors;
+
+ /**
+ * @brief Provides an extension point to nodes. If provided, this function will be
+ * called with each JSON element and definition, of a scene node.
+ * @note Constraints rely on ID resolution (from .dli to scene definition), which
+ * takes place after the parsing of the nodes; therefore AT THIS POINT the node
+ * IDs seen in constraints will still be the .dli IDs - NOT to be relied on for
+ * indexing into mScene.
+ */
+ NodeProcessor mNodePropertyProcessor{nullptr};
+
+ /**
+ * @brief Provides an extension point to animations. If provided, this function will be
+ * called with each JSON element and fully processed definition, of an animation.
+ */
+ AnimationProcessor mAnimationPropertyProcessor;
+};
+
+} // namespace Loader
+} // namespace Scene3D
+} // namespace Dali
+
+#endif // DALI_SCENE3D_LOADER_DLI_INPUT_PARAMETER_H
+++ /dev/null
-#ifndef DALI_SCENE3D_LOADER_DLI_LOADER_H
-#define DALI_SCENE3D_LOADER_DLI_LOADER_H
-/*
- * 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.
- * 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.
- *
- */
-
-// INTERNAL INCLUDES
-#include "dali-scene3d/public-api/api.h"
-#include "dali-scene3d/public-api/loader/animation-definition.h"
-#include "dali-scene3d/public-api/loader/customization.h"
-#include "dali-scene3d/public-api/loader/index.h"
-#include "dali-scene3d/public-api/loader/string-callback.h"
-
-// EXTERNAL INCLUDES
-#include "dali/public-api/common/vector-wrapper.h"
-
-namespace Dali
-{
-namespace Scene3D
-{
-namespace Loader
-{
-typedef std::pair<std::string, std::string> Metadata;
-
-// Forward declarations
-struct LoadResult;
-struct CameraParameters;
-struct LightParameters;
-struct TextParameters;
-
-class ResourceBundle;
-struct NodeDefinition;
-class SceneDefinition;
-
-class DALI_SCENE3D_API DliLoader
-{
-public:
- using ConvertFontCode = void (*)(const std::string& code, std::string& fontFamily, std::string& slant, std::string& weight, float& size);
- using ConvertColorCode = Vector4 (*)(const std::string& code);
-
- using CategoryProcessor = std::function<void(Property::Array&& categoryData, StringCallback onError)>;
- using CategoryProcessorVector = std::vector<std::pair<std::string /*name*/, CategoryProcessor>>;
-
- using NodeProcessor = std::function<void(const NodeDefinition& nodeDef,
- Property::Map&& nodeData,
- StringCallback onError)>;
-
- using AnimationProcessor = std::function<void(const AnimationDefinition& animDef,
- Property::Map&& animData,
- StringCallback onError)>;
-
- struct InputParams
- {
- /**
- * @brief The absolute path of animation binaries referenced in the .dli.
- */
- std::string mAnimationsPath;
-
- /**
- * @brief Provides a facility to determine a color from a code instead of RGB(A) values.
- */
- ConvertColorCode mConvertColorCode;
-
- /**
- * @brief A collection of handlers, mapped to the names of the top level (i.e. below
- * root) element, whom they will attempt to process. This will take place before
- * the parsing of scene Nodes and Animations, but after skeletons, environment, mesh,
- * shader and material resources.
- */
- CategoryProcessorVector mPreNodeCategoryProcessors;
-
- /**
- * @brief A collection of handlers, mapped to the names of the top level (i.e. below
- * root) element, whom they will attempt to process. This will take place after
- * the parsing of the scene Nodes and Animations.
- */
- CategoryProcessorVector mPostNodeCategoryProcessors;
-
- /**
- * @brief Provides an extension point to nodes. If provided, this function will be
- * called with each JSON element and definition, of a scene node.
- * @note Constraints rely on ID resolution (from .dli to scene definition), which
- * takes place after the parsing of the nodes; therefore AT THIS POINT the node
- * IDs seen in constraints will still be the .dli IDs - NOT to be relied on for
- * indexing into mScene.
- */
- NodeProcessor mNodePropertyProcessor;
-
- /**
- * @brief Provides an extension point to animations. If provided, this function will be
- * called with each JSON element and fully processed definition, of an animation.
- */
- AnimationProcessor mAnimationPropertyProcessor;
- };
-
- struct LoadParams
- {
- InputParams const& input;
- LoadResult& output;
- };
-
- DliLoader();
- ~DliLoader();
-
- /**
- * @brief Sets the callback that messages from non-fatal errors get posted to.
- * Uses DefaultErrorCallback by default.
- */
- void SetErrorCallback(StringCallback onError);
-
- /**
- * @brief Attempts to load and parse a .dli document into a DOM tree.
- * @return Whether the operation was successful.
- */
- bool LoadScene(const std::string& uri, LoadParams& params);
-
- /**
- * @return The error string describing how the parse has failed, if any.
- */
- std::string GetParseError() const;
-
-private:
- struct Impl;
- const std::unique_ptr<Impl> mImpl;
-};
-
-} // namespace Loader
-} // namespace Scene3D
-} // namespace Dali
-
-#endif // DALI_SCENE3D_LOADER_DLI_LOADER_H
+++ /dev/null
-#ifndef DALI_SCENE3D_LOADER_GLTF2_LOADER_H
-#define DALI_SCENE3D_LOADER_GLTF2_LOADER_H
-/*
- * 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.
- * 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.
- *
- */
-
-// INTERNAL INCLUDES
-#include "dali-scene3d/public-api/api.h"
-
-// EXTERNAL INCLUDES
-#include <string>
-
-namespace Dali
-{
-namespace Scene3D
-{
-namespace Loader
-{
-struct CameraParameters;
-struct LoadResult;
-class ShaderDefinitionFactory;
-
-/**
- * @brief Initialize glTF Loader.
- * @note This method should be called once before LoadGltfScene() is called.
- */
-DALI_SCENE3D_API void InitializeGltfLoader();
-
-/**
- * @brief Loads the scene from the glTF file located at @a url, storing the results in @a params.
- * @note Will throw std::runtime_error for JSON entities with types mismatching expectations, carrying
- * invalid values, or I/O errors.
- * @note InitializeGltfLoader() should be called once before this function is called.
- */
-DALI_SCENE3D_API void LoadGltfScene(const std::string& url, ShaderDefinitionFactory& shaderFactory, LoadResult& params);
-
-} // namespace Loader
-} // namespace Scene3D
-} // namespace Dali
-
-#endif //DALI_SCENE3D_LOADER_GLTF2_LOADER_H
--- /dev/null
+/*
+ * 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.
+ *
+ */
+
+// FILE HEADER
+#include <dali-scene3d/public-api/loader/model-loader.h>
+
+// EXTERNAL INCLUDES
+#include <dali/integration-api/debug.h>
+#include <filesystem>
+#include <memory>
+
+// INTERNAL INCLUDES
+#include <dali-scene3d/internal/loader/dli-loader-impl.h>
+#include <dali-scene3d/internal/loader/gltf2-loader-impl.h>
+#include <dali-scene3d/internal/loader/model-loader-impl.h>
+
+namespace Dali
+{
+namespace Scene3D
+{
+namespace Loader
+{
+namespace
+{
+static constexpr std::string_view OBJ_EXTENSION = ".obj";
+static constexpr std::string_view GLTF_EXTENSION = ".gltf";
+static constexpr std::string_view DLI_EXTENSION = ".dli";
+static constexpr std::string_view METADATA_EXTENSION = "metadata";
+} // namespace
+
+ModelLoader::ModelLoader(const std::string& modelUrl, const std::string& resourceDirectoryUrl, Dali::Scene3D::Loader::LoadResult& loadResult)
+: mModelUrl(modelUrl),
+ mResourceDirectoryUrl(resourceDirectoryUrl),
+ mLoadResult(loadResult)
+{
+ CreateModelLoader();
+}
+
+bool ModelLoader::LoadModel(Dali::Scene3D::Loader::ResourceBundle::PathProvider& pathProvider, bool loadOnlyRawResource)
+{
+ if(!mImpl)
+ {
+ return false;
+ }
+
+ bool loadSucceeded = false;
+
+ mLoadResult.mAnimationDefinitions.clear();
+ std::filesystem::path metaDataUrl(mModelUrl);
+ metaDataUrl.replace_extension(METADATA_EXTENSION.data());
+
+ Dali::Scene3D::Loader::LoadSceneMetadata(metaDataUrl.c_str(), mLoadResult.mSceneMetadata);
+ loadSucceeded = mImpl->LoadModel(mModelUrl, mLoadResult);
+ LoadResource(pathProvider, loadOnlyRawResource);
+
+ return loadSucceeded;
+}
+
+void ModelLoader::SetInputParameter(InputParameter& inputParameter)
+{
+ mImpl->SetInputParameter(inputParameter);
+}
+
+Dali::Scene3D::Loader::SceneDefinition& ModelLoader::GetScene()
+{
+ return mLoadResult.mScene;
+}
+
+Dali::Scene3D::Loader::ResourceBundle& ModelLoader::GetResources()
+{
+ return mLoadResult.mResources;
+}
+
+std::vector<Dali::Scene3D::Loader::AnimationDefinition>& ModelLoader::GetAnimations()
+{
+ return mLoadResult.mAnimationDefinitions;
+}
+
+std::vector<Dali::Scene3D::Loader::CameraParameters>& ModelLoader::GetCameras()
+{
+ return mLoadResult.mCameraParameters;
+}
+
+Dali::Scene3D::Loader::Customization::Choices& ModelLoader::GetResourceChoices()
+{
+ return mResourceChoices;
+}
+
+void ModelLoader::CreateModelLoader()
+{
+ std::filesystem::path modelPath(mModelUrl);
+ if(mResourceDirectoryUrl.empty())
+ {
+ mResourceDirectoryUrl = std::string(modelPath.parent_path()) + "/";
+ }
+ std::string extension = modelPath.extension();
+ std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
+
+ if(extension == DLI_EXTENSION)
+ {
+ mImpl = std::make_shared<Dali::Scene3D::Loader::Internal::DliLoaderImpl>();
+ }
+ else if(extension == GLTF_EXTENSION)
+ {
+ mImpl = std::make_shared<Dali::Scene3D::Loader::Internal::Gltf2LoaderImpl>();
+ }
+ else
+ {
+ DALI_LOG_ERROR("Not supported model format : %s\n", extension.c_str());
+ }
+}
+
+void ModelLoader::LoadResource(Dali::Scene3D::Loader::ResourceBundle::PathProvider& pathProvider, bool loadOnlyRawResource)
+{
+ if(GetResources().mRawResourcesLoaded && loadOnlyRawResource)
+ {
+ return;
+ }
+
+ Dali::Scene3D::Loader::ResourceRefCounts resourceRefCount = std::move(mLoadResult.mResources.CreateRefCounter());
+ for(auto iRoot : GetScene().GetRoots())
+ {
+ GetScene().CountResourceRefs(iRoot, mResourceChoices, resourceRefCount);
+ }
+
+ GetResources().mReferenceCounts = std::move(resourceRefCount);
+ GetResources().CountEnvironmentReferences();
+
+ if(loadOnlyRawResource)
+ {
+ GetResources().LoadRawResources(pathProvider);
+ }
+ else
+ {
+ GetResources().LoadResources(pathProvider);
+ }
+}
+
+} // namespace Loader
+} // namespace Scene3D
+} // namespace Dali
--- /dev/null
+#ifndef DALI_SCENE3D_LOADER_MODEL_LOADER_H
+#define DALI_SCENE3D_LOADER_MODEL_LOADER_H
+/*
+ * 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.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali-scene3d/public-api/api.h>
+#include <dali-scene3d/public-api/loader/load-result.h>
+#include <dali-scene3d/public-api/loader/scene-definition.h>
+
+// EXTERNAL INCLUDES
+#include <string>
+
+namespace Dali
+{
+namespace Scene3D
+{
+namespace Loader
+{
+namespace Internal
+{
+class ModelLoaderImpl;
+}
+
+class DALI_SCENE3D_API ModelLoader
+{
+public:
+ class InputParameter
+ {
+ };
+
+ /**
+ * @brief ModelLoader Constructor.
+ * @param[in] modelUrl Url of the model file to be loaded
+ * @param[in] resourceDirectoryUrl Url of directory that contains resources.
+ * @param[out] loadResult Loaded result that includes scene tree and resources.
+ */
+ ModelLoader(const std::string& modelUrl, const std::string& resourceDirectoryUrl, Dali::Scene3D::Loader::LoadResult& loadResult);
+
+ /**
+ * @brief Request to load model from model url.
+ * @param[in] pathProvider Path provider that defines resource paths.
+ * @param[in] loadOnlyRawResource If true, load Raw resource only, and do not create Dali::Handle
+ * If false, this loader load Raw resource and create Dali::Handle too.
+ * Default value is false;
+ * @return True if model loading is successfully finished.
+ */
+ bool LoadModel(Dali::Scene3D::Loader::ResourceBundle::PathProvider& pathProvider, bool loadOnlyRawResource = false);
+
+ /**
+ * @brief Set InputParameter.
+ * Thie method store only a pointer of InputParameter.
+ * The object of InputParameter should not be deleted until it is no longer used.
+ * @param[in] inputParameter Input parameters that can be used in loading time.
+ */
+ void SetInputParameter(InputParameter& inputParameter);
+
+ /**
+ * @brief Retrieves loaded scene
+ * @return SceneDefinition that is loaded from file
+ */
+ Dali::Scene3D::Loader::SceneDefinition& GetScene();
+
+ /**
+ * @brief Retrieves resource bundle that includes resource information
+ * @return ResourceBundle for model resources
+ */
+ Dali::Scene3D::Loader::ResourceBundle& GetResources();
+
+ /**
+ * @brief Retrieves loaded AnimationDefinition
+ * @return AnimationDefinition that is loaded from file
+ */
+ std::vector<Dali::Scene3D::Loader::AnimationDefinition>& GetAnimations();
+
+ /**
+ * @brief Retrieves loaded CameraParameters
+ * @return CameraParameters list that is loaded from file
+ */
+ std::vector<Dali::Scene3D::Loader::CameraParameters>& GetCameras();
+
+ /**
+ * @brief Retrieves ResourceChoices
+ * @return Choices for loaded Resources
+ */
+ Dali::Scene3D::Loader::Customization::Choices& GetResourceChoices();
+
+private:
+ /**
+ * @brief Create model loader for each file format.
+ */
+ void CreateModelLoader();
+
+ /**
+ * @brief Load resource of the model.
+ */
+ void LoadResource(Dali::Scene3D::Loader::ResourceBundle::PathProvider& pathProvider, bool loadOnlyRawResource);
+
+private:
+ std::string mModelUrl;
+ std::string mResourceDirectoryUrl;
+
+ Dali::Scene3D::Loader::LoadResult mLoadResult;
+ Dali::Scene3D::Loader::Customization::Choices mResourceChoices;
+
+ std::shared_ptr<Internal::ModelLoaderImpl> mImpl;
+};
+} // namespace Loader
+} // namespace Scene3D
+} // namespace Dali
+
+#endif // DALI_SCENE3D_LOADER_MODEL_LOADER_H
return refCounts;
}
-void ResourceBundle::CountEnvironmentReferences(ResourceRefCounts& refCounts) const
+void ResourceBundle::CountEnvironmentReferences()
{
- auto& environmentRefCounts = refCounts[ResourceType::Environment];
+ auto& environmentRefCounts = mReferenceCounts[ResourceType::Environment];
- const auto& materialRefs = refCounts[ResourceType::Material];
+ const auto& materialRefs = mReferenceCounts[ResourceType::Material];
for(uint32_t i = 0, iEnd = materialRefs.Size(); i != iEnd; ++i)
{
if(materialRefs[i] > 0)
}
}
-void ResourceBundle::LoadResources(const ResourceRefCounts& refCounts, PathProvider pathProvider, Options::Type options)
+void ResourceBundle::LoadResources(PathProvider pathProvider, Options::Type options)
{
mRawResourcesLoading = true;
mResourcesGenerating = true;
const auto kForceLoad = MaskMatch(options, Options::ForceReload);
const auto kKeepUnused = MaskMatch(options, Options::KeepUnused);
- const auto& refCountEnvMaps = refCounts[ResourceType::Environment];
+ const auto& refCountEnvMaps = mReferenceCounts[ResourceType::Environment];
auto environmentsPath = pathProvider(ResourceType::Environment);
for(uint32_t i = 0, iEnd = refCountEnvMaps.Size(); i != iEnd; ++i)
{
}
}
- const auto& refCountShaders = refCounts[ResourceType::Shader];
+ const auto& refCountShaders = mReferenceCounts[ResourceType::Shader];
auto shadersPath = pathProvider(ResourceType::Shader);
for(uint32_t i = 0, iEnd = refCountShaders.Size(); i != iEnd; ++i)
{
}
}
- const auto& refCountMeshes = refCounts[ResourceType::Mesh];
+ const auto& refCountMeshes = mReferenceCounts[ResourceType::Mesh];
auto modelsPath = pathProvider(ResourceType::Mesh);
for(uint32_t i = 0, iEnd = refCountMeshes.Size(); i != iEnd; ++i)
{
}
}
- const auto& refCountMaterials = refCounts[ResourceType::Material];
+ const auto& refCountMaterials = mReferenceCounts[ResourceType::Material];
auto imagesPath = pathProvider(ResourceType::Material);
for(uint32_t i = 0, iEnd = refCountMaterials.Size(); i != iEnd; ++i)
{
mResourcesGenerated = true;
}
-void ResourceBundle::LoadRawResources(const ResourceRefCounts& refCounts, PathProvider pathProvider, Options::Type options)
+void ResourceBundle::LoadRawResources(PathProvider pathProvider, Options::Type options)
{
const auto kForceLoad = MaskMatch(options, Options::ForceReload);
{
mRawResourcesLoading = true;
- const auto& refCountEnvMaps = refCounts[ResourceType::Environment];
+ const auto& refCountEnvMaps = mReferenceCounts[ResourceType::Environment];
auto environmentsPath = pathProvider(ResourceType::Environment);
for(uint32_t i = 0, iEnd = refCountEnvMaps.Size(); i != iEnd; ++i)
{
}
}
- const auto& refCountShaders = refCounts[ResourceType::Shader];
+ const auto& refCountShaders = mReferenceCounts[ResourceType::Shader];
auto shadersPath = pathProvider(ResourceType::Shader);
for(uint32_t i = 0, iEnd = refCountShaders.Size(); i != iEnd; ++i)
{
}
}
- const auto& refCountMeshes = refCounts[ResourceType::Mesh];
+ const auto& refCountMeshes = mReferenceCounts[ResourceType::Mesh];
auto modelsPath = pathProvider(ResourceType::Mesh);
for(uint32_t i = 0, iEnd = refCountMeshes.Size(); i != iEnd; ++i)
{
}
}
- const auto& refCountMaterials = refCounts[ResourceType::Material];
+ const auto& refCountMaterials = mReferenceCounts[ResourceType::Material];
auto imagesPath = pathProvider(ResourceType::Material);
for(uint32_t i = 0, iEnd = refCountMaterials.Size(); i != iEnd; ++i)
{
}
}
-void ResourceBundle::GenerateResources(const ResourceRefCounts& refCounts, Options::Type options)
+void ResourceBundle::GenerateResources(Options::Type options)
{
const auto kForceLoad = MaskMatch(options, Options::ForceReload);
{
mResourcesGenerating = true;
- const auto& refCountEnvMaps = refCounts[ResourceType::Environment];
+ const auto& refCountEnvMaps = mReferenceCounts[ResourceType::Environment];
for(uint32_t i = 0, iEnd = refCountEnvMaps.Size(); i != iEnd; ++i)
{
auto refCount = refCountEnvMaps[i];
}
}
- const auto& refCountShaders = refCounts[ResourceType::Shader];
+ const auto& refCountShaders = mReferenceCounts[ResourceType::Shader];
for(uint32_t i = 0, iEnd = refCountShaders.Size(); i != iEnd; ++i)
{
auto refCount = refCountShaders[i];
}
}
- const auto& refCountMeshes = refCounts[ResourceType::Mesh];
+ const auto& refCountMeshes = mReferenceCounts[ResourceType::Mesh];
for(uint32_t i = 0, iEnd = refCountMeshes.Size(); i != iEnd; ++i)
{
auto refCount = refCountMeshes[i];
}
}
- const auto& refCountMaterials = refCounts[ResourceType::Material];
+ const auto& refCountMaterials = mReferenceCounts[ResourceType::Material];
for(uint32_t i = 0, iEnd = refCountMaterials.Size(); i != iEnd; ++i)
{
auto refCount = refCountMaterials[i];
{
mResourcesGenerating = true;
- const auto& refCountShaders = refCounts[ResourceType::Shader];
+ const auto& refCountShaders = mReferenceCounts[ResourceType::Shader];
for(uint32_t i = 0, iEnd = refCountShaders.Size(); i != iEnd; ++i)
{
auto refCount = refCountShaders[i];
* count of materials therein, it will calculate the reference count of
* environment maps.
*/
- void CountEnvironmentReferences(ResourceRefCounts& refCounts) const;
+ void CountEnvironmentReferences();
/**
* @brief Performs the loading of all resources based on their respective
* loaded unless we already have a handle to them (OR the ForceReload option was specified).
* Any handles we have to resources that come in with a zero ref count will be reset,
* UNLESS the KeepUnused option was specified.
- * @param[in] refCounts Reference Count that denote how many the resource is used.
* @param[in] pathProvider path provider for resource data.
* @param[in] options Option to load resource
* @note This method creates DALi objects like Dali::Texture, Dali::Geometry, etc.
*/
- void LoadResources(const ResourceRefCounts& refCounts,
- PathProvider pathProvider,
- Options::Type options = Options::None);
+ void LoadResources(PathProvider pathProvider,
+ Options::Type options = Options::None);
/**
* @brief Loads of all resources based on their respective
* Any handles we have to resources that come in with a zero ref count will be reset,
* UNLESS the KeepUnused option was specified.
* @note This method don't create any of DALi objects.
- * @param[in] refCounts Reference Count that denote how many the resource is used.
* @param[in] pathProvider path provider for resource data.
* @param[in] options Option to load resource
* @note This method only loads raw data from resource file, and
* doesn't create any of DALi objects. GenerateResources() method is required to be called
* after this method to create DALi objects.
*/
- void LoadRawResources(const ResourceRefCounts& refCounts,
- PathProvider pathProvider,
- Options::Type options = Options::None);
+ void LoadRawResources(PathProvider pathProvider,
+ Options::Type options = Options::None);
/**
* @brief Generates DALi objects from already loaded Raw Resources.
- * @param[in] refCounts Reference Count that denote how many the resource is used.
* @param[in] options Option to load resource
* @note This method generates DALi objects from raw data that is already
* loaded by LoadRawResources method. Therefore, LoadRawResources should be called first
* before this method is called.
*/
- void GenerateResources(const ResourceRefCounts& refCounts,
- Options::Type options = Options::None);
+ void GenerateResources(Options::Type options = Options::None);
public: // DATA
+ ResourceRefCounts mReferenceCounts;
EnvironmentDefinition::Vector mEnvironmentMaps;
ShaderDefinition::Vector mShaders;
MeshDefinition::Vector mMeshes;