#include <dali-scene3d/internal/loader/gltf2-util.h>
// EXTERNAL INCLUDES
+#include <dali/devel-api/threading/mutex.h>
#include <dali/integration-api/debug.h>
using namespace Dali::Scene3D::Loader;
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;
}
auto& pbr = material.mPbrMetallicRoughness;
if(material.mAlphaMode == gltf2::AlphaMode::BLEND)
{
- materialDefinition.mIsOpaque = false;
+ materialDefinition.mAlphaModeType = Scene3D::Material::AlphaModeType::BLEND;
+ materialDefinition.mIsOpaque = false;
materialDefinition.mFlags |= MaterialDefinition::TRANSPARENCY;
}
else if(material.mAlphaMode == gltf2::AlphaMode::MASK)
{
- materialDefinition.mIsMask = true;
+ materialDefinition.mAlphaModeType = Scene3D::Material::AlphaModeType::MASK;
+ materialDefinition.mIsMask = true;
materialDefinition.SetAlphaCutoff(std::min(1.f, std::max(0.f, material.mAlphaCutoff)));
}
if(!Dali::Equals(material.mMaterialExtensions.mMaterialIor.mIor, gltf2::UNDEFINED_FLOAT_VALUE))
{
- float ior = material.mMaterialExtensions.mMaterialIor.mIor;
- materialDefinition.mDielectricSpecular = powf((ior - 1.0f) / (ior + 1.0f), 2.0f);
+ materialDefinition.mIor = material.mMaterialExtensions.mMaterialIor.mIor;
+ materialDefinition.mDielectricSpecular = powf((materialDefinition.mIor - 1.0f) / (materialDefinition.mIor + 1.0f), 2.0f);
}
materialDefinition.mSpecularFactor = material.mMaterialExtensions.mMaterialSpecular.mSpecularFactor;
materialDefinition.mSpecularColorFactor = material.mMaterialExtensions.mMaterialSpecular.mSpecularColorFactor;
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;
}
}
return duration;
}
-float LoadBlendShapeKeyFrames(ConversionContext& context, const gltf2::Animation::Channel& channel, Index nodeIndex, uint32_t& propertyIndex, std::vector<Dali::Scene3D::Loader::AnimatedProperty>& properties)
+float LoadBlendShapeKeyFrames(ConversionContext& context, const gltf2::Animation::Channel& channel, Index nodeIndex, uint32_t& propertyIndex, AnimationDefinition& animationDefinition)
{
const gltf2::Accessor& input = *channel.mSampler->mInput;
const gltf2::Accessor& output = *channel.mSampler->mOutput;
const auto remainingSize = sizeof(weightNameBuffer) - prefixSize;
for(uint32_t weightIndex = 0u, endWeightIndex = channel.mSampler->mOutput->mCount / channel.mSampler->mInput->mCount; weightIndex < endWeightIndex; ++weightIndex)
{
- AnimatedProperty& animatedProperty = properties[propertyIndex++];
+ AnimatedProperty animatedProperty;
animatedProperty.mNodeIndex = nodeIndex;
snprintf(pWeightName, remainingSize, "%d]", weightIndex);
}
animatedProperty.mTimePeriod = {0.f, duration};
+
+ animationDefinition.SetProperty(propertyIndex++, std::move(animatedProperty));
}
return duration;
template<typename T>
float LoadAnimation(AnimationDefinition& animationDefinition, Index nodeIndex, Index propertyIndex, const std::string& propertyName, const gltf2::Animation::Channel& channel, ConversionContext& context)
{
- AnimatedProperty& animatedProperty = animationDefinition.mProperties[propertyIndex];
-
+ AnimatedProperty animatedProperty;
animatedProperty.mNodeIndex = nodeIndex;
animatedProperty.mPropertyName = propertyName;
float duration = LoadKeyFrames<T>(context, channel, animatedProperty.mKeyFrames, channel.mTarget.mPath);
animatedProperty.mTimePeriod = {0.f, duration};
+ animationDefinition.SetProperty(propertyIndex, std::move(animatedProperty));
return duration;
}
if(!animation.mName.empty())
{
- animationDefinition.mName = animation.mName;
+ animationDefinition.SetName(animation.mName.data());
}
uint32_t numberOfProperties = 0u;
numberOfProperties++;
}
}
- animationDefinition.mProperties.resize(numberOfProperties);
+ animationDefinition.ReserveSize(numberOfProperties);
Index propertyIndex = 0u;
for(const auto& channel : animation.mChannels)
}
case gltf2::Animation::Channel::Target::WEIGHTS:
{
- duration = LoadBlendShapeKeyFrames(context, channel, nodeIndex, propertyIndex, animationDefinition.mProperties);
+ duration = LoadBlendShapeKeyFrames(context, channel, nodeIndex, propertyIndex, animationDefinition);
break;
}
}
}
- animationDefinition.mDuration = std::max(duration, animationDefinition.mDuration);
+ animationDefinition.SetDuration(std::max(duration, animationDefinition.GetDuration()));
++propertyIndex;
}
json::SetObjectReader(GetMaterialExtensionsReader());
json::SetObjectReader(GetMaterialReader());
json::SetObjectReader(GetMeshPrimitiveReader());
+ json::SetObjectReader(GetMeshExtrasReader());
+ json::SetObjectReader(GetMeshExtensionsReader());
json::SetObjectReader(GetMeshReader());
json::SetObjectReader(GetSkinReader());
json::SetObjectReader(GetCameraPerspectiveReader());