Skip to content

Floating Sphere

A weightless metallic sphere with studio reflections.

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

export default function Example() {
  return (
    <div style={{ height: 360 }}>
      <Objects3D
        variant="sphere"
        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).

terminal
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/core

Dependencies: 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.

Example.tsx
import { Objects3D } from "@/components/3d/objects";

export default function Example() {
  return (
    <div style={{ height: 360 }}>
      <Objects3D
        variant="sphere"
        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.

Example.tsx
import { Objects3D } from "@/components/3d/objects";

export default function Example() {
  return (
    <div style={{ height: 360 }}>
      <Objects3D
        variant="sphere"
        theme="amoled"
        color="#7777ff"
        material="metallic"
        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/floating-sphere/page.tsx
// app/floating-sphere/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="sphere"
          theme="light"
        />
      </div>
    </main>
  );
}

TypeScript interfaces

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

export interface FloatingSphereProps {
  /** Which 3D Objects & Models implementation to render */
  variant: "sphere";
  theme: Theme;

  /* Visual */
  color?: string; // default "#7777ff"
  scale?: number; // 0.4–2, default 1

  /* Material */
  material?: "chrome" | "metallic" | "glass" | "matte" | "emissive" | "holographic" | "wireframe"; // default "metallic"
  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

PropTypeDefaultGroupDescription
variant"sphere"—CoreSelects the implementation.
theme"light" | "amoled"—CoreThemes surfaces, materials and lighting.
colorstring (hex)"#7777ff"VisualColor
material"chrome" | "metallic" | "glass" | "matte" | "emissive" | "holographic" | "wireframe""metallic"MaterialMaterial
roughnessnumber-1MaterialRoughness (−1 = auto) (-1 – 1)
metalnessnumber-1MaterialMetalness (−1 = auto) (-1 – 1)
distortnumber0MaterialDistortion (0 – 1)
scalenumber1VisualScale (0.4 – 2)
autoRotatebooleantrueAnimationAuto rotate
rotationSpeednumber0.5AnimationRotation speed (0 – 3)
speednumber1AnimationAnimation speed (0 – 3)
floatnumber1AnimationFloat intensity (0 – 2)
lightnumber1LightingLight intensity (0 – 3)
glownumber1LightingEmissive glow (0 – 3)
dragbooleantrueInteractionDrag to orbit
mousebooleantrueInteractionMouse interaction
transparentbooleanfalseRenderingTransparent background
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 { Objects3D } from "@/components/3d/objects";

export default function Example() {
  return (
    <div style={{ height: 360 }}>
      <Objects3D
        variant="sphere"
        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).