File size: 5,443 Bytes
406662d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | # Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md).
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
"""Launch Isaac Sim Simulator first."""
from isaaclab.app import AppLauncher
# launch omniverse app
simulation_app = AppLauncher(headless=True).app
"""Rest everything follows."""
import pytest
from isaacsim.core.api.simulation_context import SimulationContext
from pxr import Usd, UsdLux
import isaaclab.sim as sim_utils
from isaaclab.utils.string import to_camel_case
@pytest.fixture(autouse=True)
def sim():
"""Setup and teardown for each test."""
# Setup: Create a new stage
sim_utils.create_new_stage()
# Simulation time-step
dt = 0.1
# Load kit helper
sim = SimulationContext(physics_dt=dt, rendering_dt=dt, backend="numpy")
# Wait for spawning
sim_utils.update_stage()
# Yield the simulation context for the test
yield sim
# Teardown: Stop simulation
sim.stop()
sim.clear()
sim.clear_all_callbacks()
sim.clear_instance()
def test_spawn_disk_light(sim):
"""Test spawning a disk light source."""
cfg = sim_utils.DiskLightCfg(
color=(0.1, 0.1, 0.1), enable_color_temperature=True, color_temperature=5500, intensity=100, radius=20.0
)
prim = cfg.func("/World/disk_light", cfg)
# check if the light is spawned
assert prim.IsValid()
assert sim.stage.GetPrimAtPath("/World/disk_light").IsValid()
assert prim.GetPrimTypeInfo().GetTypeName() == "DiskLight"
# validate properties on the prim
_validate_properties_on_prim(prim, cfg)
def test_spawn_distant_light(sim):
"""Test spawning a distant light."""
cfg = sim_utils.DistantLightCfg(
color=(0.1, 0.1, 0.1), enable_color_temperature=True, color_temperature=5500, intensity=100, angle=20
)
prim = cfg.func("/World/distant_light", cfg)
# check if the light is spawned
assert prim.IsValid()
assert sim.stage.GetPrimAtPath("/World/distant_light").IsValid()
assert prim.GetPrimTypeInfo().GetTypeName() == "DistantLight"
# validate properties on the prim
_validate_properties_on_prim(prim, cfg)
def test_spawn_dome_light(sim):
"""Test spawning a dome light source."""
cfg = sim_utils.DomeLightCfg(
color=(0.1, 0.1, 0.1), enable_color_temperature=True, color_temperature=5500, intensity=100
)
prim = cfg.func("/World/dome_light", cfg)
# check if the light is spawned
assert prim.IsValid()
assert sim.stage.GetPrimAtPath("/World/dome_light").IsValid()
assert prim.GetPrimTypeInfo().GetTypeName() == "DomeLight"
# validate properties on the prim
_validate_properties_on_prim(prim, cfg)
def test_spawn_cylinder_light(sim):
"""Test spawning a cylinder light source."""
cfg = sim_utils.CylinderLightCfg(
color=(0.1, 0.1, 0.1), enable_color_temperature=True, color_temperature=5500, intensity=100, radius=20.0
)
prim = cfg.func("/World/cylinder_light", cfg)
# check if the light is spawned
assert prim.IsValid()
assert sim.stage.GetPrimAtPath("/World/cylinder_light").IsValid()
assert prim.GetPrimTypeInfo().GetTypeName() == "CylinderLight"
# validate properties on the prim
_validate_properties_on_prim(prim, cfg)
def test_spawn_sphere_light(sim):
"""Test spawning a sphere light source."""
cfg = sim_utils.SphereLightCfg(
color=(0.1, 0.1, 0.1), enable_color_temperature=True, color_temperature=5500, intensity=100, radius=20.0
)
prim = cfg.func("/World/sphere_light", cfg)
# check if the light is spawned
assert prim.IsValid()
assert sim.stage.GetPrimAtPath("/World/sphere_light").IsValid()
assert prim.GetPrimTypeInfo().GetTypeName() == "SphereLight"
# validate properties on the prim
_validate_properties_on_prim(prim, cfg)
"""
Helper functions.
"""
def _validate_properties_on_prim(prim: Usd.Prim, cfg: sim_utils.LightCfg):
"""Validate the properties on the prim.
Args:
prim: The prim.
cfg: The configuration for the light source.
"""
# default list of params to skip
non_usd_params = ["func", "prim_type", "visible", "semantic_tags", "copy_from_source"]
# validate the properties
for attr_name, attr_value in cfg.__dict__.items():
# skip names we know are not present
if attr_name in non_usd_params or attr_value is None:
continue
# deal with texture input names
if "texture" in attr_name:
light_prim = UsdLux.DomeLight(prim)
if attr_name == "texture_file":
configured_value = light_prim.GetTextureFileAttr().Get()
elif attr_name == "texture_format":
configured_value = light_prim.GetTextureFormatAttr().Get()
else:
raise ValueError(f"Unknown texture attribute: '{attr_name}'")
else:
# convert attribute name in prim to cfg name
if attr_name == "visible_in_primary_ray":
prim_prop_name = f"{to_camel_case(attr_name, to='cC')}"
else:
prim_prop_name = f"inputs:{to_camel_case(attr_name, to='cC')}"
# configured value
configured_value = prim.GetAttribute(prim_prop_name).Get()
# validate the values
assert configured_value == attr_value, f"Failed for attribute: '{attr_name}'"
|