2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali-scene3d/public-api/loader/animation-definition.h>
19 #include <dali-scene3d/public-api/loader/facial-animation-loader.h>
20 #include <dali-test-suite-utils.h>
25 using namespace Dali::Scene3D::Loader;
29 std::string ReadBufferFromFile(const std::string& url)
31 std::string rawString;
32 std::fstream fileStream;
34 fileStream.open(url, std::ios::in | std::ios::binary);
35 if(!fileStream.is_open())
37 DALI_LOG_WARNING("stream open failed for: \"%s\", in mode: \"%d\".\n", url.c_str(), static_cast<int>(std::ios::in | std::ios::binary));
40 // get length of file:
41 fileStream.seekg(0, std::ios::end);
42 auto length = fileStream.tellg();
43 fileStream.seekg(0, std::ios::beg);
45 rawString.resize(length);
46 fileStream.read(rawString.data(), length);
54 int UtcDaliLoadFacialAnimation(void)
58 for(uint32_t tc = 0; tc < 2; ++tc)
60 tet_printf("UtcDaliLoadFacialAnimation testcase %u\n", tc);
61 AnimationDefinition animDef;
64 case 0: // Load bvh from url
66 animDef = LoadFacialAnimation(TEST_RESOURCE_DIR "/facial-blendshape-animation.json");
69 case 1: // Load bvh from buffer stream.
71 std::string rawString = ReadBufferFromFile(TEST_RESOURCE_DIR "/facial-blendshape-animation.json");
72 animDef = LoadFacialAnimationFromBuffer(reinterpret_cast<uint8_t*>(rawString.data()), static_cast<int>(rawString.length()));
77 std::string name = animDef.GetName();
78 DALI_TEST_EQUAL(name, "Facial_Blendshape_Animation");
79 DALI_TEST_EQUAL(animDef.GetDuration(), 14.966001f);
80 DALI_TEST_EQUAL(animDef.GetEndAction(), Animation::BAKE);
81 DALI_TEST_EQUAL(animDef.GetSpeedFactor(), 1.0f);
82 DALI_TEST_EQUAL(animDef.GetLoopCount(), 1);
83 DALI_TEST_EQUAL(animDef.GetPropertyCount(), 122);
85 DALI_TEST_EQUAL(animDef.GetPropertyAt(0).mNodeName, "GEO_1");
86 DALI_TEST_EQUAL(animDef.GetPropertyAt(0).mPropertyName, "uBlendShapeWeight[0]");
87 DALI_TEST_EQUAL(animDef.GetPropertyAt(0).mKeyFrames.GetType(), Property::Type::FLOAT);
88 DALI_TEST_EQUAL(animDef.GetPropertyAt(0).mTimePeriod.delaySeconds, 0.0f);
89 DALI_TEST_EQUAL(animDef.GetPropertyAt(0).mTimePeriod.durationSeconds, 14.966001f);
91 DALI_TEST_EQUAL(animDef.GetPropertyAt(69).mNodeName, "GEO_2");
92 DALI_TEST_EQUAL(animDef.GetPropertyAt(69).mPropertyName, "uBlendShapeWeight[1]");
93 DALI_TEST_EQUAL(animDef.GetPropertyAt(69).mKeyFrames.GetType(), Property::Type::FLOAT);
94 DALI_TEST_EQUAL(animDef.GetPropertyAt(69).mTimePeriod.delaySeconds, 0.0f);
95 DALI_TEST_EQUAL(animDef.GetPropertyAt(69).mTimePeriod.durationSeconds, 14.966001f);
97 DALI_TEST_EQUAL(animDef.GetPropertyAt(86).mNodeName, "GEO_3");
98 DALI_TEST_EQUAL(animDef.GetPropertyAt(86).mPropertyName, "uBlendShapeWeight[2]");
99 DALI_TEST_EQUAL(animDef.GetPropertyAt(86).mKeyFrames.GetType(), Property::Type::FLOAT);
100 DALI_TEST_EQUAL(animDef.GetPropertyAt(86).mTimePeriod.delaySeconds, 0.0f);
101 DALI_TEST_EQUAL(animDef.GetPropertyAt(86).mTimePeriod.durationSeconds, 14.966001f);
103 DALI_TEST_EQUAL(animDef.GetPropertyAt(100).mNodeName, "GEO_4");
104 DALI_TEST_EQUAL(animDef.GetPropertyAt(100).mPropertyName, "uBlendShapeWeight[7]");
105 DALI_TEST_EQUAL(animDef.GetPropertyAt(100).mKeyFrames.GetType(), Property::Type::FLOAT);
106 DALI_TEST_EQUAL(animDef.GetPropertyAt(100).mTimePeriod.delaySeconds, 0.0f);
107 DALI_TEST_EQUAL(animDef.GetPropertyAt(100).mTimePeriod.durationSeconds, 14.966001f);
109 DALI_TEST_EQUAL(animDef.GetPropertyAt(121).mNodeName, "GEO_5");
110 DALI_TEST_EQUAL(animDef.GetPropertyAt(121).mPropertyName, "uBlendShapeWeight[19]");
111 DALI_TEST_EQUAL(animDef.GetPropertyAt(121).mKeyFrames.GetType(), Property::Type::FLOAT);
112 DALI_TEST_EQUAL(animDef.GetPropertyAt(121).mTimePeriod.delaySeconds, 0.0f);
113 DALI_TEST_EQUAL(animDef.GetPropertyAt(121).mTimePeriod.durationSeconds, 14.966001f);
115 auto actor = Actor::New();
116 actor.SetProperty(Actor::Property::NAME, "GEO_1");
118 char weightNameBuffer[32];
119 char* const pWeightName = weightNameBuffer + snprintf(weightNameBuffer, sizeof(weightNameBuffer), "%s", "uBlendShapeWeight");
120 for(int i = 0; i < 122; i++)
122 snprintf(pWeightName, sizeof(weightNameBuffer) - (pWeightName - weightNameBuffer), "[%d]", i);
123 std::string weightName{weightNameBuffer};
124 actor.RegisterProperty(weightName, 0.0f);
127 auto getActor = [&actor](const Dali::Scene3D::Loader::AnimatedProperty& property) {
128 return actor.FindChildByName(property.mNodeName);
131 auto anim = animDef.ReAnimate(getActor);
132 DALI_TEST_EQUAL(anim.GetDuration(), animDef.GetDuration());
133 DALI_TEST_EQUAL(anim.GetEndAction(), animDef.GetEndAction());
134 DALI_TEST_EQUAL(anim.GetSpeedFactor(), animDef.GetSpeedFactor());
135 DALI_TEST_EQUAL(anim.GetLoopCount(), animDef.GetLoopCount());