<?xml version="1.0" encoding="utf-8"?>
<mujoco>
    <compiler strippath="true" meshdir="{{ template_dir }}/meshes" texturedir="{{ template_dir }}/textures" inertiafromgeom= "true" angle="radian" inertiagrouprange="0 0"/>
    <option timestep="{{ timestep }}" impratio="{{ impratio }}" cone="{{ cone_type }}" />
    <size nconmax="5000" njmax="5000"/>
    <visual>
        <headlight ambient="1 1 1" diffuse="1 1 1" specular="1 1 1" />
    </visual>
    <asset>
        <texture builtin="gradient" height="100" rgb1="1 1 1" rgb2="0 0 0" type="skybox" width="100"/>
        <texture name="texplane" type="2d" builtin="checker" rgb1=".2 .3 .4" rgb2=".1 0.15 0.2" width="512" height="512"/>
        <texture name="texplane2" type="2d" builtin="checker" rgb1=".2 .3 .4" rgb2=".1 0.15 0.2" width="512" height="512"/>
        <texture name="texplane3" type="2d" builtin="checker" rgb1=".2 .3 .4" rgb2=".1 0.15 0.2" width="512" height="512"/>
        <material name="floorplane" reflectance="0.01" shininess="0.0" specular="0.0" texrepeat="2 2" texture="texplane" texuniform="true"/>
        <material name="floorplane2" reflectance="0.01" shininess="0.0" specular="0.0" texrepeat="2 2" texture="texplane2" texuniform="true"/>
        <material name="floorplane3" reflectance="0.01" shininess="0.0" specular="0.0" texrepeat="2 2" texture="texplane2" texuniform="true"/>
        <mesh name="link0" file="meshes/link0.stl" />
        <mesh name="link1" file="meshes/link1.stl" />
        <mesh name="link2" file="meshes/link2.stl" />
        <mesh name="link3" file="meshes/link3.stl" />
        <mesh name="link4" file="meshes/link4.stl" />
        <mesh name="link5" file="meshes/link5.stl" />
        <mesh name="link6" file="meshes/link6.stl" />
        <mesh name="link7" file="meshes/link7.stl" />
        <mesh name="link0_vis" file="meshes/link0_vis.stl" />
        <mesh name="link1_vis" file="meshes/link1_vis.stl" />
        <mesh name="link2_vis" file="meshes/link2_vis.stl" />
        <mesh name="link3_vis" file="meshes/link3_vis.stl" />
        <mesh name="link4_vis" file="meshes/link4_vis.stl" />
        <mesh name="link5_vis" file="meshes/link5_vis.stl" />
        <mesh name="link6_vis" file="meshes/link6_vis.stl" />
        <mesh name="link7_vis" file="meshes/link7_vis.stl" />
        <mesh name="finger_plastic" file="meshes/3dprinted_finger.stl" />
        <mesh name="hand" file="meshes/hand.stl" />
        <mesh name="hand_vis" file="meshes/hand_vis.stl" />
        <mesh name="finger" file="meshes/finger.stl" />
        <mesh name="finger_vis" file="meshes/finger_vis.stl" />
        <mesh name="finger_vis2" file="meshes/finger_longer.stl" />


        <texture name="bath_real_texture" type="2d" file="textures/cloth.png" />
        <material name="bath_real_material" texture="bath_real_texture"/>

        <texture name="bath_2_real_texture" type="2d" file="textures/cloth.png" />
        <material name="bath_2_real_material" texture="bath_2_real_texture"/>

        <texture name="kitchen_real_texture" type="2d" file="textures/kitchen_side.png" />
        <material name="kitchen_real_material" texture="kitchen_real_texture"/>

        <texture name="kitchen_2_real_texture" type="2d" file="textures/kitchen_up.png" />
        <material name="kitchen_2_real_material" texture="kitchen_2_real_texture"/>

        <texture name="wipe_real_texture" type="2d" file="textures/wipe1.png" />
        <material name="wipe_real_material" texture="wipe_real_texture"/>

        <texture name="wipe_2_real_texture" type="2d" file="textures/wipe2.png" />
        <material name="wipe_2_real_material" texture="wipe_2_real_texture"/>

        <texture name="table_real_texture" type="cube" file="textures/table.png" />
        <material name="table_real_material" texture="table_real_texture"/>

        <texture name="floor_real_texture" type="2d" file="textures/wall.png" />
        <material name="floor_real_material" texture="floor_real_texture"/>


        <texture name="white_borders" type="2d" file="textures/white_borders.png"/>
        <material name="white_borders" texture="white_borders"/>

        <texture name="blue_real_texture" type="2d" file="textures/blue.png"/>
        <material name="blue_real_material" texture="blue_real_texture"/>

        <texture name="white_real_texture" type="2d" file="textures/white.png"/>
        <material name="white_real_material" texture="white_real_texture"/>

        <texture name="orange_real_texture" type="2d" file="textures/orange.png"/>
        <material name="orange_real_material" texture="orange_real_texture"/>



        <texture width="{{cloth_texture_width}}" height="{{cloth_texture_height}}" name="cloth_texture" type="2d" random="{{cloth_texture_random}}" rgb1="{{cloth_texture_r_1}} {{cloth_texture_g_1}} {{cloth_texture_b_1}}" rgb2="{{cloth_texture_r_2}} {{cloth_texture_g_2}} {{cloth_texture_b_2}}" builtin="{{cloth_texture_builtin}}" mark="{{cloth_texture_mark}}" />
        <material texrepeat="{{cloth_texture_repeat_x}} {{cloth_texture_repeat_y}}" name="cloth_material" texture="cloth_texture" />

        <texture width="{{table_texture_width}}" height="{{table_texture_height}}" name="table_texture" type="cube" random="{{table_texture_random}}" rgb1="{{table_texture_r_1}} {{table_texture_g_1}} {{table_texture_b_1}}" rgb2="{{table_texture_r_2}} {{table_texture_g_2}} {{table_texture_b_2}}" builtin="{{table_texture_builtin}}" mark="{{table_texture_mark}}" />
        <material texrepeat="{{table_texture_repeat_x}} {{table_texture_repeat_y}}" name="table_material" texture="table_texture" />

        <texture width="{{floor_texture_width}}" height="{{floor_texture_height}}" name="floor_texture" type="2d" random="{{floor_texture_random}}" rgb1="{{floor_texture_r_1}} {{floor_texture_g_1}} {{floor_texture_b_1}}" rgb2="{{floor_texture_r_2}} {{floor_texture_g_2}} {{floor_texture_b_2}}" builtin="{{floor_texture_builtin}}" mark="{{floor_texture_mark}}" />
        <material texrepeat="{{floor_texture_repeat_x}} {{floor_texture_repeat_y}}" name="floor_material" texture="floor_texture" />



        <texture width="{{robot1_texture_width}}" height="{{robot1_texture_height}}" name="robot1_texture" type="2d" random="{{robot1_texture_random}}" rgb1="{{robot1_texture_r_1}} {{robot1_texture_g_1}} {{robot1_texture_b_1}}" rgb2="{{robot1_texture_r_2}} {{robot1_texture_g_2}} {{robot1_texture_b_2}}" builtin="{{robot1_texture_builtin}}" mark="{{robot1_texture_mark}}" />
        <material texrepeat="{{robot1_texture_repeat_x}} {{robot1_texture_repeat_y}}" name="robot1_material" texture="robot1_texture" />

        <texture width="{{robot2_texture_width}}" height="{{robot2_texture_height}}" name="robot2_texture" type="2d" random="{{robot2_texture_random}}" rgb1="{{robot2_texture_r_1}} {{robot2_texture_g_1}} {{robot2_texture_b_1}}" rgb2="{{robot2_texture_r_2}} {{robot2_texture_g_2}} {{robot2_texture_b_2}}" builtin="{{robot2_texture_builtin}}" mark="{{robot2_texture_mark}}" />
        <material texrepeat="{{robot2_texture_repeat_x}} {{robot2_texture_repeat_y}}" name="robot2_material" texture="robot2_texture" />



    </asset>
    <worldbody>

        <geom name="ground" pos="0 0 0" size="5 5 10" type="plane" contype="1" conaffinity="1" material="{{floor_material_name}}"  />

        <body name="tabletop" pos="0.4 0 0">
            <geom name="la_tabla_col" type="box" pos="0 0 0" size="0.3 0.3 {{0.1333164 - geom_size}}" group="0" />
            <geom name="la_tabla_vis" type="box" material="{{table_material_name}}" pos="0 0 0" size="0.3 0.3 0.13" group="1" />
        </body>

        <composite type="grid" count="{{num_cloth_geoms}} {{num_cloth_geoms}} 1" spacing="{{geom_spacing}}" offset="{{0.62288139 - offset }} {{0.13480165 - offset }} 0.1333164"  >
            <joint kind="main" solimpfix="{{joint_solimp_low}} {{joint_solimp_high}} {{joint_solimp_width}}" solreffix="{{joint_solref_timeconst}} {{joint_solref_dampratio}}" />
            <tendon solimpfix="{{tendon_shear_solimp_low}} {{tendon_shear_solimp_high}} {{tendon_shear_solimp_width}}" solreffix="{{tendon_shear_solref_timeconst}} {{tendon_shear_solref_dampratio}}" width="0.001" kind="shear" />
            <tendon solimpfix="{{tendon_main_solimp_low}} {{tendon_main_solimp_high}} {{tendon_main_solimp_width}}" solreffix="{{tendon_main_solref_timeconst}} {{tendon_main_solref_dampratio}}" kind="main" />
            
            <skin material="{{cloth_material_name}}" texcoord="true" inflate="0.001" subgrid="3"/>

            <geom group="0" type="sphere" size="{{ geom_size }}" rgba="0 0 1 0.8" friction='{{ friction }} {{ friction }} {{ friction }}' solimp="{{geom_solimp_low}} {{geom_solimp_high}} {{geom_solimp_width}}" solref="{{geom_solref_timeconst}} {{geom_solref_dampratio}}" condim='4' />
        </composite>

        <body mocap="true" name="lookatbody" pos="0.49476399 0.00668401 0.13310541" />


    {% if lights_randomization %}
        {% for i in range(num_lights) %}
            <light name="{{ i }}_noshad" diffuse=".8 .8 .8" dir="0 -.15 -1" directional="true" pos="0.1 0.1 0.1" specular="0.3 0.3 0.3" castshadow="true"/>
            <light name="{{ i }}_shad" diffuse=".8 .8 .8" dir="0 -.15 -1" directional="true" pos="-0.5 -0.5 0.5" specular="0.3 0.3 0.3" castshadow="true"/>
        {% endfor %}
    {% endif %}







        <!-- front view -->
        <camera mode="fixed" name="frontview" pos="0.35 -0.1 0.25" quat="0.56 0.43 0.43 0.56"/>

        <camera fovy="{{train_camera_fovy}}" mode="targetbody" target="lookatbody" name="up" pos="0.5 -0.7  1.1"/>
        <camera fovy="{{train_camera_fovy}}" mode="targetbody" target="lookatbody" name="side" pos="-0.4 -0.7  0.65"/> 
        <camera fovy="{{train_camera_fovy}}" mode="targetbody" target="lookatbody" name="front" pos="0.5 -1.0  0.75"/> 

        <camera mode="targetbodycom" target="tabletop" name="eval_camera" pos="-0.45 -1 1"/>
        <!--cloth view -->
        <camera mode="fixed" name="clothview" pos="0.3 -0.15 0.42" quat="0.653 0.271 0.271 0.653"/>
        <!--cloth view 2 -->
        <camera mode="fixed" name="clothview2" pos="0.08 -0.16 0.6" quat="0.7071 0 0 0.7071"/>
        <!-- bird view -->
        <camera mode="fixed" name="birdview" pos="-0.2 0 3.0" quat="0.7071 0 0 0.7071"/>
        <!-- agent view -->
        <camera mode="fixed" name="agentview" pos="0.5 0 1.35" quat="0.653 0.271 0.271 0.653"/>
        <!-- side view -->
        <camera name="sideview" pos="0.1 0.2 0.3" quat="0.2 0 0.5 0.75" />
        <camera mode="fixed" name="eye_in_hand" pos="0.05 0 0" quat="0 0.707108 0.707108 0" fovy="75"/>

        <body name="base" pos="0 0 0">
            <camera name="robotview" pos="1 0 0.4" quat="0.653 0.271 0.271 0.653"/>
            <body name="link0" pos="0 0 0">
                <geom name="link0_visual" type="mesh" contype="0" conaffinity="0" group="1" rgba="1 1 1 1" mesh="link0_vis"/>
                <geom name="link0_collision" type="mesh" rgba="0 0.5 0 1" mesh="link0"/>
                <body name="link1" pos="0 0 0.333">
                    <joint name="joint1" pos="0 0 0" axis="0 0 1" limited="true" range="-2.8973 2.8973" />
                    <geom name="link1_visual" type="mesh" contype="0" conaffinity="0" group="1" rgba="1 1 1 1" mesh="link1_vis"/>
                    <geom name="link1_collision" type="mesh" rgba="0 0.5 0 1" mesh="link1"/>
                    <body name="link2" pos="0 0 0" quat="0.707107 -0.707107 0 0">
                        <joint name="joint2" pos="0 0 0" axis="0 0 1" limited="true" range="-1.7628 1.7628"/>
                        <geom name="link2_visual" type="mesh" contype="0" conaffinity="0" group="1" rgba="1 1 1 1" mesh="link2_vis"/>
                        <geom name="link2_collision" type="mesh" rgba="0 0.5 0 1" mesh="link2"/>
                        <body name="link3" pos="0 -0.316 0" quat="0.707107 0.707107 0 0">
                            <joint name="joint3" pos="0 0 0" axis="0 0 1" limited="true" range="-2.8973 2.8973" />
                            <geom name="link3_visual" type="mesh" contype="0" conaffinity="0" group="1" rgba="1 1 1 1" mesh="link3_vis"/>
                            <geom name="link3_collision" type="mesh" rgba="0 0.5 0 1" mesh="link3"/>
                            <body name="link4" pos="0.0825 0 0" quat="0.707107 0.707107 0 0">
                                <joint name="joint4" pos="0 0 0" axis="0 0 1" limited="true" range="-3.0718 -0.0698" />
                                <geom name="link4_visual" type="mesh" contype="0" conaffinity="0" group="1" rgba="1 1 1 1" mesh="link4_vis"/>
                                <geom name="link4_collision" type="mesh" rgba="0 0.5 0 1" mesh="link4"/>
                                <body name="link5" pos="-0.0825 0.384 0" quat="0.707107 -0.707107 0 0">
                                    <joint name="joint5" pos="0 0 0" axis="0 0 1" limited="true" range="-2.8973 2.8973" />
                                    <geom name="link5_visual" type="mesh" contype="0" conaffinity="0" group="1" rgba="1 1 1 1" mesh="link5_vis"/>
                                    <geom name="link5_collision" type="mesh" rgba="0 0.5 0 1" mesh="link5"/>
                                    <body name="link6" pos="0 0 0" quat="0.707107 0.707107 0 0">
                                        <joint name="joint6" pos="0 0 0" axis="0 0 1" limited="true" range="-0.0175 3.7525"/>
                                        <geom name="link6_visual" type="mesh" contype="0" conaffinity="0" group="1" rgba="1 1 1 1" mesh="link6_vis"/>
                                        <geom name="link6_collision" type="mesh" rgba="0 0.5 0 1" mesh="link6"/>
                                        <body name="link7" pos="0.088 0 0" quat="0.707107 0.707107 0 0">
                                            <joint name="joint7" pos="0 0 0" axis="0 0 1" limited="true" range="-2.8973 2.8973"/>
                                            <geom name="link7_visual" type="mesh" contype="0" conaffinity="0" group="1" rgba="1 1 1 1" mesh="link7_vis"/>
                                            <geom name="link7_collision" type="mesh" rgba="0 0.5 0 1" mesh="link7"/>
                                            <body name="right_hand" pos="0 0 0.1065" quat="0.923785 0 0 -0.382911">
                                                <site name="ee" pos="0 0 0" size="0.01" group="1" rgba="0 0 1 1"/>
                                                <site name="ee_x" pos="0 0 0" quat="0.707105 0.707108 0 0" size="0.005 0.1" group="1" type="cylinder" rgba="1 0 0 0"/>
                                                <site name="ee_z" pos="0 0 0" quat="0.707105 0 0 0.707108" size="0.005 0.1" group="1" type="cylinder" rgba="0 0 1 0"/>
                                                <site name="ee_y" pos="0 0 0" quat="0.707105 0 0.707108 0" size="0.005 0.1" group="1" type="cylinder" rgba="0 1 0 0"/>
                                                <camera name="eye_in_handu" pos="0.05 0 0" quat="0 0.707108 0.707108 0" fovy="75"/>
                                                <body name="right_gripper" pos="0 0 0" quat="0.707107 0 0 -0.707107">
                                                    {% if materials_randomization %}
                                                        <geom name="hand_visual" material="robot1_material" quat="0.707107 0 0 0.707107" type="mesh" contype="0" conaffinity="0" group="1" rgba="1 1 1 1" mesh="hand_vis"/>
                                                    {% else %}
                                                        <geom name="hand_visual" quat="0.707107 0 0 0.707107" type="mesh" contype="0" conaffinity="0" group="1" rgba="1 1 1 1" mesh="hand_vis"/>
                                                    {% endif %}
                                                    <geom name="hand_collision" quat="0.707107 0 0 0.707107" type="mesh" rgba="0 0 0.5 1" mesh="hand"/>
                                                    <geom name="grip_geom" size="0.0025" pos="0 0 0.16" group="0" contype="0" conaffinity="0" rgba="1 0 0 0.5"/>
                                                    <site name="ft_frame" pos="0 0 0" size="0.01" group="1" rgba="1 0 0 1"/>
                                                    <site name="grip_site" pos="0 0 0.10377" size="0.0025" group="1" rgba="1 0 0 0.5"/>
                                                    <body name="leftfinger" pos="0 0 0.063" quat="0.707107 0 0 0.707107">
                                                            <geom name="finger1_visual" type="mesh" contype="0" conaffinity="0" group="1" rgba="0 0 0 1" mesh="finger_plastic"/>
                                                    </body>
                                                    <body name="rightfinger" pos="0 0 0.063" quat="0.707107 0 0 0.707107">
                                                            <geom name="finger2_visual" quat="0 0 0 1" type="mesh" contype="0" conaffinity="0" group="1" rgba="0 0 0 1" mesh="finger_plastic"/>
                                                    </body>
                                                </body>
                                            </body>
                                        </body>
                                    </body>
                                </body>
                            </body>
                        </body>
                    </body>
                </body>
            </body>
        </body>

        <!--
        <body mocap="true" name="robot0:mocap" pos="0.00078214 -0.0042735   0.20663855">
            <geom group="1" name="mocap" conaffinity="0" contype="0" pos="0  0  0" rgba="0 0 1 1" size="0.005 0.005 0.005" type="box"></geom>
        </body> -->
    </worldbody>

    <actuator>
        <!-- Physical limits of the actuator. -->
        <motor joint="joint1" name="torq_j1"/>
        <motor joint="joint2" name="torq_j2"/>
        <motor joint="joint3" name="torq_j3"/>
        <motor joint="joint4" name="torq_j4"/>
        <motor joint="joint5" name="torq_j5"/>
        <motor joint="joint6" name="torq_j6"/>
        <motor joint="joint7" name="torq_j7"/>
    </actuator>

    <equality>
            <!--<distance distance="0" solimp="{{grasp_solimp_low}} {{grasp_solimp_high}} {{grasp_solimp_width}}" solref="{{grasp_solref_timeconst}} {{grasp_solref_dampratio}}" geom1="G8_8" geom2="grip_geom" /> -->
            <!--<distance distance="0" solref="0.1 0.1" geom1="G8_8" geom2="mocap" /> -->
            <!--<distance distance="0" solref="-10000 -0.1" geom1="G8_8" geom2="mocap" /> -->

    </equality>

    

</mujoco>
