Cpp api for getting usd context

Hi,

I was experimenting with the ExampleCppHelloWorldExtension from kit app template

i tried to access the prim defined in the stage.

#include <omni/fabric/IFabric.h>
#include <usdrt/scenegraph/usd/usd/stage.h>
#include <usdrt/scenegraph/usd/usd/prim.h>
#include <usdrt/scenegraph/usd/sdf/path.h>
#include <omni/usd/UsdContextIncludes.h>
#include <omni/usd/UsdContext.h>

   void onUpdate()
    {
        auto stage_id = omni::usd::UsdContext::getStageId();
        usdrt::UsdStageRefPtr stage = usdrt::UsdStage::Attach(omni::fabric::UsdStageId(stage_id));
        usdrt::UsdPrim prim = stage->GetPrimAtPath("/World/cube");
        if (!prim)
        {
            printf("Prim is not in Fabric");
        } 
        else
        {
          printf("Prim found");
        }
    }

However, i encounter the following error.

../../../_build/linux-x86_64/release/kit/dev/include/omni/usd/UsdContext.h:22:10: fatal error: omni/usd/IUsdMutex.h: No such file or directory
   22 | #include <omni/usd/IUsdMutex.h>

I am using the kit-kernel 106.2.0+release.146576.9df8bbcd.gl.linux-x86_64.release.
I would imagine it to be somewhat like python

import omni.usd
stage = omni.usd.get_context().get_stage()
prim = stage.GetPrimAtPath("/World/cube") 
  1. Is the omni.usd api not available yet?
  2. Do i have to use the pxr method instead?

Following example Action Code Samples - C++ — kit-omnigraph 1.50.0 documentation also have similar issue.
In the doc, it mentions

The API used in these samples are usable in kit-sdk version 105.1 or greater.

In the latest kit-sdk 106.4.0+release.156974.9321c814.gl.linux-x86_64.release,
there is this line in UsdContext.h

// TODO: getContext needs to me removed, but it's called 160 times across 33 files.
// Keep stub that invokes UsdManager::getContext for now to reduce MR

Hi there and thanks for posting. I am sorry you are having issues with our helloworld example. Let me ask the 106 dev team and get back to you.

In case anyone needs to get the stage

#include <pxr/usd/usd/stage.h>
#include <pxr/usd/usdUtils/stageCache.h>
#include <usdrt/scenegraph/usd/usd/stage.h>

static usdrt::UsdStageRefPtr getActiveStage()
    {
        const std::vector<PXR_NS::UsdStageRefPtr> allStages = PXR_NS::UsdUtilsStageCache::Get().GetAllStages();
        if (allStages.size() != 1) // only support one USD stage
            return nullptr;

        auto stage_id = PXR_NS::UsdUtilsStageCache::Get().GetId(allStages[0]).ToLongInt();
        return usdrt::UsdStage::Attach(omni::fabric::UsdStageId(stage_id));
    }

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.