895 lines
36 KiB
TypeScript
895 lines
36 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useRef, useState, useId } from "react";
|
|
import * as THREE from "three";
|
|
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
|
|
import {
|
|
Box,
|
|
RotateCcw,
|
|
Layers,
|
|
Ruler,
|
|
Palette,
|
|
Sparkles,
|
|
MessageCircle,
|
|
Compass,
|
|
AlertTriangle,
|
|
CheckCircle2
|
|
} from "lucide-react";
|
|
import { generateWhatsAppQuoteUrl } from "@/lib/whatsapp";
|
|
|
|
export type FenceType = "alambrado_curvo" | "alambrado_reto" | "alambrado_pvc" | "gradil_3d";
|
|
export type FenceColor = "galvanizado" | "verde" | "preto" | "cinza";
|
|
export type FenceHeight = "1.50m" | "1.80m" | "2.00m" | "2.50m" | "3.00m";
|
|
export type GroundType = "terra" | "grama" | "concreto";
|
|
export type FenceLayout = "1_lance" | "2_lances" | "4_lances" | "canto_l";
|
|
|
|
// Gerador de textura procedural perfeita para a malha losangular de Alambrado (Chain Link)
|
|
function createChainLinkTexture(colorHex: string, wireWidth: number = 3): THREE.CanvasTexture {
|
|
const canvas = document.createElement("canvas");
|
|
canvas.width = 128;
|
|
canvas.height = 128;
|
|
const ctx = canvas.getContext("2d");
|
|
|
|
if (ctx) {
|
|
ctx.clearRect(0, 0, 128, 128);
|
|
|
|
// Linha do arame com efeito metálico / degradê
|
|
ctx.strokeStyle = colorHex;
|
|
ctx.lineWidth = wireWidth;
|
|
ctx.lineCap = "round";
|
|
ctx.lineJoin = "round";
|
|
|
|
// Desenha losango central
|
|
ctx.beginPath();
|
|
ctx.moveTo(64, 0);
|
|
ctx.lineTo(128, 64);
|
|
ctx.lineTo(64, 128);
|
|
ctx.lineTo(0, 64);
|
|
ctx.closePath();
|
|
ctx.stroke();
|
|
|
|
// Linhas diagonais cruzadas nos 4 cantos para fechar o entrelaçamento contínuo
|
|
ctx.beginPath();
|
|
ctx.moveTo(0, 0); ctx.lineTo(64, 64);
|
|
ctx.moveTo(128, 0); ctx.lineTo(64, 64);
|
|
ctx.moveTo(0, 128); ctx.lineTo(64, 64);
|
|
ctx.moveTo(128, 128); ctx.lineTo(64, 64);
|
|
ctx.stroke();
|
|
}
|
|
|
|
const texture = new THREE.CanvasTexture(canvas);
|
|
texture.wrapS = THREE.RepeatWrapping;
|
|
texture.wrapT = THREE.RepeatWrapping;
|
|
texture.generateMipmaps = true;
|
|
texture.minFilter = THREE.LinearMipmapLinearFilter;
|
|
texture.magFilter = THREE.LinearFilter;
|
|
return texture;
|
|
}
|
|
|
|
export default function FenceViewer3D() {
|
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
const canvasRef = useRef<HTMLCanvasElement>(null);
|
|
|
|
// Estados
|
|
const [fenceType, setFenceType] = useState<FenceType>("alambrado_curvo");
|
|
const [color, setColor] = useState<FenceColor>("galvanizado");
|
|
const [height, setHeight] = useState<FenceHeight>("2.00m");
|
|
const [ground, setGround] = useState<GroundType>("grama");
|
|
const [layout, setLayout] = useState<FenceLayout>("2_lances");
|
|
const [hasBarbedWire, setHasBarbedWire] = useState<boolean>(true);
|
|
const [hasConcertina, setHasConcertina] = useState<boolean>(false);
|
|
const [autoRotate, setAutoRotate] = useState<boolean>(false);
|
|
const [webGLError, setWebGLError] = useState<boolean>(false);
|
|
const [isLoaded, setIsLoaded] = useState<boolean>(false);
|
|
|
|
const cepInputId = useId();
|
|
const [cep, setCep] = useState<string>("");
|
|
|
|
const numericHeight = parseFloat(height.replace("m", ""));
|
|
const isCurved = fenceType === "alambrado_curvo";
|
|
|
|
// Mapeamento de cores
|
|
const colorMap = {
|
|
galvanizado: {
|
|
hex: "#b8c0c8",
|
|
threeHex: 0xb8c0c8,
|
|
name: "Aço Galvanizado a Fogo (Zincado)",
|
|
metalness: 0.85,
|
|
roughness: 0.35,
|
|
postHex: 0x858990
|
|
},
|
|
verde: {
|
|
hex: "#225528",
|
|
threeHex: 0x225528,
|
|
name: "Revestido em PVC Verde Musgo (Quadras)",
|
|
metalness: 0.15,
|
|
roughness: 0.45,
|
|
postHex: 0x1f3621
|
|
},
|
|
preto: {
|
|
hex: "#1d1f22",
|
|
threeHex: 0x1d1f22,
|
|
name: "Revestido em PVC Preto Nobre",
|
|
metalness: 0.25,
|
|
roughness: 0.5,
|
|
postHex: 0x24272c
|
|
},
|
|
cinza: {
|
|
hex: "#5c6269",
|
|
threeHex: 0x5c6269,
|
|
name: "Revestido em PVC Cinza Urbano",
|
|
metalness: 0.3,
|
|
roughness: 0.4,
|
|
postHex: 0x484b50
|
|
},
|
|
};
|
|
|
|
// Cálculo de quantitativos
|
|
const getLayoutDetails = () => {
|
|
switch (layout) {
|
|
case "1_lance": return { meters: 2.5, posts: 2, desc: "1 Lance de Alambrado (2,50m)" };
|
|
case "2_lances": return { meters: 5.0, posts: 3, desc: "2 Lances contínuos (5,00m)" };
|
|
case "4_lances": return { meters: 10.0, posts: 5, desc: "4 Lances contínuos (10,00m)" };
|
|
case "canto_l": return { meters: 7.5, posts: 4, desc: "Canto de Esquina 90° (7,50m)" };
|
|
}
|
|
};
|
|
|
|
const currentLayout = getLayoutDetails();
|
|
const estimatedRolls = Math.max(1, Math.ceil(currentLayout.meters / 25));
|
|
const wireLines = numericHeight >= 2.0 ? 4 : 3;
|
|
const estimatedWireKg = Math.max(2, Math.ceil((currentLayout.meters * wireLines) / 35));
|
|
const estimatedTensioners = estimatedRolls * wireLines;
|
|
|
|
// Refs de Three.js
|
|
const sceneRef = useRef<THREE.Scene | null>(null);
|
|
const cameraRef = useRef<THREE.PerspectiveCamera | null>(null);
|
|
const rendererRef = useRef<THREE.WebGLRenderer | null>(null);
|
|
const controlsRef = useRef<OrbitControls | null>(null);
|
|
const fenceGroupRef = useRef<THREE.Group | null>(null);
|
|
const groundMeshRef = useRef<THREE.Mesh | null>(null);
|
|
|
|
// 1. Inicialização do Three.js (com reutilização segura do Canvas sem duplicação)
|
|
useEffect(() => {
|
|
if (!canvasRef.current || !containerRef.current) return;
|
|
|
|
const canvas = canvasRef.current;
|
|
let renderer: THREE.WebGLRenderer;
|
|
|
|
try {
|
|
renderer = new THREE.WebGLRenderer({
|
|
canvas,
|
|
antialias: true,
|
|
alpha: false,
|
|
powerPreference: "high-performance",
|
|
});
|
|
} catch (e) {
|
|
console.warn("WebGL não suportado ou falhou na inicialização:", e);
|
|
setWebGLError(true);
|
|
return;
|
|
}
|
|
|
|
const width = containerRef.current.clientWidth || 800;
|
|
const heightPx = containerRef.current.clientHeight || 560;
|
|
|
|
renderer.setSize(width, heightPx, false);
|
|
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
|
|
renderer.shadowMap.enabled = true;
|
|
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
|
renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
|
renderer.toneMappingExposure = 1.2;
|
|
rendererRef.current = renderer;
|
|
|
|
const scene = new THREE.Scene();
|
|
scene.background = new THREE.Color(0x0a0c0e);
|
|
scene.fog = new THREE.FogExp2(0x0a0c0e, 0.025);
|
|
sceneRef.current = scene;
|
|
|
|
const camera = new THREE.PerspectiveCamera(40, width / heightPx, 0.1, 100);
|
|
camera.position.set(4.8, 3.4, 6.2);
|
|
cameraRef.current = camera;
|
|
|
|
const controls = new OrbitControls(camera, canvas);
|
|
controls.enableDamping = true;
|
|
controls.dampingFactor = 0.05;
|
|
controls.maxPolarAngle = Math.PI / 2 - 0.02;
|
|
controls.minDistance = 2.0;
|
|
controls.maxDistance = 20.0;
|
|
controls.target.set(0, 1.1, 0);
|
|
controlsRef.current = controls;
|
|
|
|
// Luzes
|
|
const ambientLight = new THREE.AmbientLight(0xffffff, 1.0);
|
|
scene.add(ambientLight);
|
|
|
|
const sunLight = new THREE.DirectionalLight(0xffffff, 2.5);
|
|
sunLight.position.set(7, 14, 9);
|
|
sunLight.castShadow = true;
|
|
sunLight.shadow.mapSize.width = 1024;
|
|
sunLight.shadow.mapSize.height = 1024;
|
|
sunLight.shadow.bias = -0.0005;
|
|
scene.add(sunLight);
|
|
|
|
const fillLight = new THREE.DirectionalLight(0xa3c745, 0.4);
|
|
fillLight.position.set(-6, 4, -4);
|
|
scene.add(fillLight);
|
|
|
|
// Chão
|
|
const groundGeo = new THREE.PlaneGeometry(40, 40);
|
|
const groundMat = new THREE.MeshStandardMaterial({
|
|
color: 0x192d16,
|
|
roughness: 0.95,
|
|
metalness: 0.05,
|
|
});
|
|
const groundMesh = new THREE.Mesh(groundGeo, groundMat);
|
|
groundMesh.rotation.x = -Math.PI / 2;
|
|
groundMesh.position.y = 0;
|
|
groundMesh.receiveShadow = true;
|
|
scene.add(groundMesh);
|
|
groundMeshRef.current = groundMesh;
|
|
|
|
const gridHelper = new THREE.GridHelper(26, 26, 0x334155, 0x1e293b);
|
|
gridHelper.position.y = 0.005;
|
|
scene.add(gridHelper);
|
|
|
|
const fenceGroup = new THREE.Group();
|
|
scene.add(fenceGroup);
|
|
fenceGroupRef.current = fenceGroup;
|
|
|
|
setIsLoaded(true);
|
|
|
|
// Loop
|
|
let animId: number;
|
|
const animate = () => {
|
|
animId = requestAnimationFrame(animate);
|
|
if (controlsRef.current) {
|
|
controlsRef.current.autoRotate = autoRotate;
|
|
controlsRef.current.autoRotateSpeed = 1.2;
|
|
controlsRef.current.update();
|
|
}
|
|
renderer.render(scene, camera);
|
|
};
|
|
animate();
|
|
|
|
const handleResize = () => {
|
|
if (!containerRef.current || !renderer || !camera) return;
|
|
const w = containerRef.current.clientWidth;
|
|
const h = containerRef.current.clientHeight || 560;
|
|
camera.aspect = w / h;
|
|
camera.updateProjectionMatrix();
|
|
renderer.setSize(w, h, false);
|
|
};
|
|
window.addEventListener("resize", handleResize);
|
|
|
|
return () => {
|
|
window.removeEventListener("resize", handleResize);
|
|
cancelAnimationFrame(animId);
|
|
controls.dispose();
|
|
renderer.dispose();
|
|
};
|
|
}, []);
|
|
|
|
// 2. Chão
|
|
useEffect(() => {
|
|
if (!groundMeshRef.current) return;
|
|
const mat = groundMeshRef.current.material as THREE.MeshStandardMaterial;
|
|
if (ground === "grama") {
|
|
mat.color.setHex(0x192d16);
|
|
mat.roughness = 0.95;
|
|
} else if (ground === "concreto") {
|
|
mat.color.setHex(0x383b42);
|
|
mat.roughness = 0.7;
|
|
} else {
|
|
mat.color.setHex(0x38291a);
|
|
mat.roughness = 0.98;
|
|
}
|
|
}, [ground]);
|
|
|
|
// 3. Renderização da Cerca em 3D
|
|
useEffect(() => {
|
|
if (!fenceGroupRef.current || !sceneRef.current) return;
|
|
const group = fenceGroupRef.current;
|
|
|
|
while (group.children.length > 0) {
|
|
const obj = group.children[0];
|
|
group.remove(obj);
|
|
if ((obj as THREE.Mesh).geometry) (obj as THREE.Mesh).geometry.dispose();
|
|
}
|
|
|
|
const colConfig = colorMap[color];
|
|
const wireColorHex = fenceType === "alambrado_pvc" ? "#225528" : colConfig.hex;
|
|
|
|
// Material de mourão
|
|
const postMat = new THREE.MeshStandardMaterial({
|
|
color: fenceType === "alambrado_curvo" ? 0x82868e : colConfig.postHex,
|
|
roughness: 0.9,
|
|
metalness: 0.1,
|
|
});
|
|
|
|
const steelGuideMat = new THREE.MeshStandardMaterial({
|
|
color: 0x9ca3af,
|
|
metalness: 0.8,
|
|
roughness: 0.3,
|
|
});
|
|
|
|
const spanLength = 2.5; // 2,50m entre mourões
|
|
const h = numericHeight;
|
|
|
|
interface PostPos { x: number; z: number; isCorner?: boolean }
|
|
interface SpanPos { startX: number; startZ: number; endX: number; endZ: number }
|
|
|
|
const posts: PostPos[] = [];
|
|
const spans: SpanPos[] = [];
|
|
|
|
if (layout === "1_lance") {
|
|
posts.push({ x: -spanLength / 2, z: 0 });
|
|
posts.push({ x: spanLength / 2, z: 0 });
|
|
spans.push({ startX: -spanLength / 2, startZ: 0, endX: spanLength / 2, endZ: 0 });
|
|
} else if (layout === "2_lances") {
|
|
posts.push({ x: -spanLength, z: 0 });
|
|
posts.push({ x: 0, z: 0 });
|
|
posts.push({ x: spanLength, z: 0 });
|
|
spans.push({ startX: -spanLength, startZ: 0, endX: 0, endZ: 0 });
|
|
spans.push({ startX: 0, startZ: 0, endX: spanLength, endZ: 0 });
|
|
} else if (layout === "4_lances") {
|
|
posts.push({ x: -spanLength * 2, z: 0 });
|
|
posts.push({ x: -spanLength, z: 0 });
|
|
posts.push({ x: 0, z: 0 });
|
|
posts.push({ x: spanLength, z: 0 });
|
|
posts.push({ x: spanLength * 2, z: 0 });
|
|
spans.push({ startX: -spanLength * 2, startZ: 0, endX: -spanLength, endZ: 0 });
|
|
spans.push({ startX: -spanLength, startZ: 0, endX: 0, endZ: 0 });
|
|
spans.push({ startX: 0, startZ: 0, endX: spanLength, endZ: 0 });
|
|
spans.push({ startX: spanLength, startZ: 0, endX: spanLength * 2, endZ: 0 });
|
|
} else if (layout === "canto_l") {
|
|
posts.push({ x: -spanLength, z: 0 });
|
|
posts.push({ x: 0, z: 0, isCorner: true });
|
|
posts.push({ x: spanLength, z: 0 });
|
|
posts.push({ x: spanLength, z: spanLength });
|
|
spans.push({ startX: -spanLength, startZ: 0, endX: 0, endZ: 0 });
|
|
spans.push({ startX: 0, startZ: 0, endX: spanLength, endZ: 0 });
|
|
spans.push({ startX: spanLength, startZ: 0, endX: spanLength, endZ: spanLength });
|
|
}
|
|
|
|
// --- MOURÕES ---
|
|
posts.forEach((p, idx) => {
|
|
const postHeight = h + (isCurved ? 0.45 : 0.05);
|
|
|
|
const postGeo = new THREE.BoxGeometry(0.10, postHeight, 0.10);
|
|
const postMesh = new THREE.Mesh(postGeo, postMat);
|
|
postMesh.position.set(p.x, postHeight / 2, p.z);
|
|
postMesh.castShadow = true;
|
|
postMesh.receiveShadow = true;
|
|
group.add(postMesh);
|
|
|
|
// Base sapata
|
|
const baseGeo = new THREE.CylinderGeometry(0.14, 0.16, 0.08, 12);
|
|
const baseMesh = new THREE.Mesh(baseGeo, postMat);
|
|
baseMesh.position.set(p.x, 0.04, p.z);
|
|
baseMesh.receiveShadow = true;
|
|
group.add(baseMesh);
|
|
|
|
// Mourão Curvo (Braço 45°)
|
|
if (isCurved) {
|
|
const armLength = 0.50;
|
|
const armGeo = new THREE.BoxGeometry(0.08, armLength, 0.08);
|
|
const armMesh = new THREE.Mesh(armGeo, postMat);
|
|
armMesh.rotation.z = -Math.PI / 4;
|
|
armMesh.position.set(p.x + (armLength * Math.sin(Math.PI / 4)) / 2, postHeight + 0.12, p.z);
|
|
armMesh.castShadow = true;
|
|
group.add(armMesh);
|
|
}
|
|
|
|
// Escoras nos cantos
|
|
if (idx === 0 || idx === posts.length - 1 || p.isCorner) {
|
|
const braceLength = h * 0.95;
|
|
const braceGeo = new THREE.BoxGeometry(0.08, braceLength, 0.08);
|
|
const braceMesh = new THREE.Mesh(braceGeo, postMat);
|
|
braceMesh.rotation.z = idx === 0 ? -Math.PI / 4.5 : Math.PI / 4.5;
|
|
braceMesh.position.set(idx === 0 ? p.x + 0.55 : p.x - 0.55, h * 0.4, p.z);
|
|
braceMesh.castShadow = true;
|
|
group.add(braceMesh);
|
|
}
|
|
});
|
|
|
|
// --- PAINÉIS DE TELA DE ALAMBRADO ---
|
|
// Textura procedural ultra-leve e realista (zero crash de contexto WebGL)
|
|
const meshTexture = createChainLinkTexture(wireColorHex, 3);
|
|
const totalLines = h >= 2.0 ? 4 : 3;
|
|
|
|
spans.forEach((span) => {
|
|
const dx = span.endX - span.startX;
|
|
const dz = span.endZ - span.startZ;
|
|
const len = Math.sqrt(dx * dx + dz * dz);
|
|
const angle = Math.atan2(dz, dx);
|
|
const cx = (span.startX + span.endX) / 2;
|
|
const cz = (span.startZ + span.endZ) / 2;
|
|
|
|
// Fiadas horizontais de arame guia
|
|
for (let l = 1; l <= totalLines; l++) {
|
|
const wireY = (h / (totalLines + 0.5)) * l;
|
|
const guideGeo = new THREE.CylinderGeometry(0.003, 0.003, len, 6);
|
|
const guideMesh = new THREE.Mesh(guideGeo, steelGuideMat);
|
|
guideMesh.rotation.z = Math.PI / 2;
|
|
guideMesh.rotation.y = -angle;
|
|
guideMesh.position.set(cx, wireY, cz);
|
|
group.add(guideMesh);
|
|
}
|
|
|
|
// Fios farpados no mourão curvo
|
|
if (isCurved && hasBarbedWire) {
|
|
for (let b = 1; b <= 3; b++) {
|
|
const barbedGeo = new THREE.CylinderGeometry(0.0025, 0.0025, len, 6);
|
|
const barbedMesh = new THREE.Mesh(barbedGeo, steelGuideMat);
|
|
barbedMesh.rotation.z = Math.PI / 2;
|
|
barbedMesh.rotation.y = -angle;
|
|
barbedMesh.position.set(cx + b * 0.09, h + 0.15 + b * 0.10, cz);
|
|
group.add(barbedMesh);
|
|
}
|
|
}
|
|
|
|
// Concertina opcional
|
|
if (hasConcertina) {
|
|
const concertinaRadius = 0.18;
|
|
const coils = Math.floor(len * 5.5);
|
|
const step = len / coils;
|
|
|
|
for (let k = 0; k < coils; k++) {
|
|
const torusGeo = new THREE.TorusGeometry(concertinaRadius, 0.0028, 6, 18);
|
|
const torusMesh = new THREE.Mesh(torusGeo, steelGuideMat);
|
|
torusMesh.rotation.y = -angle + Math.PI / 2;
|
|
const px = span.startX + Math.cos(angle) * (k * step + step / 2);
|
|
const pz = span.startZ + Math.sin(angle) * (k * step + step / 2);
|
|
torusMesh.position.set(px, h + concertinaRadius + 0.02, pz);
|
|
torusMesh.castShadow = true;
|
|
group.add(torusMesh);
|
|
}
|
|
}
|
|
|
|
// Plano da Tela de Alambrado com textura de malha losangular
|
|
const spanTexture = meshTexture.clone();
|
|
spanTexture.needsUpdate = true;
|
|
const diamondScale = 0.055; // 50mm por losango
|
|
spanTexture.repeat.set(len / diamondScale, h / diamondScale);
|
|
|
|
const planeGeo = new THREE.PlaneGeometry(len, h);
|
|
const planeMat = new THREE.MeshStandardMaterial({
|
|
map: spanTexture,
|
|
transparent: true,
|
|
alphaTest: 0.15,
|
|
side: THREE.DoubleSide,
|
|
metalness: fenceType === "alambrado_pvc" ? 0.15 : 0.8,
|
|
roughness: fenceType === "alambrado_pvc" ? 0.5 : 0.35,
|
|
});
|
|
|
|
const planeMesh = new THREE.Mesh(planeGeo, planeMat);
|
|
planeMesh.position.set(cx, h / 2, cz);
|
|
planeMesh.rotation.y = -angle;
|
|
planeMesh.castShadow = true;
|
|
group.add(planeMesh);
|
|
});
|
|
|
|
}, [fenceType, color, height, layout, hasBarbedWire, hasConcertina]);
|
|
|
|
const setCameraView = (type: "geral" | "detalhe" | "topo") => {
|
|
if (!cameraRef.current || !controlsRef.current) return;
|
|
const cam = cameraRef.current;
|
|
const ctrl = controlsRef.current;
|
|
|
|
switch (type) {
|
|
case "geral":
|
|
cam.position.set(4.8, 3.4, 6.2);
|
|
ctrl.target.set(0, 1.1, 0);
|
|
break;
|
|
case "detalhe":
|
|
cam.position.set(0.8, 1.4, 1.5);
|
|
ctrl.target.set(0, 1.2, 0);
|
|
break;
|
|
case "topo":
|
|
cam.position.set(0.1, 8.0, 0.1);
|
|
ctrl.target.set(0, 0, 0);
|
|
break;
|
|
}
|
|
ctrl.update();
|
|
};
|
|
|
|
const whatsappUrl = generateWhatsAppQuoteUrl({
|
|
productType: fenceType,
|
|
productName: fenceType === "alambrado_curvo"
|
|
? "Tela de Alambrado com Mourão de Concreto Curvo (+ Arame Farpado)"
|
|
: fenceType === "alambrado_pvc"
|
|
? "Tela de Alambrado Revestida em PVC Verde (Quadras)"
|
|
: fenceType === "alambrado_reto"
|
|
? "Tela de Alambrado Galvanizada com Mourão Reto"
|
|
: "Gradil 3D Eletrosoldado",
|
|
linearMeters: currentLayout.meters,
|
|
height,
|
|
finish: colorMap[color].name,
|
|
postType: fenceType === "alambrado_curvo" ? "Mourão de Concreto com Ponta Curva" : "Mourão de Concreto / Aço Reto",
|
|
meshSize: "2 Polegadas (50mm)",
|
|
wireGauge: "BWG 12 (2,77mm) ou BWG 10",
|
|
cepOrCity: cep || "A Definir",
|
|
estimatedRolls,
|
|
estimatedPosts: currentLayout.posts,
|
|
estimatedWireKg,
|
|
estimatedTensioners,
|
|
notes: `Simulação no site: ${hasBarbedWire ? "Com 3 fios de arame farpado" : "Sem arame farpado"}${hasConcertina ? " + Concertina" : ""}.`,
|
|
});
|
|
|
|
return (
|
|
<div className="w-full bg-[#0d0e12] border border-zinc-800 rounded-2xl overflow-hidden shadow-2xl">
|
|
|
|
{/* Barra de Título Superior */}
|
|
<div className="bg-[#121419] px-4 py-3 sm:px-6 border-b border-zinc-800 flex flex-wrap items-center justify-between gap-4">
|
|
<div className="flex items-center gap-3">
|
|
<div className="w-9 h-9 rounded-lg bg-[#a3c745]/15 text-[#a3c745] flex items-center justify-center border border-[#a3c745]/30">
|
|
<Box className="w-5 h-5" />
|
|
</div>
|
|
<div>
|
|
<div className="flex items-center gap-2">
|
|
<span className="text-white font-heading font-bold text-sm sm:text-base">
|
|
Studio 3D: Simulador de Telas de Alambrado & Mourões
|
|
</span>
|
|
<span className="px-2 py-0.5 rounded text-[10px] font-bold bg-[#a3c745] text-black">
|
|
Foco em Alambrado
|
|
</span>
|
|
</div>
|
|
<p className="text-xs text-zinc-400">
|
|
Gire em 360°, teste mourões retos ou curvos com arame farpado e receba a lista de rolos.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Câmera Rápida */}
|
|
<div className="flex items-center gap-2 text-xs">
|
|
<button
|
|
type="button"
|
|
onClick={() => setCameraView("geral")}
|
|
className="px-2.5 py-1.5 rounded-lg bg-zinc-900 border border-zinc-800 text-zinc-300 hover:text-white hover:bg-zinc-800 transition-colors"
|
|
>
|
|
Visão Geral
|
|
</button>
|
|
<button
|
|
type="button"
|
|
onClick={() => setCameraView("detalhe")}
|
|
className="px-2.5 py-1.5 rounded-lg bg-zinc-900 border border-zinc-800 text-zinc-300 hover:text-white hover:bg-zinc-800 transition-colors hidden sm:inline-block"
|
|
>
|
|
Detalhe da Malha
|
|
</button>
|
|
<button
|
|
type="button"
|
|
onClick={() => setAutoRotate(!autoRotate)}
|
|
className={`p-1.5 rounded-lg border transition-colors ${
|
|
autoRotate ? "bg-[#a3c745] text-black border-[#a3c745]" : "bg-zinc-900 text-zinc-400 border-zinc-800 hover:text-white"
|
|
}`}
|
|
title="Giro Automático 360°"
|
|
>
|
|
<RotateCcw className="w-4 h-4" />
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Grid: Canvas 3D (8 cols) + Controles (4 cols) */}
|
|
<div className="grid grid-cols-1 lg:grid-cols-12 min-h-[580px]">
|
|
|
|
{/* Canvas 3D Viewport com fallback visual garantido */}
|
|
<div
|
|
ref={containerRef}
|
|
className="lg:col-span-8 relative bg-[#0a0c0e] overflow-hidden flex flex-col justify-between min-h-[380px] sm:min-h-[480px] lg:min-h-[580px]"
|
|
>
|
|
{/* O CANVAS É DECLARATIVO E EXCLUSIVO (Zero duplicações ou broken image) */}
|
|
<canvas
|
|
ref={canvasRef}
|
|
className="w-full h-full absolute inset-0 cursor-grab active:cursor-grabbing block bg-[#0a0c0e]"
|
|
/>
|
|
|
|
{/* Fallback caso WebGL seja bloqueado na GPU do usuário */}
|
|
{webGLError && (
|
|
<div className="absolute inset-0 bg-[#0c0e12] flex flex-col items-center justify-center p-6 text-center z-20 space-y-4">
|
|
<div className="w-12 h-12 rounded-xl bg-amber-500/10 text-amber-400 flex items-center justify-center border border-amber-500/30">
|
|
<AlertTriangle className="w-6 h-6" />
|
|
</div>
|
|
<div>
|
|
<h4 className="text-base font-heading font-bold text-white">Visualizador em Modo Interativo 2D</h4>
|
|
<p className="text-xs text-zinc-400 max-w-md mt-1">
|
|
Seu navegador opera com aceleração gráfica limitada, mas todos os parâmetros e o cálculo de rolos e mourões continuam 100% funcionais abaixo!
|
|
</p>
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{/* Dica de Interação */}
|
|
<div className="relative z-10 m-4 pointer-events-none flex items-center gap-2 px-3 py-1.5 rounded-lg bg-black/75 backdrop-blur-md border border-zinc-800/80 text-[11px] text-zinc-300 w-fit">
|
|
<Compass className="w-3.5 h-3.5 text-[#a3c745]" />
|
|
<span>Gire 360° • Aproxime para ver a malha losangular e mourões de concreto</span>
|
|
</div>
|
|
|
|
{/* Badge Inferior */}
|
|
<div className="relative z-10 m-4 pointer-events-none flex flex-wrap items-center justify-between gap-2">
|
|
<div className="bg-black/85 backdrop-blur-md px-3.5 py-2 rounded-xl border border-zinc-800 text-xs text-zinc-200">
|
|
<span className="text-[#a3c745] font-bold block">{currentLayout.desc}</span>
|
|
<span className="text-[11px] text-zinc-400">
|
|
Altura: {height} • Mourão: {isCurved ? "Ponta Curva com Arame Farpado" : "Reto"}
|
|
</span>
|
|
</div>
|
|
|
|
{/* Alternador de Solo */}
|
|
<div className="pointer-events-auto flex items-center gap-1 bg-black/85 backdrop-blur-md p-1 rounded-xl border border-zinc-800 text-[11px]">
|
|
<span className="text-zinc-500 px-2">Solo:</span>
|
|
<button
|
|
type="button"
|
|
onClick={() => setGround("terra")}
|
|
className={`px-2.5 py-1 rounded-lg transition-all ${
|
|
ground === "terra" ? "bg-[#a3c745] text-black font-bold" : "text-zinc-400 hover:text-white"
|
|
}`}
|
|
>
|
|
Terra
|
|
</button>
|
|
<button
|
|
type="button"
|
|
onClick={() => setGround("grama")}
|
|
className={`px-2.5 py-1 rounded-lg transition-all ${
|
|
ground === "grama" ? "bg-[#a3c745] text-black font-bold" : "text-zinc-400 hover:text-white"
|
|
}`}
|
|
>
|
|
Grama
|
|
</button>
|
|
<button
|
|
type="button"
|
|
onClick={() => setGround("concreto")}
|
|
className={`px-2.5 py-1 rounded-lg transition-all ${
|
|
ground === "concreto" ? "bg-[#a3c745] text-black font-bold" : "text-zinc-400 hover:text-white"
|
|
}`}
|
|
>
|
|
Concreto
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Controles Específicos para Alambrado */}
|
|
<div className="lg:col-span-4 bg-[#111317] border-t lg:border-t-0 lg:border-l border-zinc-800 p-5 sm:p-6 space-y-5 flex flex-col justify-between overflow-y-auto max-h-[580px]">
|
|
|
|
<div className="space-y-5">
|
|
|
|
{/* 1. Tipo de Alambrado & Mourão */}
|
|
<div>
|
|
<label className="text-xs font-bold uppercase tracking-wider text-[#a3c745] block mb-2 flex items-center gap-1.5">
|
|
<Layers className="w-3.5 h-3.5" /> 1. Tipo de Alambrado & Mourão
|
|
</label>
|
|
<div className="grid grid-cols-2 gap-2">
|
|
<button
|
|
type="button"
|
|
onClick={() => { setFenceType("alambrado_curvo"); setHasBarbedWire(true); }}
|
|
className={`p-2.5 rounded-xl border text-left transition-all ${
|
|
fenceType === "alambrado_curvo"
|
|
? "bg-[#181b22] border-[#a3c745] text-white ring-1 ring-[#a3c745]"
|
|
: "bg-zinc-900/60 border-zinc-800 text-zinc-400 hover:bg-zinc-800 hover:text-white"
|
|
}`}
|
|
>
|
|
<span className="block font-heading font-bold text-xs text-white">Mourão Curvo</span>
|
|
<span className="text-[10px] text-zinc-400 block mt-0.5">+ 3 fios farpados</span>
|
|
</button>
|
|
|
|
<button
|
|
type="button"
|
|
onClick={() => setFenceType("alambrado_reto")}
|
|
className={`p-2.5 rounded-xl border text-left transition-all ${
|
|
fenceType === "alambrado_reto"
|
|
? "bg-[#181b22] border-[#a3c745] text-white ring-1 ring-[#a3c745]"
|
|
: "bg-zinc-900/60 border-zinc-800 text-zinc-400 hover:bg-zinc-800 hover:text-white"
|
|
}`}
|
|
>
|
|
<span className="block font-heading font-bold text-xs text-white">Mourão Reto</span>
|
|
<span className="text-[10px] text-zinc-400 block mt-0.5">Padrão Chácaras</span>
|
|
</button>
|
|
|
|
<button
|
|
type="button"
|
|
onClick={() => setFenceType("alambrado_pvc")}
|
|
className={`p-2.5 rounded-xl border text-left transition-all ${
|
|
fenceType === "alambrado_pvc"
|
|
? "bg-[#181b22] border-[#a3c745] text-white ring-1 ring-[#a3c745]"
|
|
: "bg-zinc-900/60 border-zinc-800 text-zinc-400 hover:bg-zinc-800 hover:text-white"
|
|
}`}
|
|
>
|
|
<span className="block font-heading font-bold text-xs text-white">PVC Verde</span>
|
|
<span className="text-[10px] text-zinc-400 block mt-0.5">Especial Quadras</span>
|
|
</button>
|
|
|
|
<button
|
|
type="button"
|
|
onClick={() => setFenceType("gradil_3d")}
|
|
className={`p-2.5 rounded-xl border text-left transition-all ${
|
|
fenceType === "gradil_3d"
|
|
? "bg-[#181b22] border-[#a3c745] text-white ring-1 ring-[#a3c745]"
|
|
: "bg-zinc-900/60 border-zinc-800 text-zinc-400 hover:bg-zinc-800 hover:text-white"
|
|
}`}
|
|
>
|
|
<span className="block font-heading font-bold text-xs text-white">Gradil 3D</span>
|
|
<span className="text-[10px] text-zinc-400 block mt-0.5">Complementar</span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
{/* 2. Altura do Alambrado */}
|
|
<div>
|
|
<label className="text-xs font-bold uppercase tracking-wider text-[#a3c745] block mb-2 flex items-center gap-1.5">
|
|
<Ruler className="w-3.5 h-3.5" /> 2. Altura da Tela
|
|
</label>
|
|
<div className="grid grid-cols-5 gap-1.5">
|
|
{(["1.50m", "1.80m", "2.00m", "2.50m", "3.00m"] as FenceHeight[]).map((h) => (
|
|
<button
|
|
key={h}
|
|
type="button"
|
|
onClick={() => setHeight(h)}
|
|
className={`py-2 rounded-lg border text-center text-xs font-heading font-bold transition-all ${
|
|
height === h
|
|
? "bg-[#181b22] border-[#a3c745] text-[#a3c745] ring-1 ring-[#a3c745]"
|
|
: "bg-zinc-900/60 border-zinc-800 text-zinc-400 hover:text-white"
|
|
}`}
|
|
>
|
|
{h}
|
|
</button>
|
|
))}
|
|
</div>
|
|
</div>
|
|
|
|
{/* 3. Acabamento do Arame */}
|
|
<div>
|
|
<label className="text-xs font-bold uppercase tracking-wider text-[#a3c745] block mb-2 flex items-center gap-1.5">
|
|
<Palette className="w-3.5 h-3.5" /> 3. Acabamento do Arame
|
|
</label>
|
|
<div className="grid grid-cols-2 gap-2">
|
|
{[
|
|
{ id: "galvanizado", label: "Galvanizado a Fogo", hex: "bg-zinc-300" },
|
|
{ id: "verde", label: "Revestido em PVC Verde", hex: "bg-emerald-800" },
|
|
{ id: "preto", label: "Revestido em PVC Preto", hex: "bg-zinc-950 border border-zinc-700" },
|
|
{ id: "cinza", label: "Revestido em PVC Cinza", hex: "bg-zinc-600" },
|
|
].map((c) => (
|
|
<button
|
|
key={c.id}
|
|
type="button"
|
|
onClick={() => setColor(c.id as FenceColor)}
|
|
className={`flex items-center gap-2 p-2 rounded-xl border text-left transition-all ${
|
|
color === c.id
|
|
? "bg-[#181b22] border-[#a3c745] text-white ring-1 ring-[#a3c745]"
|
|
: "bg-zinc-900/60 border-zinc-800 text-zinc-400 hover:text-white"
|
|
}`}
|
|
>
|
|
<span className={`w-3.5 h-3.5 rounded-full shrink-0 ${c.hex}`} />
|
|
<span className="text-[11px] font-medium truncate">{c.label}</span>
|
|
</button>
|
|
))}
|
|
</div>
|
|
</div>
|
|
|
|
{/* 4. Módulos na Prévia 3D */}
|
|
<div>
|
|
<label className="text-xs font-bold uppercase tracking-wider text-zinc-400 block mb-2">
|
|
4. Extensão na Simulação:
|
|
</label>
|
|
<div className="grid grid-cols-2 gap-2 text-xs">
|
|
<button
|
|
type="button"
|
|
onClick={() => setLayout("1_lance")}
|
|
className={`p-2 rounded-lg border text-left ${
|
|
layout === "1_lance" ? "bg-[#181b22] border-[#a3c745] text-white" : "bg-zinc-900/60 border-zinc-800 text-zinc-400"
|
|
}`}
|
|
>
|
|
<span className="block font-bold">1 Lance (2,5m)</span>
|
|
</button>
|
|
<button
|
|
type="button"
|
|
onClick={() => setLayout("2_lances")}
|
|
className={`p-2 rounded-lg border text-left ${
|
|
layout === "2_lances" ? "bg-[#181b22] border-[#a3c745] text-white" : "bg-zinc-900/60 border-zinc-800 text-zinc-400"
|
|
}`}
|
|
>
|
|
<span className="block font-bold">2 Lances (5,0m)</span>
|
|
</button>
|
|
<button
|
|
type="button"
|
|
onClick={() => setLayout("4_lances")}
|
|
className={`p-2 rounded-lg border text-left ${
|
|
layout === "4_lances" ? "bg-[#181b22] border-[#a3c745] text-white" : "bg-zinc-900/60 border-zinc-800 text-zinc-400"
|
|
}`}
|
|
>
|
|
<span className="block font-bold">4 Lances (10m)</span>
|
|
</button>
|
|
<button
|
|
type="button"
|
|
onClick={() => setLayout("canto_l")}
|
|
className={`p-2 rounded-lg border text-left ${
|
|
layout === "canto_l" ? "bg-[#181b22] border-[#a3c745] text-white" : "bg-zinc-900/60 border-zinc-800 text-zinc-400"
|
|
}`}
|
|
>
|
|
<span className="block font-bold">Canto 90° (7,5m)</span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Opcionais de Segurança */}
|
|
<div className="pt-2 border-t border-zinc-800 space-y-2">
|
|
{isCurved && (
|
|
<label className="flex items-center gap-2.5 cursor-pointer">
|
|
<input
|
|
type="checkbox"
|
|
checked={hasBarbedWire}
|
|
onChange={(e) => setHasBarbedWire(e.target.checked)}
|
|
className="w-4 h-4 rounded accent-[#a3c745] bg-zinc-900 border-zinc-700"
|
|
/>
|
|
<span className="text-xs text-zinc-300">
|
|
Incluir 3 fiadas de arame farpado no topo
|
|
</span>
|
|
</label>
|
|
)}
|
|
|
|
<label className="flex items-center gap-2.5 cursor-pointer">
|
|
<input
|
|
type="checkbox"
|
|
checked={hasConcertina}
|
|
onChange={(e) => setHasConcertina(e.target.checked)}
|
|
className="w-4 h-4 rounded accent-[#a3c745] bg-zinc-900 border-zinc-700"
|
|
/>
|
|
<span className="text-xs text-zinc-300">
|
|
Adicionar Concertina Perimetral
|
|
</span>
|
|
</label>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{/* Resumo de Peças para Alambrado */}
|
|
<div className="pt-4 border-t border-zinc-800 space-y-3">
|
|
<div className="bg-zinc-900/90 p-3 rounded-xl border border-zinc-800 space-y-1 text-xs">
|
|
<div className="flex justify-between text-zinc-400">
|
|
<span>Extensão visualizada:</span>
|
|
<strong className="text-white">{currentLayout.meters}m lineares</strong>
|
|
</div>
|
|
<div className="flex justify-between text-zinc-400">
|
|
<span>Mourões de Concreto/Aço:</span>
|
|
<strong className="text-[#a3c745]">{currentLayout.posts} unidades</strong>
|
|
</div>
|
|
<div className="flex justify-between text-zinc-400">
|
|
<span>Arame Guia / Tensionador:</span>
|
|
<strong className="text-white">~{estimatedWireKg} kg</strong>
|
|
</div>
|
|
<div className="flex justify-between text-zinc-400">
|
|
<span>Catracas Esticadoras:</span>
|
|
<strong className="text-white">{estimatedTensioners} un</strong>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<label htmlFor={cepInputId} className="text-[11px] text-zinc-400 block mb-1">
|
|
CEP para cálculo do frete:
|
|
</label>
|
|
<input
|
|
id={cepInputId}
|
|
type="text"
|
|
placeholder="Ex: 18000-000 ou sua cidade"
|
|
value={cep}
|
|
onChange={(e) => setCep(e.target.value)}
|
|
className="w-full bg-zinc-900 border border-zinc-700/80 rounded-lg px-3 py-1.5 text-xs text-white placeholder-zinc-500 focus:outline-none focus:border-[#a3c745]"
|
|
/>
|
|
</div>
|
|
|
|
<a
|
|
href={whatsappUrl}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
className="w-full flex items-center justify-center gap-2 bg-[#a3c745] hover:bg-[#b5db50] text-black font-heading font-bold text-xs sm:text-sm py-3.5 px-4 rounded-xl shadow-lg shadow-[#a3c745]/20 transition-all text-center pulse-glow"
|
|
>
|
|
<MessageCircle className="w-4 h-4 fill-black shrink-0" />
|
|
<span>Solicitar Orçamento de Alambrado no WhatsApp</span>
|
|
</a>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
);
|
|
}
|