marselo-4/TotAuto / .claude/skills/r3f-geometry
r3f-geometry
VerifiedBuild React Three Fiber geometry, custom buffers, instanced meshes, points, and lines. Use for shape construction and geometry draw-call optimization, rather than material appearance.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 4.6 KB |
| references/instancing.md | markdown | 1.9 KB |
references/instancing.md
View on GitHub# Native instancing
Use for large sets where per-instance components or updates are too expensive. Mount below Canvas with lighting. This small example shows buffer initialization; profile at the real instance count.
```tsx
import { useLayoutEffect, useRef } from 'react'
import { InstancedMesh, Object3D } from 'three'
export default function NativeInstances() {
const mesh = useRef<InstancedMesh>(null)
useLayoutEffect(() => {
if (!mesh.current) return
const transform = new Object3D()
for (let i = 0; i < 100; i++) {
transform.position.set((i % 10) - 4.5, Math.floor(i / 10) - 4.5, 0)
transform.updateMatrix()
mesh.current.setMatrixAt(i, transform.matrix)
}
mesh.current.instanceMatrix.needsUpdate = true
mesh.current.computeBoundingBox()
mesh.current.computeBoundingSphere()
}, [])
return (
<instancedMesh ref={mesh} args={[undefined, undefined, 100]}>
<boxGeometry args={[0.5, 0.5, 0.5]} />
<meshStandardMaterial color="coral" />
</instancedMesh>
)
}
```
- `args` sets capacity; `mesh.count` controls how many initialized instances draw. Growing beyond allocated capacity requires recreation.
- Set `instanceMatrix.needsUpdate` after matrix writes and `instanceColor.needsUpdate` after color writes. Recompute bounds when transforms change their extent.
- Use a stable scratch Object3D/Matrix4 for repeated frame updates. Set DynamicDrawUsage before the first upload for frequently changing buffers.
- Picking returns `instanceId`; map it to application data. Negative instance scales are unsupported; avoid using them for mirroring.
- Instancing reduces rendering overhead, not CPU simulation or raycasting cost. Custom vertex shaders still need to apply `instanceMatrix`.
Source: [InstancedMesh](https://threejs.org/docs/#InstancedMesh), [Drei Instances tradeoffs](https://drei.docs.pmnd.rs/performances/instances).
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |