3D scenes
Solid 2Turn the vase in 3D
The Moon Vase as a three.js scene: drag it round and it spins on with your hand's momentum, and each glaze you pick flows over it.

Moon white, satin · drag the vase to turn it
Reduced motion: The vase doesn't turn on its own, and a flick sets it where it would come to rest at once; a new glaze still fades over it.
Why
A photo shows a piece from one side. A product viewer lets the visitor turn it, and that's a scene: a mesh lathe-turned from the vase's own profile, lit by a room it reflects, drawn on a WebGL canvas. Wardic's hooks work on its objects as they do on elements. Under <WardicStage>, ward(mesh, …) lifts the vase as the pointer comes over it, and springs its glaze to the one you pick. A colour blends in linear light, as three.js draws it, so a white glaze turning cobalt doesn't pass through grey.
The turn is the visitor's hand. createDrag(vase) reads the drag's samples through the scene's raycast and moves nothing itself: each sample turns the vase by how far the pointer has gone, and the release hands its velocity to an inertia transition, so a flick spins it on and slows to rest. A Frame effect keeps the soft shadow under the vase as it lifts, in the Stage's Host loop, after Wardic's writes and before the render, so shadow and vase move in the same frame.
three.js is in this page's own chunk, and the server's page shows the vase's photo. The canvas fades in over it once it has drawn its first frame. Where a browser can't draw WebGL, the photo stays.
In the docs: 3D scenes
The code
import { FAMILIES, familyName, GLAZES, type Glaze } from "@wardic/example-storefront-shared/glazes"
import { createReducedMotion } from "@wardic/solid"
import { createDrag, createFrameEffect, createStage, ward, WardicStage } from "@wardic/three/solid"
import { type Accessor, createSignal, For, untrack } from "solid-js"
import * as THREE from "three"
import { contactShadow, FINISH, hexOf, lightStudio, moonVase } from "~/lib/pottery.ts"
import { onFirstDraw, SceneView } from "~/lib/scene-view.tsx"
/** The vase's own satin white, then the middle gloss of each of the glaze library's families, under the family's name. */
const MOON_WHITE: Glaze = { id: "moon-white", name: "Moon white", family: "ash", finish: "satin", hue: 80, saturation: 10, lightness: 90 }
const CHOICES: ReadonlyArray<Glaze> = [
MOON_WHITE,
...FAMILIES.map((family) => {
const glosses = GLAZES.filter((glaze) => glaze.family === family.id && glaze.finish === "gloss")
return { ...glosses[Math.floor(glosses.length / 2)]!, name: familyName(family.id) }
}),
]
/** Degrees the vase turns a pixel the pointer moves. */
const TURN = 0.5
const LIFT = { type: "spring", bounce: 0.35, visualDuration: 0.4 } as const
const LEAN = { type: "spring", bounce: 0.2, visualDuration: 0.6 } as const
/** Where the pointer is over the view, from -1 to 1 on each axis: the vase leans toward it. */
interface Lean {
readonly x: number
readonly y: number
}
/** The scene: the vase on a turntable, which leans toward the pointer; drawn once this browser can. */
function Scene(props: { readonly glaze: Accessor<Glaze>; readonly lean: Accessor<Lean>; readonly onDrawn: () => void }) {
const scene = new THREE.Scene()
const camera = new THREE.PerspectiveCamera(30, 4 / 3, 0.1, 50)
camera.position.set(0, 2.3, 8.2)
camera.lookAt(0, 0.95, 0)
// The vase turns on its turntable, and the two lean as one toward the pointer.
const { piece, body } = moonVase(untrack(props.glaze))
const turntable = new THREE.Group()
const lean = new THREE.Group()
turntable.add(piece)
lean.add(turntable)
const shadow = contactShadow(1.5)
scene.add(lean, shadow)
onFirstDraw(body, props.onDrawn)
const stage = createStage({
renderer: () => {
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true })
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
lightStudio(scene, renderer)
return renderer
},
scene,
camera,
frameloop: "demand",
})
const Vase = () => {
// Lifted under the pointer; its glaze, the one picked, in linear light.
const vase = ward(piece, { whileHover: { y: 0.12 }, transition: LIFT })
ward(body, {
animate: () => ({ color: hexOf(props.glaze()), ...FINISH[props.glaze().finish] }),
transition: { type: "tween", duration: 0.7, ease: "easeInOut" },
})
ward(lean, { animate: () => ({ rotateX: props.lean().y * 6, rotateZ: -props.lean().x * 6 }), transition: LEAN })
// The shadow under it, in the frame the vase lifts in: smaller and fainter the higher it is.
createFrameEffect(vase.read("y"), (y) => {
shadow.scale.setScalar(1 - y * 0.9)
shadow.material.opacity = 1 - y * 3
})
// Until the visitor first takes it, the vase turns slowly on its own.
const still = createReducedMotion()
if (!untrack(still)) void stage.animate(turntable, { rotateY: [0, 360] }, { duration: 40, ease: "linear", repeat: Infinity })
// The visitor's turn: each sample turns it by how far the pointer has gone since the press, and the
// release glides on at the pointer's speed.
const drag = createDrag(piece)
let from = 0
createFrameEffect(drag, (sample) => {
if (sample === null) return
if (sample.phase === "start") from = THREE.MathUtils.radToDeg(turntable.rotation.y)
const rotateY = from + sample.offset.x * TURN
if (sample.phase === "end") {
void stage.animate(turntable, { rotateY }, { type: "inertia", velocity: sample.velocity.x * TURN, power: 0.5, timeConstant: 700 })
return
}
void stage.animate(turntable, { rotateY }, { duration: 0 })
})
return vase.held
}
return (
<WardicStage value={stage}>
<div class="scene-stage" ref={stage} />
<Vase />
</WardicStage>
)
}
/** The Moon Vase in 3D: drag it round, and pick a glaze. */
export default function TurnTheVase() {
const [glaze, setGlaze] = createSignal(MOON_WHITE)
const [lean, setLean] = createSignal<Lean>({ x: 0, y: 0 })
const onPointerMove = (event: PointerEvent) => {
const box = (event.currentTarget as HTMLElement).getBoundingClientRect()
setLean({ x: ((event.clientX - box.left) / box.width) * 2 - 1, y: ((event.clientY - box.top) / box.height) * 2 - 1 })
}
return (
<div class="scene-demo">
<SceneView piece="moon-vase" alt="The Moon Vase" onPointerMove={onPointerMove} onPointerLeave={() => setLean({ x: 0, y: 0 })}>
{(drawn) => <Scene glaze={glaze} lean={lean} onDrawn={drawn} />}
</SceneView>
<div class="chips" role="group" aria-label="Glaze">
<For each={CHOICES}>
{(choice) => (
<button type="button" class="chip" aria-pressed={String(glaze().id === choice.id) as "true" | "false"} onClick={() => setGlaze(choice)}>
<span class="swatch" style={{ background: hexOf(choice) }} />
{choice.name}
</button>
)}
</For>
</div>
<p class="scene-readout">
{glaze().name}, {glaze().finish} · <span class="muted">drag the vase to turn it</span>
</p>
</div>
)
}