Fix transform issue of skinned mesh
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-scene3d-internal / utc-Dali-DliLoaderImpl.cpp
1 /*
2  * Copyright (c) 2023 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 // Enable debug log for test coverage
19 #define DEBUG_ENABLED 1
20
21 #include <dali-scene3d/internal/loader/dli-loader-impl.h>
22 #include <dali-scene3d/internal/loader/json-util.h>
23 #include <dali-scene3d/public-api/loader/load-result.h>
24 #include <dali-scene3d/public-api/loader/resource-bundle.h>
25 #include <dali-scene3d/public-api/loader/scene-definition.h>
26 #include <dali-test-suite-utils.h>
27 #include <string_view>
28
29 using namespace Dali;
30 using namespace Dali::Scene3D::Loader;
31
32 namespace
33 {
34 void ConfigureBlendShapeShaders(ResourceBundle& resources, const SceneDefinition& scene, Actor root, std::vector<BlendshapeShaderConfigurationRequest>&& requests)
35 {
36   std::vector<std::string> errors;
37   auto                     onError = [&errors](const std::string& msg)
38   {
39     errors.push_back(msg);
40   };
41
42   if(!scene.ConfigureBlendshapeShaders(resources, root, std::move(requests), onError))
43   {
44     ExceptionFlinger flinger(ASSERT_LOCATION);
45     for(auto& msg : errors)
46     {
47       flinger << msg << '\n';
48     }
49   }
50 }
51
52 struct Context
53 {
54   ResourceBundle::PathProvider pathProvider = [](ResourceType::Value type)
55   {
56     return TEST_RESOURCE_DIR "/";
57   };
58
59   ResourceBundle                        resources;
60   SceneDefinition                       scene;
61   std::vector<CameraParameters>         cameraParameters;
62   std::vector<LightParameters>          lights;
63   std::vector<AnimationDefinition>      animations;
64   std::vector<AnimationGroupDefinition> animGroups;
65
66   SceneMetadata metaData;
67
68   LoadResult output{
69     resources,
70     scene,
71     metaData,
72     animations,
73     animGroups,
74     cameraParameters,
75     lights};
76
77   Dali::Scene3D::Loader::DliInputParameter       input;
78   std::vector<std::string>                       errors;
79   Dali::Scene3D::Loader::Internal::DliLoaderImpl loader;
80
81   StringCallback onError = [this](const std::string& error)
82   {
83     errors.push_back(error);
84     printf("%s\n", error.c_str());
85   };
86
87   Context()
88   {
89     input.mAnimationsPath = pathProvider(ResourceType::Mesh);
90     loader.SetErrorCallback(onError);
91     loader.SetInputParameter(input);
92   }
93 };
94
95 bool StringHasTokens(const char* string, const std::vector<const char*>& tokens)
96 {
97   for(auto& token : tokens)
98   {
99     auto result = strstr(string, token);
100     if(nullptr == result)
101     {
102       return false;
103     }
104     string = result + strlen(token);
105   }
106   return true;
107 }
108
109 } // namespace
110
111 int UtcDaliDliLoaderLoadSceneNotFound(void)
112 {
113   Context ctx;
114
115   DALI_TEST_EQUAL(ctx.loader.LoadModel("does_not_exist.dli", ctx.output), false);
116
117   auto error = ctx.loader.GetParseError();
118   DALI_TEST_CHECK(StringHasTokens(error.c_str(), {"Empty source buffer to parse."}));
119
120   END_TEST;
121 }
122
123 int UtcDaliDliLoaderLoadSceneFailParse(void)
124 {
125   Context ctx;
126
127   auto path = ctx.pathProvider(ResourceType::Mesh) + "invalid.gltf";
128   DALI_TEST_EQUAL(ctx.loader.LoadModel(path, ctx.output), false);
129
130   auto error = ctx.loader.GetParseError();
131   DALI_TEST_CHECK(StringHasTokens(error.c_str(), {"Unexpected character."}));
132
133   END_TEST;
134 }
135
136 int UtcDaliDliLoaderLoadSceneAssertions(void)
137 {
138   const std::pair<std::string, std::string> pathExceptionPairs[]{
139     // from RequireChild()
140     {"scenes-nodes-missing", "Failed to find child node"},
141     {"scenes-missing", "Failed to find child node"},
142     {"nodes-missing", "Failed to find child node"},
143     // from ParseSceneInternal()
144     {"scene-out-of-bounds", "out of bounds"},
145     {"nodes-invalid-type", "invalid type; array required"},
146     {"nodes-array-empty", "must define a node id"},
147     {"root-id-invalid", "invalid value for root node index"},
148     {"root-id-out-of-bounds", "out of bounds"},
149     {"root-node-invalid-type", "invalid JSON type; object required"},
150     // from ParseSkeletons()
151     {"skeleton-node-missing", "Missing required attribute"},
152     {"skeleton-root-not-found", "not defined"},
153     // from ParseShaders()
154     {"shader-vertex-missing", "Missing vertex / fragment shader"},
155     {"shader-fragment-missing", "Missing vertex / fragment shader"},
156     // from ParseMeshes()
157     {"mesh-uri-missing", "Missing required attribute"},
158     {"mesh-indices-read-fail", "Failed to read indices"},
159     {"mesh-positions-read-fail", "Failed to read positions"},
160     // from ParseMaterials()
161     {"material-environment-out-of-bounds", "out of bounds"},
162     // from ParseNodes()
163     {"node-model-mesh-missing", "Missing mesh"},
164     {"node-arc-mesh-missing", "Missing mesh"},
165     {"node-animated-image-mesh-missing", "Missing mesh"},
166     {"node-renderable-mesh-invalid-type", "Invalid Mesh index type"},
167     {"node-renderable-mesh-out-of-bounds", "out of bounds"},
168     {"node-child-invalid-type", "invalid index type"},
169     // from ParseAnimations()
170     {"animation-failed-to-open", "Failed to open animation data"}};
171   for(auto& i : pathExceptionPairs)
172   {
173     Context ctx;
174
175     auto path = ctx.pathProvider(ResourceType::Mesh) + "dli/" + i.first + ".dli";
176     printf("\n\n%s: %s\n", path.c_str(), i.second.c_str());
177     DALI_TEST_ASSERTION(ctx.loader.LoadModel(path, ctx.output), i.second.c_str());
178   }
179
180   END_TEST;
181 }
182
183 int UtcDaliDliLoaderLoadSceneExercise(void)
184 {
185   TestApplication app;
186   Context ctx;
187
188   auto path = ctx.pathProvider(ResourceType::Mesh) + "exercise.dli";
189   DALI_TEST_CHECK(ctx.loader.LoadModel(path, ctx.output));
190   DALI_TEST_CHECK(ctx.errors.empty());
191
192   auto& scene = ctx.scene;
193   auto& roots = scene.GetRoots();
194   DALI_TEST_EQUAL(roots.size(), 2u);
195   DALI_TEST_EQUAL(scene.GetNode(roots[0])->mName, "Backdrop"); // default scene is scene 1 - this one.
196   DALI_TEST_EQUAL(scene.GetNode(roots[1])->mName, "ExerciseDemo");
197
198   DALI_TEST_EQUAL(scene.GetNodeCount(), 96u);
199
200   auto& resources = ctx.resources;
201   DALI_TEST_EQUAL(resources.mMeshes.size(), 11u);
202   DALI_TEST_EQUAL(resources.mMaterials.size(), 13u);
203   DALI_TEST_EQUAL(resources.mShaders.size(), 5u);
204   DALI_TEST_EQUAL(resources.mEnvironmentMaps.size(), 2u);
205   DALI_TEST_EQUAL(resources.mSkeletons.size(), 1u);
206
207   DALI_TEST_EQUAL(ctx.cameraParameters.size(), 1u);
208   DALI_TEST_EQUAL(ctx.lights.size(), 1u);
209   DALI_TEST_EQUAL(ctx.animations.size(), 18u);
210   DALI_TEST_EQUAL(ctx.animGroups.size(), 16u);
211
212   ViewProjection viewProjection;
213   Transforms     xforms{
214     MatrixStack{},
215     viewProjection};
216   NodeDefinition::CreateParams nodeParams{
217     resources,
218     xforms,
219   };
220
221   Customization::Choices choices;
222
223   Actor root = Actor::New();
224   SetActorCentered(root);
225   for(auto iRoot : scene.GetRoots())
226   {
227     auto resourceRefs = resources.CreateRefCounter();
228     scene.CountResourceRefs(iRoot, choices, resourceRefs);
229     resources.mReferenceCounts = std::move(resourceRefs);
230     resources.CountEnvironmentReferences();
231     resources.LoadResources(ctx.pathProvider);
232     if(auto actor = scene.CreateNodes(iRoot, choices, nodeParams))
233     {
234       scene.ConfigureSkinningShaders(resources, actor, std::move(nodeParams.mSkinnables));
235       ConfigureBlendShapeShaders(resources, scene, actor, std::move(nodeParams.mBlendshapeRequests));
236       scene.ApplyConstraints(actor, std::move(nodeParams.mConstrainables));
237       root.Add(actor);
238     }
239   }
240
241   DALI_TEST_EQUAL(root.GetChildCount(), 2u);
242   DALI_TEST_EQUAL(root.GetChildAt(0).GetProperty(Actor::Property::NAME).Get<std::string>(), "Backdrop");
243   DALI_TEST_EQUAL(root.GetChildAt(1).GetProperty(Actor::Property::NAME).Get<std::string>(), "ExerciseDemo");
244
245   END_TEST;
246 }
247
248 int UtcDaliDliLoaderLoadSceneMorph(void)
249 {
250   Context ctx;
251
252   std::vector<std::string> metadata;
253   uint32_t                 metadataCount = 0;
254   ctx.input.mPreNodeCategoryProcessors.push_back({"metadata",
255                                                   [&](const Property::Array& array, StringCallback)
256                                                   {
257                                                     std::string key, value;
258                                                     for(uint32_t i0 = 0, i1 = array.Count(); i0 < i1; ++i0)
259                                                     {
260                                                       auto& data = array.GetElementAt(i0);
261                                                       DALI_TEST_EQUAL(data.GetType(), Property::MAP);
262
263                                                       auto map   = data.GetMap();
264                                                       auto key   = map->Find("key");
265                                                       auto value = map->Find("value");
266                                                       DALI_TEST_EQUAL(key->GetType(), Property::STRING);
267                                                       DALI_TEST_EQUAL(value->GetType(), Property::STRING);
268                                                       metadata.push_back(key->Get<std::string>() + ":" + value->Get<std::string>());
269
270                                                       ++metadataCount;
271                                                     }
272                                                   }});
273
274   std::vector<std::string> behaviors;
275   uint32_t                 behaviorCount = 0;
276   ctx.input.mPostNodeCategoryProcessors.push_back({"behaviors",
277                                                    [&](const Property::Array& array, StringCallback)
278                                                    {
279                                                      for(uint32_t i0 = 0, i1 = array.Count(); i0 < i1; ++i0)
280                                                      {
281                                                        auto& data = array.GetElementAt(i0);
282                                                        DALI_TEST_EQUAL(data.GetType(), Property::MAP);
283
284                                                        auto map   = data.GetMap();
285                                                        auto event = map->Find("event");
286                                                        auto url   = map->Find("url");
287                                                        DALI_TEST_EQUAL(event->GetType(), Property::STRING);
288                                                        DALI_TEST_EQUAL(url->GetType(), Property::STRING);
289                                                        behaviors.push_back(event->Get<std::string>() + ":" + url->Get<std::string>());
290
291                                                        ++behaviorCount;
292                                                      }
293                                                    }});
294
295   size_t numNodes                  = 0;
296   ctx.input.mNodePropertyProcessor = [&](const NodeDefinition&, const Property::Map&, StringCallback)
297   {
298     ++numNodes;
299   };
300
301   auto path = ctx.pathProvider(ResourceType::Mesh) + "morph.dli";
302   DALI_TEST_CHECK(ctx.loader.LoadModel(path, ctx.output));
303   DALI_TEST_CHECK(ctx.errors.empty());
304
305   auto& scene = ctx.scene;
306   auto& roots = scene.GetRoots();
307   DALI_TEST_EQUAL(roots.size(), 1u);
308   DALI_TEST_EQUAL(scene.GetNode(roots[0])->mName, "HeadTest_002");
309
310   DALI_TEST_EQUAL(numNodes, 3u);
311   DALI_TEST_EQUAL(scene.GetNodeCount(), numNodes);
312
313   auto& resources = ctx.resources;
314   DALI_TEST_EQUAL(resources.mMeshes.size(), 2u);
315   DALI_TEST_EQUAL(resources.mMaterials.size(), 1u);
316   DALI_TEST_EQUAL(resources.mShaders.size(), 5u);
317   DALI_TEST_EQUAL(resources.mEnvironmentMaps.size(), 2u);
318   DALI_TEST_EQUAL(resources.mSkeletons.size(), 0u);
319
320   DALI_TEST_EQUAL(ctx.cameraParameters.size(), 1u);
321   DALI_TEST_EQUAL(ctx.lights.size(), 1u);
322   DALI_TEST_EQUAL(ctx.animations.size(), 1u);
323   DALI_TEST_EQUAL(ctx.animGroups.size(), 0u);
324
325   DALI_TEST_EQUAL(metadata.size(), 4u);
326   DALI_TEST_EQUAL(behaviors.size(), 1u);
327
328   ViewProjection viewProjection;
329   Transforms     xforms{
330     MatrixStack{},
331     viewProjection};
332   NodeDefinition::CreateParams nodeParams{
333     resources,
334     xforms,
335   };
336
337   Customization::Choices choices;
338
339   TestApplication app;
340
341   Actor root = Actor::New();
342   SetActorCentered(root);
343   for(auto iRoot : scene.GetRoots())
344   {
345     auto resourceRefs = resources.CreateRefCounter();
346     scene.CountResourceRefs(iRoot, choices, resourceRefs);
347     resources.mReferenceCounts = std::move(resourceRefs);
348     resources.CountEnvironmentReferences();
349     resources.LoadResources(ctx.pathProvider);
350     if(auto actor = scene.CreateNodes(iRoot, choices, nodeParams))
351     {
352       scene.ConfigureSkinningShaders(resources, actor, std::move(nodeParams.mSkinnables));
353       ConfigureBlendShapeShaders(resources, scene, actor, std::move(nodeParams.mBlendshapeRequests));
354       scene.ApplyConstraints(actor, std::move(nodeParams.mConstrainables));
355       root.Add(actor);
356     }
357   }
358
359   DALI_TEST_EQUAL(root.GetChildCount(), 1u);
360   DALI_TEST_EQUAL(root.GetChildAt(0).GetProperty(Actor::Property::NAME).Get<std::string>(), "HeadTest_002");
361
362   END_TEST;
363 }
364
365 int UtcDaliDliLoaderLoadSceneArc(void)
366 {
367   Context ctx;
368
369   auto path = ctx.pathProvider(ResourceType::Mesh) + "arc.dli";
370   DALI_TEST_CHECK(ctx.loader.LoadModel(path, ctx.output));
371   DALI_TEST_CHECK(ctx.errors.empty());
372
373   auto& scene = ctx.scene;
374   auto& roots = scene.GetRoots();
375   DALI_TEST_EQUAL(roots.size(), 1u);
376   DALI_TEST_EQUAL(scene.GetNode(roots[0])->mName, "root");
377
378   DALI_TEST_EQUAL(scene.GetNodeCount(), 2u);
379
380   auto& resources = ctx.resources;
381   DALI_TEST_EQUAL(resources.mMeshes.size(), 1u);
382   DALI_TEST_EQUAL(resources.mMaterials.size(), 1u);
383   DALI_TEST_EQUAL(resources.mShaders.size(), 1u);
384   DALI_TEST_EQUAL(resources.mEnvironmentMaps.size(), 1u);
385   DALI_TEST_EQUAL(resources.mSkeletons.size(), 0u);
386
387   DALI_TEST_EQUAL(ctx.cameraParameters.size(), 0u);
388   DALI_TEST_EQUAL(ctx.lights.size(), 0u);
389   DALI_TEST_EQUAL(ctx.animations.size(), 0u);
390   DALI_TEST_EQUAL(ctx.animGroups.size(), 0u);
391
392   ViewProjection viewProjection;
393   Transforms     xforms{
394     MatrixStack{},
395     viewProjection};
396   NodeDefinition::CreateParams nodeParams{
397     resources,
398     xforms,
399   };
400
401   Customization::Choices choices;
402
403   TestApplication app;
404
405   Actor root = Actor::New();
406   SetActorCentered(root);
407   for(auto iRoot : scene.GetRoots())
408   {
409     auto resourceRefs = resources.CreateRefCounter();
410     scene.CountResourceRefs(iRoot, choices, resourceRefs);
411     resources.mReferenceCounts = std::move(resourceRefs);
412     resources.CountEnvironmentReferences();
413     resources.LoadResources(ctx.pathProvider);
414     if(auto actor = scene.CreateNodes(iRoot, choices, nodeParams))
415     {
416       scene.ConfigureSkinningShaders(resources, actor, std::move(nodeParams.mSkinnables));
417       ConfigureBlendShapeShaders(resources, scene, actor, std::move(nodeParams.mBlendshapeRequests));
418       scene.ApplyConstraints(actor, std::move(nodeParams.mConstrainables));
419       root.Add(actor);
420     }
421   }
422
423   DALI_TEST_EQUAL(root.GetChildCount(), 1u);
424   DALI_TEST_EQUAL(root.GetChildAt(0).GetProperty(Actor::Property::NAME).Get<std::string>(), "root");
425
426   END_TEST;
427 }
428
429 int UtcDaliDliLoaderLoadSceneShaderUniforms(void)
430 {
431   Context ctx;
432
433   auto path = ctx.pathProvider(ResourceType::Mesh) + "dli/shader-uniforms.dli";
434   DALI_TEST_CHECK(ctx.loader.LoadModel(path, ctx.output));
435   DALI_TEST_EQUAL(ctx.errors.size(), 1u);
436   DALI_TEST_CHECK(ctx.errors[0].find("failed to infer type") != std::string::npos);
437
438   auto& scene = ctx.scene;
439   auto& roots = scene.GetRoots();
440   DALI_TEST_EQUAL(roots.size(), 1u);
441   DALI_TEST_EQUAL(scene.GetNode(roots[0])->mName, "root");
442
443   DALI_TEST_EQUAL(scene.GetNodeCount(), 1u);
444
445   auto& resources = ctx.resources;
446   DALI_TEST_EQUAL(resources.mMeshes.size(), 0u);
447   DALI_TEST_EQUAL(resources.mMaterials.size(), 0u);
448   DALI_TEST_EQUAL(resources.mShaders.size(), 1u);
449   DALI_TEST_EQUAL(resources.mEnvironmentMaps.size(), 0u);
450   DALI_TEST_EQUAL(resources.mSkeletons.size(), 0u);
451
452   auto raw = resources.mShaders[0].first.LoadRaw(ctx.pathProvider(ResourceType::Shader));
453
454   TestApplication app;
455
456   auto shader = resources.mShaders[0].first.Load(std::move(raw));
457   DALI_TEST_EQUAL(shader.GetProperty(shader.GetPropertyIndex("uBool")).Get<float>(), 1.0f);
458   DALI_TEST_EQUAL(shader.GetProperty(shader.GetPropertyIndex("uInt")).Get<float>(), 255.0f);
459   DALI_TEST_EQUAL(shader.GetProperty(shader.GetPropertyIndex("uFloat")).Get<float>(), -0.5f);
460   DALI_TEST_EQUAL(shader.GetProperty(shader.GetPropertyIndex("uVec2")).Get<Vector2>(), Vector2(100.0f, -100.0f));
461   DALI_TEST_EQUAL(shader.GetProperty(shader.GetPropertyIndex("uVec3")).Get<Vector3>(), Vector3(50.0f, 0.f, -200.0f));
462   DALI_TEST_EQUAL(shader.GetProperty(shader.GetPropertyIndex("uVec4")).Get<Vector4>(), Vector4(0.1774f, 1.0f, 0.5333f, 0.7997f));
463   DALI_TEST_EQUAL(shader.GetProperty(shader.GetPropertyIndex("uMat3")).Get<Matrix3>(), Matrix3(9.0f, 8.0f, 7.0f, 6.0f, 5.0f, 4.0f, 3.0f, 2.0f, 1.0f));
464
465   Matrix expectedMatrix;
466   expectedMatrix.SetTransformComponents(Vector3::ONE * 8.0, Quaternion::IDENTITY, Vector3::ZERO);
467   DALI_TEST_EQUAL(shader.GetProperty(shader.GetPropertyIndex("uMat4")).Get<Matrix>(), expectedMatrix);
468
469   END_TEST;
470 }
471
472 int UtcDaliDliLoaderLoadSceneExtras(void)
473 {
474   Context ctx;
475
476   auto path = ctx.pathProvider(ResourceType::Mesh) + "dli/extras.dli";
477   DALI_TEST_CHECK(ctx.loader.LoadModel(path, ctx.output));
478   DALI_TEST_EQUAL(ctx.errors.size(), 3u);
479   DALI_TEST_CHECK(ctx.errors[0].find("already defined; overriding") != std::string::npos);
480   DALI_TEST_CHECK(ctx.errors[1].find("empty string is invalid for name") != std::string::npos);
481   DALI_TEST_CHECK(ctx.errors[2].find("failed to interpret value") != std::string::npos);
482
483   auto& scene = ctx.scene;
484   auto& roots = scene.GetRoots();
485   DALI_TEST_EQUAL(roots.size(), 1u);
486   DALI_TEST_EQUAL(scene.GetNode(roots[0])->mName, "root");
487
488   DALI_TEST_EQUAL(scene.GetNodeCount(), 1u);
489
490   ViewProjection viewProjection;
491   Transforms     xforms{
492     MatrixStack{},
493     viewProjection};
494   auto&                        resources = ctx.resources;
495   NodeDefinition::CreateParams nodeParams{
496     resources,
497     xforms,
498   };
499
500   Customization::Choices choices;
501
502   TestApplication app;
503   Actor           actor = scene.CreateNodes(0, choices, nodeParams);
504
505   DALI_TEST_EQUAL(actor.GetProperty(actor.GetPropertyIndex("fudgeFactor")).Get<float>(), 9000.1f);
506   DALI_TEST_EQUAL(actor.GetProperty(actor.GetPropertyIndex("fudgeVector")).Get<Vector2>(), Vector2(-.25f, 17.f));
507   DALI_TEST_EQUAL(actor.GetProperty(actor.GetPropertyIndex("isThisTheRealLife")).Get<bool>(), true);
508   DALI_TEST_EQUAL(actor.GetProperty(actor.GetPropertyIndex("isThisJustFantasy")).Get<bool>(), false);
509   DALI_TEST_EQUAL(actor.GetProperty(actor.GetPropertyIndex("velocity")).Get<Vector3>(), Vector3(.1f, 58.f, -.2f));
510   DALI_TEST_EQUAL(actor.GetProperty(actor.GetPropertyIndex("frameOfReference")).Get<Matrix>(), Matrix::IDENTITY);
511
512   END_TEST;
513 }
514
515 int UtcDaliDliLoaderLoadSceneConstraints(void)
516 {
517   Context ctx;
518
519   auto path = ctx.pathProvider(ResourceType::Mesh) + "dli/constraints.dli";
520   DALI_TEST_CHECK(ctx.loader.LoadModel(path, ctx.output));
521   DALI_TEST_EQUAL(ctx.errors.size(), 1u);
522   DALI_TEST_CHECK(ctx.errors[0].find("invalid", ctx.errors[0].find("node ID")) != std::string::npos);
523
524   auto& scene = ctx.scene;
525   auto& roots = scene.GetRoots();
526   DALI_TEST_EQUAL(roots.size(), 1u);
527   DALI_TEST_EQUAL(scene.GetNode(0)->mName, "root");
528   DALI_TEST_EQUAL(scene.GetNode(1)->mName, "Alice");
529   DALI_TEST_EQUAL(scene.GetNode(2)->mName, "Bob");
530   DALI_TEST_EQUAL(scene.GetNode(3)->mName, "Charlie");
531
532   DALI_TEST_EQUAL(scene.GetNodeCount(), 4u);
533
534   ViewProjection viewProjection;
535   Transforms     xforms{
536     MatrixStack{},
537     viewProjection};
538   auto&                        resources = ctx.resources;
539   NodeDefinition::CreateParams nodeParams{
540     resources,
541     xforms,
542   };
543
544   Customization::Choices choices;
545
546   TestApplication app;
547
548   Actor root    = scene.CreateNodes(0, choices, nodeParams);
549   Actor alice   = root.FindChildByName("Alice");
550   Actor bob     = root.FindChildByName("Bob");
551   Actor charlie = root.FindChildByName("Charlie");
552
553   DALI_TEST_EQUAL(nodeParams.mConstrainables.size(), 3u);
554   DALI_TEST_EQUAL(bob.GetProperty(bob.GetPropertyIndex("angularVelocity")).Get<Vector2>(), Vector2(-0.5, 0.0004));
555
556   ctx.errors.clear();
557   scene.ApplyConstraints(root, std::move(nodeParams.mConstrainables), ctx.onError);
558   DALI_TEST_CHECK(ctx.errors.empty());
559
560   app.GetScene().Add(root);
561   app.SendNotification();
562   app.Render();
563   app.SendNotification();
564   app.Render();
565
566   DALI_TEST_EQUAL(charlie.GetCurrentProperty(Actor::Property::ORIENTATION), alice.GetProperty(Actor::Property::ORIENTATION));
567   DALI_TEST_EQUAL(charlie.GetCurrentProperty(Actor::Property::POSITION), bob.GetProperty(Actor::Property::POSITION));
568   DALI_TEST_EQUAL(charlie.GetCurrentProperty(charlie.GetPropertyIndex("angularVelocity")), bob.GetProperty(bob.GetPropertyIndex("angularVelocity")));
569
570   END_TEST;
571 }
572
573 int UtcDaliDliLoaderNodeProcessor(void)
574 {
575   Context ctx;
576
577   std::vector<Property::Map> nodeMaps;
578   ctx.input.mNodePropertyProcessor = [&](const NodeDefinition&, Property::Map&& map, StringCallback)
579   {
580     nodeMaps.push_back(map);
581   };
582
583   auto path = ctx.pathProvider(ResourceType::Mesh) + "dli/node-processor.dli";
584   DALI_TEST_CHECK(ctx.loader.LoadModel(path, ctx.output));
585
586   DALI_TEST_EQUAL(nodeMaps.size(), 2u);
587   DALI_TEST_EQUAL(nodeMaps[0].Count(), 5u);
588   DALI_TEST_EQUAL(nodeMaps[0].Find("name")->Get<std::string>(), "rootA");
589   DALI_TEST_EQUAL(nodeMaps[0].Find("nickname")->Get<std::string>(), "same as name");
590   DALI_TEST_EQUAL(nodeMaps[0].Find("favourite number")->Get<int32_t>(), 63478);
591
592   auto propArray = nodeMaps[0].Find("array");
593   DALI_TEST_EQUAL(propArray->GetType(), Property::ARRAY);
594
595   auto array = propArray->GetArray();
596   DALI_TEST_EQUAL(array->Count(), 5);
597   DALI_TEST_EQUAL(array->GetElementAt(0).Get<int32_t>(), 1);
598   DALI_TEST_EQUAL(array->GetElementAt(1).Get<int32_t>(), 2);
599   DALI_TEST_EQUAL(array->GetElementAt(2).Get<int32_t>(), 4);
600   DALI_TEST_EQUAL(array->GetElementAt(3).Get<int32_t>(), 8);
601   DALI_TEST_EQUAL(array->GetElementAt(4).Get<int32_t>(), -500);
602
603   auto propObject = nodeMaps[0].Find("object");
604   DALI_TEST_EQUAL(propObject->GetType(), Property::MAP);
605
606   auto object = propObject->GetMap();
607   DALI_TEST_EQUAL(object->Count(), 5);
608   DALI_TEST_EQUAL(object->Find("physics")->Get<bool>(), true);
609   DALI_TEST_EQUAL(object->Find("elasticity")->Get<float>(), .27f);
610   DALI_TEST_EQUAL(object->Find("drag")->Get<float>(), .91f);
611
612   auto propInnerArray = object->Find("inner array");
613   DALI_TEST_EQUAL(propInnerArray->GetType(), Property::ARRAY);
614
615   auto innerArray = propInnerArray->GetArray();
616   DALI_TEST_EQUAL(innerArray->Count(), 3);
617   DALI_TEST_EQUAL(innerArray->GetElementAt(0).Get<std::string>(), "why");
618   DALI_TEST_EQUAL(innerArray->GetElementAt(1).Get<std::string>(), "not");
619   DALI_TEST_EQUAL(innerArray->GetElementAt(2).Get<bool>(), false);
620
621   auto propInnerObject = object->Find("inner object");
622   DALI_TEST_EQUAL(propInnerObject->GetType(), Property::MAP);
623
624   auto innerObject = propInnerObject->GetMap();
625   DALI_TEST_EQUAL(innerObject->Count(), 1);
626   DALI_TEST_EQUAL(innerObject->Find("supported")->Get<bool>(), true);
627
628   DALI_TEST_EQUAL(nodeMaps[1].Count(), 1u);
629   DALI_TEST_EQUAL(nodeMaps[1].Find("name")->Get<std::string>(), "rootB");
630
631   END_TEST;
632 }
633
634 int UtcDaliDliLoaderLoadCoverageTest(void)
635 {
636   Context ctx;
637
638   auto path = ctx.pathProvider(ResourceType::Mesh) + "coverageTest.dli";
639   DALI_TEST_CHECK(ctx.loader.LoadModel(path, ctx.output));
640   DALI_TEST_CHECK(ctx.errors.empty());
641
642   auto& scene = ctx.scene;
643   auto& roots = scene.GetRoots();
644   DALI_TEST_EQUAL(roots.size(), 1u);
645   DALI_TEST_EQUAL(scene.GetNode(roots[0])->mName, "root");
646
647   DALI_TEST_EQUAL(scene.GetNodeCount(), 1u);
648
649   auto& resources = ctx.resources;
650   DALI_TEST_EQUAL(resources.mMeshes.size(), 1u);
651   DALI_TEST_EQUAL(resources.mShaders.size(), 1u);
652   DALI_TEST_EQUAL(resources.mEnvironmentMaps.size(), 2u);
653   DALI_TEST_EQUAL(resources.mSkeletons.size(), 0u);
654
655   auto& materials = ctx.resources.mMaterials;
656   DALI_TEST_EQUAL(2u, materials.size());
657
658   auto  iMaterial = materials.begin();
659   auto& md        = iMaterial->first;
660   DALI_TEST_EQUAL(md.mTextureStages.size(), 1u);
661
662   auto iTexture = md.mTextureStages.begin();
663   DALI_TEST_CHECK(MaskMatch(iTexture->mSemantic, MaterialDefinition::OCCLUSION));
664   DALI_TEST_EQUAL(iTexture->mTexture.mImageUri, "exercise/Icons/Icon_Idle.png");
665   ++iTexture;
666
667   DALI_TEST_EQUAL(ctx.cameraParameters.size(), 1u);
668   DALI_TEST_EQUAL(ctx.lights.size(), 1u);
669   DALI_TEST_EQUAL(ctx.animations.size(), 0u);
670   DALI_TEST_EQUAL(ctx.animGroups.size(), 0u);
671
672   ViewProjection viewProjection;
673   Transforms     xforms{
674     MatrixStack{},
675     viewProjection};
676   NodeDefinition::CreateParams nodeParams{
677     resources,
678     xforms,
679   };
680
681   Customization::Choices choices;
682
683   TestApplication app;
684
685   Actor root = Actor::New();
686   SetActorCentered(root);
687   for(auto iRoot : scene.GetRoots())
688   {
689     auto resourceRefs = resources.CreateRefCounter();
690     scene.CountResourceRefs(iRoot, choices, resourceRefs);
691     resources.mReferenceCounts = std::move(resourceRefs);
692     resources.CountEnvironmentReferences();
693     resources.LoadResources(ctx.pathProvider);
694     if(auto actor = scene.CreateNodes(iRoot, choices, nodeParams))
695     {
696       scene.ConfigureSkinningShaders(resources, actor, std::move(nodeParams.mSkinnables));
697       ConfigureBlendShapeShaders(resources, scene, actor, std::move(nodeParams.mBlendshapeRequests));
698       scene.ApplyConstraints(actor, std::move(nodeParams.mConstrainables));
699       root.Add(actor);
700     }
701   }
702
703   DALI_TEST_EQUAL(root.GetChildCount(), 1u);
704   DALI_TEST_EQUAL(root.GetChildAt(0).GetProperty(Actor::Property::NAME).Get<std::string>(), "root");
705
706   END_TEST;
707 }