# Copyright 2026 DeepMind Technologies Limited## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.# =============================================================================="""Render helpers for MJX."""fromtypingimportAnyimportjaximportmujoco.mjx.warpasmjxw# pylint: disable=g-importing-memberfrommujoco.mjx._src.typesimportDatafrommujoco.mjx._src.typesimportImplfrommujoco.mjx._src.typesimportModel# pylint: enable=g-importing-memberdef_require_segmentation_enabled(warp_rc)->None:"""Raises if the render context has no segmentation-enabled cameras."""ifnot(warp_rc.seg_adr.numpy()>=0).any():raiseValueError('Render context was not configured with segmentation rendering. ''Pass render_seg=True or enable it for at least one camera in ''create_render_context.')
[docs]defrender(m:Model,d:Data,ctx:Any)->tuple[jax.Array,jax.Array]:"""Render packed RGB and depth buffers."""ifm.impl==Impl.WARPandd.impl==Impl.WARPandmjxw.WARP_INSTALLED:frommujoco.mjx.warpimportrenderasmjxw_render# pytype: disable=import-errorfrommujoco.mjx.warpimportrender_context# pytype: disable=import-errorrender_context.get(ctx)out=mjxw_render.render(m,d,ctx)returnout[0],out[1]raiseNotImplementedError('render only implemented for MuJoCo Warp.')
[docs]defrender_with_segmentation(m:Model,d:Data,ctx:Any)->tuple[jax.Array,jax.Array,jax.Array]:"""Render and return RGB, depth, and packed segmentation outputs. Returns: A tuple ``(rgb, depth, seg)`` of packed buffers. The segmentation buffer stores per-pixel ``(object_id, object_type)`` pairs matching the ``mujoco_warp`` convention. """ifm.impl==Impl.WARPandd.impl==Impl.WARPandmjxw.WARP_INSTALLED:frommujoco.mjx.warpimportrenderasmjxw_render# pytype: disable=import-errorfrommujoco.mjx.warpimportrender_context# pytype: disable=import-errorwarp_rc=render_context.get(ctx)_require_segmentation_enabled(warp_rc)out=mjxw_render.render(m,d,ctx)returnout[0],out[1],out[2]raiseNotImplementedError('render_with_segmentation only implemented for MuJoCo Warp.')