1 #ifndef DALI_SCENE3D_LOADER_GLTF2_UTIL_H
2 #define DALI_SCENE3D_LOADER_GLTF2_UTIL_H
4 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include <dali/devel-api/threading/mutex.h>
22 #include <dali/public-api/common/dali-common.h>
25 #include <dali-scene3d/internal/loader/gltf2-asset.h>
26 #include <dali-scene3d/public-api/loader/load-result.h>
27 #include <dali-scene3d/public-api/loader/resource-bundle.h>
28 #include <dali-scene3d/public-api/loader/scene-definition.h>
29 #include <dali-scene3d/public-api/loader/shader-definition-factory.h>
34 namespace Dali::Scene3D::Loader::Internal
43 bool operator<(Index gltfIndex) const
45 return this->gltfIndex < gltfIndex;
52 NodeIndexMapper() = default;
53 NodeIndexMapper(const NodeIndexMapper&) = delete;
54 NodeIndexMapper& operator=(const NodeIndexMapper&) = delete;
56 ///@brief Registers a mapping of the @a gltfIndex of a node to its @a runtimeIndex .
57 ///@note If the indices are the same, the registration is omitted, in order to
58 /// save growing a vector.
59 void RegisterMapping(Index gltfIndex, Index runtimeIndex)
61 if(gltfIndex != runtimeIndex)
63 auto iInsert = std::lower_bound(mNodes.begin(), mNodes.end(), gltfIndex);
64 DALI_ASSERT_DEBUG(iInsert == mNodes.end() || iInsert->gltfIndex != gltfIndex);
65 mNodes.insert(iInsert, NodeMapping{gltfIndex, runtimeIndex});
69 ///@brief Retrieves the runtime index of a Node, mapped to the given @a gltfIndex.
70 Index GetRuntimeId(Index gltfIndex) const
72 auto iFind = std::lower_bound(mNodes.begin(), mNodes.end(), gltfIndex); // using custom operator<
73 return (iFind != mNodes.end() && iFind->gltfIndex == gltfIndex) ? iFind->runtimeIndex : gltfIndex;
77 std::vector<NodeMapping> mNodes;
80 struct ConversionContext
85 Index mDefaultMaterial;
87 std::vector<Index> mMeshIds;
88 NodeIndexMapper mNodeIndices;
91 void ConvertBuffers(const gt::Document& document, ConversionContext& context);
93 void ConvertMaterials(const gt::Document& document, ConversionContext& context);
95 void ConvertMeshes(const gt::Document& document, ConversionContext& context);
97 void ConvertCamera(const gt::Camera& camera, CameraParameters& cameraParameters);
99 void ConvertNodes(const gt::Document& document, ConversionContext& context, bool isMRendererModel);
101 void ConvertAnimations(const gt::Document& document, ConversionContext& context);
103 void ProcessSkins(const gt::Document& document, ConversionContext& context);
105 void ProduceShaders(ShaderDefinitionFactory& shaderFactory, SceneDefinition& scene);
107 void SetDefaultEnvironmentMap(const gt::Document& document, ConversionContext& context);
109 const std::string_view GetRendererModelIdentification();
111 void ReadDocument(const json_object_s& jsonObject, gt::Document& document);
113 void InitializeGltfLoader();
115 void ReadDocumentFromParsedData(const json_object_s& jsonObject, gltf2::Document& document);
117 bool GenerateDocument(json::unique_ptr& root, gt::Document& document, bool& isMRendererModel);
119 void ConvertGltfToContext(gt::Document& document, Gltf2Util::ConversionContext& context, bool isMRendererModel);
121 } // namespace Gltf2Util
123 } // namespace Dali::Scene3D::Loader::Internal
125 #endif // DALI_SCENE3D_LOADER_GLTF2_UTIL_H