import { addTo, getClone, getGroup, getPrefab, getSpinning } from '.';
import { getOffset } from './getOffset';
/**
 * Creates a group of wheels that spin around a central point.
 * @example
 * ```
  // First a container for the car
  let car = getGroup({ p: [0, 2, 5], r: [0, 90, 0] });
  // Then add the car body
  addTo(car, getPrefab({ id: 'cube_01', s: [10, 0.4, 1], material: 't_plank_wall_01' }));
  // Then add the wheels

  const speedMultiplier = 0.75;
  const numWheels = 4;
  const wheelThickness = 10;
  const wheelScale = 4;
  const wheelDistance = 4.5;
  const wheelOffsetZ = 2.0;
  const wheelOffsetX = 6.0;

  let wheelProps: Partial<WheelsSpinningOptions> = {
    p: [wheelOffsetX, 0, wheelOffsetZ * -1],
    speedMultiplier,
    wheelScale: [wheelThickness, wheelScale, wheelScale],
    wheelMaterial: 't_metal_01',
    numWheels,
    wheelDistance,
  };

  addTo(car, getSpinningWheels(wheelProps));
  addTo(car, getSpinningWheels({ ...wheelProps, ...{ p: [wheelOffsetX, 0, wheelOffsetZ * 1] } }));
  const radius = 12;
  const duration = 16;
  car = getOrbiting(car, { radius, duration });
  addTo(world, car);
 * ```
 */
export const getSpinningWheels = (options) => {
    let { numWheels = 2, wheelDistance = 3, speedMultiplier = 1, seed = undefined, wheelObjects = undefined, } = options || {};
    const durationK = 1 / speedMultiplier;
    let wrapper = getGroup(options);
    if (!wheelObjects) {
        const prefabId = options?.wheelPrefabId ?? 'en_p_wooden_wheel_01';
        const wheelRotation = options?.wheelRotation ?? [0, 90, 0];
        const wheelScale = options?.wheelScale ?? [2, 2, 2];
        const wheelOffset = options?.wheelOffset ?? prefabId === 'en_p_wooden_wheel_01' ? [0, -0.48, 0] : [0, 0, 0];
        const wheelMaterial = options?.wheelMaterial;
        wheelObjects = getPrefab({
            id: prefabId,
            r: wheelRotation,
            s: wheelScale,
            material: wheelMaterial,
        });
        // Offset the wheel to it's center
        wheelObjects = getOffset(wheelObjects, { offset: wheelOffset });
    }
    wheelObjects = getSpinning(wheelObjects, { duration: (2 * durationK), axis: 'x', direction: -1 });
    for (let i = 0; i < numWheels; i++) {
        addTo(wrapper, getClone(wheelObjects, { p: [i * wheelDistance * -1, 0, 0] }));
    }
    return wrapper;
};
//# sourceMappingURL=getSpinningWheels.js.map