This commit is contained in:
Халимов Рустам
2025-12-27 23:53:52 +03:00
parent 929e071ea7
commit 8789d82064
4 changed files with 175 additions and 289 deletions

View File

@@ -8,10 +8,9 @@ export const calculateParts = (
): GeneratedPart[] => {
const parts: GeneratedPart[] = [];
// Безопасное чтение данных
const safeX = splits?.x || [];
const safeY = splits?.y || [];
const safeSub = splits?.subdivisions || {};
// Safe Access
const safeX = splits.x || [];
const safeY = splits.y || [];
const xPoints = [0, ...[...safeX].sort((a, b) => a - b), 1];
const yPoints = [0, ...[...safeY].sort((a, b) => a - b), 1];
@@ -21,58 +20,37 @@ export const calculateParts = (
for (let i = 0; i < xPoints.length - 1; i++) {
for (let j = 0; j < yPoints.length - 1; j++) {
const rawX = xPoints[i] * config.drawer.width;
const rawY = yPoints[j] * config.drawer.depth;
const rawW = (xPoints[i + 1] - xPoints[i]) * config.drawer.width;
const rawD = (yPoints[j + 1] - yPoints[j]) * config.drawer.depth;
const segmentX = xPoints[i] * config.drawer.width;
const segmentY = yPoints[j] * config.drawer.depth;
const segmentW = (xPoints[i + 1] - xPoints[i]) * config.drawer.width;
const segmentD = (yPoints[j + 1] - yPoints[j]) * config.drawer.depth;
// Получаем настройки деления
const subdiv = safeSub[`${i}-${j}`] || { rows: 1, cols: 1 };
// Размеры под-ячейки
const subCellWidth = rawW / subdiv.cols;
const subCellDepth = rawD / subdiv.rows;
const realWidth = segmentW - config.printerTolerance;
const realDepth = segmentD - config.printerTolerance;
const realX = segmentX + (config.printerTolerance / 2);
const realY = segmentY + (config.printerTolerance / 2);
// Генерируем под-ячейки
for (let r = 0; r < subdiv.rows; r++) {
for (let c = 0; c < subdiv.cols; c++) {
const subX = rawX + (c * subCellWidth);
const subY = rawY + (r * subCellDepth);
const realWidth = subCellWidth - config.printerTolerance;
const realDepth = subCellDepth - config.printerTolerance;
const realX = subX + (config.printerTolerance / 2);
const realY = subY + (config.printerTolerance / 2);
if (realWidth < 5 || realDepth < 5) continue;
// Имя: если деление, добавляем суффикс
let partName = `Ячейка ${i+1}-${j+1}`;
if (subdiv.rows > 1 || subdiv.cols > 1) {
partName += ` (${r+1}-${c+1})`;
}
parts.push({
id: `part-${partCounter}`,
name: partName,
width: realWidth,
depth: realDepth,
height: config.drawer.height,
x: realX,
y: realY,
color: `hsl(${Math.random() * 360}, 70%, 50%)`
});
partCounter++;
}
if (realWidth < 5 || realDepth < 5) {
continue;
}
parts.push({
id: `part-${partCounter}`,
name: `Ячейка ${i+1}-${j+1}`,
width: realWidth,
depth: realDepth,
height: config.drawer.height,
x: realX,
y: realY,
color: `hsl(${Math.random() * 360}, 70%, 50%)`
});
partCounter++;
}
}
return parts;
};
// ... Остальной код (createRoundedRectShape, createBinGeometry) как в работающей версии ...
const createRoundedRectShape = (width: number, height: number, radius: number): THREE.Shape => {
const shape = new THREE.Shape();
const x = -width / 2;