Merge "Add Light for Scene3D" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-scene3d / utc-Dali-Light.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/actors/actor-devel.h>
21 #include <stdlib.h>
22 #include <iostream>
23
24 #include <dali-scene3d/public-api/controls/model/model.h>
25 #include <dali-scene3d/public-api/controls/scene-view/scene-view.h>
26 #include <dali-scene3d/public-api/light/light.h>
27 #include <toolkit-event-thread-callback.h>
28
29 using namespace Dali;
30 using namespace Dali::Toolkit;
31
32 void light_startup(void)
33 {
34   test_return_value = TET_UNDEF;
35 }
36
37 void light_cleanup(void)
38 {
39   test_return_value = TET_PASS;
40 }
41
42 namespace
43 {
44 const char* TEST_GLTF_FILE_NAME = TEST_RESOURCE_DIR "/BoxAnimated.gltf";
45 } // namespace
46
47 // Negative test case for a method
48 int UtcDaliLightUninitialized(void)
49 {
50   ToolkitTestApplication application;
51   tet_infoline("UtcDaliLightUninitialized");
52
53   Scene3D::Light light;
54
55   try
56   {
57     // New() must be called to create a Model or it wont be valid.
58     Actor a = Actor::New();
59     light.Add(a);
60     DALI_TEST_CHECK(false);
61   }
62   catch(Dali::DaliException& e)
63   {
64     // Tests that a negative test of an assertion succeeds
65     DALI_TEST_PRINT_ASSERT(e);
66     DALI_TEST_CHECK(!light);
67   }
68   END_TEST;
69 }
70
71 // Positive test case for a method
72 int UtcDaliLightNew(void)
73 {
74   ToolkitTestApplication application;
75   tet_infoline("UtcDaliLightNew");
76
77   Scene3D::Light light = Scene3D::Light::New();
78   DALI_TEST_CHECK(light);
79   END_TEST;
80 }
81
82 // Positive test case for a method
83 int UtcDaliLightDownCast(void)
84 {
85   ToolkitTestApplication application;
86   tet_infoline("UtcDaliLightDownCast");
87
88   Scene3D::Light light = Scene3D::Light::New();
89   BaseHandle     handle(light);
90
91   Scene3D::Light light2 = Scene3D::Light::DownCast(handle);
92   DALI_TEST_CHECK(light);
93   DALI_TEST_CHECK(light2);
94   DALI_TEST_CHECK(light == light2);
95   END_TEST;
96 }
97
98 // Positive test case for a method
99 int UtcDaliLightCopyAndAssignment(void)
100 {
101   ToolkitTestApplication application;
102
103   Scene3D::Light light = Scene3D::Light::New();
104   DALI_TEST_CHECK(light);
105
106   Scene3D::Light copy(light);
107   DALI_TEST_CHECK(light == copy);
108
109   Scene3D::Light assign;
110   DALI_TEST_CHECK(!assign);
111
112   assign = copy;
113   DALI_TEST_CHECK(assign == light);
114
115   END_TEST;
116 }
117
118 int UtcDaliLightMoveConstructor(void)
119 {
120   ToolkitTestApplication application;
121
122   Scene3D::Light light = Scene3D::Light::New();
123   DALI_TEST_EQUALS(1, light.GetBaseObject().ReferenceCount(), TEST_LOCATION);
124   light.SetProperty(Actor::Property::SENSITIVE, false);
125   DALI_TEST_CHECK(false == light.GetProperty<bool>(Actor::Property::SENSITIVE));
126
127   Scene3D::Light moved = std::move(light);
128   DALI_TEST_CHECK(moved);
129   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
130   DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
131   DALI_TEST_CHECK(!light);
132
133   END_TEST;
134 }
135
136 int UtcDaliLightMoveAssignment(void)
137 {
138   ToolkitTestApplication application;
139
140   Scene3D::Light light = Scene3D::Light::New();
141   DALI_TEST_EQUALS(1, light.GetBaseObject().ReferenceCount(), TEST_LOCATION);
142   light.SetProperty(Actor::Property::SENSITIVE, false);
143   DALI_TEST_CHECK(false == light.GetProperty<bool>(Actor::Property::SENSITIVE));
144
145   Scene3D::Light moved;
146   moved = std::move(light);
147   DALI_TEST_CHECK(moved);
148   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
149   DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
150   DALI_TEST_CHECK(!light);
151
152   END_TEST;
153 }
154
155 // For TC coverage
156 int UtcDaliLightSize(void)
157 {
158   ToolkitTestApplication application;
159
160   Scene3D::Light light = Scene3D::Light::New();
161   application.GetScene().Add(light);
162
163   application.SendNotification();
164   application.Render();
165
166   light.SetProperty(Dali::Actor::Property::SIZE, Vector3::ONE);
167   DALI_TEST_EQUALS(Vector3::ONE, light.GetProperty<Vector3>(Dali::Actor::Property::SIZE), 0.01f, TEST_LOCATION);
168   DALI_TEST_EQUALS(Vector3::ZERO, light.GetNaturalSize(), 0.01f, TEST_LOCATION);
169
170   application.SendNotification();
171   application.Render();
172
173   light.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FIXED);
174   DALI_TEST_EQUALS(ResizePolicy::FIXED, light.GetProperty<ResizePolicy::Type>(Dali::Actor::Property::WIDTH_RESIZE_POLICY), TEST_LOCATION);
175
176   application.SendNotification();
177   application.Render();
178
179   float widthForHeight = light.GetWidthForHeight(light.GetProperty<float>(Dali::Actor::Property::SIZE_HEIGHT));
180   float heightForWidth = light.GetHeightForWidth(light.GetProperty<float>(Dali::Actor::Property::SIZE_WIDTH));
181   DALI_TEST_EQUALS(0.0f, widthForHeight, 0.01f, TEST_LOCATION);
182   DALI_TEST_EQUALS(0.0f, heightForWidth, 0.01f, TEST_LOCATION);
183
184   END_TEST;
185 }
186
187 int UtcDaliLightOnScene01(void)
188 {
189   ToolkitTestApplication application;
190
191   Scene3D::Light light = Scene3D::Light::New();
192   application.GetScene().Add(light);
193
194   application.SendNotification();
195   application.Render();
196
197   // Light is added on layer when on scene
198   DALI_TEST_EQUALS(true, light.GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE), TEST_LOCATION);
199
200   application.GetScene().Remove(light);
201
202   application.SendNotification();
203   application.Render();
204
205   // Light is removed from layer when on scene
206   DALI_TEST_EQUALS(false, light.GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE), TEST_LOCATION);
207
208   END_TEST;
209 }
210
211 // Add a light on SceneView directly
212 int UtcDaliLightAdd01(void)
213 {
214   ToolkitTestApplication application;
215   Scene3D::SceneView sceneView = Scene3D::SceneView::New();
216   sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
217   sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
218   sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
219   sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
220   application.GetScene().Add(sceneView);
221
222   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
223   sceneView.Add(model);
224
225   application.SendNotification();
226   application.Render();
227   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
228   application.SendNotification();
229   application.Render();
230
231   Scene3D::Light light = Scene3D::Light::New();
232   light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
233   Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
234   sceneView.Add(light);
235
236   application.SendNotification();
237   application.Render();
238
239   Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
240   DALI_TEST_CHECK(renderer);
241
242   DALI_TEST_EQUALS(1u, sceneView.GetActivatedLightCount(), TEST_LOCATION);
243   auto countPropertyIndex = renderer.GetPropertyIndex("uLightCount");
244   DALI_TEST_CHECK(countPropertyIndex != DALI_KEY_INVALID);
245   DALI_TEST_EQUALS(1, renderer.GetProperty<int32_t>(countPropertyIndex), TEST_LOCATION);
246   auto colorPropertyIndex = renderer.GetPropertyIndex("uLightColor[0]");
247   DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 1.0f), renderer.GetCurrentProperty<Vector3>(colorPropertyIndex), 0.01f, TEST_LOCATION);
248   auto directionPropertyIndex = renderer.GetPropertyIndex("uLightDirection[0]");
249   DALI_TEST_EQUALS(Vector3(1.0f, 0.0f, 0.0f), renderer.GetCurrentProperty<Vector3>(directionPropertyIndex), 0.01f, TEST_LOCATION);
250
251   light.Enable(false);
252
253   DALI_TEST_EQUALS(0u, sceneView.GetActivatedLightCount(), TEST_LOCATION);
254   DALI_TEST_EQUALS(0, renderer.GetProperty<int32_t>(countPropertyIndex), TEST_LOCATION);
255
256   END_TEST;
257 }
258
259 // Add a light on an Actor that is child of SceneView.
260 int UtcDaliLightAdd02(void)
261 {
262   ToolkitTestApplication application;
263
264   Scene3D::SceneView sceneView = Scene3D::SceneView::New();
265   sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
266   sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
267   sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
268   sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
269   application.GetScene().Add(sceneView);
270
271   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
272   sceneView.Add(model);
273
274   application.SendNotification();
275   application.Render();
276   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
277   application.SendNotification();
278   application.Render();
279
280   Actor actor = Actor::New();
281   sceneView.Add(actor);
282
283   Scene3D::Light light = Scene3D::Light::New();
284   light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
285   Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
286   actor.Add(light);
287
288   application.SendNotification();
289   application.Render();
290
291   Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
292   DALI_TEST_CHECK(renderer);
293
294   DALI_TEST_EQUALS(1u, sceneView.GetActivatedLightCount(), TEST_LOCATION);
295   auto countPropertyIndex = renderer.GetPropertyIndex("uLightCount");
296   DALI_TEST_CHECK(countPropertyIndex != DALI_KEY_INVALID);
297   DALI_TEST_EQUALS(1, renderer.GetProperty<int32_t>(countPropertyIndex), TEST_LOCATION);
298   auto colorPropertyIndex = renderer.GetPropertyIndex("uLightColor[0]");
299   DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 1.0f), renderer.GetCurrentProperty<Vector3>(colorPropertyIndex), 0.01f, TEST_LOCATION);
300   auto directionPropertyIndex = renderer.GetPropertyIndex("uLightDirection[0]");
301   DALI_TEST_EQUALS(Vector3(1.0f, 0.0f, 0.0f), renderer.GetCurrentProperty<Vector3>(directionPropertyIndex), 0.01f, TEST_LOCATION);
302
303   light.Enable(false);
304
305   DALI_TEST_EQUALS(0u, sceneView.GetActivatedLightCount(), TEST_LOCATION);
306   DALI_TEST_EQUALS(0, renderer.GetProperty<int32_t>(countPropertyIndex), TEST_LOCATION);
307
308   END_TEST;
309 }
310
311 // Enable a light after it is added on SceneView.
312 int UtcDaliLightAdd03(void)
313 {
314   ToolkitTestApplication application;
315
316   Scene3D::SceneView sceneView = Scene3D::SceneView::New();
317   sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
318   sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
319   sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
320   sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
321   application.GetScene().Add(sceneView);
322
323   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
324   sceneView.Add(model);
325
326   application.SendNotification();
327   application.Render();
328   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
329   application.SendNotification();
330   application.Render();
331
332   Scene3D::Light light = Scene3D::Light::New();
333   light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
334   Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
335   light.Enable(false);
336   sceneView.Add(light);
337
338   application.SendNotification();
339   application.Render();
340
341   Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
342   DALI_TEST_CHECK(renderer);
343
344   DALI_TEST_EQUALS(0u, sceneView.GetActivatedLightCount(), TEST_LOCATION);
345   auto countPropertyIndex = renderer.GetPropertyIndex("uLightCount");
346   DALI_TEST_CHECK(countPropertyIndex != DALI_KEY_INVALID);
347   DALI_TEST_EQUALS(0, renderer.GetProperty<int32_t>(countPropertyIndex), TEST_LOCATION);
348
349   light.Enable(true);
350
351   application.SendNotification();
352   application.Render();
353
354   DALI_TEST_EQUALS(1u, sceneView.GetActivatedLightCount(), TEST_LOCATION);
355   DALI_TEST_EQUALS(1, renderer.GetProperty<int32_t>(countPropertyIndex), TEST_LOCATION);
356   auto colorPropertyIndex = renderer.GetPropertyIndex("uLightColor[0]");
357   DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 1.0f), renderer.GetCurrentProperty<Vector3>(colorPropertyIndex), 0.01f, TEST_LOCATION);
358   auto directionPropertyIndex = renderer.GetPropertyIndex("uLightDirection[0]");
359   DALI_TEST_EQUALS(Vector3(1.0f, 0.0f, 0.0f), renderer.GetCurrentProperty<Vector3>(directionPropertyIndex), 0.01f, TEST_LOCATION);
360
361   light.Enable(false);
362
363   application.SendNotification();
364   application.Render();
365
366   DALI_TEST_EQUALS(0u, sceneView.GetActivatedLightCount(), TEST_LOCATION);
367   DALI_TEST_EQUALS(0, renderer.GetProperty<int32_t>(countPropertyIndex), TEST_LOCATION);
368
369   END_TEST;
370 }
371
372 int UtcDaliLightAdd04(void)
373 {
374   ToolkitTestApplication application;
375
376   Scene3D::SceneView sceneView = Scene3D::SceneView::New();
377   sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
378   sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
379   sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
380   sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
381   application.GetScene().Add(sceneView);
382
383   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
384   sceneView.Add(model);
385
386   application.SendNotification();
387   application.Render();
388   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
389   application.SendNotification();
390   application.Render();
391
392   Scene3D::Light light1 = Scene3D::Light::New();
393   light1.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
394   Dali::DevelActor::LookAt(light1, Vector3(1.0f, 0.0f, 0.0f));
395   sceneView.Add(light1);
396
397   Scene3D::Light light2 = Scene3D::Light::New();
398   light2.SetProperty(Dali::Actor::Property::COLOR, Color::RED);
399   Dali::DevelActor::LookAt(light2, Vector3(0.0f, 0.0f, -1.0f));
400   sceneView.Add(light2);
401
402   application.SendNotification();
403   application.Render();
404
405   Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
406   DALI_TEST_CHECK(renderer);
407
408   DALI_TEST_EQUALS(2u, sceneView.GetActivatedLightCount(), TEST_LOCATION);
409   auto countPropertyIndex = renderer.GetPropertyIndex("uLightCount");
410   DALI_TEST_CHECK(countPropertyIndex != DALI_KEY_INVALID);
411   DALI_TEST_EQUALS(2, renderer.GetProperty<int32_t>(countPropertyIndex), TEST_LOCATION);
412   auto colorPropertyIndex1 = renderer.GetPropertyIndex("uLightColor[0]");
413   DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 1.0f), renderer.GetCurrentProperty<Vector3>(colorPropertyIndex1), 0.01f, TEST_LOCATION);
414   auto directionPropertyIndex1 = renderer.GetPropertyIndex("uLightDirection[0]");
415   DALI_TEST_EQUALS(Vector3(1.0f, 0.0f, 0.0f), renderer.GetCurrentProperty<Vector3>(directionPropertyIndex1), 0.01f, TEST_LOCATION);
416   auto colorPropertyIndex2 = renderer.GetPropertyIndex("uLightColor[1]");
417   DALI_TEST_EQUALS(Vector3(1.0f, 0.0f, 0.0f), renderer.GetCurrentProperty<Vector3>(colorPropertyIndex2), 0.01f, TEST_LOCATION);
418   auto directionPropertyIndex2 = renderer.GetPropertyIndex("uLightDirection[1]");
419   DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, -1.0f), renderer.GetCurrentProperty<Vector3>(directionPropertyIndex2), 0.01f, TEST_LOCATION);
420
421   light1.Enable(false);
422
423   application.SendNotification();
424   application.Render();
425
426   DALI_TEST_EQUALS(1u, sceneView.GetActivatedLightCount(), TEST_LOCATION);
427   DALI_TEST_EQUALS(1, renderer.GetProperty<int32_t>(countPropertyIndex), TEST_LOCATION);
428
429   // After light1 is disable, shader uniforms of lights are reordered.
430   DALI_TEST_EQUALS(Vector3(1.0f, 0.0f, 0.0f), renderer.GetCurrentProperty<Vector3>(colorPropertyIndex1), 0.01f, TEST_LOCATION);
431   DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, -1.0f), renderer.GetCurrentProperty<Vector3>(directionPropertyIndex1), 0.01f, TEST_LOCATION);
432
433   END_TEST;
434 }
435
436 // Check unactivated light in SceneView becomes activated when a light become disabled.
437 int UtcDaliLightAdd05(void)
438 {
439   ToolkitTestApplication application;
440
441   Scene3D::SceneView sceneView = Scene3D::SceneView::New();
442   sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
443   sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
444   sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
445   sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
446   application.GetScene().Add(sceneView);
447
448   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
449   sceneView.Add(model);
450
451   application.SendNotification();
452   application.Render();
453   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
454   application.SendNotification();
455   application.Render();
456
457   uint32_t                    maxLightCount = Scene3D::Light::GetMaximumEnabledLightCount();
458   std::vector<Scene3D::Light> lightList;
459   for(uint32_t i = 0; i < maxLightCount; ++i)
460   {
461     Scene3D::Light light = Scene3D::Light::New();
462     light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
463     Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
464     sceneView.Add(light);
465     lightList.push_back(light);
466   }
467
468   Scene3D::Light light2 = Scene3D::Light::New();
469   light2.SetProperty(Dali::Actor::Property::COLOR, Color::RED);
470   Dali::DevelActor::LookAt(light2, Vector3(0.0f, 0.0f, -1.0f));
471   sceneView.Add(light2);
472   lightList.push_back(light2);
473
474   application.SendNotification();
475   application.Render();
476
477   Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
478   DALI_TEST_CHECK(renderer);
479
480   std::vector<int32_t> enableAnswers;
481   enableAnswers.assign(maxLightCount, 1);
482
483   DALI_TEST_EQUALS(maxLightCount, sceneView.GetActivatedLightCount(), TEST_LOCATION);
484   auto countPropertyIndex = renderer.GetPropertyIndex("uLightCount");
485   DALI_TEST_CHECK(countPropertyIndex != DALI_KEY_INVALID);
486   DALI_TEST_EQUALS(static_cast<int32_t>(maxLightCount), renderer.GetProperty<int32_t>(countPropertyIndex), TEST_LOCATION);
487   for(uint32_t i = 0; i < maxLightCount; ++i)
488   {
489     std::string colorStringKey     = std::string("uLightColor[") + std::to_string(i) + "]";
490     auto        colorPropertyIndex = renderer.GetPropertyIndex(colorStringKey);
491     DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 1.0f), renderer.GetCurrentProperty<Vector3>(colorPropertyIndex), 0.01f, TEST_LOCATION);
492
493     std::string directionStringKey     = std::string("uLightDirection[") + std::to_string(i) + "]";
494     auto        directionPropertyIndex = renderer.GetPropertyIndex(directionStringKey);
495     DALI_TEST_EQUALS(Vector3(1.0f, 0.0f, 0.0f), renderer.GetCurrentProperty<Vector3>(directionPropertyIndex), 0.01f, TEST_LOCATION);
496   }
497
498   lightList[2].Enable(false);
499
500   application.SendNotification();
501   application.Render();
502
503   DALI_TEST_EQUALS(maxLightCount, sceneView.GetActivatedLightCount(), TEST_LOCATION);
504   DALI_TEST_EQUALS(static_cast<int32_t>(maxLightCount), renderer.GetProperty<int32_t>(countPropertyIndex), TEST_LOCATION);
505   for(uint32_t i = 0; i < maxLightCount; ++i)
506   {
507     Vector3 color, direction;
508     if(i == 2)
509     {
510       color     = Vector3(1.0f, 0.0f, 0.0f);
511       direction = Vector3(0.0f, 0.0f, -1.0f);
512     }
513     else
514     {
515       color     = Vector3(0.0f, 0.0f, 1.0f);
516       direction = Vector3(1.0f, 0.0f, 0.0f);
517     }
518     std::string colorStringKey     = std::string("uLightColor[") + std::to_string(i) + "]";
519     auto        colorPropertyIndex = renderer.GetPropertyIndex(colorStringKey);
520     DALI_TEST_EQUALS(color, renderer.GetCurrentProperty<Vector3>(colorPropertyIndex), 0.01f, TEST_LOCATION);
521
522     std::string directionStringKey     = std::string("uLightDirection[") + std::to_string(i) + "]";
523     auto        directionPropertyIndex = renderer.GetPropertyIndex(directionStringKey);
524     DALI_TEST_EQUALS(direction, renderer.GetCurrentProperty<Vector3>(directionPropertyIndex), 0.01f, TEST_LOCATION);
525   }
526
527   for(uint32_t i = 0; i < lightList.size(); ++i)
528   {
529     if(i == 2)
530     {
531       DALI_TEST_EQUALS(false, lightList[i].IsEnabled(), TEST_LOCATION);
532     }
533     else
534     {
535       DALI_TEST_EQUALS(true, lightList[i].IsEnabled(), TEST_LOCATION);
536     }
537   }
538
539   END_TEST;
540 }
541
542 int UtcDaliLightModelAddAndRemove(void)
543 {
544   ToolkitTestApplication application;
545
546   Scene3D::SceneView sceneView = Scene3D::SceneView::New();
547   sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
548   sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
549   sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
550   sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
551   application.GetScene().Add(sceneView);
552
553   Scene3D::Light light = Scene3D::Light::New();
554   light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
555   Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
556   sceneView.Add(light);
557
558   application.SendNotification();
559   application.Render();
560
561   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
562   sceneView.Add(model);
563
564   application.SendNotification();
565   application.Render();
566   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
567   application.SendNotification();
568   application.Render();
569
570   Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
571   DALI_TEST_CHECK(renderer);
572
573   DALI_TEST_EQUALS(1u, sceneView.GetActivatedLightCount(), TEST_LOCATION);
574   auto countPropertyIndex = renderer.GetPropertyIndex("uLightCount");
575   DALI_TEST_CHECK(countPropertyIndex != DALI_KEY_INVALID);
576   DALI_TEST_EQUALS(1, renderer.GetProperty<int32_t>(countPropertyIndex), TEST_LOCATION);
577
578   auto colorPropertyIndex = renderer.GetPropertyIndex("uLightColor[0]");
579   DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 1.0f), renderer.GetCurrentProperty<Vector3>(colorPropertyIndex), 0.01f, TEST_LOCATION);
580   auto directionPropertyIndex = renderer.GetPropertyIndex("uLightDirection[0]");
581   DALI_TEST_EQUALS(Vector3(1.0f, 0.0f, 0.0f), renderer.GetCurrentProperty<Vector3>(directionPropertyIndex), 0.01f, TEST_LOCATION);
582
583   DALI_TEST_EQUALS(1u, sceneView.GetActivatedLightCount(), TEST_LOCATION);
584
585   model.Unparent();
586
587   DALI_TEST_EQUALS(1u, sceneView.GetActivatedLightCount(), TEST_LOCATION);
588   DALI_TEST_EQUALS(0, renderer.GetProperty<int32_t>(countPropertyIndex), TEST_LOCATION);
589
590   END_TEST;
591 }