Skip to content

Commit

Permalink
Allow skipping unknown apiSchema by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
syoyo committed Jul 21, 2024
1 parent 95bbe51 commit 07f05ca
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
18 changes: 10 additions & 8 deletions src/tinyusdz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -648,9 +648,10 @@ bool LoadUSDAFromMemory(const uint8_t *addr, const size_t length,

tinyusdz::StreamReader sr(addr, length, /* swap endian */ false);
tinyusdz::usda::USDAReader reader(&sr);

tinyusdz::usda::USDAReaderConfig config;
config.strict_allowedToken_check = options.strict_allowedToken_check;
config.allow_unknown_apiSchema = !options.strict_apiSchema_check;
reader.set_reader_config(config);

reader.SetBaseDir(base_dir);
Expand Down Expand Up @@ -987,6 +988,7 @@ bool LoadUSDCLayerFromMemory(const uint8_t *addr, const size_t length,
usdc::USDCReaderConfig config;
config.numThreads = options.num_threads;
config.strict_allowedToken_check = options.strict_allowedToken_check;
config.allow_unknown_apiSchemas = !options.strict_apiSchema_check;
usdc::USDCReader reader(&sr, config);

if (!reader.ReadUSDC()) {
Expand Down Expand Up @@ -1250,7 +1252,7 @@ int USDZResolveAsset(const char *asset_name, const std::vector<std::string> &sea

std::string asset_path = asset_name;

// Remove relative path prefix './'
// Remove relative path prefix './'
if (tinyusdz::startsWith(asset_path, "./")) {
asset_path = tinyusdz::removePrefix(asset_path, "./");
}
Expand Down Expand Up @@ -1391,11 +1393,11 @@ bool SetupUSDZAssetResolution(
// https://openusd.org/release/spec_usdz.html
//
// [x] Image: png, jpeg(jpg), exr
//
//
// TODO(LTE):
//
// [ ] USD: usda, usdc, usd
// [ ] Audio: m4a, mp3, wav
// [ ] USD: usda, usdc, usd
// [ ] Audio: m4a, mp3, wav

if (!pusdzAsset) {
return false;
Expand All @@ -1406,9 +1408,9 @@ bool SetupUSDZAssetResolution(
handler.resolve_fun = USDZResolveAsset;
handler.size_fun = USDZSizeAsset;
handler.read_fun = USDZReadAsset;
handler.write_fun = nullptr;
handler.write_fun = nullptr;
handler.userdata = reinterpret_cast<void *>(const_cast<USDZAsset *>(pusdzAsset));

resolver.register_asset_resolution_handler("png", handler);
resolver.register_asset_resolution_handler("PNG", handler);
resolver.register_asset_resolution_handler("JPG", handler);
Expand All @@ -1417,7 +1419,7 @@ bool SetupUSDZAssetResolution(
resolver.register_asset_resolution_handler("JPEG", handler);
resolver.register_asset_resolution_handler("exr", handler);
resolver.register_asset_resolution_handler("EXR", handler);

return true;
}

Expand Down
4 changes: 3 additions & 1 deletion src/usda-reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1069,8 +1069,10 @@ class USDAReader::Impl {
auto ret = ApiSchemaHandler(item.str());
if (ret) {
apiSchemas.names.push_back({ret.value(), /* instanceName */""});
} else {
} else if (_config.allow_unknown_apiSchema) {
PUSH_WARN("(PrimMeta) " << ret.error());
} else {
PUSH_ERROR_AND_RETURN("Unknown or invalid apiSchema: " + ret.error());
}
}
} else {
Expand Down
16 changes: 16 additions & 0 deletions tests/usda/apishcema-002.usda
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#usda 1.0
(
metersPerUnit = 1
upAxis = "Y"
defaultPrim = "hello"
)

def Cone "hello"
(
# would report warning for HoudiniViewportGuideAPI
prepend apiSchemas = ["HoudiniViewportGuideAPI", "GeomModelAPI", "MotionAPI", "ListAPI", "LightListAPI"]
)
{
uniform token axis = "X"
double height = 1.2
}
Binary file added tests/usdc/apischema-002.usdc
Binary file not shown.

0 comments on commit 07f05ca

Please sign in to comment.