From 07f05cad0400234497ddd4a5e242c73b8d3e99aa Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Sun, 21 Jul 2024 21:48:58 +0900 Subject: [PATCH] Allow skipping unknown apiSchema by default. --- src/tinyusdz.cc | 18 ++++++++++-------- src/usda-reader.cc | 4 +++- tests/usda/apishcema-002.usda | 16 ++++++++++++++++ tests/usdc/apischema-002.usdc | Bin 0 -> 900 bytes 4 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 tests/usda/apishcema-002.usda create mode 100644 tests/usdc/apischema-002.usdc diff --git a/src/tinyusdz.cc b/src/tinyusdz.cc index 329da318..1c186996 100644 --- a/src/tinyusdz.cc +++ b/src/tinyusdz.cc @@ -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); @@ -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()) { @@ -1250,7 +1252,7 @@ int USDZResolveAsset(const char *asset_name, const std::vector &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, "./"); } @@ -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; @@ -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(const_cast(pusdzAsset)); - + resolver.register_asset_resolution_handler("png", handler); resolver.register_asset_resolution_handler("PNG", handler); resolver.register_asset_resolution_handler("JPG", handler); @@ -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; } diff --git a/src/usda-reader.cc b/src/usda-reader.cc index bc98e8d6..b2d6e302 100644 --- a/src/usda-reader.cc +++ b/src/usda-reader.cc @@ -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 { diff --git a/tests/usda/apishcema-002.usda b/tests/usda/apishcema-002.usda new file mode 100644 index 00000000..0ca46331 --- /dev/null +++ b/tests/usda/apishcema-002.usda @@ -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 +} diff --git a/tests/usdc/apischema-002.usdc b/tests/usdc/apischema-002.usdc new file mode 100644 index 0000000000000000000000000000000000000000..bdb0fa7de4df7a89a1f76dbf2724a37a813387b8 GIT binary patch literal 900 zcmbtSOK;Oa5dNIz;nXQm)Cd(Wxo{|IC8BaF617P}8qo%;aZ$LSy788*YI`kv4fIyH zAR#2gksCh&i7O|51b=`d5(-cuBpzWMuL(lp#7MK>%zU#m`xvvoy|UA5HlSi6uX8E> z@2bcGd4aWpbTok#p>sk{2t6q@>o+g#(?VA#@_GHNuoHQg0^Ul*h+SS;f=4(BBa?(X zKIOQDI56(h2t(q!3=Y}1W0#vD^$>`qF{G{&5+8^HGNAjEglI6IfFA~=YkLG6EOw|* zZ&GqEU?FeE)FFo1L7Omdi#fzioGr#F^Jj5&lSW*{r8`4Dhc|XWdxIhI>M17`=~0C(+>+I!Tc{1E+DID*6CJ(py6o4iQkEM$>UE_oostQHid zIHP>2e5%~exEH|DI#AYgP;gPx^CcM2^uCJur6Nq=f?iHTj*5B>4^-r9s4IH)6zZC; zh~Tn*M#ZY8FRD;Vc!_2G*`#{;_X(<5x6w@Ur%GYLH1NIfwR~L8e@uQikqqS!0lSl2 z%%-$BXGvJrkN4wgB*|!v@$+AMr?rytQU0zq{)VEgZr!-v>h`1~;JGwENbFhLoo;)Y z@JJ44*5O*Gwb`7~cq;kFa(~LVtSn_w&g^-~n})TKaY^Wk