2026-10-25 18:20:21 +03:00
|
|
|
|
"use client";
|
|
|
|
|
|
|
2026-11-12 11:57:21 +03:00
|
|
|
|
import React, { useState } from "react";
|
|
|
|
|
|
import { Mountain, X, Sparkles } from "lucide-react";
|
2026-10-25 18:20:21 +03:00
|
|
|
|
import {
|
2026-11-12 11:57:21 +03:00
|
|
|
|
generateAdvancedTerrainWithPad,
|
|
|
|
|
|
type TerrainTopographyPreset,
|
|
|
|
|
|
} from "@/lib/architecturalBimEngine";
|
2026-10-25 18:20:21 +03:00
|
|
|
|
import type { WorkplaneShape, ArchitecturalTextureId } from "@/types/sketchforge";
|
|
|
|
|
|
|
|
|
|
|
|
export interface TerrainGeneratorModalProps {
|
|
|
|
|
|
isOpen: boolean;
|
|
|
|
|
|
onClose: () => void;
|
|
|
|
|
|
onAddShape: (shape: WorkplaneShape) => void;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export const TerrainGeneratorModal: React.FC<TerrainGeneratorModalProps> = ({
|
|
|
|
|
|
isOpen,
|
|
|
|
|
|
onClose,
|
|
|
|
|
|
onAddShape,
|
|
|
|
|
|
}) => {
|
2026-11-12 11:57:21 +03:00
|
|
|
|
const [preset, setPreset] = useState<TerrainTopographyPreset>("hills");
|
2026-10-25 18:20:21 +03:00
|
|
|
|
const [width, setWidth] = useState(200);
|
|
|
|
|
|
const [depth, setDepth] = useState(200);
|
|
|
|
|
|
const [maxHeight, setMaxHeight] = useState(18);
|
|
|
|
|
|
const [texture, setTexture] = useState<ArchitecturalTextureId>("grass");
|
2026-11-12 11:57:21 +03:00
|
|
|
|
const [includeBuildingPad, setIncludeBuildingPad] = useState(true);
|
2026-10-25 18:20:21 +03:00
|
|
|
|
|
|
|
|
|
|
if (!isOpen) return null;
|
|
|
|
|
|
|
2026-11-12 11:57:21 +03:00
|
|
|
|
const previewResult = generateAdvancedTerrainWithPad({
|
|
|
|
|
|
preset,
|
|
|
|
|
|
width,
|
|
|
|
|
|
depth,
|
|
|
|
|
|
maxHeight,
|
|
|
|
|
|
gridResolution: 16,
|
|
|
|
|
|
texture,
|
|
|
|
|
|
includeBuildingPad,
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-10-25 18:20:21 +03:00
|
|
|
|
const handleGenerate = () => {
|
2026-11-12 11:57:21 +03:00
|
|
|
|
onAddShape(previewResult.terrainShape);
|
|
|
|
|
|
if (previewResult.padShape) {
|
|
|
|
|
|
onAddShape(previewResult.padShape);
|
2026-10-25 18:20:21 +03:00
|
|
|
|
}
|
|
|
|
|
|
onClose();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div
|
|
|
|
|
|
className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4 backdrop-blur-sm"
|
|
|
|
|
|
role="dialog"
|
|
|
|
|
|
aria-modal="true"
|
|
|
|
|
|
aria-labelledby="terrain-title"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div className="relative flex max-h-[90vh] w-full max-w-md flex-col rounded-2xl border border-slate-200 bg-white shadow-2xl dark:border-slate-800 dark:bg-slate-900">
|
|
|
|
|
|
{/* Header */}
|
|
|
|
|
|
<div className="flex items-center justify-between border-b border-slate-200 px-6 py-4 dark:border-slate-800">
|
|
|
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
|
<div className="flex h-10 w-10 items-center justify-center rounded-xl bg-emerald-500/10 text-emerald-600 dark:bg-emerald-500/20 dark:text-emerald-400">
|
|
|
|
|
|
<Mountain className="h-5 w-5" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<h2
|
|
|
|
|
|
id="terrain-title"
|
|
|
|
|
|
className="text-lg font-bold text-slate-900 dark:text-white"
|
|
|
|
|
|
>
|
|
|
|
|
|
Arazi & Topoğrafya Oluşturucu
|
|
|
|
|
|
</h2>
|
|
|
|
|
|
<p className="text-xs text-slate-500 dark:text-slate-400">
|
2026-11-12 11:57:21 +03:00
|
|
|
|
Simplex-Noise + Delaunator üçgenleme ve bina oturum hafriyat hesabı
|
2026-10-25 18:20:21 +03:00
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
onClick={onClose}
|
|
|
|
|
|
className="rounded-lg p-2 text-slate-400 transition-colors hover:bg-slate-100 dark:hover:bg-slate-800"
|
|
|
|
|
|
aria-label="Kapat"
|
|
|
|
|
|
>
|
|
|
|
|
|
<X className="h-5 w-5" />
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* Content */}
|
|
|
|
|
|
<div className="flex-1 space-y-4 overflow-y-auto px-6 py-4 text-sm">
|
|
|
|
|
|
{/* Preset Selection */}
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<label className="mb-2 block text-xs font-semibold uppercase tracking-wider text-slate-500 dark:text-slate-400">
|
|
|
|
|
|
Arazi Tipi
|
|
|
|
|
|
</label>
|
|
|
|
|
|
<div className="grid grid-cols-2 gap-2">
|
|
|
|
|
|
{[
|
2026-11-12 11:57:21 +03:00
|
|
|
|
{ id: "hills", label: "Dalgalı Tepe", desc: "Simplex doğal yükseltiler" },
|
2026-10-25 18:20:21 +03:00
|
|
|
|
{ id: "slope", label: "Eğimli Arsa", desc: "Tek yöne meyil" },
|
2026-11-12 11:57:21 +03:00
|
|
|
|
{ id: "terrace", label: "Teraslı Plato", desc: "Eşyükselti kademeli kotlar" },
|
|
|
|
|
|
{ id: "valley", label: "Vadi / Çukur", desc: "Ortası alçak vadi" },
|
|
|
|
|
|
{ id: "coastal-ridge", label: "Kıyı Sırtı", desc: "Yamaç ve sırt hattı" },
|
2026-10-25 18:20:21 +03:00
|
|
|
|
].map((item) => (
|
|
|
|
|
|
<button
|
|
|
|
|
|
key={item.id}
|
|
|
|
|
|
type="button"
|
2026-11-12 11:57:21 +03:00
|
|
|
|
onClick={() => setPreset(item.id as TerrainTopographyPreset)}
|
2026-10-25 18:20:21 +03:00
|
|
|
|
className={`flex flex-col items-start rounded-xl border p-2.5 text-left transition-all ${
|
|
|
|
|
|
preset === item.id
|
|
|
|
|
|
? "border-emerald-500 bg-emerald-50/70 text-emerald-900 dark:bg-emerald-950/40 dark:text-emerald-200"
|
|
|
|
|
|
: "border-slate-200 hover:border-slate-300 dark:border-slate-800 dark:hover:border-slate-700"
|
|
|
|
|
|
}`}
|
|
|
|
|
|
>
|
|
|
|
|
|
<span className="font-semibold text-xs">{item.label}</span>
|
|
|
|
|
|
<span className="text-[10px] text-slate-400">{item.desc}</span>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* Sliders */}
|
|
|
|
|
|
<div className="space-y-3 rounded-xl border border-slate-100 bg-slate-50/60 p-3.5 dark:border-slate-800 dark:bg-slate-900/40">
|
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
|
<span className="text-xs text-slate-600 dark:text-slate-300">Genişlik & Derinlik</span>
|
|
|
|
|
|
<span className="font-mono text-xs font-semibold">{width} × {depth} mm</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<input
|
|
|
|
|
|
type="range"
|
|
|
|
|
|
min="100"
|
|
|
|
|
|
max="350"
|
|
|
|
|
|
step="10"
|
|
|
|
|
|
value={width}
|
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
|
const val = Number(e.target.value);
|
|
|
|
|
|
setWidth(val);
|
|
|
|
|
|
setDepth(val);
|
|
|
|
|
|
}}
|
|
|
|
|
|
className="w-full accent-emerald-600"
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="flex items-center justify-between pt-1">
|
|
|
|
|
|
<span className="text-xs text-slate-600 dark:text-slate-300">Tepe / Kot Yüksekliği</span>
|
|
|
|
|
|
<span className="font-mono text-xs font-semibold">{maxHeight} mm</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<input
|
|
|
|
|
|
type="range"
|
|
|
|
|
|
min="4"
|
|
|
|
|
|
max="45"
|
|
|
|
|
|
step="1"
|
|
|
|
|
|
value={maxHeight}
|
|
|
|
|
|
onChange={(e) => setMaxHeight(Number(e.target.value))}
|
|
|
|
|
|
className="w-full accent-emerald-600"
|
|
|
|
|
|
/>
|
2026-11-12 11:57:21 +03:00
|
|
|
|
|
|
|
|
|
|
<label className="flex items-center justify-between pt-2 text-xs font-medium text-slate-700 dark:text-slate-200 cursor-pointer">
|
|
|
|
|
|
<span>Bina Oturum Düzlüğü (Tesviye Kotu & Hafriyat)</span>
|
|
|
|
|
|
<input
|
|
|
|
|
|
type="checkbox"
|
|
|
|
|
|
checked={includeBuildingPad}
|
|
|
|
|
|
onChange={(e) => setIncludeBuildingPad(e.target.checked)}
|
|
|
|
|
|
className="h-4 w-4 accent-emerald-600"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</label>
|
|
|
|
|
|
{includeBuildingPad ? (
|
|
|
|
|
|
<div className="grid grid-cols-3 gap-2 pt-1 text-center text-[11px]">
|
|
|
|
|
|
<div className="rounded-lg bg-white p-1.5 dark:bg-slate-800">
|
|
|
|
|
|
<span className="block text-slate-400">Kazı (Hafriyat)</span>
|
|
|
|
|
|
<strong className="text-amber-600 dark:text-amber-400">{previewResult.excavationCutVolumeM3} m³</strong>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="rounded-lg bg-white p-1.5 dark:bg-slate-800">
|
|
|
|
|
|
<span className="block text-slate-400">Dolgu Hacmi</span>
|
|
|
|
|
|
<strong className="text-sky-600 dark:text-sky-400">{previewResult.embankmentFillVolumeM3} m³</strong>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="rounded-lg bg-white p-1.5 dark:bg-slate-800">
|
|
|
|
|
|
<span className="block text-slate-400">Delaunay Ağ</span>
|
|
|
|
|
|
<strong className="text-emerald-600 dark:text-emerald-400">{previewResult.triangleCount} üçgen</strong>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : null}
|
2026-10-25 18:20:21 +03:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* Texture */}
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<label className="mb-2 block text-xs font-semibold uppercase tracking-wider text-slate-500 dark:text-slate-400">
|
|
|
|
|
|
Yüzey Kaplaması
|
|
|
|
|
|
</label>
|
|
|
|
|
|
<div className="flex gap-2">
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
onClick={() => setTexture("grass")}
|
|
|
|
|
|
className={`flex-1 rounded-xl border py-2 text-xs font-medium transition-all ${
|
|
|
|
|
|
texture === "grass"
|
|
|
|
|
|
? "border-emerald-500 bg-emerald-500 text-white shadow-sm"
|
|
|
|
|
|
: "border-slate-200 dark:border-slate-700"
|
|
|
|
|
|
}`}
|
|
|
|
|
|
>
|
|
|
|
|
|
🌱 Çim & Doğa
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
onClick={() => setTexture("concrete")}
|
|
|
|
|
|
className={`flex-1 rounded-xl border py-2 text-xs font-medium transition-all ${
|
|
|
|
|
|
texture === "concrete"
|
|
|
|
|
|
? "border-emerald-500 bg-emerald-500 text-white shadow-sm"
|
|
|
|
|
|
: "border-slate-200 dark:border-slate-700"
|
|
|
|
|
|
}`}
|
|
|
|
|
|
>
|
|
|
|
|
|
🧱 Toprak & Beton
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* Footer */}
|
|
|
|
|
|
<div className="flex items-center justify-end gap-2 border-t border-slate-200 bg-slate-50 px-6 py-3.5 dark:border-slate-800 dark:bg-slate-950/50">
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
onClick={onClose}
|
|
|
|
|
|
className="rounded-xl px-4 py-2 text-xs font-semibold text-slate-600 hover:bg-slate-100 dark:text-slate-300 dark:hover:bg-slate-800"
|
|
|
|
|
|
>
|
|
|
|
|
|
İptal
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
onClick={handleGenerate}
|
|
|
|
|
|
className="flex items-center gap-1.5 rounded-xl bg-emerald-600 px-5 py-2 text-xs font-semibold text-white shadow-sm hover:bg-emerald-500 active:scale-95"
|
|
|
|
|
|
>
|
|
|
|
|
|
<Sparkles className="h-4 w-4" />
|
|
|
|
|
|
<span>Araziyi Oluştur</span>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|