Create professional demos and 3D mockups in seconds, directly in your browser
feat: enhance 3D viewer components with texture application and outline filters; add media mask styles for improved visual presentation
CristianOlivera182ffbd569c14
diff --git a/app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsx b/app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsxindex 82601d3..32d3cd1 100644--- a/app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsx+++ b/app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsx@@ -11,9 +11,12 @@ import {applyCropToImage,type ImageMaskConfigLike,parseShadowColor,+ applyTextureCover,+ getOutlineFilter,} from "@/lib/phone3d.utils";import type { OrbitControls as OrbitControlsType } from 'three-stdlib';import { EnvironmentPreset, HDRI_FILES } from "@/lib/viewer-controls3d";+import { GetMediaMaskStyles } from "@/lib/media-mask.utils";export interface DoubleIPhone3DApi {renderAt: (width: number, height: number) => void;@@ -39,6 +42,8 @@ interface Props {rotationSpeed?: number;glow?: number;environment?: EnvironmentPreset;+ isSelected?: boolean;+ isHovered?: boolean;}const DEG = Math.PI / 180;@@ -165,7 +170,7 @@ function ModelScene({const TARGET_W = 1080;const TARGET_H = 2340;const sourceImg = cropArea ? applyCropToImage(img, cropArea) : img;- const cover = createCoverScreenCanvas(sourceImg, TARGET_W, TARGET_H, 0, imageMaskConfig);+ const cover = createCoverScreenCanvas(sourceImg, TARGET_W, TARGET_H, 0, null);if (currentMat.map) {currentMat.map.dispose();@@ -202,14 +207,10 @@ function ModelScene({const applyVideoTextureIfReady = useCallback(() => {const mat = screenMatRef.current;const tex = videoTextureRef.current;-if (mat && tex) {if (mat.map && mat.map !== tex) {mat.map.dispose();}- tex.flipY = false;- tex.needsUpdate = true;-mat.map = tex;mat.color.set(0xffffff);mat.needsUpdate = true;@@ -227,7 +228,9 @@ function ModelScene({}const tex = new THREE.VideoTexture(videoElement);+tex.flipY = true;+tex.colorSpace = THREE.SRGBColorSpace;tex.generateMipmaps = true;tex.minFilter = THREE.LinearMipmapLinearFilter;@@ -235,6 +238,23 @@ function ModelScene({tex.wrapS = THREE.ClampToEdgeWrapping;tex.wrapT = THREE.ClampToEdgeWrapping;+ const updateTextureTransform = () => {+ applyTextureCover(+ tex,+ videoElement.videoWidth,+ videoElement.videoHeight,+ 1080,+ 2340+ );+ applyVideoTextureIfReady();+ };++ if (videoElement.readyState >= 1) {+ updateTextureTransform();+ } else {+ videoElement.addEventListener("loadedmetadata", updateTextureTransform);+ }+if (videoTextureRef.current) {videoTextureRef.current.dispose();}@@ -243,6 +263,7 @@ function ModelScene({applyVideoTextureIfReady();return () => {+ videoElement.removeEventListener("loadedmetadata", updateTextureTransform);if (videoTextureRef.current === tex) {videoTextureRef.current = null;}@@ -440,7 +461,7 @@ function CanvasWithLoader(}export function DoubleIPhone3DViewer(props: Props) {- const { shadowIntensity = 0, shadowColor = "#000000" } = props;+ const { shadowIntensity = 0, shadowColor = "#000000", imageMaskConfig = null, isSelected = false, isHovered = false } = props;const rootRef = useRef<THREE.Group | null>(null);const cameraRef = useRef<THREE.PerspectiveCamera | null>(null);const [grabbing, setGrabbing] = useState(false);@@ -454,6 +475,14 @@ export function DoubleIPhone3DViewer(props: Props) {: shadowColor;const hasShadow = t > 0.01;+ const maskStyle = GetMediaMaskStyles(imageMaskConfig, {+ inset: 400,+ deviceWidth: PHONE_W,+ deviceHeight: PHONE_H,+ });++ const outlineFilter = getOutlineFilter(isSelected, isHovered);+return (<><div@@ -491,11 +520,10 @@ export function DoubleIPhone3DViewer(props: Props) {zIndex: 2,overflow: "visible",cursor: grabbing ? "grabbing" : "grab",- filter: hasShadow- ? `drop-shadow(0px ${(tEased * 22).toFixed(1)}px ${(tEased * 32).toFixed(1)}px ${shadowRgba})`- : "none",+ filter: outlineFilter,transition: "filter 0.15s ease",pointerEvents: "auto",+ ...maskStyle,}}onPointerDown={() => setGrabbing(true)}onPointerUp={() => setGrabbing(false)}diff --git a/app/components/ui/editor/mockups-3d/IPadMini63DViewer.tsx b/app/components/ui/editor/mockups-3d/IPadMini63DViewer.tsxindex ba7e001..0b76499 100644--- a/app/components/ui/editor/mockups-3d/IPadMini63DViewer.tsx+++ b/app/components/ui/editor/mockups-3d/IPadMini63DViewer.tsx@@ -8,9 +8,12 @@ import {applyCropToImage,type ImageMaskConfigLike,parseShadowColor,+ applyTextureCover,+ getOutlineFilter,} from "@/lib/phone3d.utils";import type { OrbitControls as OrbitControlsType } from 'three-stdlib';import { EnvironmentPreset, HDRI_FILES } from "@/lib/viewer-controls3d";+import { GetMediaMaskStyles } from "@/lib/media-mask.utils";export interface IPadMini63DApi {renderAt: (width: number, height: number) => void;@@ -36,6 +39,8 @@ interface Props {rotationSpeed?: number;glow?: number;environment?: EnvironmentPreset;+ isSelected?: boolean;+ isHovered?: boolean;}const DEG = Math.PI / 180;@@ -154,7 +159,7 @@ function ModelScene({if (!currentMat) return;const sourceImg = cropArea ? applyCropToImage(img, cropArea) : img;- const cover = createCoverScreenCanvas(sourceImg, TARGET_W, TARGET_H, 0, imageMaskConfig);+ const cover = createCoverScreenCanvas(sourceImg, TARGET_W, TARGET_H, 0, null);if (currentMat.map) {currentMat.map.dispose();@@ -215,22 +220,46 @@ function ModelScene({}return;}+const tex = new THREE.VideoTexture(videoElement);+tex.flipY = false;tex.center.set(0.5, 0.5);tex.rotation = Math.PI;+tex.colorSpace = THREE.SRGBColorSpace;tex.generateMipmaps = true;tex.minFilter = THREE.LinearMipmapLinearFilter;tex.magFilter = THREE.LinearFilter;tex.wrapS = THREE.ClampToEdgeWrapping;tex.wrapT = THREE.ClampToEdgeWrapping;++ const updateTextureTransform = () => {+ applyTextureCover(+ tex,+ videoElement.videoWidth,+ videoElement.videoHeight,+ TARGET_W,+ TARGET_H+ );+ applyVideoTextureIfReady();+ };++ if (videoElement.readyState >= 1) {+ updateTextureTransform();+ } else {+ videoElement.addEventListener("loadedmetadata", updateTextureTransform);+ }+if (videoTextureRef.current) {videoTextureRef.current.dispose();}videoTextureRef.current = tex;+applyVideoTextureIfReady();+return () => {+ videoElement.removeEventListener("loadedmetadata", updateTextureTransform);if (videoTextureRef.current === tex) {videoTextureRef.current = null;}@@ -446,7 +475,8 @@ function CanvasWithLoader(}export function IPadMini63DViewer(props: Props) {- const { shadowIntensity = 0, shadowColor = "#000000" } = props;+ const { shadowIntensity = 0, shadowColor = "#000000", imageMaskConfig = null, isSelected = false,+ isHovered = false } = props;const rootRef = useRef<THREE.Group | null>(null);const cameraRef = useRef<THREE.PerspectiveCamera | null>(null);const [grabbing, setGrabbing] = useState(false);@@ -461,6 +491,14 @@ export function IPadMini63DViewer(props: Props) {const VIEWER_W = 750;const VIEWER_H = 1000;+ const maskStyle = GetMediaMaskStyles(imageMaskConfig, {+ inset: 300,+ deviceWidth: VIEWER_W,+ deviceHeight: VIEWER_H,+ });++ const outlineFilter = getOutlineFilter(isSelected, isHovered);+return (<><div@@ -498,11 +536,10 @@ export function IPadMini63DViewer(props: Props) {zIndex: 2,overflow: "visible",cursor: grabbing ? "grabbing" : "grab",- filter: hasShadow- ? `drop-shadow(0px ${(tEased * 22).toFixed(1)}px ${(tEased * 32).toFixed(1)}px ${shadowRgba})`- : "none",+ filter: outlineFilter,transition: "filter 0.15s ease",pointerEvents: "auto",+ ...maskStyle}}onPointerDown={() => setGrabbing(true)}onPointerUp={() => setGrabbing(false)}diff --git a/app/components/ui/editor/mockups-3d/IPhone13ProMax3DViewer.tsx b/app/components/ui/editor/mockups-3d/IPhone13ProMax3DViewer.tsxindex 7fdbdd3..0ed0d39 100644--- a/app/components/ui/editor/mockups-3d/IPhone13ProMax3DViewer.tsx+++ b/app/components/ui/editor/mockups-3d/IPhone13ProMax3DViewer.tsx@@ -3,14 +3,17 @@ import { Canvas, useThree, useFrame } from "@react-three/fiber";import { PerspectiveCamera, useGLTF, Environment, OrbitControls } from "@react-three/drei";import { useEffect, useRef, useState, Suspense, useLayoutEffect, useMemo } from "react";import * as THREE from "three";-import { createCoverScreenCanvas, applyCropToImage, type ImageMaskConfigLike } from "@/lib/phone3d.utils";+import { createCoverScreenCanvas, applyCropToImage, type ImageMaskConfigLike, applyTextureCover, getOutlineFilter } from "@/lib/phone3d.utils";import type { OrbitControls as OrbitControlsType } from 'three-stdlib';import { EnvironmentPreset, HDRI_FILES } from "@/lib/viewer-controls3d";+import { GetMediaMaskStyles } from "@/lib/media-mask.utils";export interface IPhone13ProMax3DApi {renderAt: (width: number, height: number) => void;restorePreview: () => void;hasBuiltInShadow: boolean;+ getVisualSize: () => { width: number; height: number } | null;+}interface Props {@@ -32,6 +35,8 @@ interface Props {rotationSpeed?: number;glow?: number;environment?: EnvironmentPreset;+ isSelected?: boolean;+ isHovered?: boolean;}const TEX_W = 1284 * 2;@@ -156,6 +161,10 @@ function ModelScene({onApiRef.current = onApi;});+ useLayoutEffect(() => {+ onApiRef.current = onApi;+ });+useFrame(() => {if (videoElement && videoTextureRef.current) {videoTextureRef.current.needsUpdate = true;@@ -163,6 +172,7 @@ function ModelScene({});useEffect(() => {+const capturedOnApi = onApiRef.current;const RENDER_PIXEL_RATIO = 2;const api: IPhone13ProMax3DApi = {@@ -190,6 +200,16 @@ function ModelScene({gl.setPixelRatio(window.devicePixelRatio > 1 ? 2 : 1);gl.setSize(freshW, freshH, false);},++ //Se agrego esto+ getVisualSize: () => {+ const canvas = gl.domElement;+ const domW = canvas.clientWidth;+ const domH = canvas.clientHeight;+ if (!domW || !domH) return null;+ return { width: domW, height: domH };+ },+hasBuiltInShadow: true,};capturedOnApi?.(api);@@ -214,6 +234,7 @@ function ModelScene({}return;}+const tex = new THREE.VideoTexture(videoElement);tex.flipY = true;tex.colorSpace = THREE.SRGBColorSpace;@@ -222,10 +243,28 @@ function ModelScene({tex.magFilter = THREE.LinearFilter;tex.wrapS = THREE.ClampToEdgeWrapping;tex.wrapT = THREE.ClampToEdgeWrapping;++ const updateTextureTransform = () => {+ applyTextureCover(+ tex,+ videoElement.videoWidth,+ videoElement.videoHeight,+ TEX_W,+ TEX_H+ );+ };++ if (videoElement.readyState >= 1) {+ updateTextureTransform();+ } else {+ videoElement.addEventListener("loadedmetadata", updateTextureTransform);+ }+if (videoTextureRef.current) {videoTextureRef.current.dispose();}videoTextureRef.current = tex;+const applyVideoTex = () => {const mat = wallpaperMatRef.current;if (!mat) return;@@ -236,8 +275,11 @@ function ModelScene({mat.color.set(0xffffff);mat.needsUpdate = true;};+applyVideoTex();+return () => {+ videoElement.removeEventListener("loadedmetadata", updateTextureTransform);if (videoTextureRef.current === tex) {videoTextureRef.current = null;}@@ -257,7 +299,8 @@ function ModelScene({const img = new Image();img.crossOrigin = "anonymous";img.onload = () => {- const cover = createCoverScreenCanvas(img, TEX_W, TEX_H, 0, null);+ const sourceImage = cropArea ? applyCropToImage(img, cropArea) : img;+ const cover = createCoverScreenCanvas(sourceImage, TEX_W, TEX_H, 0, null);if (mat.map) {mat.map.dispose();mat.map = null;@@ -646,7 +689,9 @@ export function IPhone13ProMax3DViewer({autoRotate,rotationSpeed,glow,- environment+ environment,+ isSelected = false,+ isHovered = false,}: Props) {const rootRef = useRef<THREE.Group | null>(null);const cameraRef = useRef<THREE.PerspectiveCamera | null>(null);@@ -655,6 +700,13 @@ export function IPhone13ProMax3DViewer({const tEased = t * t;const computedBlur = tEased * 60;const hasShadow = t > 0.01;+ const maskStyle = GetMediaMaskStyles(imageMaskConfig, {+ inset: 400,+ deviceWidth: 480,+ deviceHeight: 1000,+ });++ const outlineFilter = getOutlineFilter(isSelected, isHovered);return (<>@@ -676,9 +728,10 @@ export function IPhone13ProMax3DViewer({zIndex: 2,overflow: "visible",cursor: grabbing ? "grabbing" : "grab",- filter: "none",+ filter: outlineFilter,transition: "filter 0.15s ease",pointerEvents: "auto",+ ...maskStyle,}}onPointerDown={() => setGrabbing(true)}onPointerUp={() => setGrabbing(false)}diff --git a/app/components/ui/editor/mockups-3d/IPhone17ProMax3DViewer.tsx b/app/components/ui/editor/mockups-3d/IPhone17ProMax3DViewer.tsxindex 1b12c81..31d777d 100644--- a/app/components/ui/editor/mockups-3d/IPhone17ProMax3DViewer.tsx+++ b/app/components/ui/editor/mockups-3d/IPhone17ProMax3DViewer.tsx@@ -4,9 +4,10 @@ import { Canvas, useThree, useFrame } from "@react-three/fiber";import { PerspectiveCamera, useGLTF, Environment, OrbitControls, ContactShadows } from "@react-three/drei";import { useEffect, useRef, useState, Suspense, useLayoutEffect, useMemo, useCallback } from "react";import * as THREE from "three";-import { createCoverScreenCanvas, applyCropToImage, parseShadowColor, type ImageMaskConfigLike } from "@/lib/phone3d.utils";+import { createCoverScreenCanvas, applyCropToImage, parseShadowColor, type ImageMaskConfigLike, applyTextureCover, getOutlineFilter } from "@/lib/phone3d.utils";import type { OrbitControls as OrbitControlsType } from 'three-stdlib';import { EnvironmentPreset, HDRI_FILES } from "@/lib/viewer-controls3d";+import { GetMediaMaskStyles } from "@/lib/media-mask.utils";export interface IPhone17ProMax3DApi {renderAt: (width: number, height: number) => void;@@ -33,6 +34,8 @@ interface Props {rotationSpeed?: number;glow?: number;environment?: EnvironmentPreset;+ isSelected?: boolean;+ isHovered?: boolean;}const TEX_W = 1284 * 2;@@ -177,14 +180,32 @@ function ModelScene({}return;}- const tex = new THREE.VideoTexture(videoElement);+ const tex = new THREE.VideoTexture(videoElement);tex.flipY = false;-tex.colorSpace = THREE.SRGBColorSpace;tex.generateMipmaps = true;tex.minFilter = THREE.LinearMipmapLinearFilter;tex.magFilter = THREE.LinearFilter;+ tex.wrapS = THREE.ClampToEdgeWrapping;+ tex.wrapT = THREE.ClampToEdgeWrapping;++ const updateTextureTransform = () => {+ applyTextureCover(+ tex,+ videoElement.videoWidth,+ videoElement.videoHeight,+ TEX_W,+ TEX_H+ );+ invalidate();+ };++ if (videoElement.readyState >= 1) {+ updateTextureTransform();+ } else {+ videoElement.addEventListener('loadedmetadata', updateTextureTransform);+ }if (videoTextureRef.current) {videoTextureRef.current.dispose();@@ -194,19 +215,23 @@ function ModelScene({const applyVideoTex = () => {const mat = wallpaperMatRef.current;if (!mat) return;+if (mat.map && mat.map !== tex) {mat.map.dispose();}+mat.map = tex;mat.color.set(0xffffff);mat.needsUpdate = true;if (mat.map) mat.map.needsUpdate = true;+invalidate();};applyVideoTex();return () => {+ videoElement.removeEventListener('loadedmetadata', updateTextureTransform);if (videoTextureRef.current === tex) {videoTextureRef.current = null;}@@ -475,6 +500,8 @@ export function IPhone17ProMax3DViewer({rotationSpeed,glow,environment,+ isSelected = false,+ isHovered = false,}: Props) {const rootRef = useRef<THREE.Group | null>(null);const cameraRef = useRef<THREE.PerspectiveCamera | null>(null);@@ -487,6 +514,14 @@ export function IPhone17ProMax3DViewer({const shadowRgba = shadowColor.startsWith("#") ? parseShadowColor(shadowColor, computedOpacity) : shadowColor;const hasShadow = t > 0.01;+ const maskStyle = GetMediaMaskStyles(imageMaskConfig, {+ inset: 400,+ deviceWidth: 480,+ deviceHeight: 1000,+ });++ const outlineFilter = getOutlineFilter(isSelected, isHovered);+return (<><div style={{ display: "inline-block", transformOrigin: "top center", width: 480, height: 1000 + (hasShadow ? computedBlur * 0.8 : 0), marginTop: "100px", marginLeft: "170px" }}>@@ -494,7 +529,22 @@ export function IPhone17ProMax3DViewer({{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={{ position: "absolute", inset: "-400px", zIndex: 2, overflow: "visible", cursor: grabbing ? "grabbing" : "grab", filter: hasShadow ? `drop-shadow(0px ${(tEased * 22).toFixed(1)}px ${(tEased * 32).toFixed(1)}px ${shadowRgba})` : "none", transition: "filter 0.15s ease", pointerEvents: "auto" }} onPointerDown={() => setGrabbing(true)} onPointerUp={() => setGrabbing(false)} onPointerLeave={() => setGrabbing(false)} >+ <div+ style={{+ position: "absolute",+ inset: "-400px",+ zIndex: 2,+ overflow: "visible",+ cursor: grabbing ? "grabbing" : "grab",+ filter: outlineFilter,+ transition: "filter 0.15s ease",+ pointerEvents: "auto",+ ...maskStyle,+ }}+ onPointerDown={() => setGrabbing(true)}+ onPointerUp={() => setGrabbing(false)}+ onPointerLeave={() => setGrabbing(false)}+ ><CanvasWithLoaderimageUrl={imageUrl}imageMaskConfig={imageMaskConfig}diff --git a/app/components/ui/editor/mockups-3d/Laptop3DViewer.tsx b/app/components/ui/editor/mockups-3d/Laptop3DViewer.tsxindex d1f0f30..7d02bc4 100644--- a/app/components/ui/editor/mockups-3d/Laptop3DViewer.tsx+++ b/app/components/ui/editor/mockups-3d/Laptop3DViewer.tsx@@ -10,9 +10,12 @@ import {applyCropToImage,parseShadowColor,type ImageMaskConfigLike,+ applyTextureCover,+ getOutlineFilter,} from "@/lib/phone3d.utils";import type { OrbitControls as OrbitControlsType } from 'three-stdlib';import { EnvironmentPreset, HDRI_FILES } from "@/lib/viewer-controls3d";+import { GetMediaMaskStyles } from "@/lib/media-mask.utils";THREE.Cache.enabled = true;@@ -57,6 +60,8 @@ interface Props {rotationSpeed?: number;glow?: number;environment?: EnvironmentPreset;+ isHovered: boolean;+ isSelected: boolean;}let gltfCachePromise: Promise<THREE.Group> | null = null;@@ -234,7 +239,7 @@ function ModelScene({const TEX_W = RENDER_W;const TEX_H = RENDER_H;const cropped = applyCropToImage(img, cropArea);- const cover = createCoverScreenCanvas(cropped, TEX_W, TEX_H, 0, imageMaskConfig);+ const cover = createCoverScreenCanvas(cropped, TEX_W, TEX_H, 0, null);if (currentMat.map) {currentMat.map.dispose();@@ -301,6 +306,23 @@ function ModelScene({tex.wrapS = THREE.ClampToEdgeWrapping;tex.wrapT = THREE.ClampToEdgeWrapping;+ const updateTextureTransform = () => {+ applyTextureCover(+ tex,+ videoElement.videoWidth,+ videoElement.videoHeight,+ screenSize[0] * 100,+ screenSize[1] * 100+ );+ applyVideoTextureIfReady();+ };++ if (videoElement.readyState >= 1) {+ updateTextureTransform();+ } else {+ videoElement.addEventListener("loadedmetadata", updateTextureTransform);+ }+if (videoTextureRef.current) {videoTextureRef.current.dispose();}@@ -309,6 +331,7 @@ function ModelScene({applyVideoTextureIfReady();return () => {+ videoElement.removeEventListener("loadedmetadata", updateTextureTransform);if (videoTextureRef.current === tex) {videoTextureRef.current = null;}@@ -556,7 +579,7 @@ function CanvasWithLoader(}export function Laptop3DViewer(props: Props) {- const { shadowIntensity = 0, shadowColor = "#000000" } = props;+ const { shadowIntensity = 0, shadowColor = "#000000", imageMaskConfig = null, isHovered = false, isSelected = false } = props;const rootRef = useRef<THREE.Group | null>(null);const cameraRef = useRef<THREE.PerspectiveCamera | null>(null);const [grabbing, setGrabbing] = useState(false);@@ -568,6 +591,15 @@ export function Laptop3DViewer(props: Props) {const shadowRgba = shadowColor.startsWith("#") ? parseShadowColor(shadowColor, computedOpacity) : shadowColor;const hasShadow = t > 0.01;+ const maskStyle = GetMediaMaskStyles(imageMaskConfig, {+ insetX: 0,+ insetY: 0,+ deviceWidth: LAPTOP_W,+ deviceHeight: LAPTOP_H,+ });++ const outlineFilter = getOutlineFilter(isSelected, isHovered);+return (<><div@@ -615,10 +647,9 @@ export function Laptop3DViewer(props: Props) {overflow: "visible",zIndex: 2,cursor: grabbing ? "grabbing" : "grab",- filter: hasShadow- ? `drop-shadow(0px ${(tEased * 22).toFixed(1)}px ${(tEased * 32).toFixed(1)}px ${shadowRgba})`- : "none",+ filter: outlineFilter,transition: "filter 0.15s ease",+ ...maskStyle,}}onPointerDown={() => setGrabbing(true)}onPointerUp={() => setGrabbing(false)}diff --git a/app/components/ui/editor/mockups-3d/Phone3DViewer.tsx b/app/components/ui/editor/mockups-3d/Phone3DViewer.tsxindex ebb4b5b..e6fa36b 100644--- a/app/components/ui/editor/mockups-3d/Phone3DViewer.tsx+++ b/app/components/ui/editor/mockups-3d/Phone3DViewer.tsx@@ -16,9 +16,12 @@ import {cloneGroup,type ImageMaskConfigLike,parseShadowColor,+ applyTextureCover,+ getOutlineFilter,} from "@/lib/phone3d.utils";import type { OrbitControls as OrbitControlsType } from 'three-stdlib';import { EnvironmentPreset, HDRI_FILES } from "@/lib/viewer-controls3d";+import { GetMediaMaskStyles } from "@/lib/media-mask.utils";THREE.Cache.enabled = true;@@ -48,6 +51,8 @@ interface Props {rotationSpeed?: number;glow?: number;environment?: EnvironmentPreset;+ isHovered: boolean;+ isSelected: boolean;}const DEG = Math.PI / 180;@@ -355,6 +360,7 @@ function ModelScene({}return;}+const device = getDeviceFromModelUrl(modelUrl);const isDefaultPhone = device === "phone";@@ -367,13 +373,44 @@ function ModelScene({tex.wrapS = THREE.ClampToEdgeWrapping;tex.wrapT = THREE.ClampToEdgeWrapping;+ const updateTextureTransform = () => {+ let TARGET_W = 2048;+ let TARGET_H = 0;++ if (isDefaultPhone) {+ TARGET_W = PHONE_W * 4;+ TARGET_H = Math.round(TARGET_W / screenAspectRef.current);+ } else {+ const deviceConfig = deviceConfigs[device];+ TARGET_H = Math.round(TARGET_W / deviceConfig.aspectRatio);+ }++ applyTextureCover(+ tex,+ videoElement.videoWidth,+ videoElement.videoHeight,+ TARGET_W,+ TARGET_H+ );++ applyVideoTextureIfReady();+ };++ if (videoElement.readyState >= 1) {+ updateTextureTransform();+ } else {+ videoElement.addEventListener("loadedmetadata", updateTextureTransform);+ }+if (videoTextureRef.current) {videoTextureRef.current.dispose();}videoTextureRef.current = tex;+applyVideoTextureIfReady();return () => {+ videoElement.removeEventListener("loadedmetadata", updateTextureTransform);if (videoTextureRef.current === tex) {videoTextureRef.current = null;}@@ -415,10 +452,9 @@ function ModelScene({const center = box.getCenter(new THREE.Vector3());const size = box.getSize(new THREE.Vector3());const halfH = camZ * Math.tan((40 / 2) * DEG);-- // Se reduce ligeramente el factor (de 0.8 a 0.72) para dar mayor margen a la diagonal del teléfono al girar+const sf = (halfH * 2 * 0.72) / size.y;-+group.scale.setScalar(sf);group.position.copy(center).negate().multiplyScalar(sf);@@ -530,11 +566,9 @@ function ModelScene({const id = setTimeout(() => {const orbit = orbitRef.current;if (!orbit) return;-- // Mantenemos la cámara siempre a una distancia física de 1.5 para evitar colisionar con el Near-Plane.- // El zoom es manejado de manera óptica (PerspectiveCamera zoom prop)- const radius = 1.5;-++ const radius = 1.5;+const phi = Math.PI / 2 - initialRotationX * DEG;const theta = initialRotationY * DEG;orbit.object.position.setFromSphericalCoords(radius, phi, theta);@@ -554,9 +588,8 @@ function ModelScene({return (<>- {/* Pasamos zoom={zoom} y bloqueamos pos Z en 1.5 en lugar de (1.5 / zoom) para no golpear el recorte Near de la cámara */}<PerspectiveCamera ref={cameraRef} makeDefault fov={40} near={0.01} far={100} position={[0, 0, 1.5]} zoom={zoom} />-+<OrbitControlsref={orbitRef}enableZoom={false}@@ -578,7 +611,7 @@ function ModelScene({<directionalLight position={[3, 6, 5]} intensity={0.6} /><directionalLight position={[-4, -2, 3]} intensity={0.25} color="#c8d8ff" /><directionalLight position={[0, -5, 5]} intensity={0.35} />-+<group ref={rootRef} rotation={[0, 0, initialRotationZ * DEG]}>{modelGroup && <primitive object={modelGroup} />}</group>@@ -634,7 +667,7 @@ function CanvasWithLoader(}export function Phone3DViewer(props: Props) {- const { shadowIntensity = 0, shadowColor = "#000000" } = props;+ const { shadowIntensity = 0, shadowColor = "#000000", imageMaskConfig = null, isHovered = false, isSelected = false } = props;const rootRef = useRef<THREE.Group | null>(null);const cameraRef = useRef<THREE.PerspectiveCamera | null>(null);const [grabbing, setGrabbing] = useState(false);@@ -647,6 +680,14 @@ export function Phone3DViewer(props: Props) {const shadowRgba = shadowColor.startsWith("#") ? parseShadowColor(shadowColor, computedOpacity) : shadowColor;const hasShadow = t > 0.01;+ const maskStyle = GetMediaMaskStyles(imageMaskConfig, {+ inset: 300,+ deviceWidth: PHONE_W,+ deviceHeight: PHONE_H,+ });++ const outlineFilter = getOutlineFilter(isSelected, isHovered);+return (<><div@@ -678,7 +719,6 @@ export function Phone3DViewer(props: Props) {/>)}- {/* El canvas ahora fuerza una proporción cuadradra 1:1 de un tamaño generoso para evitar recortes del Frustum Horizontal */}<divstyle={{position: "absolute",@@ -690,11 +730,10 @@ export function Phone3DViewer(props: Props) {zIndex: 2,overflow: "visible",cursor: grabbing ? "grabbing" : "grab",- filter: hasShadow- ? `drop-shadow(0px ${(tEased * 22).toFixed(1)}px ${(tEased * 32).toFixed(1)}px ${shadowRgba})`- : "none",+ filter: outlineFilter,transition: "filter 0.15s ease",pointerEvents: "auto",+ ...maskStyle}}onPointerDown={() => setGrabbing(true)}onPointerUp={() => setGrabbing(false)}