# SphereGeometry

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

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

A procedural sphere-shaped geometry.

Typically, you would:

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

Create a new SphereGeometry instance.

By default, the constructor creates a sphere centered on the object space origin with a radius
of 0.5 and 16 segments in both longitude and latitude. The sphere 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.latitudeBands` (`number`, optional): The number of divisions along the latitudinal axis of
      the sphere. Defaults to 16.
    - `opts.longitudeBands` (`number`, optional): The number of divisions along the longitudinal axis of
      the sphere. Defaults to 16.
    - `opts.radius` (`number`, optional): The radius of the sphere. Defaults to 0.5.

**Example**

```ts
const geometry = new SphereGeometry({
    radius: 1,
    latitudeBands: 32,
    longitudeBands: 32
});
```

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

- `blendIndices: ArrayLike<number> | undefined`
- `blendWeights: ArrayLike<number> | undefined`
- `colors: ArrayLike<number> | undefined`
- `tangents: ArrayLike<number> | undefined`

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

- `calculateNormals(): void`
- `calculateTangents(): void`
