This commit is contained in:
Халимов Рустам
2025-12-27 23:33:57 +03:00
parent 492585a2be
commit ac00068175
4 changed files with 179 additions and 277 deletions

View File

@@ -16,57 +16,41 @@ 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 = splits.subdivisions?.[`${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;
// Формируем имя: если ячейка поделена, добавляем индексы (1-1, 1-2...)
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) остаются ТЕМИ ЖЕ,
// что и в прошлой работающей версии (со скруглениями и Extrude).
// Они не менялись при внедрении subdivisions, но для целостности я их продублирую.
const createRoundedRectShape = (width: number, height: number, radius: number): THREE.Shape => {
const shape = new THREE.Shape();
const x = -width / 2;
@@ -100,9 +84,12 @@ 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);
@@ -118,7 +105,9 @@ 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);