Create professional demos and 3D mockups in seconds, directly in your browser
feat: update texture handling in applyTextureCover function to support cropping and improve aspect ratio calculations
CristianOlivera11114baaf576f
diff --git a/lib/perspective3d.ts b/lib/perspective3d.tsindex d7f6dce..22fae19 100644--- a/lib/perspective3d.ts+++ b/lib/perspective3d.ts@@ -31,11 +31,11 @@ function ensureScene(aspect: number): { scene: THREE.Scene; plane: THREE.Mesh }_offscreen = document.createElement("canvas");_texture = new THREE.CanvasTexture(_offscreen);_texture.colorSpace = THREE.SRGBColorSpace;-- _texture.generateMipmaps = true; // Cambiar a true- _texture.minFilter = THREE.LinearMipmapLinearFilter; // Usar filtro con Mipmap++ _texture.generateMipmaps = false;+ _texture.minFilter = THREE.LinearFilter;_texture.magFilter = THREE.LinearFilter;-+_texture.wrapS = THREE.ClampToEdgeWrapping;_texture.wrapT = THREE.ClampToEdgeWrapping;_texture.premultiplyAlpha = false;diff --git a/lib/phone3d.utils.ts b/lib/phone3d.utils.tsindex a346061..aec1b1d 100644--- a/lib/phone3d.utils.ts+++ b/lib/phone3d.utils.ts@@ -270,26 +270,54 @@ export function applyCropToImage(ctx.drawImage(source, sx, sy, sw, sh, 0, 0, canvas.width, canvas.height);return canvas;}-export function applyTextureCover(texture: THREE.Texture,sourceWidth: number,sourceHeight: number,targetWidth: number,- targetHeight: number+ targetHeight: number,+ cropArea?: CropAreaLike | null) {if (sourceWidth === 0 || sourceHeight === 0) return;-- const videoAspect = sourceWidth / sourceHeight;- const screenAspect = targetWidth / targetHeight;- if (videoAspect > screenAspect) {- texture.repeat.set(screenAspect / videoAspect, 1);- texture.offset.set((1 - texture.repeat.x) / 2, 0);+ let cropX = 0, cropY = 0, cropW = 1, cropH = 1;+ if (cropArea) {+ const x = Math.max(0, Math.min(100, cropArea.x));+ const y = Math.max(0, Math.min(100, cropArea.y));+ const width = Math.max(1, Math.min(100 - x, cropArea.width));+ const height = Math.max(1, Math.min(100 - y, cropArea.height));+ cropX = x / 100;+ cropY = y / 100;+ cropW = width / 100;+ cropH = height / 100;+ }++ const croppedWidth = sourceWidth * cropW;+ const croppedHeight = sourceHeight * cropH;+ const croppedAspect = croppedWidth / croppedHeight;+ const targetAspect = targetWidth / targetHeight;++ let repeatWithinCropX: number;+ let repeatWithinCropY: number;+ if (croppedAspect > targetAspect) {+ repeatWithinCropX = targetAspect / croppedAspect;+ repeatWithinCropY = 1;} else {- texture.repeat.set(1, videoAspect / screenAspect);- texture.offset.set(0, (1 - texture.repeat.y) / 2);+ repeatWithinCropX = 1;+ repeatWithinCropY = croppedAspect / targetAspect;}+ const offsetWithinCropX = (1 - repeatWithinCropX) / 2;+ const offsetWithinCropY = (1 - repeatWithinCropY) / 2;++ const finalRepeatX = repeatWithinCropX * cropW;+ const finalOffsetX = cropX + offsetWithinCropX * cropW;++ const vBase = texture.flipY ? 1 - (cropY + cropH) : cropY;+ const finalRepeatY = repeatWithinCropY * cropH;+ const finalOffsetY = vBase + offsetWithinCropY * cropH;++ texture.repeat.set(finalRepeatX, finalRepeatY);+ texture.offset.set(finalOffsetX, finalOffsetY);texture.needsUpdate = true;}diff --git a/types/editor.types.ts b/types/editor.types.tsindex 558e72d..39d7d4f 100644--- a/types/editor.types.ts+++ b/types/editor.types.ts@@ -126,4 +126,5 @@ export interface VideoCanvasProps {onPaddingChange?: (value: number) => void;imageZoomScale?: number;onImageZoomScaleChange?: (scale: number) => void;+ otherSelectionActive?: boolean}\ No newline at end of filediff --git a/types/zoom.types.ts b/types/zoom.types.tsindex a5aad06..9fb3fbc 100644--- a/types/zoom.types.ts+++ b/types/zoom.types.ts@@ -34,6 +34,7 @@ export interface ZoomFragmentEditorProps {onBack: () => void;onDelete: () => void;onUpdate: (updates: Partial<ZoomFragment>) => void;+ is3DModelActive?: boolean;}// Smoother easing for professional zoom feel (quart curves)@@ -145,7 +146,7 @@ export function calculateZoomPhaseState(// 3D EFFECT: Completely separate from zoom animationif (enable3D) {- const intensity = (fragment.perspective3DIntensity ?? 50) / 100;+ const intensity = (fragment.perspective3DIntensity ?? 50) / 100;const baseAngleX = fragment.perspective3DAngleX ?? 0;const baseAngleY = fragment.perspective3DAngleY ?? 0;@@ -155,10 +156,10 @@ export function calculateZoomPhaseState(if (phase === 'entry') {const entryProgress = (currentTime - fragment.startTime) / transitionSeconds;effect3DOpacity = Math.min(1, entryProgress * 1.2);- } else if (phase === 'exit') {- const exitProgress = (currentTime - exitStartTime) / transitionSeconds;- effect3DOpacity = Math.max(0, 1 - exitProgress); // Reducción 1 a 1 perfecta-}else {+ } else if (phase === 'exit') {+ const exitProgress = (currentTime - exitStartTime) / transitionSeconds;+ effect3DOpacity = Math.max(0, 1 - exitProgress);+ } else {effect3DOpacity = 1;}