Diorama

Made for a big screen.

This site is one 3D scene, built for a computer: a wide window and a mouse. Open dioramajs.dev on a desktop or a laptop to see it.This site is one 3D scene, built for a wide window. Make this one wider, or open dioramajs.dev on a larger screen.

GitHub

DioramaDocs

Install with Next.js

Wrap the Next.js config with withDiorama and start the app from a client component.

View as Markdown
On this page

Next.js builds with webpack or Turbopack, not Vite. withDiorama writes the effect registry and its types to src/diorama.gen.ts and points both bundlers at it. Effects go in src/effects/.

Install the packages

Terminal window
npm install @dioramajs/diorama three
Terminal window
pnpm add @dioramajs/diorama three
Terminal window
yarn add @dioramajs/diorama three
Terminal window
bun add @dioramajs/diorama three

Wrap the config

next.config.ts
import {
function withDiorama<T extends object = NextConfigLike>(
config: T & NextConfigLike,
options?: WithDioramaOptions
): T

Wraps a Next config so the effects folder becomes @dioramajs/diorama/generated.

withDiorama
} from '@dioramajs/diorama/next'
export default
withDiorama<{}>(
config: NextConfigLike,
options?: WithDioramaOptions
): {}

Wraps a Next config so the effects folder becomes @dioramajs/diorama/generated.

withDiorama
({})

Start the app from a client component

src/app/diorama.tsx
'use client'
import { start } from '@dioramajs/diorama'
import { useEffect } from 'react'
export function Diorama() {
useEffect(() => void start(), [])
return null
}

Render <Diorama /> once in the root layout.

src/app/layout.tsx
import type { ReactNode } from 'react'
import { Diorama } from './diorama'
export default function RootLayout({
children,
}: {
children: ReactNode
}) {
return (
<html lang="en">
<body>
{children}
<Diorama />
</body>
</html>
)
}

Put an effect on an image

src/app/page.tsx
export default function Page() {
return (
<img
src="/cover.jpg"
width={800}
height={450}
data-dio="ripple"
/>
)
}

Commit src/diorama.gen.ts. In development new and removed effect files are picked up on their own, and Fast Refresh replaces an edited effect.