"use client";
import { Canvas } from "@react-three/fiber";
import {
OrbitControls,
PerspectiveCamera,
Environment,
ContactShadows,
} from "@react-three/drei";
import { Door3DEnhanced } from "./door-3d-enhanced";
import { useConfiguratorStore } from "@/lib/store";
import {
STELRUIMTE,
WALL_THICKNESS,
TAATS_PIVOT_OFFSET,
mmToMeters,
} from "@/lib/door-models";
import * as THREE from "three";
// ============================================
// WALL MATERIALS
// ============================================
/** Smooth painted wall surface */
const WallMaterial = () => (
);
/** Stucco/plaster reveal surface (inside the door opening) */
const RevealMaterial = () => (
);
/** Floor material - light wood */
const FloorMaterial = () => (
);
// ============================================
// WALL CONTAINER WITH PRECISE HOLE
// ============================================
/**
* Creates a wall with a precise rectangular opening (sparing).
* Uses 4 boxes to form the wall around the hole instead of CSG.
* The reveal (inner edge of the hole) has a plaster texture.
*/
function WallContainer({
holeWidth,
holeHeight,
wallThickness,
}: {
holeWidth: number; // meters - sparingsmaat width
holeHeight: number; // meters - sparingsmaat height
wallThickness: number; // meters
}) {
const wallWidth = 4.0; // Total wall width in meters
const wallHeight = 3.0; // Total wall height (floor to ceiling)
// Half dimensions for positioning
const halfHoleW = holeWidth / 2;
const halfWallT = wallThickness / 2;
// Left wall section: from left edge to hole left edge
const leftSectionWidth = (wallWidth - holeWidth) / 2;
const leftSectionX = -(halfHoleW + leftSectionWidth / 2);
// Right wall section: from hole right edge to right edge
const rightSectionWidth = leftSectionWidth;
const rightSectionX = halfHoleW + rightSectionWidth / 2;
// Top section: above hole, full width
const topSectionHeight = wallHeight - holeHeight;
const topSectionY = holeHeight + topSectionHeight / 2;
// Stelruimte gap (visual indicator)
const gapPerSide = mmToMeters(STELRUIMTE / 2);
return (
{/* === MAIN WALL SECTIONS === */}
{/* Left wall section */}
{/* Right wall section */}
{/* Top section (above hole, full wall width) */}
{topSectionHeight > 0.01 && (
)}
{/* === REVEAL SURFACES (inside the hole) === */}
{/* These are the plaster/stucco edges visible inside the opening */}
{/* Left reveal */}
{/* Right reveal */}
{/* Top reveal */}
{/* === REVEAL DEPTH SURFACES (visible sides inside the opening) === */}
{/* Left inner wall (visible when looking at the opening from the side) */}
{/* Right inner wall */}
{/* Top inner wall (lintel reveal) */}
{/* === FLOOR === */}
{/* Floor behind wall */}
{/* === BASEBOARD (Plint) === */}
{/* Left side baseboard */}
{/* Right side baseboard */}
);
}
// ============================================
// DOOR + WALL COMPOSITION
// ============================================
function DoorInWall() {
const { doorType, doorLeafWidth, height, holeWidth } = useConfiguratorStore();
// Convert mm to meters
const doorWidthM = mmToMeters(doorLeafWidth);
const doorHeightM = mmToMeters(height);
const wallThicknessM = mmToMeters(WALL_THICKNESS);
// Sparingsmaat = the hole in the wall
// Use doorLeafWidth + stelruimte as the opening size
const stelruimteM = mmToMeters(STELRUIMTE);
const holeWidthM = doorWidthM + stelruimteM;
const holeHeightM = doorHeightM + stelruimteM / 2; // 5mm top tolerance
// Door Z position depends on type
// Taats: centered in wall thickness (pivot at center)
// Scharnier/Paneel: flush with front wall face
const doorZOffset = doorType === 'taats' ? 0 : wallThicknessM * 0.15;
return (
<>
{/* The wall with precise opening */}
{/* The door, positioned inside the wall opening */}
>
);
}
// ============================================
// LIGHTING
// ============================================
function Lighting() {
return (
<>
{/* Ambient for overall illumination */}
{/* Main directional light (sunlight angle) */}
{/* Fill light from behind/left to illuminate reveal */}
{/* Subtle light from viewer side to show depth in reveal */}
{/* Top down light for reveal shadows */}
>
);
}
// ============================================
// MAIN SCENE EXPORT
// ============================================
export function Scene3D() {
return (
);
}