Improve file size check(and return fail when opening a folder in posix environment)

Add lit&filecheck.py experiment.
This commit is contained in:
Syoyo Fujita
2023-05-23 23:03:28 +09:00
parent e285aba0b7
commit b2308d2b0a
8 changed files with 222 additions and 110 deletions

View File

@@ -0,0 +1,17 @@
## Requirements
- FileCheck.py
- and lit(LLVM Integration Tester)
## Setup
```
$ python -m pip install filecheck
$ python -m pip install lit
```
## Run
```
$ lit ctests
```

View File

@@ -0,0 +1,10 @@
/**
RUN: clang %s -o %S/hello-world && %S/hello-world | filecheck %s
CHECK: Hello world
*/
#include <stdio.h>
int main() {
printf("Hello bora\n");
return 0;
}

View File

@@ -0,0 +1,12 @@
import lit.formats
config.name = "Test"
config.suffixes = ['.c', '.cc', '.cpp']
#config.test_format = lit.formats.ShTest("0")
config.test_format = lit.formats.ShTest()
config.test_source_root = None
config.test_exec_root = None

View File

@@ -5120,7 +5120,7 @@ bool AsciiParser::Parse(const uint32_t load_states, const AsciiParserOption &par
if (c == '(') {
// stage meta.
// TODO: We could skip parsing stage meta in flatten(composition) mode.
// TODO: We could skip parsing stage meta in flatten(composition) mode?.
if (!ParseStageMetas()) {
PUSH_ERROR_AND_RETURN("Failed to parse Stage metas.");
}

View File

@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
#include <fstream>
#include <algorithm>
#include <fstream>
#ifdef _WIN32
@@ -28,12 +28,13 @@
#include <ext/stdio_filebuf.h> // fstream (all sorts of IO stuff) + stdio_filebuf (=streambuf)
#endif // __GLIBCXX__
#endif // __GLIBCXX__
#else // !_WIN32
#else // !_WIN32
#if defined(TINYUSDZ_BUILD_IOS) || defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR) || \
defined(__ANDROID__) || defined(__EMSCRIPTEN__) || defined(__wasi__)
#if defined(TINYUSDZ_BUILD_IOS) || defined(TARGET_OS_IPHONE) || \
defined(TARGET_IPHONE_SIMULATOR) || defined(__ANDROID__) || \
defined(__EMSCRIPTEN__) || defined(__wasi__)
// non posix
@@ -44,8 +45,7 @@
#endif
#endif // _WIN32
#endif // _WIN32
#ifdef __clang__
#pragma clang diagnostic push
@@ -70,9 +70,7 @@ namespace io {
AAssetManager *asset_manager = nullptr;
#endif
std::string ExpandFilePath(const std::string &_filepath, void *) {
std::string filepath = _filepath;
if (filepath.size() > 2048) {
// file path too large.
@@ -93,8 +91,9 @@ std::string ExpandFilePath(const std::string &_filepath, void *) {
#else
#if defined(TINYUSDZ_BUILD_IOS) || defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR) || \
defined(__ANDROID__) || defined(__EMSCRIPTEN__) || defined(__OpenBSD__) || defined(__wasi__)
#if defined(TINYUSDZ_BUILD_IOS) || defined(TARGET_OS_IPHONE) || \
defined(TARGET_IPHONE_SIMULATOR) || defined(__ANDROID__) || \
defined(__EMSCRIPTEN__) || defined(__OpenBSD__) || defined(__wasi__)
// no expansion
std::string s = filepath;
#else
@@ -108,8 +107,8 @@ std::string ExpandFilePath(const std::string &_filepath, void *) {
// Quote the string to keep any spaces in filepath intact.
std::string quoted_path = "\"" + filepath + "\"";
// char** w;
// TODO: wordexp() is a awful API. Implement our own file path expansion routine.
// Set NOCMD for security.
// TODO: wordexp() is a awful API. Implement our own file path expansion
// routine. Set NOCMD for security.
int ret = wordexp(quoted_path.c_str(), &p, WRDE_NOCMD);
if (ret) {
// err
@@ -151,9 +150,9 @@ std::string WcharToUTF8(const std::wstring &wstr) {
}
#endif
bool ReadWholeFile(std::vector<uint8_t> *out, std::string *err,
const std::string &filepath, size_t filesize_max, void *userdata) {
const std::string &filepath, size_t filesize_max,
void *userdata) {
(void)userdata;
#ifdef TINYUSDZ_ANDROID_LOAD_FROM_ASSETS
@@ -210,6 +209,16 @@ bool ReadWholeFile(std::vector<uint8_t> *out, std::string *err,
return false;
}
// For directory(and pipe?), peek() will fail(Posix gnustl/libc++ only)
int buf = f.peek();
(void)buf;
if (!f) {
if (err) {
(*err) += "File read error. Maybe empty file or invalid file : " + filepath + "\n";
}
return false;
}
f.seekg(0, f.end);
size_t sz = static_cast<size_t>(f.tellg());
f.seekg(0, f.beg);
@@ -225,11 +234,20 @@ bool ReadWholeFile(std::vector<uint8_t> *out, std::string *err,
(*err) += "File is empty : " + filepath + "\n";
}
return false;
} else if (uint64_t(sz) >= uint64_t(std::numeric_limits<int64_t>::max())) {
// Posixish environment.
if (err) {
(*err) += "Invalid File(Pipe or special device?) : " + filepath + "\n";
}
return false;
}
if ((filesize_max > 0) && (sz > filesize_max)) {
if (err) {
(*err) += "File size is too large : " + filepath + " sz = " + std::to_string(sz) + "\n";
(*err) += "File size is too large : " + filepath +
" sz = " + std::to_string(sz) +
", allowed max filesize = " + std::to_string(filesize_max) +
"\n";
}
return false;
}
@@ -238,16 +256,26 @@ bool ReadWholeFile(std::vector<uint8_t> *out, std::string *err,
f.read(reinterpret_cast<char *>(&out->at(0)),
static_cast<std::streamsize>(sz));
if (!f) {
// read failure.
if (err) {
(*err) += "Failed to read file: " + filepath + "\n";
}
return false;
}
return true;
#endif
}
bool ReadFileHeader(std::vector<uint8_t> *out, std::string *err,
const std::string &filepath, uint32_t max_read_bytes, void *userdata) {
const std::string &filepath, uint32_t max_read_bytes,
void *userdata) {
(void)userdata;
// hard limit to 1MB.
max_read_bytes = (std::max)(1u, (std::min)(uint32_t(1024*1024), max_read_bytes));
max_read_bytes =
(std::max)(1u, (std::min)(uint32_t(1024 * 1024), max_read_bytes));
#ifdef TINYUSDZ_ANDROID_LOAD_FROM_ASSETS
if (tinyusdz::io::asset_manager) {
@@ -305,6 +333,17 @@ bool ReadFileHeader(std::vector<uint8_t> *out, std::string *err,
return false;
}
// For directory(and pipe?), peek() will fail(Posix gnustl/libc++ only)
int buf = f.peek();
(void)buf;
if (!f) {
if (err) {
(*err) += "File read error. Maybe empty file or invalid file : " + filepath + "\n";
}
return false;
}
f.seekg(0, f.end);
size_t sz = static_cast<size_t>(f.tellg());
f.seekg(0, f.beg);
@@ -320,6 +359,12 @@ bool ReadFileHeader(std::vector<uint8_t> *out, std::string *err,
(*err) += "File is empty : " + filepath + "\n";
}
return false;
} else if (uint64_t(sz) >= uint64_t(std::numeric_limits<int64_t>::max())) {
// Posixish environment.
if (err) {
(*err) += "Invalid File(Pipe or special device?) : " + filepath + "\n";
}
return false;
}
sz = (std::min)(size_t(max_read_bytes), sz);
@@ -328,12 +373,20 @@ bool ReadFileHeader(std::vector<uint8_t> *out, std::string *err,
f.read(reinterpret_cast<char *>(&out->at(0)),
static_cast<std::streamsize>(sz));
if (!f) {
// read failure.
if (err) {
(*err) += "Failed to read file: " + filepath + "\n";
}
return false;
}
return true;
#endif
}
bool WriteWholeFile(const std::string &filepath,
const unsigned char *contents, size_t content_bytes, std::string *err) {
bool WriteWholeFile(const std::string &filepath, const unsigned char *contents,
size_t content_bytes, std::string *err) {
#ifdef _WIN32
#if defined(__GLIBCXX__) // mingw
int file_descriptor = _wopen(UTF8ToWchar(filepath).c_str(),
@@ -369,11 +422,11 @@ bool WriteWholeFile(const std::string &filepath,
}
#ifdef _WIN32
bool WriteWholeFile(const std::wstring &filepath,
const unsigned char *contents, size_t content_bytes, std::string *err) {
bool WriteWholeFile(const std::wstring &filepath, const unsigned char *contents,
size_t content_bytes, std::string *err) {
#if defined(__GLIBCXX__) // mingw
int file_descriptor = _wopen(filepath.c_str(),
_O_CREAT | _O_WRONLY | _O_TRUNC | _O_BINARY);
int file_descriptor =
_wopen(filepath.c_str(), _O_CREAT | _O_WRONLY | _O_TRUNC | _O_BINARY);
__gnu_cxx::stdio_filebuf<char> wfile_buf(
file_descriptor, std::ios_base::out | std::ios_base::binary);
std::ostream f(&wfile_buf);
@@ -420,8 +473,7 @@ std::string GetFileExtension(const std::string &FileName) {
std::string GetBaseFilename(const std::string &filepath) {
auto idx = filepath.find_last_of("/\\");
if (idx != std::string::npos)
return filepath.substr(idx + 1);
if (idx != std::string::npos) return filepath.substr(idx + 1);
return filepath;
}
@@ -459,7 +511,7 @@ std::string JoinPath(const std::string &dir, const std::string &filename) {
}
bool USDFileExists(const std::string &fpath) {
size_t read_len = 9; // USD file must be at least 9 bytes or more.
size_t read_len = 9; // USD file must be at least 9 bytes or more.
std::string err;
std::vector<uint8_t> data;
@@ -469,16 +521,14 @@ bool USDFileExists(const std::string &fpath) {
}
return true;
}
bool IsUDIMPath(const std::string &path)
{
bool IsUDIMPath(const std::string &path) {
return SplitUDIMPath(path, nullptr, nullptr);
}
bool SplitUDIMPath(const std::string &path, std::string *pre, std::string *post)
{
bool SplitUDIMPath(const std::string &path, std::string *pre,
std::string *post) {
std::string tag = "<UDIM>";
auto rs = std::search(path.begin(), path.end(), tag.begin(), tag.end());
@@ -553,8 +603,8 @@ bool FileExists(const std::string &filepath, void *userdata) {
return ret;
}
std::string FindFile(const std::string &filename, const std::vector<std::string> &search_paths) {
std::string FindFile(const std::string &filename,
const std::vector<std::string> &search_paths) {
// TODO: Use ghc filesystem?
if (filename.empty()) {
@@ -562,16 +612,15 @@ std::string FindFile(const std::string &filename, const std::vector<std::string>
}
for (size_t i = 0; i < search_paths.size(); i++) {
std::string absPath =
io::ExpandFilePath(io::JoinPath(search_paths[i], filename), /* userdata */nullptr);
if (io::FileExists(absPath, /* userdata */nullptr)) {
std::string absPath = io::ExpandFilePath(
io::JoinPath(search_paths[i], filename), /* userdata */ nullptr);
if (io::FileExists(absPath, /* userdata */ nullptr)) {
return absPath;
}
}
return std::string();
}
} // namespace io
} // namespace tinyusdz
} // namespace io
} // namespace tinyusdz

View File

@@ -401,7 +401,7 @@ bool Stage::find_prim_from_relative_path(const Prim &root,
}
}
bool Stage::LoadLayerFromMemory(const uint8_t *addr, const size_t nbytes, const std::string &asset_name, const LoadState load_state, Layer *layer) {
bool Stage::LoadLayerFromMemory(const uint8_t *addr, const size_t nbytes, const std::string &asset_name, Layer *layer, const uint32_t load_states) {
// TODO: USDC/USDZ support.
@@ -411,18 +411,18 @@ bool Stage::LoadLayerFromMemory(const uint8_t *addr, const size_t nbytes, const
// TODO: Uase AssetResolver
//reader.SetBaseDir(base_dir);
if (!reader.Read(load_state)) {
if (!reader.read(load_states)) {
return false;
}
if (!reader.GetAsLayer(layer)) {
if (!reader.get_as_layer(layer)) {
PUSH_ERROR_AND_RETURN("Failed to retrieve USD data as Layer: filepath = " << asset_name);
}
return false;
}
bool Stage::LoadLayerFromFile(const std::string &_filename, const LoadState load_state, Layer *layer) {
bool Stage::LoadLayerFromFile(const std::string &_filename, Layer *layer, const uint32_t load_states) {
// TODO: Setup AssetResolver.
std::string filepath = io::ExpandFilePath(_filename, /* userdata */ nullptr);
@@ -438,7 +438,7 @@ bool Stage::LoadLayerFromFile(const std::string &_filename, const LoadState load
PUSH_ERROR_AND_RETURN("Read file failed: " + err);
}
return LoadLayerFromMemory(data.data(), data.size(), filepath, load_state, layer);
return LoadLayerFromMemory(data.data(), data.size(), filepath, layer, load_states);
}
bool Stage::LoadSubLayers(std::vector<Layer> *sublayers) {
@@ -457,7 +457,7 @@ void PrimPrintRec(std::stringstream &ss, const Prim &prim, uint32_t indent) {
bool require_newline = true;
// Check last 2 chars.
// if it ends with '{\n', no properties are authored so do not emit blank line before printing VariantSet or child Prims.
// if it ends with '{\n', no properties are authored so do not emit blank line before printing VariantSet or child Prims.
if (s.size() > 2) {
if ((s[s.size() - 2] == '{') && (s[s.size()-1] == '\n')) {
require_newline = false;
@@ -465,7 +465,7 @@ void PrimPrintRec(std::stringstream &ss, const Prim &prim, uint32_t indent) {
}
ss << s;
//
// print variant
//
@@ -496,7 +496,7 @@ void PrimPrintRec(std::stringstream &ss, const Prim &prim, uint32_t indent) {
ss << print_props(variant.properties(), indent+3);
if (variant.metas().variantChildren.has_value() &&
if (variant.metas().variantChildren.has_value() &&
(variant.metas().variantChildren.value().size() == variant.primChildren().size())) {
std::map<std::string, const Prim *> primNameTable;
@@ -525,13 +525,13 @@ void PrimPrintRec(std::stringstream &ss, const Prim &prim, uint32_t indent) {
ss << "\n";
}
}
}
ss << pprint::Indent(indent+2) << "}\n";
}
ss << pprint::Indent(indent+1) << "}\n";
}
}

View File

@@ -4,8 +4,8 @@
// Stage: Similar to Scene or Scene graph
#pragma once
#include "prim-types.hh"
#include "composition.hh"
#include "prim-types.hh"
namespace tinyusdz {
@@ -15,25 +15,35 @@ struct StageMetas {
PlaybackModeNone,
PlaybackModeLoop,
};
// TODO: Support more predefined properties: reference = <pxrUSD>/pxr/usd/sdf/wrapLayer.cpp
// Scene global setting
TypedAttributeWithFallback<Axis> upAxis{Axis::Y}; // This can be changed by plugInfo.json in USD: https://graphics.pixar.com/usd/dev/api/group___usd_geom_up_axis__group.html#gaf16b05f297f696c58a086dacc1e288b5
value::token defaultPrim; // prim node name
TypedAttributeWithFallback<double> metersPerUnit{1.0}; // default [m]
TypedAttributeWithFallback<double> timeCodesPerSecond {24.0}; // default 24 fps
TypedAttributeWithFallback<double> framesPerSecond {24.0}; // FIXME: default 24 fps
TypedAttributeWithFallback<double> startTimeCode{0.0}; // FIXME: default = -inf?
TypedAttributeWithFallback<double> endTimeCode{std::numeric_limits<double>::infinity()};
std::vector<value::AssetPath> subLayers; // `subLayers`
value::StringData comment; // 'comment' In Stage meta, comment must be string only(`comment = "..."` is not allowed)
value::StringData doc; // `documentation`
CustomDataType customLayerData; // customLayerData
// TODO: Support more predefined properties: reference =
// <pxrUSD>/pxr/usd/sdf/wrapLayer.cpp Scene global setting
TypedAttributeWithFallback<Axis> upAxis{
Axis::
Y}; // This can be changed by plugInfo.json in USD:
// https://graphics.pixar.com/usd/dev/api/group___usd_geom_up_axis__group.html#gaf16b05f297f696c58a086dacc1e288b5
value::token defaultPrim; // prim node name
TypedAttributeWithFallback<double> metersPerUnit{1.0}; // default [m]
TypedAttributeWithFallback<double> timeCodesPerSecond{
24.0}; // default 24 fps
TypedAttributeWithFallback<double> framesPerSecond{
24.0}; // FIXME: default 24 fps
TypedAttributeWithFallback<double> startTimeCode{
0.0}; // FIXME: default = -inf?
TypedAttributeWithFallback<double> endTimeCode{
std::numeric_limits<double>::infinity()};
std::vector<value::AssetPath> subLayers; // `subLayers`
value::StringData comment; // 'comment' In Stage meta, comment must be string
// only(`comment = "..."` is not allowed)
value::StringData doc; // `documentation`
CustomDataType customLayerData; // customLayerData
// USDZ extension
TypedAttributeWithFallback<bool> autoPlay{true}; // default(or not authored) = auto play
TypedAttributeWithFallback<PlaybackMode> playbackMode{PlaybackMode::PlaybackModeLoop};
TypedAttributeWithFallback<bool> autoPlay{
true}; // default(or not authored) = auto play
TypedAttributeWithFallback<PlaybackMode> playbackMode{
PlaybackMode::PlaybackModeLoop};
// Indirectly used.
std::vector<value::token> primChildren;
@@ -44,11 +54,8 @@ class PrimRange;
// Similar to UsdStage, but much more something like a Scene(scene graph)
class Stage {
public:
// pxrUSD compat API ----------------------------------------
static Stage CreateInMemory() {
return Stage();
}
static Stage CreateInMemory() { return Stage(); }
///
/// Traverse by depth-first order.
@@ -60,9 +67,11 @@ class Stage {
/// Get Prim at a Path.
/// Path must be absolute Path.
///
/// @returns Const pointer to Prim(to avoid a copy). Never returns nullptr upon success.
/// @returns Const pointer to Prim(to avoid a copy). Never returns nullptr
/// upon success.
///
nonstd::expected<const Prim *, std::string> GetPrimAtPath(const Path &path) const;
nonstd::expected<const Prim *, std::string> GetPrimAtPath(
const Path &path) const;
///
/// pxrUSD Compat API
@@ -82,10 +91,11 @@ class Stage {
/// Get Prim from a children of given root Prim.
/// Path must be relative Path.
///
/// @returns pointer to Prim(to avoid a copy). Never return nullptr upon success.
/// @returns pointer to Prim(to avoid a copy). Never return nullptr upon
/// success.
///
nonstd::expected<const Prim *, std::string> GetPrimFromRelativePath(const Prim &root, const Path &path) const;
nonstd::expected<const Prim *, std::string> GetPrimFromRelativePath(
const Prim &root, const Path &path) const;
/// Find(Get) Prim at a Path.
/// Path must be absolute Path.
@@ -95,7 +105,8 @@ class Stage {
/// @param[out] err Error message(filled when false is returned)
///
/// @returns true if found a Prim.
bool find_prim_at_path(const Path &path, const Prim *&prim, std::string *err = nullptr) const;
bool find_prim_at_path(const Path &path, const Prim *&prim,
std::string *err = nullptr) const;
/// Find(Get) Prim at a Path and returns its Prim id.
/// Path must be absolute Path.
@@ -105,7 +116,8 @@ class Stage {
/// @param[out] err Error message(filled when false is returned)
///
/// @returns true if found a Prim.
bool find_prim_at_path(const Path &path, int64_t *prim_id, std::string *err = nullptr) const;
bool find_prim_at_path(const Path &path, int64_t *prim_id,
std::string *err = nullptr) const;
/// Find(Get) Prim from a relative Path.
/// Path must be relative Path.
@@ -116,51 +128,47 @@ class Stage {
/// @param[out] err Error message(filled when false is returned)
///
/// @returns true if found a Prim.
bool find_prim_from_relative_path(const Prim &root, const Path &relative_path, const Prim *&prim, std::string *err) const;
bool find_prim_from_relative_path(const Prim &root, const Path &relative_path,
const Prim *&prim, std::string *err) const;
///
/// Find(Get) Prim from Prim ID. Prim with no Prim ID assigned(-1 or 0) are ignored.
/// Find(Get) Prim from Prim ID. Prim with no Prim ID assigned(-1 or 0) are
/// ignored.
///
/// @param[in] prim_id Prim ID(1 or greater)
/// @param[out] prim const reference to the pointer to Prim(if found)
/// @param[out] err Error message(filled when false is returned)
///
/// @returns true if found a Prim.
bool find_prim_by_prim_id(const uint64_t prim_id, const Prim *&prim, std::string *err = nullptr) const;
bool find_prim_by_prim_id(const uint64_t prim_id, const Prim *&prim,
std::string *err = nullptr) const;
// non-const version
bool find_prim_by_prim_id(const uint64_t prim_id, Prim *&prim, std::string *err = nullptr);
bool find_prim_by_prim_id(const uint64_t prim_id, Prim *&prim,
std::string *err = nullptr);
///
/// @brief Get Root Prims
///
/// @return Const array of Root Prims.
///
const std::vector<Prim> &root_prims() const {
return root_nodes;
}
const std::vector<Prim> &root_prims() const { return root_nodes; }
///
/// @brief Reference to Root Prims array
///
/// @return Array of Root Prims.
///
std::vector<Prim> &root_prims() {
return root_nodes;
}
std::vector<Prim> &root_prims() { return root_nodes; }
///
/// @brief Get Stage metadatum
///
/// @return Stage metadatum struct.
///
const StageMetas &metas() const {
return stage_metas;
}
const StageMetas &metas() const { return stage_metas; }
StageMetas &metas() {
return stage_metas;
}
StageMetas &metas() { return stage_metas; }
///
/// @brief Assign unique Prim id inside this Stage.
@@ -174,7 +182,8 @@ class Stage {
///
/// @brief Release Prim id inside this Stage.
///
/// @param[prim_id] prim_id Primitive ID to release(allocated by `allocate_prim_id`)
/// @param[prim_id] prim_id Primitive ID to release(allocated by
/// `allocate_prim_id`)
///
/// @return true upon success. false when given `prim_id` is an invalid id.
///
@@ -188,28 +197,34 @@ class Stage {
/// @return true if `prim_id` exists in this Stage.
///
bool has_prim_id(const uint64_t prim_id) const;
///
/// @brief Commit Stage state.
///
/// Call this function after you finished adding Prims manually(through `root_prims()`) to Stage.
/// Call this function after you finished adding Prims manually(through
/// `root_prims()`) to Stage.
///
/// (No need to call this if you just use ether USDA/USDC/USDZ reader).
///
/// - Compute absolute path and set it to Prim::abs_path for each Prim currently added to this Stage.
/// - Compute absolute path and set it to Prim::abs_path for each Prim
/// currently added to this Stage.
/// - Assign unique ID to Prim
///
/// @param[in] force_assign_prim_id true Overwrite `prim_id` of each Prim. false only assign Prim id when `prim_id` is -1(preserve user-assgiend prim_id). Setting `false` is not recommended since prim_id may not be unique over Prims in Stage.
/// @return false when the Stage contains any invalid Prim
/// @param[in] force_assign_prim_id true Overwrite `prim_id` of each Prim.
/// false only assign Prim id when `prim_id` is -1(preserve user-assgiend
/// prim_id). Setting `false` is not recommended since prim_id may not be
/// unique over Prims in Stage.
/// @return false when the Stage contains any invalid Prim
///
/// TODO: Deprecate this API an use `commit()`
bool compute_absolute_prim_path_and_assign_prim_id(bool force_assign_prim_id=true);
bool compute_absolute_prim_path_and_assign_prim_id(
bool force_assign_prim_id = true);
///
/// @brief Commit Stage state.
///
bool commit() {
// Currently we always allocate Prim ID.
// Currently we always allocate Prim ID.
return compute_absolute_prim_path_and_assign_prim_id(true);
}
@@ -218,7 +233,6 @@ class Stage {
///
bool compute_absolute_prim_path();
///
/// Dump Prim tree info(mainly for debugging).
///
@@ -230,15 +244,25 @@ class Stage {
bool compose(bool addSourceFileComment = true) const;
private:
///
/// Loads USD from and return it as Layer
///
bool LoadLayerFromFile(const std::string &filename, const LoadState load_state, Layer *layer);
/// @param[in] filename USD filename
/// @param[out] layer Layer representation of USD data.
/// @param[in] load_states Bitmask of LoadState(optional)
///
bool LoadLayerFromFile(const std::string &filename, Layer *layer, const uint32_t load_states = static_cast<uint32_t>(LoadState::Toplevel));
///
/// Loads USD asset from memory and return it as Layer
bool LoadLayerFromMemory(const uint8_t *addr, const size_t nbytes, const std::string &asset_name, const LoadState load_state, Layer *dest);
///
/// @param[in] addr Memory address
/// @param[in] nbytes Num bytes
/// @param[in] asset_name Asset name(usually filename)
/// @param[out] layer Layer representation of USD data.
/// @param[in] load_states Bitmask of LoadState(optional)
///
bool LoadLayerFromMemory(const uint8_t *addr, const size_t nbytes, const std::string &asset_name, Layer *layer, const uint32_t load_states = static_cast<uint32_t>(LoadState::Toplevel));
///
/// Loads `reference` USD asset and return it as Layer
@@ -274,11 +298,10 @@ class Stage {
mutable bool _prim_id_dirty{true}; // True when Prim Id assignent changed(TODO: Unify with `_dirty` flag)
mutable HandleAllocator<uint64_t> _prim_id_allocator;
};
inline std::string to_string(const Stage& stage) {
inline std::string to_string(const Stage &stage) {
return stage.ExportToString();
}
} // namespace tinyusdz
} // namespace tinyusdz

View File

@@ -99,6 +99,7 @@ struct USDLoadOptions {
///
/// Following load flags are valid when `do_composition` is set `true`.
///
bool load_sublayers{false}; // true: Load `subLayers`
bool load_references{false}; // true: Load `references`
bool load_payloads{false}; // true: Load `paylod` at top USD loading(no lazy loading).