Unverified Commit 9cbf024e authored by Pascal Roth's avatar Pascal Roth Committed by GitHub

Replaces IsaacSim `stage_utils` with IsaacLab `stage_utils` (#3923)

# Description

Remove dependency on IsaacSim `stage_utils` for integration of new
simulation engines like `newton`.

## Type of change

- Dependency removal

## Checklist

- [ ] I have read and understood the [contribution
guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html)
- [ ] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [ ] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

---------
Signed-off-by: 's avatarPascal Roth <57946385+pascal-roth@users.noreply.github.com>
Signed-off-by: 's avatarooctipus <zhengyuz@nvidia.com>
Signed-off-by: 's avatarKelly Guo <kellyg@nvidia.com>
Signed-off-by: 's avatarKelly Guo <kellyguo123@hotmail.com>
Co-authored-by: 's avatargreptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: 's avatarooctipus <zhengyuz@nvidia.com>
Co-authored-by: 's avatarKelly Guo <kellyg@nvidia.com>
Co-authored-by: 's avatarKelly Guo <kellyguo123@hotmail.com>
parent 7e2aba2c
......@@ -75,8 +75,8 @@ For instance, to run a standalone script with verbose logging, you can use the f
# Run the standalone script with info logging
./isaaclab.sh -p scripts/tutorials/00_sim/create_empty.py --headless --info
For more fine-grained control, you can modify the logging channels through the ``omni.log`` module.
For more information, please refer to its `documentation <https://docs.omniverse.nvidia.com/kit/docs/carbonite/latest/docs/omni.log/Logging.html>`__.
For more fine-grained control, you can modify the logging channels through the ``logger`` module.
For more information, please refer to its `documentation <https://docs.python.org/3/library/logging.html>`__.
Observing long load times at the start of the simulation
......
[package]
# Note: Semantic Versioning is used: https://semver.org/
version = "0.48.4"
version = "0.48.5"
# Description
title = "Isaac Lab framework for Robot Learning"
......
Changelog
---------
0.48.5 (2025-11-14)
~~~~~~~~~~~~~~~~~~~
Changed
^^^^^^^
* Changed import from ``isaacsim.core.utils.stage`` to ``isaaclab.sim.utils.stage`` to reduce IsaacLab dependencies.
0.48.4 (2025-11-14)
~~~~~~~~~~~~~~~~~~~
......
......@@ -18,9 +18,9 @@ import isaacsim.core.utils.prims as prim_utils
import omni.kit.app
import omni.timeline
from isaacsim.core.simulation_manager import IsaacEvents, SimulationManager
from isaacsim.core.utils.stage import get_current_stage
import isaaclab.sim as sim_utils
from isaaclab.sim.utils.stage import get_current_stage
if TYPE_CHECKING:
from .asset_base_cfg import AssetBaseCfg
......
......@@ -9,7 +9,7 @@ import weakref
import omni.physics.tensors.impl.api as physx
import isaaclab.utils.math as math_utils
from isaaclab.sim.utils import get_current_stage_id
from isaaclab.sim.utils.stage import get_current_stage_id
from isaaclab.utils.buffers import TimestampedBuffer
......
......@@ -9,7 +9,7 @@ import weakref
import omni.physics.tensors.impl.api as physx
import isaaclab.utils.math as math_utils
from isaaclab.sim.utils import get_current_stage_id
from isaaclab.sim.utils.stage import get_current_stage_id
from isaaclab.utils.buffers import TimestampedBuffer
......
......@@ -227,7 +227,6 @@ class PinkIKController:
joint_angle_changes = velocity * dt
except (AssertionError, Exception) as e:
# Print warning and return the current joint positions as the target
# Not using omni.log since its not available in CI during docs build
if self.cfg.show_ik_warnings:
print(
"Warning: IK quadratic solver could not find a solution! Did not update the target joint"
......
......@@ -25,7 +25,7 @@ from isaacsim.core.version import get_version
from isaaclab.managers import EventManager
from isaaclab.scene import InteractiveScene
from isaaclab.sim import SimulationContext
from isaaclab.sim.utils import attach_stage_to_usd_context, use_stage
from isaaclab.sim.utils.stage import attach_stage_to_usd_context, use_stage
from isaaclab.utils.noise import NoiseModel
from isaaclab.utils.seed import configure_seed
from isaaclab.utils.timer import Timer
......
......@@ -27,7 +27,7 @@ from isaacsim.core.version import get_version
from isaaclab.managers import EventManager
from isaaclab.scene import InteractiveScene
from isaaclab.sim import SimulationContext
from isaaclab.sim.utils import attach_stage_to_usd_context, use_stage
from isaaclab.sim.utils.stage import attach_stage_to_usd_context, use_stage
from isaaclab.utils.noise import NoiseModel
from isaaclab.utils.seed import configure_seed
from isaaclab.utils.timer import Timer
......
......@@ -17,7 +17,7 @@ from isaacsim.core.version import get_version
from isaaclab.managers import ActionManager, EventManager, ObservationManager, RecorderManager
from isaaclab.scene import InteractiveScene
from isaaclab.sim import SimulationContext
from isaaclab.sim.utils import attach_stage_to_usd_context, use_stage
from isaaclab.sim.utils.stage import attach_stage_to_usd_context, use_stage
from isaaclab.ui.widgets import ManagerLiveVisualizer
from isaaclab.utils.seed import configure_seed
from isaaclab.utils.timer import Timer
......
......@@ -22,7 +22,6 @@ from typing import TYPE_CHECKING, Literal
import carb
import omni.physics.tensors.impl.api as physx
from isaacsim.core.utils.extensions import enable_extension
from isaacsim.core.utils.stage import get_current_stage
from pxr import Gf, Sdf, UsdGeom, Vt
import isaaclab.sim as sim_utils
......@@ -30,6 +29,7 @@ import isaaclab.utils.math as math_utils
from isaaclab.actuators import ImplicitActuator
from isaaclab.assets import Articulation, DeformableObject, RigidObject
from isaaclab.managers import EventTermCfg, ManagerTermBase, SceneEntityCfg
from isaaclab.sim.utils.stage import get_current_stage
from isaaclab.terrains import TerrainImporter
from isaaclab.utils.version import compare_versions
......
......@@ -15,9 +15,9 @@ import isaacsim
import omni.kit.app
import omni.kit.commands
import omni.usd
from isaacsim.core.utils.stage import get_current_stage
from pxr import PhysxSchema, Sdf, Usd, UsdGeom, UsdPhysics
from isaaclab.sim.utils.stage import get_current_stage
from isaaclab.ui.widgets import ManagerLiveVisualizer
if TYPE_CHECKING:
......
......@@ -24,15 +24,13 @@ import numpy as np
import torch
from dataclasses import MISSING
import isaacsim.core.utils.stage as stage_utils
import omni.kit.commands
import omni.physx.scripts.utils as physx_utils
from isaacsim.core.utils.stage import get_current_stage
from pxr import Gf, PhysxSchema, Sdf, Usd, UsdGeom, UsdPhysics, Vt
import isaaclab.sim as sim_utils
from isaaclab.sim.spawners import SpawnerCfg
from isaaclab.sim.utils import attach_stage_to_usd_context
from isaaclab.sim.utils import stage as stage_utils
from isaaclab.utils.configclass import configclass
from isaaclab.utils.math import convert_quat
......@@ -151,7 +149,7 @@ class VisualizationMarkers:
# get next free path for the prim
prim_path = stage_utils.get_next_free_path(cfg.prim_path)
# create a new prim
self.stage = get_current_stage()
self.stage = stage_utils.get_current_stage()
self._instancer_manager = UsdGeom.PointInstancer.Define(self.stage, prim_path)
# store inputs
self.prim_path = prim_path
......@@ -401,7 +399,7 @@ class VisualizationMarkers:
if child_prim.IsA(UsdGeom.Gprim):
# early attach stage to usd context if stage is in memory
# since stage in memory is not supported by the "ChangePropertyCommand" kit command
attach_stage_to_usd_context(attaching_early=True)
stage_utils.attach_stage_to_usd_context(attaching_early=True)
# invisible to secondary rays such as depth images
omni.kit.commands.execute(
......
......@@ -11,7 +11,6 @@ from typing import Any
import carb
from isaacsim.core.cloner import GridCloner
from isaacsim.core.prims import XFormPrim
from isaacsim.core.utils.stage import get_current_stage
from isaacsim.core.version import get_version
from pxr import PhysxSchema
......@@ -31,7 +30,7 @@ from isaaclab.assets import (
)
from isaaclab.sensors import ContactSensorCfg, FrameTransformerCfg, SensorBase, SensorBaseCfg
from isaaclab.sim import SimulationContext
from isaaclab.sim.utils import get_current_stage_id
from isaaclab.sim.utils.stage import get_current_stage, get_current_stage_id
from isaaclab.terrains import TerrainImporter, TerrainImporterCfg
from .interactive_scene_cfg import InteractiveSceneCfg
......
......@@ -14,7 +14,6 @@ from collections.abc import Sequence
from typing import TYPE_CHECKING, Any, Literal
import carb
import isaacsim.core.utils.stage as stage_utils
import omni.kit.commands
import omni.usd
from isaacsim.core.prims import XFormPrim
......@@ -23,6 +22,7 @@ from pxr import Sdf, UsdGeom
import isaaclab.sim as sim_utils
import isaaclab.utils.sensors as sensor_utils
from isaaclab.sim.utils import stage as stage_utils
from isaaclab.utils import to_camel_case
from isaaclab.utils.array import convert_to_torch
from isaaclab.utils.math import (
......
......@@ -9,13 +9,13 @@ import torch
from collections.abc import Sequence
from typing import TYPE_CHECKING
import isaacsim.core.utils.stage as stage_utils
from isaacsim.core.simulation_manager import SimulationManager
from pxr import UsdPhysics
import isaaclab.sim as sim_utils
import isaaclab.utils.math as math_utils
from isaaclab.markers import VisualizationMarkers
from isaaclab.sim.utils import stage as stage_utils
from ..sensor_base import SensorBase
from .imu_data import ImuData
......
......@@ -9,12 +9,12 @@ import torch
from collections.abc import Sequence
from typing import TYPE_CHECKING, ClassVar, Literal
import isaacsim.core.utils.stage as stage_utils
import omni.physics.tensors.impl.api as physx
from isaacsim.core.prims import XFormPrim
import isaaclab.utils.math as math_utils
from isaaclab.sensors.camera import CameraData
from isaaclab.sim.utils import stage as stage_utils
from isaaclab.utils.warp import raycast_mesh
from .ray_caster import RayCaster
......
......@@ -23,9 +23,9 @@ from typing import TYPE_CHECKING, Any
import omni.kit.app
import omni.timeline
from isaacsim.core.simulation_manager import IsaacEvents, SimulationManager
from isaacsim.core.utils.stage import get_current_stage
import isaaclab.sim as sim_utils
from isaaclab.sim.utils.stage import get_current_stage
if TYPE_CHECKING:
from .sensor_base_cfg import SensorBaseCfg
......
......@@ -10,10 +10,11 @@ import logging
import math
import omni.physx.scripts.utils as physx_utils
from isaacsim.core.utils.stage import get_current_stage
from omni.physx.scripts import deformableUtils as deformable_utils
from pxr import PhysxSchema, Usd, UsdPhysics
from isaaclab.sim.utils.stage import get_current_stage
from ..utils import (
apply_nested,
find_global_fixed_joint_prim,
......
......@@ -24,7 +24,6 @@ from typing import Any
import carb
import flatdict
import isaacsim.core.utils.stage as stage_utils
import omni.physx
import omni.usd
from isaacsim.core.api.simulation_context import SimulationContext as _SimulationContext
......@@ -33,7 +32,7 @@ from isaacsim.core.utils.viewports import set_camera_view
from isaacsim.core.version import get_version
from pxr import Gf, PhysxSchema, Sdf, Usd, UsdPhysics
from isaaclab.sim.utils import create_new_stage_in_memory, use_stage
from isaaclab.sim.utils import stage as stage_utils
from .simulation_cfg import SimulationCfg
from .spawners import DomeLightCfg, GroundPlaneCfg
......@@ -138,7 +137,7 @@ class SimulationContext(_SimulationContext):
# create stage in memory if requested
if self.cfg.create_stage_in_memory:
self._initial_stage = create_new_stage_in_memory()
self._initial_stage = stage_utils.create_new_stage_in_memory()
else:
self._initial_stage = omni.usd.get_context().get_stage()
......@@ -629,7 +628,7 @@ class SimulationContext(_SimulationContext):
def _init_stage(self, *args, **kwargs) -> Usd.Stage:
_ = super()._init_stage(*args, **kwargs)
with use_stage(self.get_initial_stage()):
with stage_utils.use_stage(self.get_initial_stage()):
# a stage update here is needed for the case when physics_dt != rendering_dt, otherwise the app crashes
# when in headless mode
self.set_setting("/app/player/playSimulations", False)
......
......@@ -18,16 +18,9 @@ try:
except ModuleNotFoundError:
from pxr import Semantics
from isaacsim.core.utils.stage import get_current_stage
from isaaclab.sim import converters, schemas
from isaaclab.sim.utils import (
bind_physics_material,
bind_visual_material,
clone,
is_current_stage_in_memory,
select_usd_variants,
)
from isaaclab.sim.utils import bind_physics_material, bind_visual_material, clone, select_usd_variants
from isaaclab.sim.utils.stage import get_current_stage, is_current_stage_in_memory
from isaaclab.utils.assets import check_usd_path_with_timeout
if TYPE_CHECKING:
......
......@@ -8,10 +8,10 @@ from __future__ import annotations
from typing import TYPE_CHECKING
import isaacsim.core.utils.prims as prim_utils
from isaacsim.core.utils.stage import get_current_stage
from pxr import PhysxSchema, Usd, UsdPhysics, UsdShade
from isaaclab.sim.utils import clone, safe_set_attribute_on_usd_schema
from isaaclab.sim.utils.stage import get_current_stage
if TYPE_CHECKING:
from . import physics_materials_cfg
......
......@@ -12,7 +12,8 @@ import isaacsim.core.utils.prims as prim_utils
import omni.kit.commands
from pxr import Sdf, Usd
from isaaclab.sim.utils import attach_stage_to_usd_context, clone
from isaaclab.sim.utils import clone
from isaaclab.sim.utils.stage import attach_stage_to_usd_context
from isaaclab.utils import to_camel_case
if TYPE_CHECKING:
......
......@@ -11,12 +11,11 @@ from typing import TYPE_CHECKING
import carb
import isaacsim.core.utils.prims as prim_utils
import isaacsim.core.utils.stage as stage_utils
from isaacsim.core.utils.stage import get_current_stage
from pxr import Sdf, Usd
import isaaclab.sim as sim_utils
from isaaclab.sim.spawners.from_files import UsdFileCfg
from isaaclab.sim.utils import stage as stage_utils
if TYPE_CHECKING:
from . import wrappers_cfg
......@@ -48,7 +47,7 @@ def spawn_multi_asset(
The created prim at the first prim path.
"""
# get stage handle
stage = get_current_stage()
stage = stage_utils.get_current_stage()
# resolve: {SPAWN_NS}/AssetName
# note: this assumes that the spawn namespace already exists in the stage
......
# Copyright (c) 2022-2025, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md).
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
import builtins
import contextlib
import logging
import threading
import typing
from collections.abc import Generator
import carb
import omni
import omni.kit.app
from isaacsim.core.utils import stage as sim_stage
from isaacsim.core.utils.carb import get_carb_setting
from isaacsim.core.version import get_version
from omni.metrics.assembler.core import get_metrics_assembler_interface
from omni.usd.commands import DeletePrimsCommand
from pxr import Sdf, Usd, UsdGeom, UsdUtils
# import logger
logger = logging.getLogger(__name__)
_context = threading.local() # thread-local storage to handle nested contexts and concurrent access
# _context is a singleton design in isaacsim and for that reason
# until we fully replace all modules that references the singleton(such as XformPrim, Prim ....), we have to point
# that singleton to this _context
sim_stage._context = _context
AXES_TOKEN = {
"X": UsdGeom.Tokens.x,
"x": UsdGeom.Tokens.x,
"Y": UsdGeom.Tokens.y,
"y": UsdGeom.Tokens.y,
"Z": UsdGeom.Tokens.z,
"z": UsdGeom.Tokens.z,
}
"""Mapping from axis name to axis USD token
>>> import isaacsim.core.utils.constants as constants_utils
>>>
>>> # get the x-axis USD token
>>> constants_utils.AXES_TOKEN['x']
X
>>> constants_utils.AXES_TOKEN['X']
X
"""
def attach_stage_to_usd_context(attaching_early: bool = False):
"""Attaches the current USD stage in memory to the USD context.
This function should be called during or after scene is created and before stage is simulated or rendered.
Note:
If the stage is not in memory or rendering is not enabled, this function will return without attaching.
Args:
attaching_early: Whether to attach the stage to the usd context before stage is created. Defaults to False.
"""
from isaacsim.core.simulation_manager import SimulationManager
from isaaclab.sim.simulation_context import SimulationContext
# if Isaac Sim version is less than 5.0, stage in memory is not supported
isaac_sim_version = float(".".join(get_version()[2]))
if isaac_sim_version < 5:
return
# if stage is not in memory, we can return early
if not is_current_stage_in_memory():
return
# attach stage to physx
stage_id = get_current_stage_id()
physx_sim_interface = omni.physx.get_physx_simulation_interface()
physx_sim_interface.attach_stage(stage_id)
# this carb flag is equivalent to if rendering is enabled
carb_setting = carb.settings.get_settings()
is_rendering_enabled = get_carb_setting(carb_setting, "/physics/fabricUpdateTransformations")
# if rendering is not enabled, we don't need to attach it
if not is_rendering_enabled:
return
# early attach warning msg
if attaching_early:
logger.warning(
"Attaching stage in memory to USD context early to support an operation which doesn't support stage in"
" memory."
)
# skip this callback to avoid wiping the stage after attachment
SimulationContext.instance().skip_next_stage_open_callback()
# disable stage open callback to avoid clearing callbacks
SimulationManager.enable_stage_open_callback(False)
# enable physics fabric
SimulationContext.instance()._physics_context.enable_fabric(True)
# attach stage to usd context
omni.usd.get_context().attach_stage_with_callback(stage_id)
# attach stage to physx
physx_sim_interface = omni.physx.get_physx_simulation_interface()
physx_sim_interface.attach_stage(stage_id)
# re-enable stage open callback
SimulationManager.enable_stage_open_callback(True)
def is_current_stage_in_memory() -> bool:
"""Checks if the current stage is in memory.
This function compares the stage id of the current USD stage with the stage id of the USD context stage.
Returns:
Whether the current stage is in memory.
"""
# grab current stage id
stage_id = get_current_stage_id()
# grab context stage id
context_stage = omni.usd.get_context().get_stage()
with use_stage(context_stage):
context_stage_id = get_current_stage_id()
# check if stage ids are the same
return stage_id != context_stage_id
@contextlib.contextmanager
def use_stage(stage: Usd.Stage) -> Generator[None, None, None]:
"""Context manager that sets a thread-local stage, if supported.
In Isaac Sim < 5.0, this is a no-op to maintain compatibility.
Args:
stage: The stage to set temporarily.
Raises:
AssertionError: If the stage is not a USD stage instance.
Example:
.. code-block:: python
>>> from pxr import Usd
>>> from isaaclab.sim.utils import stage as stage_utils
>>>
>>> stage_in_memory = Usd.Stage.CreateInMemory()
>>> with stage_utils.use_stage(stage_in_memory):
... # operate on the specified stage
... pass
>>> # operate on the default stage attached to the USD context
"""
isaac_sim_version = float(".".join(get_version()[2]))
if isaac_sim_version < 5:
logger.warning("[Compat] Isaac Sim < 5.0 does not support thread-local stage contexts. Skipping use_stage().")
yield # no-op
else:
# check stage
assert isinstance(stage, Usd.Stage), f"Expected a USD stage instance, got: {type(stage)}"
# store previous context value if it exists
previous_stage = getattr(_context, "stage", None)
# set new context value
try:
_context.stage = stage
yield
# remove context value or restore previous one if it exists
finally:
if previous_stage is None:
delattr(_context, "stage")
else:
_context.stage = previous_stage
def get_current_stage(fabric: bool = False) -> Usd.Stage:
"""Get the current open USD or Fabric stage
Args:
fabric: True to get the fabric stage. False to get the USD stage. Defaults to False.
Returns:
The USD or Fabric stage as specified by the input arg fabric.
Example:
.. code-block:: python
>>> from isaaclab.sim.utils import stage as stage_utils
>>>
>>> stage_utils.get_current_stage()
Usd.Stage.Open(rootLayer=Sdf.Find('anon:0x7fba6c04f840:World7.usd'),
sessionLayer=Sdf.Find('anon:0x7fba6c01c5c0:World7-session.usda'),
pathResolverContext=<invalid repr>)
"""
stage = getattr(_context, "stage", omni.usd.get_context().get_stage())
return stage
def get_current_stage_id() -> int:
"""Get the current open stage id
Returns:
The current open stage id.
Example:
.. code-block:: python
>>> from isaaclab.sim.utils import stage as stage_utils
>>>
>>> stage_utils.get_current_stage_id()
1234567890
"""
stage = get_current_stage()
stage_cache = UsdUtils.StageCache.Get()
stage_id = stage_cache.GetId(stage).ToLongInt()
if stage_id < 0:
stage_id = stage_cache.Insert(stage).ToLongInt()
return stage_id
def update_stage() -> None:
"""Update the current USD stage.
Example:
.. code-block:: python
>>> from isaaclab.sim.utils import stage as stage_utils
>>>
>>> stage_utils.update_stage()
"""
omni.kit.app.get_app_interface().update()
# TODO: make a generic util for setting all layer properties
def set_stage_up_axis(axis: str = "z") -> None:
"""Change the up axis of the current stage
Args:
axis (UsdGeom.Tokens, optional): valid values are ``"x"``, ``"y"`` and ``"z"``
Example:
.. code-block:: python
>>> from isaaclab.sim.utils import stage as stage_utils
>>>
>>> # set stage up axis to Y-up
>>> stage_utils.set_stage_up_axis("y")
"""
stage = get_current_stage()
if stage is None:
raise Exception("There is no stage currently opened")
rootLayer = stage.GetRootLayer()
rootLayer.SetPermissionToEdit(True)
with Usd.EditContext(stage, rootLayer):
UsdGeom.SetStageUpAxis(stage, AXES_TOKEN[axis])
def get_stage_up_axis() -> str:
"""Get the current up-axis of USD stage.
Returns:
str: The up-axis of the stage.
Example:
.. code-block:: python
>>> from isaaclab.sim.utils import stage as stage_utils
>>>
>>> stage_utils.get_stage_up_axis()
Z
"""
stage = get_current_stage()
return UsdGeom.GetStageUpAxis(stage)
def clear_stage(predicate: typing.Callable[[str], bool] | None = None) -> None:
"""Deletes all prims in the stage without populating the undo command buffer
Args:
predicate: user defined function that takes a prim_path (str) as input and returns True/False if the prim
should/shouldn't be deleted. If predicate is None, a default is used that deletes all prims
Example:
.. code-block:: python
>>> from isaaclab.sim.utils import stage as stage_utils
>>>
>>> # clear the whole stage
>>> stage_utils.clear_stage()
>>>
>>> # given the stage: /World/Cube, /World/Cube_01, /World/Cube_02.
>>> # Delete only the prims of type Cube
>>> predicate = lambda path: prims_utils.get_prim_type_name(path) == "Cube"
>>> stage_utils.clear_stage(predicate) # after the execution the stage will be /World
"""
# Note: Need to import this here to prevent circular dependencies.
# TODO(Octi): uncomment and remove sim import below after prim_utils replacement merged
from isaacsim.core.utils.prims import ( # isaaclab.utils.prims import (
get_all_matching_child_prims,
get_prim_path,
is_prim_ancestral,
is_prim_hidden_in_stage,
is_prim_no_delete,
)
def default_predicate(prim_path: str):
# prim = get_prim_at_path(prim_path)
# skip prims that we cannot delete
if is_prim_no_delete(prim_path):
return False
if is_prim_hidden_in_stage(prim_path):
return False
if is_prim_ancestral(prim_path):
return False
if prim_path == "/":
return False
if prim_path.startswith("/Render"):
return False
return True
if predicate is None:
prims = get_all_matching_child_prims("/", default_predicate)
prim_paths_to_delete = [get_prim_path(prim) for prim in prims]
DeletePrimsCommand(prim_paths_to_delete).do()
else:
prims = get_all_matching_child_prims("/", predicate)
prim_paths_to_delete = [get_prim_path(prim) for prim in prims]
DeletePrimsCommand(prim_paths_to_delete).do()
if builtins.ISAAC_LAUNCHED_FROM_TERMINAL is False:
omni.kit.app.get_app_interface().update()
def print_stage_prim_paths(fabric: bool = False) -> None:
"""Traverses the stage and prints all prim (hidden or not) paths.
Example:
.. code-block:: python
>>> from isaaclab.sim.utils import stage as stage_utils
>>>
>>> # given the stage: /World/Cube, /World/Cube_01, /World/Cube_02.
>>> stage_utils.print_stage_prim_paths()
/Render
/World
/World/Cube
/World/Cube_01
/World/Cube_02
/OmniverseKit_Persp
/OmniverseKit_Front
/OmniverseKit_Top
/OmniverseKit_Right
"""
# Note: Need to import this here to prevent circular dependencies.
# TODO(Octi): uncomment and remove sim import below after prim_utils replacement merged
# from isaaclab.utils.prims import get_prim_path
from isaacsim.core.utils.prims import get_prim_path
for prim in traverse_stage(fabric=fabric):
prim_path = get_prim_path(prim)
print(prim_path)
def add_reference_to_stage(usd_path: str, prim_path: str, prim_type: str = "Xform") -> Usd.Prim:
"""Add USD reference to the opened stage at specified prim path.
Adds a reference to an external USD file at the specified prim path on the current stage.
If the prim does not exist, it will be created with the specified type.
This function also handles stage units verification to ensure compatibility.
Args:
usd_path: The path to USD file to reference.
prim_path: The prim path where the reference will be attached.
prim_type: The type of prim to create if it doesn't exist. Defaults to "Xform".
Returns:
The USD prim at the specified prim path.
Raises:
FileNotFoundError: When the input USD file is not found at the specified path.
Example:
.. code-block:: python
>>> from isaaclab.sim.utils import stage as stage_utils
>>>
>>> # load an USD file (franka.usd) to the stage under the path /World/panda
>>> prim = stage_utils.add_reference_to_stage(
... usd_path="/home/<user>/Documents/Assets/Robots/FrankaRobotics/FrankaPanda/franka.usd",
... prim_path="/World/panda"
... )
>>> prim
Usd.Prim(</World/panda>)
"""
stage = get_current_stage()
prim = stage.GetPrimAtPath(prim_path)
if not prim.IsValid():
prim = stage.DefinePrim(prim_path, prim_type)
# logger.info("Loading Asset from path {} ".format(usd_path))
# Handle units
sdf_layer = Sdf.Layer.FindOrOpen(usd_path)
if not sdf_layer:
pass
# logger.info(f"Could not get Sdf layer for {usd_path}")
else:
stage_id = UsdUtils.StageCache.Get().GetId(stage).ToLongInt()
ret_val = get_metrics_assembler_interface().check_layers(
stage.GetRootLayer().identifier, sdf_layer.identifier, stage_id
)
if ret_val["ret_val"]:
try:
import omni.metrics.assembler.ui
payref = Sdf.Reference(usd_path)
omni.kit.commands.execute("AddReference", stage=stage, prim_path=prim.GetPath(), reference=payref)
except Exception:
success_bool = prim.GetReferences().AddReference(usd_path)
if not success_bool:
raise FileNotFoundError(f"The usd file at path {usd_path} provided wasn't found")
else:
success_bool = prim.GetReferences().AddReference(usd_path)
if not success_bool:
raise FileNotFoundError(f"The usd file at path {usd_path} provided wasn't found")
return prim
def create_new_stage() -> Usd.Stage:
"""Create a new stage attached to the USD context.
Returns:
Usd.Stage: The created USD stage.
Example:
.. code-block:: python
>>> from isaaclab.sim.utils import stage as stage_utils
>>>
>>> stage_utils.create_new_stage()
Usd.Stage.Open(rootLayer=Sdf.Find('anon:0x7fba6c04f840:World7.usd'),
sessionLayer=Sdf.Find('anon:0x7fba6c01c5c0:World7-session.usda'),
pathResolverContext=<invalid repr>)
"""
return omni.usd.get_context().new_stage()
def create_new_stage_in_memory() -> Usd.Stage:
"""Creates a new stage in memory, if supported.
Returns:
The new stage in memory.
Example:
.. code-block:: python
>>> from isaaclab.sim.utils import stage as stage_utils
>>>
>>> stage_utils.create_new_stage_in_memory()
Usd.Stage.Open(rootLayer=Sdf.Find('anon:0xf7b00e0:tmp.usda'),
sessionLayer=Sdf.Find('anon:0xf7cd2e0:tmp-session.usda'),
pathResolverContext=<invalid repr>)
"""
isaac_sim_version = float(".".join(get_version()[2]))
if isaac_sim_version < 5:
logger.warning(
"[Compat] Isaac Sim < 5.0 does not support creating a new stage in memory. Falling back to creating a new"
" stage attached to USD context."
)
return create_new_stage()
else:
return Usd.Stage.CreateInMemory()
def open_stage(usd_path: str) -> bool:
"""Open the given usd file and replace currently opened stage.
Args:
usd_path (str): Path to the USD file to open.
Raises:
ValueError: When input path is not a supported file type by USD.
Returns:
bool: True if operation is successful, otherwise false.
Example:
.. code-block:: python
>>> from isaaclab.sim.utils import stage as stage_utils
>>>
>>> stage_utils.open_stage("/home/<user>/Documents/Assets/Robots/FrankaRobotics/FrankaPanda/franka.usd")
True
"""
if not Usd.Stage.IsSupportedFile(usd_path):
raise ValueError("Only USD files can be loaded with this method")
usd_context = omni.usd.get_context()
usd_context.disable_save_to_recent_files()
result = omni.usd.get_context().open_stage(usd_path)
usd_context.enable_save_to_recent_files()
return result
def save_stage(usd_path: str, save_and_reload_in_place=True) -> bool:
"""Save usd file to path, it will be overwritten with the current stage
Args:
usd_path (str): File path to save the current stage to
save_and_reload_in_place (bool, optional): use ``save_as_stage`` to save and reload the root layer in place. Defaults to True.
Raises:
ValueError: When input path is not a supported file type by USD.
Returns:
bool: True if operation is successful, otherwise false.
Example:
.. code-block:: python
>>> from isaaclab.sim.utils import stage as stage_utils
>>>
>>> stage_utils.save_stage("/home/<user>/Documents/Save/stage.usd")
True
"""
if not Usd.Stage.IsSupportedFile(usd_path):
raise ValueError("Only USD files can be saved with this method")
layer = Sdf.Layer.CreateNew(usd_path)
root_layer = get_current_stage().GetRootLayer()
layer.TransferContent(root_layer)
omni.usd.resolve_paths(root_layer.identifier, layer.identifier)
result = layer.Save()
if save_and_reload_in_place:
open_stage(usd_path)
return result
def close_stage(callback_fn: typing.Callable | None = None) -> bool:
"""Closes the current opened USD stage.
.. note::
Once the stage is closed, it is necessary to open a new stage or create a new one in order to work on it.
Args:
callback_fn: Callback function to call while closing. Defaults to None.
Returns:
bool: True if operation is successful, otherwise false.
Example:
.. code-block:: python
>>> from isaaclab.sim.utils import stage as stage_utils
>>>
>>> stage_utils.close_stage()
True
.. code-block:: python
>>> from isaaclab.sim.utils import stage as stage_utils
>>>
>>> def callback(*args, **kwargs):
... print("callback:", args, kwargs)
...
>>> stage_utils.close_stage(callback)
True
>>> stage_utils.close_stage(callback)
callback: (False, 'Stage opening or closing already in progress!!') {}
False
"""
if callback_fn is None:
result = omni.usd.get_context().close_stage()
else:
result = omni.usd.get_context().close_stage_with_callback(callback_fn)
return result
def traverse_stage(fabric=False) -> typing.Iterable:
"""Traverse through prims (hidden or not) in the opened Usd stage.
Returns:
Generator which yields prims from the stage in depth-first-traversal order.
Example:
.. code-block:: python
>>> from isaaclab.sim.utils import stage as stage_utils
>>>
>>> # given the stage: /World/Cube, /World/Cube_01, /World/Cube_02.
>>> # Traverse through prims in the stage
>>> for prim in stage_utils.traverse_stage():
>>> print(prim)
Usd.Prim(</World>)
Usd.Prim(</World/Cube>)
Usd.Prim(</World/Cube_01>)
Usd.Prim(</World/Cube_02>)
Usd.Prim(</OmniverseKit_Persp>)
Usd.Prim(</OmniverseKit_Front>)
Usd.Prim(</OmniverseKit_Top>)
Usd.Prim(</OmniverseKit_Right>)
Usd.Prim(</Render>)
"""
return get_current_stage(fabric=fabric).Traverse()
def is_stage_loading() -> bool:
"""Convenience function to see if any files are being loaded.
Returns:
bool: True if loading, False otherwise
Example:
.. code-block:: python
>>> from isaaclab.sim.utils import stage as stage_utils
>>>
>>> stage_utils.is_stage_loading()
False
"""
context = omni.usd.get_context()
if context is None:
return False
else:
_, _, loading = context.get_stage_loading_status()
return loading > 0
def set_stage_units(stage_units_in_meters: float) -> None:
"""Set the stage meters per unit
The most common units and their values are listed in the following table:
+------------------+--------+
| Unit | Value |
+==================+========+
| kilometer (km) | 1000.0 |
+------------------+--------+
| meters (m) | 1.0 |
+------------------+--------+
| inch (in) | 0.0254 |
+------------------+--------+
| centimeters (cm) | 0.01 |
+------------------+--------+
| millimeter (mm) | 0.001 |
+------------------+--------+
Args:
stage_units_in_meters (float): units for stage
Example:
.. code-block:: python
>>> from isaaclab.sim.utils import stage as stage_utils
>>>
>>> stage_utils.set_stage_units(1.0)
"""
if get_current_stage() is None:
raise Exception("There is no stage currently opened, init_stage needed before calling this func")
with Usd.EditContext(get_current_stage(), get_current_stage().GetRootLayer()):
UsdGeom.SetStageMetersPerUnit(get_current_stage(), stage_units_in_meters)
def get_stage_units() -> float:
"""Get the stage meters per unit currently set
The most common units and their values are listed in the following table:
+------------------+--------+
| Unit | Value |
+==================+========+
| kilometer (km) | 1000.0 |
+------------------+--------+
| meters (m) | 1.0 |
+------------------+--------+
| inch (in) | 0.0254 |
+------------------+--------+
| centimeters (cm) | 0.01 |
+------------------+--------+
| millimeter (mm) | 0.001 |
+------------------+--------+
Returns:
float: current stage meters per unit
Example:
.. code-block:: python
>>> from isaaclab.sim.utils import stage as stage_utils
>>>
>>> stage_utils.get_stage_units()
1.0
"""
return UsdGeom.GetStageMetersPerUnit(get_current_stage())
def get_next_free_path(path: str, parent: str = None) -> str:
"""Returns the next free usd path for the current stage
Args:
path (str): path we want to check
parent (str, optional): Parent prim for the given path. Defaults to None.
Returns:
str: a new path that is guaranteed to not exist on the current stage
Example:
.. code-block:: python
>>> from isaaclab.sim.utils import stage as stage_utils
>>>
>>> # given the stage: /World/Cube, /World/Cube_01.
>>> # Get the next available path for /World/Cube
>>> stage_utils.get_next_free_path("/World/Cube")
/World/Cube_02
"""
if parent is not None:
# remove trailing slash from parent and leading slash from path
path = omni.usd.get_stage_next_free_path(
get_current_stage(), parent.rstrip("/") + "/" + path.lstrip("/"), False
)
else:
path = omni.usd.get_stage_next_free_path(get_current_stage(), path, True)
return path
def remove_deleted_references():
"""Clean up deleted references in the current USD stage.
Removes any deleted items from both payload and references lists
for all prims in the stage's root layer. Prints information about
any deleted items that were cleaned up.
Example:
.. code-block:: python
>>> from isaaclab.sim.utils import stage as stage_utils
>>> stage_utils.remove_deleted_references()
Removed 2 deleted payload items from </World/Robot>
Removed 1 deleted reference items from </World/Scene>
"""
stage = get_current_stage()
deleted_count = 0
for prim in stage.Traverse():
prim_spec = stage.GetRootLayer().GetPrimAtPath(prim.GetPath())
if not prim_spec:
continue
# Clean payload references
payload_list = prim_spec.GetInfo("payload")
if payload_list.deletedItems:
deleted_payload_count = len(payload_list.deletedItems)
print(f"Removed {deleted_payload_count} deleted payload items from {prim.GetPath()}")
payload_list.deletedItems = []
prim_spec.SetInfo("payload", payload_list)
deleted_count += deleted_payload_count
# Clean prim references
references_list = prim_spec.GetInfo("references")
if references_list.deletedItems:
deleted_ref_count = len(references_list.deletedItems)
print(f"Removed {deleted_ref_count} deleted reference items from {prim.GetPath()}")
references_list.deletedItems = []
prim_spec.SetInfo("references", references_list)
deleted_count += deleted_ref_count
if deleted_count == 0:
print("No deleted references or payloads found in the stage.")
......@@ -7,24 +7,19 @@
from __future__ import annotations
import contextlib
import functools
import inspect
import logging
import re
import time
from collections.abc import Callable, Generator
from collections.abc import Callable
from typing import TYPE_CHECKING, Any
import carb
import isaacsim.core.utils.stage as stage_utils
import omni
import omni.kit.commands
from isaacsim.core.cloner import Cloner
from isaacsim.core.utils.carb import get_carb_setting
from isaacsim.core.utils.stage import get_current_stage
from isaacsim.core.version import get_version
from pxr import PhysxSchema, Sdf, Usd, UsdGeom, UsdPhysics, UsdShade, UsdUtils
from pxr import PhysxSchema, Sdf, Usd, UsdGeom, UsdPhysics, UsdShade
# from Isaac Sim 4.2 onwards, pxr.Semantics is deprecated
try:
......@@ -35,8 +30,10 @@ except ModuleNotFoundError:
from isaaclab.sim import schemas
from isaaclab.utils.string import to_camel_case
from .stage import attach_stage_to_usd_context, get_current_stage
if TYPE_CHECKING:
from .spawners.spawner_cfg import SpawnerCfg
from isaaclab.sim.spawners.spawner_cfg import SpawnerCfg
# import logger
logger = logging.getLogger(__name__)
......@@ -1038,157 +1035,6 @@ def select_usd_variants(prim_path: str, variants: object | dict[str, str], stage
)
"""
Stage management.
"""
def attach_stage_to_usd_context(attaching_early: bool = False):
"""Attaches the current USD stage in memory to the USD context.
This function should be called during or after scene is created and before stage is simulated or rendered.
Note:
If the stage is not in memory or rendering is not enabled, this function will return without attaching.
Args:
attaching_early: Whether to attach the stage to the usd context before stage is created. Defaults to False.
"""
from isaacsim.core.simulation_manager import SimulationManager
from isaaclab.sim.simulation_context import SimulationContext
# if Isaac Sim version is less than 5.0, stage in memory is not supported
isaac_sim_version = float(".".join(get_version()[2]))
if isaac_sim_version < 5:
return
# if stage is not in memory, we can return early
if not is_current_stage_in_memory():
return
# attach stage to physx
stage_id = get_current_stage_id()
physx_sim_interface = omni.physx.get_physx_simulation_interface()
physx_sim_interface.attach_stage(stage_id)
# this carb flag is equivalent to if rendering is enabled
carb_setting = carb.settings.get_settings()
is_rendering_enabled = get_carb_setting(carb_setting, "/physics/fabricUpdateTransformations")
# if rendering is not enabled, we don't need to attach it
if not is_rendering_enabled:
return
# early attach warning msg
if attaching_early:
logger.warning(
"Attaching stage in memory to USD context early to support an operation which doesn't support stage in"
" memory."
)
# skip this callback to avoid wiping the stage after attachment
SimulationContext.instance().skip_next_stage_open_callback()
# disable stage open callback to avoid clearing callbacks
SimulationManager.enable_stage_open_callback(False)
# enable physics fabric
SimulationContext.instance()._physics_context.enable_fabric(True)
# attach stage to usd context
omni.usd.get_context().attach_stage_with_callback(stage_id)
# attach stage to physx
physx_sim_interface = omni.physx.get_physx_simulation_interface()
physx_sim_interface.attach_stage(stage_id)
# re-enable stage open callback
SimulationManager.enable_stage_open_callback(True)
def is_current_stage_in_memory() -> bool:
"""Checks if the current stage is in memory.
This function compares the stage id of the current USD stage with the stage id of the USD context stage.
Returns:
Whether the current stage is in memory.
"""
# grab current stage id
stage_id = get_current_stage_id()
# grab context stage id
context_stage = omni.usd.get_context().get_stage()
with use_stage(context_stage):
context_stage_id = get_current_stage_id()
# check if stage ids are the same
return stage_id != context_stage_id
@contextlib.contextmanager
def use_stage(stage: Usd.Stage) -> Generator[None, None, None]:
"""Context manager that sets a thread-local stage, if supported.
In Isaac Sim < 5.0, this is a no-op to maintain compatibility.
Args:
stage: The stage to set temporarily.
Yields:
None
"""
isaac_sim_version = float(".".join(get_version()[2]))
if isaac_sim_version < 5:
logger.warning("[Compat] Isaac Sim < 5.0 does not support thread-local stage contexts. Skipping use_stage().")
yield # no-op
else:
with stage_utils.use_stage(stage):
yield
def create_new_stage_in_memory() -> Usd.Stage:
"""Creates a new stage in memory, if supported.
Returns:
The new stage in memory.
"""
isaac_sim_version = float(".".join(get_version()[2]))
if isaac_sim_version < 5:
logger.warning(
"[Compat] Isaac Sim < 5.0 does not support creating a new stage in memory. Falling back to creating a new"
" stage attached to USD context."
)
return stage_utils.create_new_stage()
else:
return stage_utils.create_new_stage_in_memory()
def get_current_stage_id() -> int:
"""Gets the current open stage id.
This function is a reimplementation of :meth:`isaacsim.core.utils.stage.get_current_stage_id` for
backwards compatibility to Isaac Sim < 5.0.
Returns:
The current open stage id.
"""
stage = get_current_stage()
stage_cache = UsdUtils.StageCache.Get()
stage_id = stage_cache.GetId(stage).ToLongInt()
if stage_id < 0:
stage_id = stage_cache.Insert(stage).ToLongInt()
return stage_id
"""
Logger.
"""
# --- Colored formatter ---
class ColoredFormatter(logging.Formatter):
COLORS = {
......
......@@ -15,13 +15,13 @@ simulation_app = AppLauncher(headless=True).app
import torch
import isaacsim.core.utils.prims as prim_utils
import isaacsim.core.utils.stage as stage_utils
import pytest
from isaacsim.core.cloner import GridCloner
import isaaclab.sim as sim_utils
from isaaclab.assets import Articulation
from isaaclab.controllers import DifferentialIKController, DifferentialIKControllerCfg
from isaaclab.sim.utils import stage as stage_utils
from isaaclab.utils.math import ( # isort:skip
compute_pose_error,
......
......@@ -15,7 +15,6 @@ simulation_app = AppLauncher(headless=True).app
import torch
import isaacsim.core.utils.prims as prim_utils
import isaacsim.core.utils.stage as stage_utils
import pytest
from isaacsim.core.cloner import GridCloner
......@@ -25,6 +24,7 @@ from isaaclab.controllers import OperationalSpaceController, OperationalSpaceCon
from isaaclab.markers import VisualizationMarkers
from isaaclab.markers.config import FRAME_MARKER_CFG
from isaaclab.sensors import ContactSensor, ContactSensorCfg
from isaaclab.sim.utils import stage as stage_utils
from isaaclab.utils.math import (
apply_delta_pose,
combine_frame_transforms,
......
......@@ -34,7 +34,6 @@ import logging
import torch
import isaacsim.core.utils.prims as prim_utils
import isaacsim.core.utils.stage as stage_utils
import omni.kit.commands
import omni.physx
from isaacsim.core.api.world import World
......@@ -45,6 +44,7 @@ from pxr import PhysxSchema, UsdPhysics
# import logger
logger = logging.getLogger(__name__)
import isaaclab.sim.utils.nucleus as nucleus_utils
import isaaclab.sim.utils.stage as stage_utils
# check nucleus connection
if nucleus_utils.get_assets_root_path() is None:
......
......@@ -14,13 +14,13 @@ simulation_app = AppLauncher(headless=True).app
import torch
import isaacsim.core.utils.stage as stage_utils
import pytest
from isaacsim.core.api.simulation_context import SimulationContext
import isaaclab.sim as sim_utils
from isaaclab.markers import VisualizationMarkers, VisualizationMarkersCfg
from isaaclab.markers.config import FRAME_MARKER_CFG, POSITION_GOAL_MARKER_CFG
from isaaclab.sim.utils import stage as stage_utils
from isaaclab.utils.math import random_orientation
from isaaclab.utils.timer import Timer
......
......@@ -23,7 +23,6 @@ import scipy.spatial.transform as tf
import torch
import isaacsim.core.utils.prims as prim_utils
import isaacsim.core.utils.stage as stage_utils
import omni.replicator.core as rep
import pytest
from isaacsim.core.prims import SingleGeometryPrim, SingleRigidPrim
......@@ -31,6 +30,7 @@ from pxr import Gf, Usd, UsdGeom
import isaaclab.sim as sim_utils
from isaaclab.sensors.camera import Camera, CameraCfg
from isaaclab.sim.utils import stage as stage_utils
from isaaclab.utils import convert_dict_to_backend
from isaaclab.utils.math import convert_quat
from isaaclab.utils.timer import Timer
......
......@@ -16,7 +16,6 @@ import math
import scipy.spatial.transform as tf
import torch
import isaacsim.core.utils.stage as stage_utils
import pytest
import isaaclab.sim as sim_utils
......@@ -24,6 +23,7 @@ import isaaclab.utils.math as math_utils
from isaaclab.assets import RigidObjectCfg
from isaaclab.scene import InteractiveScene, InteractiveSceneCfg
from isaaclab.sensors import FrameTransformerCfg, OffsetCfg
from isaaclab.sim.utils import stage as stage_utils
from isaaclab.terrains import TerrainImporterCfg
from isaaclab.utils import configclass
......
......@@ -17,7 +17,6 @@ simulation_app = app_launcher.app
import pathlib
import torch
import isaacsim.core.utils.stage as stage_utils
import pytest
import isaaclab.sim as sim_utils
......@@ -27,6 +26,7 @@ from isaaclab.assets import ArticulationCfg, RigidObjectCfg
from isaaclab.markers.config import GREEN_ARROW_X_MARKER_CFG, RED_ARROW_X_MARKER_CFG
from isaaclab.scene import InteractiveScene, InteractiveSceneCfg
from isaaclab.sensors.imu import ImuCfg
from isaaclab.sim.utils import stage as stage_utils
from isaaclab.terrains import TerrainImporterCfg
from isaaclab.utils import configclass
......
......@@ -21,7 +21,6 @@ import random
import torch
import isaacsim.core.utils.prims as prim_utils
import isaacsim.core.utils.stage as stage_utils
import omni.replicator.core as rep
import pytest
from flaky import flaky
......@@ -30,6 +29,7 @@ from pxr import Gf, UsdGeom
import isaaclab.sim as sim_utils
from isaaclab.sensors.camera import TiledCamera, TiledCameraCfg
from isaaclab.sim.utils import stage as stage_utils
@pytest.fixture()
......
......@@ -21,7 +21,6 @@ import os
import torch
import isaacsim.core.utils.prims as prim_utils
import isaacsim.core.utils.stage as stage_utils
import omni.replicator.core as rep
import pytest
from pxr import Gf
......@@ -30,6 +29,7 @@ import isaaclab.sim as sim_utils
from isaaclab.sensors.camera import Camera, CameraCfg
from isaaclab.sensors.ray_caster import RayCasterCamera, RayCasterCameraCfg, patterns
from isaaclab.sim import PinholeCameraCfg
from isaaclab.sim.utils import stage as stage_utils
from isaaclab.terrains.trimesh.utils import make_plane
from isaaclab.terrains.utils import create_prim_from_mesh
from isaaclab.utils import convert_dict_to_backend
......
......@@ -19,11 +19,11 @@ from collections.abc import Sequence
from dataclasses import dataclass
import isaacsim.core.utils.prims as prim_utils
import isaacsim.core.utils.stage as stage_utils
import pytest
import isaaclab.sim as sim_utils
from isaaclab.sensors import SensorBase, SensorBaseCfg
from isaaclab.sim.utils import stage as stage_utils
from isaaclab.utils import configclass
......
......@@ -21,12 +21,13 @@ import random
import torch
import isaacsim.core.utils.prims as prim_utils
import isaacsim.core.utils.stage as stage_utils
import omni.replicator.core as rep
import pytest
from isaacsim.core.prims import SingleGeometryPrim, SingleRigidPrim
from pxr import Gf, UsdGeom
from isaaclab.sim.utils import stage as stage_utils
# from Isaac Sim 4.2 onwards, pxr.Semantics is deprecated
try:
import Semantics
......
......@@ -18,7 +18,6 @@ import random
import tempfile
import isaacsim.core.utils.prims as prim_utils
import isaacsim.core.utils.stage as stage_utils
import omni
import pytest
from isaacsim.core.api.simulation_context import SimulationContext
......@@ -26,6 +25,7 @@ from pxr import UsdGeom, UsdPhysics
from isaaclab.sim.converters import MeshConverter, MeshConverterCfg
from isaaclab.sim.schemas import schemas_cfg
from isaaclab.sim.utils import stage as stage_utils
from isaaclab.utils.assets import ISAACLAB_NUCLEUS_DIR, retrieve_file_path
......
......@@ -15,12 +15,12 @@ simulation_app = AppLauncher(headless=True).app
import os
import isaacsim.core.utils.prims as prim_utils
import isaacsim.core.utils.stage as stage_utils
import pytest
from isaacsim.core.api.simulation_context import SimulationContext
from isaacsim.core.utils.extensions import enable_extension, get_extension_path_from_name
from isaaclab.sim.converters import MjcfConverter, MjcfConverterCfg
from isaaclab.sim.utils import stage as stage_utils
@pytest.fixture(autouse=True)
......
......@@ -15,13 +15,13 @@ simulation_app = AppLauncher(headless=True).app
import math
import isaacsim.core.utils.prims as prim_utils
import isaacsim.core.utils.stage as stage_utils
import pytest
from isaacsim.core.api.simulation_context import SimulationContext
from pxr import UsdPhysics
import isaaclab.sim.schemas as schemas
from isaaclab.sim.utils import find_global_fixed_joint_prim
from isaaclab.sim.utils import stage as stage_utils
from isaaclab.utils.assets import ISAAC_NUCLEUS_DIR
from isaaclab.utils.string import to_camel_case
......
......@@ -13,12 +13,12 @@ simulation_app = AppLauncher(headless=True).app
"""Rest everything follows."""
import isaacsim.core.utils.prims as prim_utils
import isaacsim.core.utils.stage as stage_utils
import pytest
from isaacsim.core.api.simulation_context import SimulationContext
from isaacsim.core.utils.extensions import enable_extension, get_extension_path_from_name
import isaaclab.sim as sim_utils
from isaaclab.sim.utils import stage as stage_utils
from isaaclab.utils.assets import ISAACLAB_NUCLEUS_DIR
......
......@@ -13,12 +13,12 @@ simulation_app = AppLauncher(headless=True).app
"""Rest everything follows."""
import isaacsim.core.utils.prims as prim_utils
import isaacsim.core.utils.stage as stage_utils
import pytest
from isaacsim.core.api.simulation_context import SimulationContext
from pxr import UsdLux
import isaaclab.sim as sim_utils
from isaaclab.sim.utils import stage as stage_utils
from isaaclab.utils.string import to_camel_case
......
......@@ -13,12 +13,12 @@ simulation_app = AppLauncher(headless=True).app
"""Rest everything follows."""
import isaacsim.core.utils.prims as prim_utils
import isaacsim.core.utils.stage as stage_utils
import pytest
from isaacsim.core.api.simulation_context import SimulationContext
from pxr import UsdPhysics, UsdShade
import isaaclab.sim as sim_utils
from isaaclab.sim.utils import stage as stage_utils
from isaaclab.utils.assets import NVIDIA_NUCLEUS_DIR
......
......@@ -13,11 +13,11 @@ simulation_app = AppLauncher(headless=True).app
"""Rest everything follows."""
import isaacsim.core.utils.prims as prim_utils
import isaacsim.core.utils.stage as stage_utils
import pytest
from isaacsim.core.api.simulation_context import SimulationContext
import isaaclab.sim as sim_utils
from isaaclab.sim.utils import stage as stage_utils
@pytest.fixture
......
......@@ -13,12 +13,12 @@ simulation_app = AppLauncher(headless=True).app
"""Rest everything follows."""
import isaacsim.core.utils.prims as prim_utils
import isaacsim.core.utils.stage as stage_utils
import pytest
from isaacsim.core.api.simulation_context import SimulationContext
import isaaclab.sim as sim_utils
from isaaclab.sim.spawners.sensors.sensors import CUSTOM_FISHEYE_CAMERA_ATTRIBUTES, CUSTOM_PINHOLE_CAMERA_ATTRIBUTES
from isaaclab.sim.utils import stage as stage_utils
from isaaclab.utils.string import to_camel_case
......
......@@ -13,11 +13,11 @@ simulation_app = AppLauncher(headless=True).app
"""Rest everything follows."""
import isaacsim.core.utils.prims as prim_utils
import isaacsim.core.utils.stage as stage_utils
import pytest
from isaacsim.core.api.simulation_context import SimulationContext
import isaaclab.sim as sim_utils
from isaaclab.sim.utils import stage as stage_utils
@pytest.fixture
......
......@@ -13,11 +13,11 @@ simulation_app = AppLauncher(headless=True).app
"""Rest everything follows."""
import isaacsim.core.utils.prims as prim_utils
import isaacsim.core.utils.stage as stage_utils
import pytest
from isaacsim.core.api.simulation_context import SimulationContext
import isaaclab.sim as sim_utils
from isaaclab.sim.utils import stage as stage_utils
from isaaclab.utils.assets import ISAACLAB_NUCLEUS_DIR
......
......@@ -13,7 +13,6 @@ simulation_app = AppLauncher(headless=True, enable_cameras=True).app
"""Rest everything follows."""
import isaacsim.core.utils.prims as prim_utils
import isaacsim.core.utils.stage as stage_utils
import omni
import omni.physx
import omni.usd
......@@ -24,6 +23,7 @@ from isaacsim.core.version import get_version
import isaaclab.sim as sim_utils
from isaaclab.sim.simulation_context import SimulationCfg, SimulationContext
from isaaclab.sim.utils import stage as stage_utils
from isaaclab.utils.assets import ISAACLAB_NUCLEUS_DIR
......@@ -59,7 +59,7 @@ def test_stage_in_memory_with_shapes(sim):
# grab stage in memory and set as current stage via the with statement
stage_in_memory = sim.get_initial_stage()
with sim_utils.use_stage(stage_in_memory):
with stage_utils.use_stage(stage_in_memory):
# create cloned cone stage
for i in range(num_clones):
prim_utils.create_prim(f"/World/env_{i}", "Xform", translation=(i, i, 0))
......@@ -88,7 +88,7 @@ def test_stage_in_memory_with_shapes(sim):
cfg.func(prim_path_regex, cfg)
# verify stage is in memory
assert sim_utils.is_current_stage_in_memory()
assert stage_utils.is_current_stage_in_memory()
# verify prims exist in stage in memory
prims = prim_utils.find_matching_prim_paths(prim_path_regex)
......@@ -96,7 +96,7 @@ def test_stage_in_memory_with_shapes(sim):
# verify prims do not exist in context stage
context_stage = omni.usd.get_context().get_stage()
with sim_utils.use_stage(context_stage):
with stage_utils.use_stage(context_stage):
prims = prim_utils.find_matching_prim_paths(prim_path_regex)
assert len(prims) != num_clones
......@@ -104,7 +104,7 @@ def test_stage_in_memory_with_shapes(sim):
sim_utils.attach_stage_to_usd_context()
# verify stage is no longer in memory
assert not sim_utils.is_current_stage_in_memory()
assert not stage_utils.is_current_stage_in_memory()
# verify prims now exist in context stage
prims = prim_utils.find_matching_prim_paths(prim_path_regex)
......@@ -128,7 +128,7 @@ def test_stage_in_memory_with_usds(sim):
# grab stage in memory and set as current stage via the with statement
stage_in_memory = sim.get_initial_stage()
with sim_utils.use_stage(stage_in_memory):
with stage_utils.use_stage(stage_in_memory):
# create cloned robot stage
for i in range(num_clones):
prim_utils.create_prim(f"/World/env_{i}", "Xform", translation=(i, i, 0))
......@@ -154,7 +154,7 @@ def test_stage_in_memory_with_usds(sim):
cfg.func(prim_path_regex, cfg)
# verify stage is in memory
assert sim_utils.is_current_stage_in_memory()
assert stage_utils.is_current_stage_in_memory()
# verify prims exist in stage in memory
prims = prim_utils.find_matching_prim_paths(prim_path_regex)
......@@ -162,7 +162,7 @@ def test_stage_in_memory_with_usds(sim):
# verify prims do not exist in context stage
context_stage = omni.usd.get_context().get_stage()
with sim_utils.use_stage(context_stage):
with stage_utils.use_stage(context_stage):
prims = prim_utils.find_matching_prim_paths(prim_path_regex)
assert len(prims) != num_clones
......@@ -170,7 +170,7 @@ def test_stage_in_memory_with_usds(sim):
sim_utils.attach_stage_to_usd_context()
# verify stage is no longer in memory
assert not sim_utils.is_current_stage_in_memory()
assert not stage_utils.is_current_stage_in_memory()
# verify prims now exist in context stage
prims = prim_utils.find_matching_prim_paths(prim_path_regex)
......@@ -191,7 +191,7 @@ def test_stage_in_memory_with_clone_in_fabric(sim):
# grab stage in memory and set as current stage via the with statement
stage_in_memory = sim.get_initial_stage()
with sim_utils.use_stage(stage_in_memory):
with stage_utils.use_stage(stage_in_memory):
# set up paths
base_env_path = "/World/envs"
source_prim_path = f"{base_env_path}/env_0"
......@@ -218,7 +218,7 @@ def test_stage_in_memory_with_clone_in_fabric(sim):
# verify prims do not exist in context stage
context_stage = omni.usd.get_context().get_stage()
with sim_utils.use_stage(context_stage):
with stage_utils.use_stage(context_stage):
prims = prim_utils.find_matching_prim_paths(prim_path_regex)
assert len(prims) != num_clones
......@@ -226,10 +226,10 @@ def test_stage_in_memory_with_clone_in_fabric(sim):
sim_utils.attach_stage_to_usd_context()
# verify stage is no longer in memory
assert not sim_utils.is_current_stage_in_memory()
assert not stage_utils.is_current_stage_in_memory()
# verify prims now exist in fabric stage using usdrt apis
stage_id = sim_utils.get_current_stage_id()
stage_id = stage_utils.get_current_stage_id()
usdrt_stage = usdrt.Usd.Stage.Attach(stage_id)
for i in range(num_clones):
prim = usdrt_stage.GetPrimAtPath(f"/World/envs/env_{i}/Robot")
......
......@@ -16,13 +16,13 @@ import numpy as np
import os
import isaacsim.core.utils.prims as prim_utils
import isaacsim.core.utils.stage as stage_utils
import pytest
from isaacsim.core.api.simulation_context import SimulationContext
from isaacsim.core.prims import Articulation
from isaacsim.core.utils.extensions import enable_extension, get_extension_path_from_name
from isaaclab.sim.converters import UrdfConverter, UrdfConverterCfg
from isaaclab.sim.utils import stage as stage_utils
# Create a fixture for setup and teardown
......
......@@ -16,12 +16,12 @@ import numpy as np
import torch
import isaacsim.core.utils.prims as prim_utils
import isaacsim.core.utils.stage as stage_utils
import pytest
from pxr import Sdf, Usd, UsdGeom, UsdPhysics
import isaaclab.sim as sim_utils
import isaaclab.utils.math as math_utils
from isaaclab.sim.utils import stage as stage_utils
from isaaclab.utils.assets import ISAAC_NUCLEUS_DIR, ISAACLAB_NUCLEUS_DIR
......
......@@ -70,9 +70,10 @@ def get_camera_position():
tuple: (x, y, z) camera position or None if not available
"""
try:
import isaacsim.core.utils.stage as stage_utils
from pxr import UsdGeom
from isaaclab.sim.utils import stage as stage_utils
stage = stage_utils.get_current_stage()
if stage is not None:
# Get the viewport camera prim
......
......@@ -7,7 +7,6 @@ from __future__ import annotations
import torch
from isaacsim.core.utils.stage import get_current_stage
from isaacsim.core.utils.torch.transformations import tf_combine, tf_inverse, tf_vector
from pxr import UsdGeom
......@@ -17,6 +16,7 @@ from isaaclab.assets import Articulation, ArticulationCfg
from isaaclab.envs import DirectRLEnv, DirectRLEnvCfg
from isaaclab.scene import InteractiveSceneCfg
from isaaclab.sim import SimulationCfg
from isaaclab.sim.utils.stage import get_current_stage
from isaaclab.terrains import TerrainImporterCfg
from isaaclab.utils import configclass
from isaaclab.utils.assets import ISAAC_NUCLEUS_DIR, ISAACLAB_NUCLEUS_DIR
......
......@@ -14,12 +14,11 @@ try:
except ModuleNotFoundError:
from pxr import Semantics
from isaacsim.core.utils.stage import get_current_stage
import isaaclab.sim as sim_utils
from isaaclab.assets import Articulation, RigidObject
from isaaclab.scene import InteractiveSceneCfg
from isaaclab.sensors import TiledCamera, TiledCameraCfg
from isaaclab.sim.utils.stage import get_current_stage
from isaaclab.utils import configclass
from isaaclab.utils.math import quat_apply
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment