Accessing Reference File Geom
Closed this issue · 14 comments
Are there any examples for gaining access to referenced file geometry?
Repro Steps
- Update usdobj-001.usda to reference suzanne.usdc:
def Mesh "suzanne" (
prepend references = @suzanne.usdc@
)
{
}
- Load USD as a Layer
bool ret = tinyusdz::LoadLayerFromFile(filepath, &root_layer, &warn, &err);
- Do compositions (it also returns a layer)
tinyusdz::CompositeReferences(resolver, src_layer, &composited_layer, &warn, &err)
- Then construct Stage (freezed state) from Layer
bool LayerToStage(const Layer &layer, Stage *stage
- Then call tinyusdz::tydra::ListPrims
std::map<std::string, const tinyusdz::GeomMesh*> meshmap;
tinyusdz::tydra::ListPrims(stage, meshmap);
Expected Results
meshmap should contain the mesh data for suzanne.usdc
Actual Result
I can see the geometry faces and vertices for suzanne are printed, but GeomMesh* meshmap
is empty
I'll call, and received back a source layer without any warnings or errors, but unsure how to extract the suzanne geometry.
You cannot reference USD in def
GeomMesh(or Prim). pxrUSD's usdcat reports error. You should use subLayers
in Stage metadata.
You can import .obj throughreference
in TinyUSDZ,
tusdcat usdobj-001.usda --flatten
but this is tinyusdz's usdObj extension, so the behavior may be different compared to pxrUSD(OpenUSD)'s usdObj.
And as you may see the tusdcat code, if you do the composition,
- you first need to load USD as a Layer,
- then do compositions(it also produces Layer)
- then construct Stage(freezed state) from Layer
Line 210 in 910c574
- then call
tinyusdz::tydra::ListPrims
You should use subLayers in Stage metadata.
Ah, I forgot referencing usd through over
Prim is possible. But its a bit complicated.
https://openusd.org/release/glossary.html#usdglossary-layerstack
Thank you!
And as you may see the tusdcat code, if you do the composition,
- you first need to load USD as a Layer,
- then do compositions(it also produces Layer)
- then construct Stage(freezed state) from Layer
Line 210 in 910c574
- then call
tinyusdz::tydra::ListPrims
I've used the tusdcat with --flatten --composition=r
and get src_layer
I then attempt to get geom, but meshmap is still empty.
tinyusdz::LayerToStage(src_layer, &stage, &warn, &err);
std::map<std::string, const tinyusdz::GeomMesh*> meshmap;
tinyusdz::tydra::ListPrims(stage, meshmap);
You should not post unreproducible thing. You should post an issue with reproducible procedures and minimal test files/code. And you should first dump composited Stage(Stage::ExportToString) and confirm it contains GeomMesh
Good. but Mesh
in Mesh
in the screenshot is invalid USD.
def Mesh "suzanne" (
prepend references = @suzanne.usdc@
)
{
}
TinyUSDZ should report error/warning when referencing usd
in def
Prim without prim path, so this should be a tinyusdz's bug.
And you are better to use subLayers for a while if you want to include USD scene
https://openusd.org/release/glossary.html#usdglossary-sublayers
FYI OpenUSD's usdcat --flatten
's result.
usdcat --flatten test.usda
Warning: in _ReportErrors at line 2971 of /home/syoyo/work/USD/pxr/usd/usd/stage.cpp -- In </bora>: Unresolved reference prim path @/home/syoyo/work/tinyusdz/models/suzanne.usdc@<defaultPrim> introduced by @test.usda@</bora> (instantiating stage on stage @test.usda@ <0x56496380db40>)
#usda 1.0
(
doc = """Generated from Composed Stage of root layer /home/syoyo/work/tinyusdz/models/test.usda """
)
def Mesh "bora" {
}
Further FYI, specify the prim path(which Prim path is referenced) as shown below should work both for usdcat and tinyusdz
def Mesh "suzanne" (
prepend references = @suzanne.usdc@</Suzanne/Suzanne>
)
{
}
Then you'll be able to find GeomMesh in tydra::ListPrim
Ah, that makes sense... I can validate that /Suzanne/Suzanne hierarchy inside of Omniverse USDComposer.
Unfortunately, I'm still getting an empty map when using @suzanne.usdc@</Suzanne/Suzanne> with tydra::ListPrim
after calling LayerToStage with the composited reference layer.
I'll take your suggestion and check out sub-layers instead.