Loading files
"use client";
import type { RefObject } from "react";
import { Html } from "@react-three/drei";
import { useRoom } from "@/components/livekit/RoomProvider";
import { CameraWall } from "@/components/livekit/CameraWall";
import type { Channel } from "@/lib/config";
const SCREEN_W = 2.64;
const SCREEN_H = 1.49;
// The screen is the SAME multicam stage as /broadcast, rendered as real DOM (drei <Html transform>)
// so it keeps the exact tiles, CRT styling, neon borders and LIVE/NO-SIG statuses. drei maps content
// pixels → world units by px × ((distanceFactor||10)/400) × groupScale = px × 0.025 × scale, so the
// 1320×745 (16:9) composite is fit to the screen `width` below (scale = width / (1320 × 0.025)).
const CONTENT_W = 1320;
const CONTENT_H = 745;
/**
* The cabinet's CRT plane. Lays the shared <CameraWall> composite onto the screen (pinned feed large +
* the other three alongside — matching /broadcast). Clicking a feed re-pins it via `onSelect`. The
* composite is portaled (`htmlPortal`) into the app tree so it sits above the WebGL screen but below
* the DirectorOverlay controls, and its tiles are clickable without blocking those controls.
*/
export function ScreenMesh({
active,
position,
onSelect,
htmlPortal,
width = SCREEN_W,
height = SCREEN_H,
feedWidth = width,
feedYOffset = 0,
showFeed = true,
}: {
active: Channel;
position?: [number, number, number];
onSelect?: (id: string) => void;
htmlPortal?: RefObject<HTMLDivElement | null>;
width?: number;
height?: number;
feedWidth?: number;
feedYOffset?: number;
showFeed?: boolean;
}) {
const { videoTracks } = useRoom();
// The black CRT surface is `width`×`height`; the 16:9 multicam composite is laid on it at `feedWidth`
// (native aspect preserved), centered — with a `feedYOffset` nudge — so it never stretches or spills.
// (drei maps px → world as px × 0.025 × scale, so scale = feedWidth / (CONTENT_W × 0.025).)
const htmlScale = feedWidth / (CONTENT_W * 0.025);
return (
<group position={position}>
{/* the black CRT surface (the model's monitor); the live feed sits centered on it, as before */}
<mesh>
<planeGeometry args={[width, height]} />
<meshBasicMaterial color="#05060f" toneMapped={false} />
</mesh>
{/* the multicam composite — the SAME component /broadcast renders — laid on the CRT plane, centered.
pointer-events off on the wrapper (tiles opt back in) + portaled so the controls stay on top.
Hidden (display:none) until `showFeed` — the intro shows the black CRT above and only reveals the
feeds once the camera is static, so this heavy live-video layer is never CSS-transformed mid-zoom
(that was the end-of-intro lag). Kept mounted so LiveKit tracks stay attached → instant reveal. */}
<Html
transform
position={[0, feedYOffset, 0.02]}
scale={htmlScale}
zIndexRange={[20, 0]}
pointerEvents="none"
portal={htmlPortal as RefObject<HTMLElement> | undefined}
>
<div
style={{
width: `${CONTENT_W}px`,
height: `${CONTENT_H}px`,
display: showFeed ? undefined : "none",
}}
// crt-power-on is added the instant `showFeed` flips true, so the retro tube warm-up flicker
// plays right as the feeds reveal (end of intro, or first paint for returning visitors).
className={`overflow-hidden bg-cab-900${showFeed ? " crt-power-on" : ""}`}
>
<CameraWall videoTracks={videoTracks} pinnedTrackName={active.trackName} onSelect={onSelect} />
</div>
</Html>
</group>
);
}
export { SCREEN_W, SCREEN_H };
05241c15dThis file is pinned to the selected release. Download the original to open it in your design tool.