Flutter Engine
The Flutter Engine
Functions
impeller::scene::importer::testing Namespace Reference

Functions

 TEST (ImporterTest, CanParseUnskinnedGLTF)
 
 TEST (ImporterTest, CanParseSkinnedGLTF)
 

Function Documentation

◆ TEST() [1/2]

impeller::scene::importer::testing::TEST ( ImporterTest  ,
CanParseSkinnedGLTF   
)

Definition at line 59 of file importer_unittests.cc.

59 {
60 auto mapping = flutter::testing::OpenFixtureAsMapping("two_triangles.glb");
61
62 fb::SceneT scene;
63 ASSERT_TRUE(ParseGLTF(*mapping, scene));
64
65 ASSERT_EQ(scene.children.size(), 1u);
66 auto& node = scene.nodes[scene.children[0]];
67
68 Matrix node_transform = ToMatrix(*node->transform);
69 ASSERT_MATRIX_NEAR(node_transform, Matrix());
70
71 ASSERT_EQ(node->mesh_primitives.size(), 0u);
72 ASSERT_EQ(node->children.size(), 2u);
73
74 // The skinned node contains both a skeleton and skinned mesh primitives that
75 // reference bones in the skeleton.
76 auto& skinned_node = scene.nodes[node->children[0]];
77 ASSERT_NE(skinned_node->skin, nullptr);
78
79 ASSERT_EQ(skinned_node->mesh_primitives.size(), 2u);
80 auto& bottom_triangle = *skinned_node->mesh_primitives[0];
81 ASSERT_EQ(bottom_triangle.indices->count, 3u);
82
83 ASSERT_EQ(bottom_triangle.vertices.type,
84 fb::VertexBuffer::SkinnedVertexBuffer);
85 auto& vertices = bottom_triangle.vertices.AsSkinnedVertexBuffer()->vertices;
86 ASSERT_EQ(vertices.size(), 3u);
87 auto& vertex = vertices[0];
88
89 Vector3 position = ToVector3(vertex.vertex().position());
90 ASSERT_VECTOR3_NEAR(position, Vector3(1, 1, 0));
91
92 Vector3 normal = ToVector3(vertex.vertex().normal());
93 ASSERT_VECTOR3_NEAR(normal, Vector3(0, 0, 1));
94
95 Vector4 tangent = ToVector4(vertex.vertex().tangent());
96 ASSERT_VECTOR4_NEAR(tangent, Vector4(1, 0, 0, -1));
97
98 Vector2 texture_coords = ToVector2(vertex.vertex().texture_coords());
99 ASSERT_POINT_NEAR(texture_coords, Vector2(0, 1));
100
101 Color color = ToColor(vertex.vertex().color());
102 ASSERT_COLOR_NEAR(color, Color(1, 1, 1, 1));
103
104 Vector4 joints = ToVector4(vertex.joints());
105 ASSERT_VECTOR4_NEAR(joints, Vector4(0, 0, 0, 0));
106
107 Vector4 weights = ToVector4(vertex.weights());
108 ASSERT_VECTOR4_NEAR(weights, Vector4(1, 0, 0, 0));
109
110 ASSERT_EQ(scene.animations.size(), 2u);
111 ASSERT_EQ(scene.animations[0]->name, "Idle");
112 ASSERT_EQ(scene.animations[1]->name, "Metronome");
113 ASSERT_EQ(scene.animations[1]->channels.size(), 6u);
114 auto& channel = scene.animations[1]->channels[3];
115 ASSERT_EQ(channel->keyframes.type, fb::Keyframes::RotationKeyframes);
116 auto* keyframes = channel->keyframes.AsRotationKeyframes();
117 ASSERT_EQ(keyframes->values.size(), 40u);
118 ASSERT_VECTOR4_NEAR(ToVector4(keyframes->values[0]),
119 Vector4(0.653281, -0.270598, 0.270598, 0.653281));
120 ASSERT_VECTOR4_NEAR(ToVector4(keyframes->values[10]),
121 Vector4(0.700151, 0.0989373, -0.0989373, 0.700151));
122}
DlColor color
#define ASSERT_VECTOR4_NEAR(a, b)
#define ASSERT_MATRIX_NEAR(a, b)
#define ASSERT_COLOR_NEAR(a, b)
#define ASSERT_POINT_NEAR(a, b)
#define ASSERT_VECTOR3_NEAR(a, b)
SK_API sk_sp< SkShader > Color(SkColor)
std::unique_ptr< fml::Mapping > OpenFixtureAsMapping(const std::string &fixture_name)
Opens a fixture of the given file name and returns a mapping to its contents.
Definition: testing.cc:59
bool ParseGLTF(const fml::Mapping &source_mapping, fb::SceneT &out_scene)
Vector3 ToVector3(const fb::Vec3 &v)
Definition: conversions.cc:38
Vector4 ToVector4(const fb::Vec4 &v)
Definition: conversions.cc:42
Vector2 ToVector2(const fb::Vec2 &v)
Definition: conversions.cc:34
Color ToColor(const flutter::DlColor &color)
Point Vector2
Definition: point.h:326
static Matrix ToMatrix(const SkMatrix &m)
SK_API sk_sp< PrecompileColorFilter > Matrix()
A 4x4 matrix using column-major storage.
Definition: matrix.h:37

◆ TEST() [2/2]

impeller::scene::importer::testing::TEST ( ImporterTest  ,
CanParseUnskinnedGLTF   
)

Definition at line 17 of file importer_unittests.cc.

17 {
18 auto mapping =
19 flutter::testing::OpenFixtureAsMapping("flutter_logo_baked.glb");
20
21 fb::SceneT scene;
22 ASSERT_TRUE(ParseGLTF(*mapping, scene));
23
24 ASSERT_EQ(scene.children.size(), 1u);
25 auto& node = scene.nodes[scene.children[0]];
26
27 Matrix node_transform = ToMatrix(*node->transform);
28 ASSERT_MATRIX_NEAR(node_transform, Matrix());
29
30 ASSERT_EQ(node->mesh_primitives.size(), 1u);
31 auto& mesh = *node->mesh_primitives[0];
32 ASSERT_EQ(mesh.indices->count, 918u);
33
34 uint16_t first_index =
35 *reinterpret_cast<uint16_t*>(mesh.indices->data.data());
36 ASSERT_EQ(first_index, 45u);
37
38 ASSERT_EQ(mesh.vertices.type, fb::VertexBuffer::UnskinnedVertexBuffer);
39 auto& vertices = mesh.vertices.AsUnskinnedVertexBuffer()->vertices;
40 ASSERT_EQ(vertices.size(), 260u);
41 auto& vertex = vertices[0];
42
43 Vector3 position = ToVector3(vertex.position());
44 ASSERT_VECTOR3_NEAR(position, Vector3(-0.0100185, -0.522907, 0.133178));
45
46 Vector3 normal = ToVector3(vertex.normal());
47 ASSERT_VECTOR3_NEAR(normal, Vector3(0.556984, -0.810839, 0.179746));
48
49 Vector4 tangent = ToVector4(vertex.tangent());
50 ASSERT_VECTOR4_NEAR(tangent, Vector4(0.155911, -0.110495, -0.981572, 1));
51
52 Vector2 texture_coords = ToVector2(vertex.texture_coords());
53 ASSERT_POINT_NEAR(texture_coords, Vector2(0.727937, 0.713817));
54
55 Color color = ToColor(vertex.color());
56 ASSERT_COLOR_NEAR(color, Color(0.0221714, 0.467781, 0.921584, 1));
57}
SkMesh mesh
Definition: SkRecords.h:345