Function buildBoxGeometry

  • Creates box-shaped geometry.

    This function generates the geometry arrays required for a box mesh with configurable sizes along each axis. It provides vertex positions, UV coordinates, and indices to define the box's geometry. You can adjust the box's size along the X, Y, and Z axes and also specify its center position in 3D space.

    const boxGeometryResult = buildBoxGeometry({
    center: [0, 0, 0], // Center of the box
    xSize: 2, // Half-size along the X-axis
    ySize: 1, // Half-size along the Y-axis
    zSize: 1.5 // Half-size along the Z-axis
    });

    if (boxGeometryResult.ok) {
    const boxGeometry = boxGeometryResult.value;
    // Use boxGeometry here
    } else {
    console.error("Error creating box geometry:", boxGeometryResult.error);
    }

    Parameters

    • cfg: { center?: Vec3; xSize?: number; ySize?: number; zSize?: number } = ...

      Configurations for the box geometry.

      • Optionalcenter?: Vec3

        The center of the box in 3D space, default is the origin [0, 0, 0].

      • OptionalxSize?: number

        Half-size of the box along the X-axis. The default value is 1.0.

      • OptionalySize?: number

        Half-size of the box along the Y-axis. The default value is 1.0.

      • OptionalzSize?: number

        Half-size of the box along the Z-axis. The default value is 1.0.

    Returns SDKResult<GeometryArrays>

    The geometry arrays for a box, including positions, UVs, and indices, or an error message.