import mujoco, numpy as np
import xml.etree.ElementTree as ET
from PIL import Image
root=ET.parse("gripper_testing.urdf").getroot()
for l in root.findall("link"):
    if l.find("inertial") is None:
        i=ET.SubElement(l,"inertial"); ET.SubElement(i,"mass",{"value":"0.1"})
        ET.SubElement(i,"inertia",dict(ixx="1e-4",ixy="0",ixz="0",iyy="1e-4",iyz="0",izz="1e-4"))
mj=ET.Element("mujoco"); c=ET.SubElement(mj,"compiler"); c.set("discardvisual","false"); c.set("meshdir","."); root.insert(0,mj)
m=mujoco.MjModel.from_xml_string(ET.tostring(root,encoding="unicode")); d=mujoco.MjData(m); mujoco.mj_forward(m,d)
views=[(30,-25,0.28),(150,-25,0.28),(90,-10,0.26),(-90,-15,0.26)]
ims=[]
for az,el,dist in views:
    cam=mujoco.MjvCamera(); cam.lookat[:]=[-0.05,0.0,0.01]; cam.distance=dist; cam.azimuth=az; cam.elevation=el
    with mujoco.Renderer(m,470,630) as r: r.update_scene(d,cam); ims.append(r.render())
Image.fromarray(np.hstack(ims)).save("gripper_multi.png"); print("wrote")
