add chamfer top option for gears

This commit is contained in:
Stewart Allen 2024-07-19 18:05:41 -04:00
commit ee68930f73
6 changed files with 135 additions and 19 deletions

View file

@ -322,8 +322,7 @@ let add = {
gear(opt = {}) {
function gengear(bound) {
console.log({ bound });
const { _teeth, _module, _angle, _twist, _shaft, _offset, _height } = bound;
const { _teeth, _module, _angle, _twist, _shaft, _offset, _height, _chamfer } = bound;
api.modal.hide();
worker.model_gen_gear({
teeth: parseInt(_teeth.value),
@ -333,6 +332,7 @@ let add = {
shaft: parseFloat(_shaft.value),
offset: parseFloat(_offset.value),
height: parseFloat(_height.value),
chamfer: parseFloat(_chamfer.value),
}).then(gear => {
const nmdl = new mesh.model({ file: "gear", mesh: gear.toFloat32() });
const ngrp = group.new([ nmdl ]);
@ -348,6 +348,8 @@ let add = {
h.input({ value: opt.shaft || 5, size: 5, id: "_shaft" }),
h.label('z height'),
h.input({ value: opt.height || 15, size: 5, id: "_height" }),
h.label('chamfer'),
h.input({ value: opt.chamfer || 0, size: 5, id: "_chamfer" }),
h.hr(),
h.code("all other settings must"),
h.code("match for gears to mesh"),

View file

@ -810,7 +810,6 @@ mesh.tool = class MeshTool {
polar(r, r < b ? -k : pi / numTeeth),
// polar(r, 3.142 / numTeeth) // omit b/c overlaps start when rotated
];
console.log({ p, f });
// create all gear teeth by rotating the first tooth
for (var i = 0; i < numTeeth; i++) {

View file

@ -401,7 +401,7 @@ let model = {
},
gen_gear(data, send) {
const { teeth, module, angle, twist, shaft, offset, height } = data;
const { teeth, module, angle, twist, shaft, offset, height, chamfer } = data;
const { gear, pitch } = new mesh.tool().generateGear(teeth, module, angle, offset);
const points = gear.map(v => [...v, 0]).flat();
const poly = newPolygon().addVerts(points);
@ -410,7 +410,7 @@ let model = {
const srad = shaft / 2;
poly.addInner( newPolygon().centerCircle({ x:0, y:0, z:0 }, srad, nump) );
}
const verts = poly.extrude(height || 15);
const verts = poly.extrude(height || 15, { chamfer });
if (twist) {
const rad = base.util.toRadians(twist);
for (let i=0; i<verts.length; i += 3) {