Skip to content

Add update_hfield, update_mesh, update_texture methods to Renderer class#3030

Open
Wheeeeeeeeels wants to merge 1 commit intogoogle-deepmind:mainfrom
Wheeeeeeeeels:feat/renderer-update-methods
Open

Add update_hfield, update_mesh, update_texture methods to Renderer class#3030
Wheeeeeeeeels wants to merge 1 commit intogoogle-deepmind:mainfrom
Wheeeeeeeeels:feat/renderer-update-methods

Conversation

@Wheeeeeeeeels
Copy link

Summary

Add three new methods to the Renderer class that allow uploading modified asset data to the GPU after the model has been loaded:

  • update_hfield(hfieldid): Uploads height field data
  • update_mesh(meshid): Uploads mesh vertex data
  • update_texture(texid): Uploads texture data

This enables dynamic modification of terrain, meshes, and textures without recreating the entire renderer.

Fixes #1410

Implementation

These methods wrap the corresponding mjr_upload* C functions with proper validation and GL context handling. Each method:

  • Checks if renderer is still open (raises RuntimeError if closed)
  • Validates the ID is within valid range (raises ValueError if not)
  • Makes the GL context current before calling the upload function

Example Usage

import mujoco

model = mujoco.MjModel.from_xml_path("terrain.xml")
data = mujoco.MjData(model)

with mujoco.Renderer(model, 480, 640) as renderer:
    # Modify height field data
    model.hfield_data[...] = new_terrain_data
    renderer.update_hfield(0)  # Upload to GPU
    
    renderer.update_scene(data)
    pixels = renderer.render()

Tests

Added 9 unit tests covering:

  • Successful update operations for each asset type
  • Out-of-range ID validation (negative and >= max)
  • Post-close behavior (RuntimeError)

All 15 tests pass:

python/mujoco/renderer_test.py ... 15 passed in 5.14s

@google-cla
Copy link

google-cla bot commented Jan 20, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@Wheeeeeeeeels Wheeeeeeeeels force-pushed the feat/renderer-update-methods branch from f298120 to 78da4a0 Compare January 20, 2026 08:21
@Wheeeeeeeeels Wheeeeeeeeels force-pushed the feat/renderer-update-methods branch from 78da4a0 to 0b8e805 Compare January 20, 2026 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

user_scn and update_hfield() equivalents in Renderer class

1 participant