| Flutter Impeller |

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 }

References ASSERT_COLOR_NEAR, ASSERT_MATRIX_NEAR, ASSERT_POINT_NEAR, ASSERT_VECTOR3_NEAR, ASSERT_VECTOR4_NEAR, impeller::scene::importer::ParseGLTF(), impeller::scene::importer::ToColor(), impeller::scene::importer::ToMatrix(), impeller::scene::importer::ToVector2(), impeller::scene::importer::ToVector3(), and impeller::scene::importer::ToVector4().

## ◆ 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.556997, -0.810833, 0.179733));
48
49 Vector4 tangent = ToVector4(vertex.tangent());
50 ASSERT_VECTOR4_NEAR(tangent, Vector4(0.155901, -0.110485, -0.981574, 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 }

References ASSERT_COLOR_NEAR, ASSERT_MATRIX_NEAR, ASSERT_POINT_NEAR, ASSERT_VECTOR3_NEAR, ASSERT_VECTOR4_NEAR, impeller::scene::importer::ParseGLTF(), impeller::scene::importer::ToColor(), impeller::scene::importer::ToMatrix(), impeller::scene::importer::ToVector2(), impeller::scene::importer::ToVector3(), and impeller::scene::importer::ToVector4().

ASSERT_COLOR_NEAR
#define ASSERT_COLOR_NEAR(a, b)
Definition: geometry_asserts.h:159
impeller::scene::importer::ParseGLTF
bool ParseGLTF(const fml::Mapping &source_mapping, fb::SceneT &out_scene)
Definition: importer_gltf.cc:450
impeller::Vector2
Point Vector2
Definition: point.h:312
impeller::scene::importer::ToVector4
Vector4 ToVector4(const fb::Vec4 &v)
Definition: conversions.cc:42
impeller::skia_conversions::ToColor
Color ToColor(const flutter::DlColor &color)
Definition: skia_conversions.cc:148
ASSERT_POINT_NEAR
#define ASSERT_POINT_NEAR(a, b)
Definition: geometry_asserts.h:160
ASSERT_VECTOR4_NEAR
#define ASSERT_VECTOR4_NEAR(a, b)
Definition: geometry_asserts.h:162
impeller::ToMatrix
static Matrix ToMatrix(const SkMatrix &m)
Definition: dl_dispatcher.cc:166
impeller::scene::importer::ToVector3
Vector3 ToVector3(const fb::Vec3 &v)
Definition: conversions.cc:38
ASSERT_MATRIX_NEAR
#define ASSERT_MATRIX_NEAR(a, b)
Definition: geometry_asserts.h:156
impeller::scene::importer::ToVector2
Vector2 ToVector2(const fb::Vec2 &v)
Definition: conversions.cc:34
ASSERT_VECTOR3_NEAR
#define ASSERT_VECTOR3_NEAR(a, b)
Definition: geometry_asserts.h:161