import $"{AGX_DATA_DIR}/models/bulldozer_d10t.agx" as AgxBulldozer

# Surface Contact Model between tracks and terrain
TrackTerrainContactModel is Physics.Interactions.SurfaceContact.Model:
    material_1: BulldozerTrackMaterial
    material_2: Terrain.MaterialLibrary.dirt_1
    tangential_restitution: 0.0
    normal_restitution: 0.0
    friction becomes Physics.Interactions.Dissipation.DryConstantNormalForceFriction with Vehicles.TrackSystem.SurfaceContact.Traits.TrackFriction:
        normal_force: 1000000
        coefficient: 1.0
        secondary_coefficient: 0.2

Bulldozer is AgxBulldozer:
    # Tracks
    left_track is Bulldozer.TrackSystem:
        sprocket:
            body: LeftSprocket
            radius: LeftSprocket.LeftSprocketCollisionGeometry_1.radius
            width: LeftSprocket.LeftSprocketCollisionGeometry_1.height
        roller_1:
            body: LeftRearRollerWheel
            radius: LeftRearRollerWheel.LeftRearRollerWheelCollisionGeometry_1.radius
            width: LeftRearRollerWheel.LeftRearRollerWheelCollisionGeometry_1.height
        roller_2:
            body: LeftFrontRollerWheel
            radius: LeftFrontRollerWheel.LeftFrontRollerWheelCollisionGeometry_1.radius
            width: LeftFrontRollerWheel.LeftFrontRollerWheelCollisionGeometry_1.height
        chassis_body: ChassisBody

    # Add bogie as a support geometry that supports the track around its route
    LeftBogie becomes Physics3D.Bodies.RigidBody with Vehicles.TrackSystem.Components.Traits.TrackSupportGeometry:
        track_system: left_track

    right_track is TrackSystem:
        sprocket:
            body: RightSprocket
            radius: RightSprocket.RightSprocketCollisionGeometry_1.radius
            width: RightSprocket.RightSprocketCollisionGeometry_1.height
        roller_1:
            body: RightRearRollerWheel
            radius: RightRearRollerWheel.RightRearRollerWheelCollisionGeometry_1.radius
            width: RightRearRollerWheel.RightRearRollerWheelCollisionGeometry_1.height
        roller_2:
            body: RightFrontRollerWheel
            radius: RightFrontRollerWheel.RightFrontRollerWheelCollisionGeometry_1.radius
            width: RightFrontRollerWheel.RightFrontRollerWheelCollisionGeometry_1.height
        chassis_body: ChassisBody

    # Add bogie as a support geometry that supports the track around its route
    RightBogie becomes Physics3D.Bodies.RigidBody with Vehicles.TrackSystem.Components.Traits.TrackSupportGeometry:
        track_system: right_track

    # Shovel
    shovel is Terrain.Shovel:
        body: Shovel
        top_edge: Math.Line.from_points(Shovel.ShovelUpperRight.position, Shovel.ShovelUpperLeft.position)
        cutting_edge: Math.Line.from_points(Shovel.ShovelLowerRight.position, Shovel.ShovelLowerLeft.position)

    # Rippers
    left_ripper is Terrain.Shovel:
        body: LeftRipper
        top_edge: Math.Line.from_points(LeftRipper.LeftRipperUpperRight.position, LeftRipper.LeftRipperUpperLeft.position)
        cutting_edge: Math.Line.from_points(LeftRipper.LeftRipperLowerRight.position, LeftRipper.LeftRipperLowerLeft.position)

    right_ripper is Terrain.Shovel:
        body: RightRipper
        top_edge: Math.Line.from_points(RightRipper.RightRipperUpperRight.position, RightRipper.RightRipperUpperLeft.position)
        cutting_edge: Math.Line.from_points(RightRipper.RightRipperLowerRight.position, RightRipper.RightRipperLowerLeft.position)

    # Drive Train
    drive_train is Bulldozer.DriveTrain:
        left_hinge_actuator.mate_3d: LeftSprocketHinge
        right_hinge_actuator.mate_3d: RightSprocketHinge


    # Disable Collisions
    # Add the tracks to a collision group
    tracks_collision_group is Simulation.CollisionGroup:
        systems: [left_track, right_track]

    # Add the push bars to another collision group
    chassis_collision_group is Simulation.CollisionGroup:
        bodies: [Push_Bar, Push_Bar2]

    # Disable collisions between the two groups
    tracks_chassis_collision_pair is Simulation.DisableCollisionPair:
        group1: tracks_collision_group
        group2: chassis_collision_group

Scene is Physics3D.System:
    bulldozer is Bulldozer:
        local_transform.position.z: 1.8

    terrain is Bulldozer.Terrain

    # Surface Contact Model
    track_terrain_contact_model is TrackTerrainContactModel
