# Manual D1 Setup for TitanForge GLB Editor

D1 is optional. The GLB editor works as a static local-first browser tool without a database.

Use D1 only if you want to track editor load/export events or maintain shared preference presets across the marketplace.

## Manual setup, no Wrangler or CLI

1. Open the Cloudflare Dashboard.
2. Go to **Workers & Pages**.
3. Open your TitanForge GLB Editor Pages project.
4. Go to **Settings → Functions → D1 database bindings**.
5. Add a binding named:

```text
TF_GLB_EDITOR_DB
```

6. Create or select a D1 database for the binding.
7. Open that D1 database in the Cloudflare Dashboard.
8. Go to the SQL console.
9. Paste the contents of:

```text
migrations/0001_glb_editor_manual_d1.sql
```

10. Run the SQL manually.
11. Redeploy or re-upload the Pages project if needed.

## What the included functions do

### `/api/glb-editor/audit`

Receives JSON events from the browser when a GLB is loaded or exported. It stores only lightweight metadata:

- action type
- asset name
- selected profile
- file size
- triangles
- mesh count
- material count
- texture count
- warning count
- timestamp

It does not upload or store the GLB file itself.

### `/api/glb-editor/prefs`

Stores optional named preference presets in D1.

The static app already saves the selected profile in browser local storage, so the preferences endpoint is only needed for shared marketplace/team presets later.

## Safe default

Leave D1 unconfigured until you need logging. The editor's main GLB loading, editing, analysis, and export features do not need D1.
