2 * Copyright (c) 2024 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali-toolkit-test-suite-utils.h>
19 #include <dali-toolkit/dali-toolkit.h>
20 #include <dali/devel-api/common/map-wrapper.h>
21 #include <dali/public-api/common/vector-wrapper.h>
25 #include <dali-toolkit/devel-api/focus-manager/keyboard-focus-manager-devel.h>
26 #include <dali/integration-api/events/touch-event-integ.h>
27 #include <toolkit-environment-variable.h>
28 #include <toolkit-event-thread-callback.h>
30 #include <dali-scene3d/public-api/controls/model/model.h>
31 #include <dali-scene3d/public-api/model-components/model-node.h>
33 #include <dali-scene3d/public-api/model-motion/motion-data.h>
34 #include <dali-scene3d/public-api/model-motion/motion-index/blend-shape-index.h>
35 #include <dali-scene3d/public-api/model-motion/motion-index/motion-transform-index.h>
37 #include <dali-scene3d/public-api/loader/node-definition.h>
39 #include <dali/devel-api/actors/camera-actor-devel.h>
42 using namespace Dali::Toolkit;
44 void model_startup(void)
46 test_return_value = TET_UNDEF;
49 void model_cleanup(void)
51 test_return_value = TET_PASS;
56 const bool DEFAULT_MODEL_CHILDREN_SENSITIVE = false;
57 const bool DEFAULT_MODEL_CHILDREN_FOCUSABLE = false;
59 * For the AnimatedCube.gltf and its Assets
60 * Donated by Norbert Nopper for glTF testing.
61 * Take from https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/AnimatedCube
63 const char* TEST_GLTF_FILE_NAME = TEST_RESOURCE_DIR "/AnimatedCube.gltf";
64 const char* TEST_GLTF_FILE_NAME_SAME_FILE = TEST_RESOURCE_DIR "/AnimatedCube2.gltf";
65 const char* TEST_GLTF_FILE_NAME_DIFF_META_FILE = TEST_RESOURCE_DIR "/AnimatedCube3.gltf";
66 const char* TEST_GLTF_ANIMATION_TEST_FILE_NAME = TEST_RESOURCE_DIR "/animationTest.gltf";
67 const char* TEST_GLTF_EXTRAS_FILE_NAME = TEST_RESOURCE_DIR "/AnimatedMorphCubeAnimateNonZeroFrame.gltf";
68 const char* TEST_GLTF_MULTIPLE_PRIMITIVE_FILE_NAME = TEST_RESOURCE_DIR "/simpleMultiplePrimitiveTest.gltf";
69 const char* TEST_GLTF_MORPH_FILE_NAME = TEST_RESOURCE_DIR "/AnimatedMorphCube.gltf";
70 const char* TEST_DLI_FILE_NAME = TEST_RESOURCE_DIR "/arc.dli";
71 const char* TEST_DLI_EXERCISE_FILE_NAME = TEST_RESOURCE_DIR "/exercise.dli";
74 * For the diffuse and specular cube map texture.
75 * These textures are based off version of Wave engine sample
76 * Take from https://github.com/WaveEngine/Samples
78 * Copyright (c) 2024 Wave Coorporation
80 * Permission is hereby granted, free of charge, to any person obtaining a copy
81 * of this software and associated documentation files (the "Software"), to
82 * deal in the Software without restriction, including without limitation the
83 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
84 * sell copies of the Software, and to permit persons to whom the Software is
85 * furnished to do so, subject to the following conditions:
87 * The above copyright notice and this permission notice shall be included in
88 * all copies or substantial portions of the Software.
90 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
91 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
92 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
93 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
94 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
95 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
98 const char* TEST_DIFFUSE_TEXTURE = TEST_RESOURCE_DIR "/forest_irradiance.ktx";
99 const char* TEST_SPECULAR_TEXTURE = TEST_RESOURCE_DIR "/forest_radiance.ktx";
101 bool gTouchCallBackCalled = false;
102 bool TestTouchCallback(Actor, const TouchEvent&)
104 gTouchCallBackCalled = true;
108 bool gFocusChangedCallBackCalled = false;
109 void TestFocusChangedCallback(Actor, Actor)
111 gFocusChangedCallBackCalled = true;
115 static bool gOnRelayoutCallBackCalled = false;
116 void OnRelayoutCallback(Actor actor)
118 gOnRelayoutCallBackCalled = true;
121 static bool gResourceReadyCalled = false;
122 void OnResourceReady(Control control)
124 gResourceReadyCalled = true;
127 void ApplyAllMaterialPropertyRecursively(Scene3D::ModelNode modelNode, const std::vector<KeyValuePair>& materialPropertyValues)
134 for(uint32_t primitiveIndex = 0u; primitiveIndex < modelNode.GetModelPrimitiveCount(); ++primitiveIndex)
136 Scene3D::ModelPrimitive primitive = modelNode.GetModelPrimitive(primitiveIndex);
139 Scene3D::Material material = primitive.GetMaterial();
142 for(const auto& keyValuePair : materialPropertyValues)
144 if(keyValuePair.first.type == Property::Key::Type::INDEX)
146 material.SetProperty(keyValuePair.first.indexKey, keyValuePair.second);
153 for(uint32_t childIndex = 0u; childIndex < modelNode.GetChildCount(); ++childIndex)
155 Scene3D::ModelNode childNode = Scene3D::ModelNode::DownCast(modelNode.GetChildAt(childIndex));
156 ApplyAllMaterialPropertyRecursively(childNode, materialPropertyValues);
162 // Negative test case for a method
163 int UtcDaliModelUninitialized(void)
165 ToolkitTestApplication application;
166 tet_infoline(" UtcDaliModelUninitialized");
168 Scene3D::Model model;
172 // New() must be called to create a Model or it wont be valid.
173 Actor a = Actor::New();
175 DALI_TEST_CHECK(false);
177 catch(Dali::DaliException& e)
179 // Tests that a negative test of an assertion succeeds
180 DALI_TEST_PRINT_ASSERT(e);
181 DALI_TEST_CHECK(!model);
186 // Positive test case for a method
187 int UtcDaliModelNew(void)
189 ToolkitTestApplication application;
190 tet_infoline(" UtcDaliModelNew");
192 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
193 DALI_TEST_CHECK(model);
197 // Positive test case for a method
198 int UtcDaliModelNewP2(void)
200 ToolkitTestApplication application;
201 tet_infoline(" UtcDaliModelNew without url");
203 Scene3D::Model model = Scene3D::Model::New();
204 DALI_TEST_CHECK(model);
206 application.GetScene().Add(model);
208 DALI_TEST_CHECK(model.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
210 application.GetScene().Remove(model);
212 DALI_TEST_CHECK(!model.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
217 int UtcDaliModelNewSameModelUrlCached(void)
219 ToolkitTestApplication application;
220 tet_infoline(" UtcDaliModelNew with same model");
222 // Set up trace debug
223 TestGlAbstraction& gl = application.GetGlAbstraction();
224 TraceCallStack& textureTrace = gl.GetTextureTrace();
225 textureTrace.Enable(true);
227 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
228 DALI_TEST_CHECK(model);
229 Scene3D::Model model2 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
230 DALI_TEST_CHECK(model2);
232 application.GetScene().Add(model);
234 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
236 application.SendNotification();
237 application.Render();
239 tet_printf("Test if there is at least 1 texture.\n");
240 int expectTextureCount = textureTrace.CountMethod("GenTextures");
241 DALI_TEST_GREATER(expectTextureCount, 0, TEST_LOCATION);
243 application.GetScene().Add(model2);
245 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
247 application.SendNotification();
248 application.Render();
250 tet_printf("Test if we reuse cached texture or not.\n");
251 int currentTextureCount = textureTrace.CountMethod("GenTextures");
252 DALI_TEST_EQUALS(currentTextureCount, expectTextureCount, TEST_LOCATION);
254 application.SendNotification();
255 application.Render();
260 int UtcDaliModelNewSameResourceUrlCached01(void)
262 ToolkitTestApplication application;
263 tet_infoline(" UtcDaliModelNew with difference url but same model");
265 // Set up trace debug
266 TestGlAbstraction& gl = application.GetGlAbstraction();
267 TraceCallStack& textureTrace = gl.GetTextureTrace();
268 textureTrace.Enable(true);
269 textureTrace.EnableLogging(true);
271 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
272 DALI_TEST_CHECK(model);
273 Scene3D::Model model2 = Scene3D::Model::New(TEST_GLTF_FILE_NAME_SAME_FILE); // Difference model that use same Images.
274 DALI_TEST_CHECK(model2);
275 Scene3D::Model model3 = Scene3D::Model::New(TEST_GLTF_FILE_NAME_DIFF_META_FILE); // Difference model that use same Images, but difference metadata.
276 DALI_TEST_CHECK(model3);
278 application.GetScene().Add(model);
280 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
282 application.SendNotification();
283 application.Render();
285 tet_printf("Test if there is at least 1 texture.\n");
286 int expectTextureCount = textureTrace.CountMethod("GenTextures");
287 DALI_TEST_GREATER(expectTextureCount, 0, TEST_LOCATION);
289 application.GetScene().Add(model2);
291 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
293 application.SendNotification();
294 application.Render();
296 tet_printf("Test if we reuse cached texture or not.\n");
297 int currentTextureCount = textureTrace.CountMethod("GenTextures");
298 DALI_TEST_EQUALS(currentTextureCount, expectTextureCount, TEST_LOCATION);
300 application.GetScene().Add(model3);
302 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
304 application.SendNotification();
305 application.Render();
307 tet_printf("Test if we don't reuse cached texture, due to the metadata difference.\n");
308 currentTextureCount = textureTrace.CountMethod("GenTextures");
309 DALI_TEST_GREATER(currentTextureCount, expectTextureCount, TEST_LOCATION);
311 application.SendNotification();
312 application.Render();
317 int UtcDaliModelNewSameResourceUrlCached02(void)
319 /// Make we don't use mutiple thread loading for this UTC.
320 EnvironmentVariable::SetTestEnvironmentVariable("DALI_ASYNC_MANAGER_THREAD_POOL_SIZE", "1");
321 EnvironmentVariable::SetTestEnvironmentVariable("DALI_ASYNC_MANAGER_LOW_PRIORITY_THREAD_POOL_SIZE", "1");
323 ToolkitTestApplication application;
324 tet_infoline(" UtcDaliModelNew with difference url but same model");
326 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
327 DALI_TEST_CHECK(model);
328 Scene3D::Model model2 = Scene3D::Model::New(TEST_GLTF_FILE_NAME_SAME_FILE);
329 DALI_TEST_CHECK(model2);
331 application.GetScene().Add(model);
332 application.GetScene().Add(model2);
334 application.SendNotification();
335 application.Render();
337 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
338 application.SendNotification();
339 application.Render();
344 // Positive test case for a method
345 int UtcDaliModelDownCast(void)
347 ToolkitTestApplication application;
348 tet_infoline(" UtcDaliModelDownCast");
350 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
351 BaseHandle handle(model);
353 Scene3D::Model model2 = Scene3D::Model::DownCast(handle);
354 DALI_TEST_CHECK(model);
355 DALI_TEST_CHECK(model2);
356 DALI_TEST_CHECK(model2 == model);
360 int UtcDaliModelTypeRegistry(void)
362 ToolkitTestApplication application;
364 TypeRegistry typeRegistry = TypeRegistry::Get();
365 DALI_TEST_CHECK(typeRegistry);
367 TypeInfo typeInfo = typeRegistry.GetTypeInfo("Model");
368 DALI_TEST_CHECK(typeInfo);
370 BaseHandle handle = typeInfo.CreateInstance();
371 DALI_TEST_CHECK(handle);
373 Scene3D::Model model = Scene3D::Model::DownCast(handle);
374 DALI_TEST_CHECK(model);
379 // Positive test case for a method
380 int UtcDaliModelAddRemove(void)
382 ToolkitTestApplication application;
383 tet_infoline(" UtcDaliModelAddRemove");
385 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
386 DALI_TEST_CHECK(model);
388 Actor actor = Actor::New();
389 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
391 model.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
392 model.SetProperty(Actor::Property::SIZE, application.GetScene().GetSize());
394 application.GetScene().Add(model);
396 DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
400 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
404 int UtcDaliModelCopyAndAssignment(void)
406 ToolkitTestApplication application;
408 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
409 DALI_TEST_CHECK(model);
411 Scene3D::Model copy(model);
412 DALI_TEST_CHECK(model == copy);
414 Scene3D::Model assign;
415 DALI_TEST_CHECK(!assign);
418 DALI_TEST_CHECK(assign == model);
423 int UtcDaliModelMoveConstructor(void)
425 ToolkitTestApplication application;
427 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
428 DALI_TEST_EQUALS(1, model.GetBaseObject().ReferenceCount(), TEST_LOCATION);
429 model.SetProperty(Actor::Property::SENSITIVE, false);
430 DALI_TEST_CHECK(false == model.GetProperty<bool>(Actor::Property::SENSITIVE));
432 Scene3D::Model moved = std::move(model);
433 DALI_TEST_CHECK(moved);
434 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
435 DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
436 DALI_TEST_CHECK(!model);
441 int UtcDaliModelMoveAssignment(void)
443 ToolkitTestApplication application;
445 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
446 DALI_TEST_EQUALS(1, model.GetBaseObject().ReferenceCount(), TEST_LOCATION);
447 model.SetProperty(Actor::Property::SENSITIVE, false);
448 DALI_TEST_CHECK(false == model.GetProperty<bool>(Actor::Property::SENSITIVE));
450 Scene3D::Model moved;
451 moved = std::move(model);
452 DALI_TEST_CHECK(moved);
453 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
454 DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
455 DALI_TEST_CHECK(!model);
460 int UtcDaliModelOnScene01(void)
462 ToolkitTestApplication application;
464 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
465 application.GetScene().Add(model);
467 gResourceReadyCalled = false;
468 model.ResourceReadySignal().Connect(&OnResourceReady);
469 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
471 application.SendNotification();
472 application.Render();
474 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
475 application.SendNotification();
476 application.Render();
478 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
480 uint32_t modelCount = model.GetModelRoot().GetChildCount();
481 DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
485 int UtcDaliModelOnScene02(void)
487 ToolkitTestApplication application;
489 Scene3D::Model model = Scene3D::Model::New(TEST_DLI_FILE_NAME);
490 application.GetScene().Add(model);
492 gResourceReadyCalled = false;
493 model.ResourceReadySignal().Connect(&OnResourceReady);
494 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
496 application.SendNotification();
497 application.Render();
499 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
500 application.SendNotification();
501 application.Render();
503 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
505 uint32_t modelCount = model.GetModelRoot().GetChildCount();
506 DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
508 Scene3D::ModelNode rootNode = model.GetModelRoot();
509 Vector3 rootSize = rootNode.GetProperty<Vector3>(Dali::Actor::Property::SIZE);
510 DALI_TEST_EQUALS(Vector3(2, 2, 1), rootSize, TEST_LOCATION);
515 int UtcDaliModelOnSizeSet(void)
517 ToolkitTestApplication application;
519 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
521 application.GetScene().Add(model);
523 application.SendNotification();
524 application.Render();
526 Vector2 size(200.0f, 300.0f);
527 model.SetProperty(Actor::Property::SIZE, size);
529 application.SendNotification();
530 application.Render();
532 DALI_TEST_EQUALS(model.GetCurrentProperty<Vector2>(Actor::Property::SIZE), size, TEST_LOCATION);
537 int UtcDaliModelGetNaturalSize(void)
539 ToolkitTestApplication application;
541 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
543 Vector3 naturalSize = model.GetNaturalSize();
544 DALI_TEST_EQUALS(Vector3::ZERO, naturalSize, TEST_LOCATION);
546 application.GetScene().Add(model);
548 gResourceReadyCalled = false;
549 model.ResourceReadySignal().Connect(&OnResourceReady);
550 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
552 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
553 application.SendNotification();
555 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
557 naturalSize = model.GetNaturalSize();
558 DALI_TEST_EQUALS(Vector3(2, 2, 2), naturalSize, TEST_LOCATION);
560 Scene3D::ModelNode rootNode = model.GetModelRoot();
561 DALI_TEST_CHECK(rootNode);
566 int UtcDaliModelSetImageBasedLightSource01(void)
568 ToolkitTestApplication application;
570 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
571 application.GetScene().Add(model);
573 gResourceReadyCalled = false;
574 model.ResourceReadySignal().Connect(&OnResourceReady);
575 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
577 application.SendNotification();
578 application.Render();
580 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
581 application.SendNotification();
582 application.Render();
584 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
586 Actor meshActor = model.FindChildByName("AnimatedCube");
587 DALI_TEST_CHECK(meshActor);
589 Renderer renderer = meshActor.GetRendererAt(0u);
590 DALI_TEST_CHECK(renderer);
592 TextureSet textureSet = renderer.GetTextures();
593 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 10u, TEST_LOCATION);
595 Texture diffuseTexture = textureSet.GetTexture(8u);
596 Texture specularTexture = textureSet.GetTexture(9u);
598 gResourceReadyCalled = false;
599 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
600 model.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
602 application.SendNotification();
603 application.Render();
605 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
606 application.SendNotification();
607 application.Render();
609 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
611 TextureSet newTextureSet = renderer.GetTextures();
612 Texture newDiffuseTexture = newTextureSet.GetTexture(8u);
613 Texture newSpecularTexture = newTextureSet.GetTexture(9u);
615 DALI_TEST_NOT_EQUALS(diffuseTexture, newDiffuseTexture, 0.0f, TEST_LOCATION);
616 DALI_TEST_NOT_EQUALS(specularTexture, newSpecularTexture, 0.0f, TEST_LOCATION);
623 int UtcDaliModelSetImageBasedLightSource02(void)
625 ToolkitTestApplication application;
627 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
628 application.GetScene().Add(model);
630 gResourceReadyCalled = false;
631 model.ResourceReadySignal().Connect(&OnResourceReady);
632 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
634 application.SendNotification();
635 application.Render();
637 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
638 application.SendNotification();
639 application.Render();
641 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
643 Actor meshActor = model.FindChildByName("AnimatedCube");
644 DALI_TEST_CHECK(meshActor);
646 Renderer renderer = meshActor.GetRendererAt(0u);
647 DALI_TEST_CHECK(renderer);
649 TextureSet textureSet = renderer.GetTextures();
650 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 10u, TEST_LOCATION);
652 Texture diffuseTexture = textureSet.GetTexture(8u);
653 Texture specularTexture = textureSet.GetTexture(9u);
655 // if url is empty, loading is not requested.
656 model.SetImageBasedLightSource("", "");
658 Texture newDiffuseTexture = textureSet.GetTexture(8u);
659 Texture newSpecularTexture = textureSet.GetTexture(9u);
661 DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION);
662 DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION);
667 int UtcDaliModelSetImageBasedLightSource03(void)
669 ToolkitTestApplication application;
671 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
672 application.GetScene().Add(model);
674 gResourceReadyCalled = false;
675 model.ResourceReadySignal().Connect(&OnResourceReady);
676 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
678 application.SendNotification();
679 application.Render();
681 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
682 application.SendNotification();
683 application.Render();
685 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
687 Actor meshActor = model.FindChildByName("AnimatedCube");
688 DALI_TEST_CHECK(meshActor);
690 Renderer renderer = meshActor.GetRendererAt(0u);
691 DALI_TEST_CHECK(renderer);
693 TextureSet textureSet = renderer.GetTextures();
694 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 10u, TEST_LOCATION);
696 Texture diffuseTexture = textureSet.GetTexture(8u);
697 Texture specularTexture = textureSet.GetTexture(9u);
699 gResourceReadyCalled = false;
700 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
701 model.SetImageBasedLightSource("dummy.ktx", "dummy.ktx");
703 application.SendNotification();
704 application.Render();
706 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
707 application.SendNotification();
708 application.Render();
710 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
712 Texture newDiffuseTexture = textureSet.GetTexture(8u);
713 Texture newSpecularTexture = textureSet.GetTexture(9u);
715 DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION);
716 DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION);
721 int UtcDaliModelSetImageBasedLightSource04(void)
723 ToolkitTestApplication application;
725 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
726 model.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
727 application.GetScene().Add(model);
729 gResourceReadyCalled = false;
730 model.ResourceReadySignal().Connect(&OnResourceReady);
731 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
733 application.SendNotification();
734 application.Render();
736 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
737 application.SendNotification();
738 application.Render();
740 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
744 int UtcDaliModelImageBasedFactor(void)
746 ToolkitTestApplication application;
748 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
750 DALI_TEST_EQUALS(model.GetImageBasedLightScaleFactor(), 1.0f, TEST_LOCATION);
752 model.SetImageBasedLightScaleFactor(0.5f);
753 DALI_TEST_EQUALS(model.GetImageBasedLightScaleFactor(), 0.5f, TEST_LOCATION);
757 int UtcDaliModelChildrenSensitive01(void)
759 ToolkitTestApplication application;
761 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
762 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
763 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
764 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
765 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
767 // Get default vaule.
768 DALI_TEST_EQUALS(view.GetChildrenSensitive(), DEFAULT_MODEL_CHILDREN_SENSITIVE, TEST_LOCATION);
770 // Allow children actor's event before on scene.
771 view.SetChildrenSensitive(true);
772 DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
773 application.GetScene().Add(view);
775 gResourceReadyCalled = false;
776 view.ResourceReadySignal().Connect(&OnResourceReady);
777 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
779 application.SendNotification();
780 application.Render();
782 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
783 application.SendNotification();
784 application.Render();
786 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
788 Actor meshActor = view.FindChildByName("AnimatedCube");
789 DALI_TEST_CHECK(meshActor);
791 // connect hit-test signal
792 gTouchCallBackCalled = false;
793 meshActor.TouchedSignal().Connect(TestTouchCallback);
795 Vector2 sceneSize = application.GetScene().GetSize();
797 // Try to touch center of scene.
798 Dali::Integration::Point point;
799 point.SetState(PointState::DOWN);
800 point.SetScreenPosition(sceneSize * 0.5f);
801 Dali::Integration::TouchEvent event;
802 event.AddPoint(point);
804 // flush the queue and render once
805 application.SendNotification();
806 application.Render();
809 DALI_TEST_CHECK(!gTouchCallBackCalled);
810 application.ProcessEvent(event);
812 DALI_TEST_CHECK(gTouchCallBackCalled);
815 gTouchCallBackCalled = false;
817 // Block children actor's event
818 view.SetChildrenSensitive(false);
819 DALI_TEST_EQUALS(view.GetChildrenSensitive(), false, TEST_LOCATION);
821 // flush the queue and render once
822 application.SendNotification();
823 application.Render();
826 DALI_TEST_CHECK(!gTouchCallBackCalled);
827 application.ProcessEvent(event);
829 DALI_TEST_CHECK(!gTouchCallBackCalled);
832 gTouchCallBackCalled = false;
835 view.SetChildrenSensitive(true);
836 DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
838 // flush the queue and render once
839 application.SendNotification();
840 application.Render();
843 DALI_TEST_CHECK(!gTouchCallBackCalled);
844 application.ProcessEvent(event);
846 DALI_TEST_CHECK(gTouchCallBackCalled);
849 gTouchCallBackCalled = false;
854 int UtcDaliModelChildrenSensitive02(void)
856 ToolkitTestApplication application;
858 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
859 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
860 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
861 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
862 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
865 DALI_TEST_EQUALS(view.GetChildrenSensitive(), DEFAULT_MODEL_CHILDREN_SENSITIVE, TEST_LOCATION);
867 // Block children actor's event before on scene.
868 view.SetChildrenSensitive(false);
869 DALI_TEST_EQUALS(view.GetChildrenSensitive(), false, TEST_LOCATION);
870 application.GetScene().Add(view);
872 gResourceReadyCalled = false;
873 view.ResourceReadySignal().Connect(&OnResourceReady);
874 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
876 application.SendNotification();
877 application.Render();
879 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
880 application.SendNotification();
881 application.Render();
883 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
885 Actor meshActor = view.FindChildByName("AnimatedCube");
886 DALI_TEST_CHECK(meshActor);
888 // connect hit-test signal
889 gTouchCallBackCalled = false;
890 meshActor.TouchedSignal().Connect(TestTouchCallback);
892 Vector2 sceneSize = application.GetScene().GetSize();
894 // Try to touch center of scene.
895 Dali::Integration::Point point;
896 point.SetState(PointState::DOWN);
897 point.SetScreenPosition(sceneSize * 0.5f);
898 Dali::Integration::TouchEvent event;
899 event.AddPoint(point);
901 // flush the queue and render once
902 application.SendNotification();
903 application.Render();
906 DALI_TEST_CHECK(!gTouchCallBackCalled);
907 application.ProcessEvent(event);
909 DALI_TEST_CHECK(!gTouchCallBackCalled);
912 gTouchCallBackCalled = false;
915 view.SetChildrenSensitive(true);
916 DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
918 // flush the queue and render once
919 application.SendNotification();
920 application.Render();
923 DALI_TEST_CHECK(!gTouchCallBackCalled);
924 application.ProcessEvent(event);
926 DALI_TEST_CHECK(gTouchCallBackCalled);
929 gTouchCallBackCalled = false;
934 int UtcDaliModelChildrenFocusable01(void)
936 ToolkitTestApplication application;
938 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
939 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
940 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
941 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
942 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
944 // Get vaule. Default is false.
945 DALI_TEST_EQUALS(view.GetChildrenFocusable(), DEFAULT_MODEL_CHILDREN_FOCUSABLE, TEST_LOCATION);
947 // Allow children actor's focus before on scene.
948 view.SetChildrenFocusable(true);
949 DALI_TEST_EQUALS(view.GetChildrenFocusable(), true, TEST_LOCATION);
950 application.GetScene().Add(view);
952 gResourceReadyCalled = false;
953 view.ResourceReadySignal().Connect(&OnResourceReady);
954 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
956 application.SendNotification();
957 application.Render();
959 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
960 application.SendNotification();
961 application.Render();
963 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
965 Actor meshActor = view.FindChildByName("AnimatedCube");
966 DALI_TEST_CHECK(meshActor);
968 // Enable the default algorithm
969 KeyboardFocusManager manager = KeyboardFocusManager::Get();
970 DALI_TEST_CHECK(manager);
971 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
973 // connect focusable signal
974 gFocusChangedCallBackCalled = false;
975 meshActor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
976 manager.FocusChangedSignal().Connect(TestFocusChangedCallback);
978 // Initialize with some left-positioned actor
979 Control focusStartActor = Control::New();
980 focusStartActor.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
981 focusStartActor.SetProperty(Dali::Actor::Property::POSITION, Vector3(-200, 0, 0));
982 focusStartActor.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
983 focusStartActor.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
984 focusStartActor.SetProperty(Dali::Actor::Property::KEYBOARD_FOCUSABLE, true);
985 application.GetScene().Add(focusStartActor);
988 manager.ClearFocus();
989 manager.SetCurrentFocusActor(focusStartActor);
990 gFocusChangedCallBackCalled = false;
992 // flush the queue and render once
993 application.SendNotification();
994 application.Render();
996 // Focusable view find success
997 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
998 DALI_TEST_CHECK(gFocusChangedCallBackCalled);
1001 manager.ClearFocus();
1002 manager.SetCurrentFocusActor(focusStartActor);
1003 gFocusChangedCallBackCalled = false;
1005 // Block children actor's focus
1006 view.SetChildrenFocusable(false);
1007 DALI_TEST_EQUALS(view.GetChildrenFocusable(), false, TEST_LOCATION);
1009 // flush the queue and render once
1010 application.SendNotification();
1011 application.Render();
1013 // Focusable view find failed
1014 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1015 DALI_TEST_CHECK(!gFocusChangedCallBackCalled);
1018 manager.ClearFocus();
1019 manager.SetCurrentFocusActor(focusStartActor);
1020 gFocusChangedCallBackCalled = false;
1023 view.SetChildrenFocusable(true);
1024 DALI_TEST_EQUALS(view.GetChildrenFocusable(), true, TEST_LOCATION);
1026 // flush the queue and render once
1027 application.SendNotification();
1028 application.Render();
1030 // Focusable view find success
1031 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1032 DALI_TEST_CHECK(gFocusChangedCallBackCalled);
1035 manager.ClearFocus();
1036 manager.SetCurrentFocusActor(focusStartActor);
1037 gFocusChangedCallBackCalled = false;
1042 int UtcDaliModelModelChildrenFocusable02(void)
1044 ToolkitTestApplication application;
1046 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1047 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
1048 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
1049 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
1050 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1052 // Get vaule. Default is true.
1053 DALI_TEST_EQUALS(view.GetChildrenFocusable(), DEFAULT_MODEL_CHILDREN_FOCUSABLE, TEST_LOCATION);
1055 // Block children actor's focus before on scene.
1056 view.SetChildrenFocusable(false);
1057 DALI_TEST_EQUALS(view.GetChildrenFocusable(), false, TEST_LOCATION);
1058 application.GetScene().Add(view);
1060 gResourceReadyCalled = false;
1061 view.ResourceReadySignal().Connect(&OnResourceReady);
1062 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1064 application.SendNotification();
1065 application.Render();
1067 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1068 application.SendNotification();
1069 application.Render();
1071 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1073 Actor meshActor = view.FindChildByName("AnimatedCube");
1074 DALI_TEST_CHECK(meshActor);
1076 // Enable the default algorithm
1077 KeyboardFocusManager manager = KeyboardFocusManager::Get();
1078 DALI_TEST_CHECK(manager);
1079 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
1081 // connect focusable signal
1082 gFocusChangedCallBackCalled = false;
1083 meshActor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
1084 manager.FocusChangedSignal().Connect(TestFocusChangedCallback);
1086 // Initialize with some left-positioned actor
1087 Control focusStartActor = Control::New();
1088 focusStartActor.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
1089 focusStartActor.SetProperty(Dali::Actor::Property::POSITION, Vector3(-200, 0, 0));
1090 focusStartActor.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
1091 focusStartActor.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1092 focusStartActor.SetProperty(Dali::Actor::Property::KEYBOARD_FOCUSABLE, true);
1093 application.GetScene().Add(focusStartActor);
1096 manager.ClearFocus();
1097 manager.SetCurrentFocusActor(focusStartActor);
1098 gFocusChangedCallBackCalled = false;
1100 // flush the queue and render once
1101 application.SendNotification();
1102 application.Render();
1104 // Focusable view find failed
1105 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
1106 DALI_TEST_CHECK(!gFocusChangedCallBackCalled);
1109 manager.ClearFocus();
1110 manager.SetCurrentFocusActor(focusStartActor);
1111 gFocusChangedCallBackCalled = false;
1114 view.SetChildrenFocusable(true);
1115 DALI_TEST_EQUALS(view.GetChildrenFocusable(), true, TEST_LOCATION);
1117 // flush the queue and render once
1118 application.SendNotification();
1119 application.Render();
1121 // Focusable view find success
1122 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
1123 DALI_TEST_CHECK(gFocusChangedCallBackCalled);
1126 manager.ClearFocus();
1127 manager.SetCurrentFocusActor(focusStartActor);
1128 gFocusChangedCallBackCalled = false;
1133 int UtcDaliModelAnimation01(void)
1135 ToolkitTestApplication application;
1137 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1138 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1139 application.GetScene().Add(model);
1141 gResourceReadyCalled = false;
1142 model.ResourceReadySignal().Connect(&OnResourceReady);
1143 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1145 application.SendNotification();
1146 application.Render();
1148 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1149 application.SendNotification();
1150 application.Render();
1152 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1154 uint32_t animationCount = model.GetAnimationCount();
1155 DALI_TEST_EQUALS(1, animationCount, TEST_LOCATION);
1157 Animation animationByIndex = model.GetAnimation(0u);
1158 DALI_TEST_CHECK(animationByIndex);
1160 Animation animationByName = model.GetAnimation("animation_AnimatedCube");
1161 DALI_TEST_CHECK(animationByName);
1162 DALI_TEST_EQUALS(animationByIndex, animationByName, TEST_LOCATION);
1167 int UtcDaliModelAnimation02(void)
1169 ToolkitTestApplication application;
1171 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_ANIMATION_TEST_FILE_NAME);
1172 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1173 application.GetScene().Add(model);
1175 gResourceReadyCalled = false;
1176 model.ResourceReadySignal().Connect(&OnResourceReady);
1177 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1179 application.SendNotification();
1180 application.Render();
1182 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1183 application.SendNotification();
1184 application.Render();
1186 uint32_t animationCount = model.GetAnimationCount();
1187 DALI_TEST_EQUALS(9, animationCount, TEST_LOCATION);
1189 Animation animation1 = model.GetAnimation("Step Scale");
1190 DALI_TEST_CHECK(animation1);
1191 DALI_TEST_EQUALS(1.66667f, animation1.GetDuration(), 0.001f, TEST_LOCATION);
1193 Animation animation2 = model.GetAnimation("CubicSpline Scale");
1194 DALI_TEST_CHECK(animation2);
1195 DALI_TEST_EQUALS(1.66667f, animation2.GetDuration(), 0.001f, TEST_LOCATION);
1197 DALI_TEST_NOT_EQUALS(animation1, animation2, 0.0f, TEST_LOCATION);
1202 int UtcDaliModelAnimation03(void)
1204 ToolkitTestApplication application;
1206 Scene3D::Model model = Scene3D::Model::New(TEST_DLI_EXERCISE_FILE_NAME);
1207 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1208 application.GetScene().Add(model);
1210 gResourceReadyCalled = false;
1211 model.ResourceReadySignal().Connect(&OnResourceReady);
1212 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1214 application.SendNotification();
1215 application.Render();
1217 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1218 application.SendNotification();
1219 application.Render();
1221 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1223 uint32_t animationCount = model.GetAnimationCount();
1224 DALI_TEST_EQUALS(18, animationCount, TEST_LOCATION);
1226 Animation animationByIndex = model.GetAnimation(0u);
1227 DALI_TEST_CHECK(animationByIndex);
1229 Animation animationByName = model.GetAnimation("idleClip");
1230 DALI_TEST_CHECK(animationByName);
1231 DALI_TEST_EQUALS(animationByIndex, animationByName, TEST_LOCATION);
1236 int UtcDaliModelCameraGenerate01(void)
1238 ToolkitTestApplication application;
1240 Scene3D::Model model = Scene3D::Model::New(TEST_DLI_EXERCISE_FILE_NAME);
1241 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1242 application.GetScene().Add(model);
1244 gResourceReadyCalled = false;
1245 model.ResourceReadySignal().Connect(&OnResourceReady);
1246 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1248 application.SendNotification();
1249 application.Render();
1251 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1252 application.SendNotification();
1253 application.Render();
1255 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1257 uint32_t cameraCount = model.GetCameraCount();
1258 DALI_TEST_EQUALS(1, cameraCount, TEST_LOCATION);
1260 CameraActor generatedCamera = model.GenerateCamera(0u);
1261 DALI_TEST_CHECK(generatedCamera);
1263 generatedCamera = model.GenerateCamera(1u); // Fail to generate camera
1264 DALI_TEST_CHECK(!generatedCamera);
1269 int UtcDaliModelCameraGenerate02(void)
1271 ToolkitTestApplication application;
1273 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1274 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1275 application.GetScene().Add(model);
1277 gResourceReadyCalled = false;
1278 model.ResourceReadySignal().Connect(&OnResourceReady);
1279 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1281 application.SendNotification();
1282 application.Render();
1284 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1285 application.SendNotification();
1286 application.Render();
1288 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1290 uint32_t cameraCount = model.GetCameraCount();
1291 DALI_TEST_EQUALS(6, cameraCount, TEST_LOCATION);
1293 CameraActor generatedCamera0 = model.GenerateCamera(0u);
1294 DALI_TEST_CHECK(generatedCamera0);
1295 CameraActor generatedCamera1 = model.GenerateCamera(1u);
1296 DALI_TEST_CHECK(generatedCamera1);
1297 CameraActor generatedCamera2 = model.GenerateCamera(2u);
1298 DALI_TEST_CHECK(generatedCamera2);
1299 CameraActor generatedCamera3 = model.GenerateCamera(3u); // Infinity far camera
1300 DALI_TEST_CHECK(generatedCamera3);
1301 CameraActor generatedCamera4 = model.GenerateCamera(4u); // Broken camera 1
1302 DALI_TEST_CHECK(!generatedCamera4);
1303 CameraActor generatedCamera5 = model.GenerateCamera(5u); // Broken camera 2
1304 DALI_TEST_CHECK(!generatedCamera5);
1305 CameraActor generatedCamera6 = model.GenerateCamera(6u); // Out of bound
1306 DALI_TEST_CHECK(!generatedCamera6);
1308 CameraActor appliedCamera;
1309 DALI_TEST_EQUALS(model.ApplyCamera(0u, appliedCamera), false, TEST_LOCATION); // Cannot apply into empty camera.
1311 auto CompareCameraProperties = [](CameraActor lhs, CameraActor rhs, const char* location) {
1312 DALI_TEST_EQUALS(lhs.GetProperty<int>(Dali::CameraActor::Property::PROJECTION_MODE), rhs.GetProperty<int>(Dali::CameraActor::Property::PROJECTION_MODE), TEST_LOCATION);
1313 DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::CameraActor::Property::NEAR_PLANE_DISTANCE), rhs.GetProperty<float>(Dali::CameraActor::Property::NEAR_PLANE_DISTANCE), TEST_LOCATION);
1315 if(lhs.GetProperty<int>(Dali::CameraActor::Property::PROJECTION_MODE) == static_cast<int>(Dali::Camera::ProjectionMode::PERSPECTIVE_PROJECTION))
1317 DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::CameraActor::Property::FIELD_OF_VIEW), rhs.GetProperty<float>(Dali::CameraActor::Property::FIELD_OF_VIEW), TEST_LOCATION);
1318 // TODO : Open this test when infinity far projection implement.
1319 // DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::CameraActor::Property::FAR_PLANE_DISTANCE), rhs.GetProperty<float>(Dali::CameraActor::Property::FAR_PLANE_DISTANCE), TEST_LOCATION);
1323 DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE), rhs.GetProperty<float>(Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE), TEST_LOCATION);
1324 DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::CameraActor::Property::FAR_PLANE_DISTANCE), rhs.GetProperty<float>(Dali::CameraActor::Property::FAR_PLANE_DISTANCE), TEST_LOCATION);
1328 appliedCamera = CameraActor::New();
1329 DALI_TEST_EQUALS(model.ApplyCamera(0u, appliedCamera), true, TEST_LOCATION);
1330 CompareCameraProperties(generatedCamera0, appliedCamera, TEST_LOCATION);
1331 DALI_TEST_EQUALS(model.ApplyCamera(1u, appliedCamera), true, TEST_LOCATION);
1332 CompareCameraProperties(generatedCamera1, appliedCamera, TEST_LOCATION);
1333 DALI_TEST_EQUALS(model.ApplyCamera(2u, appliedCamera), true, TEST_LOCATION);
1334 CompareCameraProperties(generatedCamera2, appliedCamera, TEST_LOCATION);
1335 DALI_TEST_EQUALS(model.ApplyCamera(3u, appliedCamera), true, TEST_LOCATION);
1336 CompareCameraProperties(generatedCamera3, appliedCamera, TEST_LOCATION);
1337 DALI_TEST_EQUALS(model.ApplyCamera(4u, appliedCamera), false, TEST_LOCATION); // Broken camera 1
1338 DALI_TEST_EQUALS(model.ApplyCamera(5u, appliedCamera), false, TEST_LOCATION); // Broken camera 2
1339 DALI_TEST_EQUALS(model.ApplyCamera(6u, appliedCamera), false, TEST_LOCATION); // Cannot apply over the index.
1344 int UtcDaliModelMultiplePrimitives(void)
1346 ToolkitTestApplication application;
1348 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_MULTIPLE_PRIMITIVE_FILE_NAME);
1349 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1350 application.GetScene().Add(model);
1352 gResourceReadyCalled = false;
1353 model.ResourceReadySignal().Connect(&OnResourceReady);
1354 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1356 application.SendNotification();
1357 application.Render();
1359 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1360 application.SendNotification();
1361 application.Render();
1363 Actor actor = model.FindChildByName("rootNode");
1365 DALI_TEST_EQUALS(0, actor.GetChildCount(), TEST_LOCATION);
1366 DALI_TEST_EQUALS(2, actor.GetRendererCount(), TEST_LOCATION);
1371 int UtcDaliModelColorMode(void)
1373 ToolkitTestApplication application;
1375 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1376 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1377 model.SetProperty(Dali::Actor::Property::COLOR, Color::RED);
1378 application.GetScene().Add(model);
1380 gResourceReadyCalled = false;
1381 model.ResourceReadySignal().Connect(&OnResourceReady);
1382 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1384 application.SendNotification();
1385 application.Render();
1387 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1388 application.SendNotification();
1389 application.Render();
1391 Actor actor = model.FindChildByName("AnimatedCube");
1392 Vector4 childColor = actor[Dali::Actor::Property::COLOR];
1393 Vector4 childWorldColor = actor[Dali::Actor::Property::WORLD_COLOR];
1395 DALI_TEST_EQUALS(childColor, Color::WHITE, TEST_LOCATION);
1396 DALI_TEST_EQUALS(childWorldColor, Color::RED, TEST_LOCATION);
1401 int UtcDaliModelResourceReady(void)
1403 ToolkitTestApplication application;
1405 gOnRelayoutCallBackCalled = false;
1406 gResourceReadyCalled = false;
1407 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_ANIMATION_TEST_FILE_NAME);
1408 model.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1409 model.OnRelayoutSignal().Connect(OnRelayoutCallback);
1410 model.ResourceReadySignal().Connect(OnResourceReady);
1411 DALI_TEST_EQUALS(model.IsResourceReady(), false, TEST_LOCATION);
1414 DALI_TEST_CHECK(!gOnRelayoutCallBackCalled);
1415 DALI_TEST_CHECK(!gResourceReadyCalled);
1417 application.GetScene().Add(model);
1419 application.SendNotification();
1420 application.Render();
1422 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1423 application.SendNotification();
1424 application.Render();
1426 DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, false, TEST_LOCATION);
1427 DALI_TEST_EQUALS(model.IsResourceReady(), true, TEST_LOCATION);
1428 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1433 int UtcDaliModelResourceReady02(void)
1435 tet_infoline("Test model load successfully even if shader language version is low\n");
1436 ToolkitTestApplication application;
1438 auto originalShaderVersion = application.GetGlAbstraction().GetShaderLanguageVersion();
1440 // Change the shader language version forcely!
1441 application.GetGlAbstraction().mShaderLanguageVersion = 200;
1445 gOnRelayoutCallBackCalled = false;
1446 gResourceReadyCalled = false;
1447 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_MORPH_FILE_NAME);
1448 model.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1449 model.OnRelayoutSignal().Connect(OnRelayoutCallback);
1450 model.ResourceReadySignal().Connect(OnResourceReady);
1451 DALI_TEST_EQUALS(model.IsResourceReady(), false, TEST_LOCATION);
1454 DALI_TEST_CHECK(!gOnRelayoutCallBackCalled);
1455 DALI_TEST_CHECK(!gResourceReadyCalled);
1457 application.GetScene().Add(model);
1459 application.SendNotification();
1460 application.Render();
1462 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1463 application.SendNotification();
1464 application.Render();
1466 DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, false, TEST_LOCATION);
1467 DALI_TEST_EQUALS(model.IsResourceReady(), true, TEST_LOCATION);
1468 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1470 // Change material information, for line coverage.
1471 auto modelNode = model.FindChildModelNodeByName("AnimatedMorphCube");
1472 DALI_TEST_CHECK(modelNode);
1473 DALI_TEST_GREATER(modelNode.GetModelPrimitiveCount(), 0u, TEST_LOCATION);
1474 auto modelPrimitive = modelNode.GetModelPrimitive(0u);
1475 DALI_TEST_CHECK(modelPrimitive);
1476 auto material = modelPrimitive.GetMaterial();
1477 DALI_TEST_CHECK(material);
1479 auto originBaseColorFactor = material.GetProperty<Dali::Vector4>(Dali::Scene3D::Material::Property::BASE_COLOR_FACTOR);
1480 auto expectBaseColorFactor = Vector4(originBaseColorFactor.r + 0.05f, originBaseColorFactor.g - 0.05f, originBaseColorFactor.b, originBaseColorFactor.a);
1481 material.SetProperty(Dali::Scene3D::Material::Property::BASE_COLOR_FACTOR, expectBaseColorFactor);
1483 application.SendNotification();
1484 application.Render();
1486 DALI_TEST_EQUALS(material.GetProperty<Dali::Vector4>(Dali::Scene3D::Material::Property::BASE_COLOR_FACTOR), expectBaseColorFactor, TEST_LOCATION);
1490 DALI_TEST_CHECK(false);
1493 // Revert shader version. We should revert it even if UTC failed.
1494 application.GetGlAbstraction().mShaderLanguageVersion = originalShaderVersion;
1499 int UtcDaliModelResourceCacheCheck(void)
1501 ToolkitTestApplication application;
1503 // Load three instances of the same model and add them to the scene
1504 Scene3D::Model model1 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1505 Scene3D::Model model2 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1506 Scene3D::Model model3 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1508 application.GetScene().Add(model1);
1509 application.GetScene().Add(model2);
1510 application.GetScene().Add(model3);
1512 gResourceReadyCalled = false;
1513 model1.ResourceReadySignal().Connect(&OnResourceReady);
1514 model2.ResourceReadySignal().Connect(&OnResourceReady);
1515 model3.ResourceReadySignal().Connect(&OnResourceReady);
1516 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1518 application.SendNotification();
1519 application.Render();
1521 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1522 application.SendNotification();
1523 application.Render();
1525 // Check that the loading has finished for all the three instances
1526 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1528 Actor meshActor1 = model1.FindChildByName("AnimatedCube");
1529 Actor meshActor2 = model2.FindChildByName("AnimatedCube");
1530 Actor meshActor3 = model3.FindChildByName("AnimatedCube");
1531 DALI_TEST_CHECK(meshActor1);
1532 DALI_TEST_CHECK(meshActor2);
1533 DALI_TEST_CHECK(meshActor3);
1535 Renderer renderer1 = meshActor1.GetRendererAt(0u);
1536 Renderer renderer2 = meshActor2.GetRendererAt(0u);
1537 Renderer renderer3 = meshActor3.GetRendererAt(0u);
1538 DALI_TEST_CHECK(renderer1);
1539 DALI_TEST_CHECK(renderer2);
1540 DALI_TEST_CHECK(renderer3);
1542 // Check that all the three instances use the shared textures and geometries from the cache
1543 // but have their own shader objects
1544 DALI_TEST_EQUALS(renderer1.GetTextures(), renderer2.GetTextures(), TEST_LOCATION);
1545 DALI_TEST_EQUALS(renderer1.GetTextures(), renderer3.GetTextures(), TEST_LOCATION);
1546 DALI_TEST_EQUALS(renderer1.GetGeometry(), renderer2.GetGeometry(), TEST_LOCATION);
1547 DALI_TEST_EQUALS(renderer1.GetGeometry(), renderer3.GetGeometry(), TEST_LOCATION);
1548 DALI_TEST_NOT_EQUALS(renderer1.GetShader(), renderer2.GetShader(), 0.0f, TEST_LOCATION);
1549 DALI_TEST_NOT_EQUALS(renderer1.GetShader(), renderer3.GetShader(), 0.0f, TEST_LOCATION);
1550 DALI_TEST_NOT_EQUALS(renderer2.GetShader(), renderer3.GetShader(), 0.0f, TEST_LOCATION);
1556 // Check that all the other two instances still use the shared textures and geometries from the cache
1557 // but have their own shader objects
1558 DALI_TEST_EQUALS(renderer2.GetTextures(), renderer3.GetTextures(), TEST_LOCATION);
1559 DALI_TEST_EQUALS(renderer2.GetGeometry(), renderer3.GetGeometry(), TEST_LOCATION);
1560 DALI_TEST_NOT_EQUALS(renderer2.GetShader(), renderer3.GetShader(), 0.0f, TEST_LOCATION);
1562 // Set new IBL textures for model2, and this should apply to model2 instance only
1563 gResourceReadyCalled = false;
1564 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1565 model2.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
1567 application.SendNotification();
1568 application.Render();
1570 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
1571 application.SendNotification();
1572 application.Render();
1574 // Check that the new IBL textures are loaded for model2
1575 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1577 // Check that the two instances still use the shared geometries from the cache
1578 // but now have their own shader objects and different texture set
1579 DALI_TEST_NOT_EQUALS(renderer2.GetTextures(), renderer3.GetTextures(), 0.0f, TEST_LOCATION);
1580 DALI_TEST_EQUALS(renderer2.GetGeometry(), renderer3.GetGeometry(), TEST_LOCATION);
1581 DALI_TEST_NOT_EQUALS(renderer2.GetShader(), renderer3.GetShader(), 0.0f, TEST_LOCATION);
1583 // Check that the two instances now have their own diffuse texture and specular texture,
1584 // but all the other textures are still the same
1585 TextureSet textureSet2 = renderer2.GetTextures();
1586 TextureSet textureSet3 = renderer3.GetTextures();
1587 DALI_TEST_EQUALS(textureSet2.GetTextureCount(), 10u, TEST_LOCATION);
1588 DALI_TEST_EQUALS(textureSet3.GetTextureCount(), 10u, TEST_LOCATION);
1590 for(uint32_t i = 0; i < 7u; i++)
1592 DALI_TEST_EQUALS(textureSet2.GetTexture(i), textureSet3.GetTexture(i), TEST_LOCATION);
1595 DALI_TEST_NOT_EQUALS(textureSet2.GetTexture(8u), textureSet3.GetTexture(7u), 0.0f, TEST_LOCATION);
1596 DALI_TEST_NOT_EQUALS(textureSet2.GetTexture(9u), textureSet3.GetTexture(8u), 0.0f, TEST_LOCATION);
1601 int UtcDaliModelAddRemoveModelNode(void)
1603 ToolkitTestApplication application;
1605 Scene3D::Model model = Scene3D::Model::New();
1606 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1608 Scene3D::ModelNode node1 = Scene3D::ModelNode::New();
1609 Scene3D::ModelNode node2 = Scene3D::ModelNode::New();
1610 Scene3D::ModelNode node3 = Scene3D::ModelNode::New();
1611 Scene3D::ModelNode node4 = Scene3D::ModelNode::New();
1613 model.AddModelNode(node1);
1614 model.AddModelNode(node2);
1615 model.AddModelNode(node3);
1616 model.RemoveModelNode(node1); // Remove node before scene on
1618 application.GetScene().Add(model);
1620 Dali::Scene3D::ModelNode root = model.GetModelRoot();
1621 DALI_TEST_CHECK(root);
1622 DALI_TEST_EQUALS(2, root.GetChildCount(), TEST_LOCATION);
1624 model.RemoveModelNode(node2); // Remove node after scene on
1626 DALI_TEST_EQUALS(1, root.GetChildCount(), TEST_LOCATION);
1628 model.AddModelNode(node4); // Add during scene on
1630 DALI_TEST_EQUALS(2, root.GetChildCount(), TEST_LOCATION);
1632 application.GetScene().Remove(model);
1634 model.RemoveModelNode(node3); // Remove node after scene off
1639 int UtcDaliModelFindChildModelNodeByName(void)
1641 tet_infoline(" UtcDaliModelNodeFindChildModelNodeByName.");
1643 ToolkitTestApplication application;
1645 Scene3D::Model model = Scene3D::Model::New();
1646 application.GetScene().Add(model);
1648 Scene3D::ModelNode modelNode1 = Scene3D::ModelNode::New();
1649 Scene3D::ModelNode modelNode2 = Scene3D::ModelNode::New();
1651 modelNode1.SetProperty(Dali::Actor::Property::NAME, "modelNode1");
1652 modelNode2.SetProperty(Dali::Actor::Property::NAME, "modelNode2");
1653 model.AddModelNode(modelNode1);
1654 model.AddModelNode(modelNode2);
1656 Scene3D::ModelNode child1 = model.FindChildModelNodeByName("modelNode1");
1657 DALI_TEST_CHECK(child1);
1658 DALI_TEST_EQUALS(child1, modelNode1, TEST_LOCATION);
1660 Scene3D::ModelNode child2 = model.FindChildModelNodeByName("modelNode2");
1661 DALI_TEST_CHECK(child2);
1662 DALI_TEST_EQUALS(child2, modelNode2, TEST_LOCATION);
1667 int UtcDaliModelSizeChange(void)
1669 tet_infoline(" UtcDaliModelSizeChange.");
1671 ToolkitTestApplication application;
1673 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1674 model.SetProperty(Dali::Actor::Property::SIZE, Vector3(300, 300, 300));
1675 application.GetScene().Add(model);
1677 application.SendNotification();
1678 application.Render();
1680 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1681 application.SendNotification();
1682 application.Render();
1684 DALI_TEST_EQUALS(model.GetChildCount(), 1u, TEST_LOCATION);
1685 Vector3 scale = model.GetChildAt(0u).GetProperty<Vector3>(Dali::Actor::Property::SCALE);
1687 model.SetProperty(Dali::Actor::Property::SIZE, Vector3(600, 600, 600));
1688 Vector3 scale2 = model.GetChildAt(0u).GetProperty<Vector3>(Dali::Actor::Property::SCALE);
1690 DALI_TEST_NOT_EQUALS(scale, scale2, 0.1f, TEST_LOCATION);
1695 int UtcDaliModelSizeChange2(void)
1697 tet_infoline(" UtcDaliModelSizeChange2.");
1699 ToolkitTestApplication application;
1701 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1702 model.SetProperty(Dali::Actor::Property::SIZE, Vector3(300, 300, 300));
1703 application.GetScene().Add(model);
1705 application.SendNotification();
1706 application.Render();
1708 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1709 application.SendNotification();
1710 application.Render();
1712 DALI_TEST_EQUALS(model.GetChildCount(), 1u, TEST_LOCATION);
1713 Vector3 scale = model.GetChildAt(0u).GetProperty<Vector3>(Dali::Actor::Property::SCALE);
1715 Animation animation = Animation::New(0.5f);
1716 animation.AnimateTo(Dali::Property(model, Dali::Actor::Property::SIZE), Vector3(600, 600, 600));
1719 application.SendNotification();
1720 application.Render(250);
1722 application.SendNotification();
1724 Vector3 scale2 = model.GetChildAt(0u).GetProperty<Vector3>(Dali::Actor::Property::SCALE);
1725 DALI_TEST_NOT_EQUALS(scale, scale2, 0.1f, TEST_LOCATION);
1730 int UtcDaliModelRetrieveBlendShapeNames(void)
1732 tet_infoline(" UtcDaliModelRetrieveBlendShapeByName.");
1734 ToolkitTestApplication application;
1736 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_EXTRAS_FILE_NAME);
1737 model.SetProperty(Dali::Actor::Property::SIZE, Vector3(300, 300, 300));
1738 application.GetScene().Add(model);
1740 application.SendNotification();
1741 application.Render();
1743 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1744 application.SendNotification();
1745 application.Render();
1747 DALI_TEST_EQUALS(model.GetChildCount(), 1u, TEST_LOCATION);
1749 // Get target ModelNode that has extras
1750 Scene3D::ModelNode expectNode = model.FindChildModelNodeByName("AnimatedMorphCube");
1752 // Pair of expected blend shape index from expectNode.
1753 std::map<std::string, Scene3D::Loader::BlendShapes::Index> expectBlendShapeNames = {
1758 std::vector<std::string> blendShapeNameList;
1759 model.RetrieveBlendShapeNames(blendShapeNameList);
1761 DALI_TEST_EQUALS(blendShapeNameList.size(), expectBlendShapeNames.size(), TEST_LOCATION);
1762 for(auto i = 0u; i < blendShapeNameList.size(); ++i)
1764 const auto& name = blendShapeNameList[i];
1765 tet_printf("Check retrieved blendshape name : %s\n", name.c_str());
1767 const auto& iter = expectBlendShapeNames.find(name);
1768 DALI_TEST_CHECK(iter != expectBlendShapeNames.end());
1770 std::vector<Scene3D::ModelNode> nodeList;
1771 model.RetrieveModelNodesByBlendShapeName(name, nodeList);
1772 DALI_TEST_EQUALS(nodeList.size(), 1u, TEST_LOCATION);
1773 DALI_TEST_EQUALS(nodeList[0], expectNode, TEST_LOCATION);
1774 DALI_TEST_EQUALS(nodeList[0].GetBlendShapeIndexByName(name), iter->second, TEST_LOCATION);
1780 int UtcDaliModelGenerateMotionDataAnimation01(void)
1782 ToolkitTestApplication application;
1784 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_MORPH_FILE_NAME);
1785 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1786 application.GetScene().Add(model);
1788 gResourceReadyCalled = false;
1789 model.ResourceReadySignal().Connect(&OnResourceReady);
1790 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1792 application.SendNotification();
1793 application.Render();
1795 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1796 application.SendNotification();
1797 application.Render();
1799 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1801 KeyFrames floatKeyFrames = KeyFrames::New();
1802 floatKeyFrames.Add(0.0f, 1.0f);
1803 floatKeyFrames.Add(1.0f, 0.5f);
1805 float duration = 3.0f;
1806 Scene3D::MotionData motionData = Scene3D::MotionData::New(duration);
1807 motionData.Add(Scene3D::MotionTransformIndex::New("AnimatedMorphCube", Scene3D::MotionTransformIndex::TransformType::SCALE_Y), Scene3D::MotionValue::New(2.0f));
1808 motionData.Add(Scene3D::MotionTransformIndex::New("AnimatedMorphCube", Scene3D::MotionTransformIndex::TransformType::SCALE_Z), Scene3D::MotionValue::New(floatKeyFrames));
1809 motionData.Add(Scene3D::BlendShapeIndex::New("AnimatedMorphCube", 0), Scene3D::MotionValue::New(0.5f));
1810 motionData.Add(Scene3D::BlendShapeIndex::New("AnimatedMorphCube", 1), Scene3D::MotionValue::New(floatKeyFrames));
1812 Animation generatedAnimation = model.GenerateMotionDataAnimation(motionData);
1813 DALI_TEST_CHECK(generatedAnimation);
1814 DALI_TEST_EQUALS(generatedAnimation.GetDuration(), duration, TEST_LOCATION);
1816 Scene3D::MotionData invalidMotionData = Scene3D::MotionData::New(duration);
1817 invalidMotionData.Add(Scene3D::MotionTransformIndex::New("NotAnimatedMorphCube", Scene3D::MotionTransformIndex::TransformType::SCALE_Y), Scene3D::MotionValue::New(2.0f));
1818 invalidMotionData.Add(Scene3D::MotionTransformIndex::New("NotAnimatedMorphCube", Scene3D::MotionTransformIndex::TransformType::SCALE_Z), Scene3D::MotionValue::New(floatKeyFrames));
1819 invalidMotionData.Add(Scene3D::BlendShapeIndex::New("NotAnimatedMorphCube", 0), Scene3D::MotionValue::New(0.5f));
1820 invalidMotionData.Add(Scene3D::BlendShapeIndex::New("NotAnimatedMorphCube", 1), Scene3D::MotionValue::New(floatKeyFrames));
1822 generatedAnimation = model.GenerateMotionDataAnimation(invalidMotionData);
1823 DALI_TEST_CHECK(!generatedAnimation); // Animation should be empty if motion data have invalid index.
1828 int UtcDaliModelSetMotionData(void)
1830 ToolkitTestApplication application;
1832 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_MORPH_FILE_NAME);
1833 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1834 application.GetScene().Add(model);
1836 gResourceReadyCalled = false;
1837 model.ResourceReadySignal().Connect(&OnResourceReady);
1838 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1840 application.SendNotification();
1841 application.Render();
1843 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1844 application.SendNotification();
1845 application.Render();
1847 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1849 KeyFrames floatKeyFrames = KeyFrames::New();
1850 floatKeyFrames.Add(0.0f, 1.0f);
1851 floatKeyFrames.Add(1.0f, 0.5f);
1853 float duration = 3.0f;
1854 Scene3D::MotionData motionData = Scene3D::MotionData::New(duration);
1855 motionData.Add(Scene3D::MotionTransformIndex::New("AnimatedMorphCube", Scene3D::MotionTransformIndex::TransformType::SCALE_Y), Scene3D::MotionValue::New(2.0f));
1856 motionData.Add(Scene3D::MotionTransformIndex::New("AnimatedMorphCube", Scene3D::MotionTransformIndex::TransformType::SCALE_Z), Scene3D::MotionValue::New(floatKeyFrames));
1857 motionData.Add(Scene3D::BlendShapeIndex::New("AnimatedMorphCube", 0), Scene3D::MotionValue::New(0.5f));
1858 motionData.Add(Scene3D::BlendShapeIndex::New("AnimatedMorphCube", 1), Scene3D::MotionValue::New(floatKeyFrames));
1860 auto cubeModelNode = model.FindChildModelNodeByName("AnimatedMorphCube");
1862 float expectScaleX = cubeModelNode.GetProperty<float>(Actor::Property::SCALE_X);
1864 model.SetMotionData(motionData);
1866 DALI_TEST_EQUALS(cubeModelNode.GetProperty<float>(Actor::Property::SCALE_X), expectScaleX, TEST_LOCATION);
1867 DALI_TEST_EQUALS(cubeModelNode.GetProperty<float>(Actor::Property::SCALE_Y), 2.0f, TEST_LOCATION);
1868 DALI_TEST_EQUALS(cubeModelNode.GetProperty<float>(Actor::Property::SCALE_Z), 0.5f, TEST_LOCATION); ///< Last value of keyframes
1873 int UtcDaliModelBlendShapeMotionDataByName(void)
1875 ToolkitTestApplication application;
1877 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_EXTRAS_FILE_NAME);
1878 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1879 application.GetScene().Add(model);
1881 gResourceReadyCalled = false;
1882 model.ResourceReadySignal().Connect(&OnResourceReady);
1883 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1885 application.SendNotification();
1886 application.Render();
1888 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1889 application.SendNotification();
1890 application.Render();
1892 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1894 KeyFrames floatKeyFrames = KeyFrames::New();
1895 floatKeyFrames.Add(0.0f, 0.5f);
1896 floatKeyFrames.Add(1.0f, 1.0f);
1898 float duration = 3.0f;
1899 Scene3D::MotionData motionData = Scene3D::MotionData::New(duration);
1900 motionData.Add(Scene3D::BlendShapeIndex::New("Target_0"), Scene3D::MotionValue::New(0.5f));
1901 motionData.Add(Scene3D::BlendShapeIndex::New("Target_1"), Scene3D::MotionValue::New(floatKeyFrames));
1903 Animation generatedAnimation = model.GenerateMotionDataAnimation(motionData);
1904 DALI_TEST_CHECK(generatedAnimation);
1905 DALI_TEST_EQUALS(generatedAnimation.GetDuration(), duration, TEST_LOCATION);
1907 model.SetMotionData(motionData);
1909 // Get target ModelNode that has extras
1910 Scene3D::ModelNode expectNode = model.FindChildModelNodeByName("AnimatedMorphCube");
1911 auto propertyIndex = expectNode.GetPropertyIndex(motionData.GetIndex(0u).GetPropertyName(expectNode));
1913 DALI_TEST_CHECK(propertyIndex != Property::INVALID_INDEX);
1914 DALI_TEST_EQUALS(expectNode.GetProperty<float>(propertyIndex), 0.5f, TEST_LOCATION);
1916 propertyIndex = expectNode.GetPropertyIndex(motionData.GetIndex(1u).GetPropertyName(expectNode));
1917 DALI_TEST_CHECK(propertyIndex != Property::INVALID_INDEX);
1918 DALI_TEST_EQUALS(expectNode.GetProperty<float>(propertyIndex), 1.0f, TEST_LOCATION);
1923 int UtcDaliModelMaterialUniformChange(void)
1925 ToolkitTestApplication application;
1927 static std::vector<UniformData> customUniforms =
1929 UniformData("uColorFactor", Property::Type::VECTOR4),
1930 UniformData("uBaseColorTextureTransformAvailable", Property::Type::FLOAT),
1931 UniformData(Scene3D::Loader::NodeDefinition::GetIblMaxLodUniformName().data(), Property::Type::FLOAT),
1932 UniformData(Scene3D::Loader::NodeDefinition::GetIblScaleFactorUniformName().data(), Property::Type::FLOAT),
1935 TestGraphicsController& graphics = application.GetGraphicsController();
1936 graphics.AddCustomUniforms(customUniforms);
1938 auto& gl = application.GetGlAbstraction();
1940 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1942 gResourceReadyCalled = false;
1943 model.ResourceReadySignal().Connect(&OnResourceReady);
1945 float expectIblFactor = 0.5f;
1946 model.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE, expectIblFactor);
1947 DALI_TEST_EQUALS(model.GetImageBasedLightScaleFactor(), expectIblFactor, TEST_LOCATION);
1949 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1950 application.GetScene().Add(model);
1952 application.SendNotification();
1953 application.Render();
1955 // Wait 3 task. (Load 1 model + Load 2 IBL)
1956 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1957 application.SendNotification();
1958 application.Render();
1960 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1961 DALI_TEST_EQUALS(model.GetImageBasedLightScaleFactor(), expectIblFactor, TEST_LOCATION);
1963 // Check uniform values before change material value
1964 Vector4 expectBaseColorFactor = Vector4(1.000f, 0.766f, 0.336f, 1.0f); // Defined at AnimatedCube.gltf
1965 float expectTransformValid = 0.0f; ///< Note : This value will be true when gltf have BaseColorTexture, and use KHR_texture_transform extension.
1966 float expectMaxLOD = 5.0f; ///< Note : The number of LOD what TEST_SPECULAR_TEXTURE file has is 5.
1968 tet_printf("Check uniform value result\n");
1969 DALI_TEST_EQUALS(gl.CheckUniformValue<Vector4>("uColorFactor", expectBaseColorFactor), true, TEST_LOCATION);
1970 DALI_TEST_EQUALS(gl.CheckUniformValue<float>("uBaseColorTextureTransformAvailable", expectTransformValid), true, TEST_LOCATION);
1971 DALI_TEST_EQUALS(gl.CheckUniformValue<float>(Scene3D::Loader::NodeDefinition::GetIblMaxLodUniformName().data(), expectMaxLOD), true, TEST_LOCATION);
1972 DALI_TEST_EQUALS(gl.CheckUniformValue<float>(Scene3D::Loader::NodeDefinition::GetIblScaleFactorUniformName().data(), expectIblFactor), true, TEST_LOCATION);
1974 // Change all materials in Model.
1975 expectBaseColorFactor = Color::BLUE;
1977 Scene3D::ModelNode rootModelNode = model.GetModelRoot();
1978 DALI_TEST_CHECK(rootModelNode);
1979 ApplyAllMaterialPropertyRecursively(rootModelNode, {{Dali::Scene3D::Material::Property::BASE_COLOR_FACTOR, expectBaseColorFactor}});
1981 application.SendNotification();
1982 application.Render();
1984 tet_printf("Check whether uniform values are not changed instead what we change now\n");
1985 DALI_TEST_EQUALS(gl.CheckUniformValue<Vector4>("uColorFactor", expectBaseColorFactor), true, TEST_LOCATION);
1986 DALI_TEST_EQUALS(gl.CheckUniformValue<float>("uBaseColorTextureTransformAvailable", expectTransformValid), true, TEST_LOCATION);
1987 DALI_TEST_EQUALS(gl.CheckUniformValue<float>(Scene3D::Loader::NodeDefinition::GetIblMaxLodUniformName().data(), expectMaxLOD), true, TEST_LOCATION);
1988 DALI_TEST_EQUALS(gl.CheckUniformValue<float>(Scene3D::Loader::NodeDefinition::GetIblScaleFactorUniformName().data(), expectIblFactor), true, TEST_LOCATION);
1993 int UtcDaliModelCastShadow(void)
1995 ToolkitTestApplication application;
1997 Scene3D::Model model = Scene3D::Model::New();
1998 application.GetScene().Add(model);
2000 Scene3D::ModelNode modelNode = Scene3D::ModelNode::New();
2001 model.AddModelNode(modelNode);
2003 DALI_TEST_EQUALS(model.IsShadowCasting(), true, TEST_LOCATION);
2005 DALI_TEST_EQUALS(modelNode.IsShadowCasting(), true, TEST_LOCATION);
2007 auto shadowCastingIndex = modelNode.GetPropertyIndex("uIsShadowCasting");
2008 DALI_TEST_EQUALS(modelNode.GetProperty<int>(shadowCastingIndex), 1, TEST_LOCATION);
2010 model.CastShadow(false);
2012 DALI_TEST_EQUALS(model.IsShadowCasting(), false, TEST_LOCATION);
2014 DALI_TEST_EQUALS(modelNode.IsShadowCasting(), false, TEST_LOCATION);
2016 DALI_TEST_EQUALS(modelNode.GetProperty<int>(shadowCastingIndex), 0, TEST_LOCATION);
2018 Scene3D::ModelNode modelNode2 = Scene3D::ModelNode::New();
2019 model.AddModelNode(modelNode2);
2021 DALI_TEST_EQUALS(modelNode2.IsShadowCasting(), true, TEST_LOCATION);
2023 auto shadowCastingIndex2 = modelNode2.GetPropertyIndex("uIsShadowCasting");
2024 DALI_TEST_EQUALS(modelNode2.GetProperty<int>(shadowCastingIndex2), 1, TEST_LOCATION);
2026 modelNode.CastShadow(true);
2028 DALI_TEST_EQUALS(modelNode.IsShadowCasting(), true, TEST_LOCATION);
2030 DALI_TEST_EQUALS(model.IsShadowCasting(), false, TEST_LOCATION);
2032 model.CastShadow(false);
2034 DALI_TEST_EQUALS(model.IsShadowCasting(), false, TEST_LOCATION);
2036 DALI_TEST_EQUALS(modelNode.IsShadowCasting(), false, TEST_LOCATION);
2038 DALI_TEST_EQUALS(modelNode.GetProperty<int>(shadowCastingIndex), 0, TEST_LOCATION);
2040 DALI_TEST_EQUALS(modelNode2.GetProperty<int>(shadowCastingIndex2), 0, TEST_LOCATION);
2044 int UtcDaliModelReceiveShadow(void)
2046 ToolkitTestApplication application;
2048 Scene3D::Model model = Scene3D::Model::New();
2049 application.GetScene().Add(model);
2051 Scene3D::ModelNode modelNode = Scene3D::ModelNode::New();
2052 model.AddModelNode(modelNode);
2054 DALI_TEST_EQUALS(model.IsShadowReceiving(), true, TEST_LOCATION);
2056 DALI_TEST_EQUALS(modelNode.IsShadowReceiving(), true, TEST_LOCATION);
2058 auto shadowReceivingIndex = modelNode.GetPropertyIndex("uIsShadowReceiving");
2059 DALI_TEST_EQUALS(modelNode.GetProperty<int>(shadowReceivingIndex), 1, TEST_LOCATION);
2061 model.ReceiveShadow(false);
2063 DALI_TEST_EQUALS(model.IsShadowReceiving(), false, TEST_LOCATION);
2065 DALI_TEST_EQUALS(modelNode.IsShadowReceiving(), false, TEST_LOCATION);
2067 DALI_TEST_EQUALS(modelNode.GetProperty<int>(shadowReceivingIndex), 0, TEST_LOCATION);
2069 Scene3D::ModelNode modelNode2 = Scene3D::ModelNode::New();
2070 model.AddModelNode(modelNode2);
2072 DALI_TEST_EQUALS(modelNode2.IsShadowReceiving(), true, TEST_LOCATION);
2074 auto shadowReceivingIndex2 = modelNode2.GetPropertyIndex("uIsShadowReceiving");
2075 DALI_TEST_EQUALS(modelNode2.GetProperty<int>(shadowReceivingIndex2), 1, TEST_LOCATION);
2077 modelNode.ReceiveShadow(true);
2079 DALI_TEST_EQUALS(modelNode.IsShadowReceiving(), true, TEST_LOCATION);
2081 DALI_TEST_EQUALS(model.IsShadowReceiving(), false, TEST_LOCATION);
2083 model.ReceiveShadow(false);
2085 DALI_TEST_EQUALS(model.IsShadowReceiving(), false, TEST_LOCATION);
2087 DALI_TEST_EQUALS(modelNode.IsShadowReceiving(), false, TEST_LOCATION);
2089 DALI_TEST_EQUALS(modelNode.GetProperty<int>(shadowReceivingIndex), 0, TEST_LOCATION);
2091 DALI_TEST_EQUALS(modelNode2.GetProperty<int>(shadowReceivingIndex2), 0, TEST_LOCATION);