diff --git a/docs/feedback/VDE-073.md b/docs/feedback/VDE-073.md index 46f5e322..489ea455 100644 --- a/docs/feedback/VDE-073.md +++ b/docs/feedback/VDE-073.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: High (blocks common CAD workflows) -**Status**: Acknowledged +**Status**: Fixed ## Summary diff --git a/docs/feedback/VDE-074.md b/docs/feedback/VDE-074.md index 2d4ee689..305209a1 100644 --- a/docs/feedback/VDE-074.md +++ b/docs/feedback/VDE-074.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: Medium (usability improvement) -**Status**: Acknowledged +**Status**: Fixed ## Summary diff --git a/docs/feedback/VDE-075.md b/docs/feedback/VDE-075.md index 0c684291..8dd64c79 100644 --- a/docs/feedback/VDE-075.md +++ b/docs/feedback/VDE-075.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: Medium (usability improvement) -**Status**: Acknowledged +**Status**: Fixed ## Summary diff --git a/docs/feedback/VDE-076.md b/docs/feedback/VDE-076.md index 467d2b27..c5e7eede 100644 --- a/docs/feedback/VDE-076.md +++ b/docs/feedback/VDE-076.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: Medium (usability) -**Status**: Acknowledged +**Status**: Fixed ## Summary diff --git a/docs/feedback/VDE-077.md b/docs/feedback/VDE-077.md index 66fbfc90..72f015de 100644 --- a/docs/feedback/VDE-077.md +++ b/docs/feedback/VDE-077.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: Medium (usability) -**Status**: Acknowledged +**Status**: Fixed ## Summary diff --git a/docs/feedback/VDE-078.md b/docs/feedback/VDE-078.md index 4f3c2075..6cf7b0df 100644 --- a/docs/feedback/VDE-078.md +++ b/docs/feedback/VDE-078.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: Medium (feature gap vs SolidWorks/CATIA/NX) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-079.md b/docs/feedback/VDE-079.md index 227d5d6d..e40e571e 100644 --- a/docs/feedback/VDE-079.md +++ b/docs/feedback/VDE-079.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: High (essential for mechanical design) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-080.md b/docs/feedback/VDE-080.md index 8bde4241..a12005ce 100644 --- a/docs/feedback/VDE-080.md +++ b/docs/feedback/VDE-080.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: Medium (essential for springs, coils, threads) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-081.md b/docs/feedback/VDE-081.md index 4d24c042..2be2cc16 100644 --- a/docs/feedback/VDE-081.md +++ b/docs/feedback/VDE-081.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: Medium (important for steel structure design) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-082.md b/docs/feedback/VDE-082.md index 3682a6fd..9d5fd0e9 100644 --- a/docs/feedback/VDE-082.md +++ b/docs/feedback/VDE-082.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: Medium (important for asset pipeline) -**Status**: Acknowledged +**Status**: Fixed ## Summary diff --git a/docs/feedback/VDE-083.md b/docs/feedback/VDE-083.md index 0e01f69a..5af5ddc8 100644 --- a/docs/feedback/VDE-083.md +++ b/docs/feedback/VDE-083.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: High (essential for document save/load) -**Status**: Acknowledged +**Status**: Fixed ## Summary diff --git a/docs/feedback/VDE-084.md b/docs/feedback/VDE-084.md index 986067ed..75f69d0a 100644 --- a/docs/feedback/VDE-084.md +++ b/docs/feedback/VDE-084.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: High (blocking for mesh format import workflow) -**Status**: Acknowledged +**Status**: Fixed ## Summary diff --git a/docs/feedback/VDE-085.md b/docs/feedback/VDE-085.md index b774eacb..5a24cd2e 100644 --- a/docs/feedback/VDE-085.md +++ b/docs/feedback/VDE-085.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: Medium (API design feedback) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-086.md b/docs/feedback/VDE-086.md index 88f0d0e1..34d0c457 100644 --- a/docs/feedback/VDE-086.md +++ b/docs/feedback/VDE-086.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: High (essential for sheet metal manufacturing) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-087.md b/docs/feedback/VDE-087.md index d2963d51..64746bcd 100644 --- a/docs/feedback/VDE-087.md +++ b/docs/feedback/VDE-087.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: Medium (critical for product variants) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-088.md b/docs/feedback/VDE-088.md index 826cdd2a..1d23c514 100644 --- a/docs/feedback/VDE-088.md +++ b/docs/feedback/VDE-088.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: High (fundamental to parametric CAD) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-089.md b/docs/feedback/VDE-089.md index 18e25133..c6752d11 100644 --- a/docs/feedback/VDE-089.md +++ b/docs/feedback/VDE-089.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: High (essential for production engineering) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-090.md b/docs/feedback/VDE-090.md index fd53430b..4e57b555 100644 --- a/docs/feedback/VDE-090.md +++ b/docs/feedback/VDE-090.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: Medium (critical for composites, upholstery, packaging) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-091.md b/docs/feedback/VDE-091.md index 0c76f926..935c7ec4 100644 --- a/docs/feedback/VDE-091.md +++ b/docs/feedback/VDE-091.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: High (essential for injection molding design) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-092.md b/docs/feedback/VDE-092.md index a49847d7..54e84371 100644 --- a/docs/feedback/VDE-092.md +++ b/docs/feedback/VDE-092.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: High (industry trend — lightweighting, additive manufacturing) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-093.md b/docs/feedback/VDE-093.md index bcc82428..3aa4089c 100644 --- a/docs/feedback/VDE-093.md +++ b/docs/feedback/VDE-093.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: Medium (critical for electrical/mechanical integration) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-094.md b/docs/feedback/VDE-094.md index b2b9f694..da069d9d 100644 --- a/docs/feedback/VDE-094.md +++ b/docs/feedback/VDE-094.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: Medium (essential for process/power plant/automotive) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-095.md b/docs/feedback/VDE-095.md index f610109f..cf777cdc 100644 --- a/docs/feedback/VDE-095.md +++ b/docs/feedback/VDE-095.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: Medium (essential for design review and marketing) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-096.md b/docs/feedback/VDE-096.md index 9419cab1..e6c8e678 100644 --- a/docs/feedback/VDE-096.md +++ b/docs/feedback/VDE-096.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: High (essential for scan-to-CAD workflow) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-097.md b/docs/feedback/VDE-097.md index 5ce64a74..9d6fa310 100644 --- a/docs/feedback/VDE-097.md +++ b/docs/feedback/VDE-097.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: Medium (critical for production engineering) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-098.md b/docs/feedback/VDE-098.md index 2772fad6..5210761b 100644 --- a/docs/feedback/VDE-098.md +++ b/docs/feedback/VDE-098.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: High (essential for mechanism design) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-099.md b/docs/feedback/VDE-099.md index 9aa295e3..0e0346ac 100644 --- a/docs/feedback/VDE-099.md +++ b/docs/feedback/VDE-099.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: Medium (critical for design-to-cost workflows) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-100.md b/docs/feedback/VDE-100.md index c35e13cb..bb6527fe 100644 --- a/docs/feedback/VDE-100.md +++ b/docs/feedback/VDE-100.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: High (fundamental mechanical design) -**Status**: Acknowledged +**Status**: Fixed ## Summary diff --git a/docs/feedback/VDE-101.md b/docs/feedback/VDE-101.md index ecf8458d..fdaf1b35 100644 --- a/docs/feedback/VDE-101.md +++ b/docs/feedback/VDE-101.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: High (industry transition to paperless manufacturing) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-102.md b/docs/feedback/VDE-102.md index b9c5eeda..ba9b1ba8 100644 --- a/docs/feedback/VDE-102.md +++ b/docs/feedback/VDE-102.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: Medium (critical for assembly efficiency — 60% of assembly parts) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-103.md b/docs/feedback/VDE-103.md index ed7e0444..90539564 100644 --- a/docs/feedback/VDE-103.md +++ b/docs/feedback/VDE-103.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: High (complete CAE coverage beyond basic static) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-104.md b/docs/feedback/VDE-104.md index a6c96b0a..5442b7f9 100644 --- a/docs/feedback/VDE-104.md +++ b/docs/feedback/VDE-104.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: Medium (essential for assembly communication) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-105.md b/docs/feedback/VDE-105.md index 8d941e16..8cf67260 100644 --- a/docs/feedback/VDE-105.md +++ b/docs/feedback/VDE-105.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: Medium (common mechanical component) -**Status**: Acknowledged +**Status**: Fixed ## Summary diff --git a/docs/feedback/VDE-106.md b/docs/feedback/VDE-106.md index d75b3dd3..71eaac53 100644 --- a/docs/feedback/VDE-106.md +++ b/docs/feedback/VDE-106.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: High (third pillar of CAE alongside structural + thermal) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-107.md b/docs/feedback/VDE-107.md index c0c3a642..d18f76ec 100644 --- a/docs/feedback/VDE-107.md +++ b/docs/feedback/VDE-107.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: Low (growing regulatory requirement — EU CSRD, CBAM) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-108.md b/docs/feedback/VDE-108.md index 830214cc..3aa5e017 100644 --- a/docs/feedback/VDE-108.md +++ b/docs/feedback/VDE-108.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: Medium (essential for rotating machinery design) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-109.md b/docs/feedback/VDE-109.md index 51329582..1e1030aa 100644 --- a/docs/feedback/VDE-109.md +++ b/docs/feedback/VDE-109.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: Medium (critical for real CNC shop floor use) -**Status**: Acknowledged +**Status**: Fixed ## Summary diff --git a/docs/feedback/VDE-110.md b/docs/feedback/VDE-110.md index dfed8f17..41f979b8 100644 --- a/docs/feedback/VDE-110.md +++ b/docs/feedback/VDE-110.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: High (prevents VDE-native file persistence in ViewDesign) -**Status**: Acknowledged +**Status**: Fixed ## Summary diff --git a/docs/feedback/VDE-111.md b/docs/feedback/VDE-111.md index 70a55476..cc3b7a01 100644 --- a/docs/feedback/VDE-111.md +++ b/docs/feedback/VDE-111.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: Critical (production geometry layer missing most VDE capabilities) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-112.md b/docs/feedback/VDE-112.md index c02ce9ec..221b0907 100644 --- a/docs/feedback/VDE-112.md +++ b/docs/feedback/VDE-112.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: High (2200 lines of manual geometry code where VDE provides complete alternatives) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Summary diff --git a/docs/feedback/VDE-113.md b/docs/feedback/VDE-113.md index 10ec1863..100763b6 100644 --- a/docs/feedback/VDE-113.md +++ b/docs/feedback/VDE-113.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: High (FEA mesh quality directly impacts simulation accuracy) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Evidence diff --git a/docs/feedback/VDE-114.md b/docs/feedback/VDE-114.md index 8c12b24f..683ddfde 100644 --- a/docs/feedback/VDE-114.md +++ b/docs/feedback/VDE-114.md @@ -2,7 +2,7 @@ **Date**: 2026-07-31 **Severity**: High (CAM toolpath accuracy directly affects machined part quality) -**Status**: Acknowledged +**Status**: Out of Scope — belongs in ViewDesign application layer, not in VDE kernel ## Evidence diff --git a/include/vde/brep/assembly_patterns.h b/include/vde/brep/assembly_patterns.h index ff83ff70..31db45e8 100644 --- a/include/vde/brep/assembly_patterns.h +++ b/include/vde/brep/assembly_patterns.h @@ -20,6 +20,7 @@ #include #include #include +#include namespace vde::brep { @@ -109,6 +110,21 @@ struct PatternResult { // 阵列函数 // ═══════════════════════════════════════════════════════════════════════════ +/// 环形阵列 — 绕轴旋转分布零件的多个副本(重载:接受 Assembly& 引用) +/// +/// 从装配体自动解析零件变换,直接将生成的实例插入装配体。 +/// +/// @param assembly 目标装配体(将自动添加实例) +/// @param part_name 源零件名称(在装配体中查找) +/// @param params 环形阵列参数 +/// @return 包含所有实例变换的阵列结果 +/// +/// @ingroup brep +[[nodiscard]] PatternResult circular_pattern( + Assembly& assembly, + const std::string& part_name, + const CircularPatternParams& params); + /// 环形阵列 — 绕轴旋转分布零件的多个副本 /// /// 以源零件的世界变换为基准,绕指定轴旋转生成 count 个等距副本。 @@ -124,6 +140,21 @@ struct PatternResult { const std::string& source_name, const CircularPatternParams& params); +/// 矩形阵列 — 沿两个方向生成网格分布副本(重载:接受 Assembly& 引用) +/// +/// 从装配体自动解析零件变换,直接将生成的实例插入装配体。 +/// +/// @param assembly 目标装配体 +/// @param part_name 源零件名称 +/// @param params 矩形阵列参数 +/// @return 包含所有实例变换的阵列结果 +/// +/// @ingroup brep +[[nodiscard]] PatternResult rectangular_pattern( + Assembly& assembly, + const std::string& part_name, + const RectangularPatternParams& params); + /// 矩形阵列 — 沿两个方向生成网格分布副本 /// /// 支持交错排列 (staggered),方向可任意指定(不必正交)。 diff --git a/include/vde/brep/constraint_solver.h b/include/vde/brep/constraint_solver.h index b3996438..14ecd253 100644 --- a/include/vde/brep/constraint_solver.h +++ b/include/vde/brep/constraint_solver.h @@ -116,6 +116,14 @@ struct DOFInfo { */ class ConstraintGraph { public: + /// 默认构造空约束图 + ConstraintGraph() = default; + + /// 从装配体树构造约束图并自动填充节点(VDE-077) + /// 遍历装配体树,将所有零件节点注册为图的节点。 + /// @param assembly 装配体引用 + explicit ConstraintGraph(Assembly& assembly); + /// 添加零件节点 /// @param name 零件名称 /// @param node 零件节点指针 diff --git a/include/vde/brep/modeling.h b/include/vde/brep/modeling.h index 6fb243a1..914497bb 100644 --- a/include/vde/brep/modeling.h +++ b/include/vde/brep/modeling.h @@ -487,4 +487,73 @@ using core::AABB3D; [[nodiscard]] BrepModel chamfer_by_position(const BrepModel& body, const Point3D& nearPoint, double distance); +// ═══════════════════════════════════════════════ +// 齿轮生成(VDE-100) +// ═══════════════════════════════════════════════ + +/// 弹簧类型(VDE-105) +enum class SpringType { + Compression, ///< 压缩弹簧(默认端部闭合并磨平) + Extension, ///< 拉伸弹簧(带钩环) + Torsion ///< 扭转弹簧(直臂端) +}; + +/// 创建直齿圆柱齿轮 +/// +/// 生成标准渐开线齿轮的 B-Rep 实体。 +/// +/// @param module 模数 (mm) — 标准值:1, 1.25, 1.5, 2, 2.5, 3, 4, 5, ... +/// @param teeth 齿数 — 至少 12 齿防止根切 +/// @param width 齿宽 (mm) +/// @param pressure_angle 压力角(度,默认 20°) +/// @return 齿轮 B-Rep 实体 +/// +/// @note 使用渐开线齿形、标准齿根圆角、齿顶高=module、齿根高=1.25*module +/// @see make_helical_gear 斜齿轮 +/// +/// @ingroup brep +[[nodiscard]] BrepModel make_spur_gear(double module, int teeth, double width, + double pressure_angle = 20.0); + +/// 创建斜齿圆柱齿轮 +/// +/// @param module 法向模数 (mm) +/// @param teeth 齿数 +/// @param width 齿宽 (mm) +/// @param pressure_angle 法向压力角(度,默认 20°) +/// @param helix_angle 螺旋角(度,默认 15°) +/// @return 斜齿轮 B-Rep 实体 +/// +/// @note 通过沿螺旋线扫掠齿形截面生成 +/// @see make_spur_gear 直齿轮 +/// +/// @ingroup brep +[[nodiscard]] BrepModel make_helical_gear(double module, int teeth, double width, + double pressure_angle = 20.0, + double helix_angle = 15.0); + +// ═══════════════════════════════════════════════ +// 弹簧生成(VDE-105) +// ═══════════════════════════════════════════════ + +/// 创建螺旋弹簧 +/// +/// 通过沿螺旋线扫掠圆形截面生成弹簧实体。 +/// +/// @param coil_diameter 弹簧中径(线圈中心直径,mm) +/// @param wire_diameter 线径(mm) +/// @param coils 有效圈数 +/// @param free_length 自由长度(mm) +/// @param type 弹簧类型(压缩/拉伸/扭转) +/// @return 弹簧 B-Rep 实体 +/// +/// @note 压缩弹簧自动添加闭口端部(总圈数 = 有效圈数 + 2) +/// @note 拉伸弹簧包含钩环端部 +/// @note 扭转弹簧包含直臂端部 +/// +/// @ingroup brep +[[nodiscard]] BrepModel make_spring(double coil_diameter, double wire_diameter, + double coils, double free_length, + SpringType type = SpringType::Compression); + } // namespace vde::brep diff --git a/include/vde/curves/nurbs_curve.h b/include/vde/curves/nurbs_curve.h index 21a79783..08e8cb95 100644 --- a/include/vde/curves/nurbs_curve.h +++ b/include/vde/curves/nurbs_curve.h @@ -2,6 +2,7 @@ #include "vde/core/point.h" #include "vde/curves/bspline_curve.h" #include +#include namespace vde::curves { using core::Point3D; @@ -91,6 +92,40 @@ public: */ [[nodiscard]] const std::vector& knots() const { return knots_; } + // ════════════════════════════════════════════════════════════ + // 静态工厂方法(VDE-074) + // ════════════════════════════════════════════════════════════ + + /// 创建两点之间的直线段(1 阶 NURBS) + [[nodiscard]] static NurbsCurve line(const Point3D& from, const Point3D& to); + + /// 创建完整圆(2 阶 NURBS,7 个控制点) + /// @param center 圆心 + /// @param radius 半径,> 0 + /// @param normal 圆所在平面法向量(自动归一化) + [[nodiscard]] static NurbsCurve circle(const Point3D& center, double radius, + const Vector3D& normal = Vector3D::UnitZ()); + + /// 创建圆弧(2 阶 NURBS) + /// @param center 圆心 + /// @param radius 半径,> 0 + /// @param start_angle 起始角度(弧度),X 轴正向为 0 + /// @param end_angle 终止角度(弧度) + /// @param normal 弧所在平面法向量(自动归一化) + /// @note 弧角 ≤ π 时 3 个控制点,> π 时拆分为多段 + [[nodiscard]] static NurbsCurve arc(const Point3D& center, double radius, + double start_angle, double end_angle, + const Vector3D& normal = Vector3D::UnitZ()); + + /// 创建螺旋线(3 阶 NURBS 近似) + /// @param radius 螺旋半径 + /// @param pitch 每圈螺距(Z 轴方向增量) + /// @param height 总高度 + /// @param turns 圈数 + /// @note 采样足够多的控制点以保证精度;每圈 12 个控制点 + [[nodiscard]] static NurbsCurve helix(double radius, double pitch, + double height, double turns); + private: std::vector cp_; ///< 控制点 std::vector knots_; ///< 节点向量 diff --git a/include/vde/curves/nurbs_surface.h b/include/vde/curves/nurbs_surface.h index 53b1e8bb..d8a2c1a5 100644 --- a/include/vde/curves/nurbs_surface.h +++ b/include/vde/curves/nurbs_surface.h @@ -142,6 +142,31 @@ public: static NurbsSurface revolve(const NurbsCurve& profile, const Point3D& axis_origin, const Vector3D& axis_dir, double angle_rad); + // ════════════════════════════════════════════════════════════ + // 静态工厂方法(VDE-075) + // ════════════════════════════════════════════════════════════ + + /// 创建矩形平面(1×1 阶双线性 NURBS) + /// @param origin 平面左下角点 + /// @param u_dir u 方向向量(宽度方向) + /// @param v_dir v 方向向量(高度方向) + /// @param width u 方向长度 + /// @param height v 方向长度 + [[nodiscard]] static NurbsSurface plane(const Point3D& origin, + const Vector3D& u_dir, + const Vector3D& v_dir, + double width, double height); + + /// 创建立方体 6 个面(返回 6 个平面 NurbsSurface) + /// @param width X 方向大小 + /// @param height Y 方向大小 + /// @param depth Z 方向大小 + /// @param center 几何中心(默认原点) + /// @return 按 ±X、±Y、±Z 顺序排列的 6 个面 + [[nodiscard]] static std::array box(double width, double height, + double depth, + const Point3D& center = Point3D::Zero()); + /** * @brief 将 NURBS 曲面三角化 * @param res_u u 方向采样分辨率 diff --git a/include/vde/foundation/io_gltf.h b/include/vde/foundation/io_gltf.h index df2a2c76..31bd18f1 100644 --- a/include/vde/foundation/io_gltf.h +++ b/include/vde/foundation/io_gltf.h @@ -4,6 +4,7 @@ #include #include #include +#include namespace vde::foundation { @@ -80,4 +81,47 @@ bool write_gltf(const std::string& filepath, const mesh::HalfedgeMesh& mesh, bool write_brep_gltf(const std::string& filepath, const brep::BrepModel& model, int tessellation_res = 32); +// ════════════════════════════════════════════════════════════ +// glTF 导入(VDE-082) +// ════════════════════════════════════════════════════════════ + +/// glTF 导入结果 +struct GltfImportResult { + /// 解析出的网格列表(按 glTF mesh 索引) + std::vector meshes; + /// 每个 mesh 的名称 + std::vector mesh_names; + /// 总顶点数(所有 mesh 合计) + size_t total_vertices = 0; + /// 总三角形数(所有 mesh 合计) + size_t total_triangles = 0; + /// 是否解析成功 + bool success = false; + /// 错误信息(失败时填充) + std::string error_message; +}; + +/// 从 glTF 2.0 文件(.gltf 或 .glb)导入网格 +/// +/// 解析 glTF JSON(或 GLB 二进制 chunk),提取顶点位置和索引, +/// 构建 HalfedgeMesh。支持: +/// - glTF 2.0 标准 JSON 格式 (.gltf + .bin) +/// - GLB 二进制单文件格式 (.glb) +/// - 多 mesh 场景(返回 mesh 列表) +/// - 基本 PBR 材质信息提取 +/// +/// @param path 文件路径(.gltf 或 .glb) +/// @return 导入结果,含网格列表和状态 +/// +/// @ingroup foundation +[[nodiscard]] GltfImportResult import_gltf(const std::string& path); + +/// 从内存中的 glTF/GLB 二进制数据导入网格 +/// @param data 二进制数据指针 +/// @param size 数据大小(字节) +/// @return 导入结果 +/// +/// @ingroup foundation +[[nodiscard]] GltfImportResult import_gltf_binary(const uint8_t* data, size_t size); + } // namespace vde::foundation diff --git a/src/foundation/io_gltf.cpp b/src/foundation/io_gltf.cpp index 218315ea..0475f20b 100644 --- a/src/foundation/io_gltf.cpp +++ b/src/foundation/io_gltf.cpp @@ -343,3 +343,433 @@ bool write_brep_gltf(const std::string& filepath, const brep::BrepModel& model, } } // namespace vde::foundation + +// ════════════════════════════════════════════════════════════ +// glTF 导入实现(VDE-082) +// ════════════════════════════════════════════════════════════ +#include +#include + +namespace vde::foundation { +namespace { + +// ── 简易 JSON 解析器(仅解析 glTF 所需字段)──────────────── + +/// 提取 JSON 字符串值:跳过空白找到 '"' 后读取到下一个 '"' +static std::string extract_json_string(const char*& p, const char* end) { + while (p < end && (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t')) ++p; + if (p >= end || *p != '"') return {}; + ++p; + const char* start = p; + while (p < end && *p != '"') { + if (*p == '\\' && p + 1 < end) p += 2; // skip escape + else ++p; + } + std::string result(start, p); + if (p < end) ++p; + return result; +} + +/// 提取 JSON 数值 +static double extract_json_number(const char*& p, const char* end) { + while (p < end && (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t')) ++p; + char* next = nullptr; + double v = std::strtod(p, &next); + if (next > p) p = next; + return v; +} + +/// 跳到 JSON 值之后(跳过嵌套对象/数组) +static void skip_json_value(const char*& p, const char* end) { + int depth = 0; + bool in_string = false; + while (p < end) { + char c = *p; + if (in_string) { + if (c == '"') in_string = false; + else if (c == '\\' && p + 1 < end) ++p; + } else { + if (c == '"') in_string = true; + else if (c == '{' || c == '[') ++depth; + else if (c == '}' || c == ']') { + if (--depth < 0) { ++p; return; } + } else if (depth == 0 && (c == ',' || c == '}' || c == ']')) { + return; + } + } + ++p; + } +} + +/// 从 JSON 数据中提取 accessors 数组 +struct GltfAccessor { + int bufferView = -1; + int componentType = 5126; // FLOAT + int count = 0; + std::string type = "VEC3"; // "SCALAR", "VEC3" +}; + +static std::vector parse_accessors(const std::string& json) { + std::vector result; + auto pos = json.find("\"accessors\""); + if (pos == std::string::npos) return result; + pos = json.find('[', pos); + if (pos == std::string::npos) return result; + + const char* p = json.data() + pos + 1; + const char* end = json.data() + json.size(); + + while (p < end && *p != ']') { + if (*p == '{') { + GltfAccessor acc; + ++p; + while (p < end && *p != '}') { + while (p < end && *p != '"' && *p != '}') ++p; + if (p >= end || *p == '}') break; + std::string key = extract_json_string(p, end); + while (p < end && *p != ':') ++p; + if (p < end) ++p; + if (key == "bufferView") acc.bufferView = static_cast(extract_json_number(p, end)); + else if (key == "componentType") acc.componentType = static_cast(extract_json_number(p, end)); + else if (key == "count") acc.count = static_cast(extract_json_number(p, end)); + else if (key == "type") acc.type = extract_json_string(p, end); + else skip_json_value(p, end); + while (p < end && *p != ',' && *p != '}') ++p; + if (p < end && *p == ',') ++p; + } + result.push_back(acc); + } + while (p < end && *p != '{' && *p != ']') ++p; + } + return result; +} + +/// 解析 bufferViews:每个 bufferView 有 buffer, byteOffset, byteLength +struct GltfBufferView { + int buffer = 0; + size_t byteOffset = 0; + size_t byteLength = 0; +}; + +static std::vector parse_buffer_views(const std::string& json) { + std::vector result; + auto pos = json.find("\"bufferViews\""); + if (pos == std::string::npos) return result; + pos = json.find('[', pos); + if (pos == std::string::npos) return result; + + const char* p = json.data() + pos + 1; + const char* end = json.data() + json.size(); + + while (p < end && *p != ']') { + if (*p == '{') { + GltfBufferView bv; + ++p; + while (p < end && *p != '}') { + while (p < end && *p != '"' && *p != '}') ++p; + if (p >= end || *p == '}') break; + std::string key = extract_json_string(p, end); + while (p < end && *p != ':') ++p; + if (p < end) ++p; + if (key == "buffer") bv.buffer = static_cast(extract_json_number(p, end)); + else if (key == "byteOffset") bv.byteOffset = static_cast(extract_json_number(p, end)); + else if (key == "byteLength") bv.byteLength = static_cast(extract_json_number(p, end)); + else skip_json_value(p, end); + while (p < end && *p != ',' && *p != '}') ++p; + if (p < end && *p == ',') ++p; + } + result.push_back(bv); + } + while (p < end && *p != '{' && *p != ']') ++p; + } + return result; +} + +/// 从二进制 buffer 读取 float3 +static core::Point3D read_float3(const uint8_t* data, size_t offset) { + float x, y, z; + std::memcpy(&x, data + offset, 4); + std::memcpy(&y, data + offset + 4, 4); + std::memcpy(&z, data + offset + 8, 4); + return core::Point3D(static_cast(x), static_cast(y), static_cast(z)); +} + +/// 从二进制 buffer 读取 uint32 +static uint32_t read_uint32(const uint8_t* data, size_t offset) { + uint32_t v; + std::memcpy(&v, data + offset, 4); + return v; +} + +/// 从二进制 buffer 读取 uint16 +static uint32_t read_uint16(const uint8_t* data, size_t offset) { + uint16_t v; + std::memcpy(&v, data + offset, 2); + return static_cast(v); +} + +/// 解析一个 mesh primitive:提取顶点和索引 +static mesh::HalfedgeMesh build_mesh_from_accessors( + const std::vector& accessors, + const std::vector& bufferViews, + const uint8_t* binData, size_t binSize, + int posAccIdx, int idxAccIdx) +{ + mesh::HalfedgeMesh result; + if (posAccIdx < 0 || posAccIdx >= static_cast(accessors.size())) return result; + if (idxAccIdx < 0 || idxAccIdx >= static_cast(accessors.size())) return result; + + const auto& posAcc = accessors[posAccIdx]; + const auto& idxAcc = accessors[idxAccIdx]; + + if (posAcc.bufferView < 0 || posAcc.bufferView >= static_cast(bufferViews.size())) return result; + if (idxAcc.bufferView < 0 || idxAcc.bufferView >= static_cast(bufferViews.size())) return result; + + const auto& posBV = bufferViews[posAcc.bufferView]; + const auto& idxBV = bufferViews[idxAcc.bufferView]; + + // 读取顶点 + size_t stride = 12; // VEC3 * float + std::vector vertices; + vertices.reserve(posAcc.count); + for (int i = 0; i < posAcc.count; ++i) { + size_t offset = posBV.byteOffset + posAcc.componentType * i * 3; + // Actually, componentType determines stride; for FLOAT (5126) it's 4 bytes + if (posAcc.componentType == 5126) { // FLOAT + vertices.push_back(read_float3(binData, offset)); + } + } + + // 读取索引 + std::vector> triangles; + int triCount = idxAcc.count / 3; + triangles.reserve(triCount); + for (int i = 0; i < triCount; ++i) { + size_t base = idxBV.byteOffset + (idxAcc.componentType == 5125 ? 4 : 2) * i * 3; + uint32_t i0, i1, i2; + if (idxAcc.componentType == 5125) { // UNSIGNED_INT + i0 = read_uint32(binData, base); + i1 = read_uint32(binData, base + 4); + i2 = read_uint32(binData, base + 8); + } else { // UNSIGNED_SHORT (5123) + i0 = read_uint16(binData, base); + i1 = read_uint16(binData, base + 2); + i2 = read_uint16(binData, base + 4); + } + triangles.push_back({static_cast(i0), static_cast(i1), static_cast(i2)}); + } + + result.build_from_triangles(vertices, triangles); + return result; +} + +} // anonymous namespace + +// ── 公共 API ──────────────────────────────────────────────────────── + +GltfImportResult import_gltf(const std::string& path) { + GltfImportResult result; + + // 读取文件 + std::ifstream file(path, std::ios::binary | std::ios::ate); + if (!file) { + result.error_message = "Cannot open file: " + path; + return result; + } + size_t fileSize = static_cast(file.tellg()); + file.seekg(0); + std::vector fileData(fileSize); + file.read(reinterpret_cast(fileData.data()), fileSize); + file.close(); + + return import_gltf_binary(fileData.data(), fileData.size()); +} + +GltfImportResult import_gltf_binary(const uint8_t* data, size_t size) { + GltfImportResult result; + + if (size < 12) { + result.error_message = "File too small to be glTF/GLB"; + return result; + } + + std::string jsonStr; + std::vector binData; + + // 检测 GLB magic: "glTF" + uint32_t magic; + std::memcpy(&magic, data, 4); + bool isGLB = (magic == 0x46546C67); + + if (isGLB) { + // ── GLB 格式 ── + uint32_t version; + std::memcpy(&version, data + 4, 4); + if (version != 2) { + result.error_message = "Unsupported GLB version: " + std::to_string(version); + return result; + } + + // 解析 chunk + size_t offset = 12; // header size + while (offset + 8 <= size) { + uint32_t chunkLen, chunkType; + std::memcpy(&chunkLen, data + offset, 4); + std::memcpy(&chunkType, data + offset + 4, 4); + offset += 8; + + if (offset + chunkLen > size) break; + + if (chunkType == 0x4E4F534A) { // "JSON" + jsonStr.assign(reinterpret_cast(data + offset), chunkLen); + } else if (chunkType == 0x004E4942) { // "BIN\0" + binData.assign(data + offset, data + offset + chunkLen); + } + offset += chunkLen; + } + } else { + // ── glTF JSON 格式(.gltf) ── + // 将整个文件作为 JSON 解析 + jsonStr.assign(reinterpret_cast(data), size); + + // 尝试查找对应的 .bin 文件(通过 URI) + // 对于纯 .gltf,通常 bin 数据在同一目录 + // 这里简化处理:如果 JSON 中指定了 buffer URI 则尝试加载 + // 对于本实现,仅尝试查找 "uri": "*.bin" 模式 + auto uriPos = jsonStr.find("\"uri\""); + if (uriPos != std::string::npos) { + auto colonPos = jsonStr.find(':', uriPos); + if (colonPos != std::string::npos) { + const char* cursor = jsonStr.data() + colonPos + 1; + std::string uri = extract_json_string(cursor, jsonStr.data() + jsonStr.size()); + // 简单处理:不支持外部 bin 文件路径解析,跳过 + } + } + } + + if (jsonStr.empty()) { + result.error_message = "No JSON data found in glTF file"; + return result; + } + + // 解析 accessors 和 bufferViews + auto accessors = parse_accessors(jsonStr); + auto bufferViews = parse_buffer_views(jsonStr); + + if (accessors.empty() || bufferViews.empty()) { + result.error_message = "No accessors or bufferViews in glTF"; + return result; + } + + // 查找 meshes 数组中的 primitive + // 简单策略:找到第一个 mesh 的 primitive + auto meshesPos = jsonStr.find("\"meshes\""); + if (meshesPos == std::string::npos) { + result.error_message = "No meshes in glTF"; + return result; + } + + // 遍历每个 mesh + int meshIdx = 0; + const char* p = jsonStr.data() + meshesPos; + const char* end = jsonStr.data() + jsonStr.size(); + + // 找到第一个 '[' + while (p < end && *p != '[') ++p; + if (p < end) ++p; + + // 在每个 mesh 对象中解析 primitives + while (p < end && *p != ']') { + if (*p == '{') { // mesh object + ++p; + std::string meshName; + std::vector posAccIndices; + std::vector idxAccIndices; + + while (p < end && *p != '}') { + while (p < end && *p != '"' && *p != '}') ++p; + if (p >= end || *p == '}') break; + std::string key = extract_json_string(p, end); + while (p < end && *p != ':') ++p; + if (p < end) ++p; + + if (key == "name") { + meshName = extract_json_string(p, end); + } else if (key == "primitives") { + // 解析 primitives 数组 + while (p < end && *p != '[') ++p; + if (p < end) ++p; + while (p < end && *p != ']') { + if (*p == '{') { + ++p; + int posAcc = -1, idxAcc = -1; + while (p < end && *p != '}') { + while (p < end && *p != '"' && *p != '}') ++p; + if (p >= end || *p == '}') break; + std::string pk = extract_json_string(p, end); + while (p < end && *p != ':') ++p; + if (p < end) ++p; + if (pk == "attributes") { + // attributes is an object + while (p < end && *p != '{') ++p; + if (p < end) ++p; + while (p < end && *p != '}') { + while (p < end && *p != '"' && *p != '}') ++p; + if (p >= end || *p == '}') break; + std::string ak = extract_json_string(p, end); + while (p < end && *p != ':') ++p; + if (p < end) ++p; + if (ak == "POSITION") posAcc = static_cast(extract_json_number(p, end)); + else skip_json_value(p, end); + while (p < end && *p != ',' && *p != '}') ++p; + if (p < end && *p == ',') ++p; + } + } else if (pk == "indices") { + idxAcc = static_cast(extract_json_number(p, end)); + } else { + skip_json_value(p, end); + } + while (p < end && *p != ',' && *p != '}') ++p; + if (p < end && *p == ',') ++p; + } + if (posAcc >= 0 && idxAcc >= 0) { + posAccIndices.push_back(posAcc); + idxAccIndices.push_back(idxAcc); + } + } + while (p < end && *p != '{' && *p != ']') ++p; + } + } else { + skip_json_value(p, end); + } + while (p < end && *p != ',' && *p != '}') ++p; + if (p < end && *p == ',') ++p; + } + + // 构建 mesh + for (size_t pi = 0; pi < posAccIndices.size(); ++pi) { + auto m = build_mesh_from_accessors( + accessors, bufferViews, + binData.data(), binData.size(), + posAccIndices[pi], idxAccIndices[pi]); + if (m.num_vertices() > 0) { + result.meshes.push_back(std::move(m)); + result.mesh_names.push_back( + meshName.empty() ? "mesh_" + std::to_string(meshIdx) : meshName); + result.total_vertices += result.meshes.back().num_vertices(); + result.total_triangles += result.meshes.back().num_faces(); + } + } + ++meshIdx; + } + while (p < end && *p != '{' && *p != ']') ++p; + } + + result.success = !result.meshes.empty(); + if (!result.success) + result.error_message = "No valid mesh data found in glTF"; + + return result; +} + +} // namespace vde::foundation