X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-scene3d%2Finternal%2Floader%2Fgltf2-util.cpp;h=6e572b7ca264a71ca35b50fe1bb77dae106622f4;hb=3520b9be81a77bd7568197379575ee76ca9aa75d;hp=15d91b663a25980cdf7ae13433db684552ea344f;hpb=c9ec8565c4fa8482897915f8ac0cce8179ec4dc0;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-scene3d/internal/loader/gltf2-util.cpp b/dali-scene3d/internal/loader/gltf2-util.cpp index 15d91b6..6e572b7 100644 --- a/dali-scene3d/internal/loader/gltf2-util.cpp +++ b/dali-scene3d/internal/loader/gltf2-util.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 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. @@ -19,6 +19,8 @@ #include // EXTERNAL INCLUDES +#include +#include #include #include #include ///< for std::numeric_limits @@ -46,19 +48,15 @@ static const Geometry::Type GLTF2_TO_DALI_PRIMITIVES[]{ Geometry::TRIANGLE_STRIP, Geometry::TRIANGLE_FAN}; //...because Dali swaps the last two. -static struct AttributeMapping -{ - gltf2::Attribute::Type mType; - MeshDefinition::Accessor MeshDefinition::*mAccessor; - uint16_t mElementSizeRequired; -} ATTRIBUTE_MAPPINGS[]{ - {gltf2::Attribute::NORMAL, &MeshDefinition::mNormals, sizeof(Vector3)}, - {gltf2::Attribute::TANGENT, &MeshDefinition::mTangents, sizeof(Vector3)}, - {gltf2::Attribute::TEXCOORD_0, &MeshDefinition::mTexCoords, sizeof(Vector2)}, - {gltf2::Attribute::COLOR_0, &MeshDefinition::mColors, sizeof(Vector4)}, - {gltf2::Attribute::JOINTS_0, &MeshDefinition::mJoints0, sizeof(Vector4)}, - {gltf2::Attribute::WEIGHTS_0, &MeshDefinition::mWeights0, sizeof(Vector4)}, +static const Dali::Scripting::StringEnum EXTENSION_STRING_TABLE[] = + { + {"NONE", gltf2::ExtensionFlags::NONE}, + {"KHR_mesh_quantization", gltf2::ExtensionFlags::KHR_MESH_QUANTIZATION}, + {"KHR_texture_transform", gltf2::ExtensionFlags::KHR_TEXTURE_TRANSFORM}, + {"KHR_materials_ior", gltf2::ExtensionFlags::KHR_MATERIALS_IOR}, + {"KHR_materials_specular", gltf2::ExtensionFlags::KHR_MATERIALS_SPECULAR}, }; +static const unsigned int EXTENSION_STRING_TABLE_COUNT = sizeof(EXTENSION_STRING_TABLE) / sizeof(EXTENSION_STRING_TABLE[0]); std::vector ReadAnimationArray(const json_value_s& j) { @@ -133,9 +131,7 @@ const json::Reader& GetAccessorReader() .Register(*new json::Property>("bufferView", gltf2::RefReader::Read, &gltf2::Accessor::mBufferView)) - .Register(*new json::Property("byteOffset", - json::Read::Number, - &gltf2::Accessor::mByteOffset)) + .Register(*new json::Property("byteOffset", json::Read::Number, &gltf2::Accessor::mByteOffset)) .Register(*new json::Property("componentType", json::Read::Enum, &gltf2::Accessor::mComponentType)) @@ -177,13 +173,31 @@ const json::Reader& GetTextureReader() return TEXURE_READER; } +const json::Reader& GetTextureTransformReader() +{ + static const auto TEXURE_TRANSFORM_READER = std::move(json::Reader() + .Register(*json::MakeProperty("rotation", json::Read::Number, &gltf2::TextureTransform::mRotation)) + .Register(*json::MakeProperty("offset", gltf2::ReadDaliVector, &gltf2::TextureTransform::mUvOffset)) + .Register(*json::MakeProperty("scale", gltf2::ReadDaliVector, &gltf2::TextureTransform::mUvScale)) + .Register(*json::MakeProperty("texCoord", json::Read::Number, &gltf2::TextureTransform::mTexCoord))); + return TEXURE_TRANSFORM_READER; +} + +const json::Reader& GetTextureExtensionsReader() +{ + static const auto TEXTURE_EXTENSION_READER = std::move(json::Reader() + .Register(*json::MakeProperty("KHR_texture_transform", json::ObjectReader::Read, &gltf2::TextureExtensions::mTextureTransform))); + return TEXTURE_EXTENSION_READER; +} + const json::Reader& GetTextureInfoReader() { static const auto TEXURE_INFO_READER = std::move(json::Reader() .Register(*json::MakeProperty("index", gltf2::RefReader::Read, &gltf2::TextureInfo::mTexture)) .Register(*json::MakeProperty("texCoord", json::Read::Number, &gltf2::TextureInfo::mTexCoord)) .Register(*json::MakeProperty("scale", json::Read::Number, &gltf2::TextureInfo::mScale)) - .Register(*json::MakeProperty("strength", json::Read::Number, &gltf2::TextureInfo::mStrength))); + .Register(*json::MakeProperty("strength", json::Read::Number, &gltf2::TextureInfo::mStrength)) + .Register(*json::MakeProperty("extensions", json::ObjectReader::Read, &gltf2::TextureInfo::mTextureExtensions))); return TEXURE_INFO_READER; } @@ -239,7 +253,26 @@ const json::Reader& GetMaterialReader() return MATERIAL_READER; } -std::map> ReadMeshPrimitiveAttributes(const json_value_s& j) +std::map> ReadMeshPrimitiveAttributes(const json_value_s& j) +{ + auto& jsonObject = json::Cast(j); + std::map> result; + + auto element = jsonObject.start; + while(element) + { + auto jsonString = *element->name; + + gltf2::Attribute::HashType hash = gltf2::Attribute::HashFromString(jsonString.string, jsonString.string_size); + + result[hash] = + gltf2::RefReader::Read(*element->value); + element = element->next; + } + return result; +} + +std::map> ReadMeshPrimitiveAttributes2(const json_value_s& j) { auto& jsonObject = json::Cast(j); std::map> result; @@ -247,9 +280,11 @@ std::map> ReadMeshPrimitiveA auto element = jsonObject.start; while(element) { - auto jsonString = *element->name; - result[gltf2::Attribute::FromString(jsonString.string, jsonString.string_size)] = gltf2::RefReader::Read(*element->value); - element = element->next; + auto jsonString = *element->name; + + result[gltf2::Attribute::TargetFromString(jsonString.string, jsonString.string_size)] = gltf2::RefReader::Read(*element->value); + + element = element->next; } return result; } @@ -264,7 +299,7 @@ std::vector>> ReadM auto element = jsonObject.start; while(element) { - result.push_back(std::move(ReadMeshPrimitiveAttributes(*element->value))); + result.push_back(std::move(ReadMeshPrimitiveAttributes2(*element->value))); element = element->next; } @@ -482,6 +517,12 @@ const json::Reader& GetDocumentReader() .Register(*json::MakeProperty("animations", ReadAnimationArray, &gltf2::Document::mAnimations)) + .Register(*json::MakeProperty("extensionsRequired", + json::Read::Array, + &gltf2::Document::mExtensionsRequired)) + .Register(*json::MakeProperty("extensionsUsed", + json::Read::Array, + &gltf2::Document::mExtensionsUsed)) .Register(*json::MakeProperty("scenes", json::Read::Array::Read>, &gltf2::Document::mScenes)) @@ -561,22 +602,27 @@ TextureDefinition ConvertTextureInfo(const gltf2::TextureInfo& textureInfo, Conv { auto& stream = context.mOutput.mResources.mBuffers[bufferIndex].GetBufferStream(); stream.clear(); - stream.seekg(textureInfo.mTexture->mSource->mBufferView->mByteOffset, stream.beg); + stream.seekg(static_cast(static_cast(textureInfo.mTexture->mSource->mBufferView->mByteOffset)), stream.beg); std::vector dataBuffer; dataBuffer.resize(textureInfo.mTexture->mSource->mBufferView->mByteLength); stream.read(reinterpret_cast(dataBuffer.data()), static_cast(static_cast(textureInfo.mTexture->mSource->mBufferView->mByteLength))); - return TextureDefinition{std::move(dataBuffer), ConvertSampler(textureInfo.mTexture->mSampler), metaData.mMinSize, metaData.mSamplingMode}; + return TextureDefinition{std::move(dataBuffer), ConvertSampler(textureInfo.mTexture->mSampler), metaData.mMinSize, metaData.mSamplingMode, textureInfo.mTextureExtensions.mTextureTransform.GetTransform()}; } return TextureDefinition(); } else { - return TextureDefinition{uri, ConvertSampler(textureInfo.mTexture->mSampler), metaData.mMinSize, metaData.mSamplingMode}; + return TextureDefinition{uri, ConvertSampler(textureInfo.mTexture->mSampler), metaData.mMinSize, metaData.mSamplingMode, textureInfo.mTextureExtensions.mTextureTransform.GetTransform()}; } } void AddTextureStage(uint32_t semantic, MaterialDefinition& materialDefinition, gltf2::TextureInfo textureInfo, const Dali::Scene3D::Loader::ImageMetadata& metaData, ConversionContext& context) { + // Overrides the textureInfo texCoord value if KHR_texture_transform extension is supported and texCoord value is supplied. + if(textureInfo.mTextureExtensions && textureInfo.mTexCoord != textureInfo.mTextureExtensions.mTextureTransform.mTexCoord && textureInfo.mTextureExtensions.mTextureTransform.mTexCoord != 0u) + { + textureInfo.mTexCoord = textureInfo.mTextureExtensions.mTextureTransform.mTexCoord; + } materialDefinition.mTextureStages.push_back({semantic, ConvertTextureInfo(textureInfo, context, metaData)}); materialDefinition.mFlags |= semantic; } @@ -750,11 +796,162 @@ MeshDefinition::Accessor ConvertMeshPrimitiveAccessor(const gltf2::Accessor& acc accessor.mMin, accessor.mMax}), std::move(sparseBlob), - accessor.mBufferView ? accessor.mBufferView->mBuffer.GetIndex() : 0}; + accessor.mBufferView ? accessor.mBufferView->mBuffer.GetIndex() : 0, + accessor.mNormalized}; +} + +MeshDefinition::Accessor* GetAccessorFromAttribute(gltf2::Attribute::HashType attributeHash, + MeshDefinition& meshDefinition, + bool& needNormals, + bool& needTangents) +{ + MeshDefinition::Accessor* accessorDest{nullptr}; + + switch(gltf2::Attribute::TypeFromHash(attributeHash)) + { + case gltf2::Attribute::POSITION: + { + accessorDest = &meshDefinition.mPositions; + break; + } + case gltf2::Attribute::NORMAL: + { + accessorDest = &meshDefinition.mNormals; + needNormals = false; + break; + } + case gltf2::Attribute::TANGENT: + { + accessorDest = &meshDefinition.mTangents; + needTangents = false; + break; + } + case gltf2::Attribute::TEXCOORD_N: + { + meshDefinition.mTexCoords.emplace_back(MeshDefinition::Accessor{}); + accessorDest = &meshDefinition.mTexCoords.back(); + break; + } + case gltf2::Attribute::COLOR_N: + { + meshDefinition.mColors.emplace_back(MeshDefinition::Accessor{}); + accessorDest = &meshDefinition.mColors.back(); + break; + } + case gltf2::Attribute::JOINTS_N: + { + if(meshDefinition.mJoints.size() < MeshDefinition::MAX_NUMBER_OF_JOINT_SETS) + { + meshDefinition.mJoints.emplace_back(MeshDefinition::Accessor{}); + accessorDest = &meshDefinition.mJoints.back(); + } + break; + } + case gltf2::Attribute::WEIGHTS_N: + { + if(meshDefinition.mWeights.size() < MeshDefinition::MAX_NUMBER_OF_JOINT_SETS) + { + meshDefinition.mWeights.emplace_back(MeshDefinition::Accessor{}); + accessorDest = &meshDefinition.mWeights.back(); + } + break; + } + case gltf2::Attribute::INVALID: + { + accessorDest = nullptr; + break; + } + } + return accessorDest; +} + +void SetFlagsFromComponentType(const gltf2::Accessor& accessor, + gltf2::Attribute::HashType attributeHash, + MeshDefinition& meshDefinition, + bool isQuantized) +{ + switch(gltf2::Attribute::TypeFromHash(attributeHash)) + { + case gltf2::Attribute::POSITION: + { + if(isQuantized) + { + meshDefinition.mFlags |= (accessor.mComponentType == gltf2::Component::BYTE) * MeshDefinition::S8_POSITION; + meshDefinition.mFlags |= (accessor.mComponentType == gltf2::Component::UNSIGNED_BYTE) * MeshDefinition::U8_POSITION; + meshDefinition.mFlags |= (accessor.mComponentType == gltf2::Component::SHORT) * MeshDefinition::S16_POSITION; + meshDefinition.mFlags |= (accessor.mComponentType == gltf2::Component::UNSIGNED_SHORT) * MeshDefinition::U16_POSITION; + } + DALI_ASSERT_DEBUG((isQuantized && (MaskMatch(meshDefinition.mFlags, MeshDefinition::S8_POSITION) || MaskMatch(meshDefinition.mFlags, MeshDefinition::U8_POSITION) || MaskMatch(meshDefinition.mFlags, MeshDefinition::S16_POSITION) || MaskMatch(meshDefinition.mFlags, MeshDefinition::U16_POSITION))) || accessor.mComponentType == gltf2::Component::FLOAT); + break; + } + case gltf2::Attribute::NORMAL: + { + if(isQuantized) + { + meshDefinition.mFlags |= (accessor.mComponentType == gltf2::Component::BYTE) * MeshDefinition::S8_NORMAL; + meshDefinition.mFlags |= (accessor.mComponentType == gltf2::Component::SHORT) * MeshDefinition::S16_NORMAL; + } + + DALI_ASSERT_DEBUG((isQuantized && (MaskMatch(meshDefinition.mFlags, MeshDefinition::S8_NORMAL) || MaskMatch(meshDefinition.mFlags, MeshDefinition::S16_NORMAL))) || accessor.mComponentType == gltf2::Component::FLOAT); + break; + } + case gltf2::Attribute::TANGENT: + { + if(isQuantized) + { + meshDefinition.mFlags |= (accessor.mComponentType == gltf2::Component::BYTE) * MeshDefinition::S8_TANGENT; + meshDefinition.mFlags |= (accessor.mComponentType == gltf2::Component::SHORT) * MeshDefinition::S16_TANGENT; + } + + DALI_ASSERT_DEBUG((isQuantized && (MaskMatch(meshDefinition.mFlags, MeshDefinition::S8_TANGENT) || MaskMatch(meshDefinition.mFlags, MeshDefinition::S16_TANGENT))) || accessor.mComponentType == gltf2::Component::FLOAT); + break; + } + case gltf2::Attribute::TEXCOORD_N: + { + if(isQuantized) + { + meshDefinition.mFlags |= (accessor.mComponentType == gltf2::Component::BYTE) * MeshDefinition::S8_TEXCOORD; + meshDefinition.mFlags |= (accessor.mComponentType == gltf2::Component::UNSIGNED_BYTE) * MeshDefinition::U8_TEXCOORD; + meshDefinition.mFlags |= (accessor.mComponentType == gltf2::Component::SHORT) * MeshDefinition::S16_TEXCOORD; + meshDefinition.mFlags |= (accessor.mComponentType == gltf2::Component::UNSIGNED_SHORT) * MeshDefinition::U16_TEXCOORD; + } + DALI_ASSERT_DEBUG((isQuantized && (MaskMatch(meshDefinition.mFlags, MeshDefinition::S8_TEXCOORD) || MaskMatch(meshDefinition.mFlags, MeshDefinition::U8_TEXCOORD) || MaskMatch(meshDefinition.mFlags, MeshDefinition::S16_TEXCOORD) || MaskMatch(meshDefinition.mFlags, MeshDefinition::U16_TEXCOORD))) || accessor.mComponentType == gltf2::Component::FLOAT); + break; + } + case gltf2::Attribute::COLOR_N: + { + break; + } + case gltf2::Attribute::JOINTS_N: + { + meshDefinition.mFlags |= (accessor.mComponentType == gltf2::Component::UNSIGNED_SHORT) * MeshDefinition::U16_JOINT_IDS; + meshDefinition.mFlags |= (accessor.mComponentType == gltf2::Component::UNSIGNED_BYTE) * MeshDefinition::U8_JOINT_IDS; + DALI_ASSERT_DEBUG(MaskMatch(meshDefinition.mFlags, MeshDefinition::U16_JOINT_IDS) || + MaskMatch(meshDefinition.mFlags, MeshDefinition::U8_JOINT_IDS) || + accessor.mComponentType == gltf2::Component::FLOAT); + break; + } + case gltf2::Attribute::WEIGHTS_N: + { + meshDefinition.mFlags |= (accessor.mComponentType == gltf2::Component::UNSIGNED_SHORT) * MeshDefinition::U16_WEIGHT; + meshDefinition.mFlags |= (accessor.mComponentType == gltf2::Component::UNSIGNED_BYTE) * MeshDefinition::U8_WEIGHT; + DALI_ASSERT_DEBUG(MaskMatch(meshDefinition.mFlags, MeshDefinition::U16_WEIGHT) || + MaskMatch(meshDefinition.mFlags, MeshDefinition::U8_WEIGHT) || + accessor.mComponentType == gltf2::Component::FLOAT); + + break; + } + case gltf2::Attribute::INVALID: + { + break; + } + } } void ConvertMeshes(const gltf2::Document& document, ConversionContext& context) { + bool isQuantized = MaskMatch(document.mExtensionFlags, gltf2::ExtensionFlags::KHR_MESH_QUANTIZATION); + uint32_t meshCount = 0; context.mMeshIds.reserve(document.mMeshes.size()); for(auto& mesh : document.mMeshes) @@ -774,58 +971,40 @@ void ConvertMeshes(const gltf2::Document& document, ConversionContext& context) auto& attribs = primitive.mAttributes; meshDefinition.mPrimitiveType = GLTF2_TO_DALI_PRIMITIVES[primitive.mMode]; - auto positionIter = attribs.find(gltf2::Attribute::POSITION); - + auto positionIter = attribs.find(gltf2::Attribute::ToHash(gltf2::Attribute::POSITION, false, 0)); if(positionIter == attribs.end()) { DALI_LOG_ERROR("Primitive mesh dosn't have POSITION atrributes!"); continue; } - auto& accPositions = *positionIter->second; - meshDefinition.mPositions = ConvertMeshPrimitiveAccessor(accPositions); + auto& positionsAccessor = *positionIter->second; + // glTF2 support vector4 tangent for mesh. // https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html#meshes-overview meshDefinition.mTangentType = Property::VECTOR4; - const bool needNormalsTangents = accPositions.mType == gltf2::AccessorType::VEC3; - for(auto& attributeMapping : ATTRIBUTE_MAPPINGS) + bool needNormals = (positionsAccessor.mType == gltf2::AccessorType::VEC3); + bool needTangents = (positionsAccessor.mType == gltf2::AccessorType::VEC3); + + for(const auto& [attributeHash, accessor] : attribs) { - auto iFind = attribs.find(attributeMapping.mType); - if(iFind != attribs.end()) + MeshDefinition::Accessor* accessorDest = GetAccessorFromAttribute(attributeHash, meshDefinition, needNormals, needTangents); + if(accessorDest == nullptr) { - auto& accessor = meshDefinition.*(attributeMapping.mAccessor); - accessor = ConvertMeshPrimitiveAccessor(*iFind->second); - - if(iFind->first == gltf2::Attribute::JOINTS_0) - { - meshDefinition.mFlags |= (iFind->second->mComponentType == gltf2::Component::UNSIGNED_SHORT) * MeshDefinition::U16_JOINT_IDS; - meshDefinition.mFlags |= (iFind->second->mComponentType == gltf2::Component::UNSIGNED_BYTE) * MeshDefinition::U8_JOINT_IDS; - DALI_ASSERT_DEBUG(MaskMatch(meshDefinition.mFlags, MeshDefinition::U16_JOINT_IDS) || MaskMatch(meshDefinition.mFlags, MeshDefinition::U8_JOINT_IDS) || iFind->second->mComponentType == gltf2::Component::FLOAT); - } - if(iFind->first == gltf2::Attribute::WEIGHTS_0) - { - meshDefinition.mFlags |= (iFind->second->mComponentType == gltf2::Component::UNSIGNED_SHORT) * MeshDefinition::U16_WEIGHT; - meshDefinition.mFlags |= (iFind->second->mComponentType == gltf2::Component::UNSIGNED_BYTE) * MeshDefinition::U8_WEIGHT; - DALI_ASSERT_DEBUG(MaskMatch(meshDefinition.mFlags, MeshDefinition::U16_WEIGHT) || MaskMatch(meshDefinition.mFlags, MeshDefinition::U8_WEIGHT) || iFind->second->mComponentType == gltf2::Component::FLOAT); - } + continue; } - else if(needNormalsTangents) - { - switch(attributeMapping.mType) - { - case gltf2::Attribute::NORMAL: - meshDefinition.RequestNormals(); - break; - - case gltf2::Attribute::TANGENT: - meshDefinition.RequestTangents(); - break; + *accessorDest = ConvertMeshPrimitiveAccessor(*accessor); + SetFlagsFromComponentType(*accessor, attributeHash, meshDefinition, isQuantized); + } - default: - break; - } - } + if(needNormals) + { + meshDefinition.RequestNormals(); + } + if(needTangents) + { + meshDefinition.RequestTangents(); } if(primitive.mIndices) @@ -849,17 +1028,44 @@ void ConvertMeshes(const gltf2::Document& document, ConversionContext& context) auto it = target.find(gltf2::Attribute::POSITION); if(it != endIt) { - blendShape.deltas = ConvertMeshPrimitiveAccessor(*it->second); + blendShape.deltas = ConvertMeshPrimitiveAccessor(*it->second); + blendShape.deltas.mNormalized = it->second->mNormalized; + + if(isQuantized) + { + blendShape.mFlags |= (it->second->mComponentType == gltf2::Component::BYTE) * MeshDefinition::S8_POSITION; + blendShape.mFlags |= (it->second->mComponentType == gltf2::Component::SHORT) * MeshDefinition::S16_POSITION; + } + + DALI_ASSERT_DEBUG((isQuantized && (MaskMatch(blendShape.mFlags, MeshDefinition::S8_POSITION) || MaskMatch(blendShape.mFlags, MeshDefinition::U8_POSITION) || MaskMatch(blendShape.mFlags, MeshDefinition::S16_POSITION) || MaskMatch(blendShape.mFlags, MeshDefinition::U16_POSITION))) || it->second->mComponentType == gltf2::Component::FLOAT); } it = target.find(gltf2::Attribute::NORMAL); if(it != endIt) { - blendShape.normals = ConvertMeshPrimitiveAccessor(*it->second); + blendShape.normals = ConvertMeshPrimitiveAccessor(*it->second); + blendShape.normals.mNormalized = it->second->mNormalized; + + if(isQuantized) + { + blendShape.mFlags |= (it->second->mComponentType == gltf2::Component::BYTE) * MeshDefinition::S8_NORMAL; + blendShape.mFlags |= (it->second->mComponentType == gltf2::Component::SHORT) * MeshDefinition::S16_NORMAL; + } + + DALI_ASSERT_DEBUG((isQuantized && (MaskMatch(blendShape.mFlags, MeshDefinition::S8_NORMAL) || MaskMatch(blendShape.mFlags, MeshDefinition::S16_NORMAL))) || it->second->mComponentType == gltf2::Component::FLOAT); } it = target.find(gltf2::Attribute::TANGENT); if(it != endIt) { - blendShape.tangents = ConvertMeshPrimitiveAccessor(*it->second); + blendShape.tangents = ConvertMeshPrimitiveAccessor(*it->second); + blendShape.tangents.mNormalized = it->second->mNormalized; + + if(isQuantized) + { + blendShape.mFlags |= (it->second->mComponentType == gltf2::Component::BYTE) * MeshDefinition::S8_TANGENT; + blendShape.mFlags |= (it->second->mComponentType == gltf2::Component::SHORT) * MeshDefinition::S16_TANGENT; + } + + DALI_ASSERT_DEBUG((isQuantized && (MaskMatch(blendShape.mFlags, MeshDefinition::S8_TANGENT) || MaskMatch(blendShape.mFlags, MeshDefinition::S16_TANGENT))) || it->second->mComponentType == gltf2::Component::FLOAT); } if(!mesh.mWeights.empty()) @@ -949,6 +1155,8 @@ void ConvertCamera(const gltf2::Camera& camera, CameraParameters& cameraParamete cameraParameters.zNear = ortho.mZNear; cameraParameters.zFar = ortho.mZFar; } + + cameraParameters.name = std::string(camera.mName); } void ConvertNode(gltf2::Node const& node, const Index gltfIndex, Index parentIndex, ConversionContext& context, bool isMRendererModel) @@ -1096,7 +1304,7 @@ void LoadDataFromAccessor(ConversionContext& context, uint32_t bufferIndex, Vect } auto& stream = buffer.GetBufferStream(); stream.clear(); - stream.seekg(offset, stream.beg); + stream.seekg(static_cast(static_cast(offset)), stream.beg); stream.read(reinterpret_cast(dataBuffer.Begin()), static_cast(static_cast(size))); } @@ -1306,7 +1514,7 @@ void ProcessSkins(const gltf2::Document& document, ConversionContext& context) DALI_LOG_ERROR("Failed to load from stream\n"); } mStream.clear(); - mStream.seekg(accessor.mBufferView->mByteOffset + accessor.mByteOffset, mStream.beg); + mStream.seekg(static_cast(static_cast(accessor.mBufferView->mByteOffset + accessor.mByteOffset)), mStream.beg); } virtual void Provide(Matrix& inverseBindMatrix) override @@ -1370,6 +1578,8 @@ void SetObjectReaders() json::SetObjectReader(GetImageReader()); json::SetObjectReader(GetSamplerReader()); json::SetObjectReader(GetTextureReader()); + json::SetObjectReader(GetTextureTransformReader()); + json::SetObjectReader(GetTextureExtensionsReader()); json::SetObjectReader(GetTextureInfoReader()); json::SetObjectReader(GetMaterialPbrReader()); json::SetObjectReader(GetMaterialSpecularReader()); @@ -1460,6 +1670,20 @@ bool GenerateDocument(json::unique_ptr& root, gt::Document& document, bool& isMR void ConvertGltfToContext(gt::Document& document, Gltf2Util::ConversionContext& context, bool isMRendererModel) { + for(auto& extension : document.mExtensionsRequired) + { + gltf2::ExtensionFlags flag; + if(Dali::Scripting::GetEnumeration(extension.data(), EXTENSION_STRING_TABLE, EXTENSION_STRING_TABLE_COUNT, flag)) + { + document.mExtensionFlags |= flag; + } + else + { + DALI_LOG_ERROR("Unsupported glTF extension required: %s\n", extension.data()); + DALI_ASSERT_DEBUG(false && "Unsupported glTF extension required"); + } + } + Gltf2Util::ConvertBuffers(document, context); Gltf2Util::ConvertMaterials(document, context); Gltf2Util::ConvertMeshes(document, context); @@ -1473,4 +1697,4 @@ void ConvertGltfToContext(gt::Document& document, Gltf2Util::ConversionContext& } // namespace Gltf2Util -} // namespace Dali::Scene3D::Loader::Internal \ No newline at end of file +} // namespace Dali::Scene3D::Loader::Internal