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

Commit a309d23

Browse files
authored
[Impeller Scene] Parse GLTF primitives (#38064)
1 parent 0efb0ef commit a309d23

14 files changed

+679
-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: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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 "impeller/scene/importer/conversions.h"
6+
7+
#include <cstring>
8+
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+
return Matrix(m[0], m[1], m[2], m[3], //
17+
m[4], m[5], m[6], m[7], //
18+
m[8], m[9], m[10], m[11], //
19+
m[12], m[13], m[14], m[15]);
20+
}
21+
22+
//-----------------------------------------------------------------------------
23+
/// Flatbuffers -> Impeller
24+
///
25+
26+
Matrix ToMatrix(const fb::Matrix& m) {
27+
auto& a = *m.m();
28+
return Matrix(a[0], a[1], a[2], a[3], //
29+
a[4], a[5], a[6], a[7], //
30+
a[8], a[9], a[10], a[11], //
31+
a[12], a[13], a[14], a[15]);
32+
}
33+
34+
Vector2 ToVector2(const fb::Vec2& v) {
35+
return Vector2(v.x(), v.y());
36+
}
37+
38+
Vector3 ToVector3(const fb::Vec3& v) {
39+
return Vector3(v.x(), v.y(), v.z());
40+
}
41+
42+
Vector4 ToVector4(const fb::Vec4& v) {
43+
return Vector4(v.x(), v.y(), v.z(), v.w());
44+
}
45+
46+
Color ToColor(const fb::Color& c) {
47+
return Color(c.r(), c.g(), c.b(), c.a());
48+
}
49+
50+
//-----------------------------------------------------------------------------
51+
/// Impeller -> Flatbuffers
52+
///
53+
54+
std::unique_ptr<fb::Matrix> ToFBMatrix(const Matrix& m) {
55+
auto array = std::array<Scalar, 16>{m.m[0], m.m[1], m.m[2], m.m[3], //
56+
m.m[4], m.m[5], m.m[6], m.m[7], //
57+
m.m[8], m.m[9], m.m[10], m.m[11], //
58+
m.m[12], m.m[13], m.m[14], m.m[15]};
59+
return std::make_unique<fb::Matrix>(array);
60+
}
61+
62+
fb::Vec2 ToFBVec2(const Vector2 v) {
63+
return fb::Vec2(v.x, v.y);
64+
}
65+
66+
fb::Vec3 ToFBVec3(const Vector3 v) {
67+
return fb::Vec3(v.x, v.y, v.z);
68+
}
69+
70+
fb::Vec4 ToFBVec4(const Vector4 v) {
71+
return fb::Vec4(v.x, v.y, v.z, v.w);
72+
}
73+
74+
fb::Color ToFBColor(const Color c) {
75+
return fb::Color(c.red, c.green, c.blue, c.alpha);
76+
}
77+
78+
} // namespace importer
79+
} // namespace scene
80+
} // namespace impeller

impeller/scene/importer/conversions.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
#pragma once
6+
7+
#include <cstddef>
8+
#include <map>
9+
10+
#include "impeller/geometry/matrix.h"
11+
#include "impeller/scene/importer/scene_flatbuffers.h"
12+
13+
namespace impeller {
14+
namespace scene {
15+
namespace importer {
16+
17+
Matrix ToMatrix(const std::vector<double>& m);
18+
19+
//-----------------------------------------------------------------------------
20+
/// Flatbuffers -> Impeller
21+
///
22+
23+
Matrix ToMatrix(const fb::Matrix& m);
24+
25+
Vector2 ToVector2(const fb::Vec2& c);
26+
27+
Vector3 ToVector3(const fb::Vec3& c);
28+
29+
Vector4 ToVector4(const fb::Vec4& c);
30+
31+
Color ToColor(const fb::Color& c);
32+
33+
//-----------------------------------------------------------------------------
34+
/// Impeller -> Flatbuffers
35+
///
36+
37+
std::unique_ptr<fb::Matrix> ToFBMatrix(const Matrix& m);
38+
39+
fb::Vec2 ToFBVec2(const Vector2 v);
40+
41+
fb::Vec3 ToFBVec3(const Vector3 v);
42+
43+
fb::Vec4 ToFBVec4(const Vector4 v);
44+
45+
fb::Color ToFBColor(const Color c);
46+
47+
} // namespace importer
48+
} // namespace scene
49+
} // namespace impeller

impeller/scene/importer/importer.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
#pragma once
6+
57
#include <array>
68
#include <memory>
79

810
#include "flutter/fml/mapping.h"
9-
#include "impeller/scene/importer/mesh_flatbuffers.h"
11+
#include "impeller/scene/importer/scene_flatbuffers.h"
1012

1113
namespace impeller {
1214
namespace scene {
1315
namespace importer {
1416

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

1719
}
1820
} // namespace scene

0 commit comments

Comments
 (0)