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