From ad899cb5c733b7c870e5772d7792f57375be0015 Mon Sep 17 00:00:00 2001 From: "huayong.xu" Date: Wed, 1 Mar 2023 18:18:13 +0800 Subject: [PATCH] Make sure that global variables are initialized lazily in scene3d. Global variables are initialized when scene3d so is loaded firstly. This would allocate more memory in some cases. This patch is to make the variables be initialized lazily. Change-Id: I317c04b7d04c74d84a44be8c603ddcdaacdabf83 --- .../public-api/loader/facial-animation-loader.cpp | 42 ++-- dali-scene3d/public-api/loader/gltf2-loader.cpp | 242 +++++++++++++++------ .../public-api/loader/load-scene-metadata.cpp | 51 +++-- 3 files changed, 233 insertions(+), 102 deletions(-) diff --git a/dali-scene3d/public-api/loader/facial-animation-loader.cpp b/dali-scene3d/public-api/loader/facial-animation-loader.cpp index 2414b1b..dfd9cc2 100644 --- a/dali-scene3d/public-api/loader/facial-animation-loader.cpp +++ b/dali-scene3d/public-api/loader/facial-animation-loader.cpp @@ -71,21 +71,29 @@ std::vector> ReadBlendShapeKeys(const json_value_s& j) return result; } -const auto BLEND_SHAPE_READER = std::move(js::Reader() - .Register(*js::MakeProperty("key", ReadBlendShapeKeys, &BlendShape::mKeys)) - .Register(*new js::Property("name", js::Read::StringView, &BlendShape::mNodeName)) - .Register(*js::MakeProperty("morphtarget", js::Read::Number, &BlendShape::mNumberOfMorphTarget)) - .Register(*new js::Property("blendShapeVersion", js::Read::StringView, &BlendShape::mVersion)) - .Register(*new js::Property("fullName", js::Read::StringView, &BlendShape::mFullName)) - .Register(*js::MakeProperty("morphname", js::Read::Array, &BlendShape::mMorphNames))); - -const auto FACIAL_ANIMATION_READER = std::move(js::Reader() - .Register(*new js::Property("name", js::Read::StringView, &FacialAnimation::mName)) - .Register(*js::MakeProperty("blendShapes", js::Read::Array::Read>, &FacialAnimation::mBlendShapes)) - .Register(*new js::Property("version", js::Read::StringView, &FacialAnimation::mVersion)) - .Register(*js::MakeProperty("shapesAmount", js::Read::Number, &FacialAnimation::mNumberOfShapes)) - .Register(*js::MakeProperty("time", js::Read::Array, &FacialAnimation::mTime)) - .Register(*js::MakeProperty("frames", js::Read::Number, &FacialAnimation::mNumberOfFrames))); +const js::Reader& GetBlendShapeReader() +{ + static const auto BLEND_SHAPE_READER = std::move(js::Reader() + .Register(*js::MakeProperty("key", ReadBlendShapeKeys, &BlendShape::mKeys)) + .Register(*new js::Property("name", js::Read::StringView, &BlendShape::mNodeName)) + .Register(*js::MakeProperty("morphtarget", js::Read::Number, &BlendShape::mNumberOfMorphTarget)) + .Register(*new js::Property("blendShapeVersion", js::Read::StringView, &BlendShape::mVersion)) + .Register(*new js::Property("fullName", js::Read::StringView, &BlendShape::mFullName)) + .Register(*js::MakeProperty("morphname", js::Read::Array, &BlendShape::mMorphNames))); + return BLEND_SHAPE_READER; +} + +const js::Reader& GetFacialAnimationReader() +{ + static const auto FACIAL_ANIMATION_READER = std::move(js::Reader() + .Register(*new js::Property("name", js::Read::StringView, &FacialAnimation::mName)) + .Register(*js::MakeProperty("blendShapes", js::Read::Array::Read>, &FacialAnimation::mBlendShapes)) + .Register(*new js::Property("version", js::Read::StringView, &FacialAnimation::mVersion)) + .Register(*js::MakeProperty("shapesAmount", js::Read::Number, &FacialAnimation::mNumberOfShapes)) + .Register(*js::MakeProperty("time", js::Read::Array, &FacialAnimation::mTime)) + .Register(*js::MakeProperty("frames", js::Read::Number, &FacialAnimation::mNumberOfFrames))); + return FACIAL_ANIMATION_READER; +} } // unnamed namespace @@ -112,14 +120,14 @@ AnimationDefinition LoadFacialAnimation(const std::string& url) if(setObjectReaders) { // NOTE: only referencing own, anonymous namespace, const objects; the pointers will never need to change. - js::SetObjectReader(BLEND_SHAPE_READER); + js::SetObjectReader(GetBlendShapeReader()); setObjectReaders = false; } auto& rootObj = js::Cast(*root); FacialAnimation facialAnimation; - FACIAL_ANIMATION_READER.Read(rootObj, facialAnimation); + GetFacialAnimationReader().Read(rootObj, facialAnimation); AnimationDefinition animationDefinition; animationDefinition.mName = std::string(facialAnimation.mName.data()); diff --git a/dali-scene3d/public-api/loader/gltf2-loader.cpp b/dali-scene3d/public-api/loader/gltf2-loader.cpp index 05bd72c..c0ca6cd 100644 --- a/dali-scene3d/public-api/loader/gltf2-loader.cpp +++ b/dali-scene3d/public-api/loader/gltf2-loader.cpp @@ -100,32 +100,54 @@ void ApplyAccessorMinMax(const gt::Accessor& acc, float* values) MeshDefinition::Blob::ApplyMinMax(acc.mMin, acc.mMax, acc.mCount, values); } -const auto BUFFER_READER = std::move(js::Reader() - .Register(*js::MakeProperty("byteLength", js::Read::Number, >::Buffer::mByteLength)) - .Register(*js::MakeProperty("uri", js::Read::StringView, >::Buffer::mUri))); - -const auto BUFFER_VIEW_READER = std::move(js::Reader() - .Register(*js::MakeProperty("buffer", gt::RefReader::Read, >::BufferView::mBuffer)) - .Register(*js::MakeProperty("byteOffset", js::Read::Number, >::BufferView::mByteOffset)) - .Register(*js::MakeProperty("byteLength", js::Read::Number, >::BufferView::mByteLength)) - .Register(*js::MakeProperty("byteStride", js::Read::Number, >::BufferView::mByteStride)) - .Register(*js::MakeProperty("target", js::Read::Number, >::BufferView::mTarget))); - -const auto BUFFER_VIEW_CLIENT_READER = std::move(js::Reader() +const js::Reader& GetBufferReader() +{ + static const auto BUFFER_READER = std::move(js::Reader() + .Register(*js::MakeProperty("byteLength", js::Read::Number, >::Buffer::mByteLength)) + .Register(*js::MakeProperty("uri", js::Read::StringView, >::Buffer::mUri))); + return BUFFER_READER; +} + +const js::Reader& GetBufferViewReader() +{ + static const auto BUFFER_VIEW_READER = std::move(js::Reader() + .Register(*js::MakeProperty("buffer", gt::RefReader::Read, >::BufferView::mBuffer)) + .Register(*js::MakeProperty("byteOffset", js::Read::Number, >::BufferView::mByteOffset)) + .Register(*js::MakeProperty("byteLength", js::Read::Number, >::BufferView::mByteLength)) + .Register(*js::MakeProperty("byteStride", js::Read::Number, >::BufferView::mByteStride)) + .Register(*js::MakeProperty("target", js::Read::Number, >::BufferView::mTarget))); + return BUFFER_VIEW_READER; +} + +const js::Reader& GetBufferViewClientReader() +{ + static const auto BUFFER_VIEW_CLIENT_READER = std::move(js::Reader() .Register(*js::MakeProperty("bufferView", gt::RefReader::Read, >::BufferViewClient::mBufferView)) .Register(*js::MakeProperty("byteOffset", js::Read::Number, >::BufferViewClient::mByteOffset))); + return BUFFER_VIEW_CLIENT_READER; +} -const auto COMPONENT_TYPED_BUFFER_VIEW_CLIENT_READER = std::move(js::Reader() +const js::Reader& GetComponentTypedBufferViewClientReader() +{ + static const auto COMPONENT_TYPED_BUFFER_VIEW_CLIENT_READER = std::move(js::Reader() .Register(*new js::Property>("bufferView", gt::RefReader::Read, >::ComponentTypedBufferViewClient::mBufferView)) .Register(*new js::Property("byteOffset", js::Read::Number, >::ComponentTypedBufferViewClient::mByteOffset)) .Register(*js::MakeProperty("componentType", js::Read::Enum, >::ComponentTypedBufferViewClient::mComponentType))); + return COMPONENT_TYPED_BUFFER_VIEW_CLIENT_READER; +} -const auto ACCESSOR_SPARSE_READER = std::move(js::Reader() +const js::Reader& GetAccessorSparseReader() +{ + static const auto ACCESSOR_SPARSE_READER = std::move(js::Reader() .Register(*js::MakeProperty("count", js::Read::Number, >::Accessor::Sparse::mCount)) .Register(*js::MakeProperty("indices", js::ObjectReader::Read, >::Accessor::Sparse::mIndices)) .Register(*js::MakeProperty("values", js::ObjectReader::Read, >::Accessor::Sparse::mValues))); + return ACCESSOR_SPARSE_READER; +} -const auto ACCESSOR_READER = std::move(js::Reader() +const js::Reader& GetAccessorReader() +{ + static const auto ACCESSOR_READER = std::move(js::Reader() .Register(*new js::Property>("bufferView", gt::RefReader::Read, >::Accessor::mBufferView)) @@ -142,50 +164,86 @@ const auto ACCESSOR_READER = std::move(js::Reader() .Register(*js::MakeProperty("min", js::Read::Array, >::Accessor::mMin)) .Register(*js::MakeProperty("max", js::Read::Array, >::Accessor::mMax)) .Register(*new js::Property("sparse", js::ObjectReader::Read, >::Accessor::SetSparse))); + return ACCESSOR_READER; +} -const auto IMAGE_READER = std::move(js::Reader() +const js::Reader& GetImageReader() +{ + static const auto IMAGE_READER = std::move(js::Reader() .Register(*new js::Property("name", js::Read::StringView, >::Material::mName)) .Register(*js::MakeProperty("uri", js::Read::StringView, >::Image::mUri)) .Register(*js::MakeProperty("mimeType", js::Read::StringView, >::Image::mMimeType)) .Register(*js::MakeProperty("bufferView", gt::RefReader::Read, >::Image::mBufferView))); + return IMAGE_READER; +} -const auto SAMPLER_READER = std::move(js::Reader() +const js::Reader& GetSamplerReader() +{ + static const auto SAMPLER_READER = std::move(js::Reader() .Register(*js::MakeProperty("minFilter", js::Read::Enum, >::Sampler::mMinFilter)) .Register(*js::MakeProperty("magFilter", js::Read::Enum, >::Sampler::mMagFilter)) .Register(*js::MakeProperty("wrapS", js::Read::Enum, >::Sampler::mWrapS)) .Register(*js::MakeProperty("wrapT", js::Read::Enum, >::Sampler::mWrapT))); + return SAMPLER_READER; +} -const auto TEXURE_READER = std::move(js::Reader() +const js::Reader& GetTextureReader() +{ + static const auto TEXURE_READER = std::move(js::Reader() .Register(*js::MakeProperty("source", gt::RefReader::Read, >::Texture::mSource)) .Register(*js::MakeProperty("sampler", gt::RefReader::Read, >::Texture::mSampler))); + return TEXURE_READER; +} -const auto TEXURE_INFO_READER = std::move(js::Reader() +const js::Reader& GetTextureInfoReader() +{ + static const auto TEXURE_INFO_READER = std::move(js::Reader() .Register(*js::MakeProperty("index", gt::RefReader::Read, >::TextureInfo::mTexture)) .Register(*js::MakeProperty("texCoord", js::Read::Number, >::TextureInfo::mTexCoord)) .Register(*js::MakeProperty("scale", js::Read::Number, >::TextureInfo::mScale)) .Register(*js::MakeProperty("strength", js::Read::Number, >::TextureInfo::mStrength))); + return TEXURE_INFO_READER; +} -const auto MATERIAL_PBR_READER = std::move(js::Reader() +const js::Reader& GetMaterialPbrReader() +{ + static const auto MATERIAL_PBR_READER = std::move(js::Reader() .Register(*js::MakeProperty("baseColorFactor", gt::ReadDaliVector, >::Material::Pbr::mBaseColorFactor)) .Register(*js::MakeProperty("baseColorTexture", js::ObjectReader::Read, >::Material::Pbr::mBaseColorTexture)) .Register(*js::MakeProperty("metallicFactor", js::Read::Number, >::Material::Pbr::mMetallicFactor)) .Register(*js::MakeProperty("roughnessFactor", js::Read::Number, >::Material::Pbr::mRoughnessFactor)) .Register(*js::MakeProperty("metallicRoughnessTexture", js::ObjectReader::Read, >::Material::Pbr::mMetallicRoughnessTexture))); + return MATERIAL_PBR_READER; +} -const auto MATERIAL_SPECULAR_READER = std::move(js::Reader() +const js::Reader& GetMaterialSpecularReader() +{ + static const auto MATERIAL_SPECULAR_READER = std::move(js::Reader() .Register(*js::MakeProperty("specularFactor", js::Read::Number, >::MaterialSpecular::mSpecularFactor)) .Register(*js::MakeProperty("specularTexture", js::ObjectReader::Read, >::MaterialSpecular::mSpecularTexture)) .Register(*js::MakeProperty("specularColorFactor", gt::ReadDaliVector, >::MaterialSpecular::mSpecularColorFactor)) .Register(*js::MakeProperty("specularColorTexture", js::ObjectReader::Read, >::MaterialSpecular::mSpecularColorTexture))); + return MATERIAL_SPECULAR_READER; +} -const auto MATERIAL_IOR_READER = std::move(js::Reader() +const js::Reader& GetMaterialIorReader() +{ + static const auto MATERIAL_IOR_READER = std::move(js::Reader() .Register(*js::MakeProperty("ior", js::Read::Number, >::MaterialIor::mIor))); + return MATERIAL_IOR_READER; +} -const auto MATERIAL_EXTENSION_READER = std::move(js::Reader() +const js::Reader& GetMaterialExtensionsReader() +{ + static const auto MATERIAL_EXTENSION_READER = std::move(js::Reader() .Register(*js::MakeProperty("KHR_materials_ior", js::ObjectReader::Read, >::MaterialExtensions::mMaterialIor)) .Register(*js::MakeProperty("KHR_materials_specular", js::ObjectReader::Read, >::MaterialExtensions::mMaterialSpecular))); + return MATERIAL_EXTENSION_READER; +} -const auto MATERIAL_READER = std::move(js::Reader() +const js::Reader& GetMaterialReader() +{ + static const auto MATERIAL_READER = std::move(js::Reader() .Register(*new js::Property("name", js::Read::StringView, >::Material::mName)) .Register(*js::MakeProperty("pbrMetallicRoughness", js::ObjectReader::Read, >::Material::mPbrMetallicRoughness)) .Register(*js::MakeProperty("normalTexture", js::ObjectReader::Read, >::Material::mNormalTexture)) @@ -196,6 +254,8 @@ const auto MATERIAL_READER = std::move(js::Reader() .Register(*js::MakeProperty("alphaCutoff", js::Read::Number, >::Material::mAlphaCutoff)) .Register(*js::MakeProperty("doubleSided", js::Read::Boolean, >::Material::mDoubleSided)) .Register(*js::MakeProperty("extensions", js::ObjectReader::Read, >::Material::mMaterialExtensions))); + return MATERIAL_READER; +} std::map> ReadMeshPrimitiveAttributes(const json_value_s& j) { @@ -229,21 +289,31 @@ std::vector>> ReadMeshPrimit return result; } -const auto MESH_PRIMITIVE_READER = std::move(js::Reader() +const js::Reader& GetMeshPrimitiveReader() +{ + static const auto MESH_PRIMITIVE_READER = std::move(js::Reader() .Register(*js::MakeProperty("attributes", ReadMeshPrimitiveAttributes, >::Mesh::Primitive::mAttributes)) .Register(*js::MakeProperty("indices", gt::RefReader::Read, >::Mesh::Primitive::mIndices)) .Register(*js::MakeProperty("material", gt::RefReader::Read, >::Mesh::Primitive::mMaterial)) .Register(*js::MakeProperty("mode", js::Read::Enum, >::Mesh::Primitive::mMode)) .Register(*js::MakeProperty("targets", ReadMeshPrimitiveTargets, >::Mesh::Primitive::mTargets))); + return MESH_PRIMITIVE_READER; +} -const auto MESH_READER = std::move(js::Reader() +const js::Reader& GetMeshReader() +{ + static const auto MESH_READER = std::move(js::Reader() .Register(*new js::Property("name", js::Read::StringView, >::Mesh::mName)) .Register(*js::MakeProperty("primitives", js::Read::Array::Read>, >::Mesh::mPrimitives)) .Register(*js::MakeProperty("weights", js::Read::Array, >::Mesh::mWeights))); + return MESH_READER; +} -const auto SKIN_READER = std::move(js::Reader() +const js::Reader& GetSkinReader() +{ + static const auto SKIN_READER = std::move(js::Reader() .Register(*new js::Property("name", js::Read::StringView, >::Skin::mName)) .Register(*js::MakeProperty("inverseBindMatrices", gt::RefReader::Read, @@ -254,26 +324,42 @@ const auto SKIN_READER = std::move(js::Reader() .Register(*js::MakeProperty("joints", js::Read::Array, gt::RefReader::Read>, >::Skin::mJoints))); + return SKIN_READER; +} -const auto CAMERA_PERSPECTIVE_READER = std::move(js::Reader() +const js::Reader& GetCameraPerspectiveReader() +{ + static const auto CAMERA_PERSPECTIVE_READER = std::move(js::Reader() .Register(*js::MakeProperty("aspectRatio", js::Read::Number, >::Camera::Perspective::mAspectRatio)) .Register(*js::MakeProperty("yfov", js::Read::Number, >::Camera::Perspective::mYFov)) .Register(*js::MakeProperty("zfar", js::Read::Number, >::Camera::Perspective::mZFar)) .Register(*js::MakeProperty("znear", js::Read::Number, >::Camera::Perspective::mZNear))); // TODO: infinite perspective projection, where znear is omitted + return CAMERA_PERSPECTIVE_READER; +} -const auto CAMERA_ORTHOGRAPHIC_READER = std::move(js::Reader() +const js::Reader& GetCameraOrthographicReader() +{ + static const auto CAMERA_ORTHOGRAPHIC_READER = std::move(js::Reader() .Register(*js::MakeProperty("xmag", js::Read::Number, >::Camera::Orthographic::mXMag)) .Register(*js::MakeProperty("ymag", js::Read::Number, >::Camera::Orthographic::mYMag)) .Register(*js::MakeProperty("zfar", js::Read::Number, >::Camera::Orthographic::mZFar)) .Register(*js::MakeProperty("znear", js::Read::Number, >::Camera::Orthographic::mZNear))); + return CAMERA_ORTHOGRAPHIC_READER; +} -const auto CAMERA_READER = std::move(js::Reader() +const js::Reader& GetCameraReader() +{ + static const auto CAMERA_READER = std::move(js::Reader() .Register(*new js::Property("name", js::Read::StringView, >::Camera::mName)) .Register(*js::MakeProperty("type", js::Read::StringView, >::Camera::mType)) .Register(*js::MakeProperty("perspective", js::ObjectReader::Read, >::Camera::mPerspective)) .Register(*js::MakeProperty("orthographic", js::ObjectReader::Read, >::Camera::mOrthographic))); + return CAMERA_READER; +} -const auto NODE_READER = std::move(js::Reader() +const js::Reader& GetNodeReader() +{ + static const auto NODE_READER = std::move(js::Reader() .Register(*new js::Property("name", js::Read::StringView, >::Node::mName)) .Register(*js::MakeProperty("translation", gt::ReadDaliVector, >::Node::mTranslation)) .Register(*js::MakeProperty("rotation", gt::ReadQuaternion, >::Node::mRotation)) @@ -283,21 +369,37 @@ const auto NODE_READER = std::move(js::Reader() .Register(*js::MakeProperty("children", js::Read::Array, gt::RefReader::Read>, >::Node::mChildren)) .Register(*js::MakeProperty("mesh", gt::RefReader::Read, >::Node::mMesh)) .Register(*js::MakeProperty("skin", gt::RefReader::Read, >::Node::mSkin))); + return NODE_READER; +} -const auto ANIMATION_SAMPLER_READER = std::move(js::Reader() +const js::Reader& GetAnimationSamplerReader() +{ + static const auto ANIMATION_SAMPLER_READER = std::move(js::Reader() .Register(*js::MakeProperty("input", gt::RefReader::Read, >::Animation::Sampler::mInput)) .Register(*js::MakeProperty("output", gt::RefReader::Read, >::Animation::Sampler::mOutput)) .Register(*js::MakeProperty("interpolation", gt::ReadStringEnum, >::Animation::Sampler::mInterpolation))); + return ANIMATION_SAMPLER_READER; +} -const auto ANIMATION_TARGET_READER = std::move(js::Reader() +const js::Reader& GetAnimationChannelTargetReader() +{ + static const auto ANIMATION_TARGET_READER = std::move(js::Reader() .Register(*js::MakeProperty("node", gt::RefReader::Read, >::Animation::Channel::Target::mNode)) .Register(*js::MakeProperty("path", gt::ReadStringEnum, >::Animation::Channel::Target::mPath))); + return ANIMATION_TARGET_READER; +} -const auto ANIMATION_CHANNEL_READER = std::move(js::Reader() +const js::Reader& GetAnimationChannelReader() +{ + static const auto ANIMATION_CHANNEL_READER = std::move(js::Reader() .Register(*js::MakeProperty("target", js::ObjectReader::Read, >::Animation::Channel::mTarget)) .Register(*js::MakeProperty("sampler", gt::RefReader::Read, >::Animation::Channel::mSampler))); + return ANIMATION_CHANNEL_READER; +} -const auto ANIMATION_READER = std::move(js::Reader() +const js::Reader& GetAnimationReader() +{ + static const auto ANIMATION_READER = std::move(js::Reader() .Register(*new js::Property("name", js::Read::StringView, >::Animation::mName)) .Register(*js::MakeProperty("samplers", js::Read::Array::Read>, @@ -305,14 +407,22 @@ const auto ANIMATION_READER = std::move(js::Reader() .Register(*js::MakeProperty("channels", js::Read::Array::Read>, >::Animation::mChannels))); + return ANIMATION_READER; +} -const auto SCENE_READER = std::move(js::Reader() +const js::Reader& GetSceneReader() +{ + static const auto SCENE_READER = std::move(js::Reader() .Register(*new js::Property("name", js::Read::StringView, >::Scene::mName)) .Register(*js::MakeProperty("nodes", js::Read::Array, gt::RefReader::Read>, >::Scene::mNodes))); + return SCENE_READER; +} -const auto DOCUMENT_READER = std::move(js::Reader() +const js::Reader& GetDocumentReader() +{ + static const auto DOCUMENT_READER = std::move(js::Reader() .Register(*js::MakeProperty("buffers", js::Read::Array::Read>, >::Document::mBuffers)) @@ -353,6 +463,8 @@ const auto DOCUMENT_READER = std::move(js::Reader() js::Read::Array::Read>, >::Document::mScenes)) .Register(*js::MakeProperty("scene", gt::RefReader::Read, >::Document::mScene))); + return DOCUMENT_READER; +} struct NodeMapping { @@ -1273,33 +1385,33 @@ void ProduceShaders(ShaderDefinitionFactory& shaderFactory, SceneDefinition& sce void SetObjectReaders() { - js::SetObjectReader(BUFFER_READER); - js::SetObjectReader(BUFFER_VIEW_READER); - js::SetObjectReader(BUFFER_VIEW_CLIENT_READER); - js::SetObjectReader(COMPONENT_TYPED_BUFFER_VIEW_CLIENT_READER); - js::SetObjectReader(ACCESSOR_SPARSE_READER); - js::SetObjectReader(ACCESSOR_READER); - js::SetObjectReader(IMAGE_READER); - js::SetObjectReader(SAMPLER_READER); - js::SetObjectReader(TEXURE_READER); - js::SetObjectReader(TEXURE_INFO_READER); - js::SetObjectReader(MATERIAL_PBR_READER); - js::SetObjectReader(MATERIAL_SPECULAR_READER); - js::SetObjectReader(MATERIAL_IOR_READER); - js::SetObjectReader(MATERIAL_EXTENSION_READER); - js::SetObjectReader(MATERIAL_READER); - js::SetObjectReader(MESH_PRIMITIVE_READER); - js::SetObjectReader(MESH_READER); - js::SetObjectReader(SKIN_READER); - js::SetObjectReader(CAMERA_PERSPECTIVE_READER); - js::SetObjectReader(CAMERA_ORTHOGRAPHIC_READER); - js::SetObjectReader(CAMERA_READER); - js::SetObjectReader(NODE_READER); - js::SetObjectReader(ANIMATION_SAMPLER_READER); - js::SetObjectReader(ANIMATION_TARGET_READER); - js::SetObjectReader(ANIMATION_CHANNEL_READER); - js::SetObjectReader(ANIMATION_READER); - js::SetObjectReader(SCENE_READER); + js::SetObjectReader(GetBufferReader()); + js::SetObjectReader(GetBufferViewReader()); + js::SetObjectReader(GetBufferViewClientReader()); + js::SetObjectReader(GetComponentTypedBufferViewClientReader()); + js::SetObjectReader(GetAccessorSparseReader()); + js::SetObjectReader(GetAccessorReader()); + js::SetObjectReader(GetImageReader()); + js::SetObjectReader(GetSamplerReader()); + js::SetObjectReader(GetTextureReader()); + js::SetObjectReader(GetTextureInfoReader()); + js::SetObjectReader(GetMaterialPbrReader()); + js::SetObjectReader(GetMaterialSpecularReader()); + js::SetObjectReader(GetMaterialIorReader()); + js::SetObjectReader(GetMaterialExtensionsReader()); + js::SetObjectReader(GetMaterialReader()); + js::SetObjectReader(GetMeshPrimitiveReader()); + js::SetObjectReader(GetMeshReader()); + js::SetObjectReader(GetSkinReader()); + js::SetObjectReader(GetCameraPerspectiveReader()); + js::SetObjectReader(GetCameraOrthographicReader()); + js::SetObjectReader(GetCameraReader()); + js::SetObjectReader(GetNodeReader()); + js::SetObjectReader(GetAnimationSamplerReader()); + js::SetObjectReader(GetAnimationChannelTargetReader()); + js::SetObjectReader(GetAnimationChannelReader()); + js::SetObjectReader(GetAnimationReader()); + js::SetObjectReader(GetSceneReader()); } void SetDefaultEnvironmentMap(const gt::Document& doc, ConversionContext& context) @@ -1364,7 +1476,7 @@ void LoadGltfScene(const std::string& url, ShaderDefinitionFactory& shaderFactor { Mutex::ScopedLock lock(gReadMutex); gt::SetRefReaderObject(doc); - DOCUMENT_READER.Read(rootObj, doc); + GetDocumentReader().Read(rootObj, doc); } auto path = url.substr(0, url.rfind('/') + 1); diff --git a/dali-scene3d/public-api/loader/load-scene-metadata.cpp b/dali-scene3d/public-api/loader/load-scene-metadata.cpp index 76c1056..826e713 100644 --- a/dali-scene3d/public-api/loader/load-scene-metadata.cpp +++ b/dali-scene3d/public-api/loader/load-scene-metadata.cpp @@ -54,32 +54,43 @@ struct ImageData ImageData::SamplingMode::Type mSamplingMode{ImageData::SamplingMode::BOX_THEN_LINEAR}; ///< The sampling mode used to resize the image. }; -const std::map SAMPLING_MODE_TYPES{ - ENUM_STRING_MAPPING(ImageData::SamplingMode, BOX), - ENUM_STRING_MAPPING(ImageData::SamplingMode, NEAREST), - ENUM_STRING_MAPPING(ImageData::SamplingMode, LINEAR), - ENUM_STRING_MAPPING(ImageData::SamplingMode, BOX_THEN_NEAREST), - ENUM_STRING_MAPPING(ImageData::SamplingMode, BOX_THEN_LINEAR), - ENUM_STRING_MAPPING(ImageData::SamplingMode, NO_FILTER), - ENUM_STRING_MAPPING(ImageData::SamplingMode, DONT_CARE), -}; +const std::map& GetStringSamplingModeTable() +{ + static const std::map SAMPLING_MODE_TYPES{ + ENUM_STRING_MAPPING(ImageData::SamplingMode, BOX), + ENUM_STRING_MAPPING(ImageData::SamplingMode, NEAREST), + ENUM_STRING_MAPPING(ImageData::SamplingMode, LINEAR), + ENUM_STRING_MAPPING(ImageData::SamplingMode, BOX_THEN_NEAREST), + ENUM_STRING_MAPPING(ImageData::SamplingMode, BOX_THEN_LINEAR), + ENUM_STRING_MAPPING(ImageData::SamplingMode, NO_FILTER), + ENUM_STRING_MAPPING(ImageData::SamplingMode, DONT_CARE), + }; + return SAMPLING_MODE_TYPES; +} -ENUM_TYPE_FROM_STRING(ImageData::SamplingMode, SAMPLING_MODE_TYPES) +ENUM_TYPE_FROM_STRING(ImageData::SamplingMode, GetStringSamplingModeTable()) struct MetaData { std::vector mImageData; }; -const auto IMAGE_METADATA_READER = std::move(js::Reader() - .Register(*js::MakeProperty("uri", js::Read::String, &ImageData::mImageUri)) - .Register(*js::MakeProperty("minWidth", js::Read::Number, &ImageData::mMinWidth)) - .Register(*js::MakeProperty("minHeight", js::Read::Number, &ImageData::mMinHeight)) - .Register(*js::MakeProperty("samplingMode", gt::ReadStringEnum, &ImageData::mSamplingMode))); - -const auto METADATA_READER = std::move(js::Reader() - .Register(*js::MakeProperty("images", js::Read::Array::Read>, &MetaData::mImageData))); +const js::Reader& GetImageMetaDataReader() +{ + static const auto IMAGE_METADATA_READER = std::move(js::Reader() + .Register(*js::MakeProperty("uri", js::Read::String, &ImageData::mImageUri)) + .Register(*js::MakeProperty("minWidth", js::Read::Number, &ImageData::mMinWidth)) + .Register(*js::MakeProperty("minHeight", js::Read::Number, &ImageData::mMinHeight)) + .Register(*js::MakeProperty("samplingMode", gt::ReadStringEnum, &ImageData::mSamplingMode))); + return IMAGE_METADATA_READER; +} +const js::Reader& GetMetaDataReader() +{ + static const auto METADATA_READER = std::move(js::Reader() + .Register(*js::MakeProperty("images", js::Read::Array::Read>, &MetaData::mImageData))); + return METADATA_READER; +} } // namespace void LoadSceneMetadata(const std::string& url, SceneMetadata& sceneMetadata) @@ -101,13 +112,13 @@ void LoadSceneMetadata(const std::string& url, SceneMetadata& sceneMetadata) static bool setObjectReaders = true; if(setObjectReaders) { - js::SetObjectReader(IMAGE_METADATA_READER); + js::SetObjectReader(GetImageMetaDataReader()); setObjectReaders = false; } MetaData metaData; - METADATA_READER.Read(rootObj, metaData); + GetMetaDataReader().Read(rootObj, metaData); sceneMetadata.mImageMetadata.reserve(metaData.mImageData.size() + metaData.mImageData.size()); for(auto&& data : metaData.mImageData) -- 2.7.4