feat(FenceViewer3D): render solid visible diamond chain-link wire lattice and 3D rolled fence bundle
This commit is contained in:
1 parent
3927630317
commit
ad34497813
4 files changed
+216
-117
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
+216
-117
@@ -13,7 +13,7 @@ import {
|
|||||||
MessageCircle,
|
MessageCircle,
|
||||||
Compass,
|
Compass,
|
||||||
AlertTriangle,
|
AlertTriangle,
|
||||||
CheckCircle2
|
Package
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { generateWhatsAppQuoteUrl } from "@/lib/whatsapp";
|
import { generateWhatsAppQuoteUrl } from "@/lib/whatsapp";
|
||||||
|
|
||||||
@@ -23,47 +23,56 @@ export type FenceHeight = "1.50m" | "1.80m" | "2.00m" | "2.50m" | "3.00m";
|
|||||||
export type GroundType = "terra" | "grama" | "concreto";
|
export type GroundType = "terra" | "grama" | "concreto";
|
||||||
export type FenceLayout = "1_lance" | "2_lances" | "4_lances" | "canto_l";
|
export type FenceLayout = "1_lance" | "2_lances" | "4_lances" | "canto_l";
|
||||||
|
|
||||||
// Gerador de textura procedural perfeita para a malha losangular de Alambrado (Chain Link)
|
// Construtor procedural de geometria de arames losangulares entrelaçados (Chain Link 45°)
|
||||||
function createChainLinkTexture(colorHex: string, wireWidth: number = 3): THREE.CanvasTexture {
|
function buildChainLinkGeometry(spanLength: number, height: number, spacing: number = 0.08): THREE.BufferGeometry {
|
||||||
const canvas = document.createElement("canvas");
|
const positions: number[] = [];
|
||||||
canvas.width = 128;
|
const s = spacing;
|
||||||
canvas.height = 128;
|
const L = spanLength;
|
||||||
const ctx = canvas.getContext("2d");
|
const H = height;
|
||||||
|
|
||||||
if (ctx) {
|
// Família 1: Linhas diagonais a +45° (y - x = c)
|
||||||
ctx.clearRect(0, 0, 128, 128);
|
for (let c = -L; c <= H + s; c += s) {
|
||||||
|
const pts: [number, number][] = [];
|
||||||
|
if (c >= 0 && c <= H) pts.push([0, c]);
|
||||||
|
if (L + c >= 0 && L + c <= H) pts.push([L, L + c]);
|
||||||
|
if (-c >= 0 && -c <= L) pts.push([-c, 0]);
|
||||||
|
if (H - c >= 0 && H - c <= L) pts.push([H - c, H]);
|
||||||
|
|
||||||
// Linha do arame com efeito metálico / degradê
|
const unique: [number, number][] = [];
|
||||||
ctx.strokeStyle = colorHex;
|
for (const p of pts) {
|
||||||
ctx.lineWidth = wireWidth;
|
if (!unique.some(u => Math.abs(u[0] - p[0]) < 1e-4 && Math.abs(u[1] - p[1]) < 1e-4)) {
|
||||||
ctx.lineCap = "round";
|
unique.push(p);
|
||||||
ctx.lineJoin = "round";
|
}
|
||||||
|
}
|
||||||
// Desenha losango central
|
if (unique.length === 2) {
|
||||||
ctx.beginPath();
|
positions.push(unique[0][0] - L / 2, unique[0][1], 0.002);
|
||||||
ctx.moveTo(64, 0);
|
positions.push(unique[1][0] - L / 2, unique[1][1], 0.002);
|
||||||
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);
|
// Família 2: Linhas diagonais a -45° (y + x = c)
|
||||||
texture.wrapS = THREE.RepeatWrapping;
|
for (let c = 0; c <= L + H + s; c += s) {
|
||||||
texture.wrapT = THREE.RepeatWrapping;
|
const pts: [number, number][] = [];
|
||||||
texture.generateMipmaps = true;
|
if (c >= 0 && c <= H) pts.push([0, c]);
|
||||||
texture.minFilter = THREE.LinearMipmapLinearFilter;
|
if (c - L >= 0 && c - L <= H) pts.push([L, c - L]);
|
||||||
texture.magFilter = THREE.LinearFilter;
|
if (c >= 0 && c <= L) pts.push([c, 0]);
|
||||||
return texture;
|
if (c - H >= 0 && c - H <= L) pts.push([c - H, H]);
|
||||||
|
|
||||||
|
const unique: [number, number][] = [];
|
||||||
|
for (const p of pts) {
|
||||||
|
if (!unique.some(u => Math.abs(u[0] - p[0]) < 1e-4 && Math.abs(u[1] - p[1]) < 1e-4)) {
|
||||||
|
unique.push(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (unique.length === 2) {
|
||||||
|
positions.push(unique[0][0] - L / 2, unique[0][1], -0.002);
|
||||||
|
positions.push(unique[1][0] - L / 2, unique[1][1], -0.002);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const geometry = new THREE.BufferGeometry();
|
||||||
|
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
|
||||||
|
return geometry;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function FenceViewer3D() {
|
export default function FenceViewer3D() {
|
||||||
@@ -73,14 +82,14 @@ export default function FenceViewer3D() {
|
|||||||
// Estados
|
// Estados
|
||||||
const [fenceType, setFenceType] = useState<FenceType>("alambrado_curvo");
|
const [fenceType, setFenceType] = useState<FenceType>("alambrado_curvo");
|
||||||
const [color, setColor] = useState<FenceColor>("galvanizado");
|
const [color, setColor] = useState<FenceColor>("galvanizado");
|
||||||
const [height, setHeight] = useState<FenceHeight>("2.00m");
|
const [height, setHeight] = useState<FenceHeight>("1.80m");
|
||||||
const [ground, setGround] = useState<GroundType>("grama");
|
const [ground, setGround] = useState<GroundType>("grama");
|
||||||
const [layout, setLayout] = useState<FenceLayout>("2_lances");
|
const [layout, setLayout] = useState<FenceLayout>("2_lances");
|
||||||
const [hasBarbedWire, setHasBarbedWire] = useState<boolean>(true);
|
const [hasBarbedWire, setHasBarbedWire] = useState<boolean>(true);
|
||||||
const [hasConcertina, setHasConcertina] = useState<boolean>(false);
|
const [hasConcertina, setHasConcertina] = useState<boolean>(false);
|
||||||
|
const [showRoll, setShowRoll] = useState<boolean>(true);
|
||||||
const [autoRotate, setAutoRotate] = useState<boolean>(false);
|
const [autoRotate, setAutoRotate] = useState<boolean>(false);
|
||||||
const [webGLError, setWebGLError] = useState<boolean>(false);
|
const [webGLError, setWebGLError] = useState<boolean>(false);
|
||||||
const [isLoaded, setIsLoaded] = useState<boolean>(false);
|
|
||||||
|
|
||||||
const cepInputId = useId();
|
const cepInputId = useId();
|
||||||
const [cep, setCep] = useState<string>("");
|
const [cep, setCep] = useState<string>("");
|
||||||
@@ -91,36 +100,32 @@ export default function FenceViewer3D() {
|
|||||||
// Mapeamento de cores
|
// Mapeamento de cores
|
||||||
const colorMap = {
|
const colorMap = {
|
||||||
galvanizado: {
|
galvanizado: {
|
||||||
hex: "#b8c0c8",
|
hex: "#cbd5e1",
|
||||||
threeHex: 0xb8c0c8,
|
threeHex: 0xd1d5db,
|
||||||
name: "Aço Galvanizado a Fogo (Zincado)",
|
name: "Aço Galvanizado a Fogo (Zincado)",
|
||||||
metalness: 0.85,
|
postHex: 0x8a8e96,
|
||||||
roughness: 0.35,
|
textureUrl: "/images/chainlink-galvanizado.png"
|
||||||
postHex: 0x858990
|
|
||||||
},
|
},
|
||||||
verde: {
|
verde: {
|
||||||
hex: "#225528",
|
hex: "#22c55e",
|
||||||
threeHex: 0x225528,
|
threeHex: 0x22c55e,
|
||||||
name: "Revestido em PVC Verde Musgo (Quadras)",
|
name: "Revestido em PVC Verde Musgo (Quadras)",
|
||||||
metalness: 0.15,
|
postHex: 0x1f3621,
|
||||||
roughness: 0.45,
|
textureUrl: "/images/chainlink-pvc-verde.png"
|
||||||
postHex: 0x1f3621
|
|
||||||
},
|
},
|
||||||
preto: {
|
preto: {
|
||||||
hex: "#1d1f22",
|
hex: "#334155",
|
||||||
threeHex: 0x1d1f22,
|
threeHex: 0x334155,
|
||||||
name: "Revestido em PVC Preto Nobre",
|
name: "Revestido em PVC Preto Nobre",
|
||||||
metalness: 0.25,
|
postHex: 0x24272c,
|
||||||
roughness: 0.5,
|
textureUrl: "/images/chainlink-preto.png"
|
||||||
postHex: 0x24272c
|
|
||||||
},
|
},
|
||||||
cinza: {
|
cinza: {
|
||||||
hex: "#5c6269",
|
hex: "#94a3b8",
|
||||||
threeHex: 0x5c6269,
|
threeHex: 0x94a3b8,
|
||||||
name: "Revestido em PVC Cinza Urbano",
|
name: "Revestido em PVC Cinza Urbano",
|
||||||
metalness: 0.3,
|
postHex: 0x484b50,
|
||||||
roughness: 0.4,
|
textureUrl: "/images/chainlink-galvanizado.png"
|
||||||
postHex: 0x484b50
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -148,10 +153,9 @@ export default function FenceViewer3D() {
|
|||||||
const fenceGroupRef = useRef<THREE.Group | null>(null);
|
const fenceGroupRef = useRef<THREE.Group | null>(null);
|
||||||
const groundMeshRef = useRef<THREE.Mesh | null>(null);
|
const groundMeshRef = useRef<THREE.Mesh | null>(null);
|
||||||
|
|
||||||
// 1. Inicialização do Three.js (com reutilização segura do Canvas sem duplicação)
|
// 1. Inicialização do Three.js
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!canvasRef.current || !containerRef.current) return;
|
if (!canvasRef.current || !containerRef.current) return;
|
||||||
|
|
||||||
const canvas = canvasRef.current;
|
const canvas = canvasRef.current;
|
||||||
let renderer: THREE.WebGLRenderer;
|
let renderer: THREE.WebGLRenderer;
|
||||||
|
|
||||||
@@ -163,7 +167,7 @@ export default function FenceViewer3D() {
|
|||||||
powerPreference: "high-performance",
|
powerPreference: "high-performance",
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("WebGL não suportado ou falhou na inicialização:", e);
|
console.warn("WebGL não suportado:", e);
|
||||||
setWebGLError(true);
|
setWebGLError(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -176,7 +180,7 @@ export default function FenceViewer3D() {
|
|||||||
renderer.shadowMap.enabled = true;
|
renderer.shadowMap.enabled = true;
|
||||||
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
||||||
renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
||||||
renderer.toneMappingExposure = 1.2;
|
renderer.toneMappingExposure = 1.25;
|
||||||
rendererRef.current = renderer;
|
rendererRef.current = renderer;
|
||||||
|
|
||||||
const scene = new THREE.Scene();
|
const scene = new THREE.Scene();
|
||||||
@@ -185,7 +189,7 @@ export default function FenceViewer3D() {
|
|||||||
sceneRef.current = scene;
|
sceneRef.current = scene;
|
||||||
|
|
||||||
const camera = new THREE.PerspectiveCamera(40, width / heightPx, 0.1, 100);
|
const camera = new THREE.PerspectiveCamera(40, width / heightPx, 0.1, 100);
|
||||||
camera.position.set(4.8, 3.4, 6.2);
|
camera.position.set(4.8, 3.2, 5.8);
|
||||||
cameraRef.current = camera;
|
cameraRef.current = camera;
|
||||||
|
|
||||||
const controls = new OrbitControls(camera, canvas);
|
const controls = new OrbitControls(camera, canvas);
|
||||||
@@ -194,11 +198,11 @@ export default function FenceViewer3D() {
|
|||||||
controls.maxPolarAngle = Math.PI / 2 - 0.02;
|
controls.maxPolarAngle = Math.PI / 2 - 0.02;
|
||||||
controls.minDistance = 2.0;
|
controls.minDistance = 2.0;
|
||||||
controls.maxDistance = 20.0;
|
controls.maxDistance = 20.0;
|
||||||
controls.target.set(0, 1.1, 0);
|
controls.target.set(0, 1.0, 0);
|
||||||
controlsRef.current = controls;
|
controlsRef.current = controls;
|
||||||
|
|
||||||
// Luzes
|
// Iluminação
|
||||||
const ambientLight = new THREE.AmbientLight(0xffffff, 1.0);
|
const ambientLight = new THREE.AmbientLight(0xffffff, 1.2);
|
||||||
scene.add(ambientLight);
|
scene.add(ambientLight);
|
||||||
|
|
||||||
const sunLight = new THREE.DirectionalLight(0xffffff, 2.5);
|
const sunLight = new THREE.DirectionalLight(0xffffff, 2.5);
|
||||||
@@ -206,10 +210,9 @@ export default function FenceViewer3D() {
|
|||||||
sunLight.castShadow = true;
|
sunLight.castShadow = true;
|
||||||
sunLight.shadow.mapSize.width = 1024;
|
sunLight.shadow.mapSize.width = 1024;
|
||||||
sunLight.shadow.mapSize.height = 1024;
|
sunLight.shadow.mapSize.height = 1024;
|
||||||
sunLight.shadow.bias = -0.0005;
|
|
||||||
scene.add(sunLight);
|
scene.add(sunLight);
|
||||||
|
|
||||||
const fillLight = new THREE.DirectionalLight(0xa3c745, 0.4);
|
const fillLight = new THREE.DirectionalLight(0xa3c745, 0.5);
|
||||||
fillLight.position.set(-6, 4, -4);
|
fillLight.position.set(-6, 4, -4);
|
||||||
scene.add(fillLight);
|
scene.add(fillLight);
|
||||||
|
|
||||||
@@ -235,9 +238,6 @@ export default function FenceViewer3D() {
|
|||||||
scene.add(fenceGroup);
|
scene.add(fenceGroup);
|
||||||
fenceGroupRef.current = fenceGroup;
|
fenceGroupRef.current = fenceGroup;
|
||||||
|
|
||||||
setIsLoaded(true);
|
|
||||||
|
|
||||||
// Loop
|
|
||||||
let animId: number;
|
let animId: number;
|
||||||
const animate = () => {
|
const animate = () => {
|
||||||
animId = requestAnimationFrame(animate);
|
animId = requestAnimationFrame(animate);
|
||||||
@@ -284,7 +284,7 @@ export default function FenceViewer3D() {
|
|||||||
}
|
}
|
||||||
}, [ground]);
|
}, [ground]);
|
||||||
|
|
||||||
// 3. Renderização da Cerca em 3D
|
// 3. Renderização da Cerca em 3D + Rolo de Alambrado
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!fenceGroupRef.current || !sceneRef.current) return;
|
if (!fenceGroupRef.current || !sceneRef.current) return;
|
||||||
const group = fenceGroupRef.current;
|
const group = fenceGroupRef.current;
|
||||||
@@ -296,19 +296,26 @@ export default function FenceViewer3D() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const colConfig = colorMap[color];
|
const colConfig = colorMap[color];
|
||||||
const wireColorHex = fenceType === "alambrado_pvc" ? "#225528" : colConfig.hex;
|
const wireColorHex = fenceType === "alambrado_pvc" ? 0x22c55e : colConfig.threeHex;
|
||||||
|
|
||||||
// Material de mourão
|
// Material dos mourões de concreto
|
||||||
const postMat = new THREE.MeshStandardMaterial({
|
const postMat = new THREE.MeshStandardMaterial({
|
||||||
color: fenceType === "alambrado_curvo" ? 0x82868e : colConfig.postHex,
|
color: fenceType === "alambrado_curvo" ? 0x82868e : colConfig.postHex,
|
||||||
roughness: 0.9,
|
roughness: 0.9,
|
||||||
metalness: 0.1,
|
metalness: 0.1,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Material dos arames guia de sustentação
|
||||||
const steelGuideMat = new THREE.MeshStandardMaterial({
|
const steelGuideMat = new THREE.MeshStandardMaterial({
|
||||||
color: 0x9ca3af,
|
color: 0xe2e8f0,
|
||||||
metalness: 0.8,
|
metalness: 0.9,
|
||||||
roughness: 0.3,
|
roughness: 0.25,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Material de linhas sólidas visíveis para a tela de alambrado
|
||||||
|
const wireLineMat = new THREE.LineBasicMaterial({
|
||||||
|
color: wireColorHex,
|
||||||
|
linewidth: 2,
|
||||||
});
|
});
|
||||||
|
|
||||||
const spanLength = 2.5; // 2,50m entre mourões
|
const spanLength = 2.5; // 2,50m entre mourões
|
||||||
@@ -350,7 +357,7 @@ export default function FenceViewer3D() {
|
|||||||
spans.push({ startX: spanLength, startZ: 0, endX: spanLength, endZ: spanLength });
|
spans.push({ startX: spanLength, startZ: 0, endX: spanLength, endZ: spanLength });
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- MOURÕES ---
|
// --- MOURÕES DE CONCRETO (10x10cm) ---
|
||||||
posts.forEach((p, idx) => {
|
posts.forEach((p, idx) => {
|
||||||
const postHeight = h + (isCurved ? 0.45 : 0.05);
|
const postHeight = h + (isCurved ? 0.45 : 0.05);
|
||||||
|
|
||||||
@@ -391,11 +398,16 @@ export default function FenceViewer3D() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// --- PAINÉIS DE TELA DE ALAMBRADO ---
|
// --- CARREGADOR DE TEXTURA REALISTA ---
|
||||||
// Textura procedural ultra-leve e realista (zero crash de contexto WebGL)
|
const texUrl = fenceType === "alambrado_pvc" ? "/images/chainlink-pvc-verde.png" : colConfig.textureUrl;
|
||||||
const meshTexture = createChainLinkTexture(wireColorHex, 3);
|
const textureLoader = new THREE.TextureLoader();
|
||||||
|
const loadedTexture = textureLoader.load(texUrl);
|
||||||
|
loadedTexture.wrapS = THREE.RepeatWrapping;
|
||||||
|
loadedTexture.wrapT = THREE.RepeatWrapping;
|
||||||
|
|
||||||
const totalLines = h >= 2.0 ? 4 : 3;
|
const totalLines = h >= 2.0 ? 4 : 3;
|
||||||
|
|
||||||
|
// --- PAINÉIS DE TELA DE ALAMBRADO ---
|
||||||
spans.forEach((span) => {
|
spans.forEach((span) => {
|
||||||
const dx = span.endX - span.startX;
|
const dx = span.endX - span.startX;
|
||||||
const dz = span.endZ - span.startZ;
|
const dz = span.endZ - span.startZ;
|
||||||
@@ -404,10 +416,10 @@ export default function FenceViewer3D() {
|
|||||||
const cx = (span.startX + span.endX) / 2;
|
const cx = (span.startX + span.endX) / 2;
|
||||||
const cz = (span.startZ + span.endZ) / 2;
|
const cz = (span.startZ + span.endZ) / 2;
|
||||||
|
|
||||||
// Fiadas horizontais de arame guia
|
// 1. Fiadas horizontais de arame guia (Tensionadores)
|
||||||
for (let l = 1; l <= totalLines; l++) {
|
for (let l = 1; l <= totalLines; l++) {
|
||||||
const wireY = (h / (totalLines + 0.5)) * l;
|
const wireY = (h / (totalLines + 0.5)) * l;
|
||||||
const guideGeo = new THREE.CylinderGeometry(0.003, 0.003, len, 6);
|
const guideGeo = new THREE.CylinderGeometry(0.0035, 0.0035, len, 6);
|
||||||
const guideMesh = new THREE.Mesh(guideGeo, steelGuideMat);
|
const guideMesh = new THREE.Mesh(guideGeo, steelGuideMat);
|
||||||
guideMesh.rotation.z = Math.PI / 2;
|
guideMesh.rotation.z = Math.PI / 2;
|
||||||
guideMesh.rotation.y = -angle;
|
guideMesh.rotation.y = -angle;
|
||||||
@@ -415,10 +427,10 @@ export default function FenceViewer3D() {
|
|||||||
group.add(guideMesh);
|
group.add(guideMesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fios farpados no mourão curvo
|
// 2. Fios farpados no mourão curvo
|
||||||
if (isCurved && hasBarbedWire) {
|
if (isCurved && hasBarbedWire) {
|
||||||
for (let b = 1; b <= 3; b++) {
|
for (let b = 1; b <= 3; b++) {
|
||||||
const barbedGeo = new THREE.CylinderGeometry(0.0025, 0.0025, len, 6);
|
const barbedGeo = new THREE.CylinderGeometry(0.0028, 0.0028, len, 6);
|
||||||
const barbedMesh = new THREE.Mesh(barbedGeo, steelGuideMat);
|
const barbedMesh = new THREE.Mesh(barbedGeo, steelGuideMat);
|
||||||
barbedMesh.rotation.z = Math.PI / 2;
|
barbedMesh.rotation.z = Math.PI / 2;
|
||||||
barbedMesh.rotation.y = -angle;
|
barbedMesh.rotation.y = -angle;
|
||||||
@@ -427,14 +439,14 @@ export default function FenceViewer3D() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Concertina opcional
|
// 3. Concertina opcional
|
||||||
if (hasConcertina) {
|
if (hasConcertina) {
|
||||||
const concertinaRadius = 0.18;
|
const concertinaRadius = 0.18;
|
||||||
const coils = Math.floor(len * 5.5);
|
const coils = Math.floor(len * 5.5);
|
||||||
const step = len / coils;
|
const step = len / coils;
|
||||||
|
|
||||||
for (let k = 0; k < coils; k++) {
|
for (let k = 0; k < coils; k++) {
|
||||||
const torusGeo = new THREE.TorusGeometry(concertinaRadius, 0.0028, 6, 18);
|
const torusGeo = new THREE.TorusGeometry(concertinaRadius, 0.003, 6, 18);
|
||||||
const torusMesh = new THREE.Mesh(torusGeo, steelGuideMat);
|
const torusMesh = new THREE.Mesh(torusGeo, steelGuideMat);
|
||||||
torusMesh.rotation.y = -angle + Math.PI / 2;
|
torusMesh.rotation.y = -angle + Math.PI / 2;
|
||||||
const px = span.startX + Math.cos(angle) * (k * step + step / 2);
|
const px = span.startX + Math.cos(angle) * (k * step + step / 2);
|
||||||
@@ -445,30 +457,106 @@ export default function FenceViewer3D() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plano da Tela de Alambrado com textura de malha losangular
|
// 4. ARAMES LOSANGULARES (SÓLIDOS 100% VISÍVEIS)
|
||||||
const spanTexture = meshTexture.clone();
|
if (fenceType !== "gradil_3d") {
|
||||||
spanTexture.needsUpdate = true;
|
// Constrói os arames diagonais cruzados a 45°
|
||||||
const diamondScale = 0.055; // 50mm por losango
|
const wireGeo = buildChainLinkGeometry(len, h, 0.08);
|
||||||
spanTexture.repeat.set(len / diamondScale, h / diamondScale);
|
const wireSegments = new THREE.LineSegments(wireGeo, wireLineMat);
|
||||||
|
wireSegments.position.set(cx, 0, cz);
|
||||||
|
wireSegments.rotation.y = -angle;
|
||||||
|
group.add(wireSegments);
|
||||||
|
|
||||||
|
// Plano com textura metálica sombreada de fundo
|
||||||
|
const spanTex = loadedTexture.clone();
|
||||||
|
spanTex.needsUpdate = true;
|
||||||
|
spanTex.repeat.set(len / 0.10, h / 0.10);
|
||||||
|
|
||||||
const planeGeo = new THREE.PlaneGeometry(len, h);
|
const planeGeo = new THREE.PlaneGeometry(len, h);
|
||||||
const planeMat = new THREE.MeshStandardMaterial({
|
const planeMat = new THREE.MeshStandardMaterial({
|
||||||
map: spanTexture,
|
map: spanTex,
|
||||||
transparent: true,
|
transparent: true,
|
||||||
alphaTest: 0.15,
|
alphaTest: 0.05,
|
||||||
side: THREE.DoubleSide,
|
side: THREE.DoubleSide,
|
||||||
metalness: fenceType === "alambrado_pvc" ? 0.15 : 0.8,
|
metalness: fenceType === "alambrado_pvc" ? 0.2 : 0.85,
|
||||||
roughness: fenceType === "alambrado_pvc" ? 0.5 : 0.35,
|
roughness: fenceType === "alambrado_pvc" ? 0.5 : 0.3,
|
||||||
});
|
});
|
||||||
|
|
||||||
const planeMesh = new THREE.Mesh(planeGeo, planeMat);
|
const planeMesh = new THREE.Mesh(planeGeo, planeMat);
|
||||||
planeMesh.position.set(cx, h / 2, cz);
|
planeMesh.position.set(cx, h / 2, cz);
|
||||||
planeMesh.rotation.y = -angle;
|
planeMesh.rotation.y = -angle;
|
||||||
planeMesh.castShadow = true;
|
|
||||||
group.add(planeMesh);
|
group.add(planeMesh);
|
||||||
|
} else {
|
||||||
|
// Modo Gradil 3D (Linha Complementar)
|
||||||
|
const vertSpacing = 0.05;
|
||||||
|
const numVert = Math.floor(len / vertSpacing);
|
||||||
|
const vertGeo = new THREE.CylinderGeometry(0.0025, 0.0025, h, 5);
|
||||||
|
for (let v = -numVert / 2; v <= numVert / 2; v++) {
|
||||||
|
const wire = new THREE.Mesh(vertGeo, steelGuideMat);
|
||||||
|
wire.position.set(cx + v * vertSpacing * Math.cos(angle), h / 2, cz + v * vertSpacing * Math.sin(angle));
|
||||||
|
group.add(wire);
|
||||||
|
}
|
||||||
|
const numHoriz = Math.floor(h / 0.20);
|
||||||
|
const horizGeo = new THREE.CylinderGeometry(0.0025, 0.0025, len, 5);
|
||||||
|
for (let hz = 1; hz <= numHoriz; hz++) {
|
||||||
|
const wire = new THREE.Mesh(horizGeo, steelGuideMat);
|
||||||
|
wire.rotation.z = Math.PI / 2;
|
||||||
|
wire.rotation.y = -angle;
|
||||||
|
wire.position.set(cx, hz * 0.20, cz);
|
||||||
|
group.add(wire);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}, [fenceType, color, height, layout, hasBarbedWire, hasConcertina]);
|
// --- 5. ROLO DE TELA DE ALAMBRADO COMPACTADO (MODELO DE FÁBRICA) ---
|
||||||
|
// Conforme foto de referência: o rolo de tela fica em pé ao lado da cerca
|
||||||
|
if (showRoll && posts.length > 0) {
|
||||||
|
const rollRadius = 0.18; // Diâmetro de 36cm
|
||||||
|
const rollHeight = h;
|
||||||
|
const rollGroup = new THREE.Group();
|
||||||
|
rollGroup.position.set(posts[0].x - 0.65, 0, 0.35);
|
||||||
|
|
||||||
|
// Cilindro do rolo de tela
|
||||||
|
const rollTex = loadedTexture.clone();
|
||||||
|
rollTex.needsUpdate = true;
|
||||||
|
rollTex.repeat.set(6, rollHeight / 0.08);
|
||||||
|
|
||||||
|
const rollGeo = new THREE.CylinderGeometry(rollRadius, rollRadius, rollHeight, 24);
|
||||||
|
const rollMat = new THREE.MeshStandardMaterial({
|
||||||
|
map: rollTex,
|
||||||
|
color: wireColorHex,
|
||||||
|
metalness: fenceType === "alambrado_pvc" ? 0.3 : 0.8,
|
||||||
|
roughness: 0.4,
|
||||||
|
});
|
||||||
|
const rollMesh = new THREE.Mesh(rollGeo, rollMat);
|
||||||
|
rollMesh.position.y = rollHeight / 2;
|
||||||
|
rollMesh.castShadow = true;
|
||||||
|
rollGroup.add(rollMesh);
|
||||||
|
|
||||||
|
// Faixa / Etiqueta central da fábrica (como na foto do cliente)
|
||||||
|
const labelGeo = new THREE.CylinderGeometry(rollRadius + 0.005, rollRadius + 0.005, 0.35, 24);
|
||||||
|
const labelMat = new THREE.MeshStandardMaterial({
|
||||||
|
color: fenceType === "alambrado_pvc" ? 0x166534 : 0x0f766e,
|
||||||
|
roughness: 0.3,
|
||||||
|
});
|
||||||
|
const labelMesh = new THREE.Mesh(labelGeo, labelMat);
|
||||||
|
labelMesh.position.y = rollHeight / 2;
|
||||||
|
rollGroup.add(labelMesh);
|
||||||
|
|
||||||
|
// Arame de amarração do rolo (topo e base)
|
||||||
|
const tieGeo = new THREE.TorusGeometry(rollRadius + 0.008, 0.004, 6, 24);
|
||||||
|
const tieTop = new THREE.Mesh(tieGeo, steelGuideMat);
|
||||||
|
tieTop.rotation.x = Math.PI / 2;
|
||||||
|
tieTop.position.y = rollHeight * 0.85;
|
||||||
|
rollGroup.add(tieTop);
|
||||||
|
|
||||||
|
const tieBot = new THREE.Mesh(tieGeo, steelGuideMat);
|
||||||
|
tieBot.rotation.x = Math.PI / 2;
|
||||||
|
tieBot.position.y = rollHeight * 0.15;
|
||||||
|
rollGroup.add(tieBot);
|
||||||
|
|
||||||
|
group.add(rollGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
}, [fenceType, color, height, layout, hasBarbedWire, hasConcertina, showRoll]);
|
||||||
|
|
||||||
const setCameraView = (type: "geral" | "detalhe" | "topo") => {
|
const setCameraView = (type: "geral" | "detalhe" | "topo") => {
|
||||||
if (!cameraRef.current || !controlsRef.current) return;
|
if (!cameraRef.current || !controlsRef.current) return;
|
||||||
@@ -477,12 +565,12 @@ export default function FenceViewer3D() {
|
|||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "geral":
|
case "geral":
|
||||||
cam.position.set(4.8, 3.4, 6.2);
|
cam.position.set(4.8, 3.2, 5.8);
|
||||||
ctrl.target.set(0, 1.1, 0);
|
ctrl.target.set(0, 1.0, 0);
|
||||||
break;
|
break;
|
||||||
case "detalhe":
|
case "detalhe":
|
||||||
cam.position.set(0.8, 1.4, 1.5);
|
cam.position.set(0.6, 1.3, 1.4);
|
||||||
ctrl.target.set(0, 1.2, 0);
|
ctrl.target.set(0, 1.1, 0);
|
||||||
break;
|
break;
|
||||||
case "topo":
|
case "topo":
|
||||||
cam.position.set(0.1, 8.0, 0.1);
|
cam.position.set(0.1, 8.0, 0.1);
|
||||||
@@ -512,7 +600,7 @@ export default function FenceViewer3D() {
|
|||||||
estimatedPosts: currentLayout.posts,
|
estimatedPosts: currentLayout.posts,
|
||||||
estimatedWireKg,
|
estimatedWireKg,
|
||||||
estimatedTensioners,
|
estimatedTensioners,
|
||||||
notes: `Simulação no site: ${hasBarbedWire ? "Com 3 fios de arame farpado" : "Sem arame farpado"}${hasConcertina ? " + Concertina" : ""}.`,
|
notes: `Simulação 3D no site: ${hasBarbedWire ? "Com 3 fios de arame farpado" : "Sem arame farpado"}${hasConcertina ? " + Concertina" : ""}.`,
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -534,7 +622,7 @@ export default function FenceViewer3D() {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<p className="text-xs text-zinc-400">
|
<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.
|
Gire em 360°, aproxime para inspecionar a malha losangular e veja o rolo compacto ao lado da cerca.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -571,27 +659,25 @@ export default function FenceViewer3D() {
|
|||||||
{/* Grid: Canvas 3D (8 cols) + Controles (4 cols) */}
|
{/* Grid: Canvas 3D (8 cols) + Controles (4 cols) */}
|
||||||
<div className="grid grid-cols-1 lg:grid-cols-12 min-h-[580px]">
|
<div className="grid grid-cols-1 lg:grid-cols-12 min-h-[580px]">
|
||||||
|
|
||||||
{/* Canvas 3D Viewport com fallback visual garantido */}
|
{/* Canvas 3D Viewport */}
|
||||||
<div
|
<div
|
||||||
ref={containerRef}
|
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]"
|
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
|
<canvas
|
||||||
ref={canvasRef}
|
ref={canvasRef}
|
||||||
className="w-full h-full absolute inset-0 cursor-grab active:cursor-grabbing block bg-[#0a0c0e]"
|
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 && (
|
{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="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">
|
<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" />
|
<AlertTriangle className="w-6 h-6" />
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<h4 className="text-base font-heading font-bold text-white">Visualizador em Modo Interativo 2D</h4>
|
<h4 className="text-base font-heading font-bold text-white">Visualizador Interativo</h4>
|
||||||
<p className="text-xs text-zinc-400 max-w-md mt-1">
|
<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!
|
Seu navegador opera com aceleração gráfica limitada, mas todos os parâmetros e o cálculo continuam 100% funcionais!
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -600,7 +686,7 @@ export default function FenceViewer3D() {
|
|||||||
{/* Dica de Interação */}
|
{/* 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">
|
<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]" />
|
<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>
|
<span>Gire 360° • Aproxime para ver a malha de arame losangular e o rolo da fábrica</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Badge Inferior */}
|
{/* Badge Inferior */}
|
||||||
@@ -742,9 +828,9 @@ export default function FenceViewer3D() {
|
|||||||
<div className="grid grid-cols-2 gap-2">
|
<div className="grid grid-cols-2 gap-2">
|
||||||
{[
|
{[
|
||||||
{ id: "galvanizado", label: "Galvanizado a Fogo", hex: "bg-zinc-300" },
|
{ id: "galvanizado", label: "Galvanizado a Fogo", hex: "bg-zinc-300" },
|
||||||
{ id: "verde", label: "Revestido em PVC Verde", hex: "bg-emerald-800" },
|
{ id: "verde", label: "Revestido em PVC Verde", hex: "bg-emerald-600" },
|
||||||
{ id: "preto", label: "Revestido em PVC Preto", hex: "bg-zinc-950 border border-zinc-700" },
|
{ 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" },
|
{ id: "cinza", label: "Revestido em PVC Cinza", hex: "bg-zinc-500" },
|
||||||
].map((c) => (
|
].map((c) => (
|
||||||
<button
|
<button
|
||||||
key={c.id}
|
key={c.id}
|
||||||
@@ -763,7 +849,7 @@ export default function FenceViewer3D() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 4. Módulos na Prévia 3D */}
|
{/* 4. Extensão na Simulação */}
|
||||||
<div>
|
<div>
|
||||||
<label className="text-xs font-bold uppercase tracking-wider text-zinc-400 block mb-2">
|
<label className="text-xs font-bold uppercase tracking-wider text-zinc-400 block mb-2">
|
||||||
4. Extensão na Simulação:
|
4. Extensão na Simulação:
|
||||||
@@ -808,8 +894,21 @@ export default function FenceViewer3D() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Opcionais de Segurança */}
|
{/* Opcionais de Fábrica */}
|
||||||
<div className="pt-2 border-t border-zinc-800 space-y-2">
|
<div className="pt-2 border-t border-zinc-800 space-y-2">
|
||||||
|
<label className="flex items-center gap-2.5 cursor-pointer">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={showRoll}
|
||||||
|
onChange={(e) => setShowRoll(e.target.checked)}
|
||||||
|
className="w-4 h-4 rounded accent-[#a3c745] bg-zinc-900 border-zinc-700"
|
||||||
|
/>
|
||||||
|
<span className="text-xs text-zinc-300 flex items-center gap-1.5 font-medium">
|
||||||
|
<Package className="w-3.5 h-3.5 text-[#a3c745]" />
|
||||||
|
Exibir Rolo de Tela ao lado da cerca
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
{isCurved && (
|
{isCurved && (
|
||||||
<label className="flex items-center gap-2.5 cursor-pointer">
|
<label className="flex items-center gap-2.5 cursor-pointer">
|
||||||
<input
|
<input
|
||||||
|
|||||||
Reference in new issue
Block a user