agentleFS
madebyarismadebyaris/advance-minimax-m3-cursor-rules/.cursor/rules/3d-graphics.mdc

advance-minimax-m3-cursor-rules / rules

Cursor rule126 starsChanged 6 months agoMITView on GitHub

Three.js / React Three Fiber syntax: scene setup, R3F hooks, models, controls. Load for 3D code — taste, perf budgets, and mobile WebGL live in the 3d-web-experiences skill.

The file

We split this 3d-graphics.mdc into the rules it gives an agent

2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Verify package APIs against installed versions before asserting prop names.

    line 11
  2. Very specific:

    Prefer .glb with Draco/Meshopt compression for web (see skill → asset pipeline).

    line 108

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
3d-graphics.mdc
---
description: "Three.js / React Three Fiber syntax: scene setup, R3F hooks, models, controls. Load for 3D code — taste, perf budgets, and mobile WebGL live in the 3d-web-experiences skill."
globs: ["**/*.{jsx,tsx,js,ts}", "**/three/**", "**/*.glb", "**/*.gltf"]
alwaysApply: false
---

# 3D Graphics — Syntax Reference

Mechanical patterns for Three.js, React Three Fiber (R3F), and `@react-three/drei`. For aesthetic direction, performance tiers, responsive/mobile WebGL, degradation, accessibility, and verified recipes, load the **`3d-web-experiences`** skill (`reference.md` for full scenes and bug catalog).

Verify package APIs against installed versions before asserting prop names.

---

## CRITICAL: Container Dimensions

A WebGL canvas without a sized parent renders at zero height or wrong aspect.

```jsx
// WRONG
<div><Canvas><Scene /></Canvas></div>

// CORRECT — explicit height on the container
<div style={{ height: '500px', width: '100%' }}>
  <Canvas><Scene /></Canvas>
</div>
```

Vanilla Three.js: size the renderer to the **container**, not always `window` — use `ResizeObserver` or container `clientWidth` / `clientHeight`.

---

## R3F Canvas Baseline

```jsx
import { Canvas } from '@react-three/fiber';
import { OrbitControls, Environment } from '@react-three/drei';

export function Scene() {
  return (
    <div style={{ height: '500px', width: '100%' }}>
      <Canvas shadows dpr={[1, 2]} camera={{ position: [0, 0, 5], fov: 45 }}>
        <Environment preset="city" />
        <ambientLight intensity={0.4} />
        <directionalLight position={[5, 5, 5]} castShadow />
        <Mesh />
        <OrbitControls enableDamping />
      </Canvas>
    </div>
  );
}
```

Set tone mapping and output color space on the renderer for PBR that is not flat — see `3d-web-experiences` → renderer baseline.

---

## Hooks & Imports (common bugs)

```jsx
import { useRef, useState } from 'react';
import { useFrame } from '@react-three/fiber'; // NOT from 'react'
import type { Mesh } from 'three';

function AnimatedBox() {
  const ref = useRef<Mesh>(null);
  useFrame((_, delta) => {
    if (ref.current) ref.current.rotation.y += delta;
  });
  return (
    <mesh ref={ref}>
      <boxGeometry />
      <meshStandardMaterial />
    </mesh>
  );
}
```

| Mistake | Fix |
|---------|-----|
| `useFrame` from `react` | Import from `@react-three/fiber` |
| `<Detail>` from `three` | Use drei `<Detailed distances={[0, 10, 20]}>` with child meshes |
| `InstancedMesh` from fiber | Use JSX `<instancedMesh>`; `Object3D` from `three` |

---

## Models & Loading

```jsx
import { Suspense } from 'react';
import { useGLTF, Html, useProgress } from '@react-three/drei';

function Model({ url }) {
  const { scene } = useGLTF(url);
  return <primitive object={scene} />;
}
useGLTF.preload('/models/asset.glb');

function Loader() {
  const { progress } = useProgress();
  return <Html center>{progress.toFixed(0)}%</Html>;
}

// Wrap async assets:
<Suspense fallback={<Loader />}><Model url="…" /></Suspense>
```

Prefer `.glb` with Draco/Meshopt compression for web (see skill → asset pipeline).

---

## LOD & Instancing (mechanics)

```jsx
import { Detailed } from '@react-three/drei';

<Detailed distances={[0, 10, 25]}>
  <HighPolyMesh />
  <MediumPolyMesh />
  <LowPolyMesh />
</Detailed>
```

For many copies of the same geometry, use `<instancedMesh>` or drei `<Instances>`. Budgets, DPR clamps, and `frameloop="demand"`: **`3d-web-experiences`**.

---

## Camera Controls (drei)

```jsx
import { OrbitControls, MapControls } from '@react-three/drei';

<OrbitControls enableDamping dampingFactor={0.05} minDistance={2} maxDistance={20} />
```

Respect `prefers-reduced-motion` — pause auto-rotate and heavy camera motion (skill → accessibility).

---

## Verification (3D changes)

| Check | How |
|-------|-----|
| Renders | Browser load — not blank/black canvas |
| Console | No WebGL / shader compile errors |
| Resize | Container height preserved; canvas scales with parent |
| Mobile | DPR/effects tier reduced when skill budget applies |

Browser verification required; use console + visual check minimum.

---

## When NOT to Load This File

- 2D UI only — use `design-systems` + `anti-slop-design`.
- “Make it look good” / hero aesthetic — start with **`3d-web-experiences`** Step 1 (direction + slop catalog), then use this file for syntax.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.