Skip to content

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

Refactor 3D Viewer Components and Introduce Mockup3D Frame

CristianOlivera1b616781137ff
diff --git a/app/components/ui/editor/Mockup3dMenu.tsx b/app/components/ui/editor/Mockup3dMenu.tsx
index 4e961d0..3b95042 100644
--- a/app/components/ui/editor/Mockup3dMenu.tsx
+++ b/app/components/ui/editor/Mockup3dMenu.tsx
@@ -308,7 +308,7 @@ export function Mockup3dMenu({
setImagePhoneRotX(-30.23);
setImagePhoneRotY(-60.82);
} else if (imagePhoneDevice === "iphone-13-pro-max") {
- setImagePhoneScale(1.2);
+ setImagePhoneScale(1.6);
} else {
setImagePhoneShadow(0.4);
}
diff --git a/app/components/ui/editor/MockupMenu.tsx b/app/components/ui/editor/MockupMenu.tsx
index 2180160..e213ad2 100644
--- a/app/components/ui/editor/MockupMenu.tsx
+++ b/app/components/ui/editor/MockupMenu.tsx
@@ -139,7 +139,7 @@ export function MockupMenu({
if (id === "iphone-13-pro-max") {
setImagePhoneRotX(-58.23);
setImagePhoneRotY(-29.82);
- setImagePhoneScale(1.2);
+ setImagePhoneScale(1.6);
} else if (id === "double_iphone_13_pro") {
setImagePhoneRotX(-30.23);
setImagePhoneRotY(-60.82);
diff --git a/app/components/ui/editor/VideoCanvas.tsx b/app/components/ui/editor/VideoCanvas.tsx
index ff11e8e..0b24abf 100644
--- a/app/components/ui/editor/VideoCanvas.tsx
+++ b/app/components/ui/editor/VideoCanvas.tsx
@@ -11,7 +11,7 @@ import { speedToTransitionMs, ZOOM_EASING, calculateZoomPhaseState, zoomLevelToF
import type { ZoomFragment } from "@/types/zoom.types";
import PlaceholderEditor from "../PlaceholderEditor";
import { MockupWrapper } from "./mockups/MockupWrapper";
-import { DEFAULT_MOCKUP_CONFIG } from "@/types/mockup.types";
+import { DEFAULT_MOCKUP_CONFIG, type ImageDeviceId } from "@/types/mockup.types";
import { calculateSmoothZoom } from "@/lib/canvas.utils";
import { VIDEO_Z_INDEX } from "@/lib/constants";
import { applyPerspective3D, disposePerspective3D } from "@/lib/perspective3d";
@@ -35,6 +35,7 @@ import { drawMaskedImage } from "@/lib/masked-image-draw.utils";
import { drawMockupAndMedia, type MockupDrawContext } from "@/lib/mockup-media-draw.utils";
import { drawPhone3DCompositeWithZoom, type Phone3DCompositeContext } from "@/lib/phone3d-composite-draw.utils";
import { buildMockupMotionCss, MockupMotionTransform, REST_MOCKUP_MOTION, sampleCombinedMockupMotion } from "@/lib/mockup-motion";
+import { Mockup3DFrame } from "./mockups-3d/Mockup3DFrame";
export type { VideoCanvasHandle, VideoCanvasProps };
@@ -195,7 +196,7 @@ function VideoCanvasInner({
hasBuiltInShadow?: boolean;
getVisualSize?: () => { width: number; height: number; offsetY?: number } | null; // ← offsetY
} | null>(null);
- const [activePhoneDevice, setActivePhoneDevice] = useState<string | null>(null);
+ const [activePhoneDevice, setActivePhoneDevice] = useState<ImageDeviceId | null>(null);
const [phoneTransitioning, setPhoneTransitioning] = useState(false);
const rafDragRef = useRef<number | null>(null);
const pendingUpdateRef = useRef<{ id: string; x: number; y: number } | null>(null);
@@ -1421,7 +1422,7 @@ function VideoCanvasInner({
focusPxX = (zoomState.focusX / 100) * canvasWidth;
focusPxY = (zoomState.focusY / 100) * canvasHeight;
}
-
+
const activeFragment = zoomFragments.find(
f => frameTime >= f.startTime && frameTime <= f.endTime
) ?? zoomFragments
@@ -2316,118 +2317,20 @@ function VideoCanvasInner({
: "none",
}}
>
- {phoneTransitioning || !activePhoneDevice ? (
+ {!imagePhoneActive || !imagePhoneDevice ? (
<div
style={{ width: PHONE_W, height: PHONE_H }}
className="flex items-center justify-center"
>
<div className="w-6 h-6 border-2 border-white/20 border-t-white/60 rounded-full animate-spin" />
</div>
- ) : activePhoneDevice === "laptop" ? (
- <Laptop3DViewer
- key="laptop"
- imageUrl={imageUrl}
- videoElement={activeVideoElement ?? undefined}
- openingProgress={imagePhoneOpening}
- imageMaskConfig={effectivePhoneMaskConfig}
- cropArea={cropArea}
- initialRotationX={imagePhoneRotX}
- initialRotationY={imagePhoneRotY}
- initialRotationZ={imagePhoneRotZ}
- onRotationChange={handlePhoneRotationChange}
- onMount={handlePhoneMount}
- onApi={handlePhoneApi}
- scale={1}
- zoom={1}
- shadowIntensity={imagePhoneShadow}
- shadowColor={imagePhoneShadowColor}
- autoRotate={viewer3D.autoRotate}
- rotationSpeed={viewer3D.rotationSpeed}
- glow={viewer3D.glow}
- environment={viewer3D.environment}
- isSelected={isVideoSelected}
- isHovered={isVideoHovered}
- onSelectChange={(value) => setIsVideoSelected(value)}
- />
- ) : activePhoneDevice === "iphone-13-pro-max" ? (
- <IPhone13ProMax3DViewer
- key="iphone-13-pro-max"
- imageUrl={imageUrl}
- videoElement={activeVideoElement ?? undefined}
- imageMaskConfig={effectivePhoneMaskConfig}
- cropArea={cropArea}
- initialRotationX={imagePhoneRotX}
- initialRotationY={imagePhoneRotY}
- initialRotationZ={imagePhoneRotZ}
- onRotationChange={handlePhoneRotationChange}
- onMount={handlePhoneMount}
- onApi={handlePhoneApi}
- scale={1}
- zoom={1}
- shadowIntensity={imagePhoneShadow}
- shadowColor={imagePhoneShadowColor}
- autoRotate={viewer3D.autoRotate}
- rotationSpeed={viewer3D.rotationSpeed}
- glow={viewer3D.glow}
- environment={viewer3D.environment}
- isSelected={isVideoSelected}
- isHovered={isVideoHovered}
- onSelectChange={(value) => setIsVideoSelected(value)}
- />
- ) : activePhoneDevice === "iphone-17-pro-max" ? (
- <IPhone17ProMax3DViewer
- key="iphone-17-pro-max"
- imageUrl={imageUrl}
- videoElement={activeVideoElement ?? undefined}
- imageMaskConfig={effectivePhoneMaskConfig}
- cropArea={cropArea}
- initialRotationX={imagePhoneRotX}
- initialRotationY={imagePhoneRotY}
- initialRotationZ={imagePhoneRotZ}
- onRotationChange={handlePhoneRotationChange}
- onMount={handlePhoneMount}
- onApi={handlePhoneApi}
- scale={1}
- zoom={1}
- shadowIntensity={imagePhoneShadow}
- shadowColor={imagePhoneShadowColor}
- autoRotate={viewer3D.autoRotate}
- rotationSpeed={viewer3D.rotationSpeed}
- glow={viewer3D.glow}
- environment={viewer3D.environment}
- isSelected={isVideoSelected}
- isHovered={isVideoHovered}
- onSelectChange={(value) => setIsVideoSelected(value)}
- />
- ) : activePhoneDevice === "double_iphone_13_pro" ? (
- <DoubleIPhone3DViewer
- key="double_iphone_13_pro"
- imageUrl={imageUrl}
- videoElement={activeVideoElement ?? undefined}
- imageMaskConfig={effectivePhoneMaskConfig}
- cropArea={cropArea}
- initialRotationX={imagePhoneRotX}
- initialRotationY={imagePhoneRotY}
- initialRotationZ={imagePhoneRotZ}
- onRotationChange={handlePhoneRotationChange}
- onMount={handlePhoneMount}
- onApi={handlePhoneApi}
- zoom={1}
- shadowIntensity={imagePhoneShadow}
- shadowColor={imagePhoneShadowColor}
- autoRotate={viewer3D.autoRotate}
- rotationSpeed={viewer3D.rotationSpeed}
- glow={viewer3D.glow}
- environment={viewer3D.environment}
- isSelected={isVideoSelected}
- isHovered={isVideoHovered}
- onSelectChange={(value) => setIsVideoSelected(value)}
- />
- ) : activePhoneDevice === "ipad_mini_6_2021" ? (
- <IPadMini63DViewer
- key="ipad_mini_6_2021"
+ ) : (
+ <Mockup3DFrame
+ device={imagePhoneDevice}
imageUrl={imageUrl}
videoElement={activeVideoElement ?? undefined}
+ openingProgress={imagePhoneDevice === "laptop" ? imagePhoneOpening : undefined}
+ modelUrl={imagePhoneDevice === "phone" || imagePhoneDevice === "iphone" ? imagePhoneModelUrl : undefined}
imageMaskConfig={effectivePhoneMaskConfig}
cropArea={cropArea}
initialRotationX={imagePhoneRotX}
@@ -2447,33 +2350,6 @@ function VideoCanvasInner({
isHovered={isVideoHovered}
onSelectChange={(value) => setIsVideoSelected(value)}
/>
-
- ) : (
- <Phone3DViewer
- key={imagePhoneDevice}
- imageUrl={imageUrl}
- videoElement={activeVideoElement ?? undefined}
- imageMaskConfig={effectivePhoneMaskConfig}
- cropArea={cropArea}
- initialRotationX={imagePhoneRotX}
- initialRotationY={imagePhoneRotY}
- initialRotationZ={imagePhoneRotZ}
- modelUrl={imagePhoneModelUrl}
- scale={1}
- zoom={1}
- shadowIntensity={imagePhoneShadow}
- shadowColor={imagePhoneShadowColor}
- onRotationChange={handlePhoneRotationChange}
- onMount={handlePhoneMount}
- onApi={handlePhoneApi}
- autoRotate={viewer3D.autoRotate}
- rotationSpeed={viewer3D.rotationSpeed}
- glow={viewer3D.glow}
- environment={viewer3D.environment}
- isSelected={isVideoSelected}
- isHovered={isVideoHovered}
- onSelectChange={(value) => setIsVideoSelected(value)}
- />
)}
</div>
</div>
diff --git a/app/components/ui/editor/VideosMenu.tsx b/app/components/ui/editor/VideosMenu.tsx
index a8722ec..9fbe6c5 100644
--- a/app/components/ui/editor/VideosMenu.tsx
+++ b/app/components/ui/editor/VideosMenu.tsx
@@ -258,118 +258,116 @@ export function VideosMenu({
)}
</Button>
- <AnimatePresence mode="popLayout">
- {videos.map((video) => (
- <motion.div
- key={video.id}
- layout
- initial={{ opacity: 0, y: 10 }}
- animate={{ opacity: 1, y: 0 }}
- exit={{ opacity: 0, x: -20, scale: 0.95 }}
- className={`group relative rounded-lg border overflow-hidden transition-all duration-200 aspect-[16/10] w-full bg-[#000] ${videosInTrackIds.includes(video.id)
- ? "border-blue-500 shadow-[0_0_15px_rgba(59,130,246,0.15)]"
- : "border-neutral-800 hover:border-neutral-700"
- }`}
- >
- <div
- className="absolute inset-0 w-full h-full cursor-pointer"
- onClick={() => {
- if (!addingId) {
- videosInTrackIds.includes(video.id)
- ? onRemoveFromTrack?.(video.id)
- : handleAddToTrack(video.id);
- }
- }}
- >
- {video.thumbnailUrl ? (
- <img
- src={video.thumbnailUrl}
- alt={video.fileName}
- className="w-full h-full object-cover transition-transform duration-300 group-hover:scale-105"
- />
- ) : (
- <div className="w-full h-full flex items-center justify-center bg-neutral-950">
- <Icon icon="solar:play-bold" width="32" className="text-neutral-800" />
- </div>
- )}
- </div>
-
- <div className="absolute top-2 right-2 px-1.5 py-0.5 bg-black/80 border border-neutral-800 rounded text-[10px] font-mono text-neutral-400 z-10">
- {formatVideoDuration(video.duration)}
- </div>
-
- <div
- className={`absolute inset-0 flex items-center justify-center transition-opacity z-10 pointer-events-none ${videosInTrackIds.includes(video.id) || addingId === video.id
- ? "opacity-100"
- : "opacity-0 group-hover:opacity-100"
+ <div className="grid grid-cols-2 gap-3">
+ <AnimatePresence mode="popLayout">
+ {videos.map((video) => (
+ <motion.div
+ key={video.id}
+ layout
+ initial={{ opacity: 0, scale: 0.95 }}
+ animate={{ opacity: 1, scale: 1 }}
+ exit={{ opacity: 0, scale: 0.95 }}
+ className={`group flex flex-col rounded-lg border overflow-hidden transition-all duration-200 bg-neutral-950 w-full ${videosInTrackIds.includes(video.id)
+ ? "border-blue-500 shadow-[0_0_15px_rgba(59,130,246,0.15)]"
+ : "border-neutral-800 hover:border-neutral-700"
}`}
>
- {addingId === video.id ? (
- <div className="p-3 rounded-full bg-black/60 backdrop-blur-sm border border-neutral-800">
- <Icon icon="svg-spinners:ring-resize" width="24" className="text-white" />
- </div>
- ) : videosInTrackIds.includes(video.id) ? (
- <div className="p-2.5 rounded-full bg-blue-500/10 backdrop-blur-sm border border-blue-500/50">
- <Icon icon="solar:check-circle-bold" width="28" className="text-white" />
- </div>
- ) : (
- <div className="absolute inset-0 flex items-center justify-center bg-black/30 backdrop-blur-[1px]">
- <div className="flex items-center gap-1 px-3 py-1 bg-white text-black rounded-full shadow-xl">
- <Icon icon="material-symbols:add-rounded" width="16" />
- <span className="text-[11px] font-bold">{t("actions.add")}</span>
+ <div
+ className="relative w-full aspect-video cursor-pointer overflow-hidden border-b border-neutral-800/50 bg-black"
+ onClick={() => {
+ if (!addingId) {
+ videosInTrackIds.includes(video.id)
+ ? onRemoveFromTrack?.(video.id)
+ : handleAddToTrack(video.id);
+ }
+ }}
+ >
+ {video.thumbnailUrl ? (
+ <img
+ src={video.thumbnailUrl}
+ alt="Video thumbnail"
+ className="w-full h-full object-cover transition-transform duration-300 group-hover:scale-105"
+ />
+ ) : (
+ <div className="w-full h-full flex items-center justify-center">
+ <Icon icon="solar:play-bold" width="28" className="text-neutral-800" />
</div>
- </div>
- )}
- </div>
-
- <div className="absolute bottom-0 left-0 right-0 h-1/2 bg-gradient-to-t from-black via-black/80 to-transparent z-10 pointer-events-none" />
+ )}
- <div className="absolute bottom-0 left-0 right-0 p-3 flex items-end justify-between gap-3 z-20">
- <div className="flex-1 min-w-0 flex flex-col gap-0.5">
- <p className="text-xs font-semibold text-white truncate drop-shadow-[0_1px_2px_rgba(0,0,0,0.5)]" title={video.fileName}>
- {video.fileName}
- </p>
- <div className="flex items-center gap-1.5 text-[10px] text-neutral-300 drop-shadow-[0_1px_1px_rgba(0,0,0,0.5)] font-medium">
- <span>{formatFileSize(video.fileSize)}</span>
- <span>•</span>
- <span>{video.width}×{video.height}</span>
+ <div
+ className={`absolute inset-0 flex items-center justify-center transition-opacity z-10 pointer-events-none ${videosInTrackIds.includes(video.id) || addingId === video.id
+ ? "opacity-100"
+ : "opacity-0 group-hover:opacity-100"
+ }`}
+ >
+ {addingId === video.id ? (
+ <div className="p-2.5 rounded-full bg-black/60 backdrop-blur-sm border border-neutral-800">
+ <Icon icon="svg-spinners:ring-resize" width="20" className="text-white" />
+ </div>
+ ) : videosInTrackIds.includes(video.id) ? (
+ <div className="p-2 rounded-full bg-blue-500/20 backdrop-blur-sm border border-blue-500/50">
+ <Icon icon="solar:check-circle-bold" width="24" className="text-blue-400" />
+ </div>
+ ) : (
+ <div className="absolute inset-0 flex items-center justify-center bg-black/20 backdrop-blur-[1px]">
+ <div className="flex items-center gap-1 px-3 py-1.5 bg-white text-black rounded-full shadow-xl">
+ <Icon icon="material-symbols:add-rounded" width="16" />
+ <span className="text-[11px] font-bold">{t("actions.add")}</span>
+ </div>
+ </div>
+ )}
</div>
</div>
- <div className="flex items-center gap-0.5 shrink-0 pointer-events-auto opacity-0 group-hover:opacity-100 transition-opacity duration-150">
- <TooltipAction label={video.hasAudio === false ? t("actions.unmute") : t("actions.mute")}>
- <button
- onClick={() => handleToggleAudio(video.id, video.hasAudio)}
- disabled={video.originalHasAudio === false}
- className={`p-1.5 rounded-md backdrop-blur-sm border transition-colors ${video.originalHasAudio === false
- ? "text-neutral-500 border-transparent cursor-not-allowed"
- : video.hasAudio === false
- ? "text-red-400 bg-red-500/20 border-red-500/50"
- : "text-neutral-300 bg-neutral-900/50 hover:text-white hover:bg-neutral-800 border-neutral-700/50"
- }`}
- >
- <Icon icon={video.hasAudio === false ? "solar:volume-cross-outline" : "solar:volume-loud-outline"} width="15" />
- </button>
- </TooltipAction>
+ <div className="flex items-center justify-between px-2.5">
+ <span className="text-[11px] font-mono font-medium text-neutral-400">
+ {formatVideoDuration(video.duration)}
+ </span>
+
+ <div className="flex items-center gap-1">
+ <TooltipAction label={video.hasAudio === false ? t("actions.unmute") : t("actions.mute")}>
+ <button
+ onClick={(e) => {
+ e.stopPropagation();
+ handleToggleAudio(video.id, video.hasAudio);
+ }}
+ disabled={video.originalHasAudio === false}
+ className={`p-1.5 rounded-md transition-colors ${video.originalHasAudio === false
+ ? "text-neutral-500 cursor-not-allowed"
+ : video.hasAudio === false
+ ? "text-red-400 hover:bg-red-500/10"
+ : "text-neutral-400 hover:text-white hover:bg-neutral-800"
+ }`}
+ >
+ <Icon
+ icon={video.hasAudio === false ? "solar:volume-cross-outline" : "solar:volume-loud-outline"}
+ width="14"
+ />
+ </button>
+ </TooltipAction>
- <TooltipAction label={t("actions.delete")}>
- <button
- onClick={() => handleDelete(video.id)}
- disabled={deletingId === video.id}
- className="p-1.5 rounded-md backdrop-blur-sm bg-neutral-900/50 hover:text-red-400 hover:bg-red-500/20 border border-neutral-700/50 hover:border-red-500/50 text-neutral-300 transition-colors disabled:opacity-50"
- >
- {deletingId === video.id ? (
- <Icon icon="svg-spinners:ring-resize" width="15" />
- ) : (
- <Icon icon="solar:trash-bin-trash-outline" width="15" />
- )}
- </button>
- </TooltipAction>
+ <TooltipAction label={t("actions.delete")}>
+ <button
+ onClick={(e) => {
+ e.stopPropagation();
+ handleDelete(video.id);
+ }}
+ disabled={deletingId === video.id}
+ className="p-1.5 rounded-md text-neutral-400 hover:text-red-400 hover:bg-red-500/10 transition-colors disabled:opacity-50"
+ >
+ {deletingId === video.id ? (
+ <Icon icon="svg-spinners:ring-resize" width="14" />
+ ) : (
+ <Icon icon="solar:trash-bin-trash-outline" width="14" />
+ )}
+ </button>
+ </TooltipAction>
+ </div>
</div>
- </div>
- </motion.div>
- ))}
- </AnimatePresence>
+ </motion.div>
+ ))}
+ </AnimatePresence>
+ </div>
</div>
)}
</div>
diff --git a/app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsx b/app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsx
index 6a3beeb..de1bb8c 100644
--- a/app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsx
+++ b/app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsx
@@ -63,7 +63,7 @@ const DEFAULT_CAMERA_POS: [number, number, number] = [0, 0, 1.5];
useGLTF.preload(MODEL_URL, DRACO_URL);
-function ModelScene({
+export function DoubleIPhoneScene({
imageUrl,
imageMaskConfig,
cropArea,
@@ -526,7 +526,7 @@ function CanvasWithLoader(
}}
>
<Suspense fallback={null}>
- <ModelScene {...props} onLoaded={handleLoaded} />
+ <DoubleIPhoneScene {...props} onLoaded={handleLoaded} />
</Suspense>
</Canvas>
{!loaded && (
diff --git a/app/components/ui/editor/mockups-3d/IPadMini63DViewer.tsx b/app/components/ui/editor/mockups-3d/IPadMini63DViewer.tsx
index 6d437c8..6ffd602 100644
--- a/app/components/ui/editor/mockups-3d/IPadMini63DViewer.tsx
+++ b/app/components/ui/editor/mockups-3d/IPadMini63DViewer.tsx
@@ -60,33 +60,9 @@ const TARGET_H = 1500;
useGLTF.preload(MODEL_URL, DRACO_URL);
-function ModelScene({
- 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,
-}: Props & {
- rootRef: React.MutableRefObject<THREE.Group | null>;
- cameraRef: React.MutableRefObject<THREE.PerspectiveCamera | null>;
- onLoaded?: () => void;
-}) {
+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,
+}: 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);
@@ -523,7 +499,7 @@ function CanvasWithLoader(
}}
>
<Suspense fallback={null}>
- <ModelScene {...props} onLoaded={handleLoaded} />
+ <IPadMiniScene {...props} onLoaded={handleLoaded} />
</Suspense>
</Canvas>
{!loaded && (
diff --git a/app/components/ui/editor/mockups-3d/IPhone13ProMax3DViewer.tsx b/app/components/ui/editor/mockups-3d/IPhone13ProMax3DViewer.tsx
index b5ae39f..f585727 100644
--- a/app/components/ui/editor/mockups-3d/IPhone13ProMax3DViewer.tsx
+++ b/app/components/ui/editor/mockups-3d/IPhone13ProMax3DViewer.tsx
@@ -45,8 +45,8 @@ interface Props {
onSelectChange?: (isSelected: boolean) => void;
}
-const TEX_W = 1284 * 2;
-const TEX_H = 2778 * 2;
+const TEX_W = 1284;
+const TEX_H = 2778;
const PLACEHOLDER_PHONE_URL = "/images/mockups-3d/placeholder-phone.avif";
const DEFAULT_CAMERA_POS: [number, number, number] = [0, 0, 1.5];
const DRACO_URL = "/draco/";
@@ -108,17 +108,17 @@ interface GLTFMaterials {
"Material.002": THREE.Material;
}
-function ModelScene({
- imageUrl,
- imageMaskConfig,
- cropArea,
- initialRotationX,
- initialRotationY,
- initialRotationZ,
+export function IPhone13ProMaxScene({
+ imageUrl = null,
+ imageMaskConfig = null,
+ cropArea = null,
+ initialRotationX = -58.23,
+ initialRotationY = -29.82,
+ initialRotationZ = 0,
onRotationChange,
rootRef,
cameraRef,
- zoom,
+ zoom = 1,
onApi,
onLoaded,
videoElement,
@@ -131,16 +131,16 @@ function ModelScene({
isSelected = false,
isHovered = false,
}: {
- imageUrl: string | null;
- imageMaskConfig: ImageMaskConfigLike | null;
- cropArea: { x: number; y: number; width: number; height: number } | null;
- initialRotationX: number;
- initialRotationY: number;
- initialRotationZ: number;
+ 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;
rootRef: React.MutableRefObject<THREE.Group | null>;
cameraRef: React.MutableRefObject<THREE.PerspectiveCamera | null>;
- zoom: number;
+ zoom?: number;
onApi?: (api: IPhone13ProMax3DApi | null) => void;
onLoaded?: () => void;
videoElement?: HTMLVideoElement | null;
@@ -694,7 +694,7 @@ function CanvasWithLoader({
}}
>
<Suspense fallback={null}>
- <ModelScene
+ <IPhone13ProMaxScene
imageUrl={imageUrl}
imageMaskConfig={imageMaskConfig}
cropArea={cropArea}
@@ -804,8 +804,6 @@ export function IPhone13ProMax3DViewer({
transformOrigin: "top center",
width: 480,
height: 1000 + (hasShadow ? computedBlur * 0.8 : 0),
- marginBottom: "300px",
- marginRight: "250px",
}}
>
<div style={{ position: "relative", width: 480, height: 1000 }}>
diff --git a/app/components/ui/editor/mockups-3d/IPhone17ProMax3DViewer.tsx b/app/components/ui/editor/mockups-3d/IPhone17ProMax3DViewer.tsx
index 2457121..f13e4a0 100644
--- a/app/components/ui/editor/mockups-3d/IPhone17ProMax3DViewer.tsx
+++ b/app/components/ui/editor/mockups-3d/IPhone17ProMax3DViewer.tsx
@@ -45,25 +45,58 @@ interface Props {
onSelectChange?: (isSelected: boolean) => void;
}
-const TEX_W = 1284 * 2;
-const TEX_H = 2778 * 2;
+const TEX_W = 1284;
+const TEX_H = 2778;
const PLACEHOLDER_PHONE_URL = "/images/mockups-3d/placeholder-phone.avif";
const DEFAULT_CAMERA_POS: [number, number, number] = [0, 0, 1.5];
const DRACO_URL = "/draco/";
useGLTF.preload("/models/iphone-17-pro-max.glb", DRACO_URL);
-function ModelScene({
- imageUrl, imageMaskConfig, cropArea, initialRotationX, initialRotationY, initialRotationZ, onRotationChange,
- rootRef, cameraRef, zoom, onApi, onLoaded, videoElement, shadowIntensity = 0, shadowColor = "#000000",
- autoRotate = false, rotationSpeed = 3.5, glow = 1.0, environment = "studio", isSelected = false, isHovered = false,
+export function IPhone17ProMaxScene({
+ imageUrl = null,
+ imageMaskConfig = null,
+ cropArea = null,
+ 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: 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;
- rootRef: React.MutableRefObject<THREE.Group | null>; cameraRef: React.MutableRefObject<THREE.PerspectiveCamera | null>; zoom: number;
- onApi?: (api: IPhone17ProMax3DApi | null) => void; onLoaded?: () => void; videoElement?: HTMLVideoElement | null;
- shadowIntensity?: number; shadowColor?: string; autoRotate?: boolean; rotationSpeed?: number; glow?: number; environment?: EnvironmentPreset;
- isSelected?: boolean; isHovered?: boolean;
+ 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;
+ rootRef: React.MutableRefObject<THREE.Group | null>;
+ cameraRef: React.MutableRefObject<THREE.PerspectiveCamera | null>;
+ zoom?: number;
+ onApi?: (api: IPhone17ProMax3DApi | null) => void;
+ onLoaded?: () => void;
+ videoElement?: HTMLVideoElement | null;
+ shadowIntensity?: number;
+ shadowColor?: string;
+ autoRotate?: boolean;
+ rotationSpeed?: number;
+ glow?: number;
+ environment?: EnvironmentPreset;
+ isSelected?: boolean;
+ isHovered?: boolean;
}) {
const { gl, scene, camera, invalidate, size } = useThree();
const gltf = useGLTF("/models/iphone-17-pro-max.glb", DRACO_URL);
@@ -495,7 +528,7 @@ function CanvasWithLoader({
}}
>
<Suspense fallback={null}>
- <ModelScene
+ <IPhone17ProMaxScene
imageUrl={imageUrl} imageMaskConfig={imageMaskConfig} cropArea={cropArea} initialRotationX={initialRotationX}
initialRotationY={initialRotationY} initialRotationZ={initialRotationZ} onRotationChange={onRotationChange}
rootRef={rootRef} cameraRef={cameraRef} zoom={zoom} onApi={onApi} onLoaded={handleLoaded} videoElement={videoElement}
diff --git a/app/components/ui/editor/mockups-3d/Laptop3DViewer.tsx b/app/components/ui/editor/mockups-3d/Laptop3DViewer.tsx
index 75cef11..4856355 100644
--- a/app/components/ui/editor/mockups-3d/Laptop3DViewer.tsx
+++ b/app/components/ui/editor/mockups-3d/Laptop3DViewer.tsx
@@ -15,7 +15,6 @@ import {
import type { OrbitControls as OrbitControlsType } from 'three-stdlib';
import { EnvironmentPreset, HDRI_FILES } 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";
import { OutlinePass } from "three/examples/jsm/postprocessing/OutlinePass.js";
@@ -23,8 +22,8 @@ import { OutputPass } from "three/examples/jsm/postprocessing/OutputPass.js";
THREE.Cache.enabled = true;
-const LAPTOP_W = 1500;
-const LAPTOP_H = 1035;
+export const LAPTOP_W = 1500;
+export const LAPTOP_H = 1035;
const RENDER_MULTIPLIER = 3;
const RENDER_W = LAPTOP_W * RENDER_MULTIPLIER;
const RENDER_H = LAPTOP_H * RENDER_MULTIPLIER;
@@ -86,17 +85,9 @@ function loadLaptopGltf(): Promise<THREE.Group> {
return gltfCachePromise;
}
-function ModelScene({
- 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,
-}: Props & {
- rootRef: React.MutableRefObject<THREE.Group | null>;
- cameraRef: React.MutableRefObject<THREE.PerspectiveCamera | null>;
- onLoaded?: () => void;
-}) {
+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,
+}: 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);
@@ -346,22 +337,23 @@ function ModelScene({
applyTexture();
}, [applyTexture]);
+ const initialOpeningRef = useRef(openingProgress);
+ const onLoadedRef = useRef(onLoaded);
+ const applyVideoRef = useRef(applyVideoTextureIfReady);
+
+ useLayoutEffect(() => {
+ onLoadedRef.current = onLoaded;
+ applyVideoRef.current = applyVideoTextureIfReady;
+ });
+
useEffect(() => {
let isMounted = true;
- const darkPlasticMaterial = new THREE.MeshStandardMaterial({
- color: 0x000000,
- roughness: 0.9,
- metalness: 0.9
- });
+ const darkPlasticMaterial = new THREE.MeshStandardMaterial({ color: 0x000000, roughness: 0.9, metalness: 0.9 });
const cameraMaterial = new THREE.MeshBasicMaterial({ color: 0x333333 });
const logoMaterial = new THREE.MeshBasicMaterial({ color: 0xffffff });
- const baseMetalMaterial = new THREE.MeshStandardMaterial({
- color: 0xcecfd3,
- roughness: 0.25,
- metalness: 0.85
- });
+ const baseMetalMaterial = new THREE.MeshStandardMaterial({ color: 0xcecfd3, roughness: 0.25, metalness: 0.85 });
- const tStart = Math.max(0, Math.min(1, openingProgress));
+ const tStart = Math.max(0, Math.min(1, initialOpeningRef.current));
const screenMaterial = new THREE.MeshBasicMaterial({
map: null,
transparent: true,
@@ -371,14 +363,12 @@ function ModelScene({
toneMapped: false,
});
screenMatRef.current = screenMaterial;
- applyVideoTextureIfReady();
+
+ applyVideoRef.current();
const textLoader = new THREE.TextureLoader();
- const keyboardMaterial = new THREE.MeshBasicMaterial({
- color: 0xffffff,
- transparent: true,
- toneMapped: false
- });
+ const keyboardMaterial = new THREE.MeshBasicMaterial({ color: 0xffffff, transparent: true, toneMapped: false });
+
textLoader.load("/images/pages/keyboard-overlay.png", (tex) => {
tex.anisotropy = gl.capabilities.getMaxAnisotropy();
keyboardMaterial.alphaMap = tex;
@@ -392,7 +382,7 @@ function ModelScene({
setTimeout(() => {
if (!isMounted) return;
applyTextureRef.current();
- onLoaded?.();
+ onLoadedRef.current?.();
invalidate();
}, 50);
};
@@ -422,12 +412,13 @@ function ModelScene({
if (!(obj instanceof THREE.Mesh)) return;
const m = obj as THREE.Mesh;
if (m.name === "base") m.material = baseMetalMaterial;
- else if (["legs", "keyboard", "inner"].includes(m.name))
- m.material = darkPlasticMaterial;
+ else if (["legs", "keyboard", "inner"].includes(m.name)) m.material = darkPlasticMaterial;
});
}
});
+ lidGroup.rotation.x = lerp(LID_CLOSED_X, LID_OPEN_X, tStart);
+
root.add(lidGroup);
root.add(bottomGroup);
lidGroupRef.current = lidGroup;
@@ -444,7 +435,7 @@ function ModelScene({
new THREE.PlaneGeometry(screenSize[0], screenSize[1]),
darkPlasticMaterial
);
- darkScreen.position.set(0, 10.5, -0.111);
+ darkScreen.position.set(0, 10.5, -0.15);
darkScreen.rotation.set(Math.PI, Math.PI, 0);
lidGroup.add(darkScreen);
@@ -473,7 +464,7 @@ function ModelScene({
screenMatRef.current.dispose();
}
};
- }, [openingProgress, applyVideoTextureIfReady, onLoaded, gl, invalidate]);
+ }, [gl, invalidate]);
const prevRotationRef = useRef<{ x: number; y: number } | null>(null);
@@ -645,7 +636,7 @@ function CanvasWithLoader(
}}
>
<Suspense fallback={null}>
- <ModelScene {...props} onLoaded={handleLoaded} />
+ <LaptopScene {...props} onLoaded={handleLoaded} />
</Suspense>
</Canvas>
{!loaded && (
diff --git a/app/components/ui/editor/mockups-3d/Mockup3DFrame.tsx b/app/components/ui/editor/mockups-3d/Mockup3DFrame.tsx
new file mode 100644
index 0000000..a43d5ba
--- /dev/null
+++ b/app/components/ui/editor/mockups-3d/Mockup3DFrame.tsx
@@ -0,0 +1,213 @@
+"use client";
+import { useEffect, useRef, useState } from "react";
+import * as THREE from "three";
+import { Mockup3DStage, type Mockup3DStageProps } from "./Mockup3DStage";
+import { GetMediaMaskStyles } from "@/lib/media-mask.utils";
+import { PHONE_W, PHONE_H, parseShadowColor } from "@/lib/phone3d.utils";
+import { LAPTOP_W, LAPTOP_H } from "./Laptop3DViewer";
+import type { ImageDeviceId } from "@/types/mockup.types";
+
+type OverlayMode =
+ | { kind: "inset"; inset: number; pointerEvents: "auto" | "none" }
+ | { kind: "fixed"; pointerEvents: "auto" | "none" }
+ | { kind: "centered"; size: number; pointerEvents: "auto" | "none" };
+
+interface DeviceLayout {
+ width: number;
+ height: number;
+ marginTop?: string;
+ marginLeft?: string;
+ marginRight?: string;
+ marginBottom?: string;
+ overlay: OverlayMode;
+ maskInset: number;
+}
+
+const DEVICE_LAYOUT: Record<ImageDeviceId, DeviceLayout> = {
+ "iphone-13-pro-max": {
+ width: 480, height: 1000,
+ marginTop: "100px", marginRight: "0",
+ overlay: { kind: "inset", inset: 400, pointerEvents: "none" },
+ maskInset: 400,
+ },
+ "double_iphone_13_pro": {
+ width: PHONE_W, height: PHONE_H,
+ marginTop: "220px", marginLeft: "140px",
+ overlay: { kind: "inset", inset: 400, pointerEvents: "auto" },
+ maskInset: 400,
+ },
+ "laptop": {
+ width: LAPTOP_W, height: LAPTOP_H,
+ marginTop: "250px",
+ overlay: { kind: "fixed", pointerEvents: "none" },
+ maskInset: 0,
+ },
+ "iphone-17-pro-max": {
+ width: 480, height: 1000,
+ marginTop: "100px", marginLeft: "170px",
+ overlay: { kind: "inset", inset: 400, pointerEvents: "none" },
+ maskInset: 400,
+ },
+ "ipad_mini_6_2021": {
+ width: 750, height: 1000,
+ marginTop: "100px", marginLeft: "100px",
+ overlay: { kind: "inset", inset: 300, pointerEvents: "none" },
+ maskInset: 300,
+ },
+ "iphone": {
+ width: PHONE_W, height: PHONE_H,
+ marginTop: "220px", marginLeft: "140px",
+ overlay: { kind: "centered", size: 1400, pointerEvents: "auto" },
+ maskInset: 300,
+ },
+ "phone": {
+ width: PHONE_W, height: PHONE_H,
+ marginTop: "220px", marginLeft: "140px",
+ overlay: { kind: "centered", size: 1400, pointerEvents: "auto" },
+ maskInset: 300,
+ },
+};
+
+interface FrameProps extends Mockup3DStageProps {
+ device: ImageDeviceId;
+}
+
+export function Mockup3DFrame({ device, ...stageProps }: FrameProps) {
+ const layout = DEVICE_LAYOUT[device];
+ const rootRef = useRef<THREE.Group | null>(null);
+ const cameraRef = useRef<THREE.PerspectiveCamera | null>(null);
+ const canvasElRef = useRef<HTMLCanvasElement | null>(null);
+ const raycasterRef = useRef(new THREE.Raycaster());
+ const [grabbing, setGrabbing] = useState(false);
+ const [modelHovered, setModelHovered] = useState(false);
+
+ const shadowIntensity = stageProps.shadowIntensity ?? 0;
+ const shadowColor = stageProps.shadowColor ?? "#000000";
+ const t = Math.max(0, Math.min(1, shadowIntensity));
+ const tEased = t * t;
+ const computedBlur = tEased * 60;
+ const computedOpacity = tEased * 0.7;
+ const shadowRgba = shadowColor.startsWith("#") ? parseShadowColor(shadowColor, computedOpacity) : shadowColor;
+ const hasShadow = t > 0.01;
+
+ const maskStyle = GetMediaMaskStyles(stageProps.imageMaskConfig ?? null, {
+ inset: layout.maskInset,
+ deviceWidth: layout.width,
+ deviceHeight: layout.height,
+ });
+
+ const hitsModel = (clientX: number, clientY: number): boolean => {
+ const canvas = canvasElRef.current;
+ const cam = cameraRef.current;
+ const model = rootRef.current;
+ if (!canvas || !cam || !model) return false;
+ const rect = canvas.getBoundingClientRect();
+ if (!rect.width || !rect.height) return false;
+ const x = ((clientX - rect.left) / rect.width) * 2 - 1;
+ const y = -((clientY - rect.top) / rect.height) * 2 + 1;
+ raycasterRef.current.setFromCamera(new THREE.Vector2(x, y), cam);
+ return raycasterRef.current.intersectObject(model, true).length > 0;
+ };
+
+ const handleMount = (canvas: HTMLCanvasElement) => {
+ canvasElRef.current = canvas;
+ stageProps.onMount?.(canvas);
+ };
+
+ useEffect(() => {
+ const onWinPointerUp = () => setGrabbing(false);
+ window.addEventListener("pointerup", onWinPointerUp);
+ return () => window.removeEventListener("pointerup", onWinPointerUp);
+ }, []);
+
+ const overlayStyle: React.CSSProperties =
+ layout.overlay.kind === "inset"
+ ? { position: "absolute", inset: `-${layout.overlay.inset}px`, zIndex: 2, overflow: "visible" }
+ : layout.overlay.kind === "fixed"
+ ? { position: "absolute", left: 0, top: 0, width: layout.width, height: layout.height, zIndex: 2, overflow: "visible" }
+ : {
+ position: "absolute", top: "50%", left: "50%",
+ width: layout.overlay.size, height: layout.overlay.size,
+ transform: "translate(-50%, -50%)", zIndex: 2, overflow: "visible",
+ };
+
+ return (
+ <div
+ style={{
+ display: "inline-block",
+ transformOrigin: "top center",
+ width: layout.width,
+ height: layout.height + (hasShadow ? computedBlur * 0.8 : 0),
+ marginTop: layout.marginTop,
+ marginLeft: layout.marginLeft,
+ marginRight: layout.marginRight,
+ marginBottom: layout.marginBottom,
+ }}
+ >
+ <div style={{ position: "relative", width: layout.width, height: layout.height }}>
+ {hasShadow && (
+ <div
+ aria-hidden
+ style={{
+ position: "absolute",
+ bottom: -(computedBlur * 0.5),
+ left: `${20 + tEased * 5}%`,
+ width: `${60 - tEased * 10}%`,
+ height: Math.max(4, computedBlur * 0.55),
+ borderRadius: "50%",
+ background: shadowRgba,
+ filter: `blur(${Math.max(2, computedBlur * 0.6)}px)`,
+ zIndex: 0,
+ pointerEvents: "none",
+ }}
+ />
+ )}
+ <div
+ style={{
+ ...overlayStyle,
+ cursor: grabbing ? "grabbing" : modelHovered ? "grab" : "default",
+ transition: "filter 0.15s ease",
+ pointerEvents: layout.overlay.pointerEvents,
+ ...maskStyle,
+ }}
+ onPointerDownCapture={(e) => {
+ const hit = hitsModel(e.clientX, e.clientY);
+ if (!hit) {
+ stageProps.onSelectChange?.(false);
+ e.stopPropagation();
+ return;
+ }
+ stageProps.onSelectChange?.(true);
+ setGrabbing(true);
+ }}
+ onPointerMove={(e) => {
+ if (!grabbing) {
+ const isCurrentlyHovering = hitsModel(e.clientX, e.clientY);
+ if (isCurrentlyHovering !== modelHovered) {
+ setModelHovered(isCurrentlyHovering);
+ stageProps.onHoverChange?.(isCurrentlyHovering);
+ }
+ }
+ }}
+ onPointerUp={() => setGrabbing(false)}
+ onPointerLeave={() => {
+ setGrabbing(false);
+ if (modelHovered) {
+ setModelHovered(false);
+ stageProps.onHoverChange?.(false);
+ }
+ }}
+ >
+ <Mockup3DStage
+ {...stageProps}
+ device={device}
+ rootRef={rootRef}
+ cameraRef={cameraRef}
+ onMount={handleMount}
+ isHovered={modelHovered}
+ />
+ </div>
+ </div>
+ </div>
+ );
+}
\ No newline at end of file
diff --git a/app/components/ui/editor/mockups-3d/Mockup3DStage.tsx b/app/components/ui/editor/mockups-3d/Mockup3DStage.tsx
new file mode 100644
index 0000000..cd1ee2e
--- /dev/null
+++ b/app/components/ui/editor/mockups-3d/Mockup3DStage.tsx
@@ -0,0 +1,132 @@
+"use client";
+import { Canvas } from "@react-three/fiber";
+import { Suspense, useRef, useState } from "react";
+import * as THREE from "three";
+import { IPhone13ProMax3DApi, IPhone13ProMaxScene } from "./IPhone13ProMax3DViewer";
+import { DoubleIPhone3DApi, DoubleIPhoneScene } from "./DoubleIPhone3DViewer";
+import { Phone3DApi, Phone3DScene } from "./Phone3DViewer";
+import { Laptop3DApi, LaptopScene } from "./Laptop3DViewer";
+import { IPhone17ProMax3DApi, IPhone17ProMaxScene } from "./IPhone17ProMax3DViewer";
+import { IPadMini63DApi, IPadMiniScene } from "./IPadMini63DViewer";
+import { PHONE_W, PHONE_H, ImageMaskConfigLike } from "@/lib/phone3d.utils";
+import type { ImageDeviceId } from "@/types/mockup.types";
+import { EnvironmentPreset } from "@/lib/viewer-controls3d";
+
+export type Mockup3DApi =
+ | IPhone13ProMax3DApi
+ | DoubleIPhone3DApi
+ | Phone3DApi
+ | Laptop3DApi
+ | IPhone17ProMax3DApi
+ | IPadMini63DApi;
+
+export interface Mockup3DStageProps {
+ imageUrl?: string | null;
+ imageMaskConfig?: ImageMaskConfigLike | null;
+ cropArea?: { x: number; y: number; width: number; height: number } | null;
+ initialRotationX?: number;
+ initialRotationY?: number;
+ initialRotationZ?: number;
+ openingProgress?: number; // solo laptop
+ modelUrl?: string; // solo devices genéricos (phone/iphone)
+ onRotationChange?: (rx: number, ry: number) => void;
+ onMount?: (canvas: HTMLCanvasElement) => void;
+ onApi?: (api: Mockup3DApi | null) => void;
+ scale?: number;
+ zoom?: number;
+ shadowIntensity?: number;
+ shadowColor?: string;
+ videoElement?: HTMLVideoElement | null;
+ autoRotate?: boolean;
+ rotationSpeed?: number;
+ glow?: number;
+ environment?: EnvironmentPreset;
+ isSelected?: boolean;
+ isHovered?: boolean;
+ onHoverChange?: (isHovered: boolean) => void;
+ onSelectChange?: (isSelected: boolean) => void;
+}
+
+interface StageProps extends Mockup3DStageProps {
+ device: ImageDeviceId;
+ rootRef?: React.MutableRefObject<THREE.Group | null>;
+ cameraRef?: React.MutableRefObject<THREE.PerspectiveCamera | null>;
+ onLoadedChange?: (loaded: boolean) => void;
+}
+
+export function Mockup3DStage({ device, rootRef: externalRootRef, cameraRef: externalCameraRef, onLoadedChange, ...props }: StageProps) {
+ const internalRootRef = useRef<THREE.Group | null>(null);
+ const internalCameraRef = useRef<THREE.PerspectiveCamera | null>(null);
+ const rootRef = externalRootRef ?? internalRootRef;
+ const cameraRef = externalCameraRef ?? internalCameraRef;
+ const canvasElRef = useRef<HTMLCanvasElement | null>(null);
+
+ const [loaded, setLoaded] = useState(false);
+ const [prevDevice, setPrevDevice] = useState(device);
+ if (device !== prevDevice) {
+ setPrevDevice(device);
+ setLoaded(false);
+ onLoadedChange?.(false);
+ }
+
+ const markLoaded = () => {
+ setLoaded(true);
+ onLoadedChange?.(true);
+ };
+
+ const handleMount = (canvas: HTMLCanvasElement) => {
+ canvasElRef.current = canvas;
+ props.onMount?.(canvas);
+ };
+
+ return (
+ <>
+ <Canvas
+ style={{ width: "100%", height: "100%", overflow: "visible" }}
+ gl={{
+ antialias: true,
+ alpha: true,
+ preserveDrawingBuffer: true,
+ powerPreference: "high-performance",
+ failIfMajorPerformanceCaveat: false,
+ }}
+ dpr={3}
+ frameloop={props.videoElement ? "always" : "demand"}
+ resize={{ scroll: false, debounce: { scroll: 0, resize: 0 } }}
+ onCreated={({ gl, scene }) => {
+ gl.outputColorSpace = THREE.SRGBColorSpace;
+ gl.toneMapping = THREE.NeutralToneMapping;
+ gl.toneMappingExposure = 1.0;
+ scene.environmentIntensity = 1.6;
+ handleMount(gl.domElement);
+ }}
+ >
+ <Suspense fallback={null}>
+ {device === "iphone-13-pro-max" && (
+ <IPhone13ProMaxScene {...props} rootRef={rootRef} cameraRef={cameraRef} onLoaded={markLoaded} />
+ )}
+ {device === "double_iphone_13_pro" && (
+ <DoubleIPhoneScene {...props} rootRef={rootRef} cameraRef={cameraRef} onLoaded={markLoaded} />
+ )}
+ {device === "iphone-17-pro-max" && (
+ <IPhone17ProMaxScene {...props} rootRef={rootRef} cameraRef={cameraRef} onLoaded={markLoaded} />
+ )}
+ {device === "laptop" && (
+ <LaptopScene {...props} rootRef={rootRef} cameraRef={cameraRef} onLoaded={markLoaded} />
+ )}
+ {device === "ipad_mini_6_2021" && (
+ <IPadMiniScene {...props} rootRef={rootRef} cameraRef={cameraRef} onLoaded={markLoaded} />
+ )}
+ {(device === "iphone" || device === "phone") && (
+ <Phone3DScene {...props} rootRef={rootRef} cameraRef={cameraRef} onLoaded={markLoaded} />
+ )}
+ </Suspense>
+ </Canvas>
+ {!loaded && (
+ <div className="absolute inset-0 flex items-center justify-center pointer-events-none" style={{ zIndex: 4 }}>
+ <div className="w-6 h-6 border-2 border-white/20 border-t-white/60 rounded-full animate-spin" />
+ </div>
+ )}
+ </>
+ );
+}
\ No newline at end of file
diff --git a/app/components/ui/editor/mockups-3d/Phone3DViewer.tsx b/app/components/ui/editor/mockups-3d/Phone3DViewer.tsx
index 44cbc2f..ab21cab 100644
--- a/app/components/ui/editor/mockups-3d/Phone3DViewer.tsx
+++ b/app/components/ui/editor/mockups-3d/Phone3DViewer.tsx
@@ -104,33 +104,9 @@ function applyMetalMaterial(m: THREE.MeshStandardMaterial, matName: string): voi
m.envMapIntensity = 2.0;
}
}
-
-function ModelScene({
- 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,
-}: Props & {
- rootRef: React.MutableRefObject<THREE.Group | null>;
- cameraRef: React.MutableRefObject<THREE.PerspectiveCamera | null>;
- onLoaded?: () => void;
-}) {
+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,
+}: 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);
const screenMatRef = useRef<THREE.MeshBasicMaterial | null>(null);
@@ -744,7 +720,7 @@ function CanvasWithLoader(
}}
>
<Suspense fallback={null}>
- <ModelScene {...props} onLoaded={handleLoaded} />
+ <Phone3DScene {...props} onLoaded={handleLoaded} />
</Suspense>
</Canvas>
{!loaded && (
diff --git a/app/contexts/Mockup3dContext.tsx b/app/contexts/Mockup3dContext.tsx
index 7ffefb9..f547ecb 100644
--- a/app/contexts/Mockup3dContext.tsx
+++ b/app/contexts/Mockup3dContext.tsx
@@ -35,9 +35,9 @@ interface Mockup3dState {
/** Perspective (px) for the 3D transform on the phone mockup */
imagePhonePerspective: number;
setImagePhonePerspective: (v: number) => void;
- /** Which 3D device model is active: the default phone JSON, iPhone 15 Pro Max, Samsung S25 Ultra, or single macOS laptop */
- imagePhoneDevice: 'phone' | 'iphone' | 'iphone-13-pro-max' | 'iphone-17-pro-max' | 'double_iphone_13_pro' | 'samsung' | 'laptop' | 'ipad_mini_6_2021';
- setImagePhoneDevice: (d: 'phone' | 'iphone' | 'iphone-13-pro-max' | 'iphone-17-pro-max' | 'double_iphone_13_pro' | 'samsung' | 'laptop' | 'ipad_mini_6_2021') => void;
+ /** Which 3D device model is active: the default phone JSON, iPhone 15 Pro Max, or single macOS laptop */
+ imagePhoneDevice: 'phone' | 'iphone' | 'iphone-13-pro-max' | 'iphone-17-pro-max' | 'double_iphone_13_pro' | 'laptop' | 'ipad_mini_6_2021';
+ setImagePhoneDevice: (d: 'phone' | 'iphone' | 'iphone-13-pro-max' | 'iphone-17-pro-max' | 'double_iphone_13_pro' | 'laptop' | 'ipad_mini_6_2021') => void;
imagePhonePresetId: string;
setImagePhonePresetId: (id: string) => void;
/** Laptop opening animation progress (0 = closed, 1 = fully open) */
@@ -68,7 +68,7 @@ export function Mockup3dProvider({ children }: { children: ReactNode }) {
const [imagePhoneRotY, setImagePhoneRotY] = useState(0);
const [imagePhoneRotZ, setImagePhoneRotZ] = useState(0);
const [imagePhonePerspective, setImagePhonePerspective] = useState(600);
- const [imagePhoneDevice, setImagePhoneDevice] = useState<'phone' | 'iphone' | 'iphone-13-pro-max' | 'iphone-17-pro-max' | 'double_iphone_13_pro' | 'samsung' | 'laptop' | 'ipad_mini_6_2021'>('phone');
+ const [imagePhoneDevice, setImagePhoneDevice] = useState<'phone' | 'iphone' | 'iphone-13-pro-max' | 'iphone-17-pro-max' | 'double_iphone_13_pro' | 'laptop' | 'ipad_mini_6_2021'>('phone');
const [imagePhonePresetId, setImagePhonePresetId] = useState('custom');
const [imagePhoneOpening, setImagePhoneOpening] = useState(1);
const [imagePhoneShadow, setImagePhoneShadow] = useState(0.6);
diff --git a/hooks/useImageProjects.ts b/hooks/useImageProjects.ts
index 3cc5496..a1fc6bc 100644
--- a/hooks/useImageProjects.ts
+++ b/hooks/useImageProjects.ts
@@ -50,7 +50,7 @@ interface ImageProjectState {
imagePhoneRotY: number;
imagePhoneRotZ: number;
imagePhonePerspective: number;
- imagePhoneDevice: 'phone' | 'iphone' | 'iphone-13-pro-max' | 'iphone-17-pro-max' | 'double_iphone_13_pro' | 'samsung' | 'laptop' | 'ipad_mini_6_2021';
+ imagePhoneDevice: 'phone' | 'iphone' | 'iphone-13-pro-max' | 'iphone-17-pro-max' | 'double_iphone_13_pro' | 'laptop' | 'ipad_mini_6_2021';
imagePhonePresetId: string;
imagePhoneOpening: number;
imagePhoneShadow: number;
diff --git a/types/editor-state.types.ts b/types/editor-state.types.ts
index 4d33387..3f2a68c 100644
--- a/types/editor-state.types.ts
+++ b/types/editor-state.types.ts
@@ -47,7 +47,7 @@ export interface EditorState {
imagePhoneRotY: number;
imagePhoneRotZ: number;
imagePhonePerspective: number;
- imagePhoneDevice: 'phone' | 'iphone' | 'iphone-13-pro-max' | 'iphone-17-pro-max' | 'double_iphone_13_pro' | 'samsung' | 'laptop' | 'ipad_mini_6_2021';
+ imagePhoneDevice: 'phone' | 'iphone' | 'iphone-13-pro-max' | 'iphone-17-pro-max' | 'double_iphone_13_pro' | 'laptop' | 'ipad_mini_6_2021';
imagePhonePresetId: string;
imagePhoneOpening: number;
imagePhoneShadow: number;
diff --git a/types/image-project.types.ts b/types/image-project.types.ts
index df48891..5f12bad 100644
--- a/types/image-project.types.ts
+++ b/types/image-project.types.ts
@@ -50,7 +50,7 @@ export interface ImageProject {
imagePhoneRotY: number;
imagePhoneRotZ: number;
imagePhonePerspective: number;
- imagePhoneDevice: 'phone' | 'iphone' | 'iphone-13-pro-max' | 'double_iphone_13_pro' | 'samsung' | 'laptop' | 'iphone-17-pro-max' | 'ipad_mini_6_2021';
+ imagePhoneDevice: 'phone' | 'iphone' | 'iphone-13-pro-max' | 'double_iphone_13_pro' | 'laptop' | 'iphone-17-pro-max' | 'ipad_mini_6_2021';
imagePhonePresetId: string;
imagePhoneOpening: number;
imagePhoneShadow: number;