Skip to content

Interactive Physics Objects

Mixed spheres, cubes and polyhedra colliding.

WebGLTypeScriptLight + AMOLED
Example.tsx
import { Experiences3D } from "@/components/3d/experiences";

export default function Example() {
  return (
    <div style={{ height: 480 }}>
      <Experiences3D
        variant="objects"
        theme="light"
      />
    </div>
  );
}

Deps: three, @react-three/fiber, @react-three/drei, framer-motion

Installation

Install the runtime dependencies, then copy the component module (and the shared 3D core when the component uses WebGL).

terminal
npm install three @react-three/fiber @react-three/drei framer-motion

# Copy the component module
cp -r src/components/3d/experiences <your-project>/src/components/3d/experiences
# Copy the shared 3D core
cp -r src/components/3d/core <your-project>/src/components/3d/core

Dependencies: three, @react-three/fiber, @react-three/drei, framer-motion

Usage

Every category module exposes one typed component. Pick an implementation with variant and pass props grouped by concern.

Example.tsx
import { Experiences3D } from "@/components/3d/experiences";

export default function Example() {
  return (
    <div style={{ height: 480 }}>
      <Experiences3D
        variant="objects"
        theme="light"
      />
    </div>
  );
}

React implementation

With every prop set explicitly. The complete, copyable source of src/components/3d/experiences/index.tsx is available in the playground’s Source tab.

Example.tsx
import { Experiences3D } from "@/components/3d/experiences";

export default function Example() {
  return (
    <div style={{ height: 480 }}>
      <Experiences3D
        variant="objects"
        theme="amoled"
        color="#7777ff"
        count={30}
        gravity={9}
        bounce={0.6}
        mouse
        speed={1}
        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/interactive-physics-objects/page.tsx
// app/interactive-physics-objects/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 Experiences3D = dynamic(
  () => import("@/components/3d/experiences").then((m) => m.Experiences3D),
  { ssr: false, loading: () => <div aria-busy="true" style={{ height: 480 }} /> },
);

export default function Page() {
  return (
    <main>
      <div style={{ height: 480 }}>
        <Experiences3D
          variant="objects"
          theme="light"
        />
      </div>
    </main>
  );
}

TypeScript interfaces

InteractivePhysicsObjects.types.ts
export type Theme = "light" | "amoled";

export interface InteractivePhysicsObjectsProps {
  /** Which Advanced Interactive Experiences implementation to render */
  variant: "objects";
  theme: Theme;

  /* Visual */
  color?: string; // default "#7777ff"
  gravity?: number; // 0–20, default 9
  bounce?: number; // 0–1, default 0.6

  /* Rendering */
  count?: number; // 10–100, default 30
  quality?: "low" | "medium" | "high"; // default "medium"

  /* Interaction */
  mouse?: boolean; // default true

  /* Animation */
  speed?: number; // 0–3, default 1
}

Props reference

PropTypeDefaultGroupDescription
variant"objects"—CoreSelects the implementation.
theme"light" | "amoled"—CoreThemes surfaces, materials and lighting.
colorstring (hex)"#7777ff"VisualAccent
countnumber30RenderingObject count (10 – 100)
gravitynumber9VisualGravity (0 – 20)
bouncenumber0.6VisualBounciness (0 – 1)
mousebooleantrueInteractionMouse interaction
speednumber1AnimationAnimation speed (0 – 3)
quality"low" | "medium" | "high""medium"RenderingQuality 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.

Customized.tsx
import { Experiences3D } from "@/components/3d/experiences";

export default function Example() {
  return (
    <div style={{ height: 480 }}>
      <Experiences3D
        variant="objects"
        theme="light"
        color="#ff5a36"
      />
    </div>
  );
}

Animation settings

  • mouseMouse interaction
  • speedAnimation speed · 0–3

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

  • — Every canvas interaction has a DOM alternative (buttons, sliders, lists).
  • — The museum is keyboard-walkable (WASD/arrows) with on-screen controls.
  • — Audio never starts without an explicit user action.

Performance notes

  • — Custom physics is O(n²) with a capped body count — tune it with the Count control.
  • — Particle simulation updates typed arrays in place.
  • — The fluid solver runs on a 80×80 grid and pauses off-screen.

Presets: LOW (DPR 1, no AA, ~35% density) · MEDIUM (DPR ≤1.5, ~70%) · HIGH (DPR ≤2, full density).