/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
ShaderDefinitionFactory sdf;
sdf.SetResources(ctx.resources);
+ InitializeGltfLoader();
DALI_TEST_THROW(LoadGltfScene("non-existent.gltf", sdf, ctx.loadResult),
std::runtime_error,
ExceptionMessageStartsWith{"Failed to load"});
ShaderDefinitionFactory sdf;
sdf.SetResources(ctx.resources);
+ InitializeGltfLoader();
DALI_TEST_THROW(LoadGltfScene(TEST_RESOURCE_DIR "/invalid.gltf", sdf, ctx.loadResult),
std::runtime_error,
ExceptionMessageStartsWith{"Failed to parse"});
ShaderDefinitionFactory sdf;
sdf.SetResources(ctx.resources);
+ InitializeGltfLoader();
LoadGltfScene(TEST_RESOURCE_DIR "/AnimatedCube.gltf", sdf, ctx.loadResult);
DALI_TEST_EQUAL(1u, ctx.scene.GetRoots().size());
auto& materials = ctx.resources.mMaterials;
DALI_TEST_EQUAL(2u, materials.size());
const MaterialDefinition materialGroundTruth[]{
- {MaterialDefinition::ALBEDO | MaterialDefinition::EMISSIVE | MaterialDefinition::OCCLUSION |
- MaterialDefinition::NORMAL | MaterialDefinition::SPECULAR | MaterialDefinition::SPECULAR_COLOR |
- (0x80 << MaterialDefinition::ALPHA_CUTOFF_SHIFT),
- 0,
- Color::WHITE,
- 1.f,
- 0.f,
- Vector4(1.000, 0.766, 0.336, 1.0),
- 1.f,
- 1.f,
- Vector3(0.2, 0.1, 0.0),
- 0.0f,
- 0.5f,
- Vector3(0, 0, 1),
- true,
- false,
- true,
- false,
- true,
- true,
- {
- {MaterialDefinition::ALBEDO,
- {"AnimatedCube_BaseColor.png",
- SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT),
- ImageDimensions(256, 256),
- SamplingMode::BOX_THEN_NEAREST}},
- {MaterialDefinition::NORMAL,
- {"AnimatedCube_BaseColor.png",
- SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT),
- ImageDimensions(256, 256),
- SamplingMode::BOX_THEN_NEAREST}},
- {MaterialDefinition::OCCLUSION,
- {"AnimatedCube_BaseColor.png",
- SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT),
- ImageDimensions(256, 256),
- SamplingMode::BOX_THEN_NEAREST}},
- {MaterialDefinition::EMISSIVE,
- {"AnimatedCube_BaseColor.png",
- SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT),
- ImageDimensions(256, 256),
- SamplingMode::BOX_THEN_NEAREST}},
- {MaterialDefinition::SPECULAR,
- {"AnimatedCube_BaseColor.png",
- SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT),
- ImageDimensions(256, 256),
- SamplingMode::BOX_THEN_NEAREST}},
- {MaterialDefinition::SPECULAR_COLOR,
- {"AnimatedCube_BaseColor.png",
- SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT),
- ImageDimensions(256, 256),
- SamplingMode::BOX_THEN_NEAREST}},
- }},
- {MaterialDefinition::ALBEDO | MaterialDefinition::METALLIC | MaterialDefinition::ROUGHNESS |
- MaterialDefinition::EMISSIVE | MaterialDefinition::OCCLUSION |
- MaterialDefinition::NORMAL | MaterialDefinition::GLTF_CHANNELS,
- 0,
- Color::WHITE,
- 1.f,
- 0.f,
- Vector4(1.000, 0.766, 0.336, 1.0),
- 1.f,
- 1.f,
- Vector3(0.2, 0.1, 0.0),
- 0.04f,
- 1.0f,
- Vector3::ONE,
- true,
- true,
- true,
- false,
- true,
- false,
- {
- {MaterialDefinition::ALBEDO,
- {"AnimatedCube_BaseColor.png",
- SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT),
- ImageDimensions(256, 256),
- SamplingMode::BOX_THEN_NEAREST}},
- {MaterialDefinition::METALLIC | MaterialDefinition::ROUGHNESS | MaterialDefinition::GLTF_CHANNELS,
- {"AnimatedCube_MetallicRoughness.png",
- SamplerFlags::Encode(FilterMode::NEAREST_MIPMAP_LINEAR, FilterMode::NEAREST, WrapMode::CLAMP_TO_EDGE, WrapMode::MIRRORED_REPEAT),
- ImageDimensions(256, 256),
- SamplingMode::NEAREST}},
- {MaterialDefinition::NORMAL,
- {"AnimatedCube_BaseColor.png",
- SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT),
- ImageDimensions(256, 256),
- SamplingMode::BOX_THEN_NEAREST}},
- {MaterialDefinition::OCCLUSION,
- {"AnimatedCube_BaseColor.png",
- SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT),
- ImageDimensions(256, 256),
- SamplingMode::BOX_THEN_NEAREST}},
- {MaterialDefinition::EMISSIVE,
- {"AnimatedCube_BaseColor.png",
- SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT),
- ImageDimensions(256, 256),
- SamplingMode::BOX_THEN_NEAREST}},
- }},
+ {
+ nullptr,
+ MaterialDefinition::ALBEDO | MaterialDefinition::EMISSIVE | MaterialDefinition::OCCLUSION |
+ MaterialDefinition::NORMAL | MaterialDefinition::SPECULAR | MaterialDefinition::SPECULAR_COLOR |
+ (0x80 << MaterialDefinition::ALPHA_CUTOFF_SHIFT),
+ 0,
+ Color::WHITE,
+ 1.f,
+ 0.f,
+ Vector4(1.000, 0.766, 0.336, 1.0),
+ 1.f,
+ 1.f,
+ Vector3(0.2, 0.1, 0.0),
+ 0.0f,
+ 0.5f,
+ Vector3(0, 0, 1),
+ true,
+ false,
+ true,
+ false,
+ true,
+ true,
+ {
+ {
+ MaterialDefinition::ALBEDO,
+ {
+ "AnimatedCube_BaseColor.png",
+ SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT),
+ ImageDimensions(256, 256),
+ SamplingMode::BOX_THEN_NEAREST,
+ },
+ },
+ {
+ MaterialDefinition::NORMAL,
+ {
+ "AnimatedCube_BaseColor.png",
+ SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT),
+ ImageDimensions(256, 256),
+ SamplingMode::BOX_THEN_NEAREST,
+ },
+ },
+ {
+ MaterialDefinition::OCCLUSION,
+ {
+ "AnimatedCube_BaseColor.png",
+ SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT),
+ ImageDimensions(256, 256),
+ SamplingMode::BOX_THEN_NEAREST,
+ },
+ },
+ {
+ MaterialDefinition::EMISSIVE,
+ {
+ "AnimatedCube_BaseColor.png",
+ SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT),
+ ImageDimensions(256, 256),
+ SamplingMode::BOX_THEN_NEAREST,
+ },
+ },
+ {
+ MaterialDefinition::SPECULAR,
+ {
+ "AnimatedCube_BaseColor.png",
+ SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT),
+ ImageDimensions(256, 256),
+ SamplingMode::BOX_THEN_NEAREST,
+ },
+ },
+ {
+ MaterialDefinition::SPECULAR_COLOR,
+ {
+ "AnimatedCube_BaseColor.png",
+ SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT),
+ ImageDimensions(256, 256),
+ SamplingMode::BOX_THEN_NEAREST,
+ },
+ },
+ },
+ },
+ {
+ nullptr,
+ MaterialDefinition::ALBEDO | MaterialDefinition::METALLIC | MaterialDefinition::ROUGHNESS |
+ MaterialDefinition::EMISSIVE | MaterialDefinition::OCCLUSION | MaterialDefinition::NORMAL |
+ MaterialDefinition::GLTF_CHANNELS,
+ 0,
+ Color::WHITE,
+ 1.f,
+ 0.f,
+ Vector4(1.000, 0.766, 0.336, 1.0),
+ 1.f,
+ 1.f,
+ Vector3(0.2, 0.1, 0.0),
+ 0.04f,
+ 1.0f,
+ Vector3::ONE,
+ true,
+ true,
+ true,
+ false,
+ true,
+ false,
+ {
+ {
+ MaterialDefinition::ALBEDO,
+ {
+ "AnimatedCube_BaseColor.png",
+ SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT),
+ ImageDimensions(256, 256),
+ SamplingMode::BOX_THEN_NEAREST,
+ },
+ },
+ {
+ MaterialDefinition::METALLIC | MaterialDefinition::ROUGHNESS | MaterialDefinition::GLTF_CHANNELS,
+ {
+ "AnimatedCube_MetallicRoughness.png",
+ SamplerFlags::Encode(FilterMode::NEAREST_MIPMAP_LINEAR, FilterMode::NEAREST, WrapMode::CLAMP_TO_EDGE, WrapMode::MIRRORED_REPEAT),
+ ImageDimensions(256, 256),
+ SamplingMode::NEAREST,
+ },
+ },
+ {
+ MaterialDefinition::NORMAL,
+ {
+ "AnimatedCube_BaseColor.png",
+ SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT),
+ ImageDimensions(256, 256),
+ SamplingMode::BOX_THEN_NEAREST,
+ },
+ },
+ {
+ MaterialDefinition::OCCLUSION,
+ {
+ "AnimatedCube_BaseColor.png",
+ SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT),
+ ImageDimensions(256, 256),
+ SamplingMode::BOX_THEN_NEAREST,
+ },
+ },
+ {
+ MaterialDefinition::EMISSIVE,
+ {
+ "AnimatedCube_BaseColor.png",
+ SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT),
+ ImageDimensions(256, 256),
+ SamplingMode::BOX_THEN_NEAREST,
+ },
+ },
+ },
+ },
};
auto iMaterial = materials.begin();
using Accessor = MeshDefinition::Accessor;
const MeshDefinition meshGroundTruth[]{
{
+ nullptr,
0,
Geometry::TRIANGLES,
"AnimatedCube.bin",
Accessor{Blob{0, 0}, {}},
},
{
+ nullptr,
0,
Geometry::TRIANGLES,
"AnimatedCube.bin",
int UtcDaliGltfLoaderSuccess2(void)
{
- Context ctx;
+ Context ctx;
ShaderDefinitionFactory sdf;
sdf.SetResources(ctx.resources);
+ InitializeGltfLoader();
LoadGltfScene(TEST_RESOURCE_DIR "/AnimatedCubeStride.gltf", sdf, ctx.loadResult);
DALI_TEST_EQUAL(1u, ctx.scene.GetRoots().size());
for(auto modelName : {
"2CylinderEngine",
"AnimatedMorphCube",
+ "AnimatedMorphCubeAnimateNonZeroFrame",
"AnimatedMorphSphere",
"AnimatedTriangle",
"BoxAnimated",
sdf.SetResources(resources);
printf("%s\n", modelName);
+ InitializeGltfLoader();
LoadGltfScene(resourcePath + modelName + ".gltf", sdf, ctx.loadResult);
DALI_TEST_CHECK(ctx.scene.GetNodeCount() > 0);
{
if(visitor.receiver.mCounts[i0])
{
- auto raw = resources.mMeshes[i0].first.LoadRaw(resourcePath);
+ auto raw = resources.mMeshes[i0].first.LoadRaw(resourcePath, resources.mBuffers);
DALI_TEST_CHECK(!raw.mAttribs.empty());
resources.mMeshes[i0].second = resources.mMeshes[i0].first.Load(std::move(raw));
sdf.SetResources(ctx.resources);
auto& resources = ctx.resources;
+ InitializeGltfLoader();
LoadGltfScene(TEST_RESOURCE_DIR "/MRendererTest.gltf", sdf, ctx.loadResult);
auto& scene = ctx.scene;
DALI_TEST_EQUAL(child.GetRendererCount(), 1u);
DALI_TEST_EQUAL(child.GetRendererAt(0).GetTextures().GetTextureCount(), 4u);
+ DALI_TEST_EQUAL(child.GetRendererCount(), 1u);
+ DALI_TEST_EQUAL(child.GetRendererAt(0u).GetProperty<decltype(BlendMode::ON)>(Renderer::Property::BLEND_MODE), BlendMode::ON);
+
+ END_TEST;
+}
+
+int UtcDaliGltfLoaderAnimationLoadingTest(void)
+{
+ Context ctx;
+
+ ShaderDefinitionFactory sdf;
+ sdf.SetResources(ctx.resources);
+ auto& resources = ctx.resources;
+
+ InitializeGltfLoader();
+ LoadGltfScene(TEST_RESOURCE_DIR "/CesiumMan_e.gltf", sdf, ctx.loadResult);
+
+ auto& scene = ctx.scene;
+ auto& roots = scene.GetRoots();
+ DALI_TEST_EQUAL(roots.size(), 1u);
+
+ ViewProjection viewProjection;
+ Transforms xforms{
+ MatrixStack{},
+ viewProjection};
+ NodeDefinition::CreateParams nodeParams{
+ resources,
+ xforms,
+ };
+
+ Customization::Choices choices;
+
+ TestApplication app;
+
+ Actor root = Actor::New();
+ SetActorCentered(root);
+ for(auto iRoot : roots)
+ {
+ auto resourceRefs = resources.CreateRefCounter();
+ scene.CountResourceRefs(iRoot, choices, resourceRefs);
+ resources.CountEnvironmentReferences(resourceRefs);
+ resources.LoadResources(resourceRefs, ctx.pathProvider);
+ if(auto actor = scene.CreateNodes(iRoot, choices, nodeParams))
+ {
+ scene.ConfigureSkeletonJoints(iRoot, resources.mSkeletons, actor);
+ scene.ConfigureSkinningShaders(resources, actor, std::move(nodeParams.mSkinnables));
+ scene.ApplyConstraints(actor, std::move(nodeParams.mConstrainables));
+ root.Add(actor);
+ }
+ }
+
+ DALI_TEST_EQUAL(ctx.loadResult.mAnimationDefinitions.size(), 1u);
+ DALI_TEST_EQUAL(ctx.loadResult.mAnimationDefinitions[0].mProperties.size(), 57u);
+
+ uint32_t id = ctx.loadResult.mScene.GetNode(ctx.loadResult.mAnimationDefinitions[0].mProperties[0].mNodeIndex)->mNodeId;
+ DALI_TEST_EQUAL(id, root.FindChildByName("Skeleton_torso_joint_1").GetProperty<int32_t>(Dali::Actor::Property::ID));
+
+ END_TEST;
+}
+
+int UtcDaliGltfLoaderImageFromBufferView(void)
+{
+ Context ctx;
+
+ ShaderDefinitionFactory sdf;
+ sdf.SetResources(ctx.resources);
+ auto& resources = ctx.resources;
+
+ InitializeGltfLoader();
+ LoadGltfScene(TEST_RESOURCE_DIR "/EnvironmentTest_b.gltf", sdf, ctx.loadResult);
+
+ auto& scene = ctx.scene;
+ auto& roots = scene.GetRoots();
+ DALI_TEST_EQUAL(roots.size(), 1u);
+
+ ViewProjection viewProjection;
+ Transforms xforms{
+ MatrixStack{},
+ viewProjection};
+ NodeDefinition::CreateParams nodeParams{
+ resources,
+ xforms,
+ };
+
+ Customization::Choices choices;
+
+ TestApplication app;
+
+ Actor root = Actor::New();
+ SetActorCentered(root);
+ for(auto iRoot : roots)
+ {
+ auto resourceRefs = resources.CreateRefCounter();
+ scene.CountResourceRefs(iRoot, choices, resourceRefs);
+ resources.CountEnvironmentReferences(resourceRefs);
+ resources.LoadResources(resourceRefs, ctx.pathProvider);
+ if(auto actor = scene.CreateNodes(iRoot, choices, nodeParams))
+ {
+ scene.ConfigureSkeletonJoints(iRoot, resources.mSkeletons, actor);
+ scene.ConfigureSkinningShaders(resources, actor, std::move(nodeParams.mSkinnables));
+ scene.ApplyConstraints(actor, std::move(nodeParams.mConstrainables));
+ root.Add(actor);
+ }
+ }
+
+ DALI_TEST_CHECK(resources.mMaterials[0].second.GetTextureCount() > 1);
+ DALI_TEST_EQUAL(resources.mMaterials[0].second.GetTexture(0).GetWidth(), 256);
+ DALI_TEST_EQUAL(resources.mMaterials[0].second.GetTexture(0).GetHeight(), 256);
+
+ END_TEST;
+}
+
+int UtcDaliGltfLoaderUint8Indices(void)
+{
+ Context ctx;
+
+ ShaderDefinitionFactory sdf;
+ sdf.SetResources(ctx.resources);
+ auto& resources = ctx.resources;
+
+ InitializeGltfLoader();
+ LoadGltfScene(TEST_RESOURCE_DIR "/AlphaBlendModeTest.gltf", sdf, ctx.loadResult);
+
+ auto& scene = ctx.scene;
+ auto& roots = scene.GetRoots();
+ DALI_TEST_EQUAL(roots.size(), 1u);
+
+ ViewProjection viewProjection;
+ Transforms xforms{
+ MatrixStack{},
+ viewProjection};
+ NodeDefinition::CreateParams nodeParams{
+ resources,
+ xforms,
+ };
+
+ Customization::Choices choices;
+
+ TestApplication app;
+
+ Actor root = Actor::New();
+ SetActorCentered(root);
+ for(auto iRoot : roots)
+ {
+ auto resourceRefs = resources.CreateRefCounter();
+ scene.CountResourceRefs(iRoot, choices, resourceRefs);
+ resources.CountEnvironmentReferences(resourceRefs);
+ resources.LoadResources(resourceRefs, ctx.pathProvider);
+ if(auto actor = scene.CreateNodes(iRoot, choices, nodeParams))
+ {
+ scene.ConfigureSkeletonJoints(iRoot, resources.mSkeletons, actor);
+ scene.ConfigureSkinningShaders(resources, actor, std::move(nodeParams.mSkinnables));
+ scene.ApplyConstraints(actor, std::move(nodeParams.mConstrainables));
+ root.Add(actor);
+ }
+ }
+
+ DALI_TEST_CHECK(root.FindChildByName("Bed"));
+ DALI_TEST_CHECK(root.FindChildByName("DecalBlend"));
+ DALI_TEST_CHECK(root.FindChildByName("DecalOpaque"));
+
END_TEST;
}