gear generation remembers previous settings and uses them as defaults

This commit is contained in:
Stewart Allen 2024-07-19 20:37:32 -04:00
commit fee09c17f5
2 changed files with 18 additions and 11 deletions

View file

@ -2050,7 +2050,8 @@ class Polygon {
// for turning a poly with an inner offset into a
// 3d mesh if and only if the inner has the same
// circularity and <= num points. used to make chamfers
// circularity and <= num points
// primarily used to make chamfers
ribbonMesh(swap) {
if (!(this.inner && this.inner.length === 1)) {
return undefined;
@ -2064,6 +2065,7 @@ class Polygon {
let p0 = outer.points.slice();
let p1 = inner.points.slice();
let min = { d: Infinity, i:0, j:0 };
// find the closests two points inner/outer
for (let i=0; i<p0.length; i++) {
for (let j=0; j<p1.length; j++) {
let d = p0[i].distTo2D(p1[j]);
@ -2072,10 +2074,11 @@ class Polygon {
}
}
}
// slide the arrays until the closest points are aligned at index = 0
p0 = p0.slice(min.i).concat(p0.slice(0, min.i)); p0.push(p0[0]);
p1 = p1.slice(min.j).concat(p1.slice(0, min.j)); p1.push(p1[0]);
// walk both arrays moving to the next poly + point that forms
// the shortest line segment between the two polys
// the shortest line segment between the two points (inner / outer)
let faces = [];
let pi0 = 0;
let pi1 = 0;

View file

@ -324,7 +324,8 @@ let add = {
function gengear(bound) {
const { _teeth, _module, _angle, _twist, _shaft, _offset, _height, _chamfer } = bound;
api.modal.hide();
worker.model_gen_gear({
let params;
worker.model_gen_gear(params = {
teeth: parseInt(_teeth.value),
module: parseFloat(_module.value),
angle: parseFloat(_angle.value),
@ -337,31 +338,34 @@ let add = {
const nmdl = new mesh.model({ file: "gear", mesh: gear.toFloat32() });
const ngrp = group.new([ nmdl ]);
ngrp.floor();
Object.assign(last, params);
api.prefs.save();
});
}
let last = api.prefs.map.gear = (api.prefs.map.gear || {});
api.modal.dialog({
title: "gear generator",
body: [ h.div({ class: "addgear" }, [
h.label('number of teeth'),
h.input({ value: opt.teeth || 20, size: 5, id: "_teeth" }),
h.input({ value: opt.teeth || last.teeth || 20, size: 5, id: "_teeth" }),
h.label('shaft diameter'),
h.input({ value: opt.shaft || 5, size: 5, id: "_shaft" }),
h.input({ value: opt.shaft || last.shaft || 5, size: 5, id: "_shaft" }),
h.label('z height'),
h.input({ value: opt.height || 15, size: 5, id: "_height" }),
h.input({ value: opt.height || last.height || 15, size: 5, id: "_height" }),
h.label('chamfer'),
h.input({ value: opt.chamfer || 0, size: 5, id: "_chamfer" }),
h.input({ value: opt.chamfer || last.chamfer || 0, size: 5, id: "_chamfer" }),
h.hr(),
h.code("all other settings must"),
h.code("match for gears to mesh"),
h.hr(),
h.label('module (diam / teeth)'),
h.input({ value: opt.module || 3, size: 5, id: "_module" }),
h.input({ value: opt.module || last.module || 3, size: 5, id: "_module" }),
h.label('pressure angle'),
h.input({ value: opt.angle || 20, size: 5, id: "_angle" }),
h.input({ value: opt.angle || last.angle || 20, size: 5, id: "_angle" }),
h.label('twist angle (helix)'),
h.input({ value: opt.twist || 0, size: 5, id: "_twist" }),
h.input({ value: opt.twist || last.twist || 0, size: 5, id: "_twist" }),
h.label('tooth offset (play)'),
h.input({ value: opt.offset || 0.1, size: 5, id: "_offset" }),
h.input({ value: opt.offset || last.offset || 0.1, size: 5, id: "_offset" }),
h.button({ _: "create", onclick() { gengear(api.modal.bound) } })
]) ]
});