I saw the video about adding the material on existing USD object in stage.(https://www.youtube.com/watch?v=McqjFelLCAE)
but is there any API I can use to open the USD file I want? then continue to change properties.
for example : i run the connector code, it add the usd file i choosed in empty stage, then change its material properties.
Is that “UsdStage::Open”? would it replace the original stage?
thank you
You can open any USD file you like with UsdStage::Open(). When you ask if using UsdStage::Open()
replaces the original stage, it’s important to realize that an application can open any number of stages. The context for each stage is stored in the return UsdStageRefPtr
. If that pointer remains in scope, then the stage is still “open” by that application.
For example, if you have an existing open stage, UsdStageRefPtr mainStage
you can open another like this:
// Demonstrate opening two stage contexts within an application
UsdStageRefPtr mainStage = UsdStage::Open("mainStage.usd");
UsdStageRefPtr differentStage = UsdStage::Open("aDifferentStage.usd");
At this point your application will have two separate stages it can operate on.
If you were to overwrite your UsdStageRefPtr
it would, in effect, close the original stage and open a new one, thus “replacing” it:
// Demonstrate "replacing" stage context within an application
UsdStageRefPtr mainStage = UsdStage::Open("mainStage.usd");
mainStage = UsdStage::Open("aDifferentStage.usd");
Most applications, like USD View or Omniverse USD Composer, they have a concept of “File>Open” that will display a particular stage, and any operations you run from a script editor will operate on that particular stage context. That doesn’t prevent the user from opening another stage, but context, scope, and lifetime must be carefully considered.
Also, note that there are different types of stage pointers that correspond to smart pointer concepts and stage lifetime:
UsdStageRefPtr
- a reference counted smart pointerUsdStagePtr
- a weak pointer