# RoundedBoxGeometry

Class · extends [`Geometry`](https://api.playcanvas.com/engine/classes/Geometry.md) · category: Graphics

Source: https://github.com/playcanvas/engine/blob/64089771243fe28a9b9d2b4de538b99b07c75097/src/scene/geometry/rounded-box-geometry.js#L103

A procedural box-shaped geometry with rounded edges and corners.

Typically, you would:

1. Create a RoundedBoxGeometry instance.
2. Generate a [Mesh](https://api.playcanvas.com/engine/classes/Mesh.md) from the geometry.
3. Create a [MeshInstance](https://api.playcanvas.com/engine/classes/MeshInstance.md) referencing the mesh.
4. Create an [Entity](https://api.playcanvas.com/engine/classes/Entity.md) with a [RenderComponent](https://api.playcanvas.com/engine/classes/RenderComponent.md) and assign the [MeshInstance](https://api.playcanvas.com/engine/classes/MeshInstance.md) to it.
5. Add the entity to the [Scene](https://api.playcanvas.com/engine/classes/Scene.md).

```javascript
// Create a mesh instance
const geometry = new RoundedBoxGeometry();
const mesh = Mesh.fromGeometry(app.graphicsDevice, geometry);
const material = new StandardMaterial();
const meshInstance = new MeshInstance(mesh, material);

// Create an entity
const entity = new Entity();
entity.addComponent('render', {
    meshInstances: [meshInstance]
});

// Add the entity to the scene hierarchy
app.scene.root.addChild(entity);
```

## Constructors

### constructor

```ts
new RoundedBoxGeometry(opts?: object)
```

Create a new RoundedBoxGeometry instance.

By default, the constructor creates a box centered on the object space origin with a width,
length and height of 1 unit, edges and corners rounded with a radius of 0.1 and 8 segments
across each rounded edge. The faces are laid out as in [BoxGeometry](https://api.playcanvas.com/engine/classes/BoxGeometry.md), each with UVs
in the range of 0 to 1. Each face also takes half of each rounded edge next to it, so
neighboring faces meet half way around the rounded edge.

**Parameters**

- `opts` (`object`, optional, default `{}`): Options object.
    - `opts.calculateTangents` (`boolean`, optional): Generate tangent information. Defaults to false.
    - `opts.halfExtents` ([`Vec3`](https://api.playcanvas.com/engine/classes/Vec3.md), optional): The half dimensions of the box in each axis. Defaults to
      [0.5, 0.5, 0.5].
    - `opts.heightSegments` (`number`, optional): The number of divisions of the flat part of the box
      along the Y axis. Defaults to 1.
    - `opts.lengthSegments` (`number`, optional): The number of divisions of the flat part of the box
      along the Z axis. Defaults to 1.
    - `opts.radius` (`number`, optional): The radius of the rounded edges and corners. It is clamped to
      the smallest half extent, where the box becomes fully rounded in that axis. A radius of 0
      generates a box identical to [BoxGeometry](https://api.playcanvas.com/engine/classes/BoxGeometry.md). Defaults to 0.1.
    - `opts.radiusSegments` (`number`, optional): The number of segments across each rounded edge,
      which turns through 90 degrees. Must be even, as neighboring faces meet half way around the
      edge, so an odd value is rounded up. Defaults to 8.
    - `opts.widthSegments` (`number`, optional): The number of divisions of the flat part of the box
      along the X axis. Defaults to 1.
    - `opts.yOffset` (`number`, optional): Move the box vertically by given offset in local space. Pass
      0.5 to generate the box with pivot point at the bottom face. Defaults to 0.

**Example**

```ts
const geometry = new RoundedBoxGeometry({
    halfExtents: new Vec3(1, 0.5, 0.5),
    radius: 0.2,
    radiusSegments: 12
});
```

## Inherited from [Geometry](https://api.playcanvas.com/engine/classes/Geometry.md)

- `blendIndices: ArrayLike<number> | undefined`
- `blendWeights: ArrayLike<number> | undefined`
- `colors: ArrayLike<number> | undefined`
- `tangents: ArrayLike<number> | undefined`
- `calculateNormals(): void`
- `calculateTangents(): void`
