Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 923e279

Browse files
committed
[Impeller Scene] Parse GLTF geometry
1 parent dce50b1 commit 923e279

14 files changed

+666
-53
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,13 +1648,18 @@ FILE: ../../../flutter/impeller/scene/camera.cc
16481648
FILE: ../../../flutter/impeller/scene/camera.h
16491649
FILE: ../../../flutter/impeller/scene/geometry.cc
16501650
FILE: ../../../flutter/impeller/scene/geometry.h
1651+
FILE: ../../../flutter/impeller/scene/importer/conversions.cc
1652+
FILE: ../../../flutter/impeller/scene/importer/conversions.h
16511653
FILE: ../../../flutter/impeller/scene/importer/importer.h
16521654
FILE: ../../../flutter/impeller/scene/importer/importer_gltf.cc
1653-
FILE: ../../../flutter/impeller/scene/importer/mesh.fbs
1655+
FILE: ../../../flutter/impeller/scene/importer/importer_unittests.cc
1656+
FILE: ../../../flutter/impeller/scene/importer/scene.fbs
16541657
FILE: ../../../flutter/impeller/scene/importer/scenec_main.cc
16551658
FILE: ../../../flutter/impeller/scene/importer/switches.cc
16561659
FILE: ../../../flutter/impeller/scene/importer/switches.h
16571660
FILE: ../../../flutter/impeller/scene/importer/types.h
1661+
FILE: ../../../flutter/impeller/scene/importer/vertices_builder.cc
1662+
FILE: ../../../flutter/impeller/scene/importer/vertices_builder.h
16581663
FILE: ../../../flutter/impeller/scene/material.cc
16591664
FILE: ../../../flutter/impeller/scene/material.h
16601665
FILE: ../../../flutter/impeller/scene/scene.cc

impeller/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ impeller_component("impeller_unittests") {
7474
"compiler:compiler_unittests",
7575
"geometry:geometry_unittests",
7676
"runtime_stage:runtime_stage_unittests",
77+
"scene/importer:importer_unittests",
7778
"tessellator:tessellator_unittests",
7879
]
7980

