# subset

Selective rendering geometry: show or hide individual features by id without recreating the geometry.

---

## `SubsetGeometry<Attributes>`

A `BufferGeometry` subclass that maintains a full position/attribute buffer while controlling which features are visible via a mutable index buffer. Features are identified by integer ids. Only features whose ids have been added will have non-zero index entries and therefore be rendered.

```typescript
new SubsetGeometry<Attributes>(attributes: Attributes, featureInfos: SubsetFeatureInfo[])
```

### Parameters

| Name | Type | Description |
|------|------|-------------|
| `attributes` | `Attributes` | Buffer attributes including at minimum `position: Float32BufferAttribute` |
| `featureInfos` | `SubsetFeatureInfo[]` | Ordered list of feature metadata (id, vertex count, local index list) |

### Methods

| Method | Description |
|--------|-------------|
| `addId(id)` | Show feature `id`; no-op if unknown or if state is `full` |
| `removeId(id)` | Hide feature `id`; no-op if unknown or if state is `empty` |
| `addAllIds()` | Show every feature; transitions state to `full` |
| `clearIds()` | Hide every feature; transitions state to `empty` |
| `hasId(id)` | Returns `true` if feature `id` is currently visible |
| `getIds()` | Returns an array of all currently visible ids |

### Example

```typescript
import { SubsetGeometry } from '@yaoc1996/js-tools/three-utils'
import { Float32BufferAttribute } from 'three'

const geo = new SubsetGeometry(
    { position: new Float32BufferAttribute(positions, 3) },
    [
        { id: 1, vertCount: 3, indices: [0, 1, 2] },
        { id: 2, vertCount: 3, indices: [0, 1, 2] },
    ]
)

geo.addId(1)        // render only feature 1
geo.addAllIds()     // render all features
geo.clearIds()      // render nothing
```

### Notes

- The index buffer is pre-allocated at construction time. `addId`/`removeId` update the relevant ranges in-place and set `needsUpdate`.
- `clone()` preserves the currently visible ids.

---

## Types

```typescript
type SubsetFeatureInfo = {
    id: number
    vertCount: number
    indices: number[]
}
```
