Small World Engine API Reference - v0.78.00
    Preparing search index...

    Class Barrel

    A barrel geometry (Fass / wooden barrel / storage cask).

    Mathematically, a barrel is a body of revolution with a bulging profile (often modelled as a parabolic arc or prolate spheroid truncated at both ends by planar circular caps).

    Mathematical formulas:

    • Kepler's Barrel Volume Formula (1615): $V \approx \pi \cdot h \cdot \frac{2 R^2 + r^2}{3}$
    • Space Diagonal: $d = \sqrt{h^2 + (2r)^2} = \sqrt{h^2 + 4r^2}$
    • Parabolic Profile Radius at height $y \in [-h/2, +h/2]$: $r(y) = R - (R - r) \cdot \left(\frac{2y}{h}\right)^2$

    Hierarchy (View Summary)

    Index
    _cachedBoundingVolume: BoundingVolume | undefined = undefined

    Cached bounding volume to prevent re-allocation

    _indices:
        | Uint16Array<ArrayBufferLike>
        | Uint32Array<ArrayBufferLike>
        | undefined = undefined

    The indices of the geometry for indexed rendering.

    _isLineGeometry: boolean = false

    Whether the geometry is purely line-based.

    _joints?: Float32Array<ArrayBufferLike> | Uint16Array<ArrayBufferLike> = undefined

    Optional skinning joints (4 IDs per vertex).

    _normals: Float32Array = ...

    The normals of the geometry (nx, ny, nz).

    _tangents: Float32Array = ...

    The tangents of the geometry (tx, ty, tz).

    _uvs: Float32Array = ...

    The UV coordinates of the geometry (u, v).

    _vertices: Float32Array = ...

    The vertices of the geometry (x, y, z).

    _weights?: Float32Array<ArrayBufferLike> = undefined

    Optional skinning weights (4 weights per vertex).

    _wireframeIndices:
        | Uint16Array<ArrayBufferLike>
        | Uint32Array<ArrayBufferLike>
        | undefined = undefined

    The indices for wireframe rendering.

    height: number

    The total height (h).

    heightSegments: number

    The number of height subdivisions.

    openEnded: boolean

    Whether the barrel ends are open (no caps).

    radialSegments: number

    The number of radial subdivisions.

    radiusBottom: number

    The bottom radius (r_bottom) at y = -height/2.

    radiusMiddle: number

    The middle radius (R) at equator y = 0.

    radiusTop: number

    The top radius (r_top) at y = +height/2.

    thetaLength: number

    The central angle in radians.

    thetaStart: number

    The start angle in radians.

    • get radiusEnds(): number

      Gets the average end radius $r = (r_{\text{top}} + r_{\text{bottom}}) / 2$.

      Returns number

    • Helper method to create an appropriately sized index array. Automatically chooses between 16-bit and 32-bit indices based on vertex count.

      Parameters

      • indexCount: number

        The number of indices needed.

      Returns Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>

      A Uint16Array or Uint32Array.

    • Calculates the space diagonal $d = \sqrt{h^2 + 4 r^2}$ between opposing rim edges.

      Returns number

    • Evaluates the radius $r(y)$ of the parabolic barrel profile at height $y \in [-h/2, +h/2]$.

      Parameters

      • y: number

        Vertical height coordinate.

      Returns number

    • Calculates the barrel volume using Kepler's Barrel Formula (Keplersche Fassregel). $V \approx \frac{\theta_{\text{len}}}{2\pi} \cdot \frac{\pi \cdot h}{3} \left(2 R^2 + \frac{r_{\text{top}}^2 + r_{\text{bottom}}^2}{2}\right)$.

      Returns number