# TorusGeometry

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

Source: https://github.com/playcanvas/engine/blob/970d89f6d3bc6667f4e1f88153abd6e7e82ed52c/src/scene/geometry/torus-geometry.js#L34

A procedural torus-shaped geometry.

Typically, you would:

1. Create a TorusGeometry 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 TorusGeometry();
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 TorusGeometry(opts?: object)
```

Create a new TorusGeometry instance.

By default, the constructor creates a torus in the XZ-plane with a tube radius of 0.2, a ring
radius of 0.3, 30 segments and 20 sides. The torus is created with UVs in the range of 0 to 1.

**Parameters**

- `opts` (`object`, optional, default `{}`): Options object.
    - `opts.calculateTangents` (`boolean`, optional): Generate tangent information. Defaults to false.
    - `opts.ringRadius` (`number`, optional): The radius from the centre of the torus to the centre of the
      tube. Defaults to 0.3.
    - `opts.sectorAngle` (`number`, optional): The sector angle in degrees of the ring of the torus.
      Defaults to 2 * Math.PI.
    - `opts.segments` (`number`, optional): The number of radial divisions forming cross-sections of the
      torus ring. Defaults to 20.
    - `opts.sides` (`number`, optional): The number of divisions around the tubular body of the torus ring.
      Defaults to 30.
    - `opts.tubeRadius` (`number`, optional): The radius of the tube forming the body of the torus.
      Defaults to 0.2.

**Example**

```ts
const geometry = new TorusGeometry({
    tubeRadius: 1,
    ringRadius: 2,
    sectorAngle: 360,
    segments: 30,
    sides: 20
});
```

## 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`