impeller/fixtures/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ test_fixtures("file_fixtures") {
5858
"blue_noise.png",
5959
"boston.jpg",
6060
"embarcadero.jpg",
61+
"flutter_logo.glb",
6162
"kalimba.jpg",
6263
"multiple_stages.hlsl",
6364
"resources_limit.vert",

impeller/scene/importer/BUILD.gn

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,26 @@ config("runtime_stage_config") {
1212
}
1313

1414
flatbuffers("importer_flatbuffers") {
15-
flatbuffers = [ "mesh.fbs" ]
15+
flatbuffers = [ "scene.fbs" ]
1616
public_configs = [ ":runtime_stage_config" ]
1717
public_deps = [ "//third_party/flatbuffers" ]
1818
}
1919

20-
impeller_component("scenec_lib") {
20+
impeller_component("importer_lib") {
2121
# Current versions of libcxx have deprecated some of the UTF-16 string
2222
# conversion APIs.
2323
defines = [ "_LIBCPP_DISABLE_DEPRECATION_WARNINGS" ]
2424

2525
sources = [
26+
"conversions.cc",
27+
"conversions.h",
2628
"importer.h",
2729
"importer_gltf.cc",
2830
"switches.cc",
2931
"switches.h",
3032
"types.h",
33+
"vertices_builder.cc",
34+
"vertices_builder.h",
3135
]
3236

3337
public_deps = [
@@ -39,8 +43,7 @@ impeller_component("scenec_lib") {
3943

4044
# All third_party deps must be reflected below in the scenec_license
4145
# target.
42-
# TODO(bdero): Fix tinygltf compilation warnings.
43-
#"//third_party/tinygltf",
46+
"//third_party/tinygltf",
4447
]
4548
}
4649

@@ -85,9 +88,24 @@ impeller_component("scenec") {
8588

8689
sources = [ "scenec_main.cc" ]
8790

88-
deps = [ ":scenec_lib" ]
91+
deps = [ ":importer_lib" ]
8992

9093
metadata = {
9194
entitlement_file_path = [ "scenec" ]
9295
}
9396
}
97+
98+
impeller_component("importer_unittests") {
99+
testonly = true
100+
101+
output_name = "scenec_unittests"
102+
103+
sources = [ "importer_unittests.cc" ]
104+
105+
deps = [
106+
":importer_lib",
107+
"../../fixtures",
108+
"../../geometry:geometry_unittests",
109+
"//flutter/testing:testing_lib",
110+
]
111+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
2+
// Copyright 2013 The Flutter Authors. All rights reserved.
3+
// Use of this source code is governed by a BSD-style license that can be
4+
// found in the LICENSE file.
5+
6+
#include "impeller/scene/importer/conversions.h"
7+
8+
#include <cstring>
9+
10+
#include "impeller/scene/importer/scene_flatbuffers.h"
11+
12+
namespace impeller {
13+
namespace scene {
14+
namespace importer {
15+
16+
Matrix ToMatrix(const std::vector<double>& m) {
17+
return Matrix(m[0], m[1], m[2], m[3], //
18+
m[4], m[5], m[6], m[7], //
19+
m[8], m[9], m[10], m[11], //
20+
m[12], m[13], m[14], m[15]);
21+
}
22+
23+
//-----------------------------------------------------------------------------
24+
/// Flatbuffers -> Impeller
25+
///
26+
27+
Matrix ToMatrix(const fb::Matrix& m) {
28+
auto& a = *m.m();
29+
return Matrix(a[0], a[1], a[2], a[3], //
30+
a[4], a[5], a[6], a[7], //
31+
a[8], a[9], a[10], a[11], //
32+
a[12], a[13], a[14], a[15]);
33+
}
34+
35+
Vector2 ToVector2(const fb::Vec2& v) {
36+
return Vector2(v.x(), v.y());
37+
}
38+
39+
Vector3 ToVector3(const fb::Vec3& v) {
40+
return Vector3(v.x(), v.y(), v.z());
41+
}
42+
43+
Vector4 ToVector4(const fb::Vec4& v) {
44+
return Vector4(v.x(), v.y(), v.z(), v.w());
45+
}
46+
47+
Color ToColor(const fb::Color& c) {
48+
return Color(c.r(), c.g(), c.b(), c.a());
49+
}
50+
51+
//-----------------------------------------------------------------------------
52+
/// Impeller -> Flatbuffers
53+
///
54+
55+
std::unique_ptr<fb::Matrix> ToFBMatrix(const Matrix& m) {
56+
auto array = std::array<Scalar, 16>{m.m[0], m.m[1], m.m[2], m.m[3], //
57+
m.m[4], m.m[5], m.m[6], m.m[7], //
58+
m.m[8], m.m[9], m.m[10], m.m[11], //
59+
m.m[12], m.m[13], m.m[14], m.m[15]};
60+
return std::make_unique<fb::Matrix>(array);
61+
}
62+
63+
fb::Vec2 ToFBVec2(const Vector2 v) {
64+
return fb::Vec2(v.x, v.y);
65+
}
66+
67+
fb::Vec3 ToFBVec3(const Vector3 v) {
68+
return fb::Vec3(v.x, v.y, v.z);
69+
}
70+
71+
fb::Vec4 ToFBVec4(const Vector4 v) {
72+
return fb::Vec4(v.x, v.y, v.z, v.w);
73+
}
74+
75+
fb::Color ToFBColor(const Color c) {
76+
return fb::Color(c.red, c.green, c.blue, c.alpha);
77+
}
78+
79+
} // namespace importer
80+
} // namespace scene
81+
} // namespace impeller

impeller/scene/importer/conversions.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include <cstddef>
6+
#include <map>
7+
8+
#include "impeller/geometry/matrix.h"
9+
#include "impeller/scene/importer/scene_flatbuffers.h"
10+
11+
namespace impeller {
12+
namespace scene {
13+
namespace importer {
14+
15+
Matrix ToMatrix(const std::vector<double>& m);
16+
17+
//-----------------------------------------------------------------------------
18+
/// Flatbuffers -> Impeller
19+
///
20+
21+
Matrix ToMatrix(const fb::Matrix& m);
22+
23+
Vector2 ToVector2(const fb::Vec2& c);
24+
25+
Vector3 ToVector3(const fb::Vec3& c);
26+
27+
Vector4 ToVector4(const fb::Vec4& c);
28+
29+
Color ToColor(const fb::Color& c);
30+
31+
//-----------------------------------------------------------------------------
32+
/// Impeller -> Flatbuffers
33+
///
34+
35+
std::unique_ptr<fb::Matrix> ToFBMatrix(const Matrix& m);
36+
37+
fb::Vec2 ToFBVec2(const Vector2 v);
38+
39+
fb::Vec3 ToFBVec3(const Vector3 v);
40+
41+
fb::Vec4 ToFBVec4(const Vector4 v);
42+
43+
fb::Color ToFBColor(const Color c);
44+
45+
} // namespace importer
46+
} // namespace scene
47+
} // namespace impeller

impeller/scene/importer/importer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
#include <memory>
77

88
#include "flutter/fml/mapping.h"
9-
#include "impeller/scene/importer/mesh_flatbuffers.h"
9+
#include "impeller/scene/importer/scene_flatbuffers.h"
1010

1111
namespace impeller {
1212
namespace scene {
1313
namespace importer {
1414

15-
bool ParseGLTF(const fml::Mapping& source_mapping, fb::MeshT& out_mesh);
15+
bool ParseGLTF(const fml::Mapping& source_mapping, fb::SceneT& out_scene);
1616

1717
}
1818
} // namespace scene

0 commit comments

Comments
 (0)