vv
This commit is contained in:
parent
a2f5121a52
commit
a8f658b0cf
2 changed files with 70 additions and 11 deletions
30
build.zig
30
build.zig
|
|
@ -36,8 +36,9 @@ pub fn build(b: *std.Build) void {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
simdjson_lib.addIncludePath(simdjson_dep.path("singleheader"));
|
simdjson_lib.addIncludePath(simdjson_dep.path("singleheader"));
|
||||||
|
b.installArtifact(simdjson_lib);
|
||||||
|
|
||||||
const lib: *std.Build.Step.Compile = switch (preferred_link_mode) {
|
const fastgltf_lib: *std.Build.Step.Compile = switch (preferred_link_mode) {
|
||||||
inline else => |x| switch (x) {
|
inline else => |x| switch (x) {
|
||||||
.static => std.Build.addStaticLibrary,
|
.static => std.Build.addStaticLibrary,
|
||||||
.dynamic => std.Build.addSharedLibrary,
|
.dynamic => std.Build.addSharedLibrary,
|
||||||
|
|
@ -49,11 +50,11 @@ pub fn build(b: *std.Build) void {
|
||||||
.link_libc = true,
|
.link_libc = true,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
lib.linkLibCpp();
|
fastgltf_lib.linkLibCpp();
|
||||||
lib.linkLibrary(simdjson_lib);
|
fastgltf_lib.linkLibrary(simdjson_lib);
|
||||||
lib.addIncludePath(fastgltf_dep.path(b.pathJoin(&.{"include"})));
|
fastgltf_lib.addIncludePath(fastgltf_dep.path(b.pathJoin(&.{"include"})));
|
||||||
lib.addIncludePath(simdjson_dep.path("include"));
|
fastgltf_lib.addIncludePath(simdjson_dep.path("include"));
|
||||||
lib.addCSourceFiles(.{
|
fastgltf_lib.addCSourceFiles(.{
|
||||||
.root = fastgltf_dep.path("."),
|
.root = fastgltf_dep.path("."),
|
||||||
.files = &(.{ "src/fastgltf.cpp", "src/base64.cpp", "src/io.cpp" }),
|
.files = &(.{ "src/fastgltf.cpp", "src/base64.cpp", "src/io.cpp" }),
|
||||||
.flags = &.{
|
.flags = &.{
|
||||||
|
|
@ -62,10 +63,17 @@ pub fn build(b: *std.Build) void {
|
||||||
b.fmt("--std={s}", .{compile_target}),
|
b.fmt("--std={s}", .{compile_target}),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
lib.root_module.addCMacro("FASTGLTF_USE_CUSTOM_SMALLVECTOR", if (use_custom_smallvec) "1" else "0");
|
fastgltf_lib.root_module.addCMacro("FASTGLTF_USE_CUSTOM_SMALLVECTOR", if (use_custom_smallvec) "1" else "0");
|
||||||
lib.root_module.addCMacro("FASTGLTF_ENABLE_DEPRECATED_EXT", if (enable_deprecated_ext) "1" else "0");
|
fastgltf_lib.root_module.addCMacro("FASTGLTF_ENABLE_DEPRECATED_EXT", if (enable_deprecated_ext) "1" else "0");
|
||||||
lib.root_module.addCMacro("FASTGLTF_DISABLE_CUSTOM_MEMORY_POOL", if (disable_custom_memory_pool) "1" else "0");
|
fastgltf_lib.root_module.addCMacro("FASTGLTF_DISABLE_CUSTOM_MEMORY_POOL", if (disable_custom_memory_pool) "1" else "0");
|
||||||
lib.root_module.addCMacro("FASTGLTF_USE_64BIT_FLOAT", if (use_64bit_float) "1" else "0");
|
fastgltf_lib.root_module.addCMacro("FASTGLTF_USE_64BIT_FLOAT", if (use_64bit_float) "1" else "0");
|
||||||
|
b.installArtifact(fastgltf_lib);
|
||||||
|
|
||||||
b.installArtifact(lib);
|
const example = b.addExecutable(.{
|
||||||
|
.name = "fastgltf-example",
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
});
|
||||||
|
example.linkLibrary(fastgltf_lib);
|
||||||
|
b.installAr
|
||||||
}
|
}
|
||||||
|
|
|
||||||
51
example/main.cpp
Normal file
51
example/main.cpp
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
#include <fastgltf/core.hpp>
|
||||||
|
#include <fastgltf/types.hpp>
|
||||||
|
|
||||||
|
bool load(std::filesystem::path path) {
|
||||||
|
// Creates a Parser instance. Optimally, you should reuse this across loads,
|
||||||
|
// but don't use it across threads. To enable extensions, you have to pass
|
||||||
|
// them into the parser's constructor.
|
||||||
|
fastgltf::Parser parser;
|
||||||
|
|
||||||
|
// The GltfDataBuffer class contains static factories which create a buffer
|
||||||
|
// for holding the glTF data. These return Expected<GltfDataBuffer>, which can
|
||||||
|
// be checked if an error occurs. The parser accepts any subtype of
|
||||||
|
// GltfDataGetter, which defines an interface for reading chunks of the glTF
|
||||||
|
// file for the Parser to handle. fastgltf provides a few predefined classes
|
||||||
|
// which inherit from GltfDataGetter, so choose whichever fits your usecase
|
||||||
|
// the best.
|
||||||
|
auto data = fastgltf::GltfDataBuffer::FromPath(path);
|
||||||
|
if (data.error() != fastgltf::Error::None) {
|
||||||
|
// The file couldn't be loaded, or the buffer could not be allocated.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This loads the glTF file into the gltf object and parses the JSON.
|
||||||
|
// It automatically detects whether this is a JSON-based or binary glTF.
|
||||||
|
// If you know the type, you can also use loadGltfJson or loadGltfBinary.
|
||||||
|
auto asset =
|
||||||
|
parser.loadGltf(data.get(), path.parent_path(), fastgltf::Options::None);
|
||||||
|
if (auto error = asset.error(); error != fastgltf::Error::None) {
|
||||||
|
// Some error occurred while reading the buffer, parsing the JSON, or
|
||||||
|
// validating the data.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The glTF 2.0 asset is now ready to be used. Simply call asset.get(),
|
||||||
|
// asset.get_if() or asset-> to get a direct reference to the Asset class. You
|
||||||
|
// can then access the glTF data structures, like, for example, with buffers:
|
||||||
|
for (auto &buffer : asset->buffers) {
|
||||||
|
// Process the buffers.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Optionally, you can now also call the fastgltf::validate method. This will
|
||||||
|
// more strictly enforce the glTF spec and is not needed most of the time,
|
||||||
|
// though I would certainly recommend it in a development environment or when
|
||||||
|
// debugging to avoid mishaps.
|
||||||
|
|
||||||
|
// fastgltf::validate(asset.get());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { return 0; }
|
||||||
Loading…
Add table
Add a link
Reference in a new issue