@@ -157,11 +157,11 @@ def render(
157157 ) -> NDArray | None :
158158 if self .viewer is None :
159159 if isinstance (camera , str ):
160- cam_id , cam_name = None , camera
160+ cam_id = mujoco .mj_name2id (self .mj_model , mujoco .mjtObj .mjOBJ_CAMERA , camera )
161+ assert cam_id > - 1 , f"Camera name '{ camera } ' not found in the model."
161162 elif isinstance (camera , int ):
162- cam_id , cam_name = camera , None
163- if cam_id < - 1 :
164- raise ValueError (f"camera id must be >=-1, was { cam_id } " )
163+ cam_id = camera
164+ assert cam_id >= - 1 , f"camera id must be >=-1, was { cam_id } "
165165 else :
166166 raise TypeError ("camera argument must be integer or string" )
167167 self .mj_model .vis .global_ .offwidth = width
@@ -174,8 +174,14 @@ def render(
174174 height = height ,
175175 width = width ,
176176 camera_id = cam_id ,
177- camera_name = cam_name ,
178177 )
178+ # In human mode, cam_id is set to -1, so we force it to the desired value
179+ if mode == "human" and cam_id > - 1 :
180+ # Render one frame to force mj to create the viewer
181+ self .viewer .render (mode )
182+ self .viewer .viewer .cam .fixedcamid = cam_id
183+ self .viewer .viewer .cam .type = mujoco .mjtCamera .mjCAMERA_FIXED
184+
179185 self .mj_data .qpos [:] = self .mjx_data .qpos [world , :]
180186 self .mj_data .mocap_pos [:] = self .mjx_data .mocap_pos [world , :]
181187 self .mj_data .mocap_quat [:] = self .mjx_data .mocap_quat [world , :]
0 commit comments