Create professional demos and 3D mockups in seconds, directly in your browser
feat: integrate HDRI environment files for enhanced lighting in 3D viewers; update shadow settings and improve camera parameters
CristianOlivera1f026e4ae57b8
diff --git a/app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsx b/app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsxindex 23d4669..9b958c1 100644--- a/app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsx+++ b/app/components/ui/editor/mockups-3d/DoubleIPhone3DViewer.tsx@@ -13,7 +13,7 @@ import {parseShadowColor,} from "@/lib/phone3d.utils";import type { OrbitControls as OrbitControlsType } from 'three-stdlib';-import { EnvironmentPreset } from "@/lib/viewer-controls3d";+import { EnvironmentPreset, HDRI_FILES } from "@/lib/viewer-controls3d";export interface DoubleIPhone3DApi {renderAt: (width: number, height: number) => void;@@ -380,7 +380,7 @@ function ModelScene({onRotationChange(rx, ry);}}/>- <Environment preset={environment as EnvironmentPreset} environmentIntensity={glow} background={false} />+ <Environment files={HDRI_FILES[environment as EnvironmentPreset]} environmentIntensity={glow} background={false} /><ambientLight intensity={0.3} /><directionalLight position={[3, 6, 5]} intensity={0.6} /><directionalLight position={[-4, -2, 3]} intensity={0.25} color="#c8d8ff" />diff --git a/app/components/ui/editor/mockups-3d/IPhone13ProMax3DViewer.tsx b/app/components/ui/editor/mockups-3d/IPhone13ProMax3DViewer.tsxindex 14d0f10..31e18fe 100644--- a/app/components/ui/editor/mockups-3d/IPhone13ProMax3DViewer.tsx+++ b/app/components/ui/editor/mockups-3d/IPhone13ProMax3DViewer.tsx@@ -6,7 +6,7 @@ import { useEffect, useRef, useState, Suspense, useLayoutEffect } from "react";import * as THREE from "three";import { createCoverScreenCanvas, applyCropToImage, parseShadowColor, type ImageMaskConfigLike } from "@/lib/phone3d.utils";import type { OrbitControls as OrbitControlsType } from 'three-stdlib';-import { EnvironmentPreset } from "@/lib/viewer-controls3d";+import { EnvironmentPreset, HDRI_FILES } from "@/lib/viewer-controls3d";export interface IPhone13ProMax3DApi {renderAt: (width: number, height: number) => void;@@ -387,7 +387,9 @@ function ModelScene({const shadowT = Math.max(0, Math.min(1, shadowIntensity));const showContactShadow = shadowT > 0.01;- const contactOpacity = shadowT * 0.65;+ const contactOpacity = shadowT * 0.45;+ // Sombra proyectada — más larga, con dirección, más sutil+ const castOpacity = shadowT * 0.55;const contactBlur = 1.5 + shadowT * 1.5;return (@@ -401,7 +403,7 @@ function ModelScene({position={DEFAULT_CAMERA_POS}zoom={zoom}/>- <Environment preset={environment as EnvironmentPreset} environmentIntensity={glow} background={false} />+ <Environment files={HDRI_FILES[environment as EnvironmentPreset]} environmentIntensity={glow} background={false} /><OrbitControlsref={orbitRef}enableZoom={false}@@ -419,19 +421,42 @@ function ModelScene({}}/><ambientLight intensity={0.3} />- <directionalLight position={[3, 6, 5]} intensity={0.6} />+ <directionalLight+ position={[3, 6, 5]}+ intensity={0.6}+ castShadow+ shadow-mapSize={[2048, 2048]}+ shadow-camera-near={0.1}+ shadow-camera-far={10}+ shadow-camera-left={-1.5}+ shadow-camera-right={1.5}+ shadow-camera-top={1.5}+ shadow-camera-bottom={-1.5}+ shadow-bias={-0.0015}+ shadow-normalBias={0.02}+ /><directionalLight position={[-4, -2, 3]} intensity={0.25} color="#c8d8ff" /><directionalLight position={[0, -5, 5]} intensity={0.35} />{showContactShadow && (- <ContactShadows- position={[0, -0.55, 0]}- opacity={contactOpacity}- scale={3}- blur={contactBlur}- far={4}- color={shadowColor}- resolution={512}- />+ <>+ {/* Capa 1: sombra proyectada real, con dirección, del shadow map */}+ <mesh position={[0, -0.55, 0]} rotation={[-Math.PI / 2, 0, 0]} receiveShadow>+ <planeGeometry args={[10, 10]} />+ <shadowMaterial transparent opacity={castOpacity} color={shadowColor} />+ </mesh>+ {/* Capa 2: AO de contacto, corta y muy oscura, justo bajo el modelo.+ Offset de +1mm en Y respecto al plano de arriba para evitar z-fighting+ entre ambos planos coplanares. */}+ <ContactShadows+ position={[0, -0.549, 0]}+ opacity={contactOpacity}+ scale={3}+ blur={contactBlur}+ far={4}+ color={shadowColor}+ resolution={512}+ />+ </>)}<group ref={rootRef} rotation={[0, Math.PI, 0]} scale={0.007} dispose={null}><group scale={100}>@@ -516,6 +541,7 @@ function CanvasWithLoader({return (<><Canvas+ shadows="soft"style={{ width: "100%", height: "100%", overflow: "visible" }}gl={{antialias: true,diff --git a/app/components/ui/editor/mockups-3d/IPhone17ProMax3DViewer.tsx b/app/components/ui/editor/mockups-3d/IPhone17ProMax3DViewer.tsxindex d6dd2f6..3e26145 100644--- a/app/components/ui/editor/mockups-3d/IPhone17ProMax3DViewer.tsx+++ b/app/components/ui/editor/mockups-3d/IPhone17ProMax3DViewer.tsx@@ -6,7 +6,7 @@ import { useEffect, useRef, useState, Suspense, useLayoutEffect, useMemo, useCalimport * as THREE from "three";import { createCoverScreenCanvas, applyCropToImage, parseShadowColor, type ImageMaskConfigLike } from "@/lib/phone3d.utils";import type { OrbitControls as OrbitControlsType } from 'three-stdlib';-import { EnvironmentPreset } from "@/lib/viewer-controls3d";+import { EnvironmentPreset, HDRI_FILES } from "@/lib/viewer-controls3d";export interface IPhone17ProMax3DApi {renderAt: (width: number, height: number) => void;@@ -349,7 +349,7 @@ function ModelScene({return (<><PerspectiveCamera ref={cameraRef} makeDefault fov={40} near={0.01} far={100} position={DEFAULT_CAMERA_POS} zoom={zoom} />- <Environment preset={environment as EnvironmentPreset} environmentIntensity={glow} background={false} />+ <Environment files={HDRI_FILES[environment as EnvironmentPreset]} environmentIntensity={glow} background={false} /><OrbitControls ref={orbitRef} enableZoom={false} enablePan={false} enableDamping dampingFactor={0.08} autoRotate={autoRotate} autoRotateSpeed={rotationSpeed} onEnd={() => {const orbit = orbitRef.current;if (!orbit || !onRotationChange) return;diff --git a/app/components/ui/editor/mockups-3d/Laptop3DViewer.tsx b/app/components/ui/editor/mockups-3d/Laptop3DViewer.tsxindex fc52004..d1f0f30 100644--- a/app/components/ui/editor/mockups-3d/Laptop3DViewer.tsx+++ b/app/components/ui/editor/mockups-3d/Laptop3DViewer.tsx@@ -12,7 +12,7 @@ import {type ImageMaskConfigLike,} from "@/lib/phone3d.utils";import type { OrbitControls as OrbitControlsType } from 'three-stdlib';-import { EnvironmentPreset } from "@/lib/viewer-controls3d";+import { EnvironmentPreset, HDRI_FILES } from "@/lib/viewer-controls3d";THREE.Cache.enabled = true;@@ -22,7 +22,7 @@ const RENDER_MULTIPLIER = 3;const RENDER_W = LAPTOP_W * RENDER_MULTIPLIER;const RENDER_H = LAPTOP_H * RENDER_MULTIPLIER;const CAM_FOV = 40;-const CAM_RADIUS = 75;+const CAM_RADIUS = 90;const screenSize: [number, number] = [29.4, 20];const LID_CLOSED_X = Math.PI * 0.5;const LID_OPEN_X = -0.2 * Math.PI;@@ -434,22 +434,31 @@ function ModelScene({};}, [openingProgress, applyVideoTextureIfReady, onLoaded, gl, invalidate]);- const prevRotationRef = useRef({ x: initialRotationX, y: initialRotationY });-+ const prevRotationRef = useRef<{ x: number; y: number } | null>(null);useEffect(() => {- if (prevRotationRef.current.x === initialRotationX && prevRotationRef.current.y === initialRotationY) return;- const orbit = orbitRef.current;- if (!orbit) return;+ if (+ prevRotationRef.current?.x === initialRotationX &&+ prevRotationRef.current?.y === initialRotationY+ ) {+ return;+ }- const radius = CAM_RADIUS / zoom;- const phi = Math.PI / 2 - initialRotationX * DEG;- const theta = initialRotationY * DEG;+ const id = setTimeout(() => {+ const orbit = orbitRef.current;+ if (!orbit) return;- orbit.object.position.setFromSphericalCoords(radius, phi, theta);- orbit.update();- invalidate();+ const radius = CAM_RADIUS / zoom;+ const phi = Math.PI / 2 - initialRotationX * DEG;+ const theta = initialRotationY * DEG;++ orbit.object.position.setFromSphericalCoords(radius, phi, theta);+ orbit.update();+ invalidate();++ prevRotationRef.current = { x: initialRotationX, y: initialRotationY };+ }, 0);- prevRotationRef.current = { x: initialRotationX, y: initialRotationY };+ return () => clearTimeout(id);}, [initialRotationX, initialRotationY, zoom, invalidate]);useEffect(() => {@@ -488,7 +497,7 @@ function ModelScene({onRotationChange(rx, ry);}}/>- <Environment preset={environment as EnvironmentPreset} environmentIntensity={glow} background={false} />+ <Environment files={HDRI_FILES[environment as EnvironmentPreset]} environmentIntensity={glow} background={false} /><ambientLight intensity={3.2} /><group><pointLight position={[0, 5, 50]} intensity={0.8} color="#fff5e1" />diff --git a/app/components/ui/editor/mockups-3d/Phone3DViewer.tsx b/app/components/ui/editor/mockups-3d/Phone3DViewer.tsxindex 991798a..5f4f3e8 100644--- a/app/components/ui/editor/mockups-3d/Phone3DViewer.tsx+++ b/app/components/ui/editor/mockups-3d/Phone3DViewer.tsx@@ -18,7 +18,7 @@ import {parseShadowColor,} from "@/lib/phone3d.utils";import type { OrbitControls as OrbitControlsType } from 'three-stdlib';-import { EnvironmentPreset } from "@/lib/viewer-controls3d";+import { EnvironmentPreset, HDRI_FILES } from "@/lib/viewer-controls3d";THREE.Cache.enabled = true;@@ -600,7 +600,7 @@ function ModelScene({onRotationChange(rx, ry);}}/>- <Environment preset={environment as EnvironmentPreset} environmentIntensity={glow} background={false} />+ <Environment files={HDRI_FILES[environment as EnvironmentPreset]} environmentIntensity={glow} background={false} /><ambientLight intensity={0.3} /><directionalLight position={[3, 6, 5]} intensity={0.6} /><directionalLight position={[-4, -2, 3]} intensity={0.25} color="#c8d8ff" />diff --git a/lib/viewer-controls3d.ts b/lib/viewer-controls3d.tsindex 2f26cac..6469fc5 100644--- a/lib/viewer-controls3d.ts+++ b/lib/viewer-controls3d.ts@@ -8,17 +8,30 @@ interface ViewerControlsOptions {defaultGlow?: number;}+export const HDRI_FILES: Record<EnvironmentPreset, string> = {+ apartment: "/hdri/lebombo_1k.hdr",+ city: "/hdri/potsdamer_platz_1k.hdr",+ dawn: "/hdri/kiara_1_dawn_1k.hdr",+ forest: "/hdri/forest_slope_1k.hdr",+ lobby: "/hdri/st_fagans_interior_1k.hdr",+ night: "/hdri/dikhololo_night_1k.hdr",+ park: "/hdri/rooitou_park_1k.hdr",+ studio: "/hdri/studio_small_03_1k.hdr",+ sunset: "/hdri/venice_sunset_1k.hdr",+ warehouse: "/hdri/empty_warehouse_01_1k.hdr",+};+const ENVIRONMENT_OPTIONS = ['sunset', 'dawn', 'night', 'warehouse', 'forest','apartment', 'studio', 'city', 'park', 'lobby',] as const;- interface Viewer3DControls {- autoRotate: boolean;- rotationSpeed: number;- glow: number;- environment: EnvironmentPreset;- }+interface Viewer3DControls {+ autoRotate: boolean;+ rotationSpeed: number;+ glow: number;+ environment: EnvironmentPreset;+}export function ViewerControls3D({ defaultEnvironment = "studio", defaultGlow = 1.0 }: ViewerControlsOptions = {}): Viewer3DControls {const [controls, set] = useControls("Configuration 3D", () => ({@@ -35,5 +48,5 @@ export function ViewerControls3D({ defaultEnvironment = "studio", defaultGlow =set({ environment: defaultEnvironment, glow: defaultGlow });}, [defaultEnvironment, defaultGlow, set]);- return controls as Viewer3DControls;+ return controls as Viewer3DControls;}\ No newline at end of filediff --git a/proxy.ts b/proxy.tsindex b88575a..a72d7cc 100644--- a/proxy.ts+++ b/proxy.ts@@ -26,6 +26,6 @@ export default async function proxy(request: NextRequest) {export const config = {matcher: [- '/((?!api|ffmpeg|models|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt|.*\\.(?:svg|png|jpg|jpeg|gif|webp|mp4|avif|webm|wasm|js|glb|gltf|json)$).*)'+ '/((?!api|ffmpeg|models|hdri|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt|.*\\.(?:svg|png|jpg|jpeg|gif|webp|mp4|avif|webm|wasm|js|glb|gltf|json)$).*)'],};\ No newline at end of filediff --git a/public/hdri/dikhololo_night_1k.hdr b/public/hdri/dikhololo_night_1k.hdrnew file mode 100644index 0000000..e64612fBinary files /dev/null and b/public/hdri/dikhololo_night_1k.hdr differdiff --git a/public/hdri/empty_warehouse_01_1k.hdr b/public/hdri/empty_warehouse_01_1k.hdrnew file mode 100644index 0000000..5066e1eBinary files /dev/null and b/public/hdri/empty_warehouse_01_1k.hdr differdiff --git a/public/hdri/forest_slope_1k.hdr b/public/hdri/forest_slope_1k.hdrnew file mode 100644index 0000000..541f33cBinary files /dev/null and b/public/hdri/forest_slope_1k.hdr differdiff --git a/public/hdri/kiara_1_dawn_1k.hdr b/public/hdri/kiara_1_dawn_1k.hdrnew file mode 100644index 0000000..26d6666Binary files /dev/null and b/public/hdri/kiara_1_dawn_1k.hdr differdiff --git a/public/hdri/lebombo_1k.hdr b/public/hdri/lebombo_1k.hdrnew file mode 100644index 0000000..3aee193Binary files /dev/null and b/public/hdri/lebombo_1k.hdr differdiff --git a/public/hdri/potsdamer_platz_1k.hdr b/public/hdri/potsdamer_platz_1k.hdrnew file mode 100644index 0000000..e3121c1Binary files /dev/null and b/public/hdri/potsdamer_platz_1k.hdr differdiff --git a/public/hdri/rooitou_park_1k.hdr b/public/hdri/rooitou_park_1k.hdrnew file mode 100644index 0000000..d05a54bBinary files /dev/null and b/public/hdri/rooitou_park_1k.hdr differdiff --git a/public/hdri/st_fagans_interior_1k.hdr b/public/hdri/st_fagans_interior_1k.hdrnew file mode 100644index 0000000..59fe3adBinary files /dev/null and b/public/hdri/st_fagans_interior_1k.hdr differdiff --git a/public/hdri/studio_small_03_1k.hdr b/public/hdri/studio_small_03_1k.hdrnew file mode 100644index 0000000..3565559Binary files /dev/null and b/public/hdri/studio_small_03_1k.hdr differdiff --git a/public/hdri/venice_sunset_1k.hdr b/public/hdri/venice_sunset_1k.hdrnew file mode 100644index 0000000..048bb13Binary files /dev/null and b/public/hdri/venice_sunset_1k.hdr differ