Add bvh loader in scene-loader
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-scene3d / utc-Dali-BvhLoader.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <dali-test-suite-utils.h>
19 #include <dali-scene3d/public-api/loader/bvh-loader.h>
20
21 using namespace Dali;
22 using namespace Dali::Scene3D::Loader;
23
24 int UtcDaliLoadBvh(void)
25 {
26   TestApplication application;
27
28   AnimationDefinition animDef = LoadBvh(TEST_RESOURCE_DIR "/test.bvh", "testBvh");
29
30   DALI_TEST_EQUAL(animDef.mName, "testBvh");
31   DALI_TEST_EQUAL(animDef.mDuration, 0.3f);
32
33   DALI_TEST_EQUAL(animDef.mProperties[0].mNodeName, "root");
34   DALI_TEST_EQUAL(animDef.mProperties[0].mPropertyName, "position");
35   DALI_TEST_EQUAL(animDef.mProperties[0].mKeyFrames.GetType(), Property::Type::VECTOR3);
36   DALI_TEST_EQUAL(animDef.mProperties[0].mTimePeriod.durationSeconds, 0.3f);
37
38   DALI_TEST_EQUAL(animDef.mProperties[1].mNodeName, "root");
39   DALI_TEST_EQUAL(animDef.mProperties[1].mPropertyName, "orientation");
40   DALI_TEST_EQUAL(animDef.mProperties[1].mKeyFrames.GetType(), Property::Type::ROTATION);
41   DALI_TEST_EQUAL(animDef.mProperties[1].mTimePeriod.durationSeconds, 0.3f);
42
43   DALI_TEST_EQUAL(animDef.mProperties[2].mNodeName, "first");
44   DALI_TEST_EQUAL(animDef.mProperties[2].mPropertyName, "position");
45   DALI_TEST_EQUAL(animDef.mProperties[2].mKeyFrames.GetType(), Property::Type::VECTOR3);
46   DALI_TEST_EQUAL(animDef.mProperties[2].mTimePeriod.durationSeconds, 0.3f);
47
48   DALI_TEST_EQUAL(animDef.mProperties[3].mNodeName, "first");
49   DALI_TEST_EQUAL(animDef.mProperties[3].mPropertyName, "orientation");
50   DALI_TEST_EQUAL(animDef.mProperties[3].mKeyFrames.GetType(), Property::Type::ROTATION);
51   DALI_TEST_EQUAL(animDef.mProperties[3].mTimePeriod.durationSeconds, 0.3f);
52
53   Actor root = Actor::New();
54   root.SetProperty(Actor::Property::NAME, "root");
55
56   Actor first = Actor::New();
57   first.SetProperty(Actor::Property::NAME, "first");
58   root.Add(first);
59
60   auto getActor = [&root](const std::string& name) {
61     return root.FindChildByName(name);
62   };
63
64   Animation animation = animDef.ReAnimate(getActor);
65   DALI_TEST_EQUAL(animation.GetDuration(), animDef.mDuration);
66
67   application.GetScene().Add(root);
68
69   application.SendNotification();
70   application.Render(20);
71
72   DALI_TEST_EQUALS(Vector2(0, 0), root.GetProperty<Vector2>(Actor::Property::POSITION), TEST_LOCATION);
73   DALI_TEST_EQUALS(Vector2(0, 0), first.GetProperty<Vector2>(Actor::Property::POSITION), TEST_LOCATION);
74   Vector3 rootWorldPositionBefore = root.GetProperty<Vector3>(Actor::Property::WORLD_POSITION);
75   Vector3 firstWorldPositionBefore = first.GetProperty<Vector3>(Actor::Property::WORLD_POSITION);
76
77   animation.Play();
78
79   application.SendNotification();
80   application.Render(1000);
81
82   DALI_TEST_EQUALS(Vector2(0, 10), root.GetProperty<Vector2>(Actor::Property::POSITION), TEST_LOCATION);
83   DALI_TEST_EQUALS(Vector2(10, 0), first.GetProperty<Vector2>(Actor::Property::POSITION), TEST_LOCATION);
84
85   Vector3 rootWorldPositionAfter = root.GetProperty<Vector3>(Actor::Property::WORLD_POSITION);
86   Vector3 firstWorldPositionAfter = first.GetProperty<Vector3>(Actor::Property::WORLD_POSITION);
87
88   DALI_TEST_EQUALS(Vector3(0, 10, 0), rootWorldPositionAfter - rootWorldPositionBefore, TEST_LOCATION);
89   DALI_TEST_EQUALS(Vector3(10, 10, 0), firstWorldPositionAfter - firstWorldPositionBefore, TEST_LOCATION);
90
91   END_TEST;
92 }
93
94
95
96 int UtcDaliLoadBvhFailed(void)
97 {
98   TestApplication application;
99
100   AnimationDefinition animDef = LoadBvh("/nothing.bvh", "testBvh");
101   DALI_TEST_EQUALS(0u, animDef.mProperties.size(), TEST_LOCATION);
102   END_TEST;
103 }