-
Notifications
You must be signed in to change notification settings - Fork 6k
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] Add offline mesh importer #37981
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# 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. | ||
|
||
import("//flutter/impeller/tools/impeller.gni") | ||
import("//flutter/shell/version/version.gni") | ||
import("//third_party/flatbuffers/flatbuffers.gni") | ||
|
||
config("runtime_stage_config") { | ||
configs = [ "//flutter/impeller:impeller_public_config" ] | ||
include_dirs = [ "$root_gen_dir/flutter" ] | ||
} | ||
|
||
flatbuffers("importer_flatbuffers") { | ||
flatbuffers = [ "mesh.fbs" ] | ||
public_configs = [ ":runtime_stage_config" ] | ||
public_deps = [ "//third_party/flatbuffers" ] | ||
} | ||
|
||
impeller_component("importer_lib") { | ||
# Current versions of libcxx have deprecated some of the UTF-16 string | ||
# conversion APIs. | ||
defines = [ "_LIBCPP_DISABLE_DEPRECATION_WARNINGS" ] | ||
|
||
sources = [ | ||
"importer.h", | ||
"importer_gltf.cc", | ||
"switches.cc", | ||
"switches.h", | ||
"types.h", | ||
] | ||
|
||
public_deps = [ | ||
":importer_flatbuffers", | ||
"../../base", | ||
"../../compiler:utilities", | ||
"../../geometry", | ||
"//flutter/fml", | ||
|
||
# All third_party deps must be reflected below in the scene_importer_license | ||
# target. | ||
# TODO(bdero): Fix tinygltf compilation warnings. | ||
#"//third_party/tinygltf", | ||
] | ||
} | ||
|
||
generated_file("scene_importer_license") { | ||
source_path = rebase_path(".", "//flutter") | ||
git_url = "https://github.com/flutter/engine/tree/$engine_version" | ||
outputs = [ "$target_gen_dir/LICENSE.scene_importer.md" ] | ||
contents = [ | ||
"# scene_importer", | ||
"", | ||
"This tool is used by the Flutter SDK to import 3D geometry.", | ||
"", | ||
"Source code for this tool: [flutter/engine/$source_path]($git_url/$source_path).", | ||
"", | ||
"## Licenses", | ||
"", | ||
"### scene_importer", | ||
"", | ||
read_file("//flutter/sky/packages/sky_engine/LICENSE", "string"), | ||
"", | ||
|
||
# These licenses are ignored by the main license checker, since they are not | ||
# shipped to end-application binaries and only shipped as part of developer | ||
# tooling in scene_importer. Add them here. | ||
"## Additional open source licenses", | ||
"", | ||
"### tinygltf", | ||
"", | ||
read_file("//third_party/tinygltf/LICENSE", "string"), | ||
] | ||
} | ||
|
||
group("importer") { | ||
deps = [ | ||
":scene_importer", | ||
":scene_importer_license", | ||
] | ||
} | ||
|
||
impeller_component("scene_importer") { | ||
target_type = "executable" | ||
|
||
sources = [ "importer_main.cc" ] | ||
|
||
deps = [ ":importer_lib" ] | ||
|
||
metadata = { | ||
entitlement_file_path = [ "scene_importer" ] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// 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 <array> | ||
#include <memory> | ||
|
||
#include "flutter/fml/mapping.h" | ||
#include "impeller/scene/importer/mesh_flatbuffers.h" | ||
|
||
namespace impeller { | ||
namespace scene { | ||
namespace importer { | ||
|
||
bool ParseGLTF(const fml::Mapping& source_mapping, fb::MeshT& out_mesh); | ||
|
||
} | ||
} // namespace scene | ||
} // namespace impeller |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// 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 <array> | ||
#include <memory> | ||
|
||
#include "impeller/scene/importer/importer.h" | ||
|
||
#include "flutter/fml/mapping.h" | ||
|
||
namespace impeller { | ||
namespace scene { | ||
namespace importer { | ||
|
||
bool ParseGLTF(const fml::Mapping& source_mapping, fb::MeshT& out_mesh) { | ||
// TODO(bdero): Parse source_mapping and populare out_mesh with just the first | ||
// mesh in the GLTF. | ||
return true; | ||
} | ||
|
||
} // namespace importer | ||
} // namespace scene | ||
} // namespace impeller |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// 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 <filesystem> | ||
#include <memory> | ||
|
||
#include "flutter/fml/backtrace.h" | ||
#include "flutter/fml/command_line.h" | ||
#include "flutter/fml/file.h" | ||
#include "flutter/fml/macros.h" | ||
#include "flutter/fml/mapping.h" | ||
#include "impeller/base/strings.h" | ||
#include "impeller/compiler/utilities.h" | ||
#include "impeller/scene/importer/importer.h" | ||
#include "impeller/scene/importer/switches.h" | ||
#include "impeller/scene/importer/types.h" | ||
|
||
#include "third_party/flatbuffers/include/flatbuffers/flatbuffer_builder.h" | ||
|
||
namespace impeller { | ||
namespace scene { | ||
namespace importer { | ||
|
||
// Sets the file access mode of the file at path 'p' to 0644. | ||
static bool SetPermissiveAccess(const std::filesystem::path& p) { | ||
auto permissions = | ||
std::filesystem::perms::owner_read | std::filesystem::perms::owner_write | | ||
std::filesystem::perms::group_read | std::filesystem::perms::others_read; | ||
std::error_code error; | ||
std::filesystem::permissions(p, permissions, error); | ||
if (error) { | ||
std::cerr << "Failed to set access on file '" << p | ||
<< "': " << error.message() << std::endl; | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool Main(const fml::CommandLine& command_line) { | ||
fml::InstallCrashHandler(); | ||
if (command_line.HasOption("help")) { | ||
Switches::PrintHelp(std::cout); | ||
return true; | ||
} | ||
|
||
Switches switches(command_line); | ||
if (!switches.AreValid(std::cerr)) { | ||
std::cerr << "Invalid flags specified." << std::endl; | ||
Switches::PrintHelp(std::cerr); | ||
return false; | ||
} | ||
|
||
auto source_file_mapping = | ||
fml::FileMapping::CreateReadOnly(switches.source_file_name); | ||
if (!source_file_mapping) { | ||
std::cerr << "Could not open input file." << std::endl; | ||
return false; | ||
} | ||
|
||
fb::MeshT mesh; | ||
bool success = false; | ||
switch (switches.input_type) { | ||
case SourceType::kGLTF: | ||
success = ParseGLTF(*source_file_mapping, mesh); | ||
break; | ||
case SourceType::kUnknown: | ||
std::cerr << "Unknown input type." << std::endl; | ||
return false; | ||
} | ||
if (!success) { | ||
std::cerr << "Failed to parse input file." << std::endl; | ||
return false; | ||
} | ||
|
||
flatbuffers::FlatBufferBuilder builder; | ||
builder.Finish(fb::Mesh::Pack(builder, &mesh)); | ||
|
||
auto output_file_name = std::filesystem::absolute( | ||
std::filesystem::current_path() / switches.output_file_name); | ||
fml::NonOwnedMapping mapping(builder.GetCurrentBufferPointer(), | ||
builder.GetSize()); | ||
if (!fml::WriteAtomically(*switches.working_directory, | ||
compiler::Utf8FromPath(output_file_name).c_str(), | ||
mapping)) { | ||
std::cerr << "Could not write file to " << switches.output_file_name | ||
<< std::endl; | ||
return false; | ||
} | ||
|
||
// Tools that consume the geometry data expect the access mode to be 0644. | ||
if (!SetPermissiveAccess(output_file_name)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} // namespace importer | ||
} // namespace scene | ||
} // namespace impeller | ||
|
||
int main(int argc, char const* argv[]) { | ||
return impeller::scene::importer::Main( | ||
fml::CommandLineFromPlatformOrArgcArgv(argc, argv)) | ||
? EXIT_SUCCESS | ||
: EXIT_FAILURE; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// 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. | ||
|
||
namespace impeller.fb; | ||
|
||
struct Vec2 { | ||
x: float; | ||
y: float; | ||
} | ||
|
||
struct Vec3 { | ||
x: float; | ||
y: float; | ||
z: float; | ||
} | ||
|
||
struct Color { | ||
r: float; | ||
g: float; | ||
b: float; | ||
} | ||
|
||
struct Vertex { | ||
position: Vec3; | ||
normal: Vec3; | ||
tangent: Vec3; | ||
texture_coords: Vec2; | ||
} | ||
|
||
table Mesh { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll probably have to sketch this out some more but this is a start! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, one triangle mesh to fake it till we make it. Materials, fuller scene description, bones, weights, and animation will all be necessary soon in my estimation. :) |
||
vertices: [Vertex]; | ||
indices: [uint16]; | ||
} | ||
|
||
root_type Mesh; | ||
file_identifier "IPME"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: On naming, perhaps just
scenec
likeimpellerc
.importer
is rather generic.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah,
scenec
seems good. My mind kept getting stuck ongeometryc
which I didn't like very much.