Skip to content

Create professional demos and 3D mockups in seconds, directly in your browser

fix: address 3D camera review feedback

Efrain Chiri Nina5620d7a99886
diff --git a/app/components/ui/editor/ControlPanel.tsx b/app/components/ui/editor/ControlPanel.tsx
index ff6168b..47651fa 100644
--- a/app/components/ui/editor/ControlPanel.tsx
+++ b/app/components/ui/editor/ControlPanel.tsx
@@ -7,7 +7,7 @@ import { TabButton } from "../../../../components/ui/TabButton";
import type { ControlPanelProps } from "@/types/control-panel.types";
import Link from "next/link";
import Image from "next/image";
-import { lazy, Suspense, useEffect, useState } from "react";
+import { lazy, Suspense, useState } from "react";
import { useTranslations } from "next-intl";
import { ElementsMenuSkeleton, ZoomGlobalConfigSkeleton, MockupMenuSkeleton, WallpaperSkeleton, BackgroundColorSkeleton, ZoomFragmentEditorSkeleton, AudioMenuSkeleton, VideosMenuSkeleton, HistoryMenuSkeleton, MotionGlobalConfigSkeleton, MotionFragmentEditorSkeleton } from "../Skeleton";
@@ -143,25 +143,11 @@ export function ControlPanel({
const hasMockup2D = mediaType === "video" && !imagePhoneActive;
const hasMockup3D = imagePhoneActive;
- const [isDark, setIsDark] = useState(false);
-
- useEffect(() => {
- const html = document.documentElement;
- const update = () => setIsDark(html.classList.contains("dark"));
- update();
- const observer = new MutationObserver(update);
- observer.observe(html, { attributes: true, attributeFilter: ["class"] });
- return () => observer.disconnect();
- }, []);
-
return (
<div className="relative w-full sm:w-[320px] h-screen bg-background flex flex-col shrink-0" role="complementary" aria-label="Control panel">
<header className="relative flex items-center justify-between h-13 p-2 border-r shrink-0 bg-transparent isolation-isolate" role="banner">
<div
- className={`absolute inset-0 z-0 bg-cover bg-center bg-no-repeat pointer-events-none opacity-90 ${isDark
- ? "bg-[url('/images/pages/header-gradient.avif')]"
- : "bg-[url('/images/pages/header-gradient-light.png')]"
- }`}
+ className="absolute inset-0 z-0 pointer-events-none opacity-90"
style={{
maskImage: `
linear-gradient(to bottom, black 55%, transparent 99%),
@@ -176,7 +162,10 @@ export function ControlPanel({
maskComposite: "intersect",
WebkitMaskComposite: "source-in"
}}
- />
+ >
+ <div className="absolute inset-0 hidden bg-[url('/images/pages/header-gradient.avif')] bg-cover bg-center bg-no-repeat dark:block" />
+ <div className="absolute inset-0 bg-[url('/images/pages/header-gradient-light.png')] bg-cover bg-center bg-no-repeat dark:hidden" />
+ </div>
<Link
href="/"
@@ -185,10 +174,18 @@ export function ControlPanel({
aria-label="Openvid home"
>
<Image
- src={isDark ? "/svg/openvid-complete-static.svg" : "/svg/openvid-complete-light.svg"}
+ src="/svg/openvid-complete-static.svg"
+ alt="Openvid"
+ width={100}
+ height={80}
+ className="hidden dark:block"
+ />
+ <Image
+ src="/svg/openvid-complete-light.svg"
alt="Openvid"
width={100}
height={80}
+ className="dark:hidden"
/>
</Link>
diff --git a/app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsx b/app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsx
index 3598508..ad263ba 100644
--- a/app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsx
+++ b/app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsx
@@ -384,14 +384,24 @@ export function DoubleIPhoneScene({
onLoaded?.();
}, [onLoaded]);
- const prevRotationRef = useRef<{ x: number; y: number } | null>({ x: initialRotationX, y: initialRotationY });
+ const prevCameraStateRef = useRef({
+ x: initialRotationX,
+ y: initialRotationY,
+ distance: cameraConfig.distance,
+ target: cameraConfig.target,
+ });
useEffect(() => {
if (isUserInteractingRef.current) return;
const currentAngles = { x: initialRotationX, y: initialRotationY };
- if (areAnglesEqual(prevRotationRef.current, currentAngles)) {
+ const previous = prevCameraStateRef.current;
+ if (
+ areAnglesEqual(previous, currentAngles) &&
+ previous.distance === cameraConfig.distance &&
+ previous.target.every((coordinate, index) => coordinate === cameraConfig.target[index])
+ ) {
return;
}
@@ -400,18 +410,20 @@ export function DoubleIPhoneScene({
const orbit = orbitRef.current;
if (!orbit) return;
- const radius = 1.5;
- const phi = Math.PI / 2 - initialRotationX * DEG;
- const theta = initialRotationY * DEG;
-
- orbit.object.position.setFromSphericalCoords(radius, phi, theta);
+ orbit.object.position.fromArray(
+ getMockupCameraPosition(initialRotationX, initialRotationY, cameraConfig.distance, cameraConfig.target),
+ );
orbit.update();
invalidateRef.current();
- prevRotationRef.current = currentAngles;
+ prevCameraStateRef.current = {
+ ...currentAngles,
+ distance: cameraConfig.distance,
+ target: cameraConfig.target,
+ };
}, 0);
return () => clearTimeout(id);
- }, [initialRotationX, initialRotationY, zoom, areAnglesEqual]);
+ }, [initialRotationX, initialRotationY, zoom, areAnglesEqual, cameraConfig.distance, cameraConfig.target]);
useEffect(() => {
if (rootRef.current) {
@@ -494,12 +506,13 @@ export function DoubleIPhoneScene({
isUserInteractingRef.current = false;
const orbit = orbitRef.current;
if (orbit) {
- prevRotationRef.current = {
+ prevCameraStateRef.current = {
+ ...prevCameraStateRef.current,
x: 90 - orbit.getPolarAngle() * (180 / Math.PI),
y: orbit.getAzimuthalAngle() * (180 / Math.PI),
};
}
- reportMockupCameraChange(orbitRef.current, 1.5, onCameraChange, onRotationChange);
+ reportMockupCameraChange(orbitRef.current, 1.5, onCameraChange, onRotationChange, cameraConfig.fov);
}}
/>
<Environment files={HDRI_FILES[environment as EnvironmentPreset]} environmentIntensity={glow} background={false} />
diff --git a/app/components/ui/editor/mockups-3d/IPadMini63DViewer.tsx b/app/components/ui/editor/mockups-3d/IPadMini63DViewer.tsx
index 8d0587e..00f71a5 100644
--- a/app/components/ui/editor/mockups-3d/IPadMini63DViewer.tsx
+++ b/app/components/ui/editor/mockups-3d/IPadMini63DViewer.tsx
@@ -347,14 +347,21 @@ export function IPadMiniScene({
onLoaded?.();
}, [onLoaded]);
- const prevRotationRef = useRef<{ x: number; y: number } | null>({ x: initialRotationX, y: initialRotationY });
+ const prevCameraStateRef = useRef({
+ x: initialRotationX,
+ y: initialRotationY,
+ distance: cameraConfig.distance,
+ target: cameraConfig.target,
+ });
useEffect(() => {
if (isUserInteractingRef.current) return;
if (
- prevRotationRef.current?.x === initialRotationX &&
- prevRotationRef.current?.y === initialRotationY
+ prevCameraStateRef.current.x === initialRotationX &&
+ prevCameraStateRef.current.y === initialRotationY &&
+ prevCameraStateRef.current.distance === cameraConfig.distance &&
+ prevCameraStateRef.current.target.every((coordinate, index) => coordinate === cameraConfig.target[index])
) {
return;
}
@@ -362,16 +369,20 @@ export function IPadMiniScene({
if (isUserInteractingRef.current) return;
const orbit = orbitRef.current;
if (!orbit) return;
- const radius = 1.5;
- const phi = Math.PI / 2 - initialRotationX * DEG;
- const theta = initialRotationY * DEG;
- orbit.object.position.setFromSphericalCoords(radius, phi, theta);
+ orbit.object.position.fromArray(
+ getMockupCameraPosition(initialRotationX, initialRotationY, cameraConfig.distance, cameraConfig.target),
+ );
orbit.update();
invalidateRef.current();
- prevRotationRef.current = { x: initialRotationX, y: initialRotationY };
+ prevCameraStateRef.current = {
+ x: initialRotationX,
+ y: initialRotationY,
+ distance: cameraConfig.distance,
+ target: cameraConfig.target,
+ };
}, 0);
return () => clearTimeout(id);
- }, [initialRotationX, initialRotationY, zoom]);
+ }, [initialRotationX, initialRotationY, zoom, cameraConfig.distance, cameraConfig.target]);
useEffect(() => {
if (rootRef.current) {
@@ -457,7 +468,7 @@ export function IPadMiniScene({
}}
onEnd={() => {
isUserInteractingRef.current = false;
- reportMockupCameraChange(orbitRef.current, 1.5, onCameraChange, onRotationChange);
+ reportMockupCameraChange(orbitRef.current, 1.5, onCameraChange, onRotationChange, cameraConfig.fov);
}}
/>
<Environment files={HDRI_FILES[environment as EnvironmentPreset]} environmentIntensity={glow} background={false} />
diff --git a/app/components/ui/editor/mockups-3d/IPhone13ProMax3DViewer.tsx b/app/components/ui/editor/mockups-3d/IPhone13ProMax3DViewer.tsx
index e08b285..1bff1af 100644
--- a/app/components/ui/editor/mockups-3d/IPhone13ProMax3DViewer.tsx
+++ b/app/components/ui/editor/mockups-3d/IPhone13ProMax3DViewer.tsx
@@ -578,7 +578,7 @@ export function IPhone13ProMaxScene({
autoRotate={autoRotate}
autoRotateSpeed={rotationSpeed}
onEnd={() => {
- reportMockupCameraChange(orbitRef.current, 1.5, onCameraChange, onRotationChange);
+ reportMockupCameraChange(orbitRef.current, 1.5, onCameraChange, onRotationChange, cameraConfig.fov);
}}
/>
<ambientLight intensity={0.3} />
@@ -646,6 +646,9 @@ function CanvasWithLoader({
initialRotationY,
initialRotationZ,
onRotationChange,
+ cameraConfig,
+ cameraNavigationMode,
+ onCameraChange,
rootRef,
cameraRef,
zoom,
@@ -668,6 +671,9 @@ function CanvasWithLoader({
initialRotationY: number;
initialRotationZ: number;
onRotationChange?: (rx: number, ry: number) => void;
+ cameraConfig?: MockupCameraConfig;
+ cameraNavigationMode?: CameraNavigationMode;
+ onCameraChange?: (camera: MockupCameraConfig) => void;
rootRef: React.MutableRefObject<THREE.Group | null>;
cameraRef: React.MutableRefObject<THREE.PerspectiveCamera | null>;
zoom: number;
@@ -716,6 +722,9 @@ function CanvasWithLoader({
initialRotationY={initialRotationY}
initialRotationZ={initialRotationZ}
onRotationChange={onRotationChange}
+ cameraConfig={cameraConfig}
+ cameraNavigationMode={cameraNavigationMode}
+ onCameraChange={onCameraChange}
rootRef={rootRef}
cameraRef={cameraRef}
zoom={zoom}
@@ -753,6 +762,9 @@ export function IPhone13ProMax3DViewer({
initialRotationY = -29.82,
initialRotationZ = 0,
onRotationChange,
+ cameraConfig = DEFAULT_MOCKUP_CAMERA,
+ cameraNavigationMode = "orbit",
+ onCameraChange,
onMount,
onApi,
zoom = 1,
@@ -871,6 +883,9 @@ export function IPhone13ProMax3DViewer({
initialRotationY={initialRotationY}
initialRotationZ={initialRotationZ}
onRotationChange={onRotationChange}
+ cameraConfig={cameraConfig}
+ cameraNavigationMode={cameraNavigationMode}
+ onCameraChange={onCameraChange}
rootRef={rootRef}
cameraRef={cameraRef}
zoom={zoom}
diff --git a/app/components/ui/editor/mockups-3d/IPhone17ProMax3DViewer.tsx b/app/components/ui/editor/mockups-3d/IPhone17ProMax3DViewer.tsx
index 53b5530..20bb562 100644
--- a/app/components/ui/editor/mockups-3d/IPhone17ProMax3DViewer.tsx
+++ b/app/components/ui/editor/mockups-3d/IPhone17ProMax3DViewer.tsx
@@ -483,7 +483,7 @@ export function IPhone17ProMaxScene({
autoRotate={autoRotate}
autoRotateSpeed={rotationSpeed}
onEnd={() => {
- reportMockupCameraChange(orbitRef.current, 1.5, onCameraChange, onRotationChange);
+ reportMockupCameraChange(orbitRef.current, 1.5, onCameraChange, onRotationChange, cameraConfig.fov);
}}
/>
<ambientLight intensity={0.3} />
@@ -513,10 +513,11 @@ export function IPhone17ProMaxScene({
function CanvasWithLoader({
imageUrl, imageMaskConfig, cropArea, initialRotationX, initialRotationY, initialRotationZ, onRotationChange,
rootRef, cameraRef, zoom, onApi, onMount, videoElement, shadowIntensity, shadowColor, autoRotate, rotationSpeed,
- glow, environment, isSelected, isHovered,
+ glow, environment, isSelected, isHovered, cameraConfig, cameraNavigationMode, onCameraChange,
}: {
imageUrl: string | null; imageMaskConfig: ImageMaskConfigLike | null; cropArea: { x: number; y: number; width: number; height: number } | null;
initialRotationX: number; initialRotationY: number; initialRotationZ: number; onRotationChange?: (rx: number, ry: number) => void;
+ cameraConfig?: MockupCameraConfig; cameraNavigationMode?: CameraNavigationMode; onCameraChange?: (camera: MockupCameraConfig) => void;
rootRef: React.MutableRefObject<THREE.Group | null>; cameraRef: React.MutableRefObject<THREE.PerspectiveCamera | null>; zoom: number;
onApi?: (api: IPhone17ProMax3DApi | null) => void; onMount?: (canvas: HTMLCanvasElement) => void; videoElement?: HTMLVideoElement | null;
shadowIntensity?: number; shadowColor?: string; autoRotate?: boolean; rotationSpeed?: number; glow?: number; environment?: EnvironmentPreset;
@@ -545,6 +546,7 @@ function CanvasWithLoader({
<IPhone17ProMaxScene
imageUrl={imageUrl} imageMaskConfig={imageMaskConfig} cropArea={cropArea} initialRotationX={initialRotationX}
initialRotationY={initialRotationY} initialRotationZ={initialRotationZ} onRotationChange={onRotationChange}
+ cameraConfig={cameraConfig} cameraNavigationMode={cameraNavigationMode} onCameraChange={onCameraChange}
rootRef={rootRef} cameraRef={cameraRef} zoom={zoom} onApi={onApi} onLoaded={handleLoaded} videoElement={videoElement}
shadowIntensity={shadowIntensity} shadowColor={shadowColor} autoRotate={autoRotate} rotationSpeed={rotationSpeed}
glow={glow} environment={environment} isSelected={isSelected} isHovered={isHovered}
@@ -564,7 +566,7 @@ export function IPhone17ProMax3DViewer({
imageUrl = null, imageMaskConfig = null, cropArea = null, initialRotationX = -58.23, initialRotationY = -29.82,
initialRotationZ = 0, onRotationChange, onMount, onApi, zoom = 1, shadowIntensity = 0, shadowColor = "#000000",
videoElement = null, autoRotate, rotationSpeed, glow, environment, isSelected = false, isHovered = false,
- onHoverChange, onSelectChange,
+ onHoverChange, onSelectChange, cameraConfig = DEFAULT_MOCKUP_CAMERA, cameraNavigationMode = "orbit", onCameraChange,
}: Props) {
const rootRef = useRef<THREE.Group | null>(null);
const cameraRef = useRef<THREE.PerspectiveCamera | null>(null);
@@ -687,6 +689,9 @@ export function IPhone17ProMax3DViewer({
initialRotationY={initialRotationY}
initialRotationZ={initialRotationZ}
onRotationChange={onRotationChange}
+ cameraConfig={cameraConfig}
+ cameraNavigationMode={cameraNavigationMode}
+ onCameraChange={onCameraChange}
rootRef={rootRef}
cameraRef={cameraRef}
zoom={zoom}
diff --git a/app/components/ui/editor/mockups-3d/IPhoneDuo3DViewer.tsx b/app/components/ui/editor/mockups-3d/IPhoneDuo3DViewer.tsx
index 0468bed..8db9d3d 100644
--- a/app/components/ui/editor/mockups-3d/IPhoneDuo3DViewer.tsx
+++ b/app/components/ui/editor/mockups-3d/IPhoneDuo3DViewer.tsx
@@ -227,7 +227,7 @@ export function IPhoneDuoScene({
<OrbitControls ref={orbitRef} {...getCameraNavigationOptions(cameraNavigationMode)} target={cameraConfig.target} enableDamping
autoRotate={autoRotate} autoRotateSpeed={rotationSpeed}
onEnd={() => {
- reportMockupCameraChange(orbitRef.current, CAMERA_RADIUS / zoom, onCameraChange, onRotationChange);
+ reportMockupCameraChange(orbitRef.current, CAMERA_RADIUS / zoom, onCameraChange, onRotationChange, cameraConfig.fov);
}} />
<Environment files={HDRI_FILES[environment]} environmentIntensity={glow} />
<ambientLight intensity={1.5} />
diff --git a/app/components/ui/editor/mockups-3d/Laptop3DViewer.tsx b/app/components/ui/editor/mockups-3d/Laptop3DViewer.tsx
index fd09f0a..1f626cf 100644
--- a/app/components/ui/editor/mockups-3d/Laptop3DViewer.tsx
+++ b/app/components/ui/editor/mockups-3d/Laptop3DViewer.tsx
@@ -594,7 +594,7 @@ export function LaptopScene({
}}
onEnd={() => {
isUserInteractingRef.current = false;
- reportMockupCameraChange(orbitRef.current, CAM_RADIUS / zoom, onCameraChange, onRotationChange);
+ reportMockupCameraChange(orbitRef.current, CAM_RADIUS / zoom, onCameraChange, onRotationChange, cameraConfig.fov);
}}
/>
<Environment files={HDRI_FILES[environment as EnvironmentPreset]} environmentIntensity={glow} background={false} />
diff --git a/app/components/ui/editor/mockups-3d/Phone3DViewer.tsx b/app/components/ui/editor/mockups-3d/Phone3DViewer.tsx
index 58a44fd..99f6dda 100644
--- a/app/components/ui/editor/mockups-3d/Phone3DViewer.tsx
+++ b/app/components/ui/editor/mockups-3d/Phone3DViewer.tsx
@@ -586,14 +586,21 @@ export function Phone3DScene({
};
}, [modelUrl, onLoaded]);
- const prevRotationRef = useRef<{ x: number; y: number } | null>({ x: initialRotationX, y: initialRotationY });
+ const prevCameraStateRef = useRef({
+ x: initialRotationX,
+ y: initialRotationY,
+ distance: cameraConfig.distance,
+ target: cameraConfig.target,
+ });
useEffect(() => {
if (isUserInteractingRef.current) return;
if (
- prevRotationRef.current?.x === initialRotationX &&
- prevRotationRef.current?.y === initialRotationY
+ prevCameraStateRef.current.x === initialRotationX &&
+ prevCameraStateRef.current.y === initialRotationY &&
+ prevCameraStateRef.current.distance === cameraConfig.distance &&
+ prevCameraStateRef.current.target.every((coordinate, index) => coordinate === cameraConfig.target[index])
) {
return;
}
@@ -601,16 +608,20 @@ export function Phone3DScene({
if (isUserInteractingRef.current) return;
const orbit = orbitRef.current;
if (!orbit) return;
- const radius = 1.5;
- const phi = Math.PI / 2 - initialRotationX * DEG;
- const theta = initialRotationY * DEG;
- orbit.object.position.setFromSphericalCoords(radius, phi, theta);
+ orbit.object.position.fromArray(
+ getMockupCameraPosition(initialRotationX, initialRotationY, cameraConfig.distance, cameraConfig.target),
+ );
orbit.update();
invalidateRef.current();
- prevRotationRef.current = { x: initialRotationX, y: initialRotationY };
+ prevCameraStateRef.current = {
+ x: initialRotationX,
+ y: initialRotationY,
+ distance: cameraConfig.distance,
+ target: cameraConfig.target,
+ };
}, 0);
return () => clearTimeout(id);
- }, [initialRotationX, initialRotationY]);
+ }, [initialRotationX, initialRotationY, cameraConfig.distance, cameraConfig.target]);
useEffect(() => {
if (rootRef.current) {
@@ -691,7 +702,7 @@ export function Phone3DScene({
}}
onEnd={() => {
isUserInteractingRef.current = false;
- reportMockupCameraChange(orbitRef.current, 1.5, onCameraChange, onRotationChange);
+ reportMockupCameraChange(orbitRef.current, 1.5, onCameraChange, onRotationChange, cameraConfig.fov);
}}
/>
<Environment files={HDRI_FILES[environment as EnvironmentPreset]} environmentIntensity={glow} background={false} />
diff --git a/components/ui/TickSliderControl.tsx b/components/ui/TickSliderControl.tsx
index a41f014..d13747c 100644
--- a/components/ui/TickSliderControl.tsx
+++ b/components/ui/TickSliderControl.tsx
@@ -29,6 +29,7 @@ export function TickSliderControl({
onChange,
onChangeEnd,
}: TickSliderControlProps) {
+ const [isHelperOpen, setIsHelperOpen] = useState(false);
const [isDragging, setIsDragging] = useState(false);
const formatValue = useCallback((val: number) => {
@@ -139,16 +140,20 @@ export function TickSliderControl({
{label}
</span>
{helperText && (
- <span
- className="text-muted-foreground/70"
- title={helperText}
+ <button
+ type="button"
aria-label={helperText}
- role="img"
+ aria-expanded={isHelperOpen}
+ onClick={() => setIsHelperOpen((open) => !open)}
+ className="inline-flex shrink-0 items-center gap-1 text-[10px] text-muted-foreground/80 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-sm"
>
<Icon icon="mdi:export-variant" width="14" aria-hidden="true" />
- </span>
+ </button>
)}
</div>
+ {helperText && isHelperOpen && (
+ <p className="text-[10px] leading-tight text-muted-foreground">{helperText}</p>
+ )}
<div className="flex items-center gap-6">
<div
diff --git a/lib/viewer-controls3d.ts b/lib/viewer-controls3d.ts
index 80946fb..6f679cd 100644
--- a/lib/viewer-controls3d.ts
+++ b/lib/viewer-controls3d.ts
@@ -83,17 +83,17 @@ export function reportMockupCameraChange(
baseRadius: number,
onCameraChange?: (camera: MockupCameraConfig) => void,
onRotationChange?: (rotX: number, rotY: number) => void,
+ configuredFov: number | null = null,
): void {
if (!controls || !Number.isFinite(baseRadius) || baseRadius <= 0) return;
- const camera = controls.object;
- const distance = camera.position.distanceTo(controls.target) / baseRadius;
+ const distance = controls.object.position.distanceTo(controls.target) / baseRadius;
if (!Number.isFinite(distance) || ![controls.target.x, controls.target.y, controls.target.z].every(Number.isFinite)) return;
onCameraChange?.({
target: normalizeMockupCameraConfig({ target: [controls.target.x, controls.target.y, controls.target.z] }).target,
distance: Math.max(0.25, Math.min(4, distance)),
- fov: "fov" in camera && typeof camera.fov === "number" && Number.isFinite(camera.fov)
- ? Math.max(20, Math.min(80, camera.fov))
+ fov: typeof configuredFov === "number" && Number.isFinite(configuredFov)
+ ? Math.max(20, Math.min(80, configuredFov))
: null,
});
onRotationChange?.(