Function buildCylinderGeometry

  • Creates a cylinder-shaped geometry.

    This function generates the geometry arrays required for a cylinder mesh. The cylinder can be configured in terms of its top and bottom radii, height, radial and height segments, and whether it has caps on its ends. It returns the geometry arrays, including vertex positions, normals, texture coordinates (UVs), and indices for the cylinder's faces.

    const cylinderGeometry = buildCylinderGeometry({
    center: [0, 0, 0], // Center of the cylinder
    radiusTop: 1, // Radius of the top of the cylinder
    radiusBottom: 1, // Radius of the bottom of the cylinder
    height: 2, // Height of the cylinder
    radialSegments: 32, // Number of segments around the cylinder
    heightSegments: 1, // Number of segments vertically
    openEnded: false // Whether the cylinder has caps at the ends
    });

    Parameters

    • cfg: {
          center: FloatArrayParam;
          height: number;
          heightSegments: number;
          openEnded: boolean;
          radialSegments: number;
          radiusBottom: number;
          radiusTop: number;
      } = ...

      Configuration for the cylinder geometry.

      • center: FloatArrayParam

        The center position of the cylinder in 3D space, default is [0, 0, 0].

      • height: number

        The height of the cylinder. Default is 1.

      • heightSegments: number

        The number of vertical segments. Default is 1.

      • openEnded: boolean

        Whether or not the cylinder has solid caps at the top and bottom. Default is false.

      • radialSegments: number

        The number of radial (horizontal) segments. Default is 60.

      • radiusBottom: number

        The radius of the bottom of the cylinder. Default is 1.

      • radiusTop: number

        The radius of the top of the cylinder. Default is 1.

    Returns GeometryArrays

    The geometry arrays for the cylinder, including positions, normals, UVs, and indices for the faces.

    If any of the size parameters (radiusTop, radiusBottom, height, radialSegments, heightSegments) are negative, the function automatically inverts the values and logs a warning.