Skip to content

Commit 5e343a5

Browse files
committed
Updates to material override
1 parent e1a5f4d commit 5e343a5

File tree

3 files changed

+66
-25
lines changed

3 files changed

+66
-25
lines changed

omnigibson/examples/scenes/scene_selector.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,15 @@ def main(random_selection=False, headless=False, short_exec=False):
4444
}
4545
load_mode = choose_from_options(options=load_options, name="load mode", random_selection=random_selection)
4646
if load_mode == "Quick":
47-
cfg["scene"]["load_object_categories"] = ["floors", "walls", "ceilings"]
47+
cfg["scene"]["load_object_categories"] = [
48+
"floors",
49+
"walls",
50+
"ceilings",
51+
"lawn",
52+
"driveway",
53+
"roof",
54+
"rail_fence",
55+
]
4856

4957
# Load the environment
5058
env = og.Environment(configs=cfg)

omnigibson/prims/entity_prim.py

+2-23
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@
1515
from omnigibson.prims.rigid_kinematic_prim import RigidKinematicPrim
1616
from omnigibson.prims.xform_prim import XFormPrim
1717
from omnigibson.utils.constants import JointAxis, JointType, PrimType
18-
from omnigibson.utils.ui_utils import create_module_logger
18+
from omnigibson.utils.render_utils import force_pbr_material_for_link
1919
from omnigibson.utils.usd_utils import PoseAPI, absolute_prim_path_to_scene_relative
2020

2121
# Create settings for this module
2222
m = create_module_macros(module_path=__file__)
2323

24-
# Create module logger
25-
log = create_module_logger(module_name=__name__)
26-
2724
# Default sleep threshold for all objects -- see https://docs.omniverse.nvidia.com/extensions/latest/ext_physics/simulation-control/physics-settings.html?highlight=sleep#sleeping
2825
# Mass-normalized kinetic energy threshold below which an actor may go to sleep
2926
m.DEFAULT_SLEEP_THRESHOLD = 0.00005
@@ -262,25 +259,7 @@ def update_links(self):
262259

263260
# Apply the V-Ray to PBR material change if request by the macro
264261
if gm.USE_PBR_MATERIALS:
265-
# Find the material prim that has the link's name in it
266-
link_pbr_material_pattern = f"__{link_name}_pbr"
267-
looks_prim = self._prim.GetChild("Looks")
268-
if not looks_prim:
269-
log.debug("Could not find Looks prim for", self.prim_path)
270-
else:
271-
for mtl_prim in looks_prim.GetChildren():
272-
mtl_prim_name = mtl_prim.GetName()
273-
if link_pbr_material_pattern in mtl_prim_name:
274-
# Bind that material and stop
275-
lazy.omni.kit.commands.execute(
276-
"BindMaterialCommand",
277-
prim_path=prim.GetPrimPath().__str__(),
278-
material_path=mtl_prim.GetPrimPath().__str__(),
279-
strength=None,
280-
)
281-
break
282-
else:
283-
log.warning("Could not find PBR material for link", link_name, "of", self.prim_path)
262+
force_pbr_material_for_link(self._prim, link_name)
284263

285264
# Create and load the link
286265
self._links[link_name] = link_cls(

omnigibson/utils/render_utils.py

+55-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
"""
44

55
import omnigibson.lazy as lazy
6-
from omnigibson.prims import EntityPrim, RigidPrim, VisualGeomPrim
76
from omnigibson.utils.physx_utils import bind_material
7+
from omnigibson.utils.ui_utils import create_module_logger
8+
9+
10+
# Create module logger
11+
log = create_module_logger(module_name=__name__)
812

913

1014
def make_glass(prim):
@@ -15,6 +19,9 @@ def make_glass(prim):
1519
Args:
1620
prim (EntityPrim or RigidPrim or VisualGeomPrim): Desired prim to convert into glass
1721
"""
22+
# Do this here to avoid circular imports
23+
from omnigibson.prims import EntityPrim, RigidPrim, VisualGeomPrim
24+
1825
# Generate the set of visual meshes we'll convert into glass
1926
if isinstance(prim, EntityPrim):
2027
# Grab all visual meshes from all links
@@ -72,3 +79,50 @@ def create_pbr_material(prim_path):
7279

7380
# Return generated material
7481
return lazy.isaacsim.core.utils.prims.get_prim_at_path(material_path)
82+
83+
84+
def force_pbr_material_for_link(entity_prim, link_name):
85+
if "meta__" in link_name:
86+
# Don't override the meta link material
87+
return
88+
89+
entity_prim_path = entity_prim.GetPrimPath().__str__()
90+
looks_prim = entity_prim.GetChild("Looks")
91+
link_prim = entity_prim.GetChild(link_name)
92+
assert link_prim, f"Could not find link {link_name} for {entity_prim_path}"
93+
94+
link_visuals_prim = link_prim.GetChild("visuals")
95+
if not looks_prim:
96+
log.debug(f"Could not find Looks prim for {entity_prim_path}")
97+
return
98+
99+
if not link_visuals_prim:
100+
log.warning(f"Could not find visuals prim for link {link_name} of {entity_prim_path}")
101+
return
102+
103+
binding_api = (
104+
lazy.pxr.UsdShade.MaterialBindingAPI(link_visuals_prim)
105+
if link_visuals_prim.HasAPI(lazy.pxr.UsdShade.MaterialBindingAPI)
106+
else lazy.pxr.UsdShade.MaterialBindingAPI.Apply(link_visuals_prim)
107+
)
108+
109+
material_path = binding_api.GetDirectBinding().GetMaterialPath().pathString
110+
if "OmniGlass" in material_path:
111+
# Don't override the glass material
112+
return
113+
114+
# Find the material prim that has the link's name in it
115+
link_pbr_material_pattern = f"__{link_name}_pbr"
116+
for mtl_prim in looks_prim.GetChildren():
117+
mtl_prim_name = mtl_prim.GetName()
118+
if link_pbr_material_pattern in mtl_prim_name:
119+
# Bind that material and stop
120+
lazy.omni.kit.commands.execute(
121+
"BindMaterialCommand",
122+
prim_path=link_visuals_prim.GetPrimPath().__str__(),
123+
material_path=mtl_prim.GetPrimPath().__str__(),
124+
strength=None,
125+
)
126+
return
127+
else:
128+
log.warning(f"Could not find PBR material for link {link_name} of {entity_prim_path}")

0 commit comments

Comments
 (0)