2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-scene3d/internal/loader/gltf2-util.h>
22 #include <dali/devel-api/threading/mutex.h>
23 #include <dali/integration-api/debug.h>
24 #include <limits> ///< for std::numeric_limits
26 using namespace Dali::Scene3D::Loader;
28 namespace Dali::Scene3D::Loader::Internal
32 static constexpr std::string_view MRENDERER_MODEL_IDENTIFICATION = "M-Renderer";
33 static constexpr std::string_view POSITION_PROPERTY = "position";
34 static constexpr std::string_view ORIENTATION_PROPERTY = "orientation";
35 static constexpr std::string_view SCALE_PROPERTY = "scale";
36 static constexpr std::string_view BLEND_SHAPE_WEIGHTS_UNIFORM = "uBlendShapeWeight";
37 static constexpr std::string_view ROOT_NODE_NAME = "RootNode";
38 static const Vector3 SCALE_TO_ADJUST(100.0f, 100.0f, 100.0f);
40 static const Geometry::Type GLTF2_TO_DALI_PRIMITIVES[]{
46 Geometry::TRIANGLE_STRIP,
47 Geometry::TRIANGLE_FAN}; //...because Dali swaps the last two.
49 static struct AttributeMapping
51 gltf2::Attribute::Type mType;
52 MeshDefinition::Accessor MeshDefinition::*mAccessor;
53 uint16_t mElementSizeRequired;
54 } ATTRIBUTE_MAPPINGS[]{
55 {gltf2::Attribute::NORMAL, &MeshDefinition::mNormals, sizeof(Vector3)},
56 {gltf2::Attribute::TANGENT, &MeshDefinition::mTangents, sizeof(Vector3)},
57 {gltf2::Attribute::TEXCOORD_0, &MeshDefinition::mTexCoords, sizeof(Vector2)},
58 {gltf2::Attribute::COLOR_0, &MeshDefinition::mColors, sizeof(Vector4)},
59 {gltf2::Attribute::JOINTS_0, &MeshDefinition::mJoints0, sizeof(Vector4)},
60 {gltf2::Attribute::WEIGHTS_0, &MeshDefinition::mWeights0, sizeof(Vector4)},
63 std::vector<gltf2::Animation> ReadAnimationArray(const json_value_s& j)
65 auto results = json::Read::Array<gltf2::Animation, json::ObjectReader<gltf2::Animation>::Read>(j);
67 for(auto& animation : results)
69 for(auto& channel : animation.mChannels)
71 channel.mSampler.UpdateVector(animation.mSamplers);
78 void ApplyAccessorMinMax(const gltf2::Accessor& accessor, float* values)
80 DALI_ASSERT_ALWAYS(accessor.mMax.empty() || gltf2::AccessorType::ElementCount(accessor.mType) == accessor.mMax.size());
81 DALI_ASSERT_ALWAYS(accessor.mMin.empty() || gltf2::AccessorType::ElementCount(accessor.mType) == accessor.mMin.size());
82 MeshDefinition::Blob::ApplyMinMax(accessor.mMin, accessor.mMax, accessor.mCount, values);
85 const json::Reader<gltf2::Buffer>& GetBufferReader()
87 static const auto BUFFER_READER = std::move(json::Reader<gltf2::Buffer>()
88 .Register(*json::MakeProperty("byteLength", json::Read::Number<uint32_t>, &gltf2::Buffer::mByteLength))
89 .Register(*json::MakeProperty("uri", json::Read::StringView, &gltf2::Buffer::mUri)));
93 const json::Reader<gltf2::BufferView>& GetBufferViewReader()
95 static const auto BUFFER_VIEW_READER = std::move(json::Reader<gltf2::BufferView>()
96 .Register(*json::MakeProperty("buffer", gltf2::RefReader<gltf2::Document>::Read<gltf2::Buffer, &gltf2::Document::mBuffers>, &gltf2::BufferView::mBuffer))
97 .Register(*json::MakeProperty("byteOffset", json::Read::Number<uint32_t>, &gltf2::BufferView::mByteOffset))
98 .Register(*json::MakeProperty("byteLength", json::Read::Number<uint32_t>, &gltf2::BufferView::mByteLength))
99 .Register(*json::MakeProperty("byteStride", json::Read::Number<uint32_t>, &gltf2::BufferView::mByteStride))
100 .Register(*json::MakeProperty("target", json::Read::Number<uint32_t>, &gltf2::BufferView::mTarget)));
101 return BUFFER_VIEW_READER;
104 const json::Reader<gltf2::BufferViewClient>& GetBufferViewClientReader()
106 static const auto BUFFER_VIEW_CLIENT_READER = std::move(json::Reader<gltf2::BufferViewClient>()
107 .Register(*json::MakeProperty("bufferView", gltf2::RefReader<gltf2::Document>::Read<gltf2::BufferView, &gltf2::Document::mBufferViews>, &gltf2::BufferViewClient::mBufferView))
108 .Register(*json::MakeProperty("byteOffset", json::Read::Number<uint32_t>, &gltf2::BufferViewClient::mByteOffset)));
109 return BUFFER_VIEW_CLIENT_READER;
112 const json::Reader<gltf2::ComponentTypedBufferViewClient>& GetComponentTypedBufferViewClientReader()
114 static const auto COMPONENT_TYPED_BUFFER_VIEW_CLIENT_READER = std::move(json::Reader<gltf2::ComponentTypedBufferViewClient>()
115 .Register(*new json::Property<gltf2::ComponentTypedBufferViewClient, gltf2::Ref<gltf2::BufferView>>("bufferView", gltf2::RefReader<gltf2::Document>::Read<gltf2::BufferView, &gltf2::Document::mBufferViews>, &gltf2::ComponentTypedBufferViewClient::mBufferView))
116 .Register(*new json::Property<gltf2::ComponentTypedBufferViewClient, uint32_t>("byteOffset", json::Read::Number<uint32_t>, &gltf2::ComponentTypedBufferViewClient::mByteOffset))
117 .Register(*json::MakeProperty("componentType", json::Read::Enum<gltf2::Component::Type>, &gltf2::ComponentTypedBufferViewClient::mComponentType)));
118 return COMPONENT_TYPED_BUFFER_VIEW_CLIENT_READER;
121 const json::Reader<gltf2::Accessor::Sparse>& GetAccessorSparseReader()
123 static const auto ACCESSOR_SPARSE_READER = std::move(json::Reader<gltf2::Accessor::Sparse>()
124 .Register(*json::MakeProperty("count", json::Read::Number<uint32_t>, &gltf2::Accessor::Sparse::mCount))
125 .Register(*json::MakeProperty("indices", json::ObjectReader<gltf2::ComponentTypedBufferViewClient>::Read, &gltf2::Accessor::Sparse::mIndices))
126 .Register(*json::MakeProperty("values", json::ObjectReader<gltf2::BufferViewClient>::Read, &gltf2::Accessor::Sparse::mValues)));
127 return ACCESSOR_SPARSE_READER;
130 const json::Reader<gltf2::Accessor>& GetAccessorReader()
132 static const auto ACCESSOR_READER = std::move(json::Reader<gltf2::Accessor>()
133 .Register(*new json::Property<gltf2::Accessor, gltf2::Ref<gltf2::BufferView>>("bufferView",
134 gltf2::RefReader<gltf2::Document>::Read<gltf2::BufferView, &gltf2::Document::mBufferViews>,
135 &gltf2::Accessor::mBufferView))
136 .Register(*new json::Property<gltf2::Accessor, uint32_t>("byteOffset",
137 json::Read::Number<uint32_t>,
138 &gltf2::Accessor::mByteOffset))
139 .Register(*new json::Property<gltf2::Accessor, gltf2::Component::Type>("componentType",
140 json::Read::Enum<gltf2::Component::Type>,
141 &gltf2::Accessor::mComponentType))
142 .Register(*new json::Property<gltf2::Accessor, std::string_view>("name", json::Read::StringView, &gltf2::Accessor::mName))
143 .Register(*json::MakeProperty("count", json::Read::Number<uint32_t>, &gltf2::Accessor::mCount))
144 .Register(*json::MakeProperty("normalized", json::Read::Boolean, &gltf2::Accessor::mNormalized))
145 .Register(*json::MakeProperty("type", gltf2::ReadStringEnum<gltf2::AccessorType>, &gltf2::Accessor::mType))
146 .Register(*json::MakeProperty("min", json::Read::Array<float, json::Read::Number>, &gltf2::Accessor::mMin))
147 .Register(*json::MakeProperty("max", json::Read::Array<float, json::Read::Number>, &gltf2::Accessor::mMax))
148 .Register(*new json::Property<gltf2::Accessor, gltf2::Accessor::Sparse>("sparse", json::ObjectReader<gltf2::Accessor::Sparse>::Read, &gltf2::Accessor::SetSparse)));
149 return ACCESSOR_READER;
152 const json::Reader<gltf2::Image>& GetImageReader()
154 static const auto IMAGE_READER = std::move(json::Reader<gltf2::Image>()
155 .Register(*new json::Property<gltf2::Image, std::string_view>("name", json::Read::StringView, &gltf2::Material::mName))
156 .Register(*json::MakeProperty("uri", json::Read::StringView, &gltf2::Image::mUri))
157 .Register(*json::MakeProperty("mimeType", json::Read::StringView, &gltf2::Image::mMimeType))
158 .Register(*json::MakeProperty("bufferView", gltf2::RefReader<gltf2::Document>::Read<gltf2::BufferView, &gltf2::Document::mBufferViews>, &gltf2::Image::mBufferView)));
162 const json::Reader<gltf2::Sampler>& GetSamplerReader()
164 static const auto SAMPLER_READER = std::move(json::Reader<gltf2::Sampler>()
165 .Register(*json::MakeProperty("minFilter", json::Read::Enum<gltf2::Filter::Type>, &gltf2::Sampler::mMinFilter))
166 .Register(*json::MakeProperty("magFilter", json::Read::Enum<gltf2::Filter::Type>, &gltf2::Sampler::mMagFilter))
167 .Register(*json::MakeProperty("wrapS", json::Read::Enum<gltf2::Wrap::Type>, &gltf2::Sampler::mWrapS))
168 .Register(*json::MakeProperty("wrapT", json::Read::Enum<gltf2::Wrap::Type>, &gltf2::Sampler::mWrapT)));
169 return SAMPLER_READER;
172 const json::Reader<gltf2::Texture>& GetTextureReader()
174 static const auto TEXURE_READER = std::move(json::Reader<gltf2::Texture>()
175 .Register(*json::MakeProperty("source", gltf2::RefReader<gltf2::Document>::Read<gltf2::Image, &gltf2::Document::mImages>, &gltf2::Texture::mSource))
176 .Register(*json::MakeProperty("sampler", gltf2::RefReader<gltf2::Document>::Read<gltf2::Sampler, &gltf2::Document::mSamplers>, &gltf2::Texture::mSampler)));
177 return TEXURE_READER;
180 const json::Reader<gltf2::TextureInfo>& GetTextureInfoReader()
182 static const auto TEXURE_INFO_READER = std::move(json::Reader<gltf2::TextureInfo>()
183 .Register(*json::MakeProperty("index", gltf2::RefReader<gltf2::Document>::Read<gltf2::Texture, &gltf2::Document::mTextures>, &gltf2::TextureInfo::mTexture))
184 .Register(*json::MakeProperty("texCoord", json::Read::Number<uint32_t>, &gltf2::TextureInfo::mTexCoord))
185 .Register(*json::MakeProperty("scale", json::Read::Number<float>, &gltf2::TextureInfo::mScale))
186 .Register(*json::MakeProperty("strength", json::Read::Number<float>, &gltf2::TextureInfo::mStrength)));
187 return TEXURE_INFO_READER;
190 const json::Reader<gltf2::Material::Pbr>& GetMaterialPbrReader()
192 static const auto MATERIAL_PBR_READER = std::move(json::Reader<gltf2::Material::Pbr>()
193 .Register(*json::MakeProperty("baseColorFactor", gltf2::ReadDaliVector<Vector4>, &gltf2::Material::Pbr::mBaseColorFactor))
194 .Register(*json::MakeProperty("baseColorTexture", json::ObjectReader<gltf2::TextureInfo>::Read, &gltf2::Material::Pbr::mBaseColorTexture))
195 .Register(*json::MakeProperty("metallicFactor", json::Read::Number<float>, &gltf2::Material::Pbr::mMetallicFactor))
196 .Register(*json::MakeProperty("roughnessFactor", json::Read::Number<float>, &gltf2::Material::Pbr::mRoughnessFactor))
197 .Register(*json::MakeProperty("metallicRoughnessTexture", json::ObjectReader<gltf2::TextureInfo>::Read, &gltf2::Material::Pbr::mMetallicRoughnessTexture)));
198 return MATERIAL_PBR_READER;
201 const json::Reader<gltf2::MaterialSpecular>& GetMaterialSpecularReader()
203 static const auto MATERIAL_SPECULAR_READER = std::move(json::Reader<gltf2::MaterialSpecular>()
204 .Register(*json::MakeProperty("specularFactor", json::Read::Number<float>, &gltf2::MaterialSpecular::mSpecularFactor))
205 .Register(*json::MakeProperty("specularTexture", json::ObjectReader<gltf2::TextureInfo>::Read, &gltf2::MaterialSpecular::mSpecularTexture))
206 .Register(*json::MakeProperty("specularColorFactor", gltf2::ReadDaliVector<Vector3>, &gltf2::MaterialSpecular::mSpecularColorFactor))
207 .Register(*json::MakeProperty("specularColorTexture", json::ObjectReader<gltf2::TextureInfo>::Read, &gltf2::MaterialSpecular::mSpecularColorTexture)));
208 return MATERIAL_SPECULAR_READER;
211 const json::Reader<gltf2::MaterialIor>& GetMaterialIorReader()
213 static const auto MATERIAL_IOR_READER = std::move(json::Reader<gltf2::MaterialIor>()
214 .Register(*json::MakeProperty("ior", json::Read::Number<float>, &gltf2::MaterialIor::mIor)));
215 return MATERIAL_IOR_READER;
218 const json::Reader<gltf2::MaterialExtensions>& GetMaterialExtensionsReader()
220 static const auto MATERIAL_EXTENSION_READER = std::move(json::Reader<gltf2::MaterialExtensions>()
221 .Register(*json::MakeProperty("KHR_materials_ior", json::ObjectReader<gltf2::MaterialIor>::Read, &gltf2::MaterialExtensions::mMaterialIor))
222 .Register(*json::MakeProperty("KHR_materials_specular", json::ObjectReader<gltf2::MaterialSpecular>::Read, &gltf2::MaterialExtensions::mMaterialSpecular)));
223 return MATERIAL_EXTENSION_READER;
226 const json::Reader<gltf2::Material>& GetMaterialReader()
228 static const auto MATERIAL_READER = std::move(json::Reader<gltf2::Material>()
229 .Register(*new json::Property<gltf2::Material, std::string_view>("name", json::Read::StringView, &gltf2::Material::mName))
230 .Register(*json::MakeProperty("pbrMetallicRoughness", json::ObjectReader<gltf2::Material::Pbr>::Read, &gltf2::Material::mPbrMetallicRoughness))
231 .Register(*json::MakeProperty("normalTexture", json::ObjectReader<gltf2::TextureInfo>::Read, &gltf2::Material::mNormalTexture))
232 .Register(*json::MakeProperty("occlusionTexture", json::ObjectReader<gltf2::TextureInfo>::Read, &gltf2::Material::mOcclusionTexture))
233 .Register(*json::MakeProperty("emissiveTexture", json::ObjectReader<gltf2::TextureInfo>::Read, &gltf2::Material::mEmissiveTexture))
234 .Register(*json::MakeProperty("emissiveFactor", gltf2::ReadDaliVector<Vector3>, &gltf2::Material::mEmissiveFactor))
235 .Register(*json::MakeProperty("alphaMode", gltf2::ReadStringEnum<gltf2::AlphaMode>, &gltf2::Material::mAlphaMode))
236 .Register(*json::MakeProperty("alphaCutoff", json::Read::Number<float>, &gltf2::Material::mAlphaCutoff))
237 .Register(*json::MakeProperty("doubleSided", json::Read::Boolean, &gltf2::Material::mDoubleSided))
238 .Register(*json::MakeProperty("extensions", json::ObjectReader<gltf2::MaterialExtensions>::Read, &gltf2::Material::mMaterialExtensions)));
239 return MATERIAL_READER;
242 std::map<gltf2::Attribute::Type, gltf2::Ref<gltf2::Accessor>> ReadMeshPrimitiveAttributes(const json_value_s& j)
244 auto& jsonObject = json::Cast<json_object_s>(j);
245 std::map<gltf2::Attribute::Type, gltf2::Ref<gltf2::Accessor>> result;
247 auto element = jsonObject.start;
250 auto jsonString = *element->name;
251 result[gltf2::Attribute::FromString(jsonString.string, jsonString.string_size)] = gltf2::RefReader<gltf2::Document>::Read<gltf2::Accessor, &gltf2::Document::mAccessors>(*element->value);
252 element = element->next;
257 std::vector<std::map<gltf2::Attribute::Type, gltf2::Ref<gltf2::Accessor>>> ReadMeshPrimitiveTargets(const json_value_s& j)
259 auto& jsonObject = json::Cast<json_array_s>(j);
260 std::vector<std::map<gltf2::Attribute::Type, gltf2::Ref<gltf2::Accessor>>> result;
262 result.reserve(jsonObject.length);
264 auto element = jsonObject.start;
267 result.push_back(std::move(ReadMeshPrimitiveAttributes(*element->value)));
268 element = element->next;
274 const json::Reader<gltf2::Mesh::Primitive>& GetMeshPrimitiveReader()
276 static const auto MESH_PRIMITIVE_READER = std::move(json::Reader<gltf2::Mesh::Primitive>()
277 .Register(*json::MakeProperty("attributes", ReadMeshPrimitiveAttributes, &gltf2::Mesh::Primitive::mAttributes))
278 .Register(*json::MakeProperty("indices", gltf2::RefReader<gltf2::Document>::Read<gltf2::Accessor, &gltf2::Document::mAccessors>, &gltf2::Mesh::Primitive::mIndices))
279 .Register(*json::MakeProperty("material", gltf2::RefReader<gltf2::Document>::Read<gltf2::Material, &gltf2::Document::mMaterials>, &gltf2::Mesh::Primitive::mMaterial))
280 .Register(*json::MakeProperty("mode", json::Read::Enum<gltf2::Mesh::Primitive::Mode>, &gltf2::Mesh::Primitive::mMode))
281 .Register(*json::MakeProperty("targets", ReadMeshPrimitiveTargets, &gltf2::Mesh::Primitive::mTargets)));
282 return MESH_PRIMITIVE_READER;
285 const json::Reader<gltf2::Mesh::Extras>& GetMeshExtrasReader()
287 static const auto MESH_EXTRAS_READER = std::move(json::Reader<gltf2::Mesh::Extras>()
288 .Register(*json::MakeProperty("targetNames", json::Read::Array<std::string_view, json::Read::StringView>, &gltf2::Mesh::Extras::mTargetNames)));
289 return MESH_EXTRAS_READER;
292 std::vector<std::string_view> ReadMeshExtensionsTargetsName(const json_value_s& j)
294 auto& jsonObject = json::Cast<json_object_s>(j);
295 std::vector<std::string_view> result;
297 auto element = jsonObject.start;
300 auto jsonString = *element->name;
301 uint32_t index = json::Read::Number<uint32_t>(*element->value);
303 if(result.size() <= index)
305 DALI_ASSERT_ALWAYS(index < std::numeric_limits<uint32_t>::max());
306 result.resize(index + 1u);
309 result[index] = json::Read::StringView(jsonString);
311 element = element->next;
316 const json::Reader<gltf2::Mesh::Extensions>& GetMeshExtensionsReader()
318 static const auto MESH_EXTENSIONS_READER = std::move(json::Reader<gltf2::Mesh::Extensions>()
319 .Register(*json::MakeProperty("SXR_targets_names", ReadMeshExtensionsTargetsName, &gltf2::Mesh::Extensions::mSXRTargetsNames))
320 .Register(*json::MakeProperty("avatar_shape_names", ReadMeshExtensionsTargetsName, &gltf2::Mesh::Extensions::mAvatarShapeNames)));
321 return MESH_EXTENSIONS_READER;
324 const json::Reader<gltf2::Mesh>& GetMeshReader()
326 static const auto MESH_READER = std::move(json::Reader<gltf2::Mesh>()
327 .Register(*new json::Property<gltf2::Mesh, std::string_view>("name", json::Read::StringView, &gltf2::Mesh::mName))
328 .Register(*json::MakeProperty("primitives",
329 json::Read::Array<gltf2::Mesh::Primitive, json::ObjectReader<gltf2::Mesh::Primitive>::Read>,
330 &gltf2::Mesh::mPrimitives))
331 .Register(*json::MakeProperty("weights", json::Read::Array<float, json::Read::Number>, &gltf2::Mesh::mWeights))
332 .Register(*json::MakeProperty("extras", json::ObjectReader<gltf2::Mesh::Extras>::Read, &gltf2::Mesh::mExtras))
333 .Register(*json::MakeProperty("extensions", json::ObjectReader<gltf2::Mesh::Extensions>::Read, &gltf2::Mesh::mExtensions)));
337 const json::Reader<gltf2::Skin>& GetSkinReader()
339 static const auto SKIN_READER = std::move(json::Reader<gltf2::Skin>()
340 .Register(*new json::Property<gltf2::Skin, std::string_view>("name", json::Read::StringView, &gltf2::Skin::mName))
341 .Register(*json::MakeProperty("inverseBindMatrices",
342 gltf2::RefReader<gltf2::Document>::Read<gltf2::Accessor, &gltf2::Document::mAccessors>,
343 &gltf2::Skin::mInverseBindMatrices))
344 .Register(*json::MakeProperty("skeleton",
345 gltf2::RefReader<gltf2::Document>::Read<gltf2::Node, &gltf2::Document::mNodes>,
346 &gltf2::Skin::mSkeleton))
347 .Register(*json::MakeProperty("joints",
348 json::Read::Array<gltf2::Ref<gltf2::Node>, gltf2::RefReader<gltf2::Document>::Read<gltf2::Node, &gltf2::Document::mNodes>>,
349 &gltf2::Skin::mJoints)));
353 const json::Reader<gltf2::Camera::Perspective>& GetCameraPerspectiveReader()
355 static const auto CAMERA_PERSPECTIVE_READER = std::move(json::Reader<gltf2::Camera::Perspective>()
356 .Register(*json::MakeProperty("aspectRatio", json::Read::Number<float>, &gltf2::Camera::Perspective::mAspectRatio))
357 .Register(*json::MakeProperty("yfov", json::Read::Number<float>, &gltf2::Camera::Perspective::mYFov))
358 .Register(*json::MakeProperty("zfar", json::Read::Number<float>, &gltf2::Camera::Perspective::mZFar))
359 .Register(*json::MakeProperty("znear", json::Read::Number<float>, &gltf2::Camera::Perspective::mZNear))); // TODO: infinite perspective projection, where znear is omitted
360 return CAMERA_PERSPECTIVE_READER;
363 const json::Reader<gltf2::Camera::Orthographic>& GetCameraOrthographicReader()
365 static const auto CAMERA_ORTHOGRAPHIC_READER = std::move(json::Reader<gltf2::Camera::Orthographic>()
366 .Register(*json::MakeProperty("xmag", json::Read::Number<float>, &gltf2::Camera::Orthographic::mXMag))
367 .Register(*json::MakeProperty("ymag", json::Read::Number<float>, &gltf2::Camera::Orthographic::mYMag))
368 .Register(*json::MakeProperty("zfar", json::Read::Number<float>, &gltf2::Camera::Orthographic::mZFar))
369 .Register(*json::MakeProperty("znear", json::Read::Number<float>, &gltf2::Camera::Orthographic::mZNear)));
370 return CAMERA_ORTHOGRAPHIC_READER;
373 const json::Reader<gltf2::Camera>& GetCameraReader()
375 static const auto CAMERA_READER = std::move(json::Reader<gltf2::Camera>()
376 .Register(*new json::Property<gltf2::Camera, std::string_view>("name", json::Read::StringView, &gltf2::Camera::mName))
377 .Register(*json::MakeProperty("type", json::Read::StringView, &gltf2::Camera::mType))
378 .Register(*json::MakeProperty("perspective", json::ObjectReader<gltf2::Camera::Perspective>::Read, &gltf2::Camera::mPerspective))
379 .Register(*json::MakeProperty("orthographic", json::ObjectReader<gltf2::Camera::Orthographic>::Read, &gltf2::Camera::mOrthographic)));
380 return CAMERA_READER;
383 const json::Reader<gltf2::Node>& GetNodeReader()
385 static const auto NODE_READER = std::move(json::Reader<gltf2::Node>()
386 .Register(*new json::Property<gltf2::Node, std::string_view>("name", json::Read::StringView, &gltf2::Node::mName))
387 .Register(*json::MakeProperty("translation", gltf2::ReadDaliVector<Vector3>, &gltf2::Node::mTranslation))
388 .Register(*json::MakeProperty("rotation", gltf2::ReadQuaternion, &gltf2::Node::mRotation))
389 .Register(*json::MakeProperty("scale", gltf2::ReadDaliVector<Vector3>, &gltf2::Node::mScale))
390 .Register(*new json::Property<gltf2::Node, Matrix>("matrix", gltf2::ReadDaliVector<Matrix>, &gltf2::Node::SetMatrix))
391 .Register(*json::MakeProperty("camera", gltf2::RefReader<gltf2::Document>::Read<gltf2::Camera, &gltf2::Document::mCameras>, &gltf2::Node::mCamera))
392 .Register(*json::MakeProperty("children", json::Read::Array<gltf2::Ref<gltf2::Node>, gltf2::RefReader<gltf2::Document>::Read<gltf2::Node, &gltf2::Document::mNodes>>, &gltf2::Node::mChildren))
393 .Register(*json::MakeProperty("mesh", gltf2::RefReader<gltf2::Document>::Read<gltf2::Mesh, &gltf2::Document::mMeshes>, &gltf2::Node::mMesh))
394 .Register(*json::MakeProperty("skin", gltf2::RefReader<gltf2::Document>::Read<gltf2::Skin, &gltf2::Document::mSkins>, &gltf2::Node::mSkin)));
398 const json::Reader<gltf2::Animation::Sampler>& GetAnimationSamplerReader()
400 static const auto ANIMATION_SAMPLER_READER = std::move(json::Reader<gltf2::Animation::Sampler>()
401 .Register(*json::MakeProperty("input", gltf2::RefReader<gltf2::Document>::Read<gltf2::Accessor, &gltf2::Document::mAccessors>, &gltf2::Animation::Sampler::mInput))
402 .Register(*json::MakeProperty("output", gltf2::RefReader<gltf2::Document>::Read<gltf2::Accessor, &gltf2::Document::mAccessors>, &gltf2::Animation::Sampler::mOutput))
403 .Register(*json::MakeProperty("interpolation", gltf2::ReadStringEnum<gltf2::Animation::Sampler::Interpolation>, &gltf2::Animation::Sampler::mInterpolation)));
404 return ANIMATION_SAMPLER_READER;
407 const json::Reader<gltf2::Animation::Channel::Target>& GetAnimationChannelTargetReader()
409 static const auto ANIMATION_TARGET_READER = std::move(json::Reader<gltf2::Animation::Channel::Target>()
410 .Register(*json::MakeProperty("node", gltf2::RefReader<gltf2::Document>::Read<gltf2::Node, &gltf2::Document::mNodes>, &gltf2::Animation::Channel::Target::mNode))
411 .Register(*json::MakeProperty("path", gltf2::ReadStringEnum<gltf2::Animation::Channel::Target>, &gltf2::Animation::Channel::Target::mPath)));
412 return ANIMATION_TARGET_READER;
415 const json::Reader<gltf2::Animation::Channel>& GetAnimationChannelReader()
417 static const auto ANIMATION_CHANNEL_READER = std::move(json::Reader<gltf2::Animation::Channel>()
418 .Register(*json::MakeProperty("target", json::ObjectReader<gltf2::Animation::Channel::Target>::Read, &gltf2::Animation::Channel::mTarget))
419 .Register(*json::MakeProperty("sampler", gltf2::RefReader<gltf2::Animation>::Read<gltf2::Animation::Sampler, &gltf2::Animation::mSamplers>, &gltf2::Animation::Channel::mSampler)));
420 return ANIMATION_CHANNEL_READER;
423 const json::Reader<gltf2::Animation>& GetAnimationReader()
425 static const auto ANIMATION_READER = std::move(json::Reader<gltf2::Animation>()
426 .Register(*new json::Property<gltf2::Animation, std::string_view>("name", json::Read::StringView, &gltf2::Animation::mName))
427 .Register(*json::MakeProperty("samplers",
428 json::Read::Array<gltf2::Animation::Sampler, json::ObjectReader<gltf2::Animation::Sampler>::Read>,
429 &gltf2::Animation::mSamplers))
430 .Register(*json::MakeProperty("channels",
431 json::Read::Array<gltf2::Animation::Channel, json::ObjectReader<gltf2::Animation::Channel>::Read>,
432 &gltf2::Animation::mChannels)));
433 return ANIMATION_READER;
436 const json::Reader<gltf2::Scene>& GetSceneReader()
438 static const auto SCENE_READER = std::move(json::Reader<gltf2::Scene>()
439 .Register(*new json::Property<gltf2::Scene, std::string_view>("name", json::Read::StringView, &gltf2::Scene::mName))
440 .Register(*json::MakeProperty("nodes",
441 json::Read::Array<gltf2::Ref<gltf2::Node>, gltf2::RefReader<gltf2::Document>::Read<gltf2::Node, &gltf2::Document::mNodes>>,
442 &gltf2::Scene::mNodes)));
446 const json::Reader<gltf2::Document>& GetDocumentReader()
448 static const auto DOCUMENT_READER = std::move(json::Reader<gltf2::Document>()
449 .Register(*json::MakeProperty("buffers",
450 json::Read::Array<gltf2::Buffer, json::ObjectReader<gltf2::Buffer>::Read>,
451 &gltf2::Document::mBuffers))
452 .Register(*json::MakeProperty("bufferViews",
453 json::Read::Array<gltf2::BufferView, json::ObjectReader<gltf2::BufferView>::Read>,
454 &gltf2::Document::mBufferViews))
455 .Register(*json::MakeProperty("accessors",
456 json::Read::Array<gltf2::Accessor, json::ObjectReader<gltf2::Accessor>::Read>,
457 &gltf2::Document::mAccessors))
458 .Register(*json::MakeProperty("images",
459 json::Read::Array<gltf2::Image, json::ObjectReader<gltf2::Image>::Read>,
460 &gltf2::Document::mImages))
461 .Register(*json::MakeProperty("samplers",
462 json::Read::Array<gltf2::Sampler, json::ObjectReader<gltf2::Sampler>::Read>,
463 &gltf2::Document::mSamplers))
464 .Register(*json::MakeProperty("textures",
465 json::Read::Array<gltf2::Texture, json::ObjectReader<gltf2::Texture>::Read>,
466 &gltf2::Document::mTextures))
467 .Register(*json::MakeProperty("materials",
468 json::Read::Array<gltf2::Material, json::ObjectReader<gltf2::Material>::Read>,
469 &gltf2::Document::mMaterials))
470 .Register(*json::MakeProperty("meshes",
471 json::Read::Array<gltf2::Mesh, json::ObjectReader<gltf2::Mesh>::Read>,
472 &gltf2::Document::mMeshes))
473 .Register(*json::MakeProperty("skins",
474 json::Read::Array<gltf2::Skin, json::ObjectReader<gltf2::Skin>::Read>,
475 &gltf2::Document::mSkins))
476 .Register(*json::MakeProperty("cameras",
477 json::Read::Array<gltf2::Camera, json::ObjectReader<gltf2::Camera>::Read>,
478 &gltf2::Document::mCameras))
479 .Register(*json::MakeProperty("nodes",
480 json::Read::Array<gltf2::Node, json::ObjectReader<gltf2::Node>::Read>,
481 &gltf2::Document::mNodes))
482 .Register(*json::MakeProperty("animations",
484 &gltf2::Document::mAnimations))
485 .Register(*json::MakeProperty("scenes",
486 json::Read::Array<gltf2::Scene, json::ObjectReader<gltf2::Scene>::Read>,
487 &gltf2::Document::mScenes))
488 .Register(*json::MakeProperty("scene", gltf2::RefReader<gltf2::Document>::Read<gltf2::Scene, &gltf2::Document::mScenes>, &gltf2::Document::mScene)));
489 return DOCUMENT_READER;
492 void ConvertBuffer(const gltf2::Buffer& buffer, decltype(ResourceBundle::mBuffers)& outBuffers, const std::string& resourcePath)
494 BufferDefinition bufferDefinition;
496 bufferDefinition.mResourcePath = resourcePath;
497 bufferDefinition.mUri = buffer.mUri;
498 bufferDefinition.mByteLength = buffer.mByteLength;
500 outBuffers.emplace_back(std::move(bufferDefinition));
503 void ConvertBuffers(const gltf2::Document& document, ConversionContext& context)
505 auto& outBuffers = context.mOutput.mResources.mBuffers;
506 outBuffers.reserve(document.mBuffers.size());
508 for(auto& buffer : document.mBuffers)
510 if(buffer.mUri.empty())
514 ConvertBuffer(buffer, outBuffers, context.mPath);
518 SamplerFlags::Type ConvertWrapMode(gltf2::Wrap::Type wrapMode)
522 case gltf2::Wrap::REPEAT:
523 return SamplerFlags::WRAP_REPEAT;
524 case gltf2::Wrap::CLAMP_TO_EDGE:
525 return SamplerFlags::WRAP_CLAMP;
526 case gltf2::Wrap::MIRRORED_REPEAT:
527 return SamplerFlags::WRAP_MIRROR;
529 throw std::runtime_error("Invalid wrap type.");
533 SamplerFlags::Type ConvertSampler(const gltf2::Ref<gltf2::Sampler>& sampler)
537 return ((sampler->mMinFilter < gltf2::Filter::NEAREST_MIPMAP_NEAREST) ? (sampler->mMinFilter - gltf2::Filter::NEAREST) : ((sampler->mMinFilter - gltf2::Filter::NEAREST_MIPMAP_NEAREST) + 2)) |
538 ((sampler->mMagFilter - gltf2::Filter::NEAREST) << SamplerFlags::FILTER_MAG_SHIFT) |
539 (ConvertWrapMode(sampler->mWrapS) << SamplerFlags::WRAP_S_SHIFT) |
540 (ConvertWrapMode(sampler->mWrapT) << SamplerFlags::WRAP_T_SHIFT);
544 // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#texturesampler
545 // "The index of the sampler used by this texture. When undefined, a sampler with repeat wrapping and auto filtering should be used."
546 // "What is an auto filtering", I hear you ask. Since there's nothing else to determine mipmapping from - including glTF image
547 // properties, if not in some extension -, we will simply assume linear filtering.
548 return SamplerFlags::FILTER_LINEAR | (SamplerFlags::FILTER_LINEAR << SamplerFlags::FILTER_MAG_SHIFT) |
549 (SamplerFlags::WRAP_REPEAT << SamplerFlags::WRAP_S_SHIFT) | (SamplerFlags::WRAP_REPEAT << SamplerFlags::WRAP_T_SHIFT);
553 TextureDefinition ConvertTextureInfo(const gltf2::TextureInfo& textureInfo, ConversionContext& context, const ImageMetadata& metaData = ImageMetadata())
555 TextureDefinition textureDefinition;
556 std::string uri = std::string(textureInfo.mTexture->mSource->mUri);
559 uint32_t bufferIndex = textureInfo.mTexture->mSource->mBufferView->mBuffer.GetIndex();
560 if(bufferIndex != INVALID_INDEX && context.mOutput.mResources.mBuffers[bufferIndex].IsAvailable())
562 auto& stream = context.mOutput.mResources.mBuffers[bufferIndex].GetBufferStream();
564 stream.seekg(textureInfo.mTexture->mSource->mBufferView->mByteOffset, stream.beg);
565 std::vector<uint8_t> dataBuffer;
566 dataBuffer.resize(textureInfo.mTexture->mSource->mBufferView->mByteLength);
567 stream.read(reinterpret_cast<char*>(dataBuffer.data()), static_cast<std::streamsize>(static_cast<size_t>(textureInfo.mTexture->mSource->mBufferView->mByteLength)));
568 return TextureDefinition{std::move(dataBuffer), ConvertSampler(textureInfo.mTexture->mSampler), metaData.mMinSize, metaData.mSamplingMode};
570 return TextureDefinition();
574 return TextureDefinition{uri, ConvertSampler(textureInfo.mTexture->mSampler), metaData.mMinSize, metaData.mSamplingMode};
578 void AddTextureStage(uint32_t semantic, MaterialDefinition& materialDefinition, gltf2::TextureInfo textureInfo, const Dali::Scene3D::Loader::ImageMetadata& metaData, ConversionContext& context)
580 materialDefinition.mTextureStages.push_back({semantic, ConvertTextureInfo(textureInfo, context, metaData)});
581 materialDefinition.mFlags |= semantic;
584 void ConvertMaterial(const gltf2::Material& material, const std::unordered_map<std::string, ImageMetadata>& imageMetaData, decltype(ResourceBundle::mMaterials)& outMaterials, ConversionContext& context)
586 auto getTextureMetaData = [](const std::unordered_map<std::string, ImageMetadata>& metaData, const gltf2::TextureInfo& info) {
587 if(!info.mTexture->mSource->mUri.empty())
589 if(auto search = metaData.find(info.mTexture->mSource->mUri.data()); search != metaData.end())
591 return search->second;
594 return ImageMetadata();
597 MaterialDefinition materialDefinition;
599 materialDefinition.mFlags |= MaterialDefinition::GLTF_CHANNELS;
601 auto& pbr = material.mPbrMetallicRoughness;
602 if(material.mAlphaMode == gltf2::AlphaMode::BLEND)
604 materialDefinition.mAlphaModeType = Scene3D::Material::AlphaModeType::BLEND;
605 materialDefinition.mIsOpaque = false;
606 materialDefinition.mFlags |= MaterialDefinition::TRANSPARENCY;
608 else if(material.mAlphaMode == gltf2::AlphaMode::MASK)
610 materialDefinition.mAlphaModeType = Scene3D::Material::AlphaModeType::MASK;
611 materialDefinition.mIsMask = true;
612 materialDefinition.SetAlphaCutoff(std::min(1.f, std::max(0.f, material.mAlphaCutoff)));
615 materialDefinition.mBaseColorFactor = pbr.mBaseColorFactor;
617 materialDefinition.mTextureStages.reserve(!!pbr.mBaseColorTexture + !!pbr.mMetallicRoughnessTexture + !!material.mNormalTexture + !!material.mOcclusionTexture + !!material.mEmissiveTexture);
618 if(pbr.mBaseColorTexture)
620 AddTextureStage(MaterialDefinition::ALBEDO, materialDefinition, pbr.mBaseColorTexture, getTextureMetaData(imageMetaData, pbr.mBaseColorTexture), context);
624 materialDefinition.mNeedAlbedoTexture = false;
627 materialDefinition.mMetallic = pbr.mMetallicFactor;
628 materialDefinition.mRoughness = pbr.mRoughnessFactor;
630 if(pbr.mMetallicRoughnessTexture)
632 AddTextureStage(MaterialDefinition::METALLIC | MaterialDefinition::ROUGHNESS,
634 pbr.mMetallicRoughnessTexture,
635 getTextureMetaData(imageMetaData, pbr.mMetallicRoughnessTexture),
640 materialDefinition.mNeedMetallicRoughnessTexture = false;
643 materialDefinition.mNormalScale = material.mNormalTexture.mScale;
644 if(material.mNormalTexture)
646 AddTextureStage(MaterialDefinition::NORMAL, materialDefinition, material.mNormalTexture, getTextureMetaData(imageMetaData, material.mNormalTexture), context);
650 materialDefinition.mNeedNormalTexture = false;
653 if(material.mOcclusionTexture)
655 AddTextureStage(MaterialDefinition::OCCLUSION, materialDefinition, material.mOcclusionTexture, getTextureMetaData(imageMetaData, material.mOcclusionTexture), context);
656 materialDefinition.mOcclusionStrength = material.mOcclusionTexture.mStrength;
659 materialDefinition.mEmissiveFactor = material.mEmissiveFactor;
660 if(material.mEmissiveTexture)
662 AddTextureStage(MaterialDefinition::EMISSIVE, materialDefinition, material.mEmissiveTexture, getTextureMetaData(imageMetaData, material.mEmissiveTexture), context);
665 if(!Dali::Equals(material.mMaterialExtensions.mMaterialIor.mIor, gltf2::UNDEFINED_FLOAT_VALUE))
667 materialDefinition.mIor = material.mMaterialExtensions.mMaterialIor.mIor;
668 materialDefinition.mDielectricSpecular = powf((materialDefinition.mIor - 1.0f) / (materialDefinition.mIor + 1.0f), 2.0f);
670 materialDefinition.mSpecularFactor = material.mMaterialExtensions.mMaterialSpecular.mSpecularFactor;
671 materialDefinition.mSpecularColorFactor = material.mMaterialExtensions.mMaterialSpecular.mSpecularColorFactor;
673 if(material.mMaterialExtensions.mMaterialSpecular.mSpecularTexture)
675 AddTextureStage(MaterialDefinition::SPECULAR, materialDefinition, material.mMaterialExtensions.mMaterialSpecular.mSpecularTexture, getTextureMetaData(imageMetaData, material.mMaterialExtensions.mMaterialSpecular.mSpecularTexture), context);
678 if(material.mMaterialExtensions.mMaterialSpecular.mSpecularColorTexture)
680 AddTextureStage(MaterialDefinition::SPECULAR_COLOR, materialDefinition, material.mMaterialExtensions.mMaterialSpecular.mSpecularColorTexture, getTextureMetaData(imageMetaData, material.mMaterialExtensions.mMaterialSpecular.mSpecularColorTexture), context);
683 materialDefinition.mDoubleSided = material.mDoubleSided;
685 outMaterials.emplace_back(std::move(materialDefinition), TextureSet());
688 void ConvertMaterials(const gltf2::Document& document, ConversionContext& context)
690 auto& imageMetaData = context.mOutput.mSceneMetadata.mImageMetadata;
692 auto& outMaterials = context.mOutput.mResources.mMaterials;
693 outMaterials.reserve(document.mMaterials.size());
695 for(auto& material : document.mMaterials)
697 ConvertMaterial(material, imageMetaData, outMaterials, context);
701 MeshDefinition::Accessor ConvertMeshPrimitiveAccessor(const gltf2::Accessor& accessor)
703 DALI_ASSERT_ALWAYS((accessor.mBufferView &&
704 (accessor.mBufferView->mByteStride < std::numeric_limits<uint16_t>::max())) ||
705 (accessor.mSparse && !accessor.mBufferView));
707 DALI_ASSERT_ALWAYS(!accessor.mSparse ||
708 ((accessor.mSparse->mIndices.mBufferView && (accessor.mSparse->mIndices.mBufferView->mByteStride < std::numeric_limits<uint16_t>::max())) &&
709 (accessor.mSparse->mValues.mBufferView && (accessor.mSparse->mValues.mBufferView->mByteStride < std::numeric_limits<uint16_t>::max()))));
711 MeshDefinition::SparseBlob sparseBlob;
714 const gltf2::Accessor::Sparse& sparse = *accessor.mSparse;
715 const gltf2::ComponentTypedBufferViewClient& indices = sparse.mIndices;
716 const gltf2::BufferViewClient& values = sparse.mValues;
718 MeshDefinition::Blob indicesBlob(
719 indices.mBufferView->mByteOffset + indices.mByteOffset,
720 sparse.mCount * indices.GetBytesPerComponent(),
721 static_cast<uint16_t>(indices.mBufferView->mByteStride),
722 static_cast<uint16_t>(indices.GetBytesPerComponent()),
725 MeshDefinition::Blob valuesBlob(
726 values.mBufferView->mByteOffset + values.mByteOffset,
727 sparse.mCount * accessor.GetElementSizeBytes(),
728 static_cast<uint16_t>(values.mBufferView->mByteStride),
729 static_cast<uint16_t>(accessor.GetElementSizeBytes()),
733 sparseBlob = std::move(MeshDefinition::SparseBlob(std::move(indicesBlob), std::move(valuesBlob), accessor.mSparse->mCount));
736 uint32_t bufferViewOffset = 0u;
737 uint32_t bufferViewStride = 0u;
738 if(accessor.mBufferView)
740 bufferViewOffset = accessor.mBufferView->mByteOffset;
741 bufferViewStride = accessor.mBufferView->mByteStride;
744 return MeshDefinition::Accessor{
745 std::move(MeshDefinition::Blob{bufferViewOffset + accessor.mByteOffset,
746 accessor.GetBytesLength(),
747 static_cast<uint16_t>(bufferViewStride),
748 static_cast<uint16_t>(accessor.GetElementSizeBytes()),
751 std::move(sparseBlob),
752 accessor.mBufferView ? accessor.mBufferView->mBuffer.GetIndex() : 0};
755 void ConvertMeshes(const gltf2::Document& document, ConversionContext& context)
757 uint32_t meshCount = 0;
758 context.mMeshIds.reserve(document.mMeshes.size());
759 for(auto& mesh : document.mMeshes)
761 context.mMeshIds.push_back(meshCount);
762 meshCount += mesh.mPrimitives.size();
765 auto& outMeshes = context.mOutput.mResources.mMeshes;
766 outMeshes.reserve(meshCount);
767 for(auto& mesh : document.mMeshes)
769 for(auto& primitive : mesh.mPrimitives)
771 MeshDefinition meshDefinition;
773 auto& attribs = primitive.mAttributes;
774 meshDefinition.mPrimitiveType = GLTF2_TO_DALI_PRIMITIVES[primitive.mMode];
776 auto positionIter = attribs.find(gltf2::Attribute::POSITION);
778 if(positionIter == attribs.end())
780 DALI_LOG_ERROR("Primitive mesh dosn't have POSITION atrributes!");
784 auto& accPositions = *positionIter->second;
785 meshDefinition.mPositions = ConvertMeshPrimitiveAccessor(accPositions);
786 // glTF2 support vector4 tangent for mesh.
787 // https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html#meshes-overview
788 meshDefinition.mTangentType = Property::VECTOR4;
790 const bool needNormalsTangents = accPositions.mType == gltf2::AccessorType::VEC3;
791 for(auto& attributeMapping : ATTRIBUTE_MAPPINGS)
793 auto iFind = attribs.find(attributeMapping.mType);
794 if(iFind != attribs.end())
796 auto& accessor = meshDefinition.*(attributeMapping.mAccessor);
797 accessor = ConvertMeshPrimitiveAccessor(*iFind->second);
799 if(iFind->first == gltf2::Attribute::JOINTS_0)
801 meshDefinition.mFlags |= (iFind->second->mComponentType == gltf2::Component::UNSIGNED_SHORT) * MeshDefinition::U16_JOINT_IDS;
802 meshDefinition.mFlags |= (iFind->second->mComponentType == gltf2::Component::UNSIGNED_BYTE) * MeshDefinition::U8_JOINT_IDS;
803 DALI_ASSERT_DEBUG(MaskMatch(meshDefinition.mFlags, MeshDefinition::U16_JOINT_IDS) || MaskMatch(meshDefinition.mFlags, MeshDefinition::U8_JOINT_IDS) || iFind->second->mComponentType == gltf2::Component::FLOAT);
805 if(iFind->first == gltf2::Attribute::WEIGHTS_0)
807 meshDefinition.mFlags |= (iFind->second->mComponentType == gltf2::Component::UNSIGNED_SHORT) * MeshDefinition::U16_WEIGHT;
808 meshDefinition.mFlags |= (iFind->second->mComponentType == gltf2::Component::UNSIGNED_BYTE) * MeshDefinition::U8_WEIGHT;
809 DALI_ASSERT_DEBUG(MaskMatch(meshDefinition.mFlags, MeshDefinition::U16_WEIGHT) || MaskMatch(meshDefinition.mFlags, MeshDefinition::U8_WEIGHT) || iFind->second->mComponentType == gltf2::Component::FLOAT);
812 else if(needNormalsTangents)
814 switch(attributeMapping.mType)
816 case gltf2::Attribute::NORMAL:
817 meshDefinition.RequestNormals();
820 case gltf2::Attribute::TANGENT:
821 meshDefinition.RequestTangents();
830 if(primitive.mIndices)
832 meshDefinition.mIndices = ConvertMeshPrimitiveAccessor(*primitive.mIndices);
833 meshDefinition.mFlags |= (primitive.mIndices->mComponentType == gltf2::Component::UNSIGNED_INT) * MeshDefinition::U32_INDICES;
834 meshDefinition.mFlags |= (primitive.mIndices->mComponentType == gltf2::Component::UNSIGNED_BYTE) * MeshDefinition::U8_INDICES;
835 DALI_ASSERT_DEBUG(MaskMatch(meshDefinition.mFlags, MeshDefinition::U32_INDICES) || MaskMatch(meshDefinition.mFlags, MeshDefinition::U8_INDICES) || primitive.mIndices->mComponentType == gltf2::Component::UNSIGNED_SHORT);
838 if(!primitive.mTargets.empty())
840 meshDefinition.mBlendShapes.reserve(primitive.mTargets.size());
841 meshDefinition.mBlendShapeVersion = BlendShapes::Version::VERSION_2_0;
842 uint32_t blendShapeIndex = 0u;
843 for(const auto& target : primitive.mTargets)
845 MeshDefinition::BlendShape blendShape;
847 auto endIt = target.end();
848 auto it = target.find(gltf2::Attribute::POSITION);
851 blendShape.deltas = ConvertMeshPrimitiveAccessor(*it->second);
853 it = target.find(gltf2::Attribute::NORMAL);
856 blendShape.normals = ConvertMeshPrimitiveAccessor(*it->second);
858 it = target.find(gltf2::Attribute::TANGENT);
861 blendShape.tangents = ConvertMeshPrimitiveAccessor(*it->second);
864 if(!mesh.mWeights.empty())
866 blendShape.weight = mesh.mWeights[meshDefinition.mBlendShapes.size()];
869 // Get blendshape name from extras / SXR_targets_names / avatar_shape_names.
870 if(blendShapeIndex < mesh.mExtras.mTargetNames.size())
872 blendShape.name = mesh.mExtras.mTargetNames[blendShapeIndex];
874 else if(blendShapeIndex < mesh.mExtensions.mSXRTargetsNames.size())
876 blendShape.name = mesh.mExtensions.mSXRTargetsNames[blendShapeIndex];
878 else if(blendShapeIndex < mesh.mExtensions.mAvatarShapeNames.size())
880 blendShape.name = mesh.mExtensions.mAvatarShapeNames[blendShapeIndex];
883 meshDefinition.mBlendShapes.push_back(std::move(blendShape));
888 outMeshes.push_back({std::move(meshDefinition), MeshGeometry{}});
893 ModelRenderable* MakeModelRenderable(const gltf2::Mesh::Primitive& primitive, ConversionContext& context)
895 auto modelRenderable = new ModelRenderable();
897 auto materialIdx = primitive.mMaterial.GetIndex();
898 if(INVALID_INDEX == materialIdx)
900 // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#default-material
901 if(INVALID_INDEX == context.mDefaultMaterial)
903 auto& outMaterials = context.mOutput.mResources.mMaterials;
904 context.mDefaultMaterial = outMaterials.size();
906 ConvertMaterial(gltf2::Material{}, context.mOutput.mSceneMetadata.mImageMetadata, outMaterials, context);
909 materialIdx = context.mDefaultMaterial;
912 modelRenderable->mMaterialIdx = materialIdx;
914 return modelRenderable;
917 void ConvertCamera(const gltf2::Camera& camera, CameraParameters& cameraParameters)
919 cameraParameters.isPerspective = camera.mType.compare("perspective") == 0;
920 if(cameraParameters.isPerspective)
922 auto& perspective = camera.mPerspective;
923 if(!Dali::Equals(perspective.mYFov, gltf2::UNDEFINED_FLOAT_VALUE))
925 cameraParameters.yFovDegree = Degree(Radian(perspective.mYFov));
929 cameraParameters.yFovDegree = Degree(gltf2::UNDEFINED_FLOAT_VALUE);
931 cameraParameters.zNear = perspective.mZNear;
932 cameraParameters.zFar = perspective.mZFar;
933 // TODO: yes, we seem to ignore aspectRatio in CameraParameters.
937 auto& ortho = camera.mOrthographic;
938 if(!Dali::Equals(ortho.mYMag, gltf2::UNDEFINED_FLOAT_VALUE) && !Dali::Equals(ortho.mXMag, gltf2::UNDEFINED_FLOAT_VALUE))
940 cameraParameters.orthographicSize = ortho.mYMag * .5f;
941 cameraParameters.aspectRatio = ortho.mXMag / ortho.mYMag;
945 cameraParameters.orthographicSize = gltf2::UNDEFINED_FLOAT_VALUE;
946 cameraParameters.aspectRatio = gltf2::UNDEFINED_FLOAT_VALUE;
948 cameraParameters.zNear = ortho.mZNear;
949 cameraParameters.zFar = ortho.mZFar;
952 cameraParameters.name = std::string(camera.mName);
955 void ConvertNode(gltf2::Node const& node, const Index gltfIndex, Index parentIndex, ConversionContext& context, bool isMRendererModel)
957 auto& output = context.mOutput;
958 auto& scene = output.mScene;
959 auto& resources = output.mResources;
961 const auto index = scene.GetNodeCount();
962 auto weakNode = scene.AddNode([&]() {
963 std::unique_ptr<NodeDefinition> nodeDefinition{new NodeDefinition()};
965 nodeDefinition->mParentIdx = parentIndex;
966 nodeDefinition->mName = node.mName;
967 if(nodeDefinition->mName.empty())
969 // TODO: Production quality generation of unique names.
970 nodeDefinition->mName = std::to_string(reinterpret_cast<uintptr_t>(nodeDefinition.get()));
973 if(!node.mSkin) // Nodes with skinned meshes are not supposed to have local transforms.
975 nodeDefinition->mPosition = node.mTranslation;
976 nodeDefinition->mOrientation = node.mRotation;
977 nodeDefinition->mScale = node.mScale;
979 if(isMRendererModel && node.mName == ROOT_NODE_NAME && node.mScale == SCALE_TO_ADJUST)
981 nodeDefinition->mScale *= 0.01f;
985 return nodeDefinition; }());
988 ExceptionFlinger(ASSERT_LOCATION) << "Node name '" << node.mName << "' is not unique; scene is invalid.";
991 context.mNodeIndices.RegisterMapping(gltfIndex, index);
993 Index skeletonIdx = node.mSkin ? node.mSkin.GetIndex() : INVALID_INDEX;
996 auto& mesh = *node.mMesh;
997 uint32_t primitiveCount = mesh.mPrimitives.size();
998 auto meshIndex = context.mMeshIds[node.mMesh.GetIndex()];
999 weakNode->mRenderables.reserve(primitiveCount);
1000 for(uint32_t i = 0; i < primitiveCount; ++i)
1002 std::unique_ptr<NodeDefinition::Renderable> renderable;
1003 auto modelRenderable = MakeModelRenderable(mesh.mPrimitives[i], context);
1004 modelRenderable->mMeshIdx = meshIndex + i;
1006 DALI_ASSERT_DEBUG(resources.mMeshes[modelRenderable->mMeshIdx].first.mSkeletonIdx == INVALID_INDEX ||
1007 resources.mMeshes[modelRenderable->mMeshIdx].first.mSkeletonIdx == skeletonIdx);
1008 resources.mMeshes[modelRenderable->mMeshIdx].first.mSkeletonIdx = skeletonIdx;
1010 renderable.reset(modelRenderable);
1011 weakNode->mRenderables.push_back(std::move(renderable));
1017 CameraParameters cameraParameters;
1018 ConvertCamera(*node.mCamera, cameraParameters);
1020 cameraParameters.matrix.SetTransformComponents(node.mScale, node.mRotation, node.mTranslation);
1021 output.mCameraParameters.push_back(cameraParameters);
1024 for(auto& child : node.mChildren)
1026 ConvertNode(*child, child.GetIndex(), index, context, isMRendererModel);
1030 void ConvertSceneNodes(const gltf2::Scene& scene, ConversionContext& context, bool isMRendererModel)
1032 auto& outScene = context.mOutput.mScene;
1033 Index rootIndex = outScene.GetNodeCount();
1034 switch(scene.mNodes.size())
1040 ConvertNode(*scene.mNodes[0], scene.mNodes[0].GetIndex(), INVALID_INDEX, context, isMRendererModel);
1041 outScene.AddRootNode(rootIndex);
1046 std::unique_ptr<NodeDefinition> sceneRoot{new NodeDefinition()};
1047 sceneRoot->mName = "GLTF_LOADER_SCENE_ROOT_" + std::to_string(outScene.GetRoots().size());
1049 outScene.AddNode(std::move(sceneRoot));
1050 outScene.AddRootNode(rootIndex);
1052 for(auto& node : scene.mNodes)
1054 ConvertNode(*node, node.GetIndex(), rootIndex, context, isMRendererModel);
1061 void ConvertNodes(const gltf2::Document& document, ConversionContext& context, bool isMRendererModel)
1063 if(!document.mScenes.empty())
1065 uint32_t rootSceneIndex = 0u;
1068 rootSceneIndex = document.mScene.GetIndex();
1070 ConvertSceneNodes(document.mScenes[rootSceneIndex], context, isMRendererModel);
1072 for(uint32_t i = 0; i < rootSceneIndex; ++i)
1074 ConvertSceneNodes(document.mScenes[i], context, isMRendererModel);
1077 for(uint32_t i = rootSceneIndex + 1; i < document.mScenes.size(); ++i)
1079 ConvertSceneNodes(document.mScenes[i], context, isMRendererModel);
1084 template<typename T>
1085 void LoadDataFromAccessor(ConversionContext& context, uint32_t bufferIndex, Vector<T>& dataBuffer, uint32_t offset, uint32_t size)
1087 if(bufferIndex >= context.mOutput.mResources.mBuffers.size())
1089 DALI_LOG_ERROR("Invailid buffer index\n");
1093 auto& buffer = context.mOutput.mResources.mBuffers[bufferIndex];
1094 if(!buffer.IsAvailable())
1096 DALI_LOG_ERROR("Failed to load from buffer stream.\n");
1098 auto& stream = buffer.GetBufferStream();
1100 stream.seekg(offset, stream.beg);
1101 stream.read(reinterpret_cast<char*>(dataBuffer.Begin()), static_cast<std::streamsize>(static_cast<size_t>(size)));
1104 template<typename T>
1105 float LoadDataFromAccessors(ConversionContext& context, const gltf2::Accessor& input, const gltf2::Accessor& output, Vector<float>& inputDataBuffer, Vector<T>& outputDataBuffer)
1107 inputDataBuffer.Resize(input.mCount);
1108 outputDataBuffer.Resize(output.mCount);
1110 const uint32_t inputDataBufferSize = input.GetBytesLength();
1111 const uint32_t outputDataBufferSize = output.GetBytesLength();
1113 LoadDataFromAccessor<float>(context, output.mBufferView->mBuffer.GetIndex(), inputDataBuffer, input.mBufferView->mByteOffset + input.mByteOffset, inputDataBufferSize);
1114 LoadDataFromAccessor<T>(context, output.mBufferView->mBuffer.GetIndex(), outputDataBuffer, output.mBufferView->mByteOffset + output.mByteOffset, outputDataBufferSize);
1115 ApplyAccessorMinMax(input, reinterpret_cast<float*>(inputDataBuffer.begin()));
1116 ApplyAccessorMinMax(output, reinterpret_cast<float*>(outputDataBuffer.begin()));
1118 return inputDataBuffer[input.mCount - 1u];
1121 bool IsFirstFrameValueEmpty(const uint32_t inputCount, const Vector<float>& inputBuffer)
1123 return (inputCount > 0 && !Dali::EqualsZero(inputBuffer[0]));
1126 template<typename T>
1127 float LoadKeyFrames(ConversionContext& context, const gltf2::Animation::Channel& channel, KeyFrames& keyFrames, gltf2::Animation::Channel::Target::Type type)
1129 const gltf2::Accessor& input = *channel.mSampler->mInput;
1130 const gltf2::Accessor& output = *channel.mSampler->mOutput;
1132 Vector<float> inputDataBuffer;
1133 Vector<T> outputDataBuffer;
1135 const float duration = std::max(LoadDataFromAccessors<T>(context, input, output, inputDataBuffer, outputDataBuffer), AnimationDefinition::MIN_DURATION_SECONDS);
1137 if(IsFirstFrameValueEmpty(input.mCount, inputDataBuffer))
1139 keyFrames.Add(0.0f, outputDataBuffer[0]);
1142 for(uint32_t i = 0; i < input.mCount; ++i)
1144 keyFrames.Add(inputDataBuffer[i] / duration, outputDataBuffer[i]);
1150 float LoadBlendShapeKeyFrames(ConversionContext& context, const gltf2::Animation::Channel& channel, Index nodeIndex, uint32_t& propertyIndex, AnimationDefinition& animationDefinition)
1152 const gltf2::Accessor& input = *channel.mSampler->mInput;
1153 const gltf2::Accessor& output = *channel.mSampler->mOutput;
1155 Vector<float> inputDataBuffer;
1156 Vector<float> outputDataBuffer;
1158 const float duration = std::max(LoadDataFromAccessors<float>(context, input, output, inputDataBuffer, outputDataBuffer), AnimationDefinition::MIN_DURATION_SECONDS);
1160 char weightNameBuffer[32];
1161 auto prefixSize = snprintf(weightNameBuffer, sizeof(weightNameBuffer), "%s[", BLEND_SHAPE_WEIGHTS_UNIFORM.data());
1162 char* const pWeightName = weightNameBuffer + prefixSize;
1163 const auto remainingSize = sizeof(weightNameBuffer) - prefixSize;
1164 for(uint32_t weightIndex = 0u, endWeightIndex = channel.mSampler->mOutput->mCount / channel.mSampler->mInput->mCount; weightIndex < endWeightIndex; ++weightIndex)
1166 AnimatedProperty animatedProperty;
1168 animatedProperty.mNodeIndex = nodeIndex;
1169 snprintf(pWeightName, remainingSize, "%d]", weightIndex);
1170 animatedProperty.mPropertyName = std::string(weightNameBuffer);
1172 animatedProperty.mKeyFrames = KeyFrames::New();
1174 if(IsFirstFrameValueEmpty(input.mCount, inputDataBuffer))
1176 animatedProperty.mKeyFrames.Add(0.0f, outputDataBuffer[weightIndex]);
1179 for(uint32_t i = 0; i < input.mCount; ++i)
1181 animatedProperty.mKeyFrames.Add(inputDataBuffer[i] / duration, outputDataBuffer[i * endWeightIndex + weightIndex]);
1184 animatedProperty.mTimePeriod = {0.f, duration};
1186 animationDefinition.SetProperty(propertyIndex++, std::move(animatedProperty));
1192 template<typename T>
1193 float LoadAnimation(AnimationDefinition& animationDefinition, Index nodeIndex, Index propertyIndex, const std::string& propertyName, const gltf2::Animation::Channel& channel, ConversionContext& context)
1195 AnimatedProperty animatedProperty;
1196 animatedProperty.mNodeIndex = nodeIndex;
1197 animatedProperty.mPropertyName = propertyName;
1199 animatedProperty.mKeyFrames = KeyFrames::New();
1200 float duration = LoadKeyFrames<T>(context, channel, animatedProperty.mKeyFrames, channel.mTarget.mPath);
1201 animatedProperty.mTimePeriod = {0.f, duration};
1203 animationDefinition.SetProperty(propertyIndex, std::move(animatedProperty));
1207 void ConvertAnimations(const gltf2::Document& document, ConversionContext& context)
1209 auto& output = context.mOutput;
1211 output.mAnimationDefinitions.reserve(output.mAnimationDefinitions.size() + document.mAnimations.size());
1213 for(const auto& animation : document.mAnimations)
1215 AnimationDefinition animationDefinition;
1217 if(!animation.mName.empty())
1219 animationDefinition.SetName(animation.mName.data());
1222 uint32_t numberOfProperties = 0u;
1223 for(const auto& channel : animation.mChannels)
1225 if(channel.mTarget.mPath == gltf2::Animation::Channel::Target::WEIGHTS)
1227 numberOfProperties += channel.mSampler->mOutput->mCount / channel.mSampler->mInput->mCount;
1231 numberOfProperties++;
1234 animationDefinition.ReserveSize(numberOfProperties);
1236 Index propertyIndex = 0u;
1237 for(const auto& channel : animation.mChannels)
1239 Index nodeIndex = context.mNodeIndices.GetRuntimeId(channel.mTarget.mNode.GetIndex());
1240 float duration = 0.f;
1242 switch(channel.mTarget.mPath)
1244 case gltf2::Animation::Channel::Target::TRANSLATION:
1246 duration = LoadAnimation<Vector3>(animationDefinition, nodeIndex, propertyIndex, POSITION_PROPERTY.data(), channel, context);
1249 case gltf2::Animation::Channel::Target::ROTATION:
1251 duration = LoadAnimation<Quaternion>(animationDefinition, nodeIndex, propertyIndex, ORIENTATION_PROPERTY.data(), channel, context);
1254 case gltf2::Animation::Channel::Target::SCALE:
1256 duration = LoadAnimation<Vector3>(animationDefinition, nodeIndex, propertyIndex, SCALE_PROPERTY.data(), channel, context);
1259 case gltf2::Animation::Channel::Target::WEIGHTS:
1261 duration = LoadBlendShapeKeyFrames(context, channel, nodeIndex, propertyIndex, animationDefinition);
1267 // nothing to animate.
1272 animationDefinition.SetDuration(std::max(duration, animationDefinition.GetDuration()));
1277 output.mAnimationDefinitions.push_back(std::move(animationDefinition));
1281 void ProcessSkins(const gltf2::Document& document, ConversionContext& context)
1283 // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skininversebindmatrices
1284 // If an inverseBindMatrices accessor was provided, we'll load the joint data from the buffer,
1285 // otherwise we'll set identity matrices for inverse bind pose.
1286 struct IInverseBindMatrixProvider
1288 virtual ~IInverseBindMatrixProvider()
1291 virtual void Provide(Matrix& inverseBindMatrix) = 0;
1294 struct InverseBindMatrixAccessor : public IInverseBindMatrixProvider
1296 std::istream& mStream;
1297 const uint32_t mElementSizeBytes;
1299 InverseBindMatrixAccessor(const gltf2::Accessor& accessor, ConversionContext& context)
1300 : mStream(context.mOutput.mResources.mBuffers[accessor.mBufferView->mBuffer.GetIndex()].GetBufferStream()),
1301 mElementSizeBytes(accessor.GetElementSizeBytes())
1303 DALI_ASSERT_DEBUG(accessor.mType == gltf2::AccessorType::MAT4 && accessor.mComponentType == gltf2::Component::FLOAT);
1305 if(!mStream.rdbuf()->in_avail())
1307 DALI_LOG_ERROR("Failed to load from stream\n");
1310 mStream.seekg(accessor.mBufferView->mByteOffset + accessor.mByteOffset, mStream.beg);
1313 virtual void Provide(Matrix& inverseBindMatrix) override
1315 DALI_ASSERT_ALWAYS(mStream.read(reinterpret_cast<char*>(inverseBindMatrix.AsFloat()), static_cast<std::streamsize>(static_cast<size_t>(mElementSizeBytes))));
1319 struct DefaultInverseBindMatrixProvider : public IInverseBindMatrixProvider
1321 virtual void Provide(Matrix& inverseBindMatrix) override
1323 inverseBindMatrix = Matrix::IDENTITY;
1327 auto& resources = context.mOutput.mResources;
1328 resources.mSkeletons.reserve(document.mSkins.size());
1330 for(auto& skin : document.mSkins)
1332 std::unique_ptr<IInverseBindMatrixProvider> inverseBindMatrixProvider;
1333 if(skin.mInverseBindMatrices)
1335 inverseBindMatrixProvider.reset(new InverseBindMatrixAccessor(*skin.mInverseBindMatrices, context));
1339 inverseBindMatrixProvider.reset(new DefaultInverseBindMatrixProvider());
1342 SkeletonDefinition skeleton;
1343 if(skin.mSkeleton.GetIndex() != INVALID_INDEX)
1345 skeleton.mRootNodeIdx = context.mNodeIndices.GetRuntimeId(skin.mSkeleton.GetIndex());
1348 skeleton.mJoints.resize(skin.mJoints.size());
1349 auto iJoint = skeleton.mJoints.begin();
1350 for(auto& joint : skin.mJoints)
1352 iJoint->mNodeIdx = context.mNodeIndices.GetRuntimeId(joint.GetIndex());
1354 inverseBindMatrixProvider->Provide(iJoint->mInverseBindMatrix);
1359 resources.mSkeletons.push_back(std::move(skeleton));
1363 void SetObjectReaders()
1365 json::SetObjectReader(GetBufferReader());
1366 json::SetObjectReader(GetBufferViewReader());
1367 json::SetObjectReader(GetBufferViewClientReader());
1368 json::SetObjectReader(GetComponentTypedBufferViewClientReader());
1369 json::SetObjectReader(GetAccessorSparseReader());
1370 json::SetObjectReader(GetAccessorReader());
1371 json::SetObjectReader(GetImageReader());
1372 json::SetObjectReader(GetSamplerReader());
1373 json::SetObjectReader(GetTextureReader());
1374 json::SetObjectReader(GetTextureInfoReader());
1375 json::SetObjectReader(GetMaterialPbrReader());
1376 json::SetObjectReader(GetMaterialSpecularReader());
1377 json::SetObjectReader(GetMaterialIorReader());
1378 json::SetObjectReader(GetMaterialExtensionsReader());
1379 json::SetObjectReader(GetMaterialReader());
1380 json::SetObjectReader(GetMeshPrimitiveReader());
1381 json::SetObjectReader(GetMeshExtrasReader());
1382 json::SetObjectReader(GetMeshExtensionsReader());
1383 json::SetObjectReader(GetMeshReader());
1384 json::SetObjectReader(GetSkinReader());
1385 json::SetObjectReader(GetCameraPerspectiveReader());
1386 json::SetObjectReader(GetCameraOrthographicReader());
1387 json::SetObjectReader(GetCameraReader());
1388 json::SetObjectReader(GetNodeReader());
1389 json::SetObjectReader(GetAnimationSamplerReader());
1390 json::SetObjectReader(GetAnimationChannelTargetReader());
1391 json::SetObjectReader(GetAnimationChannelReader());
1392 json::SetObjectReader(GetAnimationReader());
1393 json::SetObjectReader(GetSceneReader());
1396 void SetDefaultEnvironmentMap(const gltf2::Document& document, ConversionContext& context)
1398 EnvironmentDefinition environmentDefinition;
1399 environmentDefinition.mUseBrdfTexture = true;
1400 environmentDefinition.mIblIntensity = Scene3D::Loader::EnvironmentDefinition::GetDefaultIntensity();
1401 context.mOutput.mResources.mEnvironmentMaps.push_back({std::move(environmentDefinition), EnvironmentDefinition::Textures()});
1404 void InitializeGltfLoader()
1406 static Dali::Mutex initializeMutex;
1407 // Set ObjectReader only once (for all gltf loading).
1408 static bool setObjectReadersRequired = true;
1410 Mutex::ScopedLock lock(initializeMutex);
1411 if(setObjectReadersRequired)
1413 // NOTE: only referencing own, anonymous namespace, const objects; the pointers will never need to change.
1415 setObjectReadersRequired = false;
1420 const std::string_view GetRendererModelIdentification()
1422 return MRENDERER_MODEL_IDENTIFICATION;
1425 void ReadDocument(const json_object_s& jsonObject, gltf2::Document& document)
1427 GetDocumentReader().Read(jsonObject, document);
1430 void ReadDocumentFromParsedData(const json_object_s& jsonObject, gltf2::Document& document)
1432 static Dali::Mutex readMutex;
1433 Mutex::ScopedLock lock(readMutex);
1434 gt::SetRefReaderObject(document);
1435 Gltf2Util::ReadDocument(jsonObject, document);
1438 bool GenerateDocument(json::unique_ptr& root, gt::Document& document, bool& isMRendererModel)
1440 auto& rootObject = js::Cast<json_object_s>(*root);
1441 auto jsonAsset = js::FindObjectChild("asset", rootObject);
1443 auto jsAssetVersion = js::FindObjectChild("version", js::Cast<json_object_s>(*jsonAsset));
1446 document.mAsset.mVersion = js::Read::StringView(*jsAssetVersion);
1449 auto jsAssetGenerator = js::FindObjectChild("generator", js::Cast<json_object_s>(*jsonAsset));
1450 if(jsAssetGenerator)
1452 document.mAsset.mGenerator = js::Read::StringView(*jsAssetGenerator);
1453 isMRendererModel = (document.mAsset.mGenerator.find(Gltf2Util::GetRendererModelIdentification().data()) != std::string_view::npos);
1456 Gltf2Util::InitializeGltfLoader();
1457 Gltf2Util::ReadDocumentFromParsedData(rootObject, document);
1462 void ConvertGltfToContext(gt::Document& document, Gltf2Util::ConversionContext& context, bool isMRendererModel)
1464 Gltf2Util::ConvertBuffers(document, context);
1465 Gltf2Util::ConvertMaterials(document, context);
1466 Gltf2Util::ConvertMeshes(document, context);
1467 Gltf2Util::ConvertNodes(document, context, isMRendererModel);
1468 Gltf2Util::ConvertAnimations(document, context);
1469 Gltf2Util::ProcessSkins(document, context);
1471 // Set Default Environment map
1472 Gltf2Util::SetDefaultEnvironmentMap(document, context);
1475 } // namespace Gltf2Util
1477 } // namespace Dali::Scene3D::Loader::Internal