#VRML_SIM R2023b utf8
# template language: javascript
# tags: nonDeterministic

EXTERNPROTO "./Marker.proto"

PROTO BoxToken [
  field SFVec3f translation 0 0 0
  field SFRotation rotation 0 1 0 0
  field SFVec3f size 0.13 0.13 0.13
  field SFVec2f {0.08 0.08, 0.15 0.15, 0.2 0.2} marker_size 0.08 0.08
  field SFColor colour 0.7 0.55 0.35
  field SFString marker "0"
  field SFString model ""
  field SFFloat mass 0.080
  field MFString texture_url []
  field SFFloat connectorStrength 35
  field SFFloat connectorShear 20
]
{
  Solid {
    translation IS translation
    rotation IS rotation
    children [
      Shape {
        appearance DEF TOKEN_APPEARANCE PBRAppearance {
          baseColor IS colour
          metalness 0
          roughness 1
        }
        geometry DEF TOKEN_GEOMETRY Box {
          size IS size
        }
      }
      Marker {
        translation 0 %<= fields.size.value.y / 2 + 0.001 >% 0
        rotation 1 0 0 -1.5708
        size IS marker_size
        name "front"
        model IS marker
        texture_url IS texture_url
      }
      Marker {
        translation 0 %<= -(fields.size.value.y / 2 + 0.001) >% 0
        rotation 1 0 0 1.5708
        size IS marker_size
        name "back"
        model IS marker
        texture_url IS texture_url
      }
      Marker {
        translation %<= fields.size.value.x / 2 + 0.001 >% 0 0
        rotation 0 1 0 1.5708
        size IS marker_size
        name "side-1"
        model IS marker
        texture_url IS texture_url
      }
      Marker {
        translation %<= -(fields.size.value.x / 2 + 0.001) >% 0 0
        rotation 0 1 0 -1.5708
        size IS marker_size
        name "side-2"
        model IS marker
        texture_url IS texture_url
      }
      Marker {
        translation 0 0 %<= fields.size.value.z / 2 + 0.001 >%
        rotation 0 0 1 0
        size IS marker_size
        name "top"
        model IS marker
        texture_url IS texture_url
      }
      Marker {
        translation 0 0 %<= -(fields.size.value.z / 2 + 0.001) >%
        rotation 0 1 0 3.1416
        size IS marker_size
        name "bottom"
        model IS marker
        texture_url IS texture_url
      }
      # Shape {
      #   appearance PBRAppearance {
      #     transparency 0.4
      #     baseColor 1 0 0
      #   }
      #   geometry Sphere {
      #     radius %<= fields.size.value.x / 2 * 1.4 >%
      #     subdivision 5
      #   }
      # }
      Connector {
        type "passive"
        distanceTolerance %<= fields.size.value.x / 2 * 1.4 >%
        axisTolerance 3.1415
        rotationTolerance 0
        numberOfRotations 0
        tensileStrength IS connectorStrength
        shearStrength IS connectorShear
        snap FALSE
        name "Front Connector"
      }
      Connector {
        rotation 0 0 1 3.1416
        type "passive"
        distanceTolerance %<= fields.size.value.x / 2 * 1.4 >%
        axisTolerance 3.1415
        rotationTolerance 0
        numberOfRotations 0
        tensileStrength IS connectorStrength
        shearStrength IS connectorShear
        snap FALSE
        name "Rear Connector"
      }
    ]
    name IS model
    model IS model
    boundingObject USE TOKEN_GEOMETRY
    physics Physics {
      density -1
      mass IS mass
    }
  }
}
