Hello all,
I was looking for a Get() or get() method on the UsdStageRefPtr, but could not find one. Is there a way to get a UsdStage* from it in c++?
Thanks,
Koen
Hello all,
I was looking for a Get() or get() method on the UsdStageRefPtr, but could not find one. Is there a way to get a UsdStage* from it in c++?
Thanks,
Koen
We’re more paranoid than boost and the stl were/are, and intentionally make it more difficult to do, though there are a handful of places in the Presto codebase that use it (primarily, I believe, where we derive Qt types but make them TfRefBase). It would be:
UsdStage *raw = TfTypeFunctions<UsdStageRefPtr>::GetRawPtr(myStagePtr);
Use with care!
These all seem to work:
UsdStageRefPtr stageRefPtr = UsdStage::CreateInMemory();
UsdStage* stageRaw;
stageRaw = stageRefPtr.operator->();
stageRaw = &(*stageRefPtr);
stageRaw = TfTypeFunctions::GetRawPtr(stageRefPtr);
stageRaw = get_pointer(stageRefPtr);
For some reason I thought stageRePtr() would work too, but it seems my memory is playing tricks…
Thanks Spiff! The only reason I might need it is to avoid leaking the usd headers into the rest of the code base, I need something that works with a forward declare in the header. I could not get that to work with the UsdStageRefPtr, but as UsdStage* works.
@pmolodo thanks, I tried several of those without any luck, that’s odd they work for you. I’ll try again later.
Although currently, my plan is to just create it all as I have it ( leaking the headers ) and then ask a proper engineer to help me clean it up ![]()
Cheers,
Koen
| koen koen vroeijenstijn
September 17 |
- | - |
Thanks Spiff! The only reason I might need it is to avoid leaking the usd headers into the rest of the code base, I need something that works with a forward declare in the header. I could not get that to work with the UsdStageRefPtr, but as UsdStage* works.
According to the docs (search “Opaqueness”), you can get forward declare with only “pxr/base/tf/refPtr.h”, though that already may be more than you’d like…
@pmolodo thanks, I tried several of those without any luck, that’s odd they work for you. I’ll try again later.
Hmm - I tested the above by throwing it inside of pxr/usd/usd/testenv/testUsdStageNoPython.cpp, and compiling - I didn’t try to actually run the test, though, so it wouldn’t catch any runtime errors - though I wouldn’t expect any…? Tested with gcc/Ubuntu, if that makes a difference…
One oddity I noticed - I didn’t actually expect get_pointer() to work, since it’s declared a friend in the private section… but it compiled for me. ![]()
One thought - it probably didn’t work in your tests because you were trying to use it as a forward declare, without including either refPtr.h or stage.h.
All the above would require at least refPtr.h. If you REALLY don’t want to leak anything, you’ll probably need to make your own wrapper class…
yep, I was trying to use it without any includes, having just a UsdStage pointer in my header seems to work with a forward declare and I can do the conversion to and from UsdStageRefPtr in the cpp file. That might work, thanks for the tips.
I just created a simple “StageRefHolder” wrapper and that works perfectly, no need to get the stage pointer. thanks all!