5
This commit is contained in:
+127
-138
@@ -2,37 +2,23 @@ import * as THREE from 'three';
|
|||||||
import { STLExporter, mergeBufferGeometries } from 'three-stdlib';
|
import { STLExporter, mergeBufferGeometries } from 'three-stdlib';
|
||||||
import { AppConfig, LayoutSplits, GeneratedPart, Partition } from '../types';
|
import { AppConfig, LayoutSplits, GeneratedPart, Partition } from '../types';
|
||||||
|
|
||||||
// --- CLEANUP UTILS ---
|
// --- ВСПОМОГАТЕЛЬНЫЕ ФУНКЦИИ ---
|
||||||
|
|
||||||
// Удаляет дублирующиеся перегородки (фантомы)
|
// Извлекаем ВСЕ перегородки из всех ячеек в один плоский список
|
||||||
const deduplicatePartitions = (partitions: Partition[]): Partition[] => {
|
const getAllPartitions = (splits: LayoutSplits): Partition[] => {
|
||||||
const unique: Partition[] = [];
|
if (!splits || !splits.partitions) return [];
|
||||||
const seen = new Set<string>();
|
return Object.values(splits.partitions).flat();
|
||||||
|
|
||||||
partitions.forEach(p => {
|
|
||||||
// Округляем координаты для создания уникального ключа
|
|
||||||
const k = `${p.axis}-${p.offset.toFixed(3)}-${p.min?.toFixed(3)}-${p.max?.toFixed(3)}`;
|
|
||||||
if (!seen.has(k)) {
|
|
||||||
seen.add(k);
|
|
||||||
unique.push(p);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return unique;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Очистка точек для генерации цветных объемов
|
|
||||||
const cleanPoints = (points: number[]) => {
|
|
||||||
return Array.from(new Set(points.map(p => parseFloat(p.toFixed(3))))).sort((a, b) => a - b);
|
|
||||||
};
|
|
||||||
|
|
||||||
// --- CALCULATE VOLUMES (ЦВЕТНЫЕ КУБИКИ) ---
|
|
||||||
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 : [];
|
||||||
const safeY = Array.isArray(splits?.y) ? splits.y : [];
|
const safeY = Array.isArray(splits?.y) ? splits.y : [];
|
||||||
|
const safeParts = splits?.partitions || {};
|
||||||
|
|
||||||
const uniqueX = cleanPoints([0, ...safeX, 1]);
|
// Просто сортируем точки, без сложной фильтрации, чтобы совпадало с 2D
|
||||||
const uniqueY = cleanPoints([0, ...safeY, 1]);
|
const uniqueX = [0, ...safeX, 1].sort((a, b) => a - b);
|
||||||
|
const uniqueY = [0, ...safeY, 1].sort((a, b) => a - b);
|
||||||
|
|
||||||
let partCounter = 1;
|
let partCounter = 1;
|
||||||
|
|
||||||
@@ -43,24 +29,29 @@ 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];
|
||||||
|
|
||||||
const w = (x2 - x1) * config.drawer.width;
|
// Игнорируем вырожденные ячейки
|
||||||
const d = (y2 - y1) * config.drawer.depth;
|
if (x2 - x1 < 0.001 || y2 - y1 < 0.001) continue;
|
||||||
|
|
||||||
if (w < 2 || d < 2) continue;
|
const rawW = (x2 - x1) * config.drawer.width;
|
||||||
|
const rawD = (y2 - y1) * config.drawer.depth;
|
||||||
|
const rawX = x1 * config.drawer.width;
|
||||||
|
const rawY = y1 * config.drawer.depth;
|
||||||
|
|
||||||
// Отступ для визуализации (gap)
|
const internalPartitions = safeParts[`${i}-${j}`] || [];
|
||||||
const gap = config.wallThickness / 2 + 0.2;
|
|
||||||
|
// Отступ для визуализации объемов (gap)
|
||||||
|
const gap = config.wallThickness / 2 + 0.1;
|
||||||
|
|
||||||
parts.push({
|
parts.push({
|
||||||
id: `part-${partCounter}`,
|
id: `part-${partCounter}`,
|
||||||
name: `Ячейка ${partCounter}`,
|
name: `Ячейка ${partCounter}`,
|
||||||
width: Math.max(1, w - gap * 2),
|
width: Math.max(1, rawW - gap * 2),
|
||||||
depth: Math.max(1, d - gap * 2),
|
depth: Math.max(1, rawD - gap * 2),
|
||||||
height: config.drawer.height - config.wallThickness,
|
height: config.drawer.height - config.wallThickness,
|
||||||
x: (x1 * config.drawer.width) + gap,
|
x: rawX + gap,
|
||||||
y: (y1 * config.drawer.depth) + gap,
|
y: rawY + gap,
|
||||||
color: `hsl(${(partCounter * 137.5) % 360}, 70%, 50%)`,
|
color: `hsl(${(partCounter * 137.5) % 360}, 70%, 50%)`,
|
||||||
internalPartitions: []
|
internalPartitions: internalPartitions
|
||||||
});
|
});
|
||||||
partCounter++;
|
partCounter++;
|
||||||
}
|
}
|
||||||
@@ -68,24 +59,25 @@ export const calculateParts = (config: AppConfig, splits: LayoutSplits): Generat
|
|||||||
return parts;
|
return parts;
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- SHAPE GENERATION (PERFORATION) ---
|
// --- ГЕОМЕТРИЯ ---
|
||||||
|
|
||||||
|
// Прямоугольник с отверстиями
|
||||||
const createPerforatedShape = (length: number, height: number, config: AppConfig): THREE.Shape => {
|
const createPerforatedShape = (length: number, height: number, config: AppConfig): THREE.Shape => {
|
||||||
const shape = new THREE.Shape();
|
const shape = new THREE.Shape();
|
||||||
|
|
||||||
// 1. Внешний контур: CCW (Против часовой)
|
// Внешний контур (CCW)
|
||||||
shape.moveTo(0, 0);
|
shape.moveTo(0, 0);
|
||||||
shape.lineTo(length, 0);
|
shape.lineTo(length, 0);
|
||||||
shape.lineTo(length, height);
|
shape.lineTo(length, height);
|
||||||
shape.lineTo(0, height);
|
shape.lineTo(0, height);
|
||||||
shape.lineTo(0, 0);
|
shape.lineTo(0, 0);
|
||||||
|
|
||||||
// Если перфорация выключена или стена слишком мала
|
// Если перфорация выключена или стена мала
|
||||||
if (!config.perforation?.enabled || length < 10 || height < 10) return shape;
|
if (!config.perforation?.enabled || length < 10 || height < 10) return shape;
|
||||||
|
|
||||||
const { pattern, diameter, spacing } = config.perforation;
|
const { pattern, diameter, spacing } = config.perforation;
|
||||||
const step = diameter + Math.max(2, spacing);
|
const step = diameter + Math.max(2, spacing);
|
||||||
const margin = 4; // Отступ от краев
|
const margin = 3;
|
||||||
|
|
||||||
const effW = length - margin * 2;
|
const effW = length - margin * 2;
|
||||||
const effH = height - margin * 2;
|
const effH = height - margin * 2;
|
||||||
@@ -107,28 +99,24 @@ const createPerforatedShape = (length: number, height: number, config: AppConfig
|
|||||||
let cx = startX + i * step;
|
let cx = startX + i * step;
|
||||||
if ((pattern === 'hexagon' || pattern === 'triangle') && isOdd) cx += step / 2;
|
if ((pattern === 'hexagon' || pattern === 'triangle') && isOdd) cx += step / 2;
|
||||||
|
|
||||||
// Проверка границ
|
|
||||||
if (cx - diameter/2 < margin || cx + diameter/2 > length - margin ||
|
if (cx - diameter/2 < margin || cx + diameter/2 > length - margin ||
|
||||||
cy - diameter/2 < margin || cy + diameter/2 > height - margin) continue;
|
cy - diameter/2 < margin || cy + diameter/2 > height - margin) continue;
|
||||||
|
|
||||||
const hole = new THREE.Path();
|
const hole = new THREE.Path();
|
||||||
const r = diameter / 2;
|
const r = diameter / 2;
|
||||||
|
|
||||||
// 2. Отверстия: CW (По часовой) - Это критично для Three.js!
|
// ДЫРКИ СТРОГО ПО ЧАСОВОЙ (CW)
|
||||||
if (pattern === 'circle') {
|
if (pattern === 'circle') {
|
||||||
hole.absarc(cx, cy, r, 0, Math.PI * 2, true);
|
hole.absarc(cx, cy, r, 0, Math.PI * 2, true);
|
||||||
}
|
} else if (pattern === 'hexagon') {
|
||||||
else if (pattern === 'hexagon') {
|
|
||||||
for (let k = 0; k < 6; k++) {
|
for (let k = 0; k < 6; k++) {
|
||||||
// -k обеспечивает CW порядок
|
|
||||||
const angle = (-k * 60 + 90) * Math.PI / 180;
|
const angle = (-k * 60 + 90) * Math.PI / 180;
|
||||||
const px = cx + r * Math.cos(angle);
|
const px = cx + r * Math.cos(angle);
|
||||||
const py = cy + r * Math.sin(angle);
|
const py = cy + r * Math.sin(angle);
|
||||||
if (k === 0) hole.moveTo(px, py); else hole.lineTo(px, py);
|
if (k === 0) hole.moveTo(px, py); else hole.lineTo(px, py);
|
||||||
}
|
}
|
||||||
hole.closePath();
|
hole.closePath();
|
||||||
}
|
} else if (pattern === 'triangle') {
|
||||||
else if (pattern === 'triangle') {
|
|
||||||
const rot = isOdd ? 180 : 0;
|
const rot = isOdd ? 180 : 0;
|
||||||
for (let k = 0; k < 3; k++) {
|
for (let k = 0; k < 3; k++) {
|
||||||
const angle = (-k * 120 + 90 + rot) * Math.PI / 180;
|
const angle = (-k * 120 + 90 + rot) * Math.PI / 180;
|
||||||
@@ -144,9 +132,10 @@ const createPerforatedShape = (length: number, height: number, config: AppConfig
|
|||||||
return shape;
|
return shape;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Floor Shape (Solid)
|
|
||||||
const createFloorShape = (width: number, depth: number, radius: number): THREE.Shape => {
|
const createFloorShape = (width: number, depth: number, radius: number): THREE.Shape => {
|
||||||
const shape = new THREE.Shape();
|
const shape = new THREE.Shape();
|
||||||
|
// Floor shape centered at 0,0 for ease of rotation later if needed,
|
||||||
|
// BUT createBinGeometry expects floor to be from -W/2 to W/2
|
||||||
const x = -width / 2;
|
const x = -width / 2;
|
||||||
const y = -depth / 2;
|
const y = -depth / 2;
|
||||||
const r = Math.min(radius, width / 2 - 0.1, depth / 2 - 0.1);
|
const r = Math.min(radius, width / 2 - 0.1, depth / 2 - 0.1);
|
||||||
@@ -171,6 +160,7 @@ const createFloorShape = (width: number, depth: number, radius: number): THREE.S
|
|||||||
return shape;
|
return shape;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Галтель (вогнутая) для стыков
|
||||||
const createFilletShape = (radius: number): THREE.Shape => {
|
const createFilletShape = (radius: number): THREE.Shape => {
|
||||||
const shape = new THREE.Shape();
|
const shape = new THREE.Shape();
|
||||||
shape.moveTo(0, 0);
|
shape.moveTo(0, 0);
|
||||||
@@ -180,18 +170,30 @@ const createFilletShape = (radius: number): THREE.Shape => {
|
|||||||
return shape;
|
return shape;
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- BUILDER ---
|
// --- MAIN BUILDER ---
|
||||||
|
|
||||||
|
// Обратите внимание: сигнатура изменена, теперь мы принимаем splits целиком
|
||||||
export const createBinGeometry = (
|
export const createBinGeometry = (
|
||||||
width: number, depth: number, height: number, thickness: number, radius: number = 0, partitions: Partition[] = [], config?: AppConfig
|
width: number, depth: number, height: number, thickness: number, radius: number = 0,
|
||||||
|
splits: LayoutSplits | Partition[] = [], // Поддержка и старого, и нового формата
|
||||||
|
config?: AppConfig
|
||||||
): THREE.BufferGeometry => {
|
): THREE.BufferGeometry => {
|
||||||
|
|
||||||
const geometries: THREE.BufferGeometry[] = [];
|
const geometries: THREE.BufferGeometry[] = [];
|
||||||
const safeConfig = config || { perforation: { enabled: false } } as AppConfig;
|
const safeConfig = config || { perforation: { enabled: false } } as AppConfig;
|
||||||
|
|
||||||
// 1. FLOOR
|
// Нормализация входных данных: нам нужен плоский список стенок
|
||||||
|
let partitions: Partition[] = [];
|
||||||
|
if (Array.isArray(splits)) {
|
||||||
|
partitions = splits;
|
||||||
|
} else if (splits && splits.partitions) {
|
||||||
|
partitions = getAllPartitions(splits);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. ПОЛ
|
||||||
const floorShape = createFloorShape(width, depth, radius);
|
const floorShape = createFloorShape(width, depth, radius);
|
||||||
const floorGeo = new THREE.ExtrudeGeometry(floorShape, { depth: thickness, bevelEnabled: false });
|
const floorGeo = new THREE.ExtrudeGeometry(floorShape, { depth: thickness, bevelEnabled: false });
|
||||||
floorGeo.rotateX(-Math.PI / 2);
|
floorGeo.rotateX(-Math.PI / 2); // XZ plane
|
||||||
geometries.push(floorGeo);
|
geometries.push(floorGeo);
|
||||||
|
|
||||||
// Размеры внутреннего пространства
|
// Размеры внутреннего пространства
|
||||||
@@ -199,132 +201,119 @@ export const createBinGeometry = (
|
|||||||
const innerD = depth - 2 * thickness;
|
const innerD = depth - 2 * thickness;
|
||||||
const wallH = height - thickness;
|
const wallH = height - thickness;
|
||||||
|
|
||||||
// Helper для установки стенки
|
// 2. ВНЕШНИЕ СТЕНКИ
|
||||||
const placeWall = (length: number, isVertical: boolean, centerX: number, centerZ: number) => {
|
const shapeFB = createPerforatedShape(innerW, wallH, safeConfig);
|
||||||
// Генерируем 2D форму с дырками
|
const shapeLR = createPerforatedShape(depth, wallH, safeConfig);
|
||||||
const shape = createPerforatedShape(length, wallH, safeConfig);
|
|
||||||
const geo = new THREE.ExtrudeGeometry(shape, { depth: thickness, bevelEnabled: false });
|
|
||||||
|
|
||||||
if (isVertical) {
|
// Front (вдоль X, спереди)
|
||||||
// Вертикальная (идет вдоль Z)
|
const geoF = new THREE.ExtrudeGeometry(shapeFB, { depth: thickness, bevelEnabled: false });
|
||||||
// Shape рисуется в XY. Extrude в Z.
|
geoF.translate(-innerW/2, thickness, depth/2 - thickness);
|
||||||
// Поворачиваем вокруг Y на 90.
|
geometries.push(geoF);
|
||||||
// X -> Z, Y -> Y, Z -> X.
|
|
||||||
// Теперь длина (бывший X) идет вдоль Z. Толщина (бывший Z) идет вдоль X.
|
|
||||||
geo.rotateY(Math.PI / 2);
|
|
||||||
|
|
||||||
// Центр по X: centerX. Начало по Z: centerZ - length/2.
|
// Back (вдоль X, сзади)
|
||||||
// После поворота: начало в (0,0,0) перешло в (0,0,0).
|
const geoB = new THREE.ExtrudeGeometry(shapeFB, { depth: thickness, bevelEnabled: false });
|
||||||
// Длина ушла в -Z (или +Z в зависимости от правил).
|
geoB.translate(-innerW/2, thickness, -depth/2);
|
||||||
// Проще: ставим центр геометрии в центр позиции.
|
geometries.push(geoB);
|
||||||
geo.center(); // Центрируем геометрию локально
|
|
||||||
geo.translate(centerX, thickness + wallH/2, centerZ); // Ставим на место
|
|
||||||
} else {
|
|
||||||
// Горизонтальная (идет вдоль X)
|
|
||||||
// Shape в XY. Extrude в Z.
|
|
||||||
// Длина вдоль X. Толщина вдоль Z.
|
|
||||||
geo.center();
|
|
||||||
geo.translate(centerX, thickness + wallH/2, centerZ);
|
|
||||||
}
|
|
||||||
geometries.push(geo);
|
|
||||||
};
|
|
||||||
|
|
||||||
// 2. EXTERNAL WALLS
|
// Left (вдоль Z, слева)
|
||||||
// Front (вдоль X)
|
const geoL = new THREE.ExtrudeGeometry(shapeLR, { depth: thickness, bevelEnabled: false });
|
||||||
placeWall(innerW, false, -width/2 + innerW/2 + thickness, depth/2 - thickness/2); // Исправленные координаты
|
geoL.rotateY(Math.PI / 2);
|
||||||
// Проще: Front стоит на Z = depth/2 - thick/2. X центр = 0 (если floor от -W/2 до W/2).
|
geoL.translate(-width/2, thickness, -depth/2);
|
||||||
// Floor shape: -W/2..W/2.
|
geometries.push(geoL);
|
||||||
|
|
||||||
// Давайте пересчитаем позиции точно относительно центра (0,0)
|
// Right (вдоль Z, справа)
|
||||||
// Front: CenterX=0, CenterZ = (depth - thickness)/2
|
const geoR = new THREE.ExtrudeGeometry(shapeLR, { depth: thickness, bevelEnabled: false });
|
||||||
placeWall(innerW, false, 0, (depth - thickness)/2);
|
geoR.rotateY(Math.PI / 2);
|
||||||
|
geoR.translate(width/2 - thickness, thickness, -depth/2);
|
||||||
|
geometries.push(geoR);
|
||||||
|
|
||||||
// Back: CenterX=0, CenterZ = -(depth - thickness)/2
|
// 3. ВНУТРЕННИЕ ПЕРЕГОРОДКИ (Исправлено позиционирование)
|
||||||
placeWall(innerW, false, 0, -(depth - thickness)/2);
|
partitions.forEach(p => {
|
||||||
|
|
||||||
// Left: CenterX=-(width - thickness)/2, CenterZ=0. Length = depth.
|
|
||||||
placeWall(depth, true, -(width - thickness)/2, 0);
|
|
||||||
|
|
||||||
// Right: CenterX=(width - thickness)/2, CenterZ=0. Length = depth.
|
|
||||||
placeWall(depth, true, (width - thickness)/2, 0);
|
|
||||||
|
|
||||||
|
|
||||||
// 3. INTERNAL PARTITIONS
|
|
||||||
// Используем дедупликацию, чтобы убрать двойные стенки
|
|
||||||
const uniquePartitions = deduplicatePartitions(partitions);
|
|
||||||
|
|
||||||
uniquePartitions.forEach(p => {
|
|
||||||
const pMin = p.min ?? 0;
|
const pMin = p.min ?? 0;
|
||||||
const pMax = p.max ?? 1;
|
const pMax = p.max ?? 1;
|
||||||
|
|
||||||
if (pMax - pMin < 0.01) return;
|
// Игнорируем ошибки данных
|
||||||
|
if (pMax - pMin < 0.001) return;
|
||||||
|
|
||||||
let length = 0;
|
let length = 0;
|
||||||
let cX = 0;
|
let isVertical = false; // Vertical on 2D screen = Along Z axis in 3D
|
||||||
let cZ = 0;
|
|
||||||
let isVertical = false;
|
// Вычисляем координаты центра и длины
|
||||||
|
let posX = 0; // Центр по X (для верт) или Начало по X (для гориз)
|
||||||
|
let posZ = 0; // Начало по Z (для верт) или Центр по Z (для гориз)
|
||||||
|
|
||||||
if (p.axis === 'x') {
|
if (p.axis === 'x') {
|
||||||
// Вертикальная на экране 2D (вдоль Z в 3D)
|
// Вертикальная на экране (Z-axis in 3D)
|
||||||
isVertical = true;
|
isVertical = true;
|
||||||
length = (pMax - pMin) * innerD;
|
length = (pMax - pMin) * innerD;
|
||||||
|
// В 2D X идет слева направо (0..1). В 3D X идет от -innerW/2 до innerW/2.
|
||||||
// X: offset * innerW. Но innerW начинается от -innerW/2.
|
posX = (-innerW/2) + (p.offset * innerW);
|
||||||
cX = (-innerW/2) + (p.offset * innerW);
|
// В 2D Y идет сверху вниз (0..1). В 3D Z идет от -innerD/2 (зад) до innerD/2 (перед).
|
||||||
|
posZ = (-innerD/2) + (pMin * innerD);
|
||||||
// Z центр: Середина между pMin и pMax
|
|
||||||
const midRatio = (pMin + pMax) / 2;
|
|
||||||
cZ = (-innerD/2) + (midRatio * innerD);
|
|
||||||
} else {
|
} else {
|
||||||
// Горизонтальная на экране 2D (вдоль X в 3D)
|
// Горизонтальная на экране (X-axis in 3D)
|
||||||
isVertical = false;
|
isVertical = false;
|
||||||
length = (pMax - pMin) * innerW;
|
length = (pMax - pMin) * innerW;
|
||||||
|
posX = (-innerW/2) + (pMin * innerW);
|
||||||
// X центр
|
posZ = (-innerD/2) + (p.offset * innerD);
|
||||||
const midRatio = (pMin + pMax) / 2;
|
|
||||||
cX = (-innerW/2) + (midRatio * innerW);
|
|
||||||
|
|
||||||
// Z: offset * innerD
|
|
||||||
cZ = (-innerD/2) + (p.offset * innerD);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
placeWall(length, isVertical, cX, cZ);
|
// Генерируем 2D профиль
|
||||||
|
const partShape = createPerforatedShape(length, wallH, safeConfig);
|
||||||
|
const partGeo = new THREE.ExtrudeGeometry(partShape, { depth: thickness, bevelEnabled: false });
|
||||||
|
|
||||||
// --- FILLETS ---
|
if (isVertical) {
|
||||||
|
// Поворот чтобы шла вдоль Z
|
||||||
|
partGeo.rotateY(Math.PI / 2);
|
||||||
|
// Смещаем в позицию.
|
||||||
|
// Центр X = posX. Но так как толщина экструзии идет в +X (после поворота), надо сместить на -thickness/2
|
||||||
|
partGeo.translate(posX - thickness/2, thickness, posZ);
|
||||||
|
} else {
|
||||||
|
// Вдоль X
|
||||||
|
// Центр Z = posZ. Смещаем на -thickness/2
|
||||||
|
partGeo.translate(posX, thickness, posZ - thickness/2);
|
||||||
|
}
|
||||||
|
|
||||||
|
geometries.push(partGeo);
|
||||||
|
|
||||||
|
// --- СКРУГЛЕНИЯ (FILLETS) ---
|
||||||
if (p.rounded && radius > 1) {
|
if (p.rounded && radius > 1) {
|
||||||
const fR = Math.min(radius, 5);
|
const fR = Math.min(radius, 5);
|
||||||
const fShape = createFilletShape(fR);
|
const fShape = createFilletShape(fR);
|
||||||
const h = p.height;
|
const h = p.height;
|
||||||
|
|
||||||
const addFillet = (x: number, z: number, rot: number) => {
|
const addFillet = (fx: number, fz: number, rot: number) => {
|
||||||
const geo = new THREE.ExtrudeGeometry(fShape, { depth: h, bevelEnabled: false });
|
const geo = new THREE.ExtrudeGeometry(fShape, { depth: h, bevelEnabled: false });
|
||||||
geo.rotateX(-Math.PI / 2);
|
geo.rotateX(-Math.PI / 2);
|
||||||
geo.rotateY(rot);
|
geo.rotateY(rot);
|
||||||
geo.translate(x, thickness, z);
|
geo.translate(fx, thickness, fz);
|
||||||
geometries.push(geo);
|
geometries.push(geo);
|
||||||
};
|
};
|
||||||
|
|
||||||
const t = thickness / 2;
|
const t = thickness / 2;
|
||||||
|
|
||||||
// Вычисляем концы стенки для скруглений
|
|
||||||
if (isVertical) {
|
if (isVertical) {
|
||||||
const zStart = cZ - length/2;
|
const zStart = posZ;
|
||||||
const zEnd = cZ + length/2;
|
const zEnd = posZ + length;
|
||||||
|
|
||||||
// Верхний стык (дальний по Z, если смотреть в 2D) -> Min
|
// Top junction (Z-min / Back)
|
||||||
addFillet(cX - t, zStart, Math.PI);
|
addFillet(posX - t, zStart, Math.PI); // Face Back-Left
|
||||||
addFillet(cX + t, zStart, -Math.PI/2);
|
addFillet(posX + t, zStart, -Math.PI/2); // Face Back-Right
|
||||||
// Нижний стык -> Max
|
|
||||||
addFillet(cX - t, zEnd, Math.PI/2);
|
// Bottom junction (Z-max / Front)
|
||||||
addFillet(cX + t, zEnd, 0);
|
addFillet(posX - t, zEnd, Math.PI/2); // Face Front-Left
|
||||||
|
addFillet(posX + t, zEnd, 0); // Face Front-Right
|
||||||
} else {
|
} else {
|
||||||
const xStart = cX - length/2;
|
const xStart = posX;
|
||||||
const xEnd = cX + length/2;
|
const xEnd = posX + length;
|
||||||
|
|
||||||
addFillet(xStart, cZ - t, 0);
|
// Left junction (X-min / Left)
|
||||||
addFillet(xStart, cZ + t, -Math.PI/2);
|
addFillet(xStart, posZ - t, 0); // Face Left-Back
|
||||||
addFillet(xEnd, cZ - t, Math.PI/2);
|
addFillet(xStart, posZ + t, -Math.PI/2); // Face Left-Front
|
||||||
addFillet(xEnd, cZ + t, Math.PI);
|
|
||||||
|
// Right junction (X-max / Right)
|
||||||
|
addFillet(xEnd, posZ - t, Math.PI/2); // Face Right-Back
|
||||||
|
addFillet(xEnd, posZ + t, Math.PI); // Face Right-Front
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user