X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-scene3d%2Finternal%2Floader%2Fgltf2-util.cpp;h=90deac919ebeb71c45bfc60fbb3bf9f0a2f81af5;hb=2116ad7b1ce51093a891ca6b3e83419b0b5b79dd;hp=219f207423208188b585cbb28cda7c0d4c3c596c;hpb=0d1a321056df3120e1896035e4a4f9617cc8a1a5;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 219f207..90deac9 100644 --- a/dali-scene3d/internal/loader/gltf2-util.cpp +++ b/dali-scene3d/internal/loader/gltf2-util.cpp @@ -281,6 +281,44 @@ const json::Reader& GetMeshPrimitiveReader() return MESH_PRIMITIVE_READER; } +const json::Reader& GetMeshExtrasReader() +{ + static const auto MESH_EXTRAS_READER = std::move(json::Reader() + .Register(*json::MakeProperty("targetNames", json::Read::Array, &gltf2::Mesh::Extras::mTargetNames))); + return MESH_EXTRAS_READER; +} + +std::vector ReadMeshExtensionsTargetsName(const json_value_s& j) +{ + auto& jsonObject = json::Cast(j); + std::vector result; + + auto element = jsonObject.start; + while(element) + { + auto jsonString = *element->name; + uint32_t index = json::Read::Number(*element->value); + + if(result.size() <= index) + { + result.resize(index + 1u); + } + + result[index] = json::Read::StringView(jsonString); + + element = element->next; + } + return result; +} + +const json::Reader& GetMeshExtensionsReader() +{ + static const auto MESH_EXTENSIONS_READER = std::move(json::Reader() + .Register(*json::MakeProperty("SXR_targets_names", ReadMeshExtensionsTargetsName, &gltf2::Mesh::Extensions::mSXRTargetsNames)) + .Register(*json::MakeProperty("avatar_shape_names", ReadMeshExtensionsTargetsName, &gltf2::Mesh::Extensions::mAvatarShapeNames))); + return MESH_EXTENSIONS_READER; +} + const json::Reader& GetMeshReader() { static const auto MESH_READER = std::move(json::Reader() @@ -288,7 +326,9 @@ const json::Reader& GetMeshReader() .Register(*json::MakeProperty("primitives", json::Read::Array::Read>, &gltf2::Mesh::mPrimitives)) - .Register(*json::MakeProperty("weights", json::Read::Array, &gltf2::Mesh::mWeights))); + .Register(*json::MakeProperty("weights", json::Read::Array, &gltf2::Mesh::mWeights)) + .Register(*json::MakeProperty("extras", json::ObjectReader::Read, &gltf2::Mesh::mExtras)) + .Register(*json::MakeProperty("extensions", json::ObjectReader::Read, &gltf2::Mesh::mExtensions))); return MESH_READER; } @@ -541,8 +581,7 @@ void AddTextureStage(uint32_t semantic, MaterialDefinition& materialDefinition, void ConvertMaterial(const gltf2::Material& material, const std::unordered_map& imageMetaData, decltype(ResourceBundle::mMaterials)& outMaterials, ConversionContext& context) { - auto getTextureMetaData = [](const std::unordered_map& metaData, const gltf2::TextureInfo& info) - { + auto getTextureMetaData = [](const std::unordered_map& metaData, const gltf2::TextureInfo& info) { if(!info.mTexture->mSource->mUri.empty()) { if(auto search = metaData.find(info.mTexture->mSource->mUri.data()); search != metaData.end()) @@ -796,6 +835,7 @@ void ConvertMeshes(const gltf2::Document& document, ConversionContext& context) { meshDefinition.mBlendShapes.reserve(primitive.mTargets.size()); meshDefinition.mBlendShapeVersion = BlendShapes::Version::VERSION_2_0; + uint32_t blendShapeIndex = 0u; for(const auto& target : primitive.mTargets) { MeshDefinition::BlendShape blendShape; @@ -822,7 +862,22 @@ void ConvertMeshes(const gltf2::Document& document, ConversionContext& context) blendShape.weight = mesh.mWeights[meshDefinition.mBlendShapes.size()]; } + // Get blendshape name from extras / SXR_targets_names / avatar_shape_names. + if(blendShapeIndex < mesh.mExtras.mTargetNames.size()) + { + blendShape.name = mesh.mExtras.mTargetNames[blendShapeIndex]; + } + else if(blendShapeIndex < mesh.mExtensions.mSXRTargetsNames.size()) + { + blendShape.name = mesh.mExtensions.mSXRTargetsNames[blendShapeIndex]; + } + else if(blendShapeIndex < mesh.mExtensions.mAvatarShapeNames.size()) + { + blendShape.name = mesh.mExtensions.mAvatarShapeNames[blendShapeIndex]; + } + meshDefinition.mBlendShapes.push_back(std::move(blendShape)); + ++blendShapeIndex; } } @@ -900,8 +955,7 @@ void ConvertNode(gltf2::Node const& node, const Index gltfIndex, Index parentInd auto& resources = output.mResources; const auto index = scene.GetNodeCount(); - auto weakNode = scene.AddNode([&]() - { + auto weakNode = scene.AddNode([&]() { std::unique_ptr nodeDefinition{new NodeDefinition()}; nodeDefinition->mParentIdx = parentIndex; @@ -1333,6 +1387,8 @@ void SetObjectReaders() json::SetObjectReader(GetMaterialExtensionsReader()); json::SetObjectReader(GetMaterialReader()); json::SetObjectReader(GetMeshPrimitiveReader()); + json::SetObjectReader(GetMeshExtrasReader()); + json::SetObjectReader(GetMeshExtensionsReader()); json::SetObjectReader(GetMeshReader()); json::SetObjectReader(GetSkinReader()); json::SetObjectReader(GetCameraPerspectiveReader());