Skip to content

Commit

Permalink
when removing ancestral prims (all scene objects now), we deactivate …
Browse files Browse the repository at this point in the history
…them
  • Loading branch information
ChengshuLi committed Sep 24, 2024
1 parent 3ac33e0 commit cf6e32c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 33 deletions.
9 changes: 4 additions & 5 deletions omnigibson/prims/prim_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import omnigibson as og
import omnigibson.lazy as lazy
from omnigibson.utils.python_utils import Recreatable, Serializable
from omnigibson.utils.sim_utils import check_deletable_prim
from omnigibson.utils.ui_utils import create_module_logger
from omnigibson.utils.usd_utils import scene_relative_prim_path_to_absolute
from omnigibson.utils.usd_utils import delete_or_deactivate_prim, scene_relative_prim_path_to_absolute

# Create module logger
log = create_module_logger(module_name=__name__)
Expand Down Expand Up @@ -133,9 +132,9 @@ def remove(self):
if not self._loaded:
raise ValueError("Cannot remove a prim that was never loaded.")

# Remove prim if it can be deleted
if check_deletable_prim(self.prim_path):
lazy.omni.isaac.core.utils.prims.delete_prim(self.prim_path)
# Remove or deactivate prim if it's possible
if not delete_or_deactivate_prim(self.prim_path):
log.warning(f"Prim {self.name} at prim_path {self.prim_path} could not be deleted or deactivated.")

def _load(self):
"""
Expand Down
28 changes: 0 additions & 28 deletions omnigibson/utils/sim_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,6 @@ def set_carb_setting(carb_settings, setting, value):
raise TypeError(f"Value of type {type(value)} is not supported.")


def check_deletable_prim(prim_path):
"""
Checks whether the prim defined at @prim_path can be deleted.
Args:
prim_path (str): Path defining which prim should be checked for deletion
Returns:
bool: Whether the prim can be deleted or not
"""
if not lazy.omni.isaac.core.utils.prims.is_prim_path_valid(prim_path):
return False
if lazy.omni.isaac.core.utils.prims.is_prim_no_delete(prim_path):
return False
if lazy.omni.isaac.core.utils.prims.is_prim_ancestral(prim_path):
return False
if lazy.omni.isaac.core.utils.prims.get_prim_type_name(prim_path=prim_path) == "PhysicsScene":
return False
if prim_path == "/World":
return False
if prim_path == "/":
return False
# Don't remove any /Render prims as that can cause crashes
if prim_path.startswith("/Render"):
return False
return True


def prims_to_rigid_prim_set(inp_prims):
"""
Converts prims @inp_prims into its corresponding set of rigid prims
Expand Down
36 changes: 36 additions & 0 deletions omnigibson/utils/usd_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1743,3 +1743,39 @@ def deep_copy_prim(source_root_prim, dest_stage, dest_root_path):
for child in source_prim.GetAllChildren():
new_dest_path = dest_path + "/" + child.GetName()
queue.append((child, new_dest_path))


def delete_or_deactivate_prim(prim_path):
"""
Attept to delete or deactivate the prim defined at @prim_path.
Args:
prim_path (str): Path defining which prim should be deleted or deactivated
Returns:
bool: Whether the operation was successful or not
"""
if not lazy.omni.isaac.core.utils.prims.is_prim_path_valid(prim_path):
return False
if lazy.omni.isaac.core.utils.prims.is_prim_no_delete(prim_path):
return False
if lazy.omni.isaac.core.utils.prims.get_prim_type_name(prim_path=prim_path) == "PhysicsScene":
return False
if prim_path == "/World":
return False
if prim_path == "/":
return False
# Don't remove any /Render prims as that can cause crashes
if prim_path.startswith("/Render"):
return False

# If the prim is not ancestral, we can delete it.
if not lazy.omni.isaac.core.utils.prims.is_prim_ancestral(prim_path):
lazy.omni.usd.commands.DeletePrimsCommand([prim_path], destructive=True).do()

# Otherwise, we can only deactivate it, which essentially serves the same purpose.
# All objects that are originally in the scene are ancestral because we add the pre-build scene to the stage.
else:
lazy.omni.usd.commands.DeletePrimsCommand([prim_path], destructive=False).do()

return True

0 comments on commit cf6e32c

Please sign in to comment.