Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Impeller Scene] Parse GLTF primitives #38064

Merged
merged 7 commits into from Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion DEPS
Expand Up @@ -236,7 +236,7 @@ allowed_hosts = [
]

deps = {
'src': 'https://github.com/flutter/buildroot.git' + '@' + '8747bce41d0dc6d9dc45c4d1b46d2100bb9ee688',
'src': 'https://github.com/flutter/buildroot.git' + '@' + '908edab91bffdea18876868b20bef94f44746d21',

# Fuchsia compatibility
#
Expand Down
7 changes: 6 additions & 1 deletion ci/licenses_golden/licenses_flutter
Expand Up @@ -1648,13 +1648,18 @@ FILE: ../../../flutter/impeller/scene/camera.cc
FILE: ../../../flutter/impeller/scene/camera.h
FILE: ../../../flutter/impeller/scene/geometry.cc
FILE: ../../../flutter/impeller/scene/geometry.h
FILE: ../../../flutter/impeller/scene/importer/conversions.cc
FILE: ../../../flutter/impeller/scene/importer/conversions.h
FILE: ../../../flutter/impeller/scene/importer/importer.h
FILE: ../../../flutter/impeller/scene/importer/importer_gltf.cc
FILE: ../../../flutter/impeller/scene/importer/mesh.fbs
FILE: ../../../flutter/impeller/scene/importer/importer_unittests.cc
FILE: ../../../flutter/impeller/scene/importer/scene.fbs
FILE: ../../../flutter/impeller/scene/importer/scenec_main.cc
FILE: ../../../flutter/impeller/scene/importer/switches.cc
FILE: ../../../flutter/impeller/scene/importer/switches.h
FILE: ../../../flutter/impeller/scene/importer/types.h
FILE: ../../../flutter/impeller/scene/importer/vertices_builder.cc
FILE: ../../../flutter/impeller/scene/importer/vertices_builder.h
FILE: ../../../flutter/impeller/scene/material.cc
FILE: ../../../flutter/impeller/scene/material.h
FILE: ../../../flutter/impeller/scene/scene.cc
Expand Down
1 change: 1 addition & 0 deletions impeller/BUILD.gn
Expand Up @@ -74,6 +74,7 @@ impeller_component("impeller_unittests") {
"compiler:compiler_unittests",
"geometry:geometry_unittests",
"runtime_stage:runtime_stage_unittests",
"scene/importer:importer_unittests",
"tessellator:tessellator_unittests",
]

Expand Down
1 change: 1 addition & 0 deletions impeller/fixtures/BUILD.gn
Expand Up @@ -58,6 +58,7 @@ test_fixtures("file_fixtures") {
"blue_noise.png",
"boston.jpg",
"embarcadero.jpg",
"flutter_logo.glb",
"kalimba.jpg",
"multiple_stages.hlsl",
"resources_limit.vert",
Expand Down
28 changes: 23 additions & 5 deletions impeller/scene/importer/BUILD.gn
Expand Up @@ -12,22 +12,26 @@ config("runtime_stage_config") {
}

flatbuffers("importer_flatbuffers") {
flatbuffers = [ "mesh.fbs" ]
flatbuffers = [ "scene.fbs" ]
public_configs = [ ":runtime_stage_config" ]
public_deps = [ "//third_party/flatbuffers" ]
}

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

sources = [
"conversions.cc",
"conversions.h",
"importer.h",
"importer_gltf.cc",
"switches.cc",
"switches.h",
"types.h",
"vertices_builder.cc",
"vertices_builder.h",
]

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

# All third_party deps must be reflected below in the scenec_license
# target.
# TODO(bdero): Fix tinygltf compilation warnings.
#"//third_party/tinygltf",
"//third_party/tinygltf",
]
}

Expand Down Expand Up @@ -85,9 +88,24 @@ impeller_component("scenec") {

sources = [ "scenec_main.cc" ]

deps = [ ":scenec_lib" ]
deps = [ ":importer_lib" ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this based off of an old commit? I thought scenec was the name we settled on?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured it would make sense to call the frontend/executable name "scenec" and the namespace/library with the importing utilities "importer", similar to how "impellerc" is the frontend for the "compiler" lib. Perhaps I should use the scenec name all around?


metadata = {
entitlement_file_path = [ "scenec" ]
}
}

impeller_component("importer_unittests") {
testonly = true

output_name = "scenec_unittests"

sources = [ "importer_unittests.cc" ]

deps = [
":importer_lib",
"../../fixtures",
"../../geometry:geometry_unittests",
"//flutter/testing:testing_lib",
]
}
80 changes: 80 additions & 0 deletions impeller/scene/importer/conversions.cc
@@ -0,0 +1,80 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "impeller/scene/importer/conversions.h"

#include <cstring>

#include "impeller/scene/importer/scene_flatbuffers.h"

namespace impeller {
namespace scene {
namespace importer {

Matrix ToMatrix(const std::vector<double>& m) {
return Matrix(m[0], m[1], m[2], m[3], //
m[4], m[5], m[6], m[7], //
m[8], m[9], m[10], m[11], //
m[12], m[13], m[14], m[15]);
}

//-----------------------------------------------------------------------------
/// Flatbuffers -> Impeller
///

Matrix ToMatrix(const fb::Matrix& m) {
auto& a = *m.m();
return Matrix(a[0], a[1], a[2], a[3], //
a[4], a[5], a[6], a[7], //
a[8], a[9], a[10], a[11], //
a[12], a[13], a[14], a[15]);
}

Vector2 ToVector2(const fb::Vec2& v) {
return Vector2(v.x(), v.y());
}

Vector3 ToVector3(const fb::Vec3& v) {
return Vector3(v.x(), v.y(), v.z());
}

Vector4 ToVector4(const fb::Vec4& v) {
return Vector4(v.x(), v.y(), v.z(), v.w());
}

Color ToColor(const fb::Color& c) {
return Color(c.r(), c.g(), c.b(), c.a());
}

//-----------------------------------------------------------------------------
/// Impeller -> Flatbuffers
///

std::unique_ptr<fb::Matrix> ToFBMatrix(const Matrix& m) {
auto array = std::array<Scalar, 16>{m.m[0], m.m[1], m.m[2], m.m[3], //
m.m[4], m.m[5], m.m[6], m.m[7], //
m.m[8], m.m[9], m.m[10], m.m[11], //
m.m[12], m.m[13], m.m[14], m.m[15]};
return std::make_unique<fb::Matrix>(array);
}

fb::Vec2 ToFBVec2(const Vector2 v) {
return fb::Vec2(v.x, v.y);
}

fb::Vec3 ToFBVec3(const Vector3 v) {
return fb::Vec3(v.x, v.y, v.z);
}

fb::Vec4 ToFBVec4(const Vector4 v) {
return fb::Vec4(v.x, v.y, v.z, v.w);
}

fb::Color ToFBColor(const Color c) {
return fb::Color(c.red, c.green, c.blue, c.alpha);
}

} // namespace importer
} // namespace scene
} // namespace impeller
49 changes: 49 additions & 0 deletions impeller/scene/importer/conversions.h
@@ -0,0 +1,49 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto question about include guards in this file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#pragma once

#include <cstddef>
#include <map>

#include "impeller/geometry/matrix.h"
#include "impeller/scene/importer/scene_flatbuffers.h"

namespace impeller {
namespace scene {
namespace importer {

Matrix ToMatrix(const std::vector<double>& m);

//-----------------------------------------------------------------------------
/// Flatbuffers -> Impeller
///

Matrix ToMatrix(const fb::Matrix& m);

Vector2 ToVector2(const fb::Vec2& c);

Vector3 ToVector3(const fb::Vec3& c);

Vector4 ToVector4(const fb::Vec4& c);

Color ToColor(const fb::Color& c);

//-----------------------------------------------------------------------------
/// Impeller -> Flatbuffers
///

std::unique_ptr<fb::Matrix> ToFBMatrix(const Matrix& m);

fb::Vec2 ToFBVec2(const Vector2 v);

fb::Vec3 ToFBVec3(const Vector3 v);

fb::Vec4 ToFBVec4(const Vector4 v);

fb::Color ToFBColor(const Color c);

} // namespace importer
} // namespace scene
} // namespace impeller
6 changes: 4 additions & 2 deletions impeller/scene/importer/importer.h
Expand Up @@ -2,17 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#pragma once

#include <array>
#include <memory>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto question about include guards in this file

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


#include "flutter/fml/mapping.h"
#include "impeller/scene/importer/mesh_flatbuffers.h"
#include "impeller/scene/importer/scene_flatbuffers.h"

namespace impeller {
namespace scene {
namespace importer {

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

}
} // namespace scene
Expand Down