# GSplatContainer

Class · category: Graphics

Source: https://github.com/playcanvas/engine/blob/970d89f6d3bc6667f4e1f88153abd6e7e82ed52c/src/scene/gsplat/gsplat-container.js#L66

A container for procedural Gaussian Splat data. This class allows you to create splat data
programmatically using either a built-in format or a custom format with your own texture
streams and read code.

A default format is provided via [GSplatFormat.createDefaultFormat](https://api.playcanvas.com/engine/classes/GSplatFormat.md#createdefaultformat) which uses float
textures for easy CPU population.

**Example**

```ts
// Example 1: Using the default format (easy CPU population)
const format = GSplatFormat.createDefaultFormat(device);
const container = new GSplatContainer(device, 100, format);

// Float format textures are straightforward to fill
const centerTex = container.getTexture('dataCenter');
const pixels = centerTex.lock();
// pixels is Float32Array, fill with [x, y, z, 0, x, y, z, 0, ...]
centerTex.unlock();

// Set bounding box
container.aabb = new BoundingBox();

// fill centers only if you need CPU sorting
container.centers.set([x0, y0, z0, x1, y1, z1, ...]);  // xyz per splat

// Add to scene
entity.addComponent('gsplat', { resource: container });
```

**Example**

```ts
// Example 2: Using a custom format
const format = new GSplatFormat(device, [
    { name: 'data', format: PIXELFORMAT_RGBA32F }
], {
    // Shader code to read splat attributes from the texture
    readGLSL: `
        vec4 d = loadData();
        splatCenter = d.xyz;
        splatColor = vec4(1.0);
        splatScale = vec3(d.w);
        splatRotation = vec4(0, 0, 0, 1);
    `,
    readWGSL: `
        let d = loadData();
        splatCenter = d.xyz;
        splatColor = vec4f(1.0);
        splatScale = vec3f(d.w);
        splatRotation = vec4f(0, 0, 0, 1);
    `
});

const container = new GSplatContainer(device, 100, format);
```

## Constructors

### constructor

```ts
new GSplatContainer(device: GraphicsDevice, maxSplats: number, format: GSplatFormat)
```

Creates a new GSplatContainer instance.

**Parameters**

- `device` ([`GraphicsDevice`](https://api.playcanvas.com/engine/classes/GraphicsDevice.md)): The graphics device.
- `maxSplats` (`number`): Maximum number of splats this container can hold.
- `format` ([`GSplatFormat`](https://api.playcanvas.com/engine/classes/GSplatFormat.md)): The format descriptor with streams and read code. Use
  [GSplatFormat.createDefaultFormat](https://api.playcanvas.com/engine/classes/GSplatFormat.md#createdefaultformat) for the built-in format, or create a custom
  [GSplatFormat](https://api.playcanvas.com/engine/classes/GSplatFormat.md).

## Accessors

### centers

```ts
get centers(): Float32Array<ArrayBufferLike>
set centers(value: Float32Array<ArrayBufferLike>)
```

CPU-side splat center positions (xyz per splat), or null when not built for this resource.

### maxSplats

```ts
get maxSplats(): number
```

Maximum number of splats this container can hold.

### numSplats

```ts
get numSplats(): number
```

Gets the number of splats to render.

## Methods

### update

```ts
update(numSplats?: number, centersUpdated?: boolean): void
```

Updates the container after modifying texture data and centers. Call this after filling
data to signal that the container contents have changed.

**Parameters**

- `numSplats` (`number`, optional): Number of splats to render. Defaults to current value.
  Must be between 0 and [maxSplats](https://api.playcanvas.com/engine/classes/GSplatContainer.md#maxsplats).
- `centersUpdated` (`boolean`, optional, default `true`): Whether the centers array was modified. Set to
  false when only numSplats changes but center positions remain the same, to avoid the cost
  of re-cloning centers in the sorter (can be significant for large containers).

## Inherited from GSplatResourceBase

- `protected _centers: Float32Array<ArrayBufferLike> | null`
- `aabb: BoundingBox`
- `get format(): GSplatFormat`
- `get hasCenters(): boolean`
- `get textureDimensions(): Vec2`
- `protected _actualDestroy(): void`
- `destroy(): void`
- `getTexture(name: string): Texture | null`
