How to access bounding box of floor in Omniverse Code since we don't have access to bound_utils and prims_utils from Isaac?

I want to use this piece of code or any piece of code that can give me the min_x, min_y, min_z, max_x, max_y, max_z.

So, in Isaac Sim Script Editor, I can use this told to me by @toni.sm

import omni.replicator.core as rep

from omni.isaac.core.utils.stage import get_current_stage, open_stage

import omni.isaac.core.utils.bounds as bounds_utils

import omni.isaac.core.utils.prims as prims_utils

import numpy as np

ENV_URL ="omniverse://localhost/NVIDIA/Assets/Isaac/2022.2.0/Isaac/Samples/Replicator/Stage/full_warehouse_worker_and_anim_cameras.usd"

open_stage(ENV_URL)

stage =get_current_stage()

floor_prims = [x.GetPath() for x in stage.Traverse() if "SM_floor" in x.GetName() and prims_utils.get_prim_type_name(x.GetPath()) == "Xform"]

print('dir floor_prims: ', dir(floor_prims))

bb_cache = bounds_utils.create_bbox_cache()

combined_range_arr = bounds_utils.compute_combined_aabb(bb_cache, prim_paths=floor_prims)
min_x, min_y, min_z, max_x, max_y, max_z = combined_range_arr

How can I do the same in Omniverse Code Script editor?

Here’s the error I get if I use same code in Omniverse Code since we don’t have access to Isaac packages.

I am able to get the stage from the omni but not the bounding box.

import carb

import omni.usd

import omni.replicator.core as rep

#from omni.isaac.core.utils.stage import get_current_stage, open_stage

import omni.isaac.core.utils.bounds as bounds_utils

import omni.isaac.core.utils.prims as prims_utils

import numpy as np

ENV_URL ="omniverse://localhost/NVIDIA/Assets/Isaac/2022.2.0/Isaac/Samples/Replicator/Stage/full_warehouse_worker_and_anim_cameras.usd"

#open_stage(ENV_URL)

result, error = omni.usd.get_context().open_stage_async(ENV_URL, load_set=omni.usd.UsdContextInitialLoadSet.LOAD_NONE)

stage = omni.usd.get_context().get_stage()

carb.log_info(f"Opened stage {stage} with result {result}")

#stage = get_current_stage()

floor_prims = [x.GetPath() for x in stage.Traverse() if "SM_floor" in x.GetName() and prims_utils.get_prim_type_name(x.GetPath()) == "Xform"]

print('dir floor_prims: ', dir(floor_prims))

bb_cache = bounds_utils.create_bbox_cache()

combined_range_arr = bounds_utils.compute_combined_aabb(bb_cache, prim_paths=floor_prims)

min_x, min_y, min_z, max_x, max_y, max_z = combined_range_arr

I also searched for the code of bounds_util and prims_util in isaac and couldn’t find the source code.

(base) mona@ard-gpu-01:~/.local/share/ov/pkg/isaac_sim-2022.2.0$ rg "bounds_util"
(base) mona@ard-gpu-01:~/.local/share/ov/pkg/isaac_sim-2022.2.0$ rg "prims_util"

I can’t find any methods for compute_combined_aabb in omniverse code. Can you please help me with that?

import carb 
import omni.usd

import omni.replicator.core as rep

#from omni.isaac.core.utils.stage import get_current_stage, open_stage

# import omni.isaac.core.utils.bounds as bounds_utils

# import omni.isaac.core.utils.prims as prims_utils

import numpy as np

ENV_URL ="omniverse://localhost/NVIDIA/Assets/Isaac/2022.2.0/Isaac/Samples/Replicator/Stage/full_warehouse_worker_and_anim_cameras.usd"

#open_stage(ENV_URL)
#result, error = omni.usd.get_context().open_stage(ENV_URL, load_set=omni.usd.UsdContextInitialLoadSet.LOAD_NONE)
omni.usd.get_context().open_stage(ENV_URL)

stage = omni.usd.get_context().get_stage()

#stage = get_current_stage()

#floor_prims = [x.GetPath() for x in stage.Traverse() if "SM_floor" in x.GetName() and prims_utils.get_prim_type_name(x.GetPath()) == "Xform"]
floor_prims = [x.GetPath() for x in stage.Traverse() if "SM_floor" in x.GetName() ]
print(floor_prims)

print('dir floor_prims: ', dir(floor_prims))

#bb_cache = bounds_utils.create_bbox_cache()

#combined_range_arr = bounds_utils.compute_combined_aabb(bb_cache, prim_paths=floor_prims)

#min_x, min_y, min_z, max_x, max_y, max_z = combined_range_arr

bbox = omni.usd.get_context().compute_path_world_bounding_box(floor_prims)
min_x, min_y, min_z, max_x, max_y, max_z = bbox

print("bbox is: ", bbox)

The error I get is:

TypeError: compute_path_world_bounding_box(): incompatible function arguments

I am aware I should find something like compute_combined_aabb as in Isaac Sim package however didn’t find something similar.

Also, could you please confirm that both of the following yield same results? I don’t have access to prims_path in Omniverse Code and couldn’t find something similar.

#floor_prims = [x.GetPath() for x in stage.Traverse() if "SM_floor" in x.GetName() and prims_utils.get_prim_type_name(x.GetPath()) == "Xform"]
floor_prims = [x.GetPath() for x in stage.Traverse() if "SM_floor" in x.GetName() ]
print(floor_prims)

Hi @mona.jalal

If you look at the definition of the compute_combined_aabb method, it is possible to track and unwrap its implementation to use only the USD API as follow:

# with prim_paths as a list[str]

stage = omni.usd.get_context().get_stage()
bbox_cache = UsdGeom.BBoxCache(time=Usd.TimeCode.Default(), includedPurposes=[UsdGeom.Tokens.default_], useExtentsHint=True)

total_bounds = Gf.BBox3d()
for prim_path in prim_paths:
    prim = stage.GetPrimAtPath(prim_path)
    bounds = bbox_cache.ComputeWorldBound(prim)
    total_bounds = Gf.BBox3d.Combine(total_bounds, Gf.BBox3d(bounds.ComputeAlignedRange()))
b_range = total_bounds.GetRange()

combined_aabb = [*b_range.GetMin(), *b_range.GetMax()]
1 Like

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