fix(v1.0.3): VDE-019 center参数 + VDE-020 cone/torus + VDE-022 位置查询 + VDE-026 BVH索引
Build & Test / build-and-test (push) Waiting to run
Build & Test / python-bindings (push) Blocked by required conditions
CI / Build & Test (push) Failing after 41s
CI / Release Build (push) Failing after 33s

VDE-019 (Fixed): make_box/make_cylinder/make_sphere 添加 Point3D center 参数
VDE-020 (Fixed): 新增 make_cone(r1,r2,height) 和 make_torus(rMajor,rMinor) 基本体
VDE-022 (Partially Fixed): 添加 get_edge_index_by_position / get_face_index_by_position / fillet_by_position / chamfer_by_position
VDE-026 (Fixed): Triangle3D 添加 int id 字段,BVH::build() 自动赋值索引,HitResult 添加 tri_index
VDE-021/023/024/025 (Acknowledged): mesh→NURBS 转换等复杂几何算法,需求已记录

反馈来自 ViewDesign feat/viewdesign-engine 分支
This commit is contained in:
茂之钳
2026-07-28 17:08:03 +08:00
parent fbf9b400b5
commit aeb29ab87c
15 changed files with 735 additions and 87 deletions
+111 -3
View File
@@ -157,7 +157,8 @@ using core::AABB3D;
* @see make_cylinder 圆柱体
* @see make_sphere 球体
*/
[[nodiscard]] BrepModel make_box(double w, double h, double d);
[[nodiscard]] BrepModel make_box(double w, double h, double d,
const Point3D& center = Point3D(0, 0, 0));
/**
* @brief 创建圆柱体
@@ -178,7 +179,8 @@ using core::AABB3D;
* @see make_box 立方体
* @see make_sphere 球体
*/
[[nodiscard]] BrepModel make_cylinder(double radius, double height, int segments = 32);
[[nodiscard]] BrepModel make_cylinder(double radius, double height, int segments = 32,
const Point3D& center = Point3D(0, 0, 0));
/**
* @brief 创建球体
@@ -196,7 +198,52 @@ using core::AABB3D;
*
* @see make_cylinder 圆柱体
*/
[[nodiscard]] BrepModel make_sphere(double radius, int segments_u = 32, int segments_v = 16);
[[nodiscard]] BrepModel make_sphere(double radius, int segments_u = 32, int segments_v = 16,
const Point3D& center = Point3D(0, 0, 0));
/**
* @brief 创建圆锥/圆台
*
* 沿 Y 轴、以给定位置为中心的圆锥或圆台。
*
* @param r1 底部半径,必须 ≥ 0
* @param r2 顶部半径,必须 ≥ 0(r2=0 时为圆锥)
* @param height 总高度,沿 Y 轴从 -h/2 到 +h/2
* @param segments 截面分段数(边数,默认 32)
* @param center 几何中心位置(默认原点)
* @return 实心圆台/圆锥 B-Rep
*
* @code{.cpp}
* auto cone = make_cone(3.0, 1.0, 8.0); // 底部半径 3,顶部半径 1
* auto pointy = make_cone(2.0, 0.0, 5.0); // 圆锥(顶部半径 0
* @endcode
*
* @see make_cylinder 圆柱体
*/
[[nodiscard]] BrepModel make_cone(double r1, double r2, double height, int segments = 32,
const Point3D& center = Point3D(0, 0, 0));
/**
* @brief 创建圆环体
*
* 以给定位置为中心的圆环体(torus)。
*
* @param rMajor 中心环半径(从圆环中心到管中心的距离)
* @param rMinor 管半径
* @param segments_u 绕中心环的分段数(默认 32)
* @param segments_v 绕管截面的分段数(默认 16)
* @param center 几何中心位置(默认原点)
* @return 实心圆环体 B-Rep
*
* @pre rMajor > rMinor > 0
*
* @code{.cpp}
* auto torus = make_torus(5.0, 1.0, 64, 32);
* @endcode
*/
[[nodiscard]] BrepModel make_torus(double rMajor, double rMinor,
int segments_u = 32, int segments_v = 16,
const Point3D& center = Point3D(0, 0, 0));
// ═══════════════════════════════════════════════
// 编辑操作
@@ -291,4 +338,65 @@ using core::AABB3D;
*/
[[nodiscard]] BrepModel shell(const BrepModel& body, int face_id, double thickness);
// ═══════════════════════════════════════════════
// 拓扑查询(基于几何位置)
// ═══════════════════════════════════════════════
/**
* @brief 根据几何位置查找最近的 edge ID
*
* 遍历所有边,返回其端点中点距离给定点最近的边的 ID。
* 用于 mesh→BrepModel 转换后重新定位拓扑元素。
*
* @param body 输入实体
* @param nearPoint 参考点(通常为 mesh edge 中点)
* @return 最近的边 ID,若 body 无边则返回 -1
*
* @see get_face_index_by_position
*/
[[nodiscard]] int get_edge_index_by_position(const BrepModel& body, const Point3D& nearPoint);
/**
* @brief 根据几何位置查找最近的 face ID
*
* 遍历所有面,返回其边界盒中心距离给定点最近的面 ID。
* 用于 mesh→BrepModel 转换后重新定位拓扑元素。
*
* @param body 输入实体
* @param nearPoint 参考点(通常为 mesh face 中心)
* @return 最近的面 ID,若 body 无面则返回 -1
*
* @see get_edge_index_by_position
*/
[[nodiscard]] int get_face_index_by_position(const BrepModel& body, const Point3D& nearPoint);
/**
* @brief 基于几何位置对边做圆角(VDE-022 方案二)
*
* 自动查找距离 nearPoint 最近的边并对其倒圆角。
* 适用于 mesh→BrepModel 转换后的场景(edge ID 已发生变化)。
*
* @param body 输入实体
* @param nearPoint 参考点(靠近目标边的任意点)
* @param radius 圆角半径
* @return 圆角后的实体(若未找到边则返回原实体)
*
* @see fillet 基于 ID 的圆角
*/
[[nodiscard]] BrepModel fillet_by_position(const BrepModel& body,
const Point3D& nearPoint, double radius);
/**
* @brief 基于几何位置对边做倒角(VDE-022 方案二)
*
* @param body 输入实体
* @param nearPoint 参考点
* @param distance 倒角距离
* @return 倒角后的实体
*
* @see chamfer 基于 ID 的倒角
*/
[[nodiscard]] BrepModel chamfer_by_position(const BrepModel& body,
const Point3D& nearPoint, double distance);
} // namespace vde::brep
+3
View File
@@ -97,6 +97,9 @@ public:
return v >= 0 && w >= 0 && v + w <= 1;
}
/// 用户定义的三角形索引(BVH 构建时自动赋值,默认为 -1 表示未设置)
int id = -1;
private:
std::array<Point3D, 3> v_{};
};
+1
View File
@@ -156,6 +156,7 @@ public:
double t; /**< 沿射线的参数 t */
Triangle3D tri; /**< 命中的三角形 */
Point3D point; /**< 命中点的世界坐标 = origin + t * dir */
int tri_index; /**< 命中三角形在原始数组中的索引 */
};
/**