Files
snapcad-studio/apps/web/src/components/snapcad/TerrainGeneratorModal.tsx
T
Enes Yakıştır 6769717276
Build and Push Docker Images / build (push) Canceled after 0s
Desktop Release / Build linux desktop (push) Canceled after 0s
Desktop Release / Build windows desktop (push) Canceled after 0s
Desktop Release / Attach packages to release (push) Canceled after 0s
CI / Typecheck and unit tests (push) Canceled after 0s
Desktop Release / Build macos desktop (push) Canceled after 0s
release: SnapCAD Studio 1.0.11 (Mimari BIM & Metraj Studyosu, IFC4 ihraci, canli guncelleme ilerlemesi, YakNet SSO iyilestirmesi)
2026-11-12 11:57:21 +03:00

232 lines
9.5 KiB
TypeScript

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client";
import React, { useState } from "react";
import { Mountain, X, Sparkles } from "lucide-react";
import {
generateAdvancedTerrainWithPad,
type TerrainTopographyPreset,
} from "@/lib/architecturalBimEngine";
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,
}) => {
const [preset, setPreset] = useState<TerrainTopographyPreset>("hills");
const [width, setWidth] = useState(200);
const [depth, setDepth] = useState(200);
const [maxHeight, setMaxHeight] = useState(18);
const [texture, setTexture] = useState<ArchitecturalTextureId>("grass");
const [includeBuildingPad, setIncludeBuildingPad] = useState(true);
if (!isOpen) return null;
const previewResult = generateAdvancedTerrainWithPad({
preset,
width,
depth,
maxHeight,
gridResolution: 16,
texture,
includeBuildingPad,
});
const handleGenerate = () => {
onAddShape(previewResult.terrainShape);
if (previewResult.padShape) {
onAddShape(previewResult.padShape);
}
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 &amp; Topoğrafya Oluşturucu
</h2>
<p className="text-xs text-slate-500 dark:text-slate-400">
Simplex-Noise + Delaunator üçgenleme ve bina oturum hafriyat hesabı
</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">
{[
{ id: "hills", label: "Dalgalı Tepe", desc: "Simplex doğal yükseltiler" },
{ id: "slope", label: "Eğimli Arsa", desc: "Tek yöne meyil" },
{ 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ı" },
].map((item) => (
<button
key={item.id}
type="button"
onClick={() => setPreset(item.id as TerrainTopographyPreset)}
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 &amp; 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"
/>
<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 &amp; 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}
</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 &amp; 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 &amp; 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>
);
};