import { Objects3D } from "@/components/3d/objects";
export default function Example() {
return (
<div style={{ height: 360 }}>
<Objects3D
variant="crystal"
theme="light"
/>
</div>
);
}
Deps: three, @react-three/fiber, @react-three/drei
Installation
Install the runtime dependencies, then copy the component module (and the shared 3D core when the component uses WebGL).
npm install three @react-three/fiber @react-three/drei
# Copy the component module
cp -r src/components/3d/objects <your-project>/src/components/3d/objects
# Copy the shared 3D core
cp -r src/components/3d/core <your-project>/src/components/3d/coreDependencies: three, @react-three/fiber, @react-three/drei
Usage
Every category module exposes one typed component. Pick an implementation with variant and pass props grouped by concern.
import { Objects3D } from "@/components/3d/objects";
export default function Example() {
return (
<div style={{ height: 360 }}>
<Objects3D
variant="crystal"
theme="light"
/>
</div>
);
}
React implementation
With every prop set explicitly. The complete, copyable source of src/components/3d/objects/index.tsx is available in the playground’s Source tab.
import { Objects3D } from "@/components/3d/objects";
export default function Example() {
return (
<div style={{ height: 360 }}>
<Objects3D
variant="crystal"
theme="amoled"
color="#7777ff"
material="glass"
roughness={-1}
metalness={-1}
distort={0}
scale={1}
autoRotate
rotationSpeed={0.5}
speed={1}
float={1}
light={1}
glow={1}
drag
mouse
transparent={false}
quality="medium"
/>
</div>
);
}
Next.js implementation
WebGL needs the browser. Load the scene through next/dynamic with ssr disabled and a sized placeholder to avoid layout shift.
// app/3d-crystal/page.tsx (Next.js App Router)
"use client";
import dynamic from "next/dynamic";
// WebGL must never run on the server — load the scene client-side only.
const Objects3D = dynamic(
() => import("@/components/3d/objects").then((m) => m.Objects3D),
{ ssr: false, loading: () => <div aria-busy="true" style={{ height: 360 }} /> },
);
export default function Page() {
return (
<main>
<div style={{ height: 360 }}>
<Objects3D
variant="crystal"
theme="light"
/>
</div>
</main>
);
}
TypeScript interfaces
export type Theme = "light" | "amoled";
export interface 3DCrystalProps {
/** Which 3D Objects & Models implementation to render */
variant: "crystal";
theme: Theme;
/* Visual */
color?: string; // default "#7777ff"
scale?: number; // 0.4–2, default 1
/* Material */
material?: "chrome" | "metallic" | "glass" | "matte" | "emissive" | "holographic" | "wireframe"; // default "glass"
roughness?: number; // -1–1, default -1
metalness?: number; // -1–1, default -1
distort?: number; // 0–1, default 0
/* Animation */
autoRotate?: boolean; // default true
rotationSpeed?: number; // 0–3, default 0.5
speed?: number; // 0–3, default 1
float?: number; // 0–2, default 1
/* Lighting */
light?: number; // 0–3, default 1
glow?: number; // 0–3, default 1
/* Interaction */
drag?: boolean; // default true
mouse?: boolean; // default true
/* Rendering */
transparent?: boolean; // default false
quality?: "low" | "medium" | "high"; // default "medium"
}
Props reference
| Prop | Type | Default | Group | Description |
|---|---|---|---|---|
| variant | "crystal" | — | Core | Selects the implementation. |
| theme | "light" | "amoled" | — | Core | Themes surfaces, materials and lighting. |
| color | string (hex) | "#7777ff" | Visual | Color |
| material | "chrome" | "metallic" | "glass" | "matte" | "emissive" | "holographic" | "wireframe" | "glass" | Material | Material |
| roughness | number | -1 | Material | Roughness (−1 = auto) (-1 – 1) |
| metalness | number | -1 | Material | Metalness (−1 = auto) (-1 – 1) |
| distort | number | 0 | Material | Distortion (0 – 1) |
| scale | number | 1 | Visual | Scale (0.4 – 2) |
| autoRotate | boolean | true | Animation | Auto rotate |
| rotationSpeed | number | 0.5 | Animation | Rotation speed (0 – 3) |
| speed | number | 1 | Animation | Animation speed (0 – 3) |
| float | number | 1 | Animation | Float intensity (0 – 2) |
| light | number | 1 | Lighting | Light intensity (0 – 3) |
| glow | number | 1 | Lighting | Emissive glow (0 – 3) |
| drag | boolean | true | Interaction | Drag to orbit |
| mouse | boolean | true | Interaction | Mouse interaction |
| transparent | boolean | false | Rendering | Transparent background |
| quality | "low" | "medium" | "high" | "medium" | Rendering | Quality preset |
Customization
Colour props accept any hex string. Content props accept plain strings. Every value shown in the playground maps 1:1 to a prop, so you can design visually and copy the generated code. Use Share to send a pre-configured link or Export to download the configuration JSON.
import { Objects3D } from "@/components/3d/objects";
export default function Example() {
return (
<div style={{ height: 360 }}>
<Objects3D
variant="crystal"
theme="light"
color="#ff5a36"
/>
</div>
);
}
Animation settings
- autoRotateAuto rotate
- rotationSpeedRotation speed · 0–3
- speedAnimation speed · 0–3
- floatFloat intensity · 0–2
- dragDrag to orbit
- mouseMouse interaction
All motion is suspended when prefers-reduced-motion is on.
Theme support
Pass theme="light" or theme="amoled". Lighting rigs, environment reflections, blending modes and canvas backgrounds change with it — AMOLED uses true #000000 with controlled emissive accents; Light uses soft studio lighting with contact shadows. Use the theme switch in the playground toolbar to preview both.
Responsive behavior
The component fills its parent, so size it with the container. Use the playground’s desktop / tablet / mobile selector to test. Canvas resolution adapts through the adaptive DPR range of the active quality preset.
Accessibility notes
- — Objects are decorative: the wrapper carries a descriptive aria-label.
- — Drag-to-orbit is pointer-only; the surrounding page remains fully keyboard navigable.
- — Auto-rotation halts under reduced-motion.
Performance notes
- — Repeated geometry (DNA, cubes, helix, crystals) is drawn with InstancedMesh.
- — Glass uses physical transmission — use MEDIUM or lower on mobile.
- — Contact shadows render at a quality-dependent resolution.
Presets: LOW (DPR 1, no AA, ~35% density) · MEDIUM (DPR ≤1.5, ~70%) · HIGH (DPR ≤2, full density).