"use client";
import { useRef } from "react";
import { useConfiguratorStore } from "@/lib/store";
import { RoundedBox, Text, useTexture } from "@react-three/drei";
import { getMetalTexture } from "@/lib/asset-map";
import * as THREE from "three";
// Steel material with photorealistic texture mapping
const SteelMaterial = ({ color, finish }: { color: string; finish: string }) => {
try {
const metalTexture = useTexture(getMetalTexture(finish));
// Configure texture repeat for realistic grain (4x horizontal, 8x vertical)
metalTexture.wrapS = metalTexture.wrapT = THREE.RepeatWrapping;
metalTexture.repeat.set(4, 8);
return (
);
} catch (error) {
// Fallback to solid color if texture fails
return (
);
}
};
// Glass material
const GlassMaterial = () => (
);
// 3D Dimension Label Component
function DimensionLabel({
value,
position,
label,
}: {
value: number;
position: [number, number, number];
label: string;
}) {
return (
{`${Math.round(value)} ${label}`}
{/* Background for better readability */}
);
}
export function Door3DEnhanced() {
const { doorType, gridType, finish, handle, doorLeafWidth, height } =
useConfiguratorStore();
const doorRef = useRef(null);
// Frame color based on finish
const frameColor = {
zwart: "#1a1a1a",
brons: "#8B6F47",
grijs: "#525252",
}[finish];
// Convert mm to meters for 3D scene
const doorWidth = doorLeafWidth / 1000; // Convert mm to m
const doorHeight = height / 1000; // Convert mm to m
// Profile dimensions (in meters)
const stileWidth = 0.04; // 40mm vertical profiles
const stileDepth = 0.04; // 40mm depth
const railHeight = 0.02; // 20mm horizontal profiles
const railDepth = 0.04; // 40mm depth
const glassThickness = 0.008; // 8mm glass
const profileRadius = 0.001; // 1mm rounded corners
// Calculate positions for grid dividers
const getDividerPositions = () => {
if (gridType === "3-vlak") {
return [-doorHeight / 3, doorHeight / 3];
} else if (gridType === "4-vlak") {
return [-doorHeight / 2, 0, doorHeight / 2];
}
return [];
};
const dividerPositions = getDividerPositions();
return (
{/* LEFT STILE - Vertical profile */}
{/* RIGHT STILE - Vertical profile */}
{/* TOP RAIL - Horizontal profile */}
{/* BOTTOM RAIL - Horizontal profile */}
{/* INTERMEDIATE RAILS (Grid dividers) */}
{dividerPositions.map((yPos, index) => (
))}
{/* VERTICAL DIVIDER for Paneel */}
{doorType === "paneel" && (
)}
{/* GLASS PANEL - Sits inside the frame */}
{/* HANDLE - U-Greep for Taats */}
{doorType === "taats" && handle === "u-greep" && (
)}
{/* HANDLE - Klink for Scharnier */}
{doorType === "scharnier" && handle === "klink" && (
)}
{/* 3D DIMENSION LABELS */}
{/* Width dimension */}
{/* Height dimension */}
{/* Dimension lines */}
{/* Horizontal line for width */}
{/* Vertical line for height */}
);
}