gear generation remembers previous settings and uses them as defaults
This commit is contained in:
parent
9f2fcc1a09
commit
fee09c17f5
2 changed files with 18 additions and 11 deletions
|
|
@ -2050,7 +2050,8 @@ class Polygon {
|
||||||
|
|
||||||
// for turning a poly with an inner offset into a
|
// for turning a poly with an inner offset into a
|
||||||
// 3d mesh if and only if the inner has the same
|
// 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) {
|
ribbonMesh(swap) {
|
||||||
if (!(this.inner && this.inner.length === 1)) {
|
if (!(this.inner && this.inner.length === 1)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
@ -2064,6 +2065,7 @@ class Polygon {
|
||||||
let p0 = outer.points.slice();
|
let p0 = outer.points.slice();
|
||||||
let p1 = inner.points.slice();
|
let p1 = inner.points.slice();
|
||||||
let min = { d: Infinity, i:0, j:0 };
|
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 i=0; i<p0.length; i++) {
|
||||||
for (let j=0; j<p1.length; j++) {
|
for (let j=0; j<p1.length; j++) {
|
||||||
let d = p0[i].distTo2D(p1[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]);
|
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]);
|
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
|
// 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 faces = [];
|
||||||
let pi0 = 0;
|
let pi0 = 0;
|
||||||
let pi1 = 0;
|
let pi1 = 0;
|
||||||
|
|
|
||||||
|
|
@ -324,7 +324,8 @@ let add = {
|
||||||
function gengear(bound) {
|
function gengear(bound) {
|
||||||
const { _teeth, _module, _angle, _twist, _shaft, _offset, _height, _chamfer } = bound;
|
const { _teeth, _module, _angle, _twist, _shaft, _offset, _height, _chamfer } = bound;
|
||||||
api.modal.hide();
|
api.modal.hide();
|
||||||
worker.model_gen_gear({
|
let params;
|
||||||
|
worker.model_gen_gear(params = {
|
||||||
teeth: parseInt(_teeth.value),
|
teeth: parseInt(_teeth.value),
|
||||||
module: parseFloat(_module.value),
|
module: parseFloat(_module.value),
|
||||||
angle: parseFloat(_angle.value),
|
angle: parseFloat(_angle.value),
|
||||||
|
|
@ -337,31 +338,34 @@ let add = {
|
||||||
const nmdl = new mesh.model({ file: "gear", mesh: gear.toFloat32() });
|
const nmdl = new mesh.model({ file: "gear", mesh: gear.toFloat32() });
|
||||||
const ngrp = group.new([ nmdl ]);
|
const ngrp = group.new([ nmdl ]);
|
||||||
ngrp.floor();
|
ngrp.floor();
|
||||||
|
Object.assign(last, params);
|
||||||
|
api.prefs.save();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
let last = api.prefs.map.gear = (api.prefs.map.gear || {});
|
||||||
api.modal.dialog({
|
api.modal.dialog({
|
||||||
title: "gear generator",
|
title: "gear generator",
|
||||||
body: [ h.div({ class: "addgear" }, [
|
body: [ h.div({ class: "addgear" }, [
|
||||||
h.label('number of teeth'),
|
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.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.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.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.hr(),
|
||||||
h.code("all other settings must"),
|
h.code("all other settings must"),
|
||||||
h.code("match for gears to mesh"),
|
h.code("match for gears to mesh"),
|
||||||
h.hr(),
|
h.hr(),
|
||||||
h.label('module (diam / teeth)'),
|
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.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.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.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) } })
|
h.button({ _: "create", onclick() { gengear(api.modal.bound) } })
|
||||||
]) ]
|
]) ]
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue