9
9
#include " str-util.hh"
10
10
#include " io-util.hh"
11
11
12
+ #include " tydra/scene-access.hh"
13
+
12
14
struct CompositionFeatures {
13
15
bool subLayers{true };
14
16
bool inherits{true };
@@ -31,9 +33,8 @@ static std::string str_tolower(std::string s) {
31
33
return s;
32
34
}
33
35
34
- int main (int argc, char **argv) {
35
- if (argc < 2 ) {
36
- std::cout << " Usage tusdcat [--flatten] [--composition=STRLIST] [--relative] [--extract-variants] input.usda/usdc/usdz\n " ;
36
+ void print_help () {
37
+ std::cout << " Usage tusdcat [--flatten] [--composition=STRLIST] [--relative] [--extract-variants] [--parse-only] input.usda/usdc/usdz\n " ;
37
38
std::cout << " \n --flatten (not fully implemented yet) Do composition(load sublayers, refences, payload, evaluate `over`, inherit, variants..)" ;
38
39
std::cout << " --composition: Specify which composition feature to be "
39
40
" enabled(valid when `--flatten` is supplied). Comma separated "
@@ -43,12 +44,20 @@ int main(int argc, char **argv) {
43
44
" --composition=r,p --composition=references,subLayers\n " ;
44
45
std::cout << " \n --extract-variants (w.i.p) Dump variants information to .json\n " ;
45
46
std::cout << " \n --relative (not implemented yet) Print Path as relative Path\n " ;
47
+ std::cout << " \n --parse-only Parse USD file only(Check if input USD is valid or not)\n " ;
48
+
49
+ }
50
+
51
+ int main (int argc, char **argv) {
52
+ if (argc < 2 ) {
53
+ print_help ();
46
54
return EXIT_FAILURE;
47
55
}
48
56
49
57
bool has_flatten{false };
50
58
bool has_relative{false };
51
59
bool has_extract_variants{false };
60
+ bool parse_only{false };
52
61
53
62
constexpr int kMaxIteration = 128 ;
54
63
@@ -59,10 +68,15 @@ int main(int argc, char **argv) {
59
68
60
69
for (size_t i = 1 ; i < argc; i++) {
61
70
std::string arg = argv[i];
62
- if (arg.compare (" --flatten" ) == 0 ) {
71
+ if ((arg.compare (" -h" ) == 0 ) || (arg.compare (" --help" ) ==0 )) {
72
+ print_help ();
73
+ return EXIT_FAILURE;
74
+ } else if (arg.compare (" --flatten" ) == 0 ) {
63
75
has_flatten = true ;
64
76
} else if (arg.compare (" --relative" ) == 0 ) {
65
77
has_relative = true ;
78
+ } else if (arg.compare (" --parse-only" ) == 0 ) {
79
+ parse_only = true ;
66
80
} else if (arg.compare (" --extract-variants" ) == 0 ) {
67
81
has_extract_variants = true ;
68
82
} else if (tinyusdz::startsWith (arg, " --composition=" )) {
@@ -119,6 +133,11 @@ int main(int argc, char **argv) {
119
133
120
134
if (has_flatten) {
121
135
136
+ if (parse_only) {
137
+ std::cerr << " --flatten and --parse-only cannot be specified at a time\n " ;
138
+ return EXIT_FAILURE;
139
+ }
140
+
122
141
// TODO: flatten for USDZ
123
142
if (tinyusdz::IsUSDZ (filepath)) {
124
143
@@ -305,6 +324,7 @@ int main(int argc, char **argv) {
305
324
std::cout << " # of composition iteration to resolve fully: " << (i + 1 ) << " \n " ;
306
325
break ;
307
326
}
327
+
308
328
}
309
329
310
330
if (has_extract_variants) {
@@ -317,80 +337,51 @@ int main(int argc, char **argv) {
317
337
318
338
}
319
339
320
- } else {
340
+ tinyusdz::Stage comp_stage;
341
+ ret = LayerToStage (src_layer, &comp_stage, &warn, &err);
342
+ if (warn.size ()) {
343
+ std::cout << warn<< " \n " ;
344
+ }
321
345
322
- tinyusdz::Stage stage;
346
+ if (!ret) {
347
+ std::cerr << err << " \n " ;
348
+ }
349
+
350
+ std::cout << comp_stage.ExportToString () << " \n " ;
323
351
324
- if (ext.compare (" usdc" ) == 0 ) {
325
- tinyusdz::USDLoadOptions options;
326
- options.do_composition = has_flatten;
352
+ using MeshMap = std::map<std::string, const tinyusdz::GeomMesh *>;
353
+ MeshMap meshmap;
327
354
328
- bool ret = tinyusdz::LoadUSDCFromFile (filepath, &stage, &warn, &err, options);
329
- if (!warn.empty ()) {
330
- std::cerr << " WARN : " << warn << " \n " ;
331
- }
332
- if (!err.empty ()) {
333
- std::cerr << " ERR : " << err << " \n " ;
334
- // return EXIT_FAILURE;
335
- }
355
+ tinyusdz::tydra::ListPrims (comp_stage, meshmap);
336
356
337
- if (!ret) {
338
- std::cerr << " Failed to load USDC file: " << filepath << " \n " ;
339
- return EXIT_FAILURE;
340
- }
341
- } else if (ext.compare (" usda" ) == 0 ) {
342
- tinyusdz::USDLoadOptions options;
343
- options.do_composition = has_flatten;
357
+ for (const auto &item : meshmap) {
344
358
345
- bool ret = tinyusdz::LoadUSDAFromFile (filepath, &stage, &warn, &err, options);
346
- if (!warn.empty ()) {
347
- std::cerr << " WARN : " << warn << " \n " ;
348
- }
349
- if (!err.empty ()) {
350
- std::cerr << " ERR : " << err << " \n " ;
351
- // return EXIT_FAILURE;
352
- }
359
+ std::cout << " Prim : " << item.first << " \n " ;
360
+ }
353
361
354
- if (!ret) {
355
- std::cerr << " Failed to load USDA file: " << filepath << " \n " ;
356
- return EXIT_FAILURE;
357
- }
358
- } else if (ext.compare (" usdz" ) == 0 ) {
359
- if (has_flatten) {
360
- std::cout << " --flatten is ignored for USDZ model at the moment.\n " ;
361
- }
362
- // std::cout << "usdz\n";
363
- bool ret = tinyusdz::LoadUSDZFromFile (filepath, &stage, &warn, &err);
364
- if (!warn.empty ()) {
365
- std::cerr << " WARN : " << warn << " \n " ;
366
- }
367
- if (!err.empty ()) {
368
- std::cerr << " ERR : " << err << " \n " ;
369
- // return EXIT_FAILURE;
370
- }
362
+ } else {
371
363
372
- if (!ret) {
373
- std::cerr << " Failed to load USDZ file: " << filepath << " \n " ;
374
- return EXIT_FAILURE;
375
- }
376
- } else {
377
- tinyusdz::USDLoadOptions options;
378
- options.do_composition = has_flatten;
364
+ tinyusdz::Stage stage;
379
365
380
- // try to auto detect format.
381
- bool ret = tinyusdz::LoadUSDFromFile (filepath, &stage, &warn, &err, options);
382
- if (!warn.empty ()) {
383
- std::cerr << " WARN : " << warn << " \n " ;
384
- }
385
- if (!err.empty ()) {
386
- std::cerr << " ERR : " << err << " \n " ;
387
- // return EXIT_FAILURE;
388
- }
366
+ tinyusdz::USDLoadOptions options;
389
367
390
- if (!ret) {
391
- std::cerr << " Failed to load USD file: " << filepath << " \n " ;
392
- return EXIT_FAILURE;
393
- }
368
+ // auto detect format.
369
+ bool ret = tinyusdz::LoadUSDFromFile (filepath, &stage, &warn, &err, options);
370
+ if (!warn.empty ()) {
371
+ std::cerr << " WARN : " << warn << " \n " ;
372
+ }
373
+ if (!err.empty ()) {
374
+ std::cerr << " ERR : " << err << " \n " ;
375
+ // return EXIT_FAILURE;
376
+ }
377
+
378
+ if (!ret) {
379
+ std::cerr << " Failed to load USD file: " << filepath << " \n " ;
380
+ return EXIT_FAILURE;
381
+ }
382
+
383
+ if (parse_only) {
384
+ return EXIT_SUCCESS;
394
385
}
395
386
396
387
std::string s = stage.ExportToString (has_relative);
0 commit comments