# CylinderGeometry

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

Source: https://github.com/playcanvas/engine/blob/f059dc005842f76e052cdf44d8370c8c7ec475ac/src/scene/geometry/cylinder-geometry.js#L33

A procedural cylinder-shaped geometry.

Typically, you would:

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

Create a new CylinderGeometry instance.

By default, the constructor creates a cylinder standing vertically centered on the XZ-plane
with a radius of 0.5, a height of 1.0, 1 height segment and 20 cap segments. The cylinder 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.capSegments` (`number`, optional): The number of divisions around the tubular body of the
      cylinder. Defaults to 20.
    - `opts.height` (`number`, optional): The length of the body of the cylinder. Defaults to 1.
    - `opts.heightSegments` (`number`, optional): The number of divisions along the length of the
      cylinder. Defaults to 5.
    - `opts.radius` (`number`, optional): The radius of the tube forming the body of the cylinder.
      Defaults to 0.5.

**Example**

```ts
const geometry = new CylinderGeometry({
    radius: 1,
    height: 2,
    heightSegments: 2,
    capSegments: 10
});
```

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

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