Try fix layout step

This commit is contained in:
Халимов Рустам
2026-01-10 16:57:20 +03:00
parent 4af73b00eb
commit f7911e7147
5 changed files with 86 additions and 75 deletions
+8 -29
View File
@@ -20,10 +20,8 @@ export const calculateParts = (config: AppConfig, splits: LayoutSplits): Generat
const rawW = (xPoints[i + 1] - xPoints[i]) * config.drawer.width;
const rawD = (yPoints[j + 1] - yPoints[j]) * config.drawer.depth;
// Получаем перегородки для этой ячейки
const internalPartitions = safeParts[`${i}-${j}`] || [];
// Рассчитываем реальные размеры с учетом допуска принтера
const realWidth = rawW - config.printerTolerance;
const realDepth = rawD - config.printerTolerance;
const realX = rawX + (config.printerTolerance / 2);
@@ -48,9 +46,7 @@ export const calculateParts = (config: AppConfig, splits: LayoutSplits): Generat
return parts;
};
// --- GEOMETRY GENERATION ---
// Создает форму скругленного прямоугольника (или обычного)
// Геометрия
const createRoundedRectShape = (width: number, height: number, radius: number): THREE.Shape => {
const shape = new THREE.Shape();
const x = -width / 2;
@@ -77,7 +73,6 @@ const createRoundedRectShape = (width: number, height: number, radius: number):
return shape;
};
// Генерирует геометрию ячейки С ПЕРЕГОРОДКАМИ
export const createBinGeometry = (
width: number,
depth: number,
@@ -89,12 +84,13 @@ export const createBinGeometry = (
const geometries: THREE.BufferGeometry[] = [];
// 1. ОСНОВНАЯ КОРОБКА (Дно + Стенки)
// 1. ДНО
const floorShape = createRoundedRectShape(width, depth, radius);
const floorGeo = new THREE.ExtrudeGeometry(floorShape, { depth: thickness, bevelEnabled: false, curveSegments: 12 });
floorGeo.rotateX(-Math.PI / 2);
geometries.push(floorGeo);
// 2. ВНЕШНИЕ СТЕНКИ
const outerShape = createRoundedRectShape(width, depth, radius);
const innerRadius = Math.max(0, radius - thickness);
const innerWidth = width - (2 * thickness);
@@ -111,62 +107,45 @@ export const createBinGeometry = (
wallGeo.translate(0, thickness, 0);
geometries.push(wallGeo);
// 2. ВНУТРЕННИЕ ПЕРЕГОРОДКИ
// Мы создаем их внутри внутреннего пространства (innerWidth/innerDepth)
// 3. ВНУТРЕННИЕ ПЕРЕГОРОДКИ
partitions.forEach(p => {
// Размеры перегородки
let pWidth = 0;
let pDepth = 0;
// Позиция центра перегородки относительно центра ящика
let pX = 0;
let pY = 0; // (это Z в 3D)
let pY = 0;
if (p.axis === 'x') {
// Вертикальная палка (делит ширину)
pWidth = thickness;
// Длина палки равна внутренней глубине ящика
pDepth = innerDepth;
// Смещение: p.offset (0..1) переводим в координаты.
// innerLeft = -innerWidth/2. Position = innerLeft + (innerWidth * offset)
pX = (-innerWidth / 2) + (innerWidth * p.offset);
pY = 0; // По центру глубины
pY = 0;
} else {
// Горизонтальная палка (делит глубину)
pWidth = innerWidth;
pDepth = thickness;
pX = 0; // По центру ширины
pX = 0;
pY = (-innerDepth / 2) + (innerDepth * p.offset);
}
// Форма перегородки (скругленная или нет)
// Если скругленная, радиус берем такой же как у основной стенки, но не больше половины толщины
const pRadius = p.rounded ? Math.min(radius, thickness / 1.5) : 0;
const partShape = createRoundedRectShape(pWidth, pDepth, pRadius);
const partGeo = new THREE.ExtrudeGeometry(partShape, {
depth: p.height, // Высота перегородки (может отличаться от основной)
depth: p.height,
bevelEnabled: false,
curveSegments: 8
});
partGeo.rotateX(-Math.PI / 2);
// Поднимаем на толщину дна
partGeo.translate(pX, thickness, pY);
geometries.push(partGeo);
});
// 3. СЛИЯНИЕ
const merged = mergeBufferGeometries(geometries);
if (merged) merged.computeVertexNormals();
return merged || new THREE.BoxGeometry(1, 1, 1);
};
// ... Остальной код экспорта (без изменений) ...
export const generateSTL = (mesh: THREE.Object3D): Uint8Array | string => {
const exporter = new STLExporter();
const result = exporter.parse(mesh, { binary: true });