|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +Audience: humans and AI agents working in this repository. This file defines expectations, conventions, and tips for making safe, minimal, and consistent changes. |
| 4 | + |
| 5 | +Scope: the entire repository rooted at this folder. |
| 6 | + |
| 7 | +## Quick Start |
| 8 | +- Requirements: Node.js 18+ (Vite 5), npm 9+. |
| 9 | +- Install: `npm i` |
| 10 | +- Dev server: `npm run dev` |
| 11 | +- Build: `npm run build` |
| 12 | +- Preview build: `npm run preview` |
| 13 | +- Lint/format: `npm run lint`, `npm run format` |
| 14 | +- Scene tests: `npm run test` (serves `src/tests` via Vite) |
| 15 | + |
| 16 | +## Project Layout |
| 17 | +- `index.html`, `main.js`: default app entry. |
| 18 | +- `src/`: application code and assets. |
| 19 | + - `core/`: rendering, cameras, environments, managers, etc. |
| 20 | + - `gui/`: Tweakpane Manager and helpers. |
| 21 | + - `assets/`: images, HDRI, models, audio. |
| 22 | + - `presets/`: preset data (env, fog, camera, scene requirements). |
| 23 | +- `public/`: static assets served at root (avoid duplicating assets already in `src/assets`). |
| 24 | +- `lumaLabs/`: standalone prototypes/demos; not part of the main build. Keep edits minimal and localized when fixing issues here. |
| 25 | + |
| 26 | +## Module Resolution & Aliases |
| 27 | +Aliased imports are configured in both `vite.config.js` and `jsconfig.json`. Prefer these paths: |
| 28 | +- `@` → `src` |
| 29 | +- `@core` → `src/core` |
| 30 | +- `@components` → `src/core/components` |
| 31 | +- `@managers` → `src/core/managers` |
| 32 | +- `@renderers` → `src/core/renderers` |
| 33 | +- `@cameras` → `src/core/cameras` |
| 34 | +- `@controls` → `src/core/controls` |
| 35 | +- `@environments` → `src/core/components/environments` |
| 36 | +- `@effects` → `src/core/effects` |
| 37 | +- `@postprocessing` → `src/core/postprocessing` |
| 38 | +- `@utils` → `src/utils` |
| 39 | +- `@gui` → `src/gui` |
| 40 | +- `@assets` → `src/assets` |
| 41 | +- `@models` → `src/assets/models` |
| 42 | +- `@textures` → `src/assets/textures` |
| 43 | +- `@environmentMaps` → `src/assets/environmentMaps` |
| 44 | +- `@presets` → `src/presets` |
| 45 | +- `@tests` → `src/tests` |
| 46 | + |
| 47 | +When you add or move folders, update both `vite.config.js` and `jsconfig.json` consistently. |
| 48 | + |
| 49 | +## Three.js Version Notes (r157+) |
| 50 | +- Use `THREE.SRGBColorSpace` for color spaces; avoid deprecated `encoding` options. |
| 51 | +- For `WebGLRenderTarget`/`WebGLCubeRenderTarget`, prefer `{ colorSpace: THREE.SRGBColorSpace }`. |
| 52 | +- Tone mapping defaults: ACESFilmic is standard here. |
| 53 | + |
| 54 | +## Tweakpane Usage |
| 55 | +- Use `TweakpaneManager` (`@gui/TweakpaneManager`) to create UI. It provides: |
| 56 | + - `addFolder({ title: string })` or `addFolder("Title")` alias (internally uses `createFolder`). |
| 57 | + - `pane.addTab`, `folder.addBinding`, etc. via Tweakpane. |
| 58 | + - `refresh()` and `dispose()` passthroughs. |
| 59 | +- Event signature: `.on("change", ({ value }) => { ... })` (Tweakpane v4 style). Do not assume raw value is passed. |
| 60 | +- Prefer updating parameters then calling `pane.refresh()` or component-specific update methods when needed. |
| 61 | + |
| 62 | +## HDRI Environments & Assets |
| 63 | +- HDR files live under `src/assets/environmentMaps/hdr/`. EXR files, if used, under `src/assets/environmentMaps/exr/`. |
| 64 | +- `HDRIEnvironment` resolves preset paths using Vite’s `import.meta.glob` with `{ as: 'url' }`. Keep preset paths in `src/presets/envPresets.js` like `/environmentMaps/hdr/<file>.hdr` — the loader will resolve to the correct bundled URL. |
| 65 | +- If you add new HDRs, place them in the folder above and add a corresponding preset entry. |
| 66 | +- The environment system exposes `environment.debugObject` with keys like `intensity`, `blur`, `rotation`, `path`, `exposure`. Use `environment.updateFromDebug(scene, renderer)` to apply changes. |
| 67 | + |
| 68 | +## Vite Configuration |
| 69 | +- Aliases are defined under `resolve.alias`. |
| 70 | +- `build` and `server.hmr` should be top-level keys in the exported config (not nested under `resolve`). If you alter Vite config, preserve structure and keep aliases in sync with `jsconfig.json`. |
| 71 | +- For runtime asset URLs, prefer `import.meta.glob` or `new URL('./path', import.meta.url)`. Avoid hardcoding dev server URLs. |
| 72 | + |
| 73 | +## Coding Conventions |
| 74 | +- ESM only (`"type": "module"` is set). Use `import`/`export`; do not use CommonJS. |
| 75 | +- Keep diffs small and focused. Avoid refactors that aren’t required by the task. |
| 76 | +- Match existing file style (Prettier config included). Run `npm run format` if you touch multiple files. |
| 77 | +- Favor descriptive variable names; avoid single-letter names. |
| 78 | +- Do not add license headers unless explicitly requested. |
| 79 | + |
| 80 | +## Prototypes in `lumaLabs/` |
| 81 | +- These HTML files are standalone demos. If fixing issues (e.g., reassigning a `const`), keep changes minimal (e.g., change to `let`) and avoid cross-wiring them into the main app. |
| 82 | + |
| 83 | +## Common Pitfalls |
| 84 | +- Tweakpane change handlers must destructure `{ value }`. |
| 85 | +- With Three r157+, replace deprecated `encoding` with `colorSpace` options. |
| 86 | +- Reassignments: don’t reassign `const` variables. Use `let` if reassignment is intended. |
| 87 | +- Ensure new assets are placed under `src/assets/...` to be bundled by Vite. |
| 88 | + |
| 89 | +## PRs/Commits (for human contributors) |
| 90 | +- Use clear, task-focused commit messages. |
| 91 | +- Don’t mix unrelated changes. Update docs when behavior changes. |
| 92 | +- If you move/rename files referenced by presets or aliases, update references atomically. |
| 93 | + |
| 94 | +## When in Doubt |
| 95 | +- Prefer minimal, surgical changes. |
| 96 | +- Keep presets and aliases consistent. |
| 97 | +- Validate locally (`npm run dev`) and check the browser console for warnings/errors. |
0 commit comments