import mujoco, numpy as np
from PIL import Image
def build(off):
    return f"""<mujoco><compiler meshdir="." angle="radian"/>
  <asset>
    <mesh name="A" file="base_holder_detach.stl" scale="0.001 0.001 0.001"/>
    <mesh name="B" file="fiducial_mount.stl" scale="0.001 0.001 0.001"/>
    <texture name="sky" type="skybox" builtin="gradient" rgb1=".35 .5 .7" rgb2=".05 .05 .1" width="256" height="256"/></asset>
  <visual><global offwidth="1500" offheight="950"/><headlight ambient="0.5 0.5 0.5" diffuse="0.5 0.5 0.5"/></visual>
  <worldbody><light pos="0.15 0.25 0.4" dir="-0.3 -0.4 -1" directional="true"/>
    <geom type="mesh" mesh="A" rgba=".2 .52 .85 1"/>
    <geom type="mesh" mesh="B" rgba=".93 .55 .16 1" pos="0 {off} 0"/></worldbody></mujoco>"""
def shot(off, look, dist, az, el, w=740, h=930):
    m = mujoco.MjModel.from_xml_string(build(off)); d = mujoco.MjData(m); mujoco.mj_forward(m, d)
    c = mujoco.MjvCamera(); c.lookat[:] = look; c.distance = dist; c.azimuth = az; c.elevation = el
    with mujoco.Renderer(m, w, h) as r: r.update_scene(d, c); return r.render()
panels = [
    shot(0.0,  [-0.02, -0.03, -0.13], 0.46, 62, -20),      # whole, mated
    shot(0.05, [0.04, -0.005, -0.03], 0.13, 38, 14),
]
Image.fromarray(np.hstack(panels)).save("detach_view.png"); print("wrote")
