X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-scene3d%2Futc-Dali-Model.cpp;h=3ba8059479d99d15cbee9de2dd3f68713b3db872;hb=416c967b32519657cc2bb301c3087534e59e6af6;hp=c219f9379c6dd16722aec08eed97e586caf094d2;hpb=2f746c0479e119947e13e01a5189654d5ddc7756;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/automated-tests/src/dali-scene3d/utc-Dali-Model.cpp b/automated-tests/src/dali-scene3d/utc-Dali-Model.cpp index c219f93..3ba8059 100644 --- a/automated-tests/src/dali-scene3d/utc-Dali-Model.cpp +++ b/automated-tests/src/dali-scene3d/utc-Dali-Model.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,16 +17,25 @@ #include #include +#include +#include #include #include #include #include +#include #include #include #include +#include +#include +#include + +#include + #include using namespace Dali; @@ -52,8 +61,12 @@ const bool DEFAULT_MODEL_CHILDREN_FOCUSABLE = false; * Take from https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/AnimatedCube */ const char* TEST_GLTF_FILE_NAME = TEST_RESOURCE_DIR "/AnimatedCube.gltf"; +const char* TEST_GLTF_FILE_NAME_SAME_FILE = TEST_RESOURCE_DIR "/AnimatedCube2.gltf"; +const char* TEST_GLTF_FILE_NAME_DIFF_META_FILE = TEST_RESOURCE_DIR "/AnimatedCube3.gltf"; const char* TEST_GLTF_ANIMATION_TEST_FILE_NAME = TEST_RESOURCE_DIR "/animationTest.gltf"; +const char* TEST_GLTF_EXTRAS_FILE_NAME = TEST_RESOURCE_DIR "/AnimatedMorphCubeAnimateNonZeroFrame.gltf"; const char* TEST_GLTF_MULTIPLE_PRIMITIVE_FILE_NAME = TEST_RESOURCE_DIR "/simpleMultiplePrimitiveTest.gltf"; +const char* TEST_GLTF_MORPH_FILE_NAME = TEST_RESOURCE_DIR "/AnimatedMorphCube.gltf"; const char* TEST_DLI_FILE_NAME = TEST_RESOURCE_DIR "/arc.dli"; const char* TEST_DLI_EXERCISE_FILE_NAME = TEST_RESOURCE_DIR "/exercise.dli"; @@ -62,7 +75,7 @@ const char* TEST_DLI_EXERCISE_FILE_NAME = TEST_RESOURCE_DIR "/exercis * These textures are based off version of Wave engine sample * Take from https://github.com/WaveEngine/Samples * - * Copyright (c) 2023 Wave Coorporation + * Copyright (c) 2024 Wave Coorporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -111,6 +124,39 @@ void OnResourceReady(Control control) gResourceReadyCalled = true; } +void ApplyAllMaterialPropertyRecursively(Scene3D::ModelNode modelNode, const std::vector& materialPropertyValues) +{ + if(!modelNode) + { + return; + } + + for(uint32_t primitiveIndex = 0u; primitiveIndex < modelNode.GetModelPrimitiveCount(); ++primitiveIndex) + { + Scene3D::ModelPrimitive primitive = modelNode.GetModelPrimitive(primitiveIndex); + if(primitive) + { + Scene3D::Material material = primitive.GetMaterial(); + if(material) + { + for(const auto& keyValuePair : materialPropertyValues) + { + if(keyValuePair.first.type == Property::Key::Type::INDEX) + { + material.SetProperty(keyValuePair.first.indexKey, keyValuePair.second); + } + } + } + } + } + + for(uint32_t childIndex = 0u; childIndex < modelNode.GetChildCount(); ++childIndex) + { + Scene3D::ModelNode childNode = Scene3D::ModelNode::DownCast(modelNode.GetChildAt(childIndex)); + ApplyAllMaterialPropertyRecursively(childNode, materialPropertyValues); + } +} + } // namespace // Negative test case for a method @@ -168,6 +214,133 @@ int UtcDaliModelNewP2(void) END_TEST; } +int UtcDaliModelNewSameModelUrlCached(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliModelNew with same model"); + + // Set up trace debug + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& textureTrace = gl.GetTextureTrace(); + textureTrace.Enable(true); + + Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME); + DALI_TEST_CHECK(model); + Scene3D::Model model2 = Scene3D::Model::New(TEST_GLTF_FILE_NAME); + DALI_TEST_CHECK(model2); + + application.GetScene().Add(model); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + tet_printf("Test if there is at least 1 texture.\n"); + int expectTextureCount = textureTrace.CountMethod("GenTextures"); + DALI_TEST_GREATER(expectTextureCount, 0, TEST_LOCATION); + + application.GetScene().Add(model2); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + tet_printf("Test if we reuse cached texture or not.\n"); + int currentTextureCount = textureTrace.CountMethod("GenTextures"); + DALI_TEST_EQUALS(currentTextureCount, expectTextureCount, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + END_TEST; +} + +int UtcDaliModelNewSameResourceUrlCached01(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliModelNew with difference url but same model"); + + // Set up trace debug + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& textureTrace = gl.GetTextureTrace(); + textureTrace.Enable(true); + textureTrace.EnableLogging(true); + + Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME); + DALI_TEST_CHECK(model); + Scene3D::Model model2 = Scene3D::Model::New(TEST_GLTF_FILE_NAME_SAME_FILE); // Difference model that use same Images. + DALI_TEST_CHECK(model2); + Scene3D::Model model3 = Scene3D::Model::New(TEST_GLTF_FILE_NAME_DIFF_META_FILE); // Difference model that use same Images, but difference metadata. + DALI_TEST_CHECK(model3); + + application.GetScene().Add(model); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + tet_printf("Test if there is at least 1 texture.\n"); + int expectTextureCount = textureTrace.CountMethod("GenTextures"); + DALI_TEST_GREATER(expectTextureCount, 0, TEST_LOCATION); + + application.GetScene().Add(model2); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + tet_printf("Test if we reuse cached texture or not.\n"); + int currentTextureCount = textureTrace.CountMethod("GenTextures"); + DALI_TEST_EQUALS(currentTextureCount, expectTextureCount, TEST_LOCATION); + + application.GetScene().Add(model3); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + tet_printf("Test if we don't reuse cached texture, due to the metadata difference.\n"); + currentTextureCount = textureTrace.CountMethod("GenTextures"); + DALI_TEST_GREATER(currentTextureCount, expectTextureCount, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + END_TEST; +} + +int UtcDaliModelNewSameResourceUrlCached02(void) +{ + /// Make we don't use mutiple thread loading for this UTC. + EnvironmentVariable::SetTestEnvironmentVariable("DALI_ASYNC_MANAGER_THREAD_POOL_SIZE", "1"); + EnvironmentVariable::SetTestEnvironmentVariable("DALI_ASYNC_MANAGER_LOW_PRIORITY_THREAD_POOL_SIZE", "1"); + + ToolkitTestApplication application; + tet_infoline(" UtcDaliModelNew with difference url but same model"); + + Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME); + DALI_TEST_CHECK(model); + Scene3D::Model model2 = Scene3D::Model::New(TEST_GLTF_FILE_NAME_SAME_FILE); + DALI_TEST_CHECK(model2); + + application.GetScene().Add(model); + application.GetScene().Add(model2); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION); + application.SendNotification(); + application.Render(); + + END_TEST; +} + // Positive test case for a method int UtcDaliModelDownCast(void) { @@ -417,10 +590,10 @@ int UtcDaliModelSetImageBasedLightSource01(void) DALI_TEST_CHECK(renderer); TextureSet textureSet = renderer.GetTextures(); - DALI_TEST_EQUALS(textureSet.GetTextureCount(), 9u, TEST_LOCATION); + DALI_TEST_EQUALS(textureSet.GetTextureCount(), 10u, TEST_LOCATION); - Texture diffuseTexture = textureSet.GetTexture(7u); - Texture specularTexture = textureSet.GetTexture(8u); + Texture diffuseTexture = textureSet.GetTexture(8u); + Texture specularTexture = textureSet.GetTexture(9u); gResourceReadyCalled = false; DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION); @@ -436,8 +609,8 @@ int UtcDaliModelSetImageBasedLightSource01(void) DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION); TextureSet newTextureSet = renderer.GetTextures(); - Texture newDiffuseTexture = newTextureSet.GetTexture(7u); - Texture newSpecularTexture = newTextureSet.GetTexture(8u); + Texture newDiffuseTexture = newTextureSet.GetTexture(8u); + Texture newSpecularTexture = newTextureSet.GetTexture(9u); DALI_TEST_NOT_EQUALS(diffuseTexture, newDiffuseTexture, 0.0f, TEST_LOCATION); DALI_TEST_NOT_EQUALS(specularTexture, newSpecularTexture, 0.0f, TEST_LOCATION); @@ -474,16 +647,16 @@ int UtcDaliModelSetImageBasedLightSource02(void) DALI_TEST_CHECK(renderer); TextureSet textureSet = renderer.GetTextures(); - DALI_TEST_EQUALS(textureSet.GetTextureCount(), 9u, TEST_LOCATION); + DALI_TEST_EQUALS(textureSet.GetTextureCount(), 10u, TEST_LOCATION); - Texture diffuseTexture = textureSet.GetTexture(7u); - Texture specularTexture = textureSet.GetTexture(8u); + Texture diffuseTexture = textureSet.GetTexture(8u); + Texture specularTexture = textureSet.GetTexture(9u); // if url is empty, loading is not requested. model.SetImageBasedLightSource("", ""); - Texture newDiffuseTexture = textureSet.GetTexture(7u); - Texture newSpecularTexture = textureSet.GetTexture(8u); + Texture newDiffuseTexture = textureSet.GetTexture(8u); + Texture newSpecularTexture = textureSet.GetTexture(9u); DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION); DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION); @@ -518,10 +691,10 @@ int UtcDaliModelSetImageBasedLightSource03(void) DALI_TEST_CHECK(renderer); TextureSet textureSet = renderer.GetTextures(); - DALI_TEST_EQUALS(textureSet.GetTextureCount(), 9u, TEST_LOCATION); + DALI_TEST_EQUALS(textureSet.GetTextureCount(), 10u, TEST_LOCATION); - Texture diffuseTexture = textureSet.GetTexture(7u); - Texture specularTexture = textureSet.GetTexture(8u); + Texture diffuseTexture = textureSet.GetTexture(8u); + Texture specularTexture = textureSet.GetTexture(9u); gResourceReadyCalled = false; DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION); @@ -536,8 +709,8 @@ int UtcDaliModelSetImageBasedLightSource03(void) DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION); - Texture newDiffuseTexture = textureSet.GetTexture(7u); - Texture newSpecularTexture = textureSet.GetTexture(8u); + Texture newDiffuseTexture = textureSet.GetTexture(8u); + Texture newSpecularTexture = textureSet.GetTexture(9u); DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION); DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION); @@ -1135,8 +1308,7 @@ int UtcDaliModelCameraGenerate02(void) CameraActor appliedCamera; DALI_TEST_EQUALS(model.ApplyCamera(0u, appliedCamera), false, TEST_LOCATION); // Cannot apply into empty camera. - auto CompareCameraProperties = [](CameraActor lhs, CameraActor rhs, const char* location) - { + auto CompareCameraProperties = [](CameraActor lhs, CameraActor rhs, const char* location) { DALI_TEST_EQUALS(lhs.GetProperty(Dali::CameraActor::Property::PROJECTION_MODE), rhs.GetProperty(Dali::CameraActor::Property::PROJECTION_MODE), TEST_LOCATION); DALI_TEST_EQUALS(lhs.GetProperty(Dali::CameraActor::Property::NEAR_PLANE_DISTANCE), rhs.GetProperty(Dali::CameraActor::Property::NEAR_PLANE_DISTANCE), TEST_LOCATION); @@ -1258,6 +1430,72 @@ int UtcDaliModelResourceReady(void) END_TEST; } +int UtcDaliModelResourceReady02(void) +{ + tet_infoline("Test model load successfully even if shader language version is low\n"); + ToolkitTestApplication application; + + auto originalShaderVersion = application.GetGlAbstraction().GetShaderLanguageVersion(); + + // Change the shader language version forcely! + application.GetGlAbstraction().mShaderLanguageVersion = 200; + + try + { + gOnRelayoutCallBackCalled = false; + gResourceReadyCalled = false; + Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_MORPH_FILE_NAME); + model.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f)); + model.OnRelayoutSignal().Connect(OnRelayoutCallback); + model.ResourceReadySignal().Connect(OnResourceReady); + DALI_TEST_EQUALS(model.IsResourceReady(), false, TEST_LOCATION); + + // Sanity check + DALI_TEST_CHECK(!gOnRelayoutCallBackCalled); + DALI_TEST_CHECK(!gResourceReadyCalled); + + application.GetScene().Add(model); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, false, TEST_LOCATION); + DALI_TEST_EQUALS(model.IsResourceReady(), true, TEST_LOCATION); + DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION); + + // Change material information, for line coverage. + auto modelNode = model.FindChildModelNodeByName("AnimatedMorphCube"); + DALI_TEST_CHECK(modelNode); + DALI_TEST_GREATER(modelNode.GetModelPrimitiveCount(), 0u, TEST_LOCATION); + auto modelPrimitive = modelNode.GetModelPrimitive(0u); + DALI_TEST_CHECK(modelPrimitive); + auto material = modelPrimitive.GetMaterial(); + DALI_TEST_CHECK(material); + + auto originBaseColorFactor = material.GetProperty(Dali::Scene3D::Material::Property::BASE_COLOR_FACTOR); + auto expectBaseColorFactor = Vector4(originBaseColorFactor.r + 0.05f, originBaseColorFactor.g - 0.05f, originBaseColorFactor.b, originBaseColorFactor.a); + material.SetProperty(Dali::Scene3D::Material::Property::BASE_COLOR_FACTOR, expectBaseColorFactor); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(material.GetProperty(Dali::Scene3D::Material::Property::BASE_COLOR_FACTOR), expectBaseColorFactor, TEST_LOCATION); + } + catch(...) + { + DALI_TEST_CHECK(false); + } + + // Revert shader version. We should revert it even if UTC failed. + application.GetGlAbstraction().mShaderLanguageVersion = originalShaderVersion; + + END_TEST; +} + int UtcDaliModelResourceCacheCheck(void) { ToolkitTestApplication application; @@ -1329,7 +1567,7 @@ int UtcDaliModelResourceCacheCheck(void) application.SendNotification(); application.Render(); - DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION); application.SendNotification(); application.Render(); @@ -1346,16 +1584,16 @@ int UtcDaliModelResourceCacheCheck(void) // but all the other textures are still the same TextureSet textureSet2 = renderer2.GetTextures(); TextureSet textureSet3 = renderer3.GetTextures(); - DALI_TEST_EQUALS(textureSet2.GetTextureCount(), 9u, TEST_LOCATION); - DALI_TEST_EQUALS(textureSet3.GetTextureCount(), 9u, TEST_LOCATION); + DALI_TEST_EQUALS(textureSet2.GetTextureCount(), 10u, TEST_LOCATION); + DALI_TEST_EQUALS(textureSet3.GetTextureCount(), 10u, TEST_LOCATION); for(uint32_t i = 0; i < 7u; i++) { DALI_TEST_EQUALS(textureSet2.GetTexture(i), textureSet3.GetTexture(i), TEST_LOCATION); } - DALI_TEST_NOT_EQUALS(textureSet2.GetTexture(7u), textureSet3.GetTexture(7u), 0.0f, TEST_LOCATION); - DALI_TEST_NOT_EQUALS(textureSet2.GetTexture(8u), textureSet3.GetTexture(8u), 0.0f, TEST_LOCATION); + DALI_TEST_NOT_EQUALS(textureSet2.GetTexture(8u), textureSet3.GetTexture(7u), 0.0f, TEST_LOCATION); + DALI_TEST_NOT_EQUALS(textureSet2.GetTexture(9u), textureSet3.GetTexture(8u), 0.0f, TEST_LOCATION); END_TEST; } @@ -1488,3 +1726,266 @@ int UtcDaliModelSizeChange2(void) END_TEST; } + +int UtcDaliModelRetrieveBlendShapeNames(void) +{ + tet_infoline(" UtcDaliModelRetrieveBlendShapeByName."); + + ToolkitTestApplication application; + + Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_EXTRAS_FILE_NAME); + model.SetProperty(Dali::Actor::Property::SIZE, Vector3(300, 300, 300)); + application.GetScene().Add(model); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(model.GetChildCount(), 1u, TEST_LOCATION); + + // Get target ModelNode that has extras + Scene3D::ModelNode expectNode = model.FindChildModelNodeByName("AnimatedMorphCube"); + + // Pair of expected blend shape index from expectNode. + std::map expectBlendShapeNames = { + {"Target_0", 0u}, + {"Target_1", 1u}, + }; + + std::vector blendShapeNameList; + model.RetrieveBlendShapeNames(blendShapeNameList); + + DALI_TEST_EQUALS(blendShapeNameList.size(), expectBlendShapeNames.size(), TEST_LOCATION); + for(auto i = 0u; i < blendShapeNameList.size(); ++i) + { + const auto& name = blendShapeNameList[i]; + tet_printf("Check retrieved blendshape name : %s\n", name.c_str()); + + const auto& iter = expectBlendShapeNames.find(name); + DALI_TEST_CHECK(iter != expectBlendShapeNames.end()); + + std::vector nodeList; + model.RetrieveModelNodesByBlendShapeName(name, nodeList); + DALI_TEST_EQUALS(nodeList.size(), 1u, TEST_LOCATION); + DALI_TEST_EQUALS(nodeList[0], expectNode, TEST_LOCATION); + DALI_TEST_EQUALS(nodeList[0].GetBlendShapeIndexByName(name), iter->second, TEST_LOCATION); + } + + END_TEST; +} + +int UtcDaliModelGenerateMotionDataAnimation01(void) +{ + ToolkitTestApplication application; + + Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_MORPH_FILE_NAME); + model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50)); + application.GetScene().Add(model); + + gResourceReadyCalled = false; + model.ResourceReadySignal().Connect(&OnResourceReady); + DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION); + + KeyFrames floatKeyFrames = KeyFrames::New(); + floatKeyFrames.Add(0.0f, 1.0f); + floatKeyFrames.Add(1.0f, 0.5f); + + float duration = 3.0f; + Scene3D::MotionData motionData = Scene3D::MotionData::New(duration); + motionData.Add(Scene3D::MotionTransformIndex::New("AnimatedMorphCube", Scene3D::MotionTransformIndex::TransformType::SCALE_Y), Scene3D::MotionValue::New(2.0f)); + motionData.Add(Scene3D::MotionTransformIndex::New("AnimatedMorphCube", Scene3D::MotionTransformIndex::TransformType::SCALE_Z), Scene3D::MotionValue::New(floatKeyFrames)); + motionData.Add(Scene3D::BlendShapeIndex::New("AnimatedMorphCube", 0), Scene3D::MotionValue::New(0.5f)); + motionData.Add(Scene3D::BlendShapeIndex::New("AnimatedMorphCube", 1), Scene3D::MotionValue::New(floatKeyFrames)); + + Animation generatedAnimation = model.GenerateMotionDataAnimation(motionData); + DALI_TEST_CHECK(generatedAnimation); + DALI_TEST_EQUALS(generatedAnimation.GetDuration(), duration, TEST_LOCATION); + + Scene3D::MotionData invalidMotionData = Scene3D::MotionData::New(duration); + invalidMotionData.Add(Scene3D::MotionTransformIndex::New("NotAnimatedMorphCube", Scene3D::MotionTransformIndex::TransformType::SCALE_Y), Scene3D::MotionValue::New(2.0f)); + invalidMotionData.Add(Scene3D::MotionTransformIndex::New("NotAnimatedMorphCube", Scene3D::MotionTransformIndex::TransformType::SCALE_Z), Scene3D::MotionValue::New(floatKeyFrames)); + invalidMotionData.Add(Scene3D::BlendShapeIndex::New("NotAnimatedMorphCube", 0), Scene3D::MotionValue::New(0.5f)); + invalidMotionData.Add(Scene3D::BlendShapeIndex::New("NotAnimatedMorphCube", 1), Scene3D::MotionValue::New(floatKeyFrames)); + + generatedAnimation = model.GenerateMotionDataAnimation(invalidMotionData); + DALI_TEST_CHECK(!generatedAnimation); // Animation should be empty if motion data have invalid index. + + END_TEST; +} + +int UtcDaliModelSetMotionData(void) +{ + ToolkitTestApplication application; + + Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_MORPH_FILE_NAME); + model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50)); + application.GetScene().Add(model); + + gResourceReadyCalled = false; + model.ResourceReadySignal().Connect(&OnResourceReady); + DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION); + + KeyFrames floatKeyFrames = KeyFrames::New(); + floatKeyFrames.Add(0.0f, 1.0f); + floatKeyFrames.Add(1.0f, 0.5f); + + float duration = 3.0f; + Scene3D::MotionData motionData = Scene3D::MotionData::New(duration); + motionData.Add(Scene3D::MotionTransformIndex::New("AnimatedMorphCube", Scene3D::MotionTransformIndex::TransformType::SCALE_Y), Scene3D::MotionValue::New(2.0f)); + motionData.Add(Scene3D::MotionTransformIndex::New("AnimatedMorphCube", Scene3D::MotionTransformIndex::TransformType::SCALE_Z), Scene3D::MotionValue::New(floatKeyFrames)); + motionData.Add(Scene3D::BlendShapeIndex::New("AnimatedMorphCube", 0), Scene3D::MotionValue::New(0.5f)); + motionData.Add(Scene3D::BlendShapeIndex::New("AnimatedMorphCube", 1), Scene3D::MotionValue::New(floatKeyFrames)); + + auto cubeModelNode = model.FindChildModelNodeByName("AnimatedMorphCube"); + + float expectScaleX = cubeModelNode.GetProperty(Actor::Property::SCALE_X); + + model.SetMotionData(motionData); + + DALI_TEST_EQUALS(cubeModelNode.GetProperty(Actor::Property::SCALE_X), expectScaleX, TEST_LOCATION); + DALI_TEST_EQUALS(cubeModelNode.GetProperty(Actor::Property::SCALE_Y), 2.0f, TEST_LOCATION); + DALI_TEST_EQUALS(cubeModelNode.GetProperty(Actor::Property::SCALE_Z), 0.5f, TEST_LOCATION); ///< Last value of keyframes + + END_TEST; +} + +int UtcDaliModelBlendShapeMotionDataByName(void) +{ + ToolkitTestApplication application; + + Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_EXTRAS_FILE_NAME); + model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50)); + application.GetScene().Add(model); + + gResourceReadyCalled = false; + model.ResourceReadySignal().Connect(&OnResourceReady); + DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION); + + KeyFrames floatKeyFrames = KeyFrames::New(); + floatKeyFrames.Add(0.0f, 0.5f); + floatKeyFrames.Add(1.0f, 1.0f); + + float duration = 3.0f; + Scene3D::MotionData motionData = Scene3D::MotionData::New(duration); + motionData.Add(Scene3D::BlendShapeIndex::New("Target_0"), Scene3D::MotionValue::New(0.5f)); + motionData.Add(Scene3D::BlendShapeIndex::New("Target_1"), Scene3D::MotionValue::New(floatKeyFrames)); + + Animation generatedAnimation = model.GenerateMotionDataAnimation(motionData); + DALI_TEST_CHECK(generatedAnimation); + DALI_TEST_EQUALS(generatedAnimation.GetDuration(), duration, TEST_LOCATION); + + model.SetMotionData(motionData); + + // Get target ModelNode that has extras + Scene3D::ModelNode expectNode = model.FindChildModelNodeByName("AnimatedMorphCube"); + auto propertyIndex = expectNode.GetPropertyIndex(motionData.GetIndex(0u).GetPropertyName(expectNode)); + + DALI_TEST_CHECK(propertyIndex != Property::INVALID_INDEX); + DALI_TEST_EQUALS(expectNode.GetProperty(propertyIndex), 0.5f, TEST_LOCATION); + + propertyIndex = expectNode.GetPropertyIndex(motionData.GetIndex(1u).GetPropertyName(expectNode)); + DALI_TEST_CHECK(propertyIndex != Property::INVALID_INDEX); + DALI_TEST_EQUALS(expectNode.GetProperty(propertyIndex), 1.0f, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliModelMaterialUniformChange(void) +{ + ToolkitTestApplication application; + + static std::vector customUniforms = + { + UniformData("uColorFactor", Property::Type::VECTOR4), + UniformData("uBaseColorTextureTransformAvailable", Property::Type::FLOAT), + UniformData(Scene3D::Loader::NodeDefinition::GetIblMaxLodUniformName().data(), Property::Type::FLOAT), + UniformData(Scene3D::Loader::NodeDefinition::GetIblScaleFactorUniformName().data(), Property::Type::FLOAT), + }; + + TestGraphicsController& graphics = application.GetGraphicsController(); + graphics.AddCustomUniforms(customUniforms); + + auto& gl = application.GetGlAbstraction(); + + Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME); + + gResourceReadyCalled = false; + model.ResourceReadySignal().Connect(&OnResourceReady); + + float expectIblFactor = 0.5f; + model.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE, expectIblFactor); + DALI_TEST_EQUALS(model.GetImageBasedLightScaleFactor(), expectIblFactor, TEST_LOCATION); + + DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION); + application.GetScene().Add(model); + + application.SendNotification(); + application.Render(); + + // Wait 3 task. (Load 1 model + Load 2 IBL) + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION); + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION); + DALI_TEST_EQUALS(model.GetImageBasedLightScaleFactor(), expectIblFactor, TEST_LOCATION); + + // Check uniform values before change material value + Vector4 expectBaseColorFactor = Vector4(1.000f, 0.766f, 0.336f, 1.0f); // Defined at AnimatedCube.gltf + float expectTransformValid = 0.0f; ///< Note : This value will be true when gltf have BaseColorTexture, and use KHR_texture_transform extension. + float expectMaxLOD = 5.0f; ///< Note : The number of LOD what TEST_SPECULAR_TEXTURE file has is 5. + + tet_printf("Check uniform value result\n"); + DALI_TEST_EQUALS(gl.CheckUniformValue("uColorFactor", expectBaseColorFactor), true, TEST_LOCATION); + DALI_TEST_EQUALS(gl.CheckUniformValue("uBaseColorTextureTransformAvailable", expectTransformValid), true, TEST_LOCATION); + DALI_TEST_EQUALS(gl.CheckUniformValue(Scene3D::Loader::NodeDefinition::GetIblMaxLodUniformName().data(), expectMaxLOD), true, TEST_LOCATION); + DALI_TEST_EQUALS(gl.CheckUniformValue(Scene3D::Loader::NodeDefinition::GetIblScaleFactorUniformName().data(), expectIblFactor), true, TEST_LOCATION); + + // Change all materials in Model. + expectBaseColorFactor = Color::BLUE; + + Scene3D::ModelNode rootModelNode = model.GetModelRoot(); + DALI_TEST_CHECK(rootModelNode); + ApplyAllMaterialPropertyRecursively(rootModelNode, {{Dali::Scene3D::Material::Property::BASE_COLOR_FACTOR, expectBaseColorFactor}}); + + application.SendNotification(); + application.Render(); + + tet_printf("Check whether uniform values are not changed instead what we change now\n"); + DALI_TEST_EQUALS(gl.CheckUniformValue("uColorFactor", expectBaseColorFactor), true, TEST_LOCATION); + DALI_TEST_EQUALS(gl.CheckUniformValue("uBaseColorTextureTransformAvailable", expectTransformValid), true, TEST_LOCATION); + DALI_TEST_EQUALS(gl.CheckUniformValue(Scene3D::Loader::NodeDefinition::GetIblMaxLodUniformName().data(), expectMaxLOD), true, TEST_LOCATION); + DALI_TEST_EQUALS(gl.CheckUniformValue(Scene3D::Loader::NodeDefinition::GetIblScaleFactorUniformName().data(), expectIblFactor), true, TEST_LOCATION); + + END_TEST; +} \ No newline at end of file