Skip to content

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

fix: upload render 3d

CristianOlivera17100cc797003
diff --git a/app/[locale]/(editor)/editor/page.tsx b/app/[locale]/(editor)/editor/page.tsx
index add2e71..f105030 100644
--- a/app/[locale]/(editor)/editor/page.tsx
+++ b/app/[locale]/(editor)/editor/page.tsx
@@ -152,6 +152,11 @@ export default function Editor() {
// MockupMenu via the `initialPage` prop (resets to "home" on remount when
// the menu is collapsed/expanded).
const [initialMockupMenuPage, setInitialMockupMenuPage] = useState<MenuPage>("home");
+ // Increments on every handleMockupClick so the MockupMenu re-navigates
+ // even when the user clicks the SAME mockup twice in a row (in which
+ // case initialMockupMenuPage would not change and the useEffect inside
+ // MockupMenu would not fire).
+ const [mockupMenuNavigationToken, setMockupMenuNavigationToken] = useState(0);
// Video transform state (rotation and position)
const [videoTransform, setVideoTransform] = useState<{ rotation: number; translateX: number; translateY: number }>({
@@ -1112,6 +1117,7 @@ export default function Editor() {
// (see onMockupClick in VideoCanvasProps).
const handleMockupClick = useCallback((kind: "2d" | "3d") => {
setInitialMockupMenuPage(kind === "2d" ? "detail-2d" : "detail-3d");
+ setMockupMenuNavigationToken((t) => t + 1);
setActiveTool("mockup");
setIsControlPanelOpen(true);
}, [setActiveTool]);
@@ -2999,6 +3005,7 @@ export default function Editor() {
onMockupChange={handleMockupChange}
onMockupConfigChange={handleMockupConfigChange}
initialMockupMenuPage={initialMockupMenuPage}
+ mockupMenuNavigationToken={mockupMenuNavigationToken}
onAddCanvasElement={addCanvasElement}
selectedCanvasElement={canvasElements.find(el => el.id === selectedElementId) || null}
onUpdateCanvasElement={updateCanvasElement}
diff --git a/app/components/ui/editor/ControlPanel.tsx b/app/components/ui/editor/ControlPanel.tsx
index 4e258dd..05711e6 100644
--- a/app/components/ui/editor/ControlPanel.tsx
+++ b/app/components/ui/editor/ControlPanel.tsx
@@ -89,8 +89,12 @@ export function ControlPanel({
onMockupConfigChange,
// Initial page for the MockupMenu (home | detail-2d | detail-3d). Set by
// the parent when the user clicks a mockup already applied on the canvas,
- // so the menu opens directly on the config panel of that frame.
+ // so the menu opens directly on the config panel of that frame. The
+ // MockupMenu is keyed by `mockupMenuNavigationToken` to re-mount on every
+ // canvas click so the `useState(initialPage)` re-reads the new value
+ // even when the same page is selected twice in a row.
initialMockupMenuPage,
+ mockupMenuNavigationToken = 0,
// Canvas elements props
onAddCanvasElement,
selectedCanvasElement,
@@ -280,6 +284,7 @@ export function ControlPanel({
{activeTool === "mockup" && (
<Suspense fallback={<MockupMenuSkeleton />}>
<MockupMenu
+ key={mockupMenuNavigationToken}
mockupId={mockupId}
mockupConfig={mockupConfig}
onMockupChange={onMockupChange}
diff --git a/app/components/ui/editor/IPhone13ProMax3DViewer.tsx b/app/components/ui/editor/IPhone13ProMax3DViewer.tsx
index 83abcf2..b17cb50 100644
--- a/app/components/ui/editor/IPhone13ProMax3DViewer.tsx
+++ b/app/components/ui/editor/IPhone13ProMax3DViewer.tsx
@@ -196,13 +196,13 @@ function ModelScene({
tex.magFilter = THREE.LinearFilter;
tex.wrapS = THREE.ClampToEdgeWrapping;
tex.wrapT = THREE.ClampToEdgeWrapping;
-
+
// EL SECRETO PARA LOS ÁNGULOS: Filtro Anisotrópico al máximo
tex.anisotropy = gl.capabilities.getMaxAnisotropy();
-
+
mat.map = tex;
mat.needsUpdate = true;
-
+
lastLoadedImageUrlRef.current = imageUrl;
lastLoadedMaskKeyRef.current = maskKey;
lastLoadedCropKeyRef.current = cropKey;
@@ -257,7 +257,7 @@ function ModelScene({
}}
/>
- <Environment preset="city" background={false} />
+ <Environment preset="studio" background={false} />
<ambientLight intensity={0.3} />
<directionalLight position={[3, 6, 5]} intensity={0.6} />
<directionalLight position={[-4, -2, 3]} intensity={0.25} color="#c8d8ff" />
@@ -416,7 +416,6 @@ export function IPhone13ProMax3DViewer({
style={{
display: "inline-block",
transformOrigin: "top center",
- transform: `scale(${scale})`,
width: 480,
height: 1000 + (hasShadow ? computedBlur * 0.8 : 0),
marginTop: "200px",
diff --git a/app/components/ui/editor/Laptop3DViewer.tsx b/app/components/ui/editor/Laptop3DViewer.tsx
index 13f3aea..5a992f3 100644
--- a/app/components/ui/editor/Laptop3DViewer.tsx
+++ b/app/components/ui/editor/Laptop3DViewer.tsx
@@ -84,7 +84,7 @@ function ModelScene({
const { gl, scene, camera } = useThree();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const orbitRef = useRef<any>(null);
-
+
const [modelGroup, setModelGroup] = useState<THREE.Group | null>(null);
const lidGroupRef = useRef<THREE.Group | null>(null);
const screenMatRef = useRef<THREE.MeshBasicMaterial | null>(null);
@@ -144,7 +144,7 @@ function ModelScene({
if (!currentMat) return;
// Usamos una resolución alta para evitar pixelación
- const TEX_W = RENDER_W;
+ const TEX_W = RENDER_W;
const TEX_H = RENDER_H;
const cropped = applyCropToImage(img, cropArea);
@@ -158,7 +158,7 @@ function ModelScene({
tex.flipY = false;
tex.wrapS = THREE.RepeatWrapping;
tex.colorSpace = THREE.SRGBColorSpace;
-
+
if (cover.width && cover.height) {
tex.repeat.y = ((cover.width / cover.height) / screenSize[0]) * screenSize[1];
}
@@ -202,17 +202,17 @@ function ModelScene({
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 tStart = Math.max(0, Math.min(1, openingProgress));
-
+
// MEJORA DE CALIDAD: toneMapped: false evita que los colores de la captura se vean grises/oscuros
- const screenMaterial = new THREE.MeshBasicMaterial({
- map: null,
- transparent: true,
- opacity: 0.96 * tStart,
+ const screenMaterial = new THREE.MeshBasicMaterial({
+ map: null,
+ transparent: true,
+ opacity: 0.96 * tStart,
side: THREE.BackSide,
color: 0xffffff,
- toneMapped: false
+ toneMapped: false
});
screenMatRef.current = screenMaterial;
@@ -228,7 +228,7 @@ function ModelScene({
const finalizeSetup = (group: THREE.Group) => {
if (!isMounted) return;
setModelGroup(group);
-
+
setTimeout(() => {
if (!isMounted) return;
applyTextureRef.current();
@@ -290,7 +290,7 @@ function ModelScene({
});
return () => { isMounted = false; };
- // eslint-disable-next-line react-hooks/exhaustive-deps
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
// 4. Actualizar posiciones de cámara dinámicas
@@ -322,25 +322,25 @@ function ModelScene({
return (
<>
<PerspectiveCamera ref={cameraRef} makeDefault fov={CAM_FOV} near={10} far={1000} position={[0, 0, CAM_RADIUS / zoom]} />
-
- <OrbitControls
- ref={orbitRef}
- enableZoom={false}
- enablePan={false}
- enableDamping
- dampingFactor={0.08}
+
+ <OrbitControls
+ ref={orbitRef}
+ enableZoom={false}
+ enablePan={false}
+ enableDamping
+ dampingFactor={0.08}
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);
- }}
+ }}
/>
<Environment preset="city" background={false} />
<ambientLight intensity={3.2} />
-
+
<group>
<pointLight position={[0, 5, 50]} intensity={0.8} color="#fff5e1" />
</group>
@@ -399,7 +399,6 @@ function CanvasWithLoader(props: Props & {
export function Laptop3DViewer(props: Props) {
const {
- scale = 1,
shadowIntensity = 0,
shadowColor = "#000000",
} = props;
@@ -416,7 +415,7 @@ export function Laptop3DViewer(props: Props) {
const shadowRgba = shadowColor.startsWith("#")
? parseShadowColor(shadowColor, computedOpacity)
: shadowColor;
-
+
const hasShadow = t > 0.01;
return (
@@ -424,7 +423,6 @@ export function Laptop3DViewer(props: Props) {
style={{
display: "inline-block",
transformOrigin: "top center",
- transform: `scale(${scale})`,
width: LAPTOP_W,
height: LAPTOP_H + (hasShadow ? computedBlur * 0.8 : 0),
marginTop: "250px",
diff --git a/app/components/ui/editor/MockupMenu.tsx b/app/components/ui/editor/MockupMenu.tsx
index 992b895..fa9a350 100644
--- a/app/components/ui/editor/MockupMenu.tsx
+++ b/app/components/ui/editor/MockupMenu.tsx
@@ -73,7 +73,7 @@ function DeviceCard({
{isActive && (
<div
className="pointer-events-none absolute inset-0 rounded-2xl"
- style={{ boxShadow: `0 0 0 1.5px ${tpl.accentColor}88` }}
+ style={{ boxShadow: `inset 0 0 0 1.5px ${tpl.accentColor}88` }}
/>
)}
</div>
@@ -120,6 +120,17 @@ export function MockupMenu({
// ── Navigation state ──
const [page, setPage] = useState<MenuPage>(initialPage);
+ // Sync page when the parent (VideoCanvas click) sets initialPage to a
+ // detail view while the menu is already mounted. Without this, the
+ // `useState(initialPage)` only reads the prop on first mount, so a click
+ // on a mockup already applied on the canvas wouldn't navigate the menu
+ // to the matching detail page.
+ useEffect(() => {
+ if (initialPage !== "home") {
+ setPage(initialPage);
+ }
+ }, [initialPage]);
+
// ── 2D popover state ──
const [selectedCategory, setSelectedCategory] = useState<MockupCategory>("all");
const [gridLoaded, setGridLoaded] = useState(false);
@@ -283,24 +294,27 @@ export function MockupMenu({
// ── Handlers: 3D ──
const handleDeviceClick = (id: ImageDeviceId) => {
- if (id !== imagePhoneDevice) {
- setImagePhoneDevice(id);
- setImagePhoneX(0);
- setImagePhoneY(0);
- setImagePhoneScale(0.8);
- if (id === "iphone-13-pro-max") {
- setImagePhoneRotX(-58.23);
- setImagePhoneRotY(-29.82);
- } else if (id === "laptop") {
- setImagePhoneRotX(43.23);
- setImagePhoneRotY(-37.82);
- setImagePhoneOpening(1);
- setImagePhoneScale(1);
- } else {
- setImagePhoneRotX(0);
- setImagePhoneRotY(0);
- }
-
+ // Always apply the per-device defaults on every click — even if the
+ // user picks the same device twice, we want to reset to the canonical
+ // pose. Without this, a device that starts at the context's default
+ // (imagePhoneRotX=0, imagePhoneRotY=0) would never snap to its pose
+ // because the "device changed" guard would be false.
+ setImagePhoneDevice(id);
+ setImagePhoneX(0);
+ setImagePhoneY(0);
+ setImagePhoneScale(0.8);
+ if (id === "iphone-13-pro-max") {
+ setImagePhoneRotX(-58.23);
+ setImagePhoneRotY(-29.82);
+ } else if (id === "laptop") {
+ setImagePhoneRotX(43.23);
+ setImagePhoneRotY(-37.82);
+ setImagePhoneOpening(1);
+ setImagePhoneScale(1);
+ } else {
+ // phone, iphone, samsung — all rendered through Phone3DViewer.tsx
+ setImagePhoneRotX(-58.23);
+ setImagePhoneRotY(-29.82);
}
setImagePhoneActive(true);
if (mockupId !== "none") onMockupChange?.("none");
@@ -315,9 +329,7 @@ export function MockupMenu({
setPage("home");
};
- // ─────────────────────────────────────────────────────────────────────────
// PAGE: DETAIL 2D
- // ─────────────────────────────────────────────────────────────────────────
if (page === "detail-2d") {
return (
@@ -331,9 +343,7 @@ export function MockupMenu({
);
}
- // ─────────────────────────────────────────────────────────────────────────
// PAGE: DETAIL 3D
- // ─────────────────────────────────────────────────────────────────────────
if (page === "detail-3d") {
return (
@@ -363,9 +373,7 @@ export function MockupMenu({
);
}
- // ─────────────────────────────────────────────────────────────────────────
// PAGE: HOME
- // ─────────────────────────────────────────────────────────────────────────
return (
<div className="p-4 flex flex-col gap-6">
@@ -580,11 +588,7 @@ export function MockupMenu({
onMouseLeave={() => setIsDevicesHover(false)}
>
<div
- className={`pointer-events-none absolute inset-y-0 left-0 z-20 w-10 bg-gradient-to-r from-[#141417] to-transparent transition-opacity duration-200 ${isDevicesHover && canScrollLeft ? "opacity-100" : "opacity-0"
- }`}
- />
- <div
- className={`pointer-events-none absolute inset-y-0 right-0 z-20 w-12 bg-gradient-to-l from-[#141417] to-transparent transition-opacity duration-200 ${isDevicesHover && canScrollRight ? "opacity-100" : "opacity-0"
+ className={`pointer-events-none absolute inset-y-0 right-0 z-20 w-8 bg-gradient-to-l from-[#141417] to-transparent transition-opacity duration-200 ${canScrollRight ? "opacity-100" : "opacity-0"
}`}
/>
diff --git a/app/components/ui/editor/Phone3DViewer.tsx b/app/components/ui/editor/Phone3DViewer.tsx
index e039fd3..0767b52 100644
--- a/app/components/ui/editor/Phone3DViewer.tsx
+++ b/app/components/ui/editor/Phone3DViewer.tsx
@@ -75,8 +75,8 @@ function ModelScene({
imageUrl,
imageMaskConfig,
cropArea,
- initialRotationX = 0,
- initialRotationY = 0,
+ initialRotationX = -58.23,
+ initialRotationY = -29,
initialRotationZ = 0,
onRotationChange,
rootRef,
@@ -85,8 +85,8 @@ function ModelScene({
modelUrl,
onApi,
onLoaded,
-}: Props & {
- rootRef: React.MutableRefObject<THREE.Group | null>;
+}: Props & {
+ rootRef: React.MutableRefObject<THREE.Group | null>;
cameraRef: React.MutableRefObject<THREE.PerspectiveCamera | null>;
onLoaded?: () => void;
}) {
@@ -235,13 +235,13 @@ function ModelScene({
const finalizeSetup = (group: THREE.Group) => {
if (!isMounted) return;
setModelGroup(group);
-
+
// Retrasamos unos milisegundos para asegurar que Three ha inyectado el nodo
setTimeout(() => {
if (!isMounted) return;
- applyTextureRef.current();
+ applyTextureRef.current();
onLoaded?.();
- }, 50);
+ }, 50);
};
if (isDefaultPhone) {
@@ -249,13 +249,13 @@ function ModelScene({
loadGltfGroup().then((cached) => {
const group = cloneGroup(cached);
// Usamos zoom default aquí para montar el tamaño base. El useEffect dinámico hará el resto.
- const camZ = 1.5;
+ const camZ = 1.5;
const box = new THREE.Box3().setFromObject(group);
const center = box.getCenter(new THREE.Vector3());
const size = box.getSize(new THREE.Vector3());
const halfH = camZ * Math.tan((40 / 2) * DEG);
const sf = (halfH * 2 * 0.8) / size.y;
-
+
group.scale.setScalar(sf);
group.position.copy(center).negate().multiplyScalar(sf);
@@ -269,7 +269,7 @@ function ModelScene({
const meshBox = new THREE.Box3().setFromObject(child);
const meshSize = meshBox.getSize(new THREE.Vector3());
if (meshSize.x > 0 && meshSize.y > 0) screenAspectRef.current = meshSize.x / meshSize.y;
-
+
const basicMat = new THREE.MeshBasicMaterial({
color: 0x111111, side: THREE.FrontSide, transparent: true, depthTest: false, depthWrite: false,
});
@@ -293,7 +293,7 @@ function ModelScene({
const size = box.getSize(new THREE.Vector3());
const halfH = camZ * Math.tan((40 / 2) * DEG);
const sf = (halfH * 2 * 0.8) / size.y;
-
+
group.scale.setScalar(sf);
group.position.copy(center).negate().multiplyScalar(sf);
@@ -316,8 +316,8 @@ function ModelScene({
}
return () => { isMounted = false; };
- // Desactivamos exhaust-deps para que NUNCA se vuelva a ejecutar este setup al hacer zoom o cambiar onLoaded
- // eslint-disable-next-line react-hooks/exhaustive-deps
+ // Desactivamos exhaust-deps para que NUNCA se vuelva a ejecutar este setup al hacer zoom o cambiar onLoaded
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, [modelUrl]);
// 4. Actualizar posiciones de cámara dinámicas (Esto es seguro de ejecutar contínuamente)
@@ -338,20 +338,20 @@ function ModelScene({
return (
<>
<PerspectiveCamera ref={cameraRef} makeDefault fov={40} near={0.01} far={100} position={[0, 0, 1.5 / zoom]} />
-
- <OrbitControls
- ref={orbitRef}
- enableZoom={false}
- enablePan={false}
- enableDamping
- dampingFactor={0.08}
+
+ <OrbitControls
+ ref={orbitRef}
+ enableZoom={false}
+ enablePan={false}
+ enableDamping
+ dampingFactor={0.08}
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);
- }}
+ }}
/>
<Environment preset="city" background={false} />
@@ -431,7 +431,7 @@ export function Phone3DViewer(props: Props) {
const shadowRgba = shadowColor.startsWith("#")
? parseShadowColor(shadowColor, computedOpacity)
: shadowColor;
-
+
const hasShadow = t > 0.01;
return (
@@ -439,7 +439,6 @@ export function Phone3DViewer(props: Props) {
style={{
display: "inline-block",
transformOrigin: "top center",
- transform: `scale(${scale})`,
width: PHONE_W,
height: PHONE_H + (hasShadow ? computedBlur * 0.8 : 0),
marginTop: "220px",
@@ -447,7 +446,7 @@ export function Phone3DViewer(props: Props) {
}}
>
<div style={{ position: "relative", width: PHONE_W, height: PHONE_H }}>
-
+
{hasShadow && (
<div
aria-hidden
diff --git a/types/control-panel.types.ts b/types/control-panel.types.ts
index 35afaa3..449d897 100644
--- a/types/control-panel.types.ts
+++ b/types/control-panel.types.ts
@@ -47,9 +47,13 @@ export interface ControlPanelProps {
/**
* Initial page for the MockupMenu (home | detail-2d | detail-3d). Set by
* the parent when the user clicks a mockup already applied on the canvas,
- * so the menu opens directly on the config panel of that frame.
+ * so the menu opens directly on the config panel of that frame. The
+ * MockupMenu is keyed by `mockupMenuNavigationToken` to re-mount on every
+ * canvas click so the `useState(initialPage)` re-reads the new value
+ * even when the same page is selected twice in a row.
*/
initialMockupMenuPage?: MenuPage;
+ mockupMenuNavigationToken?: number;
onAddCanvasElement?: (element: CanvasElement) => void;
selectedCanvasElement?: CanvasElement | null;
onUpdateCanvasElement?: (id: string, updates: Partial<CanvasElement>) => void;