Try repeat

This commit is contained in:
Халимов Рустам
2025-12-27 23:46:13 +03:00
parent ac00068175
commit 929e071ea7
4 changed files with 299 additions and 181 deletions

View File

@@ -8,49 +8,71 @@ export const calculateParts = (
): GeneratedPart[] => {
const parts: GeneratedPart[] = [];
const xPoints = [0, ...[...splits.x].sort((a, b) => a - b), 1];
const yPoints = [0, ...[...splits.y].sort((a, b) => a - b), 1];
// Безопасное чтение данных
const safeX = splits?.x || [];
const safeY = splits?.y || [];
const safeSub = splits?.subdivisions || {};
const xPoints = [0, ...[...safeX].sort((a, b) => a - b), 1];
const yPoints = [0, ...[...safeY].sort((a, b) => a - b), 1];
let partCounter = 1;
for (let i = 0; i < xPoints.length - 1; i++) {
for (let j = 0; j < yPoints.length - 1; j++) {
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 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 realWidth = segmentW - config.printerTolerance;
const realDepth = segmentD - config.printerTolerance;
const realX = segmentX + (config.printerTolerance / 2);
const realY = segmentY + (config.printerTolerance / 2);
// Получаем настройки деления
const subdiv = safeSub[`${i}-${j}`] || { rows: 1, cols: 1 };
// Размеры под-ячейки
const subCellWidth = rawW / subdiv.cols;
const subCellDepth = rawD / subdiv.rows;
if (realWidth < 5 || realDepth < 5) {
continue;
// Генерируем под-ячейки
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++;
}
}
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) остаются ТЕМИ ЖЕ,
// что и в прошлой работающей версии (со скруглениями и Extrude).
// Они не менялись при внедрении subdivisions, но для целостности я их продублирую.
// ... Остальной код (createRoundedRectShape, createBinGeometry) как в работающей версии ...
const createRoundedRectShape = (width: number, height: number, radius: number): THREE.Shape => {
const shape = new THREE.Shape();
const x = -width / 2;
@@ -84,12 +106,9 @@ export const createBinGeometry = (
thickness: number,
radius: number = 0
): THREE.BufferGeometry => {
const floorShape = createRoundedRectShape(width, depth, radius);
const floorGeo = new THREE.ExtrudeGeometry(floorShape, {
depth: thickness,
bevelEnabled: false,
curveSegments: 16
depth: thickness, bevelEnabled: false, curveSegments: 16
});
floorGeo.rotateX(-Math.PI / 2);
@@ -105,9 +124,7 @@ export const createBinGeometry = (
const wallHeight = height - thickness;
const wallGeo = new THREE.ExtrudeGeometry(outerShape, {
depth: wallHeight,
bevelEnabled: false,
curveSegments: 16
depth: wallHeight, bevelEnabled: false, curveSegments: 16
});
wallGeo.rotateX(-Math.PI / 2);