three-agent-skills 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +225 -0
- package/README.md +129 -0
- package/package.json +33 -0
- package/skills/r3f-best-practices/SKILL.md +230 -0
- package/skills/r3f-best-practices/rules/_sections.md +90 -0
- package/skills/r3f-best-practices/rules/drei-use-gltf.md +159 -0
- package/skills/r3f-best-practices/rules/frame-delta-time.md +124 -0
- package/skills/r3f-best-practices/rules/loading-suspense.md +187 -0
- package/skills/r3f-best-practices/rules/perf-never-set-state-in-useframe.md +130 -0
- package/skills/r3f-best-practices/rules/perf-zustand-selectors.md +124 -0
- package/skills/r3f-best-practices.zip +0 -0
- package/skills/three-best-practices/SKILL.md +225 -0
- package/skills/three-best-practices/rules/_sections.md +111 -0
- package/skills/three-best-practices/rules/geometry-instanced-mesh.md +117 -0
- package/skills/three-best-practices/rules/memory-dispose-geometry.md +91 -0
- package/skills/three-best-practices/rules/render-delta-time.md +78 -0
- package/skills/three-best-practices/rules/setup-use-import-maps.md +61 -0
- package/skills/three-best-practices/rules/tsl-why-use.md +97 -0
- package/skills/three-best-practices.zip +0 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to AI coding agents (Claude Code, Cursor, Copilot, etc.) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Repository Overview
|
|
6
|
+
|
|
7
|
+
A collection of agent skills for Three.js development. Skills are packaged instructions and scripts that extend AI agent capabilities for 3D web development, shader programming, and WebGL optimization.
|
|
8
|
+
|
|
9
|
+
## Creating a New Skill
|
|
10
|
+
|
|
11
|
+
### Directory Structure
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
skills/
|
|
15
|
+
{skill-name}/ # kebab-case directory name
|
|
16
|
+
SKILL.md # Required: skill definition
|
|
17
|
+
scripts/ # Optional: executable scripts
|
|
18
|
+
{script-name}.sh # Bash scripts (preferred)
|
|
19
|
+
references/ # Optional: supporting documentation
|
|
20
|
+
*.md # Additional reference files
|
|
21
|
+
{skill-name}.zip # Required for distribution: packaged skill
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Naming Conventions
|
|
25
|
+
|
|
26
|
+
- **Skill directory**: `kebab-case` (e.g., `shader-optimization`, `scene-setup`)
|
|
27
|
+
- **SKILL.md**: Always uppercase, always this exact filename
|
|
28
|
+
- **Scripts**: `kebab-case.sh` (e.g., `analyze.sh`, `generate-boilerplate.sh`)
|
|
29
|
+
- **Zip file**: Must match directory name exactly: `{skill-name}.zip`
|
|
30
|
+
|
|
31
|
+
### SKILL.md Format
|
|
32
|
+
|
|
33
|
+
Every skill must have a `SKILL.md` file with this structure:
|
|
34
|
+
|
|
35
|
+
```markdown
|
|
36
|
+
---
|
|
37
|
+
name: {skill-name}
|
|
38
|
+
description: {One sentence describing when to use this skill. Include trigger phrases.}
|
|
39
|
+
argument-hint: <optional-args> # Optional: hint for arguments
|
|
40
|
+
license: MIT
|
|
41
|
+
metadata:
|
|
42
|
+
author: {author-name}
|
|
43
|
+
version: "{semver}"
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
# {Skill Title}
|
|
47
|
+
|
|
48
|
+
{Brief description of what the skill does.}
|
|
49
|
+
|
|
50
|
+
## When to Apply
|
|
51
|
+
|
|
52
|
+
Reference these guidelines when:
|
|
53
|
+
- {Scenario 1}
|
|
54
|
+
- {Scenario 2}
|
|
55
|
+
- {Scenario 3}
|
|
56
|
+
|
|
57
|
+
## How It Works
|
|
58
|
+
|
|
59
|
+
{Numbered list explaining the skill's workflow}
|
|
60
|
+
|
|
61
|
+
1. Step one
|
|
62
|
+
2. Step two
|
|
63
|
+
3. Step three
|
|
64
|
+
|
|
65
|
+
## Usage
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
bash /mnt/skills/user/{skill-name}/scripts/{script}.sh [args]
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**Arguments:**
|
|
72
|
+
- `arg1` - Description (defaults to X)
|
|
73
|
+
|
|
74
|
+
**Examples:**
|
|
75
|
+
{Show 2-3 common usage patterns}
|
|
76
|
+
|
|
77
|
+
## Quick Reference
|
|
78
|
+
|
|
79
|
+
{Concise summary of rules/patterns organized by category}
|
|
80
|
+
|
|
81
|
+
## Output
|
|
82
|
+
|
|
83
|
+
{Show example output users will see}
|
|
84
|
+
|
|
85
|
+
## Present Results to User
|
|
86
|
+
|
|
87
|
+
{Template for how the agent should format results when presenting to users}
|
|
88
|
+
|
|
89
|
+
## Troubleshooting
|
|
90
|
+
|
|
91
|
+
{Common issues and solutions}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Best Practices for Context Efficiency
|
|
95
|
+
|
|
96
|
+
Skills are loaded on-demand. Only the skill name and description are loaded at startup. The full `SKILL.md` loads into context only when the agent decides the skill is relevant.
|
|
97
|
+
|
|
98
|
+
To minimize context usage:
|
|
99
|
+
|
|
100
|
+
- **Keep SKILL.md under 500 lines** - put detailed reference material in separate files
|
|
101
|
+
- **Write specific descriptions** - helps the agent know exactly when to activate the skill
|
|
102
|
+
- **Use progressive disclosure** - reference supporting files that get read only when needed
|
|
103
|
+
- **Prefer scripts over inline code** - script execution doesn't consume context (only output does)
|
|
104
|
+
- **File references work one level deep** - link directly from SKILL.md to supporting files
|
|
105
|
+
|
|
106
|
+
### Script Requirements
|
|
107
|
+
|
|
108
|
+
If your skill includes scripts:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
#!/bin/bash
|
|
112
|
+
set -e # Fail-fast behavior
|
|
113
|
+
|
|
114
|
+
# Write status messages to stderr
|
|
115
|
+
echo "Processing..." >&2
|
|
116
|
+
|
|
117
|
+
# Write machine-readable output (JSON) to stdout
|
|
118
|
+
echo '{"result": "success"}'
|
|
119
|
+
|
|
120
|
+
# Include cleanup trap for temp files
|
|
121
|
+
cleanup() {
|
|
122
|
+
rm -rf "$TEMP_DIR"
|
|
123
|
+
}
|
|
124
|
+
trap cleanup EXIT
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Key requirements:
|
|
128
|
+
- Use `#!/bin/bash` shebang
|
|
129
|
+
- Use `set -e` for fail-fast behavior
|
|
130
|
+
- Write status messages to stderr: `echo "Message" >&2`
|
|
131
|
+
- Write machine-readable output (JSON) to stdout
|
|
132
|
+
- Include a cleanup trap for temp files
|
|
133
|
+
- Reference the script path as `/mnt/skills/user/{skill-name}/scripts/{script}.sh`
|
|
134
|
+
|
|
135
|
+
### Creating the Zip Package
|
|
136
|
+
|
|
137
|
+
After creating or updating a skill:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
cd skills
|
|
141
|
+
zip -r {skill-name}.zip {skill-name}/
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### End-User Installation
|
|
145
|
+
|
|
146
|
+
**Claude Code:**
|
|
147
|
+
```bash
|
|
148
|
+
cp -r skills/{skill-name} ~/.claude/skills/
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**claude.ai:**
|
|
152
|
+
Add the skill to project knowledge or paste SKILL.md contents into the conversation.
|
|
153
|
+
|
|
154
|
+
If the skill requires network access, instruct users to add required domains at `claude.ai/settings/capabilities`.
|
|
155
|
+
|
|
156
|
+
## Skill Types
|
|
157
|
+
|
|
158
|
+
### 1. Guidelines Skills (No Scripts)
|
|
159
|
+
|
|
160
|
+
Pure documentation skills that provide rules and best practices. Example: `react-best-practices`.
|
|
161
|
+
|
|
162
|
+
Structure:
|
|
163
|
+
```
|
|
164
|
+
skill-name/
|
|
165
|
+
SKILL.md # Rules and guidelines
|
|
166
|
+
rules/ # Optional: individual rule files
|
|
167
|
+
rule-1.md
|
|
168
|
+
rule-2.md
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### 2. Tool Skills (With Scripts)
|
|
172
|
+
|
|
173
|
+
Skills that execute actions via bash scripts. Example: `vercel-deploy`.
|
|
174
|
+
|
|
175
|
+
Structure:
|
|
176
|
+
```
|
|
177
|
+
skill-name/
|
|
178
|
+
SKILL.md # Usage instructions
|
|
179
|
+
scripts/
|
|
180
|
+
main-action.sh # Primary script
|
|
181
|
+
helper.sh # Supporting scripts
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### 3. Hybrid Skills
|
|
185
|
+
|
|
186
|
+
Combine guidelines with automation tools.
|
|
187
|
+
|
|
188
|
+
Structure:
|
|
189
|
+
```
|
|
190
|
+
skill-name/
|
|
191
|
+
SKILL.md # Instructions + quick reference
|
|
192
|
+
AGENTS.md # Full compiled guidelines
|
|
193
|
+
scripts/
|
|
194
|
+
analyze.sh # Automation scripts
|
|
195
|
+
rules/
|
|
196
|
+
detailed-rules/
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Frontmatter Reference
|
|
200
|
+
|
|
201
|
+
| Field | Required | Description |
|
|
202
|
+
|-------|----------|-------------|
|
|
203
|
+
| `name` | Yes | Unique identifier (kebab-case) |
|
|
204
|
+
| `description` | Yes | One sentence with trigger phrases |
|
|
205
|
+
| `argument-hint` | No | Hint for arguments (e.g., `<file-or-pattern>`) |
|
|
206
|
+
| `license` | No | License type (default: MIT) |
|
|
207
|
+
| `metadata.author` | No | Author name |
|
|
208
|
+
| `metadata.version` | No | Semantic version |
|
|
209
|
+
|
|
210
|
+
## Testing Your Skill
|
|
211
|
+
|
|
212
|
+
1. **Local Testing**: Copy to `~/.claude/skills/` and test with Claude Code
|
|
213
|
+
2. **Description Testing**: Verify the agent activates on expected trigger phrases
|
|
214
|
+
3. **Script Testing**: Run scripts manually to verify behavior
|
|
215
|
+
4. **Context Testing**: Ensure SKILL.md stays under 500 lines
|
|
216
|
+
|
|
217
|
+
## Example Skills for Three.js
|
|
218
|
+
|
|
219
|
+
Future skills in this repository:
|
|
220
|
+
|
|
221
|
+
- `three-scene-setup` - Best practices for Three.js scene initialization
|
|
222
|
+
- `shader-optimization` - GLSL shader performance patterns
|
|
223
|
+
- `three-performance` - Rendering optimization guidelines
|
|
224
|
+
- `three-postprocessing` - Post-processing effects setup
|
|
225
|
+
- `three-physics` - Physics engine integration patterns
|
package/README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Three Agent Skills
|
|
2
|
+
|
|
3
|
+
AI coding agent skills for Three.js and React Three Fiber development.
|
|
4
|
+
|
|
5
|
+
Skills follow the [Agent Skills](https://agentskills.io/) specification.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx add-skill three-agent-skills
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or from GitHub directly:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx add-skill emalorenzo/three-agent-skills
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### List available skills
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx add-skill three-agent-skills --list
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Install specific skill
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npx add-skill three-agent-skills --skill three-best-practices
|
|
29
|
+
npx add-skill three-agent-skills --skill r3f-best-practices
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Available Skills
|
|
33
|
+
|
|
34
|
+
### three-best-practices
|
|
35
|
+
|
|
36
|
+
Pure Three.js optimization guidelines. 70+ rules across 12 categories.
|
|
37
|
+
|
|
38
|
+
**Use when:**
|
|
39
|
+
- Writing Three.js code
|
|
40
|
+
- Optimizing WebGL performance
|
|
41
|
+
- Managing memory and disposal
|
|
42
|
+
- Writing shaders (GLSL or TSL)
|
|
43
|
+
|
|
44
|
+
**Categories:**
|
|
45
|
+
- Modern Setup & Imports (Import Maps, renderers)
|
|
46
|
+
- Memory Management & Dispose (CRITICAL)
|
|
47
|
+
- Render Loop Optimization (CRITICAL)
|
|
48
|
+
- Geometry & Buffer Management
|
|
49
|
+
- Material & Texture Optimization
|
|
50
|
+
- Lighting & Shadows
|
|
51
|
+
- Scene Graph Organization
|
|
52
|
+
- Shader Best Practices (GLSL)
|
|
53
|
+
- TSL - Three.js Shading Language
|
|
54
|
+
- Loading & Assets
|
|
55
|
+
- Camera & Controls
|
|
56
|
+
- Debug & DevTools
|
|
57
|
+
|
|
58
|
+
### r3f-best-practices
|
|
59
|
+
|
|
60
|
+
React Three Fiber and Poimandres ecosystem best practices. 60+ rules across 11 categories.
|
|
61
|
+
|
|
62
|
+
**Use when:**
|
|
63
|
+
- Writing R3F components
|
|
64
|
+
- Optimizing R3F performance (re-renders)
|
|
65
|
+
- Using Drei helpers
|
|
66
|
+
- Managing state with Zustand
|
|
67
|
+
- Implementing physics or post-processing
|
|
68
|
+
|
|
69
|
+
**Ecosystem coverage:**
|
|
70
|
+
- @react-three/fiber
|
|
71
|
+
- @react-three/drei
|
|
72
|
+
- @react-three/postprocessing
|
|
73
|
+
- @react-three/rapier
|
|
74
|
+
- zustand
|
|
75
|
+
- leva
|
|
76
|
+
|
|
77
|
+
**Categories:**
|
|
78
|
+
- Performance & Re-renders (CRITICAL)
|
|
79
|
+
- useFrame & Animation (CRITICAL)
|
|
80
|
+
- Component Patterns
|
|
81
|
+
- Canvas & Setup
|
|
82
|
+
- Drei Helpers
|
|
83
|
+
- Loading & Suspense
|
|
84
|
+
- State Management
|
|
85
|
+
- Events & Interaction
|
|
86
|
+
- Post-processing
|
|
87
|
+
- Physics (Rapier)
|
|
88
|
+
- Leva (Debug GUI)
|
|
89
|
+
|
|
90
|
+
## Usage Examples
|
|
91
|
+
|
|
92
|
+
Once installed, the agent uses skills automatically based on context:
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
Help me set up a Three.js scene with proper memory management
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
Review my R3F component for performance issues
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
How do I load GLTF models with Drei?
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
Optimize my shader for mobile devices
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Supported Agents
|
|
111
|
+
|
|
112
|
+
Works with any agent that supports the [Agent Skills](https://agentskills.io/) spec:
|
|
113
|
+
|
|
114
|
+
- Claude Code
|
|
115
|
+
- Cursor
|
|
116
|
+
- Codex
|
|
117
|
+
- OpenCode
|
|
118
|
+
- VS Code Copilot
|
|
119
|
+
- And more...
|
|
120
|
+
|
|
121
|
+
## Documentation
|
|
122
|
+
|
|
123
|
+
- Full Three.js guide: [THREE_BEST_PRACTICES.md](./THREE_BEST_PRACTICES.md)
|
|
124
|
+
- Full R3F guide: [R3F_BEST_PRACTICES.md](./R3F_BEST_PRACTICES.md)
|
|
125
|
+
- Creating skills: [AGENTS.md](./AGENTS.md)
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "three-agent-skills",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "AI coding agent skills for Three.js and React Three Fiber best practices",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"threejs",
|
|
7
|
+
"three.js",
|
|
8
|
+
"react-three-fiber",
|
|
9
|
+
"r3f",
|
|
10
|
+
"webgl",
|
|
11
|
+
"3d",
|
|
12
|
+
"agent-skills",
|
|
13
|
+
"ai",
|
|
14
|
+
"llm",
|
|
15
|
+
"claude",
|
|
16
|
+
"cursor"
|
|
17
|
+
],
|
|
18
|
+
"author": "emalorenzo",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/emalorenzo/three-agent-skills.git"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/emalorenzo/three-agent-skills#readme",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/emalorenzo/three-agent-skills/issues"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"skills",
|
|
30
|
+
"AGENTS.md",
|
|
31
|
+
"README.md"
|
|
32
|
+
]
|
|
33
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: r3f-best-practices
|
|
3
|
+
description: React Three Fiber (R3F) and Poimandres ecosystem best practices. Use when writing, reviewing, or optimizing R3F code. Triggers on tasks involving @react-three/fiber, @react-three/drei, zustand, @react-three/postprocessing, @react-three/rapier, or leva.
|
|
4
|
+
license: MIT
|
|
5
|
+
metadata:
|
|
6
|
+
author: three-agent-skills
|
|
7
|
+
version: "1.0.0"
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# React Three Fiber Best Practices
|
|
11
|
+
|
|
12
|
+
Comprehensive guide for React Three Fiber and the Poimandres ecosystem. Contains 60+ rules across 11 categories, prioritized by impact.
|
|
13
|
+
|
|
14
|
+
## When to Apply
|
|
15
|
+
|
|
16
|
+
Reference these guidelines when:
|
|
17
|
+
- Writing new R3F components
|
|
18
|
+
- Optimizing R3F performance (re-renders are the #1 issue)
|
|
19
|
+
- Using Drei helpers correctly
|
|
20
|
+
- Managing state with Zustand
|
|
21
|
+
- Implementing post-processing or physics
|
|
22
|
+
|
|
23
|
+
## Ecosystem Coverage
|
|
24
|
+
|
|
25
|
+
- **@react-three/fiber** - React renderer for Three.js
|
|
26
|
+
- **@react-three/drei** - Useful helpers and abstractions
|
|
27
|
+
- **@react-three/postprocessing** - Post-processing effects
|
|
28
|
+
- **@react-three/rapier** - Physics engine
|
|
29
|
+
- **zustand** - State management
|
|
30
|
+
- **leva** - Debug GUI
|
|
31
|
+
|
|
32
|
+
## Rule Categories by Priority
|
|
33
|
+
|
|
34
|
+
| Priority | Category | Impact | Prefix |
|
|
35
|
+
|----------|----------|--------|--------|
|
|
36
|
+
| 1 | Performance & Re-renders | CRITICAL | `perf-` |
|
|
37
|
+
| 2 | useFrame & Animation | CRITICAL | `frame-` |
|
|
38
|
+
| 3 | Component Patterns | HIGH | `component-` |
|
|
39
|
+
| 4 | Canvas & Setup | HIGH | `canvas-` |
|
|
40
|
+
| 5 | Drei Helpers | MEDIUM-HIGH | `drei-` |
|
|
41
|
+
| 6 | Loading & Suspense | MEDIUM-HIGH | `loading-` |
|
|
42
|
+
| 7 | State Management | MEDIUM | `state-` |
|
|
43
|
+
| 8 | Events & Interaction | MEDIUM | `events-` |
|
|
44
|
+
| 9 | Post-processing | MEDIUM | `postpro-` |
|
|
45
|
+
| 10 | Physics (Rapier) | LOW-MEDIUM | `physics-` |
|
|
46
|
+
| 11 | Leva (Debug GUI) | LOW | `leva-` |
|
|
47
|
+
|
|
48
|
+
## Quick Reference
|
|
49
|
+
|
|
50
|
+
### 1. Performance & Re-renders (CRITICAL)
|
|
51
|
+
|
|
52
|
+
- `perf-never-set-state-in-useframe` - NEVER call setState in useFrame
|
|
53
|
+
- `perf-isolate-state` - Isolate components that need React state
|
|
54
|
+
- `perf-zustand-selectors` - Use Zustand selectors, not entire store
|
|
55
|
+
- `perf-transient-subscriptions` - Use transient subscriptions for continuous values
|
|
56
|
+
- `perf-memo-components` - Memoize expensive components
|
|
57
|
+
- `perf-keys-for-lists` - Use stable keys for dynamic lists
|
|
58
|
+
- `perf-avoid-inline-objects` - Avoid creating objects/arrays in JSX
|
|
59
|
+
- `perf-dispose-auto` - Understand R3F auto-dispose behavior
|
|
60
|
+
|
|
61
|
+
### 2. useFrame & Animation (CRITICAL)
|
|
62
|
+
|
|
63
|
+
- `frame-priority` - Use priority for execution order
|
|
64
|
+
- `frame-delta-time` - Always use delta for animations
|
|
65
|
+
- `frame-conditional-subscription` - Disable useFrame when not needed
|
|
66
|
+
- `frame-destructure-state` - Destructure only what you need
|
|
67
|
+
- `frame-render-on-demand` - Use invalidate() for on-demand rendering
|
|
68
|
+
- `frame-avoid-heavy-computation` - Move heavy work outside useFrame
|
|
69
|
+
|
|
70
|
+
### 3. Component Patterns (HIGH)
|
|
71
|
+
|
|
72
|
+
- `component-jsx-elements` - Use JSX for Three.js objects
|
|
73
|
+
- `component-attach-prop` - Use attach for non-standard properties
|
|
74
|
+
- `component-primitive` - Use primitive for existing objects
|
|
75
|
+
- `component-extend` - Use extend() for custom classes
|
|
76
|
+
- `component-forwardref` - Use forwardRef for reusable components
|
|
77
|
+
- `component-dispose-null` - Set dispose={null} on shared resources
|
|
78
|
+
|
|
79
|
+
### 4. Canvas & Setup (HIGH)
|
|
80
|
+
|
|
81
|
+
- `canvas-size-container` - Canvas fills parent container
|
|
82
|
+
- `canvas-camera-default` - Configure camera via prop
|
|
83
|
+
- `canvas-gl-config` - Configure WebGL context
|
|
84
|
+
- `canvas-shadows` - Enable shadows at Canvas level
|
|
85
|
+
- `canvas-frameloop` - Choose appropriate frameloop mode
|
|
86
|
+
- `canvas-events` - Configure event handling
|
|
87
|
+
- `canvas-linear-flat` - Use linear/flat for correct colors
|
|
88
|
+
|
|
89
|
+
### 5. Drei Helpers (MEDIUM-HIGH)
|
|
90
|
+
|
|
91
|
+
- `drei-use-gltf` - useGLTF with preloading
|
|
92
|
+
- `drei-use-texture` - useTexture for texture loading
|
|
93
|
+
- `drei-environment` - Environment for realistic lighting
|
|
94
|
+
- `drei-orbit-controls` - OrbitControls from Drei
|
|
95
|
+
- `drei-html` - Html for DOM overlays
|
|
96
|
+
- `drei-text` - Text for 3D text
|
|
97
|
+
- `drei-instances` - Instances for optimized instancing
|
|
98
|
+
- `drei-use-helper` - useHelper for debug visualization
|
|
99
|
+
- `drei-bounds` - Bounds to fit camera
|
|
100
|
+
- `drei-center` - Center to center objects
|
|
101
|
+
- `drei-float` - Float for floating animation
|
|
102
|
+
|
|
103
|
+
### 6. Loading & Suspense (MEDIUM-HIGH)
|
|
104
|
+
|
|
105
|
+
- `loading-suspense` - Wrap async components in Suspense
|
|
106
|
+
- `loading-preload` - Preload assets with useGLTF.preload
|
|
107
|
+
- `loading-use-progress` - useProgress for loading UI
|
|
108
|
+
- `loading-lazy-components` - Lazy load heavy components
|
|
109
|
+
- `loading-error-boundary` - Handle loading errors
|
|
110
|
+
|
|
111
|
+
### 7. State Management (MEDIUM)
|
|
112
|
+
|
|
113
|
+
- `state-zustand-store` - Create focused Zustand stores
|
|
114
|
+
- `state-avoid-objects-in-store` - Be careful with Three.js objects
|
|
115
|
+
- `state-subscribeWithSelector` - Fine-grained subscriptions
|
|
116
|
+
- `state-persist` - Persist state when needed
|
|
117
|
+
- `state-separate-concerns` - Separate stores by concern
|
|
118
|
+
|
|
119
|
+
### 8. Events & Interaction (MEDIUM)
|
|
120
|
+
|
|
121
|
+
- `events-pointer-events` - Use pointer events on meshes
|
|
122
|
+
- `events-stop-propagation` - Prevent event bubbling
|
|
123
|
+
- `events-cursor-pointer` - Change cursor on hover
|
|
124
|
+
- `events-raycast-filter` - Filter raycasting
|
|
125
|
+
- `events-event-data` - Understand event data structure
|
|
126
|
+
|
|
127
|
+
### 9. Post-processing (MEDIUM)
|
|
128
|
+
|
|
129
|
+
- `postpro-effect-composer` - Use EffectComposer
|
|
130
|
+
- `postpro-common-effects` - Common effects reference
|
|
131
|
+
- `postpro-selective-bloom` - SelectiveBloom for optimized glow
|
|
132
|
+
- `postpro-custom-shader` - Create custom effects
|
|
133
|
+
- `postpro-performance` - Optimize post-processing
|
|
134
|
+
|
|
135
|
+
### 10. Physics Rapier (LOW-MEDIUM)
|
|
136
|
+
|
|
137
|
+
- `physics-setup` - Basic Rapier setup
|
|
138
|
+
- `physics-body-types` - dynamic, fixed, kinematic
|
|
139
|
+
- `physics-colliders` - Choose appropriate colliders
|
|
140
|
+
- `physics-events` - Handle collision events
|
|
141
|
+
- `physics-api-ref` - Use ref for physics API
|
|
142
|
+
- `physics-performance` - Optimize physics
|
|
143
|
+
|
|
144
|
+
### 11. Leva (LOW)
|
|
145
|
+
|
|
146
|
+
- `leva-basic` - Basic Leva usage
|
|
147
|
+
- `leva-folders` - Organize with folders
|
|
148
|
+
- `leva-conditional` - Hide in production
|
|
149
|
+
|
|
150
|
+
## How to Use
|
|
151
|
+
|
|
152
|
+
Read individual rule files for detailed explanations and code examples:
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
rules/perf-never-set-state-in-useframe.md
|
|
156
|
+
rules/drei-use-gltf.md
|
|
157
|
+
rules/state-zustand-selectors.md
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Full Compiled Document
|
|
161
|
+
|
|
162
|
+
For the complete guide with all rules expanded: `../R3F_BEST_PRACTICES.md`
|
|
163
|
+
|
|
164
|
+
## Critical Patterns
|
|
165
|
+
|
|
166
|
+
### NEVER setState in useFrame
|
|
167
|
+
|
|
168
|
+
```jsx
|
|
169
|
+
// BAD - 60 re-renders per second!
|
|
170
|
+
function BadComponent() {
|
|
171
|
+
const [position, setPosition] = useState(0);
|
|
172
|
+
useFrame(() => {
|
|
173
|
+
setPosition(p => p + 0.01); // NEVER DO THIS
|
|
174
|
+
});
|
|
175
|
+
return <mesh position-x={position} />;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// GOOD - Mutate refs directly
|
|
179
|
+
function GoodComponent() {
|
|
180
|
+
const meshRef = useRef();
|
|
181
|
+
useFrame(() => {
|
|
182
|
+
meshRef.current.position.x += 0.01;
|
|
183
|
+
});
|
|
184
|
+
return <mesh ref={meshRef} />;
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Zustand Selectors
|
|
189
|
+
|
|
190
|
+
```jsx
|
|
191
|
+
// BAD - Re-renders on ANY store change
|
|
192
|
+
const store = useGameStore();
|
|
193
|
+
|
|
194
|
+
// GOOD - Only re-renders when playerX changes
|
|
195
|
+
const playerX = useGameStore(state => state.playerX);
|
|
196
|
+
|
|
197
|
+
// BETTER - No re-renders, direct mutation
|
|
198
|
+
useFrame(() => {
|
|
199
|
+
const { value } = useStore.getState();
|
|
200
|
+
ref.current.position.x = value;
|
|
201
|
+
});
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Drei useGLTF
|
|
205
|
+
|
|
206
|
+
```jsx
|
|
207
|
+
import { useGLTF } from '@react-three/drei';
|
|
208
|
+
|
|
209
|
+
function Model() {
|
|
210
|
+
const { scene } = useGLTF('/model.glb');
|
|
211
|
+
return <primitive object={scene} />;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Preload for instant loading
|
|
215
|
+
useGLTF.preload('/model.glb');
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Suspense Loading
|
|
219
|
+
|
|
220
|
+
```jsx
|
|
221
|
+
function App() {
|
|
222
|
+
return (
|
|
223
|
+
<Canvas>
|
|
224
|
+
<Suspense fallback={<Loader />}>
|
|
225
|
+
<Model />
|
|
226
|
+
</Suspense>
|
|
227
|
+
</Canvas>
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
```
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Rule Sections
|
|
2
|
+
|
|
3
|
+
## Priority 1: Performance & Re-renders (CRITICAL)
|
|
4
|
+
- perf-never-set-state-in-useframe
|
|
5
|
+
- perf-isolate-state
|
|
6
|
+
- perf-zustand-selectors
|
|
7
|
+
- perf-transient-subscriptions
|
|
8
|
+
- perf-memo-components
|
|
9
|
+
- perf-keys-for-lists
|
|
10
|
+
- perf-avoid-inline-objects
|
|
11
|
+
- perf-dispose-auto
|
|
12
|
+
|
|
13
|
+
## Priority 2: useFrame & Animation (CRITICAL)
|
|
14
|
+
- frame-priority
|
|
15
|
+
- frame-delta-time
|
|
16
|
+
- frame-conditional-subscription
|
|
17
|
+
- frame-destructure-state
|
|
18
|
+
- frame-render-on-demand
|
|
19
|
+
- frame-avoid-heavy-computation
|
|
20
|
+
|
|
21
|
+
## Priority 3: Component Patterns (HIGH)
|
|
22
|
+
- component-jsx-elements
|
|
23
|
+
- component-attach-prop
|
|
24
|
+
- component-primitive
|
|
25
|
+
- component-extend
|
|
26
|
+
- component-forwardref
|
|
27
|
+
- component-dispose-null
|
|
28
|
+
|
|
29
|
+
## Priority 4: Canvas & Setup (HIGH)
|
|
30
|
+
- canvas-size-container
|
|
31
|
+
- canvas-camera-default
|
|
32
|
+
- canvas-gl-config
|
|
33
|
+
- canvas-shadows
|
|
34
|
+
- canvas-frameloop
|
|
35
|
+
- canvas-events
|
|
36
|
+
- canvas-linear-flat
|
|
37
|
+
|
|
38
|
+
## Priority 5: Drei Helpers (MEDIUM-HIGH)
|
|
39
|
+
- drei-use-gltf
|
|
40
|
+
- drei-use-texture
|
|
41
|
+
- drei-environment
|
|
42
|
+
- drei-orbit-controls
|
|
43
|
+
- drei-html
|
|
44
|
+
- drei-text
|
|
45
|
+
- drei-instances
|
|
46
|
+
- drei-use-helper
|
|
47
|
+
- drei-bounds
|
|
48
|
+
- drei-center
|
|
49
|
+
- drei-float
|
|
50
|
+
|
|
51
|
+
## Priority 6: Loading & Suspense (MEDIUM-HIGH)
|
|
52
|
+
- loading-suspense
|
|
53
|
+
- loading-preload
|
|
54
|
+
- loading-use-progress
|
|
55
|
+
- loading-lazy-components
|
|
56
|
+
- loading-error-boundary
|
|
57
|
+
|
|
58
|
+
## Priority 7: State Management (MEDIUM)
|
|
59
|
+
- state-zustand-store
|
|
60
|
+
- state-avoid-objects-in-store
|
|
61
|
+
- state-subscribeWithSelector
|
|
62
|
+
- state-persist
|
|
63
|
+
- state-separate-concerns
|
|
64
|
+
|
|
65
|
+
## Priority 8: Events & Interaction (MEDIUM)
|
|
66
|
+
- events-pointer-events
|
|
67
|
+
- events-stop-propagation
|
|
68
|
+
- events-cursor-pointer
|
|
69
|
+
- events-raycast-filter
|
|
70
|
+
- events-event-data
|
|
71
|
+
|
|
72
|
+
## Priority 9: Post-processing (MEDIUM)
|
|
73
|
+
- postpro-effect-composer
|
|
74
|
+
- postpro-common-effects
|
|
75
|
+
- postpro-selective-bloom
|
|
76
|
+
- postpro-custom-shader
|
|
77
|
+
- postpro-performance
|
|
78
|
+
|
|
79
|
+
## Priority 10: Physics Rapier (LOW-MEDIUM)
|
|
80
|
+
- physics-setup
|
|
81
|
+
- physics-body-types
|
|
82
|
+
- physics-colliders
|
|
83
|
+
- physics-events
|
|
84
|
+
- physics-api-ref
|
|
85
|
+
- physics-performance
|
|
86
|
+
|
|
87
|
+
## Priority 11: Leva Debug GUI (LOW)
|
|
88
|
+
- leva-basic
|
|
89
|
+
- leva-folders
|
|
90
|
+
- leva-conditional
|