From 56dec18d27a2ea56f6cead944d34afdaa5b002c6 Mon Sep 17 00:00:00 2001 From: seungho baek Date: Sat, 18 Mar 2023 13:29:20 +0900 Subject: [PATCH] Remove Duplicated code in gltf2-util using template Change-Id: I5e181ef0925eb5151151849be3dbcef0f888c5f3 Signed-off-by: seungho baek --- dali-scene3d/internal/loader/gltf2-util.cpp | 101 +++++++++++----------------- 1 file changed, 41 insertions(+), 60 deletions(-) diff --git a/dali-scene3d/internal/loader/gltf2-util.cpp b/dali-scene3d/internal/loader/gltf2-util.cpp index 6f70d28..b01c8ba 100644 --- a/dali-scene3d/internal/loader/gltf2-util.cpp +++ b/dali-scene3d/internal/loader/gltf2-util.cpp @@ -420,6 +420,12 @@ TextureDefinition ConvertTextureInfo(const gltf2::TextureInfo& textureInfo, Conv } } +void AddTextureStage(uint32_t semantic, MaterialDefinition& materialDefinition, gltf2::TextureInfo textureInfo, const Dali::Scene3D::Loader::ImageMetadata &metaData, ConversionContext& context) +{ + materialDefinition.mTextureStages.push_back({semantic, ConvertTextureInfo(textureInfo, context, metaData)}); + materialDefinition.mFlags |= semantic; +} + 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) @@ -453,10 +459,7 @@ void ConvertMaterial(const gltf2::Material& material, const std::unordered_map +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.mNodeIndex = nodeIndex; + animatedProperty.mPropertyName = propertyName; + + animatedProperty.mKeyFrames = KeyFrames::New(); + float duration = LoadKeyFrames(context, channel, animatedProperty.mKeyFrames, channel.mTarget.mPath); + animatedProperty.mTimePeriod = {0.f, duration}; + + return duration; +} + void ConvertAnimations(const gltf2::Document& document, ConversionContext& context) { auto& output = context.mOutput; @@ -1015,11 +1020,11 @@ void ConvertAnimations(const gltf2::Document& document, ConversionContext& conte for(const auto& animation : document.mAnimations) { - AnimationDefinition animationDef; + AnimationDefinition animationDefinition; if(!animation.mName.empty()) { - animationDef.mName = animation.mName; + animationDefinition.mName = animation.mName; } uint32_t numberOfProperties = 0u; @@ -1034,7 +1039,7 @@ void ConvertAnimations(const gltf2::Document& document, ConversionContext& conte numberOfProperties++; } } - animationDef.mProperties.resize(numberOfProperties); + animationDefinition.mProperties.resize(numberOfProperties); Index propertyIndex = 0u; for(const auto& channel : animation.mChannels) @@ -1046,46 +1051,22 @@ void ConvertAnimations(const gltf2::Document& document, ConversionContext& conte { case gltf2::Animation::Channel::Target::TRANSLATION: { - AnimatedProperty& animatedProperty = animationDef.mProperties[propertyIndex]; - - animatedProperty.mNodeIndex = nodeIndex; - animatedProperty.mPropertyName = POSITION_PROPERTY; - - animatedProperty.mKeyFrames = KeyFrames::New(); - duration = LoadKeyFrames(context, channel, animatedProperty.mKeyFrames, channel.mTarget.mPath); - - animatedProperty.mTimePeriod = {0.f, duration}; + duration = LoadAnimation(animationDefinition, nodeIndex, propertyIndex, POSITION_PROPERTY.data(), channel, context); break; } case gltf2::Animation::Channel::Target::ROTATION: { - AnimatedProperty& animatedProperty = animationDef.mProperties[propertyIndex]; - - animatedProperty.mNodeIndex = nodeIndex; - animatedProperty.mPropertyName = ORIENTATION_PROPERTY; - - animatedProperty.mKeyFrames = KeyFrames::New(); - duration = LoadKeyFrames(context, channel, animatedProperty.mKeyFrames, channel.mTarget.mPath); - - animatedProperty.mTimePeriod = {0.f, duration}; + duration = LoadAnimation(animationDefinition, nodeIndex, propertyIndex, ORIENTATION_PROPERTY.data(), channel, context); break; } case gltf2::Animation::Channel::Target::SCALE: { - AnimatedProperty& animatedProperty = animationDef.mProperties[propertyIndex]; - - animatedProperty.mNodeIndex = nodeIndex; - animatedProperty.mPropertyName = SCALE_PROPERTY; - - animatedProperty.mKeyFrames = KeyFrames::New(); - duration = LoadKeyFrames(context, channel, animatedProperty.mKeyFrames, channel.mTarget.mPath); - - animatedProperty.mTimePeriod = {0.f, duration}; + duration = LoadAnimation(animationDefinition, nodeIndex, propertyIndex, SCALE_PROPERTY.data(), channel, context); break; } case gltf2::Animation::Channel::Target::WEIGHTS: { - duration = LoadBlendShapeKeyFrames(context, channel, nodeIndex, propertyIndex, animationDef.mProperties); + duration = LoadBlendShapeKeyFrames(context, channel, nodeIndex, propertyIndex, animationDefinition.mProperties); break; } @@ -1096,12 +1077,12 @@ void ConvertAnimations(const gltf2::Document& document, ConversionContext& conte } } - animationDef.mDuration = std::max(duration, animationDef.mDuration); + animationDefinition.mDuration = std::max(duration, animationDefinition.mDuration); ++propertyIndex; } - output.mAnimationDefinitions.push_back(std::move(animationDef)); + output.mAnimationDefinitions.push_back(std::move(animationDefinition)); } } -- 2.7.4