5
This commit is contained in:
2675
package-lock.json
generated
2675
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -20,7 +20,6 @@
|
|||||||
"react": "^19.2.3",
|
"react": "^19.2.3",
|
||||||
"react-dom": "^19.2.3",
|
"react-dom": "^19.2.3",
|
||||||
"three": "^0.182.0",
|
"three": "^0.182.0",
|
||||||
"three-bvh-csg": "^0.0.17",
|
|
||||||
"three-stdlib": "^2.36.1",
|
"three-stdlib": "^2.36.1",
|
||||||
"uuid": "^9.0.1"
|
"uuid": "^9.0.1"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,21 +1,29 @@
|
|||||||
import * as THREE from 'three';
|
import * as THREE from 'three';
|
||||||
import { STLExporter } from 'three-stdlib';
|
import { STLExporter, mergeBufferGeometries } from 'three-stdlib';
|
||||||
import { SUBTRACTION, ADDITION, Brush, Evaluator } from 'three-bvh-csg';
|
|
||||||
import { mergeBufferGeometries } from 'three-stdlib';
|
|
||||||
import { AppConfig, LayoutSplits, GeneratedPart, Partition } from '../types';
|
import { AppConfig, LayoutSplits, GeneratedPart, Partition } from '../types';
|
||||||
|
|
||||||
// --- ВСПОМОГАТЕЛЬНЫЕ ФУНКЦИИ ---
|
// --- УТИЛИТЫ ---
|
||||||
|
|
||||||
|
// Очистка координат (убирает фантомные ячейки)
|
||||||
const cleanPoints = (points: number[]) => {
|
const cleanPoints = (points: number[]) => {
|
||||||
const rounded = points.map(p => Math.round(p * 1000) / 1000).sort((a, b) => a - b);
|
// Округляем и убираем дубликаты с допуском
|
||||||
return [...new Set(rounded)];
|
const sorted = points.map(p => Math.round(p * 1000) / 1000).sort((a, b) => a - b);
|
||||||
|
const unique = [sorted[0]];
|
||||||
|
for (let i = 1; i < sorted.length; i++) {
|
||||||
|
if (sorted[i] - unique[unique.length - 1] > 0.002) {
|
||||||
|
unique.push(sorted[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return unique;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Сбор перегородок
|
||||||
const getAllPartitions = (splits: LayoutSplits): Partition[] => {
|
const getAllPartitions = (splits: LayoutSplits): Partition[] => {
|
||||||
if (!splits || !splits.partitions) return [];
|
if (!splits || !splits.partitions) return [];
|
||||||
return Object.values(splits.partitions).flat();
|
return Object.values(splits.partitions).flat();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// --- ВИЗУАЛИЗАЦИЯ (ЦВЕТНЫЕ БЛОКИ) ---
|
||||||
export const calculateParts = (config: AppConfig, splits: LayoutSplits): GeneratedPart[] => {
|
export const calculateParts = (config: AppConfig, splits: LayoutSplits): GeneratedPart[] => {
|
||||||
const parts: GeneratedPart[] = [];
|
const parts: GeneratedPart[] = [];
|
||||||
const safeX = Array.isArray(splits?.x) ? splits.x : [];
|
const safeX = Array.isArray(splits?.x) ? splits.x : [];
|
||||||
@@ -33,10 +41,12 @@ export const calculateParts = (config: AppConfig, splits: LayoutSplits): Generat
|
|||||||
const y1 = uniqueY[j];
|
const y1 = uniqueY[j];
|
||||||
const y2 = uniqueY[j+1];
|
const y2 = uniqueY[j+1];
|
||||||
|
|
||||||
if (x2 - x1 < 0.001 || y2 - y1 < 0.001) continue;
|
|
||||||
|
|
||||||
const rawW = (x2 - x1) * config.drawer.width;
|
const rawW = (x2 - x1) * config.drawer.width;
|
||||||
const rawD = (y2 - y1) * config.drawer.depth;
|
const rawD = (y2 - y1) * config.drawer.depth;
|
||||||
|
|
||||||
|
// Игнорируем слишком мелкие технические зазоры
|
||||||
|
if (rawW < 2 || rawD < 2) continue;
|
||||||
|
|
||||||
const rawX = x1 * config.drawer.width;
|
const rawX = x1 * config.drawer.width;
|
||||||
const rawY = y1 * config.drawer.depth;
|
const rawY = y1 * config.drawer.depth;
|
||||||
|
|
||||||
@@ -47,7 +57,7 @@ export const calculateParts = (config: AppConfig, splits: LayoutSplits): Generat
|
|||||||
name: `Ячейка ${partCounter}`,
|
name: `Ячейка ${partCounter}`,
|
||||||
width: Math.max(1, rawW - gap * 2),
|
width: Math.max(1, rawW - gap * 2),
|
||||||
depth: Math.max(1, rawD - gap * 2),
|
depth: Math.max(1, rawD - gap * 2),
|
||||||
height: config.drawer.height,
|
height: config.drawer.height - config.wallThickness,
|
||||||
x: rawX + gap,
|
x: rawX + gap,
|
||||||
y: rawY + gap,
|
y: rawY + gap,
|
||||||
color: `hsl(${(partCounter * 137.5) % 360}, 70%, 50%)`,
|
color: `hsl(${(partCounter * 137.5) % 360}, 70%, 50%)`,
|
||||||
@@ -59,7 +69,117 @@ export const calculateParts = (config: AppConfig, splits: LayoutSplits): Generat
|
|||||||
return parts;
|
return parts;
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- ГЕНЕРАЦИЯ ГЕОМЕТРИИ (ПОСЛЕДОВАТЕЛЬНЫЙ CSG) ---
|
// --- ГЕНЕРАЦИЯ СТЕН С ПЕРФОРАЦИЕЙ (2D SHAPE -> EXTRUDE) ---
|
||||||
|
|
||||||
|
const createPerforatedShape = (length: number, height: number, config: AppConfig): THREE.Shape => {
|
||||||
|
const shape = new THREE.Shape();
|
||||||
|
|
||||||
|
// 1. Внешний контур (CCW - Против часовой стрелки)
|
||||||
|
shape.moveTo(0, 0);
|
||||||
|
shape.lineTo(length, 0);
|
||||||
|
shape.lineTo(length, height);
|
||||||
|
shape.lineTo(0, height);
|
||||||
|
shape.lineTo(0, 0);
|
||||||
|
|
||||||
|
// Если перфорация выключена или стена слишком мала
|
||||||
|
if (!config.perforation?.enabled || length < 15 || height < 15) return shape;
|
||||||
|
|
||||||
|
const { pattern, diameter, spacing } = config.perforation;
|
||||||
|
const step = diameter + Math.max(2, spacing);
|
||||||
|
const margin = 4; // Отступ от края
|
||||||
|
|
||||||
|
// Рабочая зона
|
||||||
|
const effW = length - margin * 2;
|
||||||
|
const effH = height - margin * 2;
|
||||||
|
|
||||||
|
if (effW <= diameter || effH <= diameter) return shape;
|
||||||
|
|
||||||
|
// Расчет сетки
|
||||||
|
const rowH = pattern === 'circle' ? step : step * 0.866;
|
||||||
|
const cols = Math.floor(effW / step);
|
||||||
|
const rows = Math.floor(effH / rowH);
|
||||||
|
|
||||||
|
// Центрирование
|
||||||
|
const startX = margin + (effW - (cols - 1) * step) / 2;
|
||||||
|
const startY = margin + (effH - (rows - 1) * rowH) / 2;
|
||||||
|
|
||||||
|
for (let j = 0; j < rows; j++) {
|
||||||
|
const isOdd = j % 2 !== 0;
|
||||||
|
const cy = startY + j * rowH;
|
||||||
|
|
||||||
|
for (let i = 0; i < cols; i++) {
|
||||||
|
let cx = startX + i * step;
|
||||||
|
if ((pattern === 'hexagon' || pattern === 'triangle') && isOdd) cx += step / 2;
|
||||||
|
|
||||||
|
// Проверка границ
|
||||||
|
if (cx - diameter/2 < margin || cx + diameter/2 > length - margin ||
|
||||||
|
cy - diameter/2 < margin || cy + diameter/2 > height - margin) continue;
|
||||||
|
|
||||||
|
const hole = new THREE.Path();
|
||||||
|
const r = diameter / 2;
|
||||||
|
|
||||||
|
// 2. ОТВЕРСТИЯ (CW - По часовой стрелке)!!!
|
||||||
|
// Это критически важно. Если рисовать CCW, Three.js зальет дырку.
|
||||||
|
|
||||||
|
if (pattern === 'circle') {
|
||||||
|
// aClockwise = true
|
||||||
|
hole.absarc(cx, cy, r, 0, Math.PI * 2, true);
|
||||||
|
}
|
||||||
|
else if (pattern === 'hexagon') {
|
||||||
|
// 6 точек по часовой
|
||||||
|
for (let k = 0; k < 6; k++) {
|
||||||
|
const angle = (-k * 60 + 90) * Math.PI / 180;
|
||||||
|
const px = cx + r * Math.cos(angle);
|
||||||
|
const py = cy + r * Math.sin(angle);
|
||||||
|
if (k === 0) hole.moveTo(px, py); else hole.lineTo(px, py);
|
||||||
|
}
|
||||||
|
hole.closePath();
|
||||||
|
}
|
||||||
|
else if (pattern === 'triangle') {
|
||||||
|
const rot = isOdd ? 180 : 0;
|
||||||
|
// 3 точки по часовой
|
||||||
|
for (let k = 0; k < 3; k++) {
|
||||||
|
const angle = (-k * 120 + 90 + rot) * Math.PI / 180;
|
||||||
|
const px = cx + r * Math.cos(angle);
|
||||||
|
const py = cy + r * Math.sin(angle);
|
||||||
|
if (k === 0) hole.moveTo(px, py); else hole.lineTo(px, py);
|
||||||
|
}
|
||||||
|
hole.closePath();
|
||||||
|
}
|
||||||
|
shape.holes.push(hole);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return shape;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Пол (всегда сплошной)
|
||||||
|
const createFloorShape = (width: number, depth: number, radius: number): THREE.Shape => {
|
||||||
|
const shape = new THREE.Shape();
|
||||||
|
const x = -width / 2;
|
||||||
|
const y = -depth / 2;
|
||||||
|
const r = Math.min(radius, width / 2 - 0.1, depth / 2 - 0.1);
|
||||||
|
|
||||||
|
if (r <= 0.1) {
|
||||||
|
shape.moveTo(x, y);
|
||||||
|
shape.lineTo(x + width, y);
|
||||||
|
shape.lineTo(x + width, y + depth);
|
||||||
|
shape.lineTo(x, y + depth);
|
||||||
|
shape.lineTo(x, y);
|
||||||
|
} else {
|
||||||
|
shape.moveTo(x, y + r);
|
||||||
|
shape.lineTo(x, y + depth - r);
|
||||||
|
shape.quadraticCurveTo(x, y + depth, x + r, y + depth);
|
||||||
|
shape.lineTo(x + width - r, y + depth);
|
||||||
|
shape.quadraticCurveTo(x + width, y + depth, x + width, y + depth - r);
|
||||||
|
shape.lineTo(x + width, y + r);
|
||||||
|
shape.quadraticCurveTo(x + width, y, x + width - r, y);
|
||||||
|
shape.lineTo(x + r, y);
|
||||||
|
shape.quadraticCurveTo(x, y, x, y + r);
|
||||||
|
}
|
||||||
|
return shape;
|
||||||
|
};
|
||||||
|
|
||||||
|
// --- СБОРКА МОДЕЛИ ---
|
||||||
|
|
||||||
export const createBinGeometry = (
|
export const createBinGeometry = (
|
||||||
width: number, depth: number, height: number, thickness: number, radius: number = 0,
|
width: number, depth: number, height: number, thickness: number, radius: number = 0,
|
||||||
@@ -67,169 +187,137 @@ export const createBinGeometry = (
|
|||||||
config?: AppConfig
|
config?: AppConfig
|
||||||
): THREE.BufferGeometry => {
|
): THREE.BufferGeometry => {
|
||||||
|
|
||||||
|
// Массив для слияния всех частей
|
||||||
|
const geometries: THREE.BufferGeometry[] = [];
|
||||||
const safeConfig = config || { perforation: { enabled: false } } as AppConfig;
|
const safeConfig = config || { perforation: { enabled: false } } as AppConfig;
|
||||||
const evaluator = new Evaluator();
|
|
||||||
evaluator.useGroups = false;
|
// 1. ПОЛ
|
||||||
|
const floorShape = createFloorShape(width, depth, radius);
|
||||||
|
const floorGeo = new THREE.ExtrudeGeometry(floorShape, { depth: thickness, bevelEnabled: false });
|
||||||
|
floorGeo.rotateX(-Math.PI / 2); // Кладем плашмя (XZ)
|
||||||
|
geometries.push(floorGeo);
|
||||||
|
|
||||||
const wallH = height - thickness;
|
const wallH = height - thickness;
|
||||||
const innerW = width - 2 * thickness;
|
const innerW = width - 2 * thickness;
|
||||||
const innerD = depth - 2 * thickness;
|
const innerD = depth - 2 * thickness;
|
||||||
|
|
||||||
// 1. Базовая геометрия - ПОЛ
|
// Функция для создания и установки стены
|
||||||
const floorGeo = new THREE.BoxGeometry(width, thickness, depth);
|
// Мы создаем 2D форму (Length x Height), экструдим её на Thickness, и ставим в 3D
|
||||||
floorGeo.translate(0, thickness / 2, 0);
|
const placeWall = (length: number, isVertical: boolean, centerX: number, centerZ: number) => {
|
||||||
let mainBrush = new Brush(floorGeo);
|
// 1. Создаем 2D профиль с дырками
|
||||||
mainBrush.updateMatrixWorld();
|
const shape = createPerforatedShape(length, wallH, safeConfig);
|
||||||
|
|
||||||
// --- ФУНКЦИИ ОПЕРАЦИЙ ---
|
// 2. Экструдим (получаем толщину)
|
||||||
|
const geo = new THREE.ExtrudeGeometry(shape, { depth: thickness, bevelEnabled: false });
|
||||||
|
|
||||||
// Добавить твердое тело (стену/скругление)
|
// 3. Позиционируем
|
||||||
const addSolid = (geo: THREE.BufferGeometry) => {
|
// Изначально: 0..Length по X, 0..Height по Y, 0..Thickness по Z
|
||||||
const brush = new Brush(geo);
|
|
||||||
brush.updateMatrixWorld();
|
|
||||||
mainBrush = evaluator.evaluate(mainBrush, brush, ADDITION);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Вычесть отверстия для конкретной зоны
|
// Центрируем геометрию относительно её осей для удобства вращения
|
||||||
const subtractHoles = (W: number, H: number, startX: number, startY: number, startZ: number, axis: 'x' | 'z') => {
|
geo.center();
|
||||||
if (!safeConfig.perforation?.enabled) return;
|
// Теперь она от -L/2 до L/2 по X, -H/2 до H/2 по Y, -T/2 до T/2 по Z
|
||||||
const { pattern, diameter, spacing } = safeConfig.perforation;
|
|
||||||
const margin = 4;
|
|
||||||
const step = diameter + Math.max(2, spacing);
|
|
||||||
|
|
||||||
const cols = Math.floor((W - margin*2) / step);
|
if (isVertical) {
|
||||||
const rowH = pattern === 'circle' ? step : step * 0.866;
|
// Вертикальная стена (идет вдоль Z)
|
||||||
const rows = Math.floor((H - margin*2) / rowH);
|
geo.rotateY(Math.PI / 2); // Поворачиваем: теперь длина вдоль Z, толщина вдоль X
|
||||||
|
|
||||||
if (cols <= 0 || rows <= 0) return;
|
|
||||||
|
|
||||||
const offsetX = (W - cols * step) / 2;
|
|
||||||
const offsetY = (H - rows * rowH) / 2;
|
|
||||||
|
|
||||||
// Базовое сверло
|
|
||||||
const drillBase = new THREE.CylinderGeometry(diameter/2, diameter/2, thickness * 3, 12);
|
|
||||||
if (axis === 'x') drillBase.rotateX(Math.PI / 2); // Вдоль Z
|
|
||||||
else drillBase.rotateZ(Math.PI / 2); // Вдоль X
|
|
||||||
|
|
||||||
const drills: THREE.BufferGeometry[] = [];
|
|
||||||
|
|
||||||
for(let r=0; r<rows; r++) {
|
|
||||||
const isOdd = r % 2 !== 0;
|
|
||||||
for(let c=0; c<cols; c++) {
|
|
||||||
let u = offsetX + c * step + diameter/2;
|
|
||||||
let v = offsetY + r * rowH + diameter/2;
|
|
||||||
if ((pattern === 'hexagon' || pattern === 'triangle') && isOdd) u += step/2;
|
|
||||||
if (u > W - margin || v > H - margin) continue;
|
|
||||||
|
|
||||||
const drill = drillBase.clone();
|
|
||||||
if (axis === 'x') drill.translate(startX + u, startY + v, startZ);
|
|
||||||
else drill.translate(startX, startY + v, startZ + u);
|
|
||||||
drills.push(drill);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (drills.length > 0) {
|
// Переносим на финальную позицию
|
||||||
const mergedDrills = mergeBufferGeometries(drills);
|
// Y = thickness (пол) + wallH/2 (так как мы центрировали геометрию по Y)
|
||||||
if (mergedDrills) {
|
geo.translate(centerX, thickness + wallH/2, centerZ);
|
||||||
const drillBrush = new Brush(mergedDrills);
|
|
||||||
drillBrush.updateMatrixWorld();
|
geometries.push(geo);
|
||||||
mainBrush = evaluator.evaluate(mainBrush, drillBrush, SUBTRACTION);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 2. ВНЕШНИЕ СТЕНЫ
|
||||||
|
// Front (Спереди, вдоль X)
|
||||||
|
placeWall(innerW, false, 0, depth/2 - thickness/2);
|
||||||
|
|
||||||
// 2. СБОРКА СТЕН (ADDITION)
|
// Back (Сзади, вдоль X)
|
||||||
|
placeWall(innerW, false, 0, -depth/2 + thickness/2);
|
||||||
|
|
||||||
// Внешние стены
|
// Left (Слева, вдоль Z, полная глубина)
|
||||||
// Front
|
placeWall(depth, true, -width/2 + thickness/2, 0);
|
||||||
addSolid(new THREE.BoxGeometry(innerW, wallH, thickness).translate(0, thickness + wallH/2, depth/2 - thickness/2));
|
|
||||||
// Back
|
|
||||||
addSolid(new THREE.BoxGeometry(innerW, wallH, thickness).translate(0, thickness + wallH/2, -depth/2 + thickness/2));
|
|
||||||
// Left
|
|
||||||
addSolid(new THREE.BoxGeometry(thickness, wallH, depth).translate(-width/2 + thickness/2, thickness + wallH/2, 0));
|
|
||||||
// Right
|
|
||||||
addSolid(new THREE.BoxGeometry(thickness, wallH, depth).translate(width/2 - thickness/2, thickness + wallH/2, 0));
|
|
||||||
|
|
||||||
// Внутренние перегородки
|
// Right (Справа, вдоль Z, полная глубина)
|
||||||
|
placeWall(depth, true, width/2 - thickness/2, 0);
|
||||||
|
|
||||||
|
|
||||||
|
// 3. ВНУТРЕННИЕ ПЕРЕГОРОДКИ
|
||||||
let partitions: Partition[] = [];
|
let partitions: Partition[] = [];
|
||||||
if (Array.isArray(splits)) partitions = splits;
|
if (Array.isArray(splits)) partitions = splits;
|
||||||
else if (splits && splits.partitions) partitions = getAllPartitions(splits);
|
else if (splits && splits.partitions) partitions = getAllPartitions(splits);
|
||||||
|
|
||||||
partitions.forEach(p => {
|
partitions.forEach(p => {
|
||||||
const pMin = p.min ?? 0; const pMax = p.max ?? 1;
|
const pMin = p.min ?? 0;
|
||||||
|
const pMax = p.max ?? 1;
|
||||||
|
|
||||||
if (Math.abs(pMax - pMin) < 0.001) return;
|
if (Math.abs(pMax - pMin) < 0.001) return;
|
||||||
|
|
||||||
let w=0, h=p.height, d=0, x=0, z=0;
|
let length = 0;
|
||||||
if (p.axis === 'x') { // Vert (Z-axis)
|
let cX = 0;
|
||||||
w = thickness; d = (pMax - pMin) * innerD;
|
let cZ = 0;
|
||||||
x = (-innerW/2) + (p.offset * innerW);
|
let isVert = false;
|
||||||
z = (-innerD/2) + ((pMin + pMax)/2 * innerD);
|
|
||||||
} else { // Horiz (X-axis)
|
if (p.axis === 'x') {
|
||||||
w = (pMax - pMin) * innerW; d = thickness;
|
// Вертикальная на схеме (вдоль Z)
|
||||||
x = (-innerW/2) + ((pMin + pMax)/2 * innerW);
|
isVert = true;
|
||||||
z = (-innerD/2) + (p.offset * innerD);
|
length = (pMax - pMin) * innerD;
|
||||||
|
// X: смещение от центра
|
||||||
|
cX = (-innerW/2) + (p.offset * innerW);
|
||||||
|
// Z: центр отрезка
|
||||||
|
const midRatio = (pMin + pMax) / 2;
|
||||||
|
cZ = (-innerD/2) + (midRatio * innerD);
|
||||||
|
} else {
|
||||||
|
// Горизонтальная на схеме (вдоль X)
|
||||||
|
isVert = false;
|
||||||
|
length = (pMax - pMin) * innerW;
|
||||||
|
// X: центр отрезка
|
||||||
|
const midRatio = (pMin + pMax) / 2;
|
||||||
|
cX = (-innerW/2) + (midRatio * innerW);
|
||||||
|
// Z: смещение от центра
|
||||||
|
cZ = (-innerD/2) + (p.offset * innerD);
|
||||||
}
|
}
|
||||||
addSolid(new THREE.BoxGeometry(w, h, d).translate(x, thickness + h/2, z));
|
|
||||||
});
|
|
||||||
|
|
||||||
// 3. СКРУГЛЕНИЯ (ADDITION - цилиндры в углы)
|
placeWall(length, isVert, cX, cZ);
|
||||||
if (radius > 0) {
|
|
||||||
const fRad = Math.min(radius, 5);
|
|
||||||
const filletBase = new THREE.CylinderGeometry(fRad, fRad, 1, 16);
|
|
||||||
filletBase.translate(0, 0.5, 0); // Pivot at bottom
|
|
||||||
|
|
||||||
partitions.forEach(p => {
|
// --- СКРУГЛЕНИЯ (СТОЛБИКИ) ---
|
||||||
if (!p.rounded) return;
|
// Добавляем цилиндры в места стыков для прочности и визуального скругления
|
||||||
const pMin = p.min ?? 0; const pMax = p.max ?? 1;
|
if (p.rounded && radius > 0) {
|
||||||
if (Math.abs(pMax - pMin) < 0.001) return;
|
const r = Math.min(radius, 5);
|
||||||
|
const cylGeo = new THREE.CylinderGeometry(r, r, p.height, 16);
|
||||||
|
cylGeo.translate(0, p.height/2, 0); // Пивот внизу
|
||||||
|
|
||||||
const addF = (x: number, z: number) => {
|
const addCyl = (x: number, z: number) => {
|
||||||
const f = filletBase.clone();
|
const c = cylGeo.clone();
|
||||||
f.scale(1, p.height, 1);
|
c.translate(x, thickness, z);
|
||||||
f.translate(x, thickness, z);
|
geometries.push(c);
|
||||||
addSolid(f);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (p.axis === 'x') { // Vert
|
if (isVert) {
|
||||||
const xPos = (-innerW/2) + (p.offset * innerW);
|
const startZ = cZ - length/2;
|
||||||
addF(xPos, (-innerD/2) + (pMin * innerD)); // Start Z
|
const endZ = cZ + length/2;
|
||||||
addF(xPos, (-innerD/2) + (pMax * innerD)); // End Z
|
addCyl(cX, startZ);
|
||||||
} else { // Horiz
|
addCyl(cX, endZ);
|
||||||
const zPos = (-innerD/2) + (p.offset * innerD);
|
|
||||||
addF((-innerW/2) + (pMin * innerW), zPos); // Start X
|
|
||||||
addF((-innerW/2) + (pMax * innerW), zPos); // End X
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. ПЕРФОРАЦИЯ (SUBTRACTION)
|
|
||||||
if (safeConfig.perforation?.enabled) {
|
|
||||||
// Внешние стены
|
|
||||||
subtractHoles(innerW, wallH, -innerW/2, thickness, depth/2, 'x'); // Front
|
|
||||||
subtractHoles(innerW, wallH, -innerW/2, thickness, -depth/2, 'x'); // Back
|
|
||||||
subtractHoles(depth, wallH, -width/2, thickness, -depth/2, 'z'); // Left
|
|
||||||
subtractHoles(depth, wallH, width/2, thickness, -depth/2, 'z'); // Right
|
|
||||||
|
|
||||||
// Внутренние перегородки
|
|
||||||
partitions.forEach(p => {
|
|
||||||
const pMin = p.min ?? 0; const pMax = p.max ?? 1;
|
|
||||||
if (Math.abs(pMax - pMin) < 0.001) return;
|
|
||||||
if (p.axis === 'x') {
|
|
||||||
const len = (pMax - pMin) * innerD;
|
|
||||||
const xPos = (-innerW/2) + (p.offset * innerW);
|
|
||||||
const zStart = (-innerD/2) + (pMin * innerD);
|
|
||||||
subtractHoles(len, p.height, xPos, thickness, zStart, 'z');
|
|
||||||
} else {
|
} else {
|
||||||
const len = (pMax - pMin) * innerW;
|
const startX = cX - length/2;
|
||||||
const xStart = (-innerW/2) + (pMin * innerW);
|
const endX = cX + length/2;
|
||||||
const zPos = (-innerD/2) + (p.offset * innerD);
|
addCyl(startX, cZ);
|
||||||
subtractHoles(len, p.height, xStart, thickness, zPos, 'x');
|
addCyl(endX, cZ);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 4. СЛИЯНИЕ ВСЕГО В ОДИН МЕШ
|
||||||
|
// Это критично для STL экспорта - должен быть один объект
|
||||||
|
const merged = mergeBufferGeometries(geometries);
|
||||||
|
|
||||||
|
if (merged) {
|
||||||
|
merged.computeVertexNormals();
|
||||||
|
return merged;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mainBrush.geometry;
|
return new THREE.BoxGeometry(1, 1, 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const generateSTL = (mesh: THREE.Object3D): Uint8Array | string => {
|
export const generateSTL = (mesh: THREE.Object3D): Uint8Array | string => {
|
||||||
|
|||||||
Reference in New Issue
Block a user