2 * Copyright (c) 2022 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-test-suite-utils.h>
19 #include <dali-scene3d/public-api/loader/animation-definition.h>
20 #include <dali-scene3d/public-api/loader/facial-animation-loader.h>
23 using namespace Dali::Scene3D::Loader;
25 int UtcDaliLoadFacialAnimation(void)
29 AnimationDefinition animDef = LoadFacialAnimation(TEST_RESOURCE_DIR "/facial-blendshape-animation.json");
31 std::string name = animDef.GetName();
32 DALI_TEST_EQUAL(name, "Facial_Blendshape_Animation");
33 DALI_TEST_EQUAL(animDef.GetDuration(), 14.966001f);
34 DALI_TEST_EQUAL(animDef.GetEndAction(), Animation::BAKE);
35 DALI_TEST_EQUAL(animDef.GetSpeedFactor(), 1.0f);
36 DALI_TEST_EQUAL(animDef.GetLoopCount(), 1);
37 DALI_TEST_EQUAL(animDef.GetPropertyCount(), 122);
39 DALI_TEST_EQUAL(animDef.GetPropertyAt(0).mNodeName, "GEO_1");
40 DALI_TEST_EQUAL(animDef.GetPropertyAt(0).mPropertyName, "uBlendShapeWeight[0]");
41 DALI_TEST_EQUAL(animDef.GetPropertyAt(0).mKeyFrames.GetType(), Property::Type::FLOAT);
42 DALI_TEST_EQUAL(animDef.GetPropertyAt(0).mTimePeriod.delaySeconds, 0.0f);
43 DALI_TEST_EQUAL(animDef.GetPropertyAt(0).mTimePeriod.durationSeconds, 14.966001f);
45 DALI_TEST_EQUAL(animDef.GetPropertyAt(69).mNodeName, "GEO_2");
46 DALI_TEST_EQUAL(animDef.GetPropertyAt(69).mPropertyName, "uBlendShapeWeight[1]");
47 DALI_TEST_EQUAL(animDef.GetPropertyAt(69).mKeyFrames.GetType(), Property::Type::FLOAT);
48 DALI_TEST_EQUAL(animDef.GetPropertyAt(69).mTimePeriod.delaySeconds, 0.0f);
49 DALI_TEST_EQUAL(animDef.GetPropertyAt(69).mTimePeriod.durationSeconds, 14.966001f);
51 DALI_TEST_EQUAL(animDef.GetPropertyAt(86).mNodeName, "GEO_3");
52 DALI_TEST_EQUAL(animDef.GetPropertyAt(86).mPropertyName, "uBlendShapeWeight[2]");
53 DALI_TEST_EQUAL(animDef.GetPropertyAt(86).mKeyFrames.GetType(), Property::Type::FLOAT);
54 DALI_TEST_EQUAL(animDef.GetPropertyAt(86).mTimePeriod.delaySeconds, 0.0f);
55 DALI_TEST_EQUAL(animDef.GetPropertyAt(86).mTimePeriod.durationSeconds, 14.966001f);
57 DALI_TEST_EQUAL(animDef.GetPropertyAt(100).mNodeName, "GEO_4");
58 DALI_TEST_EQUAL(animDef.GetPropertyAt(100).mPropertyName, "uBlendShapeWeight[7]");
59 DALI_TEST_EQUAL(animDef.GetPropertyAt(100).mKeyFrames.GetType(), Property::Type::FLOAT);
60 DALI_TEST_EQUAL(animDef.GetPropertyAt(100).mTimePeriod.delaySeconds, 0.0f);
61 DALI_TEST_EQUAL(animDef.GetPropertyAt(100).mTimePeriod.durationSeconds, 14.966001f);
63 DALI_TEST_EQUAL(animDef.GetPropertyAt(121).mNodeName, "GEO_5");
64 DALI_TEST_EQUAL(animDef.GetPropertyAt(121).mPropertyName, "uBlendShapeWeight[19]");
65 DALI_TEST_EQUAL(animDef.GetPropertyAt(121).mKeyFrames.GetType(), Property::Type::FLOAT);
66 DALI_TEST_EQUAL(animDef.GetPropertyAt(121).mTimePeriod.delaySeconds, 0.0f);
67 DALI_TEST_EQUAL(animDef.GetPropertyAt(121).mTimePeriod.durationSeconds, 14.966001f);
69 auto actor = Actor::New();
70 actor.SetProperty(Actor::Property::NAME, "GEO_1");
72 char weightNameBuffer[32];
73 char* const pWeightName = weightNameBuffer + snprintf(weightNameBuffer, sizeof(weightNameBuffer), "%s", "uBlendShapeWeight");
74 for(int i = 0; i < 122; i++)
76 snprintf(pWeightName, sizeof(weightNameBuffer) - (pWeightName - weightNameBuffer), "[%d]", i);
77 std::string weightName{weightNameBuffer};
78 actor.RegisterProperty(weightName, 0.0f);
81 auto getActor = [&actor](const Dali::Scene3D::Loader::AnimatedProperty& property) {
82 return actor.FindChildByName(property.mNodeName);
85 auto anim = animDef.ReAnimate(getActor);
86 DALI_TEST_EQUAL(anim.GetDuration(), animDef.GetDuration());
87 DALI_TEST_EQUAL(anim.GetEndAction(), animDef.GetEndAction());
88 DALI_TEST_EQUAL(anim.GetSpeedFactor(), animDef.GetSpeedFactor());
89 DALI_TEST_EQUAL(anim.GetLoopCount(), animDef.GetLoopCount());