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-scene3d/internal/loader/gltf2-asset.h>
22 #include <dali-scene3d/public-api/loader/load-result.h>
23 #include <dali-scene3d/public-api/loader/resource-bundle.h>
24 #include <dali-scene3d/public-api/loader/scene-definition.h>
25 #include <dali-scene3d/public-api/loader/shader-definition-factory.h>
28 #include <dali/devel-api/threading/mutex.h>
29 #include <dali/integration-api/debug.h>
50 bool operator<(Index gltfIdx) const
52 return this->gltfIdx < gltfIdx;
59 NodeIndexMapper() = default;
60 NodeIndexMapper(const NodeIndexMapper&) = delete;
61 NodeIndexMapper& operator=(const NodeIndexMapper&) = delete;
63 ///@brief Registers a mapping of the @a gltfIdx of a node to its @a runtimeIdx .
64 ///@note If the indices are the same, the registration is omitted, in order to
65 /// save growing a vector.
66 void RegisterMapping(Index gltfIdx, Index runtimeIdx)
68 if(gltfIdx != runtimeIdx)
70 auto iInsert = std::lower_bound(mNodes.begin(), mNodes.end(), gltfIdx);
71 DALI_ASSERT_DEBUG(iInsert == mNodes.end() || iInsert->gltfIdx != gltfIdx);
72 mNodes.insert(iInsert, NodeMapping{gltfIdx, runtimeIdx});
76 ///@brief Retrieves the runtime index of a Node, mapped to the given @a gltfIdx.
77 Index GetRuntimeId(Index gltfIdx) const
79 auto iFind = std::lower_bound(mNodes.begin(), mNodes.end(), gltfIdx); // using custom operator<
80 return (iFind != mNodes.end() && iFind->gltfIdx == gltfIdx) ? iFind->runtimeIdx : gltfIdx;
84 std::vector<NodeMapping> mNodes;
87 struct ConversionContext
92 Index mDefaultMaterial;
94 std::vector<Index> mMeshIds;
95 NodeIndexMapper mNodeIndices;
98 void ConvertBuffers(const gt::Document& doc, ConversionContext& context);
100 void ConvertMaterials(const gt::Document& doc, ConversionContext& context);
102 void ConvertMeshes(const gt::Document& doc, ConversionContext& context);
104 void ConvertCamera(const gt::Camera& camera, CameraParameters& camParams);
106 void ConvertNodes(const gt::Document& doc, ConversionContext& context, bool isMRendererModel);
108 void ConvertAnimations(const gt::Document& doc, ConversionContext& context);
110 void ProcessSkins(const gt::Document& doc, ConversionContext& context);
112 void ProduceShaders(ShaderDefinitionFactory& shaderFactory, SceneDefinition& scene);
114 void SetDefaultEnvironmentMap(const gt::Document& doc, ConversionContext& context);
116 const std::string_view GetRendererModelIdentification();
118 void ReadDocument(const json_object_s& jsonObject, gt::Document& document);
120 void InitializeGltfLoader();
122 void ReadDocumentFromParsedData(const json_object_s& jsonObject, gltf2::Document& document);
124 bool GenerateDocument(json::unique_ptr& root, gt::Document& document, bool& isMRendererModel);
126 void ConvertGltfToContext(gt::Document& document, Gltf2Util::ConversionContext& context, bool isMRendererModel);
128 } // namespace Gltf2Util
130 } // namespace Internal
131 } // namespace Loader
132 } // namespace Scene3D
135 #endif // DALI_SCENE3D_LOADER_GLTF2_UTIL_H