#VRML_SIM R2025a utf8
# Sheep - wheeled base with sheep character on top

EXTERNPROTO "https://raw.githubusercontent.com/cyberbotics/webots/R2025a/projects/appearances/protos/TireRubber.proto"

PROTO Sheep [
  field SFVec3f    translation     0 0 0
  field SFRotation rotation        0 1 0 0
  field SFString   name            "sheep"
  field SFString   controller      "sheep"
  field MFString   controllerArgs  []
  field SFString   customData      ""
  field SFBool     supervisor      TRUE
  field SFBool     synchronization TRUE
  field SFColor    woolColor       0.92 0.90 0.85
]
{
  Robot {
    translation IS translation
    rotation IS rotation
    name IS name
    controller IS controller
    controllerArgs IS controllerArgs
    customData IS customData
    supervisor IS supervisor
    synchronization IS synchronization
    children [
      # ========== CHASSIS / BASE ==========
      DEF SHEEP_CHASSIS Transform {
        translation 0 0 0.04
        children [
          Shape {
            appearance DEF SHEEP_CHASSIS_APP PBRAppearance {
              baseColor 0.25 0.25 0.25
              roughness 0.6
              metalness 0.3
            }
            geometry Box {
              size 0.24 0.14 0.05
            }
          }
        ]
      }

      # ========== FLUFFY WOOL BODY ==========
      DEF SHEEP_BODY Transform {
        translation 0 0 0.12
        children [
          Shape {
            appearance DEF WOOL PBRAppearance {
              baseColor IS woolColor
              roughness 0.95
              metalness 0.0
            }
            geometry Box {
              size 0.26 0.16 0.12
            }
          }
          # Fluffy wool bumps — 6 spheres clustered on top of the body box
          Transform {
            translation -0.04 0 0.07
            children [
              Shape {
                appearance USE WOOL
                geometry Sphere {
                  radius 0.055
                  subdivision 3
                }
              }
            ]
          }
          Transform {
            translation 0.04 0.035 0.07
            children [
              Shape {
                appearance USE WOOL
                geometry Sphere {
                  radius 0.05
                  subdivision 3
                }
              }
            ]
          }
          Transform {
            translation 0.04 -0.035 0.07
            children [
              Shape {
                appearance USE WOOL
                geometry Sphere {
                  radius 0.05
                  subdivision 3
                }
              }
            ]
          }
          Transform {
            translation -0.04 0.035 0.07
            children [
              Shape {
                appearance USE WOOL
                geometry Sphere {
                  radius 0.05
                  subdivision 3
                }
              }
            ]
          }
          Transform {
            translation -0.04 -0.035 0.07
            children [
              Shape {
                appearance USE WOOL
                geometry Sphere {
                  radius 0.05
                  subdivision 3
                }
              }
            ]
          }
          Transform {
            translation 0 0 0.07
            children [
              Shape {
                appearance USE WOOL
                geometry Sphere {
                  radius 0.06
                  subdivision 3
                }
              }
            ]
          }
        ]
      }

      # ========== HEAD ==========
      DEF SHEEP_HEAD Transform {
        translation 0.16 0 0.12
        children [
          Shape {
            appearance DEF SHEEP_DARK PBRAppearance {
              baseColor 0.25 0.22 0.18
              roughness 0.8
              metalness 0.0
            }
            geometry Box {
              size 0.08 0.10 0.08
            }
          }
          # Left eye (white sphere + dark pupil)
          Transform {
            translation 0.04 0.03 0.02
            children [
              Shape {
                appearance PBRAppearance {
                  baseColor 0.95 0.95 0.95
                  roughness 0.3
                }
                geometry Sphere {
                  radius 0.013
                  subdivision 2
                }
              }
              Transform {
                translation 0.008 0 0.003
                children [
                  Shape {
                    appearance PBRAppearance {
                      baseColor 0.1 0.1 0.1
                      roughness 0.2
                    }
                    geometry Sphere {
                      radius 0.007
                      subdivision 2
                    }
                  }
                ]
              }
            ]
          }
          # Right eye
          Transform {
            translation 0.04 -0.03 0.02
            children [
              Shape {
                appearance PBRAppearance {
                  baseColor 0.95 0.95 0.95
                  roughness 0.3
                }
                geometry Sphere {
                  radius 0.013
                  subdivision 2
                }
              }
              Transform {
                translation 0.008 0 0.003
                children [
                  Shape {
                    appearance PBRAppearance {
                      baseColor 0.1 0.1 0.1
                      roughness 0.2
                    }
                    geometry Sphere {
                      radius 0.007
                      subdivision 2
                    }
                  }
                ]
              }
            ]
          }
          # Left ear
          Transform {
            translation 0 0.055 0.03
            rotation 0 0 -1 0.3
            children [
              Shape {
                appearance USE SHEEP_DARK
                geometry Box {
                  size 0.05 0.018 0.03
                }
              }
            ]
          }
          # Right ear
          Transform {
            translation 0 -0.055 0.03
            rotation 0 0 1 0.3
            children [
              Shape {
                appearance USE SHEEP_DARK
                geometry Box {
                  size 0.05 0.018 0.03
                }
              }
            ]
          }
        ]
      }

      # ========== SHORT TAIL ==========
      Transform {
        translation -0.15 0 0.14
        children [
          Shape {
            appearance USE WOOL
            geometry Sphere {
              radius 0.035
              subdivision 2
            }
          }
        ]
      }

      # ========== RIGHT AXLE ARM ==========
      DEF SHEEP_RIGHT_AXLE Transform {
        translation 0 -0.085 0.031
        children [
          Shape {
            appearance PBRAppearance {
              baseColor 0.5 0.5 0.5
              roughness 0.3
              metalness 0.8
            }
            geometry Box {
              size 0.02 0.05 0.02
            }
          }
        ]
      }

      # ========== LEFT AXLE ARM ==========
      DEF SHEEP_LEFT_AXLE Transform {
        translation 0 0.085 0.031
        children [
          Shape {
            appearance PBRAppearance {
              baseColor 0.5 0.5 0.5
              roughness 0.3
              metalness 0.8
            }
            geometry Box {
              size 0.02 0.05 0.02
            }
          }
        ]
      }

      # ========== RIGHT WHEEL ==========
      DEF SHEEP_RIGHT_WHEEL HingeJoint {
        jointParameters HingeJointParameters {
          axis 0 1 0
          anchor 0 -0.10 0.031
        }
        device [
          RotationalMotor {
            name "right wheel motor"
            maxVelocity 25.0
            maxTorque 3.0
          }
          PositionSensor {
            name "right wheel sensor"
            resolution 0.00628
          }
        ]
        endPoint Solid {
          translation 0 -0.10 0.031
          rotation 0 -1 0 1.570796
          children [
            DEF SHEEP_WHEEL_VIS Pose {
              rotation 1 0 0 -1.5708
              children [
                Shape {
                  appearance PBRAppearance {
                    baseColor 0.15 0.15 0.15
                    roughness 0.4
                    metalness 0.5
                  }
                  geometry Cylinder {
                    height 0.014
                    radius 0.028
                    subdivision 24
                  }
                }
                Shape {
                  appearance TireRubber {
                    textureTransform TextureTransform {
                      scale 1.2 0.5
                    }
                    type "bike"
                  }
                  geometry Cylinder {
                    height 0.018
                    radius 0.031
                    subdivision 24
                  }
                }
                Shape {
                  appearance PBRAppearance {
                    baseColor 0.5 0.5 0.5
                    metalness 0.6
                  }
                  geometry Cylinder {
                    height 0.016
                    radius 0.012
                    subdivision 12
                  }
                }
              ]
            }
          ]
          name "right wheel"
          boundingObject Pose {
            rotation 1 0 0 -1.5708
            children [
              Cylinder {
                height 0.018
                radius 0.031
              }
            ]
          }
          physics Physics {
            density -1
            mass 0.04
            centerOfMass [
              0 0 0
            ]
          }
        }
      }

      # ========== LEFT WHEEL ==========
      DEF SHEEP_LEFT_WHEEL HingeJoint {
        jointParameters HingeJointParameters {
          axis 0 1 0
          anchor 0 0.10 0.031
        }
        device [
          RotationalMotor {
            name "left wheel motor"
            maxVelocity 25.0
            maxTorque 3.0
          }
          PositionSensor {
            name "left wheel sensor"
            resolution 0.00628
          }
        ]
        endPoint Solid {
          translation 0 0.10 0.031
          rotation 0.707105 0 0.707109 -3.14159
          children [
            USE SHEEP_WHEEL_VIS
          ]
          name "left wheel"
          boundingObject Pose {
            rotation 1 0 0 -1.5708
            children [
              Cylinder {
                height 0.018
                radius 0.031
              }
            ]
          }
          physics Physics {
            density -1
            mass 0.04
            centerOfMass [
              0 0 0
            ]
          }
        }
      }

      # ========== FRONT CASTER ==========
      BallJoint {
        jointParameters BallJointParameters {
          anchor 0.10 0 0.016
        }
        endPoint Solid {
          translation 0.10 0 0.016
          name "front caster"
          children [
            Shape {
              appearance PBRAppearance {
                baseColor 0.2 0.2 0.2
                roughness 0.3
              }
              geometry Sphere {
                radius 0.016
                subdivision 2
              }
            }
          ]
          boundingObject Sphere {
            radius 0.016
          }
          physics Physics {
            density -1
            mass 0.02
          }
        }
      }

      # ========== REAR CASTER ==========
      BallJoint {
        jointParameters BallJointParameters {
          anchor -0.10 0 0.016
        }
        endPoint Solid {
          translation -0.10 0 0.016
          name "rear caster"
          children [
            Shape {
              appearance PBRAppearance {
                baseColor 0.2 0.2 0.2
                roughness 0.3
              }
              geometry Sphere {
                radius 0.016
                subdivision 2
              }
            }
          ]
          boundingObject Sphere {
            radius 0.016
          }
          physics Physics {
            density -1
            mass 0.02
          }
        }
      }

      # ========== RECEIVER ==========
      Receiver {
        name "receiver"
        channel 1
      }

      # ========== EMITTER ==========
      Emitter {
        name "emitter"
        channel 1
        range 30.0
      }

      # ========== GPS ==========
      GPS {
        translation 0 0 0.15
        name "gps"
      }

      # ========== COMPASS ==========
      Compass {
        translation 0 0 0.10
        name "compass"
      }
    ]

    boundingObject Group {
      children [
        # Chassis box
        Transform {
          translation 0 0 0.04
          children [
            Box {
              size 0.24 0.14 0.05
            }
          ]
        }
        # Body box
        Transform {
          translation 0 0 0.12
          children [
            Box {
              size 0.26 0.16 0.12
            }
          ]
        }
      ]
    }

    physics Physics {
      density -1
      mass 5.0
      centerOfMass [
        0 0 0.02
      ]
    }
  }
}
