diff --git a/mjx/mujoco/mjx/_src/io_test.py b/mjx/mujoco/mjx/_src/io_test.py index bd39f5f4..953b1f72 100644 --- a/mjx/mujoco/mjx/_src/io_test.py +++ b/mjx/mujoco/mjx/_src/io_test.py @@ -113,6 +113,15 @@ _SIMPLE_BODY = """ """ +_LIGHTS = """ + + + + + + +""" + def _get_name_from_path(path: jax.tree_util.KeyPath) -> str: """Returns a flattened name from a jax.tree_util.KeyPath.""" @@ -203,6 +212,21 @@ class ModelIOTest(parameterized.TestCase): np.testing.assert_equal(mx.wrap_objid, m.wrap_objid) np.testing.assert_almost_equal(mx.wrap_prm, m.wrap_prm) + @parameterized.parameters('jax', 'warp', 'cpp') + def test_put_model_light_active(self, impl): + """Tests that light_active is copied to the public Model field.""" + if impl == 'warp' and not mjxw.WARP_INSTALLED: + self.skipTest('Warp not installed.') + + m = mujoco.MjModel.from_xml_string(_LIGHTS) + mx = mjx.put_model(m, impl=impl) + + self.assertIn('light_active', [f.name for f in mx.fields()]) + np.testing.assert_array_equal( + np.asarray(mx.light_active), + m.light_active.astype(np.asarray(mx.light_active).dtype), + ) + def test_fluid_params(self): """Test that has_fluid_params is set when fluid params are present.""" m = mjx.put_model( diff --git a/mjx/mujoco/mjx/_src/types.py b/mjx/mujoco/mjx/_src/types.py index bc51e6e5..1f3cf7b4 100644 --- a/mjx/mujoco/mjx/_src/types.py +++ b/mjx/mujoco/mjx/_src/types.py @@ -747,6 +747,7 @@ class Model(PyTreeNode): cam_intrinsic: jax.Array light_mode: np.ndarray light_type: jax.Array + light_active: jax.Array light_castshadow: jax.Array light_pos: jax.Array light_dir: jax.Array diff --git a/mjx/mujoco/mjx/warp/render.py b/mjx/mujoco/mjx/warp/render.py index 3fb5a2ea..92311b58 100644 --- a/mjx/mujoco/mjx/warp/render.py +++ b/mjx/mujoco/mjx/warp/render.py @@ -152,6 +152,7 @@ def _render_jax_impl(m: types.Model, d: types.Data, ctx: RenderContextPytree): 'geom_size', 'geom_xmat', 'geom_xpos', + 'light_active', 'light_castshadow', 'light_type', 'mat_rgba', @@ -175,7 +176,7 @@ def _render_jax_impl(m: types.Model, d: types.Data, ctx: RenderContextPytree): m.geom_rgba, m.geom_size, m.geom_type, - m._impl.light_active, + m.light_active, m.light_castshadow, m.light_type, m.mat_rgba, diff --git a/mjx/mujoco/mjx/warp/types.py b/mjx/mujoco/mjx/warp/types.py index 5e7ef094..8f952897 100644 --- a/mjx/mujoco/mjx/warp/types.py +++ b/mjx/mujoco/mjx/warp/types.py @@ -240,7 +240,6 @@ class ModelWarp(PyTreeNode): is_sparse: bool jnt_limited_ball_adr: np.ndarray jnt_limited_slide_hinge_adr: np.ndarray - light_active: jax.Array light_bodyid: np.ndarray light_targetbodyid: np.ndarray mapD2M: np.ndarray