[dali_2.2.50] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-scene3d / utc-Dali-Model.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 #include <dali-toolkit-test-suite-utils.h>
19 #include <dali-toolkit/dali-toolkit.h>
20 #include <dali/devel-api/common/map-wrapper.h>
21 #include <stdlib.h>
22 #include <iostream>
23
24 #include <dali-toolkit/devel-api/focus-manager/keyboard-focus-manager-devel.h>
25 #include <dali/integration-api/events/touch-event-integ.h>
26 #include <toolkit-environment-variable.h>
27 #include <toolkit-event-thread-callback.h>
28
29 #include <dali-scene3d/public-api/controls/model/model.h>
30 #include <dali-scene3d/public-api/model-components/model-node.h>
31
32 #include <dali-scene3d/public-api/model-motion/motion-data.h>
33 #include <dali-scene3d/public-api/model-motion/motion-index/blend-shape-index.h>
34 #include <dali-scene3d/public-api/model-motion/motion-index/motion-transform-index.h>
35
36 #include <dali/devel-api/actors/camera-actor-devel.h>
37
38 using namespace Dali;
39 using namespace Dali::Toolkit;
40
41 void model_startup(void)
42 {
43   test_return_value = TET_UNDEF;
44 }
45
46 void model_cleanup(void)
47 {
48   test_return_value = TET_PASS;
49 }
50
51 namespace
52 {
53 const bool DEFAULT_MODEL_CHILDREN_SENSITIVE = false;
54 const bool DEFAULT_MODEL_CHILDREN_FOCUSABLE = false;
55 /**
56  * For the AnimatedCube.gltf and its Assets
57  * Donated by Norbert Nopper for glTF testing.
58  * Take from https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/AnimatedCube
59  */
60 const char* TEST_GLTF_FILE_NAME                    = TEST_RESOURCE_DIR "/AnimatedCube.gltf";
61 const char* TEST_GLTF_FILE_NAME_SAME_FILE          = TEST_RESOURCE_DIR "/AnimatedCube2.gltf";
62 const char* TEST_GLTF_FILE_NAME_DIFF_META_FILE     = TEST_RESOURCE_DIR "/AnimatedCube3.gltf";
63 const char* TEST_GLTF_ANIMATION_TEST_FILE_NAME     = TEST_RESOURCE_DIR "/animationTest.gltf";
64 const char* TEST_GLTF_EXTRAS_FILE_NAME             = TEST_RESOURCE_DIR "/AnimatedMorphCubeAnimateNonZeroFrame.gltf";
65 const char* TEST_GLTF_MULTIPLE_PRIMITIVE_FILE_NAME = TEST_RESOURCE_DIR "/simpleMultiplePrimitiveTest.gltf";
66 const char* TEST_GLTF_MORPH_FILE_NAME              = TEST_RESOURCE_DIR "/AnimatedMorphCube.gltf";
67 const char* TEST_DLI_FILE_NAME                     = TEST_RESOURCE_DIR "/arc.dli";
68 const char* TEST_DLI_EXERCISE_FILE_NAME            = TEST_RESOURCE_DIR "/exercise.dli";
69
70 /**
71  * For the diffuse and specular cube map texture.
72  * These textures are based off version of Wave engine sample
73  * Take from https://github.com/WaveEngine/Samples
74  *
75  * Copyright (c) 2023 Wave Coorporation
76  *
77  * Permission is hereby granted, free of charge, to any person obtaining a copy
78  * of this software and associated documentation files (the "Software"), to
79  * deal in the Software without restriction, including without limitation the
80  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
81  * sell copies of the Software, and to permit persons to whom the Software is
82  * furnished to do so, subject to the following conditions:
83  *
84  * The above copyright notice and this permission notice shall be included in
85  * all copies or substantial portions of the Software.
86  *
87  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
88  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
89  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
90  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
91  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
92  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
93  * THE SOFTWARE.
94  */
95 const char* TEST_DIFFUSE_TEXTURE  = TEST_RESOURCE_DIR "/forest_irradiance.ktx";
96 const char* TEST_SPECULAR_TEXTURE = TEST_RESOURCE_DIR "/forest_radiance.ktx";
97
98 bool gTouchCallBackCalled = false;
99 bool TestTouchCallback(Actor, const TouchEvent&)
100 {
101   gTouchCallBackCalled = true;
102   return true;
103 }
104
105 bool gFocusChangedCallBackCalled = false;
106 void TestFocusChangedCallback(Actor, Actor)
107 {
108   gFocusChangedCallBackCalled = true;
109 }
110
111 // For ResourceReady
112 static bool gOnRelayoutCallBackCalled = false;
113 void        OnRelayoutCallback(Actor actor)
114 {
115   gOnRelayoutCallBackCalled = true;
116 }
117
118 static bool gResourceReadyCalled = false;
119 void        OnResourceReady(Control control)
120 {
121   gResourceReadyCalled = true;
122 }
123
124 } // namespace
125
126 // Negative test case for a method
127 int UtcDaliModelUninitialized(void)
128 {
129   ToolkitTestApplication application;
130   tet_infoline(" UtcDaliModelUninitialized");
131
132   Scene3D::Model model;
133
134   try
135   {
136     // New() must be called to create a Model or it wont be valid.
137     Actor a = Actor::New();
138     model.Add(a);
139     DALI_TEST_CHECK(false);
140   }
141   catch(Dali::DaliException& e)
142   {
143     // Tests that a negative test of an assertion succeeds
144     DALI_TEST_PRINT_ASSERT(e);
145     DALI_TEST_CHECK(!model);
146   }
147   END_TEST;
148 }
149
150 // Positive test case for a method
151 int UtcDaliModelNew(void)
152 {
153   ToolkitTestApplication application;
154   tet_infoline(" UtcDaliModelNew");
155
156   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
157   DALI_TEST_CHECK(model);
158   END_TEST;
159 }
160
161 // Positive test case for a method
162 int UtcDaliModelNewP2(void)
163 {
164   ToolkitTestApplication application;
165   tet_infoline(" UtcDaliModelNew without url");
166
167   Scene3D::Model model = Scene3D::Model::New();
168   DALI_TEST_CHECK(model);
169
170   application.GetScene().Add(model);
171
172   DALI_TEST_CHECK(model.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
173
174   application.GetScene().Remove(model);
175
176   DALI_TEST_CHECK(!model.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
177
178   END_TEST;
179 }
180
181 int UtcDaliModelNewSameModelUrlCached(void)
182 {
183   ToolkitTestApplication application;
184   tet_infoline(" UtcDaliModelNew with same model");
185
186   // Set up trace debug
187   TestGlAbstraction& gl           = application.GetGlAbstraction();
188   TraceCallStack&    textureTrace = gl.GetTextureTrace();
189   textureTrace.Enable(true);
190
191   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
192   DALI_TEST_CHECK(model);
193   Scene3D::Model model2 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
194   DALI_TEST_CHECK(model2);
195
196   application.GetScene().Add(model);
197
198   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
199
200   application.SendNotification();
201   application.Render();
202
203   tet_printf("Test if there is at least 1 texture.\n");
204   int expectTextureCount = textureTrace.CountMethod("GenTextures");
205   DALI_TEST_GREATER(expectTextureCount, 0, TEST_LOCATION);
206
207   application.GetScene().Add(model2);
208
209   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
210
211   application.SendNotification();
212   application.Render();
213
214   tet_printf("Test if we reuse cached texture or not.\n");
215   int currentTextureCount = textureTrace.CountMethod("GenTextures");
216   DALI_TEST_EQUALS(currentTextureCount, expectTextureCount, TEST_LOCATION);
217
218   application.SendNotification();
219   application.Render();
220
221   END_TEST;
222 }
223
224 int UtcDaliModelNewSameResourceUrlCached01(void)
225 {
226   ToolkitTestApplication application;
227   tet_infoline(" UtcDaliModelNew with difference url but same model");
228
229   // Set up trace debug
230   TestGlAbstraction& gl           = application.GetGlAbstraction();
231   TraceCallStack&    textureTrace = gl.GetTextureTrace();
232   textureTrace.Enable(true);
233   textureTrace.EnableLogging(true);
234
235   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
236   DALI_TEST_CHECK(model);
237   Scene3D::Model model2 = Scene3D::Model::New(TEST_GLTF_FILE_NAME_SAME_FILE); // Difference model that use same Images.
238   DALI_TEST_CHECK(model2);
239   Scene3D::Model model3 = Scene3D::Model::New(TEST_GLTF_FILE_NAME_DIFF_META_FILE); // Difference model that use same Images, but difference metadata.
240   DALI_TEST_CHECK(model3);
241
242   application.GetScene().Add(model);
243
244   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
245
246   application.SendNotification();
247   application.Render();
248
249   tet_printf("Test if there is at least 1 texture.\n");
250   int expectTextureCount = textureTrace.CountMethod("GenTextures");
251   DALI_TEST_GREATER(expectTextureCount, 0, TEST_LOCATION);
252
253   application.GetScene().Add(model2);
254
255   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
256
257   application.SendNotification();
258   application.Render();
259
260   tet_printf("Test if we reuse cached texture or not.\n");
261   int currentTextureCount = textureTrace.CountMethod("GenTextures");
262   DALI_TEST_EQUALS(currentTextureCount, expectTextureCount, TEST_LOCATION);
263
264   application.GetScene().Add(model3);
265
266   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
267
268   application.SendNotification();
269   application.Render();
270
271   tet_printf("Test if we don't reuse cached texture, due to the metadata difference.\n");
272   currentTextureCount = textureTrace.CountMethod("GenTextures");
273   DALI_TEST_GREATER(currentTextureCount, expectTextureCount, TEST_LOCATION);
274
275   application.SendNotification();
276   application.Render();
277
278   END_TEST;
279 }
280
281 int UtcDaliModelNewSameResourceUrlCached02(void)
282 {
283   /// Make we don't use mutiple thread loading for this UTC.
284   EnvironmentVariable::SetTestEnvironmentVariable("DALI_ASYNC_MANAGER_THREAD_POOL_SIZE", "1");
285   EnvironmentVariable::SetTestEnvironmentVariable("DALI_ASYNC_MANAGER_LOW_PRIORITY_THREAD_POOL_SIZE", "1");
286
287   ToolkitTestApplication application;
288   tet_infoline(" UtcDaliModelNew with difference url but same model");
289
290   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
291   DALI_TEST_CHECK(model);
292   Scene3D::Model model2 = Scene3D::Model::New(TEST_GLTF_FILE_NAME_SAME_FILE);
293   DALI_TEST_CHECK(model2);
294
295   application.GetScene().Add(model);
296   application.GetScene().Add(model2);
297
298   application.SendNotification();
299   application.Render();
300
301   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
302   application.SendNotification();
303   application.Render();
304
305   END_TEST;
306 }
307
308 // Positive test case for a method
309 int UtcDaliModelDownCast(void)
310 {
311   ToolkitTestApplication application;
312   tet_infoline(" UtcDaliModelDownCast");
313
314   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
315   BaseHandle     handle(model);
316
317   Scene3D::Model model2 = Scene3D::Model::DownCast(handle);
318   DALI_TEST_CHECK(model);
319   DALI_TEST_CHECK(model2);
320   DALI_TEST_CHECK(model2 == model);
321   END_TEST;
322 }
323
324 int UtcDaliModelTypeRegistry(void)
325 {
326   ToolkitTestApplication application;
327
328   TypeRegistry typeRegistry = TypeRegistry::Get();
329   DALI_TEST_CHECK(typeRegistry);
330
331   TypeInfo typeInfo = typeRegistry.GetTypeInfo("Model");
332   DALI_TEST_CHECK(typeInfo);
333
334   BaseHandle handle = typeInfo.CreateInstance();
335   DALI_TEST_CHECK(handle);
336
337   Scene3D::Model model = Scene3D::Model::DownCast(handle);
338   DALI_TEST_CHECK(model);
339
340   END_TEST;
341 }
342
343 // Positive test case for a method
344 int UtcDaliModelAddRemove(void)
345 {
346   ToolkitTestApplication application;
347   tet_infoline(" UtcDaliModelAddRemove");
348
349   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
350   DALI_TEST_CHECK(model);
351
352   Actor actor = Actor::New();
353   DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
354
355   model.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
356   model.SetProperty(Actor::Property::SIZE, application.GetScene().GetSize());
357   model.Add(actor);
358   application.GetScene().Add(model);
359
360   DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
361
362   model.Remove(actor);
363
364   DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
365   END_TEST;
366 }
367
368 int UtcDaliModelCopyAndAssignment(void)
369 {
370   ToolkitTestApplication application;
371
372   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
373   DALI_TEST_CHECK(model);
374
375   Scene3D::Model copy(model);
376   DALI_TEST_CHECK(model == copy);
377
378   Scene3D::Model assign;
379   DALI_TEST_CHECK(!assign);
380
381   assign = copy;
382   DALI_TEST_CHECK(assign == model);
383
384   END_TEST;
385 }
386
387 int UtcDaliModelMoveConstructor(void)
388 {
389   ToolkitTestApplication application;
390
391   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
392   DALI_TEST_EQUALS(1, model.GetBaseObject().ReferenceCount(), TEST_LOCATION);
393   model.SetProperty(Actor::Property::SENSITIVE, false);
394   DALI_TEST_CHECK(false == model.GetProperty<bool>(Actor::Property::SENSITIVE));
395
396   Scene3D::Model moved = std::move(model);
397   DALI_TEST_CHECK(moved);
398   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
399   DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
400   DALI_TEST_CHECK(!model);
401
402   END_TEST;
403 }
404
405 int UtcDaliModelMoveAssignment(void)
406 {
407   ToolkitTestApplication application;
408
409   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
410   DALI_TEST_EQUALS(1, model.GetBaseObject().ReferenceCount(), TEST_LOCATION);
411   model.SetProperty(Actor::Property::SENSITIVE, false);
412   DALI_TEST_CHECK(false == model.GetProperty<bool>(Actor::Property::SENSITIVE));
413
414   Scene3D::Model moved;
415   moved = std::move(model);
416   DALI_TEST_CHECK(moved);
417   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
418   DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
419   DALI_TEST_CHECK(!model);
420
421   END_TEST;
422 }
423
424 int UtcDaliModelOnScene01(void)
425 {
426   ToolkitTestApplication application;
427
428   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
429   application.GetScene().Add(model);
430
431   gResourceReadyCalled = false;
432   model.ResourceReadySignal().Connect(&OnResourceReady);
433   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
434
435   application.SendNotification();
436   application.Render();
437
438   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
439   application.SendNotification();
440   application.Render();
441
442   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
443
444   uint32_t modelCount = model.GetModelRoot().GetChildCount();
445   DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
446   END_TEST;
447 }
448
449 int UtcDaliModelOnScene02(void)
450 {
451   ToolkitTestApplication application;
452
453   Scene3D::Model model = Scene3D::Model::New(TEST_DLI_FILE_NAME);
454   application.GetScene().Add(model);
455
456   gResourceReadyCalled = false;
457   model.ResourceReadySignal().Connect(&OnResourceReady);
458   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
459
460   application.SendNotification();
461   application.Render();
462
463   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
464   application.SendNotification();
465   application.Render();
466
467   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
468
469   uint32_t modelCount = model.GetModelRoot().GetChildCount();
470   DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
471
472   Scene3D::ModelNode rootNode = model.GetModelRoot();
473   Vector3            rootSize = rootNode.GetProperty<Vector3>(Dali::Actor::Property::SIZE);
474   DALI_TEST_EQUALS(Vector3(2, 2, 1), rootSize, TEST_LOCATION);
475
476   END_TEST;
477 }
478
479 int UtcDaliModelOnSizeSet(void)
480 {
481   ToolkitTestApplication application;
482
483   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
484
485   application.GetScene().Add(model);
486
487   application.SendNotification();
488   application.Render();
489
490   Vector2 size(200.0f, 300.0f);
491   model.SetProperty(Actor::Property::SIZE, size);
492
493   application.SendNotification();
494   application.Render();
495
496   DALI_TEST_EQUALS(model.GetCurrentProperty<Vector2>(Actor::Property::SIZE), size, TEST_LOCATION);
497
498   END_TEST;
499 }
500
501 int UtcDaliModelGetNaturalSize(void)
502 {
503   ToolkitTestApplication application;
504
505   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
506
507   Vector3 naturalSize = model.GetNaturalSize();
508   DALI_TEST_EQUALS(Vector3::ZERO, naturalSize, TEST_LOCATION);
509
510   application.GetScene().Add(model);
511
512   gResourceReadyCalled = false;
513   model.ResourceReadySignal().Connect(&OnResourceReady);
514   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
515
516   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
517   application.SendNotification();
518
519   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
520
521   naturalSize = model.GetNaturalSize();
522   DALI_TEST_EQUALS(Vector3(2, 2, 2), naturalSize, TEST_LOCATION);
523
524   Scene3D::ModelNode rootNode = model.GetModelRoot();
525   DALI_TEST_CHECK(rootNode);
526
527   END_TEST;
528 }
529
530 int UtcDaliModelSetImageBasedLightSource01(void)
531 {
532   ToolkitTestApplication application;
533
534   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
535   application.GetScene().Add(model);
536
537   gResourceReadyCalled = false;
538   model.ResourceReadySignal().Connect(&OnResourceReady);
539   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
540
541   application.SendNotification();
542   application.Render();
543
544   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
545   application.SendNotification();
546   application.Render();
547
548   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
549
550   Actor meshActor = model.FindChildByName("AnimatedCube");
551   DALI_TEST_CHECK(meshActor);
552
553   Renderer renderer = meshActor.GetRendererAt(0u);
554   DALI_TEST_CHECK(renderer);
555
556   TextureSet textureSet = renderer.GetTextures();
557   DALI_TEST_EQUALS(textureSet.GetTextureCount(), 10u, TEST_LOCATION);
558
559   Texture diffuseTexture  = textureSet.GetTexture(8u);
560   Texture specularTexture = textureSet.GetTexture(9u);
561
562   gResourceReadyCalled = false;
563   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
564   model.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
565
566   application.SendNotification();
567   application.Render();
568
569   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
570   application.SendNotification();
571   application.Render();
572
573   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
574
575   TextureSet newTextureSet      = renderer.GetTextures();
576   Texture    newDiffuseTexture  = newTextureSet.GetTexture(8u);
577   Texture    newSpecularTexture = newTextureSet.GetTexture(9u);
578
579   DALI_TEST_NOT_EQUALS(diffuseTexture, newDiffuseTexture, 0.0f, TEST_LOCATION);
580   DALI_TEST_NOT_EQUALS(specularTexture, newSpecularTexture, 0.0f, TEST_LOCATION);
581
582   model.Unparent();
583   model.Reset();
584   END_TEST;
585 }
586
587 int UtcDaliModelSetImageBasedLightSource02(void)
588 {
589   ToolkitTestApplication application;
590
591   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
592   application.GetScene().Add(model);
593
594   gResourceReadyCalled = false;
595   model.ResourceReadySignal().Connect(&OnResourceReady);
596   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
597
598   application.SendNotification();
599   application.Render();
600
601   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
602   application.SendNotification();
603   application.Render();
604
605   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
606
607   Actor meshActor = model.FindChildByName("AnimatedCube");
608   DALI_TEST_CHECK(meshActor);
609
610   Renderer renderer = meshActor.GetRendererAt(0u);
611   DALI_TEST_CHECK(renderer);
612
613   TextureSet textureSet = renderer.GetTextures();
614   DALI_TEST_EQUALS(textureSet.GetTextureCount(), 10u, TEST_LOCATION);
615
616   Texture diffuseTexture  = textureSet.GetTexture(8u);
617   Texture specularTexture = textureSet.GetTexture(9u);
618
619   // if url is empty, loading is not requested.
620   model.SetImageBasedLightSource("", "");
621
622   Texture newDiffuseTexture  = textureSet.GetTexture(8u);
623   Texture newSpecularTexture = textureSet.GetTexture(9u);
624
625   DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION);
626   DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION);
627
628   END_TEST;
629 }
630
631 int UtcDaliModelSetImageBasedLightSource03(void)
632 {
633   ToolkitTestApplication application;
634
635   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
636   application.GetScene().Add(model);
637
638   gResourceReadyCalled = false;
639   model.ResourceReadySignal().Connect(&OnResourceReady);
640   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
641
642   application.SendNotification();
643   application.Render();
644
645   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
646   application.SendNotification();
647   application.Render();
648
649   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
650
651   Actor meshActor = model.FindChildByName("AnimatedCube");
652   DALI_TEST_CHECK(meshActor);
653
654   Renderer renderer = meshActor.GetRendererAt(0u);
655   DALI_TEST_CHECK(renderer);
656
657   TextureSet textureSet = renderer.GetTextures();
658   DALI_TEST_EQUALS(textureSet.GetTextureCount(), 10u, TEST_LOCATION);
659
660   Texture diffuseTexture  = textureSet.GetTexture(8u);
661   Texture specularTexture = textureSet.GetTexture(9u);
662
663   gResourceReadyCalled = false;
664   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
665   model.SetImageBasedLightSource("dummy.ktx", "dummy.ktx");
666
667   application.SendNotification();
668   application.Render();
669
670   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
671   application.SendNotification();
672   application.Render();
673
674   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
675
676   Texture newDiffuseTexture  = textureSet.GetTexture(8u);
677   Texture newSpecularTexture = textureSet.GetTexture(9u);
678
679   DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION);
680   DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION);
681
682   END_TEST;
683 }
684
685 int UtcDaliModelSetImageBasedLightSource04(void)
686 {
687   ToolkitTestApplication application;
688
689   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
690   model.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
691   application.GetScene().Add(model);
692
693   gResourceReadyCalled = false;
694   model.ResourceReadySignal().Connect(&OnResourceReady);
695   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
696
697   application.SendNotification();
698   application.Render();
699
700   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
701   application.SendNotification();
702   application.Render();
703
704   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
705   END_TEST;
706 }
707
708 int UtcDaliModelImageBasedFactor(void)
709 {
710   ToolkitTestApplication application;
711
712   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
713
714   DALI_TEST_EQUALS(model.GetImageBasedLightScaleFactor(), 1.0f, TEST_LOCATION);
715
716   model.SetImageBasedLightScaleFactor(0.5f);
717   DALI_TEST_EQUALS(model.GetImageBasedLightScaleFactor(), 0.5f, TEST_LOCATION);
718   END_TEST;
719 }
720
721 int UtcDaliModelChildrenSensitive01(void)
722 {
723   ToolkitTestApplication application;
724
725   Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
726   view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
727   view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
728   view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
729   view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
730
731   // Get default vaule.
732   DALI_TEST_EQUALS(view.GetChildrenSensitive(), DEFAULT_MODEL_CHILDREN_SENSITIVE, TEST_LOCATION);
733
734   // Allow children actor's event before on scene.
735   view.SetChildrenSensitive(true);
736   DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
737   application.GetScene().Add(view);
738
739   gResourceReadyCalled = false;
740   view.ResourceReadySignal().Connect(&OnResourceReady);
741   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
742
743   application.SendNotification();
744   application.Render();
745
746   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
747   application.SendNotification();
748   application.Render();
749
750   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
751
752   Actor meshActor = view.FindChildByName("AnimatedCube");
753   DALI_TEST_CHECK(meshActor);
754
755   // connect hit-test signal
756   gTouchCallBackCalled = false;
757   meshActor.TouchedSignal().Connect(TestTouchCallback);
758
759   Vector2 sceneSize = application.GetScene().GetSize();
760
761   // Try to touch center of scene.
762   Dali::Integration::Point point;
763   point.SetState(PointState::DOWN);
764   point.SetScreenPosition(sceneSize * 0.5f);
765   Dali::Integration::TouchEvent event;
766   event.AddPoint(point);
767
768   // flush the queue and render once
769   application.SendNotification();
770   application.Render();
771
772   // Not touched yet.
773   DALI_TEST_CHECK(!gTouchCallBackCalled);
774   application.ProcessEvent(event);
775   // Touched.
776   DALI_TEST_CHECK(gTouchCallBackCalled);
777
778   // Clear
779   gTouchCallBackCalled = false;
780
781   // Block children actor's event
782   view.SetChildrenSensitive(false);
783   DALI_TEST_EQUALS(view.GetChildrenSensitive(), false, TEST_LOCATION);
784
785   // flush the queue and render once
786   application.SendNotification();
787   application.Render();
788
789   // Not touched yet.
790   DALI_TEST_CHECK(!gTouchCallBackCalled);
791   application.ProcessEvent(event);
792   // Also not touched.
793   DALI_TEST_CHECK(!gTouchCallBackCalled);
794
795   // Clear
796   gTouchCallBackCalled = false;
797
798   // Allow again
799   view.SetChildrenSensitive(true);
800   DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
801
802   // flush the queue and render once
803   application.SendNotification();
804   application.Render();
805
806   // Not touched yet.
807   DALI_TEST_CHECK(!gTouchCallBackCalled);
808   application.ProcessEvent(event);
809   // Touched.
810   DALI_TEST_CHECK(gTouchCallBackCalled);
811
812   // Clear
813   gTouchCallBackCalled = false;
814
815   END_TEST;
816 }
817
818 int UtcDaliModelChildrenSensitive02(void)
819 {
820   ToolkitTestApplication application;
821
822   Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
823   view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
824   view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
825   view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
826   view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
827
828   // Get vaule.
829   DALI_TEST_EQUALS(view.GetChildrenSensitive(), DEFAULT_MODEL_CHILDREN_SENSITIVE, TEST_LOCATION);
830
831   // Block children actor's event before on scene.
832   view.SetChildrenSensitive(false);
833   DALI_TEST_EQUALS(view.GetChildrenSensitive(), false, TEST_LOCATION);
834   application.GetScene().Add(view);
835
836   gResourceReadyCalled = false;
837   view.ResourceReadySignal().Connect(&OnResourceReady);
838   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
839
840   application.SendNotification();
841   application.Render();
842
843   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
844   application.SendNotification();
845   application.Render();
846
847   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
848
849   Actor meshActor = view.FindChildByName("AnimatedCube");
850   DALI_TEST_CHECK(meshActor);
851
852   // connect hit-test signal
853   gTouchCallBackCalled = false;
854   meshActor.TouchedSignal().Connect(TestTouchCallback);
855
856   Vector2 sceneSize = application.GetScene().GetSize();
857
858   // Try to touch center of scene.
859   Dali::Integration::Point point;
860   point.SetState(PointState::DOWN);
861   point.SetScreenPosition(sceneSize * 0.5f);
862   Dali::Integration::TouchEvent event;
863   event.AddPoint(point);
864
865   // flush the queue and render once
866   application.SendNotification();
867   application.Render();
868
869   // Not touched yet.
870   DALI_TEST_CHECK(!gTouchCallBackCalled);
871   application.ProcessEvent(event);
872   // Also not touched.
873   DALI_TEST_CHECK(!gTouchCallBackCalled);
874
875   // Clear
876   gTouchCallBackCalled = false;
877
878   // Allow again
879   view.SetChildrenSensitive(true);
880   DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
881
882   // flush the queue and render once
883   application.SendNotification();
884   application.Render();
885
886   // Not touched yet.
887   DALI_TEST_CHECK(!gTouchCallBackCalled);
888   application.ProcessEvent(event);
889   // Touched.
890   DALI_TEST_CHECK(gTouchCallBackCalled);
891
892   // Clear
893   gTouchCallBackCalled = false;
894
895   END_TEST;
896 }
897
898 int UtcDaliModelChildrenFocusable01(void)
899 {
900   ToolkitTestApplication application;
901
902   Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
903   view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
904   view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
905   view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
906   view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
907
908   // Get vaule. Default is false.
909   DALI_TEST_EQUALS(view.GetChildrenFocusable(), DEFAULT_MODEL_CHILDREN_FOCUSABLE, TEST_LOCATION);
910
911   // Allow children actor's focus before on scene.
912   view.SetChildrenFocusable(true);
913   DALI_TEST_EQUALS(view.GetChildrenFocusable(), true, TEST_LOCATION);
914   application.GetScene().Add(view);
915
916   gResourceReadyCalled = false;
917   view.ResourceReadySignal().Connect(&OnResourceReady);
918   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
919
920   application.SendNotification();
921   application.Render();
922
923   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
924   application.SendNotification();
925   application.Render();
926
927   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
928
929   Actor meshActor = view.FindChildByName("AnimatedCube");
930   DALI_TEST_CHECK(meshActor);
931
932   // Enable the default algorithm
933   KeyboardFocusManager manager = KeyboardFocusManager::Get();
934   DALI_TEST_CHECK(manager);
935   Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
936
937   // connect focusable signal
938   gFocusChangedCallBackCalled = false;
939   meshActor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
940   manager.FocusChangedSignal().Connect(TestFocusChangedCallback);
941
942   // Initialize with some left-positioned actor
943   Control focusStartActor = Control::New();
944   focusStartActor.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
945   focusStartActor.SetProperty(Dali::Actor::Property::POSITION, Vector3(-200, 0, 0));
946   focusStartActor.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
947   focusStartActor.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
948   focusStartActor.SetProperty(Dali::Actor::Property::KEYBOARD_FOCUSABLE, true);
949   application.GetScene().Add(focusStartActor);
950
951   // Clear
952   manager.ClearFocus();
953   manager.SetCurrentFocusActor(focusStartActor);
954   gFocusChangedCallBackCalled = false;
955
956   // flush the queue and render once
957   application.SendNotification();
958   application.Render();
959
960   // Focusable view find success
961   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
962   DALI_TEST_CHECK(gFocusChangedCallBackCalled);
963
964   // Clear
965   manager.ClearFocus();
966   manager.SetCurrentFocusActor(focusStartActor);
967   gFocusChangedCallBackCalled = false;
968
969   // Block children actor's focus
970   view.SetChildrenFocusable(false);
971   DALI_TEST_EQUALS(view.GetChildrenFocusable(), false, TEST_LOCATION);
972
973   // flush the queue and render once
974   application.SendNotification();
975   application.Render();
976
977   // Focusable view find failed
978   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
979   DALI_TEST_CHECK(!gFocusChangedCallBackCalled);
980
981   // Clear
982   manager.ClearFocus();
983   manager.SetCurrentFocusActor(focusStartActor);
984   gFocusChangedCallBackCalled = false;
985
986   // Allow again
987   view.SetChildrenFocusable(true);
988   DALI_TEST_EQUALS(view.GetChildrenFocusable(), true, TEST_LOCATION);
989
990   // flush the queue and render once
991   application.SendNotification();
992   application.Render();
993
994   // Focusable view find success
995   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
996   DALI_TEST_CHECK(gFocusChangedCallBackCalled);
997
998   // Clear
999   manager.ClearFocus();
1000   manager.SetCurrentFocusActor(focusStartActor);
1001   gFocusChangedCallBackCalled = false;
1002
1003   END_TEST;
1004 }
1005
1006 int UtcDaliModelModelChildrenFocusable02(void)
1007 {
1008   ToolkitTestApplication application;
1009
1010   Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1011   view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
1012   view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
1013   view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
1014   view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1015
1016   // Get vaule. Default is true.
1017   DALI_TEST_EQUALS(view.GetChildrenFocusable(), DEFAULT_MODEL_CHILDREN_FOCUSABLE, TEST_LOCATION);
1018
1019   // Block children actor's focus before on scene.
1020   view.SetChildrenFocusable(false);
1021   DALI_TEST_EQUALS(view.GetChildrenFocusable(), false, TEST_LOCATION);
1022   application.GetScene().Add(view);
1023
1024   gResourceReadyCalled = false;
1025   view.ResourceReadySignal().Connect(&OnResourceReady);
1026   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1027
1028   application.SendNotification();
1029   application.Render();
1030
1031   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1032   application.SendNotification();
1033   application.Render();
1034
1035   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1036
1037   Actor meshActor = view.FindChildByName("AnimatedCube");
1038   DALI_TEST_CHECK(meshActor);
1039
1040   // Enable the default algorithm
1041   KeyboardFocusManager manager = KeyboardFocusManager::Get();
1042   DALI_TEST_CHECK(manager);
1043   Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
1044
1045   // connect focusable signal
1046   gFocusChangedCallBackCalled = false;
1047   meshActor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1048   manager.FocusChangedSignal().Connect(TestFocusChangedCallback);
1049
1050   // Initialize with some left-positioned actor
1051   Control focusStartActor = Control::New();
1052   focusStartActor.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
1053   focusStartActor.SetProperty(Dali::Actor::Property::POSITION, Vector3(-200, 0, 0));
1054   focusStartActor.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
1055   focusStartActor.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1056   focusStartActor.SetProperty(Dali::Actor::Property::KEYBOARD_FOCUSABLE, true);
1057   application.GetScene().Add(focusStartActor);
1058
1059   // Clear
1060   manager.ClearFocus();
1061   manager.SetCurrentFocusActor(focusStartActor);
1062   gFocusChangedCallBackCalled = false;
1063
1064   // flush the queue and render once
1065   application.SendNotification();
1066   application.Render();
1067
1068   // Focusable view find failed
1069   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1070   DALI_TEST_CHECK(!gFocusChangedCallBackCalled);
1071
1072   // Clear
1073   manager.ClearFocus();
1074   manager.SetCurrentFocusActor(focusStartActor);
1075   gFocusChangedCallBackCalled = false;
1076
1077   // Allow again
1078   view.SetChildrenFocusable(true);
1079   DALI_TEST_EQUALS(view.GetChildrenFocusable(), true, TEST_LOCATION);
1080
1081   // flush the queue and render once
1082   application.SendNotification();
1083   application.Render();
1084
1085   // Focusable view find success
1086   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1087   DALI_TEST_CHECK(gFocusChangedCallBackCalled);
1088
1089   // Clear
1090   manager.ClearFocus();
1091   manager.SetCurrentFocusActor(focusStartActor);
1092   gFocusChangedCallBackCalled = false;
1093
1094   END_TEST;
1095 }
1096
1097 int UtcDaliModelAnimation01(void)
1098 {
1099   ToolkitTestApplication application;
1100
1101   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1102   model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1103   application.GetScene().Add(model);
1104
1105   gResourceReadyCalled = false;
1106   model.ResourceReadySignal().Connect(&OnResourceReady);
1107   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1108
1109   application.SendNotification();
1110   application.Render();
1111
1112   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1113   application.SendNotification();
1114   application.Render();
1115
1116   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1117
1118   uint32_t animationCount = model.GetAnimationCount();
1119   DALI_TEST_EQUALS(1, animationCount, TEST_LOCATION);
1120
1121   Animation animationByIndex = model.GetAnimation(0u);
1122   DALI_TEST_CHECK(animationByIndex);
1123
1124   Animation animationByName = model.GetAnimation("animation_AnimatedCube");
1125   DALI_TEST_CHECK(animationByName);
1126   DALI_TEST_EQUALS(animationByIndex, animationByName, TEST_LOCATION);
1127
1128   END_TEST;
1129 }
1130
1131 int UtcDaliModelAnimation02(void)
1132 {
1133   ToolkitTestApplication application;
1134
1135   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_ANIMATION_TEST_FILE_NAME);
1136   model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1137   application.GetScene().Add(model);
1138
1139   gResourceReadyCalled = false;
1140   model.ResourceReadySignal().Connect(&OnResourceReady);
1141   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1142
1143   application.SendNotification();
1144   application.Render();
1145
1146   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1147   application.SendNotification();
1148   application.Render();
1149
1150   uint32_t animationCount = model.GetAnimationCount();
1151   DALI_TEST_EQUALS(9, animationCount, TEST_LOCATION);
1152
1153   Animation animation1 = model.GetAnimation("Step Scale");
1154   DALI_TEST_CHECK(animation1);
1155   DALI_TEST_EQUALS(1.66667f, animation1.GetDuration(), 0.001f, TEST_LOCATION);
1156
1157   Animation animation2 = model.GetAnimation("CubicSpline Scale");
1158   DALI_TEST_CHECK(animation2);
1159   DALI_TEST_EQUALS(1.66667f, animation2.GetDuration(), 0.001f, TEST_LOCATION);
1160
1161   DALI_TEST_NOT_EQUALS(animation1, animation2, 0.0f, TEST_LOCATION);
1162
1163   END_TEST;
1164 }
1165
1166 int UtcDaliModelAnimation03(void)
1167 {
1168   ToolkitTestApplication application;
1169
1170   Scene3D::Model model = Scene3D::Model::New(TEST_DLI_EXERCISE_FILE_NAME);
1171   model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1172   application.GetScene().Add(model);
1173
1174   gResourceReadyCalled = false;
1175   model.ResourceReadySignal().Connect(&OnResourceReady);
1176   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1177
1178   application.SendNotification();
1179   application.Render();
1180
1181   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1182   application.SendNotification();
1183   application.Render();
1184
1185   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1186
1187   uint32_t animationCount = model.GetAnimationCount();
1188   DALI_TEST_EQUALS(18, animationCount, TEST_LOCATION);
1189
1190   Animation animationByIndex = model.GetAnimation(0u);
1191   DALI_TEST_CHECK(animationByIndex);
1192
1193   Animation animationByName = model.GetAnimation("idleClip");
1194   DALI_TEST_CHECK(animationByName);
1195   DALI_TEST_EQUALS(animationByIndex, animationByName, TEST_LOCATION);
1196
1197   END_TEST;
1198 }
1199
1200 int UtcDaliModelCameraGenerate01(void)
1201 {
1202   ToolkitTestApplication application;
1203
1204   Scene3D::Model model = Scene3D::Model::New(TEST_DLI_EXERCISE_FILE_NAME);
1205   model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1206   application.GetScene().Add(model);
1207
1208   gResourceReadyCalled = false;
1209   model.ResourceReadySignal().Connect(&OnResourceReady);
1210   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1211
1212   application.SendNotification();
1213   application.Render();
1214
1215   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1216   application.SendNotification();
1217   application.Render();
1218
1219   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1220
1221   uint32_t cameraCount = model.GetCameraCount();
1222   DALI_TEST_EQUALS(1, cameraCount, TEST_LOCATION);
1223
1224   CameraActor generatedCamera = model.GenerateCamera(0u);
1225   DALI_TEST_CHECK(generatedCamera);
1226
1227   generatedCamera = model.GenerateCamera(1u); // Fail to generate camera
1228   DALI_TEST_CHECK(!generatedCamera);
1229
1230   END_TEST;
1231 }
1232
1233 int UtcDaliModelCameraGenerate02(void)
1234 {
1235   ToolkitTestApplication application;
1236
1237   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1238   model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1239   application.GetScene().Add(model);
1240
1241   gResourceReadyCalled = false;
1242   model.ResourceReadySignal().Connect(&OnResourceReady);
1243   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1244
1245   application.SendNotification();
1246   application.Render();
1247
1248   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1249   application.SendNotification();
1250   application.Render();
1251
1252   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1253
1254   uint32_t cameraCount = model.GetCameraCount();
1255   DALI_TEST_EQUALS(6, cameraCount, TEST_LOCATION);
1256
1257   CameraActor generatedCamera0 = model.GenerateCamera(0u);
1258   DALI_TEST_CHECK(generatedCamera0);
1259   CameraActor generatedCamera1 = model.GenerateCamera(1u);
1260   DALI_TEST_CHECK(generatedCamera1);
1261   CameraActor generatedCamera2 = model.GenerateCamera(2u);
1262   DALI_TEST_CHECK(generatedCamera2);
1263   CameraActor generatedCamera3 = model.GenerateCamera(3u); // Infinity far camera
1264   DALI_TEST_CHECK(generatedCamera3);
1265   CameraActor generatedCamera4 = model.GenerateCamera(4u); // Broken camera 1
1266   DALI_TEST_CHECK(!generatedCamera4);
1267   CameraActor generatedCamera5 = model.GenerateCamera(5u); // Broken camera 2
1268   DALI_TEST_CHECK(!generatedCamera5);
1269   CameraActor generatedCamera6 = model.GenerateCamera(6u); // Out of bound
1270   DALI_TEST_CHECK(!generatedCamera6);
1271
1272   CameraActor appliedCamera;
1273   DALI_TEST_EQUALS(model.ApplyCamera(0u, appliedCamera), false, TEST_LOCATION); // Cannot apply into empty camera.
1274
1275   auto CompareCameraProperties = [](CameraActor lhs, CameraActor rhs, const char* location) {
1276     DALI_TEST_EQUALS(lhs.GetProperty<int>(Dali::CameraActor::Property::PROJECTION_MODE), rhs.GetProperty<int>(Dali::CameraActor::Property::PROJECTION_MODE), TEST_LOCATION);
1277     DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::CameraActor::Property::NEAR_PLANE_DISTANCE), rhs.GetProperty<float>(Dali::CameraActor::Property::NEAR_PLANE_DISTANCE), TEST_LOCATION);
1278
1279     if(lhs.GetProperty<int>(Dali::CameraActor::Property::PROJECTION_MODE) == static_cast<int>(Dali::Camera::ProjectionMode::PERSPECTIVE_PROJECTION))
1280     {
1281       DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::CameraActor::Property::FIELD_OF_VIEW), rhs.GetProperty<float>(Dali::CameraActor::Property::FIELD_OF_VIEW), TEST_LOCATION);
1282       // TODO : Open this test when infinity far projection implement.
1283       // DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::CameraActor::Property::FAR_PLANE_DISTANCE), rhs.GetProperty<float>(Dali::CameraActor::Property::FAR_PLANE_DISTANCE), TEST_LOCATION);
1284     }
1285     else
1286     {
1287       DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE), rhs.GetProperty<float>(Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE), TEST_LOCATION);
1288       DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::CameraActor::Property::FAR_PLANE_DISTANCE), rhs.GetProperty<float>(Dali::CameraActor::Property::FAR_PLANE_DISTANCE), TEST_LOCATION);
1289     }
1290   };
1291
1292   appliedCamera = CameraActor::New();
1293   DALI_TEST_EQUALS(model.ApplyCamera(0u, appliedCamera), true, TEST_LOCATION);
1294   CompareCameraProperties(generatedCamera0, appliedCamera, TEST_LOCATION);
1295   DALI_TEST_EQUALS(model.ApplyCamera(1u, appliedCamera), true, TEST_LOCATION);
1296   CompareCameraProperties(generatedCamera1, appliedCamera, TEST_LOCATION);
1297   DALI_TEST_EQUALS(model.ApplyCamera(2u, appliedCamera), true, TEST_LOCATION);
1298   CompareCameraProperties(generatedCamera2, appliedCamera, TEST_LOCATION);
1299   DALI_TEST_EQUALS(model.ApplyCamera(3u, appliedCamera), true, TEST_LOCATION);
1300   CompareCameraProperties(generatedCamera3, appliedCamera, TEST_LOCATION);
1301   DALI_TEST_EQUALS(model.ApplyCamera(4u, appliedCamera), false, TEST_LOCATION); // Broken camera 1
1302   DALI_TEST_EQUALS(model.ApplyCamera(5u, appliedCamera), false, TEST_LOCATION); // Broken camera 2
1303   DALI_TEST_EQUALS(model.ApplyCamera(6u, appliedCamera), false, TEST_LOCATION); // Cannot apply over the index.
1304
1305   END_TEST;
1306 }
1307
1308 int UtcDaliModelMultiplePrimitives(void)
1309 {
1310   ToolkitTestApplication application;
1311
1312   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_MULTIPLE_PRIMITIVE_FILE_NAME);
1313   model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1314   application.GetScene().Add(model);
1315
1316   gResourceReadyCalled = false;
1317   model.ResourceReadySignal().Connect(&OnResourceReady);
1318   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1319
1320   application.SendNotification();
1321   application.Render();
1322
1323   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1324   application.SendNotification();
1325   application.Render();
1326
1327   Actor actor = model.FindChildByName("rootNode");
1328
1329   DALI_TEST_EQUALS(0, actor.GetChildCount(), TEST_LOCATION);
1330   DALI_TEST_EQUALS(2, actor.GetRendererCount(), TEST_LOCATION);
1331
1332   END_TEST;
1333 }
1334
1335 int UtcDaliModelColorMode(void)
1336 {
1337   ToolkitTestApplication application;
1338
1339   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1340   model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1341   model.SetProperty(Dali::Actor::Property::COLOR, Color::RED);
1342   application.GetScene().Add(model);
1343
1344   gResourceReadyCalled = false;
1345   model.ResourceReadySignal().Connect(&OnResourceReady);
1346   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1347
1348   application.SendNotification();
1349   application.Render();
1350
1351   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1352   application.SendNotification();
1353   application.Render();
1354
1355   Actor   actor           = model.FindChildByName("AnimatedCube");
1356   Vector4 childColor      = actor[Dali::Actor::Property::COLOR];
1357   Vector4 childWorldColor = actor[Dali::Actor::Property::WORLD_COLOR];
1358
1359   DALI_TEST_EQUALS(childColor, Color::WHITE, TEST_LOCATION);
1360   DALI_TEST_EQUALS(childWorldColor, Color::RED, TEST_LOCATION);
1361
1362   END_TEST;
1363 }
1364
1365 int UtcDaliModelResourceReady(void)
1366 {
1367   ToolkitTestApplication application;
1368
1369   gOnRelayoutCallBackCalled = false;
1370   gResourceReadyCalled      = false;
1371   Scene3D::Model model      = Scene3D::Model::New(TEST_GLTF_ANIMATION_TEST_FILE_NAME);
1372   model.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1373   model.OnRelayoutSignal().Connect(OnRelayoutCallback);
1374   model.ResourceReadySignal().Connect(OnResourceReady);
1375   DALI_TEST_EQUALS(model.IsResourceReady(), false, TEST_LOCATION);
1376
1377   // Sanity check
1378   DALI_TEST_CHECK(!gOnRelayoutCallBackCalled);
1379   DALI_TEST_CHECK(!gResourceReadyCalled);
1380
1381   application.GetScene().Add(model);
1382
1383   application.SendNotification();
1384   application.Render();
1385
1386   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1387   application.SendNotification();
1388   application.Render();
1389
1390   DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, false, TEST_LOCATION);
1391   DALI_TEST_EQUALS(model.IsResourceReady(), true, TEST_LOCATION);
1392   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1393
1394   END_TEST;
1395 }
1396
1397 int UtcDaliModelResourceCacheCheck(void)
1398 {
1399   ToolkitTestApplication application;
1400
1401   // Load three instances of the same model and add them to the scene
1402   Scene3D::Model model1 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1403   Scene3D::Model model2 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1404   Scene3D::Model model3 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1405
1406   application.GetScene().Add(model1);
1407   application.GetScene().Add(model2);
1408   application.GetScene().Add(model3);
1409
1410   gResourceReadyCalled = false;
1411   model1.ResourceReadySignal().Connect(&OnResourceReady);
1412   model2.ResourceReadySignal().Connect(&OnResourceReady);
1413   model3.ResourceReadySignal().Connect(&OnResourceReady);
1414   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1415
1416   application.SendNotification();
1417   application.Render();
1418
1419   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1420   application.SendNotification();
1421   application.Render();
1422
1423   // Check that the loading has finished for all the three instances
1424   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1425
1426   Actor meshActor1 = model1.FindChildByName("AnimatedCube");
1427   Actor meshActor2 = model2.FindChildByName("AnimatedCube");
1428   Actor meshActor3 = model3.FindChildByName("AnimatedCube");
1429   DALI_TEST_CHECK(meshActor1);
1430   DALI_TEST_CHECK(meshActor2);
1431   DALI_TEST_CHECK(meshActor3);
1432
1433   Renderer renderer1 = meshActor1.GetRendererAt(0u);
1434   Renderer renderer2 = meshActor2.GetRendererAt(0u);
1435   Renderer renderer3 = meshActor3.GetRendererAt(0u);
1436   DALI_TEST_CHECK(renderer1);
1437   DALI_TEST_CHECK(renderer2);
1438   DALI_TEST_CHECK(renderer3);
1439
1440   // Check that all the three instances use the shared textures and geometries from the cache
1441   // but have their own shader objects
1442   DALI_TEST_EQUALS(renderer1.GetTextures(), renderer2.GetTextures(), TEST_LOCATION);
1443   DALI_TEST_EQUALS(renderer1.GetTextures(), renderer3.GetTextures(), TEST_LOCATION);
1444   DALI_TEST_EQUALS(renderer1.GetGeometry(), renderer2.GetGeometry(), TEST_LOCATION);
1445   DALI_TEST_EQUALS(renderer1.GetGeometry(), renderer3.GetGeometry(), TEST_LOCATION);
1446   DALI_TEST_NOT_EQUALS(renderer1.GetShader(), renderer2.GetShader(), 0.0f, TEST_LOCATION);
1447   DALI_TEST_NOT_EQUALS(renderer1.GetShader(), renderer3.GetShader(), 0.0f, TEST_LOCATION);
1448   DALI_TEST_NOT_EQUALS(renderer2.GetShader(), renderer3.GetShader(), 0.0f, TEST_LOCATION);
1449
1450   // Destroy model1
1451   model1.Unparent();
1452   model1.Reset();
1453
1454   // Check that all the other two instances still use the shared textures and geometries from the cache
1455   // but have their own shader objects
1456   DALI_TEST_EQUALS(renderer2.GetTextures(), renderer3.GetTextures(), TEST_LOCATION);
1457   DALI_TEST_EQUALS(renderer2.GetGeometry(), renderer3.GetGeometry(), TEST_LOCATION);
1458   DALI_TEST_NOT_EQUALS(renderer2.GetShader(), renderer3.GetShader(), 0.0f, TEST_LOCATION);
1459
1460   // Set new IBL textures for model2, and this should apply to model2 instance only
1461   gResourceReadyCalled = false;
1462   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1463   model2.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
1464
1465   application.SendNotification();
1466   application.Render();
1467
1468   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1469   application.SendNotification();
1470   application.Render();
1471
1472   // Check that the new IBL textures are loaded for model2
1473   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1474
1475   // Check that the two instances still use the shared geometries from the cache
1476   // but now have their own shader objects and different texture set
1477   DALI_TEST_NOT_EQUALS(renderer2.GetTextures(), renderer3.GetTextures(), 0.0f, TEST_LOCATION);
1478   DALI_TEST_EQUALS(renderer2.GetGeometry(), renderer3.GetGeometry(), TEST_LOCATION);
1479   DALI_TEST_NOT_EQUALS(renderer2.GetShader(), renderer3.GetShader(), 0.0f, TEST_LOCATION);
1480
1481   // Check that the two instances now have their own diffuse texture and specular texture,
1482   // but all the other textures are still the same
1483   TextureSet textureSet2 = renderer2.GetTextures();
1484   TextureSet textureSet3 = renderer3.GetTextures();
1485   DALI_TEST_EQUALS(textureSet2.GetTextureCount(), 10u, TEST_LOCATION);
1486   DALI_TEST_EQUALS(textureSet3.GetTextureCount(), 10u, TEST_LOCATION);
1487
1488   for(uint32_t i = 0; i < 7u; i++)
1489   {
1490     DALI_TEST_EQUALS(textureSet2.GetTexture(i), textureSet3.GetTexture(i), TEST_LOCATION);
1491   }
1492
1493   DALI_TEST_NOT_EQUALS(textureSet2.GetTexture(8u), textureSet3.GetTexture(7u), 0.0f, TEST_LOCATION);
1494   DALI_TEST_NOT_EQUALS(textureSet2.GetTexture(9u), textureSet3.GetTexture(8u), 0.0f, TEST_LOCATION);
1495
1496   END_TEST;
1497 }
1498
1499 int UtcDaliModelAddRemoveModelNode(void)
1500 {
1501   ToolkitTestApplication application;
1502
1503   Scene3D::Model model = Scene3D::Model::New();
1504   model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1505
1506   Scene3D::ModelNode node1 = Scene3D::ModelNode::New();
1507   Scene3D::ModelNode node2 = Scene3D::ModelNode::New();
1508   Scene3D::ModelNode node3 = Scene3D::ModelNode::New();
1509   Scene3D::ModelNode node4 = Scene3D::ModelNode::New();
1510
1511   model.AddModelNode(node1);
1512   model.AddModelNode(node2);
1513   model.AddModelNode(node3);
1514   model.RemoveModelNode(node1); // Remove node before scene on
1515
1516   application.GetScene().Add(model);
1517
1518   Dali::Scene3D::ModelNode root = model.GetModelRoot();
1519   DALI_TEST_CHECK(root);
1520   DALI_TEST_EQUALS(2, root.GetChildCount(), TEST_LOCATION);
1521
1522   model.RemoveModelNode(node2); // Remove node after scene on
1523
1524   DALI_TEST_EQUALS(1, root.GetChildCount(), TEST_LOCATION);
1525
1526   model.AddModelNode(node4); // Add during scene on
1527
1528   DALI_TEST_EQUALS(2, root.GetChildCount(), TEST_LOCATION);
1529
1530   application.GetScene().Remove(model);
1531
1532   model.RemoveModelNode(node3); // Remove node after scene off
1533
1534   END_TEST;
1535 }
1536
1537 int UtcDaliModelFindChildModelNodeByName(void)
1538 {
1539   tet_infoline(" UtcDaliModelNodeFindChildModelNodeByName.");
1540
1541   ToolkitTestApplication application;
1542
1543   Scene3D::Model model = Scene3D::Model::New();
1544   application.GetScene().Add(model);
1545
1546   Scene3D::ModelNode modelNode1 = Scene3D::ModelNode::New();
1547   Scene3D::ModelNode modelNode2 = Scene3D::ModelNode::New();
1548
1549   modelNode1.SetProperty(Dali::Actor::Property::NAME, "modelNode1");
1550   modelNode2.SetProperty(Dali::Actor::Property::NAME, "modelNode2");
1551   model.AddModelNode(modelNode1);
1552   model.AddModelNode(modelNode2);
1553
1554   Scene3D::ModelNode child1 = model.FindChildModelNodeByName("modelNode1");
1555   DALI_TEST_CHECK(child1);
1556   DALI_TEST_EQUALS(child1, modelNode1, TEST_LOCATION);
1557
1558   Scene3D::ModelNode child2 = model.FindChildModelNodeByName("modelNode2");
1559   DALI_TEST_CHECK(child2);
1560   DALI_TEST_EQUALS(child2, modelNode2, TEST_LOCATION);
1561
1562   END_TEST;
1563 }
1564
1565 int UtcDaliModelSizeChange(void)
1566 {
1567   tet_infoline(" UtcDaliModelSizeChange.");
1568
1569   ToolkitTestApplication application;
1570
1571   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1572   model.SetProperty(Dali::Actor::Property::SIZE, Vector3(300, 300, 300));
1573   application.GetScene().Add(model);
1574
1575   application.SendNotification();
1576   application.Render();
1577
1578   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1579   application.SendNotification();
1580   application.Render();
1581
1582   DALI_TEST_EQUALS(model.GetChildCount(), 1u, TEST_LOCATION);
1583   Vector3 scale = model.GetChildAt(0u).GetProperty<Vector3>(Dali::Actor::Property::SCALE);
1584
1585   model.SetProperty(Dali::Actor::Property::SIZE, Vector3(600, 600, 600));
1586   Vector3 scale2 = model.GetChildAt(0u).GetProperty<Vector3>(Dali::Actor::Property::SCALE);
1587
1588   DALI_TEST_NOT_EQUALS(scale, scale2, 0.1f, TEST_LOCATION);
1589
1590   END_TEST;
1591 }
1592
1593 int UtcDaliModelSizeChange2(void)
1594 {
1595   tet_infoline(" UtcDaliModelSizeChange2.");
1596
1597   ToolkitTestApplication application;
1598
1599   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1600   model.SetProperty(Dali::Actor::Property::SIZE, Vector3(300, 300, 300));
1601   application.GetScene().Add(model);
1602
1603   application.SendNotification();
1604   application.Render();
1605
1606   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1607   application.SendNotification();
1608   application.Render();
1609
1610   DALI_TEST_EQUALS(model.GetChildCount(), 1u, TEST_LOCATION);
1611   Vector3 scale = model.GetChildAt(0u).GetProperty<Vector3>(Dali::Actor::Property::SCALE);
1612
1613   Animation animation = Animation::New(0.5f);
1614   animation.AnimateTo(Dali::Property(model, Dali::Actor::Property::SIZE), Vector3(600, 600, 600));
1615   animation.Play();
1616
1617   application.SendNotification();
1618   application.Render(250);
1619
1620   application.SendNotification();
1621
1622   Vector3 scale2 = model.GetChildAt(0u).GetProperty<Vector3>(Dali::Actor::Property::SCALE);
1623   DALI_TEST_NOT_EQUALS(scale, scale2, 0.1f, TEST_LOCATION);
1624
1625   END_TEST;
1626 }
1627
1628 int UtcDaliModelRetrieveBlendShapeNames(void)
1629 {
1630   tet_infoline(" UtcDaliModelRetrieveBlendShapeByName.");
1631
1632   ToolkitTestApplication application;
1633
1634   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_EXTRAS_FILE_NAME);
1635   model.SetProperty(Dali::Actor::Property::SIZE, Vector3(300, 300, 300));
1636   application.GetScene().Add(model);
1637
1638   application.SendNotification();
1639   application.Render();
1640
1641   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1642   application.SendNotification();
1643   application.Render();
1644
1645   DALI_TEST_EQUALS(model.GetChildCount(), 1u, TEST_LOCATION);
1646
1647   // Get target ModelNode that has extras
1648   Scene3D::ModelNode expectNode = model.FindChildModelNodeByName("AnimatedMorphCube");
1649
1650   // Pair of expected blend shape index from expectNode.
1651   std::map<std::string, Scene3D::Loader::BlendShapes::Index> expectBlendShapeNames = {
1652     {"Target_0", 0u},
1653     {"Target_1", 1u},
1654   };
1655
1656   std::vector<std::string> blendShapeNameList;
1657   model.RetrieveBlendShapeNames(blendShapeNameList);
1658
1659   DALI_TEST_EQUALS(blendShapeNameList.size(), expectBlendShapeNames.size(), TEST_LOCATION);
1660   for(auto i = 0u; i < blendShapeNameList.size(); ++i)
1661   {
1662     const auto& name = blendShapeNameList[i];
1663     tet_printf("Check retrieved blendshape name : %s\n", name.c_str());
1664
1665     const auto& iter = expectBlendShapeNames.find(name);
1666     DALI_TEST_CHECK(iter != expectBlendShapeNames.end());
1667
1668     std::vector<Scene3D::ModelNode> nodeList;
1669     model.RetrieveModelNodesByBlendShapeName(name, nodeList);
1670     DALI_TEST_EQUALS(nodeList.size(), 1u, TEST_LOCATION);
1671     DALI_TEST_EQUALS(nodeList[0], expectNode, TEST_LOCATION);
1672     DALI_TEST_EQUALS(nodeList[0].GetBlendShapeIndexByName(name), iter->second, TEST_LOCATION);
1673   }
1674
1675   END_TEST;
1676 }
1677
1678 int UtcDaliModelGenerateMotionDataAnimation01(void)
1679 {
1680   ToolkitTestApplication application;
1681
1682   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_MORPH_FILE_NAME);
1683   model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1684   application.GetScene().Add(model);
1685
1686   gResourceReadyCalled = false;
1687   model.ResourceReadySignal().Connect(&OnResourceReady);
1688   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1689
1690   application.SendNotification();
1691   application.Render();
1692
1693   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1694   application.SendNotification();
1695   application.Render();
1696
1697   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1698
1699   KeyFrames floatKeyFrames = KeyFrames::New();
1700   floatKeyFrames.Add(0.0f, 1.0f);
1701   floatKeyFrames.Add(1.0f, 0.5f);
1702
1703   float               duration   = 3.0f;
1704   Scene3D::MotionData motionData = Scene3D::MotionData::New(duration);
1705   motionData.Add(Scene3D::MotionTransformIndex::New("AnimatedMorphCube", Scene3D::MotionTransformIndex::TransformType::SCALE_Y), Scene3D::MotionValue::New(2.0f));
1706   motionData.Add(Scene3D::MotionTransformIndex::New("AnimatedMorphCube", Scene3D::MotionTransformIndex::TransformType::SCALE_Z), Scene3D::MotionValue::New(floatKeyFrames));
1707   motionData.Add(Scene3D::BlendShapeIndex::New("AnimatedMorphCube", 0), Scene3D::MotionValue::New(0.5f));
1708   motionData.Add(Scene3D::BlendShapeIndex::New("AnimatedMorphCube", 1), Scene3D::MotionValue::New(floatKeyFrames));
1709
1710   Animation generatedAnimation = model.GenerateMotionDataAnimation(motionData);
1711   DALI_TEST_CHECK(generatedAnimation);
1712   DALI_TEST_EQUALS(generatedAnimation.GetDuration(), duration, TEST_LOCATION);
1713
1714   Scene3D::MotionData invalidMotionData = Scene3D::MotionData::New(duration);
1715   invalidMotionData.Add(Scene3D::MotionTransformIndex::New("NotAnimatedMorphCube", Scene3D::MotionTransformIndex::TransformType::SCALE_Y), Scene3D::MotionValue::New(2.0f));
1716   invalidMotionData.Add(Scene3D::MotionTransformIndex::New("NotAnimatedMorphCube", Scene3D::MotionTransformIndex::TransformType::SCALE_Z), Scene3D::MotionValue::New(floatKeyFrames));
1717   invalidMotionData.Add(Scene3D::BlendShapeIndex::New("NotAnimatedMorphCube", 0), Scene3D::MotionValue::New(0.5f));
1718   invalidMotionData.Add(Scene3D::BlendShapeIndex::New("NotAnimatedMorphCube", 1), Scene3D::MotionValue::New(floatKeyFrames));
1719
1720   generatedAnimation = model.GenerateMotionDataAnimation(invalidMotionData);
1721   DALI_TEST_CHECK(!generatedAnimation); // Animation should be empty if motion data have invalid index.
1722
1723   END_TEST;
1724 }
1725
1726 int UtcDaliModelSetMotionData(void)
1727 {
1728   ToolkitTestApplication application;
1729
1730   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_MORPH_FILE_NAME);
1731   model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1732   application.GetScene().Add(model);
1733
1734   gResourceReadyCalled = false;
1735   model.ResourceReadySignal().Connect(&OnResourceReady);
1736   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1737
1738   application.SendNotification();
1739   application.Render();
1740
1741   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1742   application.SendNotification();
1743   application.Render();
1744
1745   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1746
1747   KeyFrames floatKeyFrames = KeyFrames::New();
1748   floatKeyFrames.Add(0.0f, 1.0f);
1749   floatKeyFrames.Add(1.0f, 0.5f);
1750
1751   float               duration   = 3.0f;
1752   Scene3D::MotionData motionData = Scene3D::MotionData::New(duration);
1753   motionData.Add(Scene3D::MotionTransformIndex::New("AnimatedMorphCube", Scene3D::MotionTransformIndex::TransformType::SCALE_Y), Scene3D::MotionValue::New(2.0f));
1754   motionData.Add(Scene3D::MotionTransformIndex::New("AnimatedMorphCube", Scene3D::MotionTransformIndex::TransformType::SCALE_Z), Scene3D::MotionValue::New(floatKeyFrames));
1755   motionData.Add(Scene3D::BlendShapeIndex::New("AnimatedMorphCube", 0), Scene3D::MotionValue::New(0.5f));
1756   motionData.Add(Scene3D::BlendShapeIndex::New("AnimatedMorphCube", 1), Scene3D::MotionValue::New(floatKeyFrames));
1757
1758   auto cubeModelNode = model.FindChildModelNodeByName("AnimatedMorphCube");
1759
1760   float expectScaleX = cubeModelNode.GetProperty<float>(Actor::Property::SCALE_X);
1761
1762   model.SetMotionData(motionData);
1763
1764   DALI_TEST_EQUALS(cubeModelNode.GetProperty<float>(Actor::Property::SCALE_X), expectScaleX, TEST_LOCATION);
1765   DALI_TEST_EQUALS(cubeModelNode.GetProperty<float>(Actor::Property::SCALE_Y), 2.0f, TEST_LOCATION);
1766   DALI_TEST_EQUALS(cubeModelNode.GetProperty<float>(Actor::Property::SCALE_Z), 0.5f, TEST_LOCATION); ///< Last value of keyframes
1767
1768   END_TEST;
1769 }
1770
1771 int UtcDaliModelBlendShapeMotionDataByName(void)
1772 {
1773   ToolkitTestApplication application;
1774
1775   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_EXTRAS_FILE_NAME);
1776   model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1777   application.GetScene().Add(model);
1778
1779   gResourceReadyCalled = false;
1780   model.ResourceReadySignal().Connect(&OnResourceReady);
1781   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1782
1783   application.SendNotification();
1784   application.Render();
1785
1786   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1787   application.SendNotification();
1788   application.Render();
1789
1790   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1791
1792   KeyFrames floatKeyFrames = KeyFrames::New();
1793   floatKeyFrames.Add(0.0f, 0.5f);
1794   floatKeyFrames.Add(1.0f, 1.0f);
1795
1796   float               duration   = 3.0f;
1797   Scene3D::MotionData motionData = Scene3D::MotionData::New(duration);
1798   motionData.Add(Scene3D::BlendShapeIndex::New("Target_0"), Scene3D::MotionValue::New(0.5f));
1799   motionData.Add(Scene3D::BlendShapeIndex::New("Target_1"), Scene3D::MotionValue::New(floatKeyFrames));
1800
1801   Animation generatedAnimation = model.GenerateMotionDataAnimation(motionData);
1802   DALI_TEST_CHECK(generatedAnimation);
1803   DALI_TEST_EQUALS(generatedAnimation.GetDuration(), duration, TEST_LOCATION);
1804
1805   model.SetMotionData(motionData);
1806
1807   // Get target ModelNode that has extras
1808   Scene3D::ModelNode expectNode    = model.FindChildModelNodeByName("AnimatedMorphCube");
1809   auto               propertyIndex = expectNode.GetPropertyIndex(motionData.GetIndex(0u).GetPropertyName(expectNode));
1810
1811   DALI_TEST_CHECK(propertyIndex != Property::INVALID_INDEX);
1812   DALI_TEST_EQUALS(expectNode.GetProperty<float>(propertyIndex), 0.5f, TEST_LOCATION);
1813
1814   propertyIndex = expectNode.GetPropertyIndex(motionData.GetIndex(1u).GetPropertyName(expectNode));
1815   DALI_TEST_CHECK(propertyIndex != Property::INVALID_INDEX);
1816   DALI_TEST_EQUALS(expectNode.GetProperty<float>(propertyIndex), 1.0f, TEST_LOCATION);
1817
1818   END_TEST;
1819 }