#include <dali-toolkit-test-suite-utils.h>
#include <dali-toolkit/dali-toolkit.h>
+#include <dali/devel-api/common/map-wrapper.h>
#include <stdlib.h>
#include <iostream>
#include <dali-scene3d/public-api/controls/model/model.h>
#include <dali-scene3d/public-api/model-components/model-node.h>
+#include <dali-scene3d/public-api/model-motion/motion-data.h>
+#include <dali-scene3d/public-api/model-motion/motion-index/blend-shape-index.h>
+#include <dali-scene3d/public-api/model-motion/motion-index/motion-transform-index.h>
+
#include <dali/devel-api/actors/camera-actor-devel.h>
using namespace Dali;
*/
const char* TEST_GLTF_FILE_NAME = TEST_RESOURCE_DIR "/AnimatedCube.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";
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);
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);
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);
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);
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);
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<int>(Dali::CameraActor::Property::PROJECTION_MODE), rhs.GetProperty<int>(Dali::CameraActor::Property::PROJECTION_MODE), TEST_LOCATION);
DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::CameraActor::Property::NEAR_PLANE_DISTANCE), rhs.GetProperty<float>(Dali::CameraActor::Property::NEAR_PLANE_DISTANCE), TEST_LOCATION);
// 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;
}
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<std::string, Scene3D::Loader::BlendShapes::Index> expectBlendShapeNames = {
+ {"Target_0", 0u},
+ {"Target_1", 1u},
+ };
+
+ std::vector<std::string> 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<Scene3D::ModelNode> 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<float>(Actor::Property::SCALE_X);
+
+ model.SetMotionData(motionData);
+
+ DALI_TEST_EQUALS(cubeModelNode.GetProperty<float>(Actor::Property::SCALE_X), expectScaleX, TEST_LOCATION);
+ DALI_TEST_EQUALS(cubeModelNode.GetProperty<float>(Actor::Property::SCALE_Y), 2.0f, TEST_LOCATION);
+ DALI_TEST_EQUALS(cubeModelNode.GetProperty<float>(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<float>(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<float>(propertyIndex), 1.0f, TEST_LOCATION);
+
+ END_TEST;
+}