#include <dali/integration-api/debug.h>
#include <dali/public-api/images/image-operations.h>
#include <dali/public-api/math/quaternion.h>
+#include <dali/devel-api/threading/mutex.h>
#include <fstream>
// INTERNAL INCLUDES
{
namespace
{
+Dali::Mutex gInitializeMutex;
+Dali::Mutex gReadMutex;
+
const std::string POSITION_PROPERTY("position");
const std::string ORIENTATION_PROPERTY("orientation");
const std::string SCALE_PROPERTY("scale");
std::vector<gt::Animation> ReadAnimationArray(const json_value_s& j)
{
- gt::Animation proxy;
- SetRefReaderObject(proxy);
-
auto results = js::Read::Array<gt::Animation, js::ObjectReader<gt::Animation>::Read>(j);
for(auto& animation : results)
return duration;
}
-float LoadBlendShapeKeyFrames(const std::string& path, const gt::Animation::Channel& channel, const std::string& nodeName, uint32_t& propertyIndex, std::vector<Dali::Scene3D::Loader::AnimatedProperty>& properties)
+float LoadBlendShapeKeyFrames(const std::string& path, const gt::Animation::Channel& channel, Index nodeIndex, uint32_t& propertyIndex, std::vector<Dali::Scene3D::Loader::AnimatedProperty>& properties)
{
const gltf2::Accessor& input = *channel.mSampler->mInput;
const gltf2::Accessor& output = *channel.mSampler->mOutput;
{
AnimatedProperty& animatedProperty = properties[propertyIndex++];
- animatedProperty.mNodeName = nodeName;
+ animatedProperty.mNodeIndex = nodeIndex;
snprintf(pWeightName, remainingSize, "%d]", weightIndex);
animatedProperty.mPropertyName = std::string(weightNameBuffer);
}
uint32_t numberOfProperties = 0u;
-
for(const auto& channel : animation.mChannels)
{
- numberOfProperties += channel.mSampler->mOutput->mCount;
- }
- animationDef.mProperties.resize(numberOfProperties);
-
- Index propertyIndex = 0u;
- for(const auto& channel : animation.mChannels)
- {
- std::string nodeName;
- if(!channel.mTarget.mNode->mName.empty())
+ if(channel.mTarget.mPath == gt::Animation::Channel::Target::WEIGHTS)
{
- nodeName = channel.mTarget.mNode->mName;
+ numberOfProperties += channel.mSampler->mOutput->mCount / channel.mSampler->mInput->mCount;
}
else
{
- Index index = context.mNodeIndices.GetRuntimeId(channel.mTarget.mNode.GetIndex());
- nodeName = context.mOutput.mScene.GetNode(index)->mName;
+ numberOfProperties++;
}
+ }
+ animationDef.mProperties.resize(numberOfProperties);
+ Index propertyIndex = 0u;
+ for(const auto& channel : animation.mChannels)
+ {
+ Index nodeIndex = context.mNodeIndices.GetRuntimeId(channel.mTarget.mNode.GetIndex());
float duration = 0.f;
switch(channel.mTarget.mPath)
{
AnimatedProperty& animatedProperty = animationDef.mProperties[propertyIndex];
- animatedProperty.mNodeName = nodeName;
+ animatedProperty.mNodeIndex = nodeIndex;
animatedProperty.mPropertyName = POSITION_PROPERTY;
animatedProperty.mKeyFrames = KeyFrames::New();
{
AnimatedProperty& animatedProperty = animationDef.mProperties[propertyIndex];
- animatedProperty.mNodeName = nodeName;
+ animatedProperty.mNodeIndex = nodeIndex;
animatedProperty.mPropertyName = ORIENTATION_PROPERTY;
animatedProperty.mKeyFrames = KeyFrames::New();
{
AnimatedProperty& animatedProperty = animationDef.mProperties[propertyIndex];
- animatedProperty.mNodeName = nodeName;
+ animatedProperty.mNodeIndex = nodeIndex;
animatedProperty.mPropertyName = SCALE_PROPERTY;
animatedProperty.mKeyFrames = KeyFrames::New();
}
case gt::Animation::Channel::Target::WEIGHTS:
{
- duration = LoadBlendShapeKeyFrames(context.mPath, channel, nodeName, propertyIndex, animationDef.mProperties);
+ duration = LoadBlendShapeKeyFrames(context.mPath, channel, nodeIndex, propertyIndex, animationDef.mProperties);
break;
}
} // namespace
+void InitializeGltfLoader()
+{
+ // Set ObjectReader only once (for all gltf loading).
+ static bool setObjectReadersRequired = true;
+ {
+ Mutex::ScopedLock lock(gInitializeMutex);
+ if(setObjectReadersRequired)
+ {
+ // NOTE: only referencing own, anonymous namespace, const objects; the pointers will never need to change.
+ SetObjectReaders();
+ setObjectReadersRequired = false;
+ }
+ }
+}
+
void LoadGltfScene(const std::string& url, ShaderDefinitionFactory& shaderFactory, LoadResult& params)
{
bool failed = false;
throw std::runtime_error("Failed to parse " + url);
}
- static bool setObjectReaders = true;
- if(setObjectReaders)
- {
- // NOTE: only referencing own, anonymous namespace, const objects; the pointers will never need to change.
- SetObjectReaders();
- setObjectReaders = false;
- }
-
gt::Document doc;
auto& rootObj = js::Cast<json_object_s>(*root);
isMRendererModel = (doc.mAsset.mGenerator.find(MRENDERER_MODEL_IDENTIFICATION) != std::string_view::npos);
}
- gt::SetRefReaderObject(doc);
- DOCUMENT_READER.Read(rootObj, doc);
+ {
+ Mutex::ScopedLock lock(gReadMutex);
+ gt::SetRefReaderObject(doc);
+ DOCUMENT_READER.Read(rootObj, doc);
+ }
auto path = url.substr(0, url.rfind('/') + 1);
ConversionContext context{params, path, INVALID_INDEX};