return MESH_PRIMITIVE_READER;
}
+const json::Reader<gltf2::Mesh::Extras>& GetMeshExtrasReader()
+{
+ static const auto MESH_EXTRAS_READER = std::move(json::Reader<gltf2::Mesh::Extras>()
+ .Register(*json::MakeProperty("targetNames", json::Read::Array<std::string_view, json::Read::StringView>, &gltf2::Mesh::Extras::mTargetNames)));
+ return MESH_EXTRAS_READER;
+}
+
+std::vector<std::string_view> ReadMeshExtensionsTargetsName(const json_value_s& j)
+{
+ auto& jsonObject = json::Cast<json_object_s>(j);
+ std::vector<std::string_view> result;
+
+ auto element = jsonObject.start;
+ while(element)
+ {
+ auto jsonString = *element->name;
+ uint32_t index = json::Read::Number<uint32_t>(*element->value);
+
+ if(result.size() <= index)
+ {
+ result.resize(index + 1u);
+ }
+
+ result[index] = json::Read::StringView(jsonString);
+
+ element = element->next;
+ }
+ return result;
+}
+
+const json::Reader<gltf2::Mesh::Extensions>& GetMeshExtensionsReader()
+{
+ static const auto MESH_EXTENSIONS_READER = std::move(json::Reader<gltf2::Mesh::Extensions>()
+ .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<gltf2::Mesh>& GetMeshReader()
{
static const auto MESH_READER = std::move(json::Reader<gltf2::Mesh>()
.Register(*json::MakeProperty("primitives",
json::Read::Array<gltf2::Mesh::Primitive, json::ObjectReader<gltf2::Mesh::Primitive>::Read>,
&gltf2::Mesh::mPrimitives))
- .Register(*json::MakeProperty("weights", json::Read::Array<float, json::Read::Number>, &gltf2::Mesh::mWeights)));
+ .Register(*json::MakeProperty("weights", json::Read::Array<float, json::Read::Number>, &gltf2::Mesh::mWeights))
+ .Register(*json::MakeProperty("extras", json::ObjectReader<gltf2::Mesh::Extras>::Read, &gltf2::Mesh::mExtras))
+ .Register(*json::MakeProperty("extensions", json::ObjectReader<gltf2::Mesh::Extensions>::Read, &gltf2::Mesh::mExtensions)));
return MESH_READER;
}
void ConvertMaterial(const gltf2::Material& material, const std::unordered_map<std::string, ImageMetadata>& imageMetaData, decltype(ResourceBundle::mMaterials)& outMaterials, ConversionContext& context)
{
- auto getTextureMetaData = [](const std::unordered_map<std::string, ImageMetadata>& metaData, const gltf2::TextureInfo& info)
- {
+ auto getTextureMetaData = [](const std::unordered_map<std::string, ImageMetadata>& metaData, const gltf2::TextureInfo& info) {
if(!info.mTexture->mSource->mUri.empty())
{
if(auto search = metaData.find(info.mTexture->mSource->mUri.data()); search != metaData.end())
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);
+ }
}
else if(needNormalsTangents)
{
{
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;
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;
}
}
auto& resources = output.mResources;
const auto index = scene.GetNodeCount();
- auto weakNode = scene.AddNode([&]()
- {
+ auto weakNode = scene.AddNode([&]() {
std::unique_ptr<NodeDefinition> nodeDefinition{new NodeDefinition()};
nodeDefinition->mParentIdx = parentIndex;
json::SetObjectReader(GetMaterialExtensionsReader());
json::SetObjectReader(GetMaterialReader());
json::SetObjectReader(GetMeshPrimitiveReader());
+ json::SetObjectReader(GetMeshExtrasReader());
+ json::SetObjectReader(GetMeshExtensionsReader());
json::SetObjectReader(GetMeshReader());
json::SetObjectReader(GetSkinReader());
json::SetObjectReader(GetCameraPerspectiveReader());