Skip to content

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

feat: add 3D mockup camera controls

Efrain Chiri Ninad6bbb5306809
diff --git a/app/[locale]/(editor)/editor/page.tsx b/app/[locale]/(editor)/editor/page.tsx
index 397f687..f2e4085 100644
--- a/app/[locale]/(editor)/editor/page.tsx
+++ b/app/[locale]/(editor)/editor/page.tsx
@@ -31,6 +31,7 @@ import { DEFAULT_CAMERA_CONFIG } from "@/types/camera.types";
import type { Preview3DConfig, ImageMaskConfig } from "@/types/photo.types";
import { DEFAULT_MASK_CONFIG, PREVIEW_CONFIGS } from "@/types/photo.types";
import { MOCKUPS } from "@/lib/mockup-data";
+import { normalizeMockupCameraConfig } from "@/lib/viewer-controls3d";
import { gradientToCss, generateDefaultZoomFragments } from "@/types";
import { ToolsSidebar } from "@/app/components/ui/editor/ToolsSidebar";
import { MobileToolsMenu } from "@/app/components/ui/editor/MobileToolsMenu";
@@ -79,6 +80,7 @@ export default function Editor() {
imagePhoneRotY, setImagePhoneRotY,
imagePhoneRotZ, setImagePhoneRotZ,
imagePhonePerspective, setImagePhonePerspective,
+ mockupCamera, setMockupCamera,
imagePhoneDevice, setImagePhoneDevice,
imagePhonePresetId, setImagePhonePresetId,
imagePhoneOpening, setImagePhoneOpening,
@@ -373,11 +375,12 @@ export default function Editor() {
imagePreview3D: imageTransform,
apply3DToBackground,
imageMaskConfig,
+ mockupCamera,
}), [
backgroundTab, selectedWallpaper, backgroundBlur, selectedImageUrl,
backgroundColorConfig, padding, roundedCorners, shadows, aspectRatio,
customDimensions, cropArea, mockupId, mockupConfig, canvasElements,
- videoTransform, imageTransform, apply3DToBackground, imageMaskConfig,
+ videoTransform, imageTransform, apply3DToBackground, imageMaskConfig, mockupCamera,
]);
const autoSaveCurrentProject = useCallback(async () => {
@@ -386,12 +389,12 @@ export default function Editor() {
if (autoSaveTimeoutRef.current) clearTimeout(autoSaveTimeoutRef.current);
autoSaveTimeoutRef.current = setTimeout(async () => {
try {
- await saveCurrentProject({ ...buildPhotoProjectSnapshot(), imageZoomScale, imagePhoneActive });
+ await saveCurrentProject({ ...buildPhotoProjectSnapshot(), imageZoomScale, imagePhoneActive, mockupCamera });
} catch (error) {
console.error("Auto-save failed:", error);
}
}, 3000);
- }, [isPhotoMode, imageUrl, currentProject, saveCurrentProject, buildPhotoProjectSnapshot, imageZoomScale, imagePhoneActive]);
+ }, [isPhotoMode, imageUrl, currentProject, saveCurrentProject, buildPhotoProjectSnapshot, imageZoomScale, imagePhoneActive, mockupCamera]);
const currentProjectId = currentProject?.id ?? null;
const autoSaveRef = useRef(autoSaveCurrentProject);
@@ -444,6 +447,7 @@ export default function Editor() {
setApply3DToBackground(currentProject.apply3DToBackground);
setImageMaskConfig(currentProject.imageMaskConfig);
setImageZoomScale(currentProject.imageZoomScale ?? 1);
+ setMockupCamera(normalizeMockupCameraConfig(currentProject.mockupCamera));
setImageDimensions({
width: currentProject.imageWidth,
height: currentProject.imageHeight,
@@ -675,6 +679,7 @@ export default function Editor() {
imagePhoneShadow,
imagePhoneShadowColor,
imagePhoneRefWidth,
+ mockupCamera,
mockupMotionFragments,
videoClips,
globalSpeed,
@@ -692,6 +697,7 @@ export default function Editor() {
imagePhoneActive, imagePhoneX, imagePhoneY, imagePhoneScale, imagePhoneRotX, imagePhoneRotY,
imagePhoneRotZ, imagePhonePerspective, imagePhoneDevice, imagePhonePresetId, imagePhoneOpening,
imagePhoneShadow, imagePhoneShadowColor, imagePhoneRefWidth, mockupMotionFragments,
+ mockupCamera,
setEditorState, videoClips, globalSpeed
]);
@@ -744,6 +750,7 @@ export default function Editor() {
setImagePhoneShadow(editorState.imagePhoneShadow);
setImagePhoneShadowColor(editorState.imagePhoneShadowColor);
setImagePhoneRefWidth(editorState.imagePhoneRefWidth ?? 0);
+ setMockupCamera(normalizeMockupCameraConfig(editorState.mockupCamera));
setMockupMotionFragments(editorState.mockupMotionFragments ?? []);
setGlobalSpeed(editorState.globalSpeed ?? 1);
@@ -972,6 +979,7 @@ export default function Editor() {
canvasElements,
mockupId,
mockupConfig,
+ mockupCamera,
mockupMotionFragments,
backgroundTab,
selectedWallpaper,
@@ -1000,7 +1008,7 @@ export default function Editor() {
zoomFragments, zoomMovements,
audioTracks, uploadedAudios, muteOriginalAudio, masterVolume,
canvasElements,
- mockupId, mockupConfig,
+ mockupId, mockupConfig, mockupCamera,
mockupMotionFragments,
backgroundTab, selectedWallpaper, backgroundBlur, selectedImageUrl,
unsplashBgUrl, backgroundColorConfig,
@@ -1752,6 +1760,7 @@ export default function Editor() {
setZoomMovements(savedProject.zoomMovements ?? []);
setMockupId(savedProject.mockupId);
setMockupConfig(savedProject.mockupConfig);
+ setMockupCamera(normalizeMockupCameraConfig(savedProject.mockupCamera));
setCanvasElements(savedProject.canvasElements ?? []);
setAudioTracks(savedProject.audioTracks ?? []);
setMuteOriginalAudio(savedProject.muteOriginalAudio ?? false);
diff --git a/app/components/ui/editor/ControlPanel.tsx b/app/components/ui/editor/ControlPanel.tsx
index 79c9082..aad6fc7 100644
--- a/app/components/ui/editor/ControlPanel.tsx
+++ b/app/components/ui/editor/ControlPanel.tsx
@@ -142,9 +142,7 @@ export function ControlPanel({
const hasMockup2D = mediaType === "video" && !imagePhoneActive;
const hasMockup3D = imagePhoneActive;
- const [isDark, setIsDark] = useState(
- () => typeof window !== "undefined" && document.documentElement.classList.contains("dark")
- );
+ const [isDark, setIsDark] = useState(false);
useEffect(() => {
const html = document.documentElement;
diff --git a/app/components/ui/editor/Mockup3dMenu.tsx b/app/components/ui/editor/Mockup3dMenu.tsx
index 898476a..6c91303 100644
--- a/app/components/ui/editor/Mockup3dMenu.tsx
+++ b/app/components/ui/editor/Mockup3dMenu.tsx
@@ -9,6 +9,7 @@ import { Button } from "@/components/ui/button";
import { DetailPageHeader } from "@/components/ui/DetailHeaderMenu";
import { Position3DPresetsEditor } from "@/components/ui/Position3DPresetsEditor";
import { ENVIRONMENT_OPTIONS, type EnvironmentPreset } from "@/lib/viewer-controls3d";
+import type { CameraNavigationMode, MockupCameraConfig } from "@/lib/viewer-controls3d";
import {
Select,
SelectContent,
@@ -189,6 +190,10 @@ export interface Mockup3dMenuProps {
setViewer3DGlow: (v: number) => void;
viewer3DEnvironment: EnvironmentPreset;
setViewer3DEnvironment: (v: EnvironmentPreset) => void;
+ mockupCamera: MockupCameraConfig;
+ setMockupCamera: (v: MockupCameraConfig) => void;
+ cameraNavigationMode: CameraNavigationMode;
+ setCameraNavigationMode: (v: CameraNavigationMode) => void;
}
export function Mockup3dMenu({
@@ -227,6 +232,10 @@ export function Mockup3dMenu({
setViewer3DGlow,
viewer3DEnvironment,
setViewer3DEnvironment,
+ mockupCamera,
+ setMockupCamera,
+ cameraNavigationMode,
+ setCameraNavigationMode,
}: Mockup3dMenuProps) {
const t = useTranslations("mockupMenu");
@@ -238,6 +247,7 @@ export function Mockup3dMenu({
const defaultRotY = imagePhoneDevice === "laptop" ? -37.82 : -29.82;
setImagePhoneRotX(defaultRotX);
setImagePhoneRotY(defaultRotY);
+ setCameraNavigationMode("orbit");
setImagePhoneRotZ(0);
if (imagePhoneDevice === "iphone-duo") {
@@ -259,6 +269,7 @@ export function Mockup3dMenu({
}
setImagePhoneShadowColor("#000000");
setImagePhonePresetId("custom");
+ setMockupCamera({ target: [0, 0, 0], distance: 1, fov: null });
}, [
imagePhoneDevice,
setImagePhoneX,
@@ -271,6 +282,8 @@ export function Mockup3dMenu({
setImagePhoneShadow,
setImagePhoneShadowColor,
setImagePhonePresetId,
+ setMockupCamera,
+ setCameraNavigationMode,
]);
return (
@@ -352,6 +365,105 @@ export function Mockup3dMenu({
/>
</div>
+ <section className="flex flex-col gap-3 pt-4 border-t border-border" aria-labelledby="camera-controls-title">
+ <div className="flex items-center gap-2">
+ <span className="flex size-8 shrink-0 items-center justify-center rounded-lg border border-primary/20 bg-primary/10 text-primary">
+ <Icon icon="mdi:camera" width="17" aria-hidden="true" />
+ </span>
+ <div className="min-w-0">
+ <h3 id="camera-controls-title" className="text-[11px] font-bold text-foreground uppercase tracking-wider">
+ {t("cameraControls")}
+ </h3>
+ </div>
+ </div>
+
+ <div className="grid grid-cols-3 gap-1" role="group" aria-label={t("cameraControls")}>
+ {([
+ ["orbit", "mdi:orbit-variant", "orbit"],
+ ["trackXY", "mdi:move", "trackXY"],
+ ["trackZ", "mdi:arrow-expand-vertical", "trackZ"],
+ ] as const).map(([mode, icon, label]) => (
+ <button
+ key={mode}
+ type="button"
+ onClick={() => setCameraNavigationMode(mode)}
+ aria-pressed={cameraNavigationMode === mode}
+ aria-label={t(label)}
+ title={`${t(label)}: ${t(mode === "orbit" ? "orbitHint" : mode === "trackXY" ? "trackXYHint" : "trackZHint")}`}
+ className={`relative flex h-10 min-w-0 items-center justify-center gap-1.5 rounded-lg border px-2 text-[10px] font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-background ${
+ cameraNavigationMode === mode
+ ? "border-primary/50 bg-primary/10 text-primary"
+ : "border-border bg-muted/40 text-muted-foreground hover:border-muted-foreground/40 hover:bg-muted hover:text-foreground"
+ }`}
+ >
+ <Icon icon={icon} width="15" aria-hidden="true" />
+ <span className="leading-tight">{mode === "trackXY" ? "XY" : mode === "trackZ" ? "Z" : t(label)}</span>
+ {cameraNavigationMode === mode && (
+ <Icon
+ icon="lucide:check"
+ width="11"
+ className="absolute right-1 top-1"
+ aria-hidden="true"
+ />
+ )}
+ </button>
+ ))}
+ </div>
+
+ <div className="space-y-2 border-t border-border/70 pt-2.5">
+ <h4 className="flex items-center gap-1.5 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground">
+ <Icon icon="mdi:camera-metering-center" width="13" aria-hidden="true" />
+ {t("cameraFraming")}
+ </h4>
+ <SliderControl
+ icon="mdi:arrow-expand-vertical"
+ label={t("dolly")}
+ value={Math.round(mockupCamera.distance * 100)}
+ min={25}
+ max={400}
+ step={1}
+ onChange={(value) => setMockupCamera({ ...mockupCamera, distance: value / 100 })}
+ suffix="%"
+ />
+ <SliderControl
+ icon="mdi:camera-metering-center"
+ label={t("fieldOfView")}
+ value={mockupCamera.fov ?? (imagePhoneDevice === "iphone-duo" ? 30 : 40)}
+ min={20}
+ max={80}
+ step={1}
+ onChange={(fov) => setMockupCamera({ ...mockupCamera, fov })}
+ suffix="°"
+ />
+ </div>
+
+ <div className="space-y-2 border-t border-border/70 pt-2.5">
+ <h4 className="flex items-center gap-1.5 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground">
+ <Icon icon="mdi:crosshairs-gps" width="13" aria-hidden="true" />
+ {t("cameraTarget")}
+ </h4>
+ {(["X", "Y", "Z"] as const).map((axis, index) => {
+ const targetRange = imagePhoneDevice === "laptop" ? 100 : imagePhoneDevice === "iphone-duo" ? 5 : 1;
+ return (
+ <SliderControl
+ key={axis}
+ icon="mdi:crosshairs-gps"
+ label={`${t("target")} ${axis}`}
+ value={Math.round((mockupCamera.target[index] / targetRange) * 100)}
+ min={-100}
+ max={100}
+ step={1}
+ onChange={(value) => {
+ const target = [...mockupCamera.target] as [number, number, number];
+ target[index] = (value / 100) * targetRange;
+ setMockupCamera({ ...mockupCamera, target });
+ }}
+ />
+ );
+ })}
+ </div>
+ </section>
+
<div className="flex flex-col gap-3 pt-4 border-t border-border">
<span className="text-[10px] font-bold text-muted-foreground/60 uppercase tracking-wider">
{t("modelProperties") || "Propiedades del Modelo"}
diff --git a/app/components/ui/editor/MockupMenu.tsx b/app/components/ui/editor/MockupMenu.tsx
index 2e4c43b..9926185 100644
--- a/app/components/ui/editor/MockupMenu.tsx
+++ b/app/components/ui/editor/MockupMenu.tsx
@@ -74,6 +74,8 @@ export function MockupMenu({
imagePhoneOpening, setImagePhoneOpening,
imagePhoneShadow, setImagePhoneShadow,
imagePhoneShadowColor,
+ mockupCamera, setMockupCamera,
+ cameraNavigationMode, setCameraNavigationMode,
imagePhonePresetId, setImagePhonePresetId,
setImagePhoneShadowColor,
viewer3DAutoRotate, setViewer3DAutoRotate,
@@ -295,6 +297,10 @@ export function MockupMenu({
onRemove={handleRemoveAll}
imagePhoneRotX={imagePhoneRotX}
imagePhoneRotY={imagePhoneRotY}
+ mockupCamera={mockupCamera}
+ setMockupCamera={setMockupCamera}
+ cameraNavigationMode={cameraNavigationMode}
+ setCameraNavigationMode={setCameraNavigationMode}
imagePhoneRotZ={imagePhoneRotZ}
setImagePhoneRotZ={setImagePhoneRotZ}
imagePhonePresetId={imagePhonePresetId}
diff --git a/app/components/ui/editor/VideoCanvas.tsx b/app/components/ui/editor/VideoCanvas.tsx
index 34cf517..3ebbdcf 100644
--- a/app/components/ui/editor/VideoCanvas.tsx
+++ b/app/components/ui/editor/VideoCanvas.tsx
@@ -135,6 +135,7 @@ function VideoCanvasInner({
imagePhoneShadow, imagePhoneShadowColor,
imagePhoneRefWidth, setImagePhoneRefWidth,
viewer3DAutoRotate, viewer3DRotationSpeed, viewer3DGlow, viewer3DEnvironment,
+ mockupCamera, setMockupCamera, cameraNavigationMode,
} = useMockup3dContext();
// 3D phone overlay is active in both video and image mode
@@ -2557,6 +2558,9 @@ function VideoCanvasInner({
initialRotationY={imagePhoneRotY}
initialRotationZ={imagePhoneRotZ}
onRotationChange={handlePhoneRotationChange}
+ cameraConfig={mockupCamera}
+ cameraNavigationMode={cameraNavigationMode}
+ onCameraChange={setMockupCamera}
onMount={handlePhoneMount}
onApi={handlePhoneApi}
zoom={1}
diff --git a/app/components/ui/editor/VideosMenu.tsx b/app/components/ui/editor/VideosMenu.tsx
index 5d3d55e..b22a6b9 100644
--- a/app/components/ui/editor/VideosMenu.tsx
+++ b/app/components/ui/editor/VideosMenu.tsx
@@ -185,9 +185,11 @@ export function VideosMenu({
<span>{t("title")}</span>
</div>
- <div className="bg-muted border border-border squircle-element p-3 shrink-0 mb-1">
+ <div className="bg-muted/70 border border-border squircle-element p-3 shrink-0 mb-1 space-y-2">
<TickSliderControl
label={t("speed")}
+ helperText={t("speedExport")}
+ icon="solar:play-speed-bold"
value={globalSpeed}
min={0.5}
max={3}
@@ -196,6 +198,24 @@ export function VideosMenu({
suffix="x"
onChange={(val) => onGlobalSpeedChange?.(val)}
/>
+ <div className="flex items-center justify-end gap-1.5" role="group" aria-label={t("speedPresets")}>
+ {[1, 1.5, 2, 3].map((speed) => (
+ <button
+ key={speed}
+ type="button"
+ onClick={() => onGlobalSpeedChange?.(speed)}
+ aria-label={`${speed}x ${t("speed")}`}
+ aria-pressed={Math.abs(globalSpeed - speed) < 0.001}
+ className={`rounded-md border px-2 py-1 text-[10px] font-mono transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary ${
+ Math.abs(globalSpeed - speed) < 0.001
+ ? "border-primary/40 bg-primary/10 text-primary"
+ : "border-border bg-background/60 text-muted-foreground hover:bg-background hover:text-foreground"
+ }`}
+ >
+ {speed}x
+ </button>
+ ))}
+ </div>
</div>
<div className="flex-1 overflow-y-auto custom-scrollbar -mx-1 px-1">
diff --git a/app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsx b/app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsx
index 27b14ec..3598508 100644
--- a/app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsx
+++ b/app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsx
@@ -14,7 +14,16 @@ import {
applyTextureCover
} from "@/lib/phone3d.utils";
import type { OrbitControls as OrbitControlsType } from 'three-stdlib';
-import { EnvironmentPreset, HDRI_FILES, sphericalCameraPos } from "@/lib/viewer-controls3d";
+import {
+ DEFAULT_MOCKUP_CAMERA,
+ EnvironmentPreset,
+ HDRI_FILES,
+ type CameraNavigationMode,
+ type MockupCameraConfig,
+ getCameraNavigationOptions,
+ getMockupCameraPosition,
+ reportMockupCameraChange,
+} from "@/lib/viewer-controls3d";
import { GetMediaMaskStyles } from "@/lib/media-mask.utils";
import { EffectComposer } from "three/examples/jsm/postprocessing/EffectComposer.js";
@@ -39,6 +48,9 @@ interface Props {
initialRotationY?: number;
initialRotationZ?: number;
onRotationChange?: (rx: number, ry: number) => void;
+ cameraConfig?: MockupCameraConfig;
+ cameraNavigationMode?: CameraNavigationMode;
+ onCameraChange?: (camera: MockupCameraConfig) => void;
onMount?: (canvas: HTMLCanvasElement) => void;
onApi?: (api: DoubleIPhone3DApi | null) => void;
zoom?: number;
@@ -70,6 +82,9 @@ export function DoubleIPhoneScene({
initialRotationY = -29,
initialRotationZ = 0,
onRotationChange,
+ cameraConfig = DEFAULT_MOCKUP_CAMERA,
+ cameraNavigationMode = "orbit",
+ onCameraChange,
rootRef,
cameraRef,
zoom = 1,
@@ -463,11 +478,11 @@ export function DoubleIPhoneScene({
return (
<>
- <PerspectiveCamera ref={cameraRef} makeDefault fov={40} near={0.01} far={100} position={sphericalCameraPos(initialRotationX, initialRotationY)} zoom={zoom} />
+ <PerspectiveCamera ref={cameraRef} makeDefault fov={cameraConfig.fov ?? 40} near={0.01} far={100} position={getMockupCameraPosition(initialRotationX, initialRotationY, cameraConfig.distance, cameraConfig.target)} zoom={zoom} />
<OrbitControls
ref={orbitRef}
- enableZoom={false}
- enablePan={false}
+ {...getCameraNavigationOptions(cameraNavigationMode)}
+ target={cameraConfig.target}
enableDamping
dampingFactor={0.08}
autoRotate={autoRotate}
@@ -478,14 +493,13 @@ export function DoubleIPhoneScene({
onEnd={() => {
isUserInteractingRef.current = false;
const orbit = orbitRef.current;
- if (!orbit || !onRotationChange) return;
-
- const ry = orbit.getAzimuthalAngle() * (180 / Math.PI);
- const rx = (Math.PI / 2 - orbit.getPolarAngle()) * (180 / Math.PI);
-
- prevRotationRef.current = { x: rx, y: ry };
-
- onRotationChange(rx, ry);
+ if (orbit) {
+ prevRotationRef.current = {
+ x: 90 - orbit.getPolarAngle() * (180 / Math.PI),
+ y: orbit.getAzimuthalAngle() * (180 / Math.PI),
+ };
+ }
+ reportMockupCameraChange(orbitRef.current, 1.5, onCameraChange, onRotationChange);
}}
/>
<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 b0898a7..8d0587e 100644
--- a/app/components/ui/editor/mockups-3d/IPadMini63DViewer.tsx
+++ b/app/components/ui/editor/mockups-3d/IPadMini63DViewer.tsx
@@ -12,7 +12,16 @@ import {
applyTextureCover
} from "@/lib/phone3d.utils";
import type { OrbitControls as OrbitControlsType } from 'three-stdlib';
-import { EnvironmentPreset, HDRI_FILES, sphericalCameraPos } from "@/lib/viewer-controls3d";
+import {
+ DEFAULT_MOCKUP_CAMERA,
+ EnvironmentPreset,
+ HDRI_FILES,
+ type CameraNavigationMode,
+ type MockupCameraConfig,
+ getCameraNavigationOptions,
+ getMockupCameraPosition,
+ reportMockupCameraChange,
+} from "@/lib/viewer-controls3d";
import { GetMediaMaskStyles } from "@/lib/media-mask.utils";
import { EffectComposer } from "three/examples/jsm/postprocessing/EffectComposer.js";
@@ -34,6 +43,9 @@ interface Props {
initialRotationY?: number;
initialRotationZ?: number;
onRotationChange?: (rx: number, ry: number) => void;
+ cameraConfig?: MockupCameraConfig;
+ cameraNavigationMode?: CameraNavigationMode;
+ onCameraChange?: (camera: MockupCameraConfig) => void;
onMount?: (canvas: HTMLCanvasElement) => void;
onApi?: (api: IPadMini63DApi | null) => void;
zoom?: number;
@@ -60,7 +72,7 @@ const TARGET_H = 1500;
useGLTF.preload(MODEL_URL, DRACO_URL);
export function IPadMiniScene({
- imageUrl, imageMaskConfig, cropArea, initialRotationX = -58.23, initialRotationY = -29.82, initialRotationZ = 0, onRotationChange, rootRef, cameraRef, zoom = 1, onApi, onLoaded, videoElement, shadowIntensity = 0, shadowColor = "#000000", autoRotate = false, rotationSpeed = 3.5, glow = 1.0, environment = "studio", isSelected = false, isHovered = false,
+ imageUrl, imageMaskConfig, cropArea, initialRotationX = -58.23, initialRotationY = -29.82, initialRotationZ = 0, onRotationChange, cameraConfig = DEFAULT_MOCKUP_CAMERA, cameraNavigationMode = "orbit", onCameraChange, rootRef, cameraRef, zoom = 1, onApi, onLoaded, videoElement, shadowIntensity = 0, shadowColor = "#000000", autoRotate = false, rotationSpeed = 3.5, glow = 1.0, environment = "studio", isSelected = false, isHovered = false,
}: Props & { rootRef: React.MutableRefObject<THREE.Group | null>; cameraRef: React.MutableRefObject<THREE.PerspectiveCamera | null>; onLoaded?: () => void; }) {
const { gl, scene, camera, invalidate, size } = useThree();
const gltf = useGLTF(MODEL_URL, DRACO_URL);
@@ -431,11 +443,11 @@ export function IPadMiniScene({
return (
<>
- <PerspectiveCamera ref={cameraRef} makeDefault fov={40} near={0.01} far={100} position={sphericalCameraPos(initialRotationX, initialRotationY)} zoom={zoom} />
+ <PerspectiveCamera ref={cameraRef} makeDefault fov={cameraConfig.fov ?? 40} near={0.01} far={100} position={getMockupCameraPosition(initialRotationX, initialRotationY, cameraConfig.distance, cameraConfig.target)} zoom={zoom} />
<OrbitControls
ref={orbitRef}
- enableZoom={false}
- enablePan={false}
+ {...getCameraNavigationOptions(cameraNavigationMode)}
+ target={cameraConfig.target}
enableDamping
dampingFactor={0.08}
autoRotate={autoRotate}
@@ -445,11 +457,7 @@ export function IPadMiniScene({
}}
onEnd={() => {
isUserInteractingRef.current = false;
- const orbit = orbitRef.current;
- if (!orbit || !onRotationChange) return;
- const ry = orbit.getAzimuthalAngle() * (180 / Math.PI);
- const rx = (Math.PI / 2 - orbit.getPolarAngle()) * (180 / Math.PI);
- onRotationChange(rx, ry);
+ reportMockupCameraChange(orbitRef.current, 1.5, onCameraChange, onRotationChange);
}}
/>
<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 1453431..e08b285 100644
--- a/app/components/ui/editor/mockups-3d/IPhone13ProMax3DViewer.tsx
+++ b/app/components/ui/editor/mockups-3d/IPhone13ProMax3DViewer.tsx
@@ -6,7 +6,16 @@ import { useEffect, useRef, useState, Suspense, useLayoutEffect, useMemo } from
import * as THREE from "three";
import { createCoverScreenCanvas, applyCropToImage, type ImageMaskConfigLike, applyTextureCover } from "@/lib/phone3d.utils";
import type { OrbitControls as OrbitControlsType } from 'three-stdlib';
-import { EnvironmentPreset, HDRI_FILES, sphericalCameraPos } from "@/lib/viewer-controls3d";
+import {
+ DEFAULT_MOCKUP_CAMERA,
+ EnvironmentPreset,
+ HDRI_FILES,
+ type CameraNavigationMode,
+ type MockupCameraConfig,
+ getCameraNavigationOptions,
+ getMockupCameraPosition,
+ reportMockupCameraChange,
+} from "@/lib/viewer-controls3d";
import { GetMediaMaskStyles } from "@/lib/media-mask.utils";
import { EffectComposer } from "three/examples/jsm/postprocessing/EffectComposer.js";
import { RenderPass } from "three/examples/jsm/postprocessing/RenderPass.js";
@@ -28,6 +37,9 @@ interface Props {
initialRotationY?: number;
initialRotationZ?: number;
onRotationChange?: (rx: number, ry: number) => void;
+ cameraConfig?: MockupCameraConfig;
+ cameraNavigationMode?: CameraNavigationMode;
+ onCameraChange?: (camera: MockupCameraConfig) => void;
onMount?: (canvas: HTMLCanvasElement) => void;
onApi?: (api: IPhone13ProMax3DApi | null) => void;
scale?: number;
@@ -115,6 +127,9 @@ export function IPhone13ProMaxScene({
initialRotationY = -29.82,
initialRotationZ = 0,
onRotationChange,
+ cameraConfig = DEFAULT_MOCKUP_CAMERA,
+ cameraNavigationMode = "orbit",
+ onCameraChange,
rootRef,
cameraRef,
zoom = 1,
@@ -137,6 +152,9 @@ export function IPhone13ProMaxScene({
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;
@@ -399,17 +417,14 @@ export function IPhone13ProMaxScene({
const id = setTimeout(() => {
const orbit = orbitRef.current;
if (!orbit) return;
- const DEG = Math.PI / 180;
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, radius));
orbit.update();
invalidateRef.current();
prevRotationRef.current = { x: initialRotationX, y: initialRotationY };
}, 0);
return () => clearTimeout(id);
- }, [initialRotationX, initialRotationY, zoom]);
+ }, [initialRotationX, initialRotationY, zoom, cameraConfig.distance, cameraConfig.target]);
useEffect(() => {
const root = rootRef.current;
@@ -552,22 +567,18 @@ export function IPhone13ProMaxScene({
}, 1);
return (
<>
- <PerspectiveCamera ref={cameraRef} makeDefault fov={40} near={0.01} far={100} position={sphericalCameraPos(initialRotationX, initialRotationY)} zoom={zoom} />
+ <PerspectiveCamera ref={cameraRef} makeDefault fov={cameraConfig.fov ?? 40} near={0.01} far={100} position={getMockupCameraPosition(initialRotationX, initialRotationY, cameraConfig.distance, cameraConfig.target)} zoom={zoom} />
<Environment files={HDRI_FILES[environment as EnvironmentPreset]} environmentIntensity={glow} background={false} />
<OrbitControls
ref={orbitRef}
- enableZoom={false}
- enablePan={false}
+ {...getCameraNavigationOptions(cameraNavigationMode)}
+ target={cameraConfig.target}
enableDamping
dampingFactor={0.08}
autoRotate={autoRotate}
autoRotateSpeed={rotationSpeed}
onEnd={() => {
- const orbit = orbitRef.current;
- if (!orbit || !onRotationChange) return;
- const ry = orbit.getAzimuthalAngle() * (180 / Math.PI);
- const rx = (Math.PI / 2 - orbit.getPolarAngle()) * (180 / Math.PI);
- onRotationChange(rx, ry);
+ reportMockupCameraChange(orbitRef.current, 1.5, onCameraChange, onRotationChange);
}}
/>
<ambientLight intensity={0.3} />
diff --git a/app/components/ui/editor/mockups-3d/IPhone17ProMax3DViewer.tsx b/app/components/ui/editor/mockups-3d/IPhone17ProMax3DViewer.tsx
index 13f2b0c..53b5530 100644
--- a/app/components/ui/editor/mockups-3d/IPhone17ProMax3DViewer.tsx
+++ b/app/components/ui/editor/mockups-3d/IPhone17ProMax3DViewer.tsx
@@ -6,7 +6,16 @@ import { useEffect, useRef, useState, Suspense, useLayoutEffect, useMemo, useCal
import * as THREE from "three";
import { createCoverScreenCanvas, applyCropToImage, parseShadowColor, type ImageMaskConfigLike, applyTextureCover } from "@/lib/phone3d.utils";
import type { OrbitControls as OrbitControlsType } from 'three-stdlib';
-import { EnvironmentPreset, HDRI_FILES, sphericalCameraPos } from "@/lib/viewer-controls3d";
+import {
+ DEFAULT_MOCKUP_CAMERA,
+ EnvironmentPreset,
+ HDRI_FILES,
+ type CameraNavigationMode,
+ type MockupCameraConfig,
+ getCameraNavigationOptions,
+ getMockupCameraPosition,
+ reportMockupCameraChange,
+} from "@/lib/viewer-controls3d";
import { GetMediaMaskStyles } from "@/lib/media-mask.utils";
import { EffectComposer } from "three/examples/jsm/postprocessing/EffectComposer.js";
import { RenderPass } from "three/examples/jsm/postprocessing/RenderPass.js";
@@ -28,6 +37,9 @@ interface Props {
initialRotationY?: number;
initialRotationZ?: number;
onRotationChange?: (rx: number, ry: number) => void;
+ cameraConfig?: MockupCameraConfig;
+ cameraNavigationMode?: CameraNavigationMode;
+ onCameraChange?: (camera: MockupCameraConfig) => void;
onMount?: (canvas: HTMLCanvasElement) => void;
onApi?: (api: IPhone17ProMax3DApi | null) => void;
scale?: number;
@@ -60,6 +72,9 @@ export function IPhone17ProMaxScene({
initialRotationY = -29.82,
initialRotationZ = 0,
onRotationChange,
+ cameraConfig = DEFAULT_MOCKUP_CAMERA,
+ cameraNavigationMode = "orbit",
+ onCameraChange,
rootRef,
cameraRef,
zoom = 1,
@@ -82,6 +97,9 @@ export function IPhone17ProMaxScene({
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;
@@ -369,17 +387,14 @@ export function IPhone17ProMaxScene({
const id = setTimeout(() => {
const orbit = orbitRef.current;
if (!orbit) return;
- const DEG = Math.PI / 180;
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, radius));
orbit.update();
invalidateRef.current();
prevRotationRef.current = { x: initialRotationX, y: initialRotationY };
}, 0);
return () => clearTimeout(id);
- }, [initialRotationX, initialRotationY, zoom]);
+ }, [initialRotationX, initialRotationY, zoom, cameraConfig.distance, cameraConfig.target]);
useEffect(() => {
const root = rootRef.current;
@@ -452,27 +467,23 @@ export function IPhone17ProMaxScene({
<PerspectiveCamera
ref={cameraRef}
makeDefault
- fov={40}
+ fov={cameraConfig.fov ?? 40}
near={0.01}
far={100}
- position={sphericalCameraPos(initialRotationX, initialRotationY)}
+ position={getMockupCameraPosition(initialRotationX, initialRotationY, cameraConfig.distance, cameraConfig.target)}
zoom={zoom}
/>
<Environment files={HDRI_FILES[environment as EnvironmentPreset]} environmentIntensity={glow} background={false} />
<OrbitControls
ref={orbitRef}
- enableZoom={false}
- enablePan={false}
+ {...getCameraNavigationOptions(cameraNavigationMode)}
+ target={cameraConfig.target}
enableDamping
dampingFactor={0.08}
autoRotate={autoRotate}
autoRotateSpeed={rotationSpeed}
onEnd={() => {
- const orbit = orbitRef.current;
- if (!orbit || !onRotationChange) return;
- const ry = orbit.getAzimuthalAngle() * (180 / Math.PI);
- const rx = (Math.PI / 2 - orbit.getPolarAngle()) * (180 / Math.PI);
- onRotationChange(rx, ry);
+ reportMockupCameraChange(orbitRef.current, 1.5, onCameraChange, onRotationChange);
}}
/>
<ambientLight intensity={0.3} />
diff --git a/app/components/ui/editor/mockups-3d/IPhoneDuo3DViewer.tsx b/app/components/ui/editor/mockups-3d/IPhoneDuo3DViewer.tsx
index d5bb1d2..0468bed 100644
--- a/app/components/ui/editor/mockups-3d/IPhoneDuo3DViewer.tsx
+++ b/app/components/ui/editor/mockups-3d/IPhoneDuo3DViewer.tsx
@@ -8,7 +8,13 @@ import type { OrbitControls as OrbitControlsType } from "three-stdlib";
import { createScreenMaterial } from "@/lib/iphone-duo/screen-material";
import { foldChoreography } from "@/lib/iphone-duo/fold-choreography";
import { applyTextureCover } from "@/lib/phone3d.utils";
-import { HDRI_FILES, sphericalCameraPos } from "@/lib/viewer-controls3d";
+import {
+ DEFAULT_MOCKUP_CAMERA,
+ HDRI_FILES,
+ getCameraNavigationOptions,
+ getMockupCameraPosition,
+ reportMockupCameraChange,
+} from "@/lib/viewer-controls3d";
import type { Mockup3DStageProps } from "./Mockup3DStage";
import type { Phone3DApi } from "@/lib/phone3d-composite-draw.utils";
import type { Mockup3DMotionTransform } from "@/lib/mockup-motion-3d";
@@ -20,6 +26,7 @@ const CAMERA_RADIUS = 1.7;
export function IPhoneDuoScene({
imageUrl, videoElement, cropArea, openingProgress = 1,
initialRotationX = 6, initialRotationY = -12, initialRotationZ = 0,
+ cameraConfig = DEFAULT_MOCKUP_CAMERA, cameraNavigationMode = "orbit", onCameraChange,
zoom = 1, autoRotate = false, rotationSpeed = 3.5,
environment = "studio", glow = 1.2, shadowIntensity = 0,
motionTransform, onRotationChange, onApi, onLoaded, rootRef, cameraRef,
@@ -165,11 +172,13 @@ export function IPhoneDuoScene({
useEffect(() => {
const cam = cameraRef.current;
if (!cam) return;
- cam.position.set(...sphericalCameraPos(initialRotationX, initialRotationY, CAMERA_RADIUS / zoom));
- cam.lookAt(0, 0, 0);
+ cam.position.set(...getMockupCameraPosition(initialRotationX, initialRotationY, cameraConfig.distance / zoom, cameraConfig.target, CAMERA_RADIUS));
+ cam.fov = cameraConfig.fov ?? 30;
+ cam.updateProjectionMatrix();
+ cam.lookAt(...cameraConfig.target);
orbitRef.current?.update();
invalidate();
- }, [initialRotationX, initialRotationY, zoom, cameraRef, invalidate]);
+ }, [initialRotationX, initialRotationY, zoom, cameraRef, invalidate, cameraConfig]);
useEffect(() => {
const callback = callbacks.current.onApi;
@@ -213,13 +222,12 @@ export function IPhoneDuoScene({
return (
<>
- <PerspectiveCamera ref={cameraRef} makeDefault fov={30} near={0.01} far={100}
- position={sphericalCameraPos(initialRotationX, initialRotationY, CAMERA_RADIUS / zoom)} />
- <OrbitControls ref={orbitRef} enableZoom={false} enablePan={false} enableDamping
+ <PerspectiveCamera ref={cameraRef} makeDefault fov={cameraConfig.fov ?? 30} near={0.01} far={100}
+ position={getMockupCameraPosition(initialRotationX, initialRotationY, cameraConfig.distance / zoom, cameraConfig.target, CAMERA_RADIUS)} />
+ <OrbitControls ref={orbitRef} {...getCameraNavigationOptions(cameraNavigationMode)} target={cameraConfig.target} enableDamping
autoRotate={autoRotate} autoRotateSpeed={rotationSpeed}
onEnd={() => {
- const orbit = orbitRef.current;
- if (orbit) onRotationChange?.(90 - orbit.getPolarAngle() / DEG, orbit.getAzimuthalAngle() / DEG);
+ reportMockupCameraChange(orbitRef.current, CAMERA_RADIUS / zoom, onCameraChange, onRotationChange);
}} />
<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 3dac289..fd09f0a 100644
--- a/app/components/ui/editor/mockups-3d/Laptop3DViewer.tsx
+++ b/app/components/ui/editor/mockups-3d/Laptop3DViewer.tsx
@@ -13,7 +13,16 @@ import {
applyTextureCover
} from "@/lib/phone3d.utils";
import type { OrbitControls as OrbitControlsType } from 'three-stdlib';
-import { EnvironmentPreset, HDRI_FILES, sphericalCameraPos } from "@/lib/viewer-controls3d";
+import {
+ DEFAULT_MOCKUP_CAMERA,
+ EnvironmentPreset,
+ HDRI_FILES,
+ type CameraNavigationMode,
+ type MockupCameraConfig,
+ getCameraNavigationOptions,
+ getMockupCameraPosition,
+ reportMockupCameraChange,
+} from "@/lib/viewer-controls3d";
import { GetMediaMaskStyles } from "@/lib/media-mask.utils";
import { EffectComposer } from "three/examples/jsm/postprocessing/EffectComposer.js";
import { RenderPass } from "three/examples/jsm/postprocessing/RenderPass.js";
@@ -53,6 +62,9 @@ interface Props {
initialRotationY?: number;
initialRotationZ?: number;
onRotationChange?: (rx: number, ry: number) => void;
+ cameraConfig?: MockupCameraConfig;
+ cameraNavigationMode?: CameraNavigationMode;
+ onCameraChange?: (camera: MockupCameraConfig) => void;
onMount?: (canvas: HTMLCanvasElement) => void;
onApi?: (api: Laptop3DApi | null) => void;
scale?: number;
@@ -86,7 +98,7 @@ function loadLaptopGltf(): Promise<THREE.Group> {
}
export function LaptopScene({
- imageUrl, imageMaskConfig, cropArea, openingProgress = 1, initialRotationX = 43.23, initialRotationY = -37.82, initialRotationZ = 0, onRotationChange, rootRef, cameraRef, zoom = 1, onApi, onLoaded, videoElement, autoRotate = false, rotationSpeed = 3.5, glow = 1.0, environment = "forest", isSelected = false, isHovered = false, shadowIntensity = 0,
+ imageUrl, imageMaskConfig, cropArea, openingProgress = 1, initialRotationX = 43.23, initialRotationY = -37.82, initialRotationZ = 0, onRotationChange, cameraConfig = DEFAULT_MOCKUP_CAMERA, cameraNavigationMode = "orbit", onCameraChange, rootRef, cameraRef, zoom = 1, onApi, onLoaded, videoElement, autoRotate = false, rotationSpeed = 3.5, glow = 1.0, environment = "forest", isSelected = false, isHovered = false, shadowIntensity = 0,
}: Props & { rootRef: React.MutableRefObject<THREE.Group | null>; cameraRef: React.MutableRefObject<THREE.PerspectiveCamera | null>; onLoaded?: () => void; }) {
const { gl, scene, camera, invalidate, size } = useThree();
const orbitRef = useRef<OrbitControlsType | null>(null);
@@ -485,16 +497,13 @@ export function LaptopScene({
if (isUserInteractingRef.current) return;
const orbit = orbitRef.current;
if (!orbit) return;
- const radius = CAM_RADIUS / zoom;
- 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 / zoom, cameraConfig.target, CAM_RADIUS));
orbit.update();
invalidateRef.current();
prevRotationRef.current = { x: initialRotationX, y: initialRotationY };
}, 0);
return () => clearTimeout(id);
- }, [initialRotationX, initialRotationY, zoom]);
+ }, [initialRotationX, initialRotationY, zoom, cameraConfig.distance, cameraConfig.target]);
useEffect(() => {
if (rootRef.current) {
@@ -571,11 +580,11 @@ export function LaptopScene({
return (
<>
- <PerspectiveCamera ref={cameraRef} makeDefault fov={CAM_FOV} near={10} far={1000} position={sphericalCameraPos(initialRotationX, initialRotationY, CAM_RADIUS / zoom)} />
+ <PerspectiveCamera ref={cameraRef} makeDefault fov={cameraConfig.fov ?? CAM_FOV} near={10} far={1000} position={getMockupCameraPosition(initialRotationX, initialRotationY, cameraConfig.distance / zoom, cameraConfig.target, CAM_RADIUS)} />
<OrbitControls
ref={orbitRef}
- enableZoom={false}
- enablePan={false}
+ {...getCameraNavigationOptions(cameraNavigationMode)}
+ target={cameraConfig.target}
enableDamping
dampingFactor={0.08}
autoRotate={autoRotate}
@@ -585,11 +594,7 @@ export function LaptopScene({
}}
onEnd={() => {
isUserInteractingRef.current = false;
- const orbit = orbitRef.current;
- if (!orbit || !onRotationChange) return;
- const ry = orbit.getAzimuthalAngle() * (180 / Math.PI);
- const rx = (Math.PI / 2 - orbit.getPolarAngle()) * (180 / Math.PI);
- onRotationChange(rx, ry);
+ reportMockupCameraChange(orbitRef.current, CAM_RADIUS / zoom, onCameraChange, onRotationChange);
}}
/>
<Environment files={HDRI_FILES[environment as EnvironmentPreset]} environmentIntensity={glow} background={false} />
diff --git a/app/components/ui/editor/mockups-3d/Mockup3DStage.tsx b/app/components/ui/editor/mockups-3d/Mockup3DStage.tsx
index dbde54a..dd272fe 100644
--- a/app/components/ui/editor/mockups-3d/Mockup3DStage.tsx
+++ b/app/components/ui/editor/mockups-3d/Mockup3DStage.tsx
@@ -12,7 +12,11 @@ import { IPhone17ProMax3DApi, IPhone17ProMaxScene } from "./IPhone17ProMax3DView
import { IPadMini63DApi, IPadMiniScene } from "./IPadMini63DViewer";
import { ImageMaskConfigLike, PHONE_DEVICE_URLS } from "@/lib/phone3d.utils";
import type { ImageDeviceId } from "@/types/mockup.types";
-import { EnvironmentPreset } from "@/lib/viewer-controls3d";
+import type {
+ CameraNavigationMode,
+ EnvironmentPreset,
+ MockupCameraConfig,
+} from "@/lib/viewer-controls3d";
import { REST_MOCKUP_3D_MOTION, type Mockup3DMotionTransform } from "@/lib/mockup-motion-3d";
import { useFrame } from "@react-three/fiber";
@@ -34,6 +38,9 @@ export interface Mockup3DStageProps {
openingProgress?: number; // laptop / foldable phone
modelUrl?: string; // solo devices genéricos (phone/iphone)
onRotationChange?: (rx: number, ry: number) => void;
+ cameraConfig?: MockupCameraConfig;
+ cameraNavigationMode?: CameraNavigationMode;
+ onCameraChange?: (camera: MockupCameraConfig) => void;
onMount?: (canvas: HTMLCanvasElement) => void;
onApi?: (api: Mockup3DApi | null) => void;
scale?: number;
diff --git a/app/components/ui/editor/mockups-3d/Phone3DViewer.tsx b/app/components/ui/editor/mockups-3d/Phone3DViewer.tsx
index bf3a139..58a44fd 100644
--- a/app/components/ui/editor/mockups-3d/Phone3DViewer.tsx
+++ b/app/components/ui/editor/mockups-3d/Phone3DViewer.tsx
@@ -19,7 +19,16 @@ import {
applyTextureCover
} from "@/lib/phone3d.utils";
import type { OrbitControls as OrbitControlsType } from 'three-stdlib';
-import { EnvironmentPreset, HDRI_FILES, sphericalCameraPos } from "@/lib/viewer-controls3d";
+import {
+ DEFAULT_MOCKUP_CAMERA,
+ EnvironmentPreset,
+ HDRI_FILES,
+ type CameraNavigationMode,
+ type MockupCameraConfig,
+ getCameraNavigationOptions,
+ getMockupCameraPosition,
+ reportMockupCameraChange,
+} from "@/lib/viewer-controls3d";
import { GetMediaMaskStyles } from "@/lib/media-mask.utils";
import { EffectComposer } from "three/examples/jsm/postprocessing/EffectComposer.js";
@@ -44,6 +53,9 @@ interface Props {
initialRotationY?: number;
initialRotationZ?: number;
onRotationChange?: (rx: number, ry: number) => void;
+ cameraConfig?: MockupCameraConfig;
+ cameraNavigationMode?: CameraNavigationMode;
+ onCameraChange?: (camera: MockupCameraConfig) => void;
onMount?: (canvas: HTMLCanvasElement) => void;
onApi?: (api: Phone3DApi | null) => void;
modelUrl?: string;
@@ -106,7 +118,7 @@ function applyMetalMaterial(m: THREE.MeshStandardMaterial, matName: string): voi
}
}
export function Phone3DScene({
- imageUrl, imageMaskConfig, cropArea, initialRotationX = -58.23, initialRotationY = -29, initialRotationZ = 0, onRotationChange, rootRef, cameraRef, zoom = 1, modelUrl, onApi, onLoaded, videoElement, autoRotate = false, rotationSpeed = 3.5, glow = 1.0, environment = "studio", isSelected = false, isHovered = false,
+ imageUrl, imageMaskConfig, cropArea, initialRotationX = -58.23, initialRotationY = -29, initialRotationZ = 0, onRotationChange, cameraConfig = DEFAULT_MOCKUP_CAMERA, cameraNavigationMode = "orbit", onCameraChange, rootRef, cameraRef, zoom = 1, modelUrl, onApi, onLoaded, videoElement, autoRotate = false, rotationSpeed = 3.5, glow = 1.0, environment = "studio", isSelected = false, isHovered = false,
}: Props & { rootRef: React.MutableRefObject<THREE.Group | null>; cameraRef: React.MutableRefObject<THREE.PerspectiveCamera | null>; onLoaded?: () => void; }) {
const { gl, scene, camera, invalidate, size } = useThree();
const orbitRef = useRef<OrbitControlsType | null>(null);
@@ -665,11 +677,11 @@ export function Phone3DScene({
return (
<>
- <PerspectiveCamera ref={cameraRef} makeDefault fov={40} near={0.01} far={100} position={sphericalCameraPos(initialRotationX, initialRotationY)} zoom={zoom} />
+ <PerspectiveCamera ref={cameraRef} makeDefault fov={cameraConfig.fov ?? 40} near={0.01} far={100} position={getMockupCameraPosition(initialRotationX, initialRotationY, cameraConfig.distance, cameraConfig.target)} zoom={zoom} />
<OrbitControls
ref={orbitRef}
- enableZoom={false}
- enablePan={false}
+ {...getCameraNavigationOptions(cameraNavigationMode)}
+ target={cameraConfig.target}
enableDamping
dampingFactor={0.08}
autoRotate={autoRotate}
@@ -679,11 +691,7 @@ export function Phone3DScene({
}}
onEnd={() => {
isUserInteractingRef.current = false;
- const orbit = orbitRef.current;
- if (!orbit || !onRotationChange) return;
- const ry = orbit.getAzimuthalAngle() * (180 / Math.PI);
- const rx = (Math.PI / 2 - orbit.getPolarAngle()) * (180 / Math.PI);
- onRotationChange(rx, ry);
+ reportMockupCameraChange(orbitRef.current, 1.5, onCameraChange, onRotationChange);
}}
/>
<Environment files={HDRI_FILES[environment as EnvironmentPreset]} environmentIntensity={glow} background={false} />
diff --git a/app/contexts/Mockup3dContext.tsx b/app/contexts/Mockup3dContext.tsx
index 488349e..d917efe 100644
--- a/app/contexts/Mockup3dContext.tsx
+++ b/app/contexts/Mockup3dContext.tsx
@@ -3,7 +3,12 @@
import type { ImageDeviceId } from "@/types/mockup.types";
import { createContext, useContext, useState, useEffect, useRef, useMemo, type ReactNode } from "react";
import { DEVICE_VIEWER_DEFAULTS } from "@/lib/phone3d.utils";
-import type { EnvironmentPreset } from "@/lib/viewer-controls3d";
+import {
+ DEFAULT_MOCKUP_CAMERA,
+ type CameraNavigationMode,
+ type EnvironmentPreset,
+ type MockupCameraConfig,
+} from "@/lib/viewer-controls3d";
interface Mockup3dState {
selectedTemplateId: string | null;
@@ -38,6 +43,10 @@ interface Mockup3dState {
/** Perspective (px) for the 3D transform on the phone mockup */
imagePhonePerspective: number;
setImagePhonePerspective: (v: number) => void;
+ mockupCamera: MockupCameraConfig;
+ setMockupCamera: (v: MockupCameraConfig) => void;
+ cameraNavigationMode: CameraNavigationMode;
+ setCameraNavigationMode: (v: CameraNavigationMode) => void;
/** Active device from the shared 3D catalogue */
imagePhoneDevice: ImageDeviceId;
setImagePhoneDevice: (d: ImageDeviceId) => void;
@@ -79,6 +88,8 @@ export function Mockup3dProvider({ children }: { children: ReactNode }) {
const [imagePhoneRotY, setImagePhoneRotY] = useState(0);
const [imagePhoneRotZ, setImagePhoneRotZ] = useState(0);
const [imagePhonePerspective, setImagePhonePerspective] = useState(600);
+ const [mockupCamera, setMockupCamera] = useState<MockupCameraConfig>(DEFAULT_MOCKUP_CAMERA);
+ const [cameraNavigationMode, setCameraNavigationMode] = useState<CameraNavigationMode>("orbit");
const [imagePhoneDevice, setImagePhoneDevice] = useState<ImageDeviceId>('phone');
const [imagePhonePresetId, setImagePhonePresetId] = useState('custom');
const [imagePhoneOpening, setImagePhoneOpening] = useState(1);
@@ -113,6 +124,8 @@ export function Mockup3dProvider({ children }: { children: ReactNode }) {
imagePhoneRotY, setImagePhoneRotY,
imagePhoneRotZ, setImagePhoneRotZ,
imagePhonePerspective, setImagePhonePerspective,
+ mockupCamera, setMockupCamera,
+ cameraNavigationMode, setCameraNavigationMode,
imagePhoneDevice, setImagePhoneDevice,
imagePhonePresetId, setImagePhonePresetId,
imagePhoneOpening, setImagePhoneOpening,
@@ -127,6 +140,7 @@ export function Mockup3dProvider({ children }: { children: ReactNode }) {
selectedTemplateId, motionImageUrl, motionIntensity,
imagePhoneActive, imagePhoneX, imagePhoneY, imagePhoneScale,
imagePhoneRotX, imagePhoneRotY, imagePhoneRotZ, imagePhonePerspective,
+ mockupCamera, cameraNavigationMode,
imagePhoneDevice, imagePhonePresetId, imagePhoneOpening,
imagePhoneShadow, imagePhoneShadowColor, imagePhoneRefWidth,
viewer3DAutoRotate, viewer3DRotationSpeed, viewer3DGlow, viewer3DEnvironment,
diff --git a/components/ui/TickSliderControl.tsx b/components/ui/TickSliderControl.tsx
index 6a2df66..a41f014 100644
--- a/components/ui/TickSliderControl.tsx
+++ b/components/ui/TickSliderControl.tsx
@@ -1,8 +1,11 @@
"use client";
import { useRef, useState, useEffect, useCallback, useMemo } from "react";
+import { Icon } from "@iconify/react";
interface TickSliderControlProps {
label: string;
+ helperText?: string;
+ icon?: string;
value: number;
min?: number;
max?: number;
@@ -15,6 +18,8 @@ interface TickSliderControlProps {
export function TickSliderControl({
label,
+ helperText,
+ icon,
value,
min = 0.5,
max = 3,
@@ -128,9 +133,22 @@ export function TickSliderControl({
return (
<div className="flex w-full flex-col gap-3 select-none touch-none font-sans">
- <span className="flex items-center gap-1.5 text-[11px] uppercase tracking-widest text-muted-foreground font-bold">
- {label}
- </span>
+ <div className="flex items-start justify-between gap-2">
+ <span className="flex items-center gap-1.5 text-[11px] uppercase tracking-widest text-muted-foreground font-bold">
+ {icon && <Icon icon={icon} width="15" className="text-primary" aria-hidden="true" />}
+ {label}
+ </span>
+ {helperText && (
+ <span
+ className="text-muted-foreground/70"
+ title={helperText}
+ aria-label={helperText}
+ role="img"
+ >
+ <Icon icon="mdi:export-variant" width="14" aria-hidden="true" />
+ </span>
+ )}
+ </div>
<div className="flex items-center gap-6">
<div
diff --git a/hooks/useImageProjects.ts b/hooks/useImageProjects.ts
index 9d0c1ec..f68761e 100644
--- a/hooks/useImageProjects.ts
+++ b/hooks/useImageProjects.ts
@@ -18,6 +18,7 @@ import type { MockupConfig } from "@/types/mockup.types";
import type { Preview3DConfig, ImageMaskConfig } from "@/types/photo.types";
import { DEFAULT_MOCKUP_CONFIG } from "@/types/mockup.types";
import { DEFAULT_MASK_CONFIG, PREVIEW_CONFIGS } from "@/types/photo.types";
+import { DEFAULT_MOCKUP_CAMERA, type MockupCameraConfig } from "@/lib/viewer-controls3d";
interface ImageProjectState {
backgroundTab: BackgroundTab;
@@ -51,6 +52,7 @@ interface ImageProjectState {
imagePhoneRotY: number;
imagePhoneRotZ: number;
imagePhonePerspective: number;
+ mockupCamera: MockupCameraConfig;
imagePhoneDevice: ImageDeviceId;
imagePhonePresetId: string;
imagePhoneOpening: number;
@@ -92,6 +94,7 @@ const DEFAULT_PROJECT_STATE: ImageProjectState = {
imagePhoneRotY: 0,
imagePhoneRotZ: 0,
imagePhonePerspective: 600,
+ mockupCamera: DEFAULT_MOCKUP_CAMERA,
imagePhoneDevice: 'phone',
imagePhonePresetId: 'front',
imagePhoneOpening: 1,
diff --git a/lib/canvas.utils.ts b/lib/canvas.utils.ts
index 99d7802..f8a7998 100644
--- a/lib/canvas.utils.ts
+++ b/lib/canvas.utils.ts
@@ -234,11 +234,11 @@ export function calculateSmoothZoom(
return 1 + (targetScale - 1) * easeOutQuart(progress);
}
- // Exit ramp [end-T, end]
+ // Exit ramp [end-T, end]: begin at targetScale and decay back to 1 by endTime.
const timeBeforeEnd = fragment.endTime - time;
if (transitionSec > 0 && timeBeforeEnd < transitionSec) {
- const progress = Math.min(1, Math.max(0, timeBeforeEnd / transitionSec));
- return 1 + (targetScale - 1) * easeOutQuart(progress);
+ const progress = Math.min(1, Math.max(0, (transitionSec - timeBeforeEnd) / transitionSec));
+ return 1 + (targetScale - 1) * (1 - easeOutQuart(progress));
}
// Hold
diff --git a/lib/video-project-cache.ts b/lib/video-project-cache.ts
index 4a92dff..6e1955c 100644
--- a/lib/video-project-cache.ts
+++ b/lib/video-project-cache.ts
@@ -8,6 +8,7 @@ import type { BackgroundTab, BackgroundColorConfig, AspectRatio, CropArea } from
import type { CameraConfig } from "@/types/camera.types";
import type { Preview3DConfig, ImageMaskConfig } from "@/types/photo.types";
import type { TrimRange } from "@/types/timeline.types";
+import type { MockupCameraConfig } from "@/lib/viewer-controls3d";
const DB_NAME = "openvid-video-project";
const DB_VERSION = 3;
@@ -38,6 +39,7 @@ export interface VideoProject {
mockupId: string;
mockupConfig: MockupConfig;
+ mockupCamera?: MockupCameraConfig;
mockupMotionFragments: MockupMotionFragment[];
diff --git a/lib/viewer-controls3d.ts b/lib/viewer-controls3d.ts
index c7311f3..80946fb 100644
--- a/lib/viewer-controls3d.ts
+++ b/lib/viewer-controls3d.ts
@@ -1,7 +1,106 @@
import { useControls } from "leva";
import { useEffect } from "react";
+import { MOUSE, TOUCH } from "three";
+import type { OrbitControls as OrbitControlsType } from "three-stdlib";
export type EnvironmentPreset = "sunset" | "dawn" | "night" | "warehouse" | "forest" | "apartment" | "studio" | "city" | "park" | "lobby";
+export type CameraNavigationMode = "orbit" | "trackXY" | "trackZ";
+
+export interface MockupCameraConfig {
+ target: [number, number, number];
+ distance: number;
+ fov: number | null;
+}
+
+export const DEFAULT_MOCKUP_CAMERA: MockupCameraConfig = {
+ target: [0, 0, 0],
+ distance: 1,
+ fov: null,
+};
+
+export function normalizeMockupCameraConfig(
+ value?: Partial<MockupCameraConfig> | null,
+): MockupCameraConfig {
+ const target = value?.target;
+ const coordinateAt = (index: number) => {
+ const coordinate = target?.[index];
+ return typeof coordinate === "number" && Number.isFinite(coordinate)
+ ? Math.max(-1000, Math.min(1000, coordinate))
+ : 0;
+ };
+ const normalizedTarget: [number, number, number] = [
+ coordinateAt(0),
+ coordinateAt(1),
+ coordinateAt(2),
+ ];
+ const distance = value?.distance;
+ const fov = value?.fov;
+ return {
+ target: normalizedTarget,
+ distance: typeof distance === "number" && Number.isFinite(distance)
+ ? Math.max(0.25, Math.min(4, distance))
+ : 1,
+ fov: typeof fov === "number" && Number.isFinite(fov)
+ ? Math.max(20, Math.min(80, fov))
+ : null,
+ };
+}
+
+export function getCameraNavigationOptions(mode: CameraNavigationMode = "orbit") {
+ return {
+ enableRotate: mode === "orbit",
+ enablePan: mode === "trackXY",
+ enableZoom: mode === "trackZ",
+ mouseButtons: {
+ LEFT: mode === "orbit" ? MOUSE.ROTATE : mode === "trackXY" ? MOUSE.PAN : MOUSE.DOLLY,
+ MIDDLE: MOUSE.DOLLY,
+ RIGHT: MOUSE.PAN,
+ },
+ touches: {
+ ONE: mode === "orbit" ? TOUCH.ROTATE : TOUCH.PAN,
+ TWO: mode === "trackZ" ? TOUCH.DOLLY_PAN : TOUCH.PAN,
+ },
+ };
+}
+
+export function getMockupCameraPosition(
+ rotX: number,
+ rotY: number,
+ distance: number,
+ target: [number, number, number],
+ baseRadius = 1.5,
+): [number, number, number] {
+ const camera = normalizeMockupCameraConfig({ target, distance });
+ const safeRotX = Number.isFinite(rotX) ? rotX : 0;
+ const safeRotY = Number.isFinite(rotY) ? rotY : 0;
+ const safeBaseRadius = Number.isFinite(baseRadius) && baseRadius > 0 ? baseRadius : 1.5;
+ const [x, y, z] = sphericalCameraPos(safeRotX, safeRotY, safeBaseRadius * camera.distance);
+ return [x + camera.target[0], y + camera.target[1], z + camera.target[2]];
+}
+
+export function reportMockupCameraChange(
+ controls: OrbitControlsType | null,
+ baseRadius: number,
+ onCameraChange?: (camera: MockupCameraConfig) => void,
+ onRotationChange?: (rotX: number, rotY: number) => void,
+): void {
+ if (!controls || !Number.isFinite(baseRadius) || baseRadius <= 0) return;
+ const camera = controls.object;
+ const distance = camera.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))
+ : null,
+ });
+ onRotationChange?.(
+ 90 - controls.getPolarAngle() * (180 / Math.PI),
+ controls.getAzimuthalAngle() * (180 / Math.PI),
+ );
+}
interface ViewerControlsOptions {
defaultEnvironment?: EnvironmentPreset;
diff --git a/messages/en.json b/messages/en.json
index 675a010..b3d9c48 100644
--- a/messages/en.json
+++ b/messages/en.json
@@ -642,6 +642,18 @@
"retry": "Try again",
"shadow": "Shadow",
"position": "Position",
+ "cameraControls": "3D camera",
+ "cameraFraming": "Camera framing",
+ "cameraTarget": "Look-at point",
+ "orbit": "Orbit",
+ "trackXY": "Track XY",
+ "trackZ": "Track Z",
+ "orbitHint": "Drag to rotate around the device.",
+ "trackXYHint": "Drag to pan the view.",
+ "trackZHint": "Drag or scroll to move closer or farther.",
+ "dolly": "Camera distance",
+ "fieldOfView": "Field of view",
+ "target": "Target",
"removeFrame": "Remove frame",
"darkMode": {
"label": "Dark mode",
@@ -742,6 +754,8 @@
"videosMenu": {
"title": "Videos",
"speed": "Speed",
+ "speedExport": "Applies to preview and export",
+ "speedPresets": "Playback speed presets",
"dropzone": "Drop your video here!",
"emptyState": {
"title": "Upload video",
diff --git a/messages/es.json b/messages/es.json
index 4f68878..5cf42f3 100644
--- a/messages/es.json
+++ b/messages/es.json
@@ -598,6 +598,18 @@
"retry": "Reintentar",
"shadow": "Sombra",
"position": "Posición",
+ "cameraControls": "Cámara 3D",
+ "cameraFraming": "Encuadre de cámara",
+ "cameraTarget": "Punto de enfoque",
+ "orbit": "Orbitar",
+ "trackXY": "Mover XY",
+ "trackZ": "Acercar / alejar",
+ "orbitHint": "Arrastra para girar alrededor del dispositivo.",
+ "trackXYHint": "Arrastra para desplazar la vista.",
+ "trackZHint": "Arrastra o usa la rueda para acercar o alejar.",
+ "dolly": "Distancia de cámara",
+ "fieldOfView": "Campo de visión",
+ "target": "Objetivo",
"removeFrame": "Quitar marco",
"darkMode": {
"label": "Modo oscuro",
@@ -698,6 +710,8 @@
"videosMenu": {
"title": "Videos",
"speed": "Velocidad",
+ "speedExport": "Se aplica a la vista previa y a la exportación",
+ "speedPresets": "Ajustes rápidos de velocidad",
"dropzone": "¡Suelta tu video aquí!",
"emptyState": {
"title": "Subir video",
diff --git a/messages/ko.json b/messages/ko.json
index 3121f7b..9e07723 100644
--- a/messages/ko.json
+++ b/messages/ko.json
@@ -642,6 +642,18 @@
"retry": "다시 시도",
"shadow": "그림자",
"position": "위치",
+ "cameraControls": "3D 카메라",
+ "cameraFraming": "카메라 구도",
+ "cameraTarget": "시선 대상",
+ "orbit": "회전",
+ "trackXY": "XY 이동",
+ "trackZ": "Z 이동",
+ "orbitHint": "드래그하여 기기 주변을 회전합니다.",
+ "trackXYHint": "드래그하여 화면을 이동합니다.",
+ "trackZHint": "드래그하거나 스크롤하여 가까이 또는 멀리 이동합니다.",
+ "dolly": "카메라 거리",
+ "fieldOfView": "시야각",
+ "target": "대상",
"removeFrame": "프레임 제거",
"darkMode": {
"label": "다크 모드",
@@ -742,6 +754,8 @@
"videosMenu": {
"title": "동영상",
"speed": "속도",
+ "speedExport": "미리보기와 내보내기에 적용",
+ "speedPresets": "재생 속도 빠른 설정",
"dropzone": "여기에 동영상을 놓으세요!",
"emptyState": {
"title": "동영상 업로드",
diff --git a/messages/ru.json b/messages/ru.json
index aacce3b..72c727e 100644
--- a/messages/ru.json
+++ b/messages/ru.json
@@ -609,6 +609,18 @@
"retry": "Повторить",
"shadow": "Тень",
"position": "Позиция",
+ "cameraControls": "3D-камера",
+ "cameraFraming": "Кадрирование камеры",
+ "cameraTarget": "Точка фокуса",
+ "orbit": "Орбита",
+ "trackXY": "Перемещение XY",
+ "trackZ": "Перемещение Z",
+ "orbitHint": "Перетаскивайте, чтобы вращаться вокруг устройства.",
+ "trackXYHint": "Перетаскивайте, чтобы смещать изображение.",
+ "trackZHint": "Перетаскивайте или прокручивайте, чтобы приблизить или отдалить.",
+ "dolly": "Дистанция камеры",
+ "fieldOfView": "Поле зрения",
+ "target": "Цель",
"removeFrame": "Удалить рамку",
"darkMode": {
"label": "Тёмная тема",
@@ -709,6 +721,8 @@
"videosMenu": {
"title": "Видео",
"speed": "Скорость",
+ "speedExport": "Применяется к предпросмотру и экспорту",
+ "speedPresets": "Быстрый выбор скорости",
"dropzone": "Отпустите видео здесь!",
"emptyState": {
"title": "Загрузить видео",
diff --git a/types/editor-state.types.ts b/types/editor-state.types.ts
index a3b9082..91899f7 100644
--- a/types/editor-state.types.ts
+++ b/types/editor-state.types.ts
@@ -7,6 +7,7 @@ import type { CameraConfig } from "@/types/camera.types";
import type { Preview3DConfig, ImageMaskConfig } from "@/types/photo.types";
import { MockupMotionFragment } from "@/lib/mockup-motion";
import { VideoTrackClip } from "./video-track.types";
+import type { MockupCameraConfig } from "@/lib/viewer-controls3d";
export interface VideoTransform {
rotation: number;
@@ -48,6 +49,7 @@ export interface EditorState {
imagePhoneRotY: number;
imagePhoneRotZ: number;
imagePhonePerspective: number;
+ mockupCamera: MockupCameraConfig;
imagePhoneDevice: ImageDeviceId;
imagePhonePresetId: string;
imagePhoneOpening: number;
@@ -121,6 +123,7 @@ export function createInitialEditorState(overrides?: Partial<EditorState>): Edit
imagePhoneRotY: 0,
imagePhoneRotZ: 0,
imagePhonePerspective: 600,
+ mockupCamera: { target: [0, 0, 0], distance: 1, fov: null },
imagePhoneDevice: 'phone',
imagePhonePresetId: 'front',
imagePhoneOpening: 1,
diff --git a/types/image-project.types.ts b/types/image-project.types.ts
index 5d603b4..d0c960c 100644
--- a/types/image-project.types.ts
+++ b/types/image-project.types.ts
@@ -3,6 +3,7 @@ import type { BackgroundTab, BackgroundColorConfig, AspectRatio, CropArea } from
import type { MockupConfig } from "@/types/mockup.types";
import { CanvasElement } from "./canvas-elements.types";
import type { Preview3DConfig, ImageMaskConfig } from "./photo.types";
+import type { MockupCameraConfig } from "@/lib/viewer-controls3d";
export interface ImageProject {
id: string;
@@ -51,6 +52,7 @@ export interface ImageProject {
imagePhoneRotY: number;
imagePhoneRotZ: number;
imagePhonePerspective: number;
+ mockupCamera: MockupCameraConfig;
imagePhoneDevice: ImageDeviceId;
imagePhonePresetId: string;
imagePhoneOpening: number;