threejs-worldgen
    Preparing search index...

    Class Fleet

    Thousands of animated vehicles in a few draw calls: one InstancedMesh per model part (bodies, wheels, fans, rocket stages), driven every frame from the typed arrays of a FleetSim. Cars and bikes follow a road network or splines, trains pull their wagons along rails, boats bob, roll and leave wakes, planes bank through their turns, rockets launch and drop stages, carriers carry parked jets. Every vehicle gets wet, snowy, burnt and damaged through threejs-weathering's per-instance states.

    const fleet = new Fleet({ groups: [
    { type: 'car', count: 400, route: { kind: 'roads' } },
    { type: 'train', count: 1, params: { wagons: 8, cargo: 'freight' }, route: { kind: 'path', points: rail } },
    { type: 'airplane', count: 3, route: { kind: 'circle', center: [0, 600, 0], radius: 2500 } },
    ] }, { roads: city.graph })
    scene.add(fleet.object)
    renderer.setAnimationLoop(() => { fleet.update(); renderer.render(scene, camera) })
    fleet.set({ exposure: { snowfall: 1 } }) // parked cars collect snow, moving ones shed it
    Index
    material: MeshPhysicalNodeMaterial

    The single material every part shares.

    object: Group<Object3DEventMap> = ...

    Add this to your scene.

    settings: FleetSettings

    Resolved settings.

    The simulation (typed arrays of every vehicle's pose and state).

    uniforms: {
        crumple: UniformNode<"float", number>;
        lights: UniformNode<"float", number>;
    }

    Live material uniforms.

    Type Declaration

    • crumple: UniformNode<"float", number>

      Dent depth at full damage, metres.

    • lights: UniformNode<"float", number>

      Headlights and lit windows, 0…1.

    • get drawCalls(): number

      Draw calls the fleet costs (one per part mesh, plus fx and wakes).

      Returns number

    • Sets vehicle i on fire (heat 0…1); it burns, slows to a stop and chars until it burns out or rain douses it.

      Parameters

      • i: number
      • heat: number = 1

      Returns this

    • Advances and redraws the fleet. Call once per frame.

      Parameters

      • Optionaldt: number

        Seconds since the last call (measured if omitted).

      • env: FleetEnvironment = {}

        Weather, fire and ground states to react to.

      Returns void