@faicad/faijs-gears 0.0.0-stage → 0.29.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/dist/bevel_gear.d.ts +113 -0
- package/dist/bevel_gear.d.ts.map +1 -0
- package/dist/bevel_gear.js +327 -0
- package/dist/bevel_gear.js.map +1 -0
- package/dist/crossed_helical_gear.d.ts +24 -0
- package/dist/crossed_helical_gear.d.ts.map +1 -0
- package/dist/crossed_helical_gear.js +24 -0
- package/dist/crossed_helical_gear.js.map +1 -0
- package/dist/crossed_pair.d.ts +177 -0
- package/dist/crossed_pair.d.ts.map +1 -0
- package/dist/crossed_pair.js +237 -0
- package/dist/crossed_pair.js.map +1 -0
- package/dist/features.d.ts +184 -0
- package/dist/features.d.ts.map +1 -0
- package/dist/features.js +408 -0
- package/dist/features.js.map +1 -0
- package/dist/index.d.ts +178 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +223 -0
- package/dist/index.js.map +1 -0
- package/dist/kernel/gears.d.ts +231 -0
- package/dist/kernel/gears.d.ts.map +1 -0
- package/dist/kernel/gears.js +274 -0
- package/dist/kernel/gears.js.map +1 -0
- package/dist/kernel/index.d.ts +10 -0
- package/dist/kernel/index.d.ts.map +1 -0
- package/dist/kernel/index.js +9 -0
- package/dist/kernel/index.js.map +1 -0
- package/dist/math.d.ts +200 -0
- package/dist/math.d.ts.map +1 -0
- package/dist/math.js +274 -0
- package/dist/math.js.map +1 -0
- package/dist/pairs.d.ts +161 -0
- package/dist/pairs.d.ts.map +1 -0
- package/dist/pairs.js +183 -0
- package/dist/pairs.js.map +1 -0
- package/dist/planetary.d.ts +96 -0
- package/dist/planetary.d.ts.map +1 -0
- package/dist/planetary.js +139 -0
- package/dist/planetary.js.map +1 -0
- package/dist/profile.d.ts +439 -0
- package/dist/profile.d.ts.map +1 -0
- package/dist/profile.js +597 -0
- package/dist/profile.js.map +1 -0
- package/dist/rack_gear.d.ts +125 -0
- package/dist/rack_gear.d.ts.map +1 -0
- package/dist/rack_gear.js +344 -0
- package/dist/rack_gear.js.map +1 -0
- package/dist/ring_gear.d.ts +54 -0
- package/dist/ring_gear.d.ts.map +1 -0
- package/dist/ring_gear.js +133 -0
- package/dist/ring_gear.js.map +1 -0
- package/dist/spline-face.d.ts +99 -0
- package/dist/spline-face.d.ts.map +1 -0
- package/dist/spline-face.js +94 -0
- package/dist/spline-face.js.map +1 -0
- package/dist/spur_gear.d.ts +112 -0
- package/dist/spur_gear.d.ts.map +1 -0
- package/dist/spur_gear.js +206 -0
- package/dist/spur_gear.js.map +1 -0
- package/dist/worm_gear.d.ts +78 -0
- package/dist/worm_gear.d.ts.map +1 -0
- package/dist/worm_gear.js +256 -0
- package/dist/worm_gear.js.map +1 -0
- package/package.json +49 -4
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bevel_gear — BevelGear 锥齿轮实体构造
|
|
3
|
+
*
|
|
4
|
+
* 对应 cq_gears `bevel_gear.py::BevelGear`(`_build_tooth_faces` / `_build_gear_faces`
|
|
5
|
+
* / `_trim_bottom` / `_trim_top` / `_make_bore` / `_build`):
|
|
6
|
+
*
|
|
7
|
+
* ```
|
|
8
|
+
* ① 球面齿廓(单位球面,`profile.ts::bevelGearGeometry`)× 每行锥距 r
|
|
9
|
+
* → 4 段 × surf_splines 行点阵 → `Face.makeSplineApprox` → 4 张齿面
|
|
10
|
+
* ② 每张齿面用两个 z=const 平面 `face.split` 裁顶(z=tc_h,取 zmax 最大片)
|
|
11
|
+
* 与裁底(z=pc_h,取 zmax 最小片)
|
|
12
|
+
* ③ 每张齿面绕 Z 转 tau·i(i = 0..z-1)→ 4z 张面;再补 z=tc_h / z=pc_h 两个端盖
|
|
13
|
+
* ④ sew(shell_sewing_tol) → makeSolid → fixFaceOrientations
|
|
14
|
+
* ⑤ `_trim_bottom`/`_trim_top`:XZ 平面轮廓绕 **Z** 回转 360° 的 cutter 布尔差
|
|
15
|
+
* ⑥ 重定向(绕 X 转 180° → 沿 Z 平移 cone_h → 绕 Z 转 t_align_angle)
|
|
16
|
+
* ⑦ `_make_bore`:沿 Z 贯穿圆柱差
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* 与 Python 的差异(有意为之,几何等价):
|
|
20
|
+
* - 端盖的边界边不用 cq 的 `edges('<Z')` 极值选择器(按**边的质心**聚类,容差 1e-4),
|
|
21
|
+
* 而用**解析平面**判定:两条裁切边分别精确落在 z = tc_h / z = pc_h 上,
|
|
22
|
+
* 按「边上采样点全部落在该平面 ±1e-6」收集,选出的边集与极值选择器一致且更稳。
|
|
23
|
+
* - `Wire.combine(...)` 用 `geom-build.ts::connectEdgesToWires` 复刻(同 `wire_comb_tol`)。
|
|
24
|
+
*
|
|
25
|
+
* ⚠️ `cq.Workplane('XZ')` 的局部坐标 (u, v) → 世界 (u, 0, v),其法向为 **−Y**;
|
|
26
|
+
* `revolve()` 缺省轴 = 工作面原点沿法向 → 即**全局 Z 轴**。故回转体一律绕 Z。
|
|
27
|
+
*/
|
|
28
|
+
import type { BrepHandle } from '@faicad/faijs';
|
|
29
|
+
import type { GearKernel } from './kernel/index.js';
|
|
30
|
+
import { type BevelGearGeometry, type BevelGearParams } from './profile.js';
|
|
31
|
+
import { type SplineFaceOptions, type SplineFaceStrategy } from './spline-face.js';
|
|
32
|
+
/** BevelGear 实体构造选项。 */
|
|
33
|
+
export interface BuildBevelGearOptions extends SplineFaceOptions {
|
|
34
|
+
strategy?: SplineFaceStrategy;
|
|
35
|
+
/** 缝合容差(cq `shell_sewing_tol`,GearBase 默认 1e-2)。 */
|
|
36
|
+
shellSewingTol?: number;
|
|
37
|
+
/** 组线容差(cq `wire_comb_tol`,GearBase 默认 1e-2)。 */
|
|
38
|
+
wireCombTol?: number;
|
|
39
|
+
/** 轴孔直径(沿 Z 贯穿,`BevelGear._make_bore`)。 */
|
|
40
|
+
boreD?: number;
|
|
41
|
+
/** 是否裁底(cq `trim_bottom`,默认 true)。 */
|
|
42
|
+
trimBottom?: boolean;
|
|
43
|
+
/** 是否裁顶(cq `trim_top`,默认 true)。 */
|
|
44
|
+
trimTop?: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* ①+②:4 张齿面(每张已按 z = tc_h / z = pc_h 裁顶裁底)。
|
|
48
|
+
*
|
|
49
|
+
* 复刻 `_build_tooth_faces`:行参数 `spline_tf = linspace((pc_f, ta1), (tc_f − 0.01, ta2), n)`
|
|
50
|
+
* 给出每行的锥距 `r` 与扭转角 `a`,行点 = 「单位球面齿廓 @ rotation_matrix(轴 Z, a)」× r。
|
|
51
|
+
*
|
|
52
|
+
* @param kernel 原始 OCCT 内核
|
|
53
|
+
* @param geom 锥齿轮几何量
|
|
54
|
+
* @param strategy 齿面建面策略
|
|
55
|
+
* @param options 容差/次数选项
|
|
56
|
+
* @returns 4 张裁切后的齿面
|
|
57
|
+
*/
|
|
58
|
+
export declare function buildBevelToothFaces(kernel: GearKernel, geom: BevelGearGeometry, strategy: SplineFaceStrategy, options?: SplineFaceOptions): BrepHandle[];
|
|
59
|
+
/**
|
|
60
|
+
* 收集落在 z 平面上的边界边并组成一个平面端盖。
|
|
61
|
+
*
|
|
62
|
+
* 对应 `_build_gear_faces` 里的 `wp.edges('<Z')` / `wp.edges('>Z')` + `Wire.combine`
|
|
63
|
+
* + `Face.makeFromWires`。判据用「边上采样点全部落在该平面 ±PLANE_PICK_TOL」——
|
|
64
|
+
* 两条裁切边是 split 产生的、精确落在 z = tc_h / z = pc_h 上,故与极值选择器等价。
|
|
65
|
+
*
|
|
66
|
+
* @param kernel 原始 OCCT 内核
|
|
67
|
+
* @param faces 全部齿面
|
|
68
|
+
* @param z 目标平面高度
|
|
69
|
+
* @param wireCombTol 组线容差
|
|
70
|
+
* @returns 平面端盖
|
|
71
|
+
*/
|
|
72
|
+
export declare function capBevelAtZ(kernel: GearKernel, faces: BrepHandle[], z: number, wireCombTol?: number): BrepHandle;
|
|
73
|
+
/**
|
|
74
|
+
* ③:全部面(4z 张齿面 + 顶/底两个端盖)。
|
|
75
|
+
*
|
|
76
|
+
* 复刻 `_build_gear_faces`:每张齿面绕 Z 转 tau·i,然后按 `edges('<Z')`(z 最小 = tc_h)
|
|
77
|
+
* 与 `edges('>Z')`(z 最大 = pc_h)组线成端盖。
|
|
78
|
+
*
|
|
79
|
+
* @param kernel 原始 OCCT 内核
|
|
80
|
+
* @param geom 锥齿轮几何量
|
|
81
|
+
* @param strategy 齿面建面策略
|
|
82
|
+
* @param options 容差/次数选项
|
|
83
|
+
* @returns 全部面(含两端盖)
|
|
84
|
+
*/
|
|
85
|
+
export declare function buildBevelGearFaces(kernel: GearKernel, geom: BevelGearGeometry, strategy: SplineFaceStrategy, options?: BuildBevelGearOptions): BrepHandle[];
|
|
86
|
+
/**
|
|
87
|
+
* 复刻 `BevelGear._trim_bottom`:半径 gs_r 上的三点圆弧轮廓绕 Z 回转成 cutter,
|
|
88
|
+
* 再从实体上布尔差。
|
|
89
|
+
*
|
|
90
|
+
* @param kernel 原始 OCCT 内核
|
|
91
|
+
* @param geom 锥齿轮几何量
|
|
92
|
+
* @returns cutter(旋转体)
|
|
93
|
+
*/
|
|
94
|
+
export declare function makeTrimBottomCutter(kernel: GearKernel, geom: BevelGearGeometry): BrepHandle;
|
|
95
|
+
/**
|
|
96
|
+
* 复刻 `BevelGear._trim_top`:半径 gs_r − face_width 上的圆弧轮廓(内边界落在轴上)
|
|
97
|
+
* 绕 Z 回转成 cutter,再从实体上布尔差。
|
|
98
|
+
*
|
|
99
|
+
* @param kernel 原始 OCCT 内核
|
|
100
|
+
* @param geom 锥齿轮几何量
|
|
101
|
+
* @returns cutter(旋转体)
|
|
102
|
+
*/
|
|
103
|
+
export declare function makeTrimTopCutter(kernel: GearKernel, geom: BevelGearGeometry): BrepHandle;
|
|
104
|
+
/**
|
|
105
|
+
* ①–⑦:完整 BevelGear 实体。
|
|
106
|
+
*
|
|
107
|
+
* @param kernel 原始 OCCT 内核
|
|
108
|
+
* @param params 锥齿轮参数(逐字沿用 Python 构造参数名)
|
|
109
|
+
* @param build 构造选项(策略/容差/裁切/轴孔)
|
|
110
|
+
* @returns 朝向归一化(齿轮轴 = +Z、底面 z = 0)后的 solid
|
|
111
|
+
*/
|
|
112
|
+
export declare function buildBevelGearSolid(kernel: GearKernel, params: BevelGearParams, build?: BuildBevelGearOptions): BrepHandle;
|
|
113
|
+
//# sourceMappingURL=bevel_gear.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bevel_gear.d.ts","sourceRoot":"","sources":["../src/bevel_gear.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAY,MAAM,eAAe,CAAA;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAC1C,OAAO,EAEL,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAC7C,MAAM,WAAW,CAAA;AAElB,OAAO,EAEL,KAAK,iBAAiB,EAAE,KAAK,kBAAkB,EAChD,MAAM,eAAe,CAAA;AAqBtB,wBAAwB;AACxB,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC9D,QAAQ,CAAC,EAAE,kBAAkB,CAAA;IAC7B,oDAAoD;IACpD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,2CAA2C;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,sCAAsC;IACtC,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,mCAAmC;IACnC,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AA2ED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,iBAAiB,EACvB,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,GAAE,iBAAsB,GAC9B,UAAU,EAAE,CAgCd;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,UAAU,EAAE,EACnB,CAAC,EAAE,MAAM,EACT,WAAW,GAAE,MAA0C,GACtD,UAAU,CA2BZ;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,iBAAiB,EACvB,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,GAAE,qBAA0B,GAClC,UAAU,EAAE,CAed;AAmBD;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,iBAAiB,GAC1C,UAAU,CAYZ;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,iBAAiB,GAC1C,UAAU,CAWZ;AAeD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,eAAe,EACvB,KAAK,GAAE,qBAA0B,GAChC,UAAU,CAiDZ"}
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bevel_gear — BevelGear 锥齿轮实体构造
|
|
3
|
+
*
|
|
4
|
+
* 对应 cq_gears `bevel_gear.py::BevelGear`(`_build_tooth_faces` / `_build_gear_faces`
|
|
5
|
+
* / `_trim_bottom` / `_trim_top` / `_make_bore` / `_build`):
|
|
6
|
+
*
|
|
7
|
+
* ```
|
|
8
|
+
* ① 球面齿廓(单位球面,`profile.ts::bevelGearGeometry`)× 每行锥距 r
|
|
9
|
+
* → 4 段 × surf_splines 行点阵 → `Face.makeSplineApprox` → 4 张齿面
|
|
10
|
+
* ② 每张齿面用两个 z=const 平面 `face.split` 裁顶(z=tc_h,取 zmax 最大片)
|
|
11
|
+
* 与裁底(z=pc_h,取 zmax 最小片)
|
|
12
|
+
* ③ 每张齿面绕 Z 转 tau·i(i = 0..z-1)→ 4z 张面;再补 z=tc_h / z=pc_h 两个端盖
|
|
13
|
+
* ④ sew(shell_sewing_tol) → makeSolid → fixFaceOrientations
|
|
14
|
+
* ⑤ `_trim_bottom`/`_trim_top`:XZ 平面轮廓绕 **Z** 回转 360° 的 cutter 布尔差
|
|
15
|
+
* ⑥ 重定向(绕 X 转 180° → 沿 Z 平移 cone_h → 绕 Z 转 t_align_angle)
|
|
16
|
+
* ⑦ `_make_bore`:沿 Z 贯穿圆柱差
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* 与 Python 的差异(有意为之,几何等价):
|
|
20
|
+
* - 端盖的边界边不用 cq 的 `edges('<Z')` 极值选择器(按**边的质心**聚类,容差 1e-4),
|
|
21
|
+
* 而用**解析平面**判定:两条裁切边分别精确落在 z = tc_h / z = pc_h 上,
|
|
22
|
+
* 按「边上采样点全部落在该平面 ±1e-6」收集,选出的边集与极值选择器一致且更稳。
|
|
23
|
+
* - `Wire.combine(...)` 用 `geom-build.ts::connectEdgesToWires` 复刻(同 `wire_comb_tol`)。
|
|
24
|
+
*
|
|
25
|
+
* ⚠️ `cq.Workplane('XZ')` 的局部坐标 (u, v) → 世界 (u, 0, v),其法向为 **−Y**;
|
|
26
|
+
* `revolve()` 缺省轴 = 工作面原点沿法向 → 即**全局 Z 轴**。故回转体一律绕 Z。
|
|
27
|
+
*/
|
|
28
|
+
import { GEAR_BASE_CONSTANTS, bevelGearGeometry, } from './profile.js';
|
|
29
|
+
import { linspace, rotateRows, sphereToCartesian } from './math.js';
|
|
30
|
+
import { buildSplineFace, DEFAULT_SPLINE_FACE_STRATEGY, } from './spline-face.js';
|
|
31
|
+
import { connectEdgesToWires } from './kernel/index.js';
|
|
32
|
+
/** 判定「边上所有采样点是否落在 z 平面内」的容差(mm)。 */
|
|
33
|
+
const PLANE_PICK_TOL = 1e-6;
|
|
34
|
+
/** `_make_bore` 的贯穿余量(与 features.ts 的 CHAMFER_E 同量级)。 */
|
|
35
|
+
const BORE_E = 0.01;
|
|
36
|
+
/** 齿廓 4 段(顺序与 Python `_build_tooth_faces` 的循环一致)。 */
|
|
37
|
+
const BEVEL_SEGMENTS = ['lflank', 'tip', 'rflank', 'root'];
|
|
38
|
+
function segmentPoints(geom, seg) {
|
|
39
|
+
switch (seg) {
|
|
40
|
+
case 'lflank': return geom.t_lflank_pts;
|
|
41
|
+
case 'tip': return geom.t_tip_pts;
|
|
42
|
+
case 'rflank': return geom.t_rflank_pts;
|
|
43
|
+
case 'root': return geom.t_root_pts;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function faceFrames(geom) {
|
|
47
|
+
const pcH = Math.cos(geom.gammaR) * geom.gsR;
|
|
48
|
+
const pcF = pcH / Math.cos(geom.gammaF);
|
|
49
|
+
const tcH = Math.cos(geom.gammaF) * (geom.gsR - geom.faceWidth);
|
|
50
|
+
const tcF = tcH / Math.cos(geom.gammaR);
|
|
51
|
+
return {
|
|
52
|
+
pcH, pcF,
|
|
53
|
+
pcRB: pcF * Math.sin(geom.gammaF),
|
|
54
|
+
tcH, tcF,
|
|
55
|
+
tcRB: tcF * Math.sin(geom.gammaF),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** z = const、边长 `size` 的正方形平面(cq `Face.makePlane(length=size, width=size)` 的等价物)。 */
|
|
59
|
+
function squarePlaneAtZ(kernel, z, size) {
|
|
60
|
+
const half = size / 2;
|
|
61
|
+
const c = [
|
|
62
|
+
{ x: -half, y: -half, z },
|
|
63
|
+
{ x: half, y: -half, z },
|
|
64
|
+
{ x: half, y: half, z },
|
|
65
|
+
{ x: -half, y: half, z },
|
|
66
|
+
];
|
|
67
|
+
const edges = c.map((p, i) => kernel.makeLineEdge(p, c[(i + 1) % 4]));
|
|
68
|
+
return kernel.makeFace(kernel.makeWire(edges));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 复刻 cq `Face.split(plane)` + 「按 zmax 取片」的选择规则。
|
|
72
|
+
*
|
|
73
|
+
* cq 侧:`cpd = face.split(plane)`,若返回 Compound 则取 `max/min(list(cpd), key=zmax)`,
|
|
74
|
+
* 否则(平面没切到面)直接用原面。内核的 `split` 同样在「没切到」时原样返回该面。
|
|
75
|
+
*
|
|
76
|
+
* @param which `'top'` 取 zmax 最大的片(裁顶)、`'bottom'` 取 zmax 最小的片(裁底)
|
|
77
|
+
* @returns 保留的那一片
|
|
78
|
+
*/
|
|
79
|
+
function splitFaceKeep(kernel, face, plane, which) {
|
|
80
|
+
const res = kernel.split(face, [plane]);
|
|
81
|
+
if (kernel.isFace(res))
|
|
82
|
+
return res;
|
|
83
|
+
const pieces = kernel.getSubShapes(res, 'face');
|
|
84
|
+
if (pieces.length === 0) {
|
|
85
|
+
throw new Error(`splitFaceKeep: split produced no face fragment (which=${which})`);
|
|
86
|
+
}
|
|
87
|
+
if (pieces.length === 1)
|
|
88
|
+
return pieces[0];
|
|
89
|
+
let best = pieces[0];
|
|
90
|
+
let bestZ = which === 'top' ? -Infinity : Infinity;
|
|
91
|
+
for (const p of pieces) {
|
|
92
|
+
const z = kernel.getBoundingBox(p).zmax;
|
|
93
|
+
if (which === 'top' ? z > bestZ : z < bestZ) {
|
|
94
|
+
bestZ = z;
|
|
95
|
+
best = p;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return best;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* ①+②:4 张齿面(每张已按 z = tc_h / z = pc_h 裁顶裁底)。
|
|
102
|
+
*
|
|
103
|
+
* 复刻 `_build_tooth_faces`:行参数 `spline_tf = linspace((pc_f, ta1), (tc_f − 0.01, ta2), n)`
|
|
104
|
+
* 给出每行的锥距 `r` 与扭转角 `a`,行点 = 「单位球面齿廓 @ rotation_matrix(轴 Z, a)」× r。
|
|
105
|
+
*
|
|
106
|
+
* @param kernel 原始 OCCT 内核
|
|
107
|
+
* @param geom 锥齿轮几何量
|
|
108
|
+
* @param strategy 齿面建面策略
|
|
109
|
+
* @param options 容差/次数选项
|
|
110
|
+
* @returns 4 张裁切后的齿面
|
|
111
|
+
*/
|
|
112
|
+
export function buildBevelToothFaces(kernel, geom, strategy, options = {}) {
|
|
113
|
+
const f = faceFrames(geom);
|
|
114
|
+
// 起止扭转角
|
|
115
|
+
const ta1 = (-(f.pcF - geom.gsR) / geom.faceWidth) * geom.twistAngle;
|
|
116
|
+
const ta2 = ((geom.gsR - f.tcF) / geom.faceWidth) * geom.twistAngle;
|
|
117
|
+
const surfSplines = Math.max(1, Math.ceil(Math.abs(geom.twistAngle) / (Math.PI * 2)))
|
|
118
|
+
* geom.surfaceSplines;
|
|
119
|
+
// np.linspace((pc_f, ta1), (tc_f - 0.01, ta2), surf_splines)
|
|
120
|
+
const rs = linspace(f.pcF, f.tcF - 0.01, surfSplines);
|
|
121
|
+
const as = linspace(ta1, ta2, surfSplines);
|
|
122
|
+
// cq 的裁切平面比齿面大 1000 倍(tcp_size = tc_rb·1000),照抄保证平面完全覆盖面。
|
|
123
|
+
const topPlane = squarePlaneAtZ(kernel, f.tcH, f.tcRB * 1000);
|
|
124
|
+
const bottomPlane = squarePlaneAtZ(kernel, f.pcH, f.pcRB * 1000);
|
|
125
|
+
const tFaces = [];
|
|
126
|
+
for (const seg of BEVEL_SEGMENTS) {
|
|
127
|
+
const spline = segmentPoints(geom, seg);
|
|
128
|
+
const rows = rs.map((r, i) => {
|
|
129
|
+
const rotated = rotateRows(spline, { x: 0, y: 0, z: 1 }, as[i]);
|
|
130
|
+
return rotated.map((p) => ({ x: p.x * r, y: p.y * r, z: p.z * r }));
|
|
131
|
+
});
|
|
132
|
+
const grid = { segment: seg, rows: rows.length, cols: rows[0].length, points: rows };
|
|
133
|
+
let face = buildSplineFace(kernel, grid, strategy, options);
|
|
134
|
+
face = splitFaceKeep(kernel, face, topPlane, 'top');
|
|
135
|
+
face = splitFaceKeep(kernel, face, bottomPlane, 'bottom');
|
|
136
|
+
tFaces.push(face);
|
|
137
|
+
}
|
|
138
|
+
return tFaces;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* 收集落在 z 平面上的边界边并组成一个平面端盖。
|
|
142
|
+
*
|
|
143
|
+
* 对应 `_build_gear_faces` 里的 `wp.edges('<Z')` / `wp.edges('>Z')` + `Wire.combine`
|
|
144
|
+
* + `Face.makeFromWires`。判据用「边上采样点全部落在该平面 ±PLANE_PICK_TOL」——
|
|
145
|
+
* 两条裁切边是 split 产生的、精确落在 z = tc_h / z = pc_h 上,故与极值选择器等价。
|
|
146
|
+
*
|
|
147
|
+
* @param kernel 原始 OCCT 内核
|
|
148
|
+
* @param faces 全部齿面
|
|
149
|
+
* @param z 目标平面高度
|
|
150
|
+
* @param wireCombTol 组线容差
|
|
151
|
+
* @returns 平面端盖
|
|
152
|
+
*/
|
|
153
|
+
export function capBevelAtZ(kernel, faces, z, wireCombTol = GEAR_BASE_CONSTANTS.wire_comb_tol) {
|
|
154
|
+
const edges = [];
|
|
155
|
+
for (const f of faces) {
|
|
156
|
+
for (const e of kernel.getSubShapes(f, 'edge')) {
|
|
157
|
+
const { first, last } = kernel.curveParameters(e);
|
|
158
|
+
const samples = [first, (first + last) / 2, last].map((t) => kernel.curvePointAtParam(e, t));
|
|
159
|
+
if (samples.every((p) => Math.abs(p.z - z) <= PLANE_PICK_TOL))
|
|
160
|
+
edges.push(e);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (edges.length === 0) {
|
|
164
|
+
throw new Error(`capBevelAtZ: no boundary edges found on plane z=${z}`);
|
|
165
|
+
}
|
|
166
|
+
const wires = connectEdgesToWires(kernel, edges, wireCombTol);
|
|
167
|
+
if (wires.length === 0) {
|
|
168
|
+
throw new Error(`capBevelAtZ: no closed loop on z=${z} from ${edges.length} edges`);
|
|
169
|
+
}
|
|
170
|
+
// 接缝处可能产生小碎环(多于一条 wire);取 bbox 面积最大的那条(真实端面边界)。
|
|
171
|
+
let cap = wires[0];
|
|
172
|
+
if (wires.length > 1) {
|
|
173
|
+
let bestArea = -1;
|
|
174
|
+
for (const w of wires) {
|
|
175
|
+
const bb = kernel.getBoundingBox(w);
|
|
176
|
+
const area = (bb.xmax - bb.xmin) * (bb.ymax - bb.ymin);
|
|
177
|
+
if (area > bestArea) {
|
|
178
|
+
bestArea = area;
|
|
179
|
+
cap = w;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return kernel.makeFace(kernel.healWire(cap, wireCombTol));
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* ③:全部面(4z 张齿面 + 顶/底两个端盖)。
|
|
187
|
+
*
|
|
188
|
+
* 复刻 `_build_gear_faces`:每张齿面绕 Z 转 tau·i,然后按 `edges('<Z')`(z 最小 = tc_h)
|
|
189
|
+
* 与 `edges('>Z')`(z 最大 = pc_h)组线成端盖。
|
|
190
|
+
*
|
|
191
|
+
* @param kernel 原始 OCCT 内核
|
|
192
|
+
* @param geom 锥齿轮几何量
|
|
193
|
+
* @param strategy 齿面建面策略
|
|
194
|
+
* @param options 容差/次数选项
|
|
195
|
+
* @returns 全部面(含两端盖)
|
|
196
|
+
*/
|
|
197
|
+
export function buildBevelGearFaces(kernel, geom, strategy, options = {}) {
|
|
198
|
+
const f = faceFrames(geom);
|
|
199
|
+
const tFaces = buildBevelToothFaces(kernel, geom, strategy, options);
|
|
200
|
+
const axisZ = { point: { x: 0, y: 0, z: 0 }, direction: { x: 0, y: 0, z: 1 } };
|
|
201
|
+
const faces = [];
|
|
202
|
+
for (let i = 0; i < geom.z; i++) {
|
|
203
|
+
const angle = geom.tau * i;
|
|
204
|
+
for (const tf of tFaces) {
|
|
205
|
+
faces.push(i === 0 ? tf : kernel.rotate(tf, axisZ, angle));
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
faces.push(capBevelAtZ(kernel, faces, f.tcH, options.wireCombTol));
|
|
209
|
+
faces.push(capBevelAtZ(kernel, faces, f.pcH, options.wireCombTol));
|
|
210
|
+
return faces;
|
|
211
|
+
}
|
|
212
|
+
/** XZ 平面轮廓(世界坐标 (u, 0, v))→ wire → face → 绕 Z 回转 360° 的旋转体。 */
|
|
213
|
+
function revolveProfile(kernel, pts, arcMid) {
|
|
214
|
+
// pts = [起点, 弧中点, 弧终点, 拐点1, 拐点2],最后自动闭合回起点。
|
|
215
|
+
const edges = [
|
|
216
|
+
kernel.makeArcEdge(pts[0], pts[arcMid], pts[2]),
|
|
217
|
+
kernel.makeLineEdge(pts[2], pts[3]),
|
|
218
|
+
kernel.makeLineEdge(pts[3], pts[4]),
|
|
219
|
+
kernel.makeLineEdge(pts[4], pts[0]),
|
|
220
|
+
];
|
|
221
|
+
const face = kernel.makeFace(kernel.makeWire(edges));
|
|
222
|
+
return kernel.revolve(face, { point: { x: 0, y: 0, z: 0 }, direction: { x: 0, y: 0, z: 1 } }, Math.PI * 2);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* 复刻 `BevelGear._trim_bottom`:半径 gs_r 上的三点圆弧轮廓绕 Z 回转成 cutter,
|
|
226
|
+
* 再从实体上布尔差。
|
|
227
|
+
*
|
|
228
|
+
* @param kernel 原始 OCCT 内核
|
|
229
|
+
* @param geom 锥齿轮几何量
|
|
230
|
+
* @returns cutter(旋转体)
|
|
231
|
+
*/
|
|
232
|
+
export function makeTrimBottomCutter(kernel, geom) {
|
|
233
|
+
const r = geom.gsR;
|
|
234
|
+
const p1 = sphereToCartesian(r, geom.gammaR * 0.99, Math.PI / 2);
|
|
235
|
+
const p2 = sphereToCartesian(r, geom.gammaP, Math.PI / 2);
|
|
236
|
+
const p3 = sphereToCartesian(r, geom.gammaF * 1.01, Math.PI / 2);
|
|
237
|
+
const x1 = Math.tan(geom.gammaF) * geom.coneH + 1.0;
|
|
238
|
+
const uv = (p) => ({ x: p.x, y: 0, z: p.z });
|
|
239
|
+
return revolveProfile(kernel, [
|
|
240
|
+
uv(p1), uv(p2), uv(p3),
|
|
241
|
+
{ x: x1, y: 0, z: p3.z },
|
|
242
|
+
{ x: x1, y: 0, z: p1.z },
|
|
243
|
+
], 1);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* 复刻 `BevelGear._trim_top`:半径 gs_r − face_width 上的圆弧轮廓(内边界落在轴上)
|
|
247
|
+
* 绕 Z 回转成 cutter,再从实体上布尔差。
|
|
248
|
+
*
|
|
249
|
+
* @param kernel 原始 OCCT 内核
|
|
250
|
+
* @param geom 锥齿轮几何量
|
|
251
|
+
* @returns cutter(旋转体)
|
|
252
|
+
*/
|
|
253
|
+
export function makeTrimTopCutter(kernel, geom) {
|
|
254
|
+
const r = geom.gsR - geom.faceWidth;
|
|
255
|
+
const p1 = sphereToCartesian(r, geom.gammaR, Math.PI / 2);
|
|
256
|
+
const p2 = sphereToCartesian(r, geom.gammaP, Math.PI / 2);
|
|
257
|
+
const p3 = sphereToCartesian(r, geom.gammaF * 1.01, Math.PI / 2);
|
|
258
|
+
const uv = (p) => ({ x: p.x, y: 0, z: p.z });
|
|
259
|
+
return revolveProfile(kernel, [
|
|
260
|
+
uv(p1), uv(p2), uv(p3),
|
|
261
|
+
{ x: 0, y: 0, z: p3.z },
|
|
262
|
+
{ x: 0, y: 0, z: p1.z },
|
|
263
|
+
], 1);
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* 内核布尔差有时返回「仅含 1 个 solid 的 compound」外壳,
|
|
267
|
+
* 解包成 solid(与 `features.ts::asSolid` 同思路)。
|
|
268
|
+
*/
|
|
269
|
+
function asSolid(kernel, shape) {
|
|
270
|
+
if (kernel.isSolid(shape))
|
|
271
|
+
return shape;
|
|
272
|
+
if (kernel.getShapeType(shape) === 'compound') {
|
|
273
|
+
const solids = kernel.getSubShapes(shape, 'solid');
|
|
274
|
+
if (solids.length === 1)
|
|
275
|
+
return solids[0];
|
|
276
|
+
}
|
|
277
|
+
return shape;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* ①–⑦:完整 BevelGear 实体。
|
|
281
|
+
*
|
|
282
|
+
* @param kernel 原始 OCCT 内核
|
|
283
|
+
* @param params 锥齿轮参数(逐字沿用 Python 构造参数名)
|
|
284
|
+
* @param build 构造选项(策略/容差/裁切/轴孔)
|
|
285
|
+
* @returns 朝向归一化(齿轮轴 = +Z、底面 z = 0)后的 solid
|
|
286
|
+
*/
|
|
287
|
+
export function buildBevelGearSolid(kernel, params, build = {}) {
|
|
288
|
+
const geom = bevelGearGeometry(params);
|
|
289
|
+
const strategy = build.strategy ?? DEFAULT_SPLINE_FACE_STRATEGY;
|
|
290
|
+
const faces = buildBevelGearFaces(kernel, geom, strategy, build);
|
|
291
|
+
// cq `make_shell(faces)`(BRepBuilderAPI_Sewing,tol = shell_sewing_tol)+ `Solid.makeSolid`
|
|
292
|
+
const shell = kernel.sew(faces, build.shellSewingTol ?? GEAR_BASE_CONSTANTS.shell_sewing_tol);
|
|
293
|
+
const solid = kernel.makeSolid(shell);
|
|
294
|
+
let body = kernel.fixFaceOrientations(solid);
|
|
295
|
+
if (!kernel.isSolid(body)) {
|
|
296
|
+
throw new Error(`buildBevelGearSolid: result is not a solid (got ${String(kernel.getShapeType(body))})`);
|
|
297
|
+
}
|
|
298
|
+
// ⑤ 裁底 / 裁顶(cq 顺序:先 bottom 后 top)
|
|
299
|
+
if (build.trimBottom !== false) {
|
|
300
|
+
body = asSolid(kernel, kernel.cut(body, makeTrimBottomCutter(kernel, geom)));
|
|
301
|
+
}
|
|
302
|
+
if (build.trimTop !== false) {
|
|
303
|
+
body = asSolid(kernel, kernel.cut(body, makeTrimTopCutter(kernel, geom)));
|
|
304
|
+
}
|
|
305
|
+
if (!kernel.isSolid(body)) {
|
|
306
|
+
throw new Error('buildBevelGearSolid: result is not a solid after trims');
|
|
307
|
+
}
|
|
308
|
+
// ⑥ 把齿轮摆正:绕 X 转 180° → 沿 Z 平移 cone_h → 绕 Z 转 t_align_angle
|
|
309
|
+
const tAlignAngle = -geom.mpTheta / 2.0 - Math.PI / 2.0 + Math.PI / geom.z;
|
|
310
|
+
body = kernel.rotate(body, { point: { x: 0, y: 0, z: 0 }, direction: { x: 1, y: 0, z: 0 } }, Math.PI);
|
|
311
|
+
body = kernel.translate(body, 0, 0, geom.coneH);
|
|
312
|
+
body = kernel.rotate(body, { point: { x: 0, y: 0, z: 0 }, direction: { x: 0, y: 0, z: 1 } }, tAlignAngle);
|
|
313
|
+
// ⑦ 轴孔:`faces('<Z').workplane().circle(bore_d/2).cutThruAll()`。
|
|
314
|
+
// 缺省 centerOption='ProjectedOrigin' ⇒ 圆的圆心落在齿轮轴上(x=y=0),故等价于
|
|
315
|
+
// 「沿 Z 轴、从实体 zmin 下方贯穿到 zmax 上方」的圆柱差。
|
|
316
|
+
if (build.boreD !== undefined) {
|
|
317
|
+
const bb = kernel.getBoundingBox(body);
|
|
318
|
+
const height = (bb.zmax - bb.zmin) + 2 * BORE_E;
|
|
319
|
+
const cyl = kernel.makeCylinder(build.boreD / 2, height);
|
|
320
|
+
body = asSolid(kernel, kernel.cut(body, kernel.translate(cyl, 0, 0, bb.zmin - BORE_E)));
|
|
321
|
+
if (!kernel.isSolid(body)) {
|
|
322
|
+
throw new Error('buildBevelGearSolid: result is not a solid after bore');
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return body;
|
|
326
|
+
}
|
|
327
|
+
//# sourceMappingURL=bevel_gear.js.map
|