add more gear parameters, better dialog
This commit is contained in:
parent
96586c0137
commit
0b69cfdc7e
6 changed files with 56 additions and 46 deletions
|
|
@ -321,14 +321,18 @@ let add = {
|
|||
},
|
||||
|
||||
gear(opt = {}) {
|
||||
function gengear(teeth, module, angle, twist, shaft) {
|
||||
function gengear(bound) {
|
||||
console.log({ bound });
|
||||
const { _teeth, _module, _angle, _twist, _shaft, _offset, _height } = bound;
|
||||
api.modal.hide();
|
||||
worker.model_gen_gear({
|
||||
teeth: parseInt(teeth),
|
||||
module: parseFloat(module),
|
||||
angle: parseFloat(angle),
|
||||
twist: parseFloat(twist),
|
||||
shaft: parseFloat(shaft),
|
||||
teeth: parseInt(_teeth.value),
|
||||
module: parseFloat(_module.value),
|
||||
angle: parseFloat(_angle.value),
|
||||
twist: parseFloat(_twist.value),
|
||||
shaft: parseFloat(_shaft.value),
|
||||
offset: parseFloat(_offset.value),
|
||||
height: parseFloat(_height.value),
|
||||
}).then(gear => {
|
||||
const nmdl = new mesh.model({ file: "gear", mesh: gear.toFloat32() });
|
||||
const ngrp = group.new([ nmdl ]);
|
||||
|
|
@ -339,27 +343,27 @@ let add = {
|
|||
title: "gear generator",
|
||||
body: [ h.div({ class: "addgear" }, [
|
||||
h.label('number of teeth'),
|
||||
h.input({ value: opt.teeth || 20, size: 5, id: "gteeth" }),
|
||||
h.label('module (diam / teeth)'),
|
||||
h.input({ value: opt.module || 3, size: 5, id: "gmodule" }),
|
||||
h.label('pressure angle'),
|
||||
h.input({ value: opt.angle || 20, size: 5, id: "gangle" }),
|
||||
h.label('twist angle'),
|
||||
h.input({ value: opt.twist || 0, size: 5, id: "gtwist" }),
|
||||
h.input({ value: opt.teeth || 20, size: 5, id: "_teeth" }),
|
||||
h.label('shaft diameter'),
|
||||
h.input({ value: opt.shaft || 5, size: 5, id: "gshaft" }),
|
||||
h.button({ _: "create", onclick() {
|
||||
gengear(
|
||||
api.modal.bound.gteeth.value,
|
||||
api.modal.bound.gmodule.value,
|
||||
api.modal.bound.gangle.value,
|
||||
api.modal.bound.gtwist.value,
|
||||
api.modal.bound.gshaft.value,
|
||||
)
|
||||
} })
|
||||
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.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.label('pressure angle'),
|
||||
h.input({ value: opt.angle || 20, size: 5, id: "_angle" }),
|
||||
h.label('twist angle (helix)'),
|
||||
h.input({ value: opt.twist || 0, size: 5, id: "_twist" }),
|
||||
h.label('tooth offset (play)'),
|
||||
h.input({ value: opt.offset || 0.1, size: 5, id: "_offset" }),
|
||||
h.button({ _: "create", onclick() { gengear(api.modal.bound) } })
|
||||
]) ]
|
||||
});
|
||||
api.modal.bound.gteeth.focus();
|
||||
api.modal.bound._teeth.focus();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -375,7 +375,7 @@ function ui_build() {
|
|||
h.div({ class: "pop"}, [
|
||||
h.button({ _: 'cylinder', onclick: add.cylinder }),
|
||||
h.button({ _: 'cube', onclick: add.cube }),
|
||||
h.button({ _: 'gear', onclick: add.gear }),
|
||||
h.button({ _: 'gear', onclick() { add.gear() } }),
|
||||
devel ? h.button({ _: 'input', onclick: add.input }) : undefined
|
||||
])
|
||||
]),
|
||||
|
|
|
|||
|
|
@ -740,7 +740,7 @@ mesh.tool = class MeshTool {
|
|||
|
||||
// returns points array for a polygon
|
||||
// extrusion and twist is handled in work.js
|
||||
generateGear(numTeeth, module, pressureAngle) {
|
||||
generateGear(numTeeth, module, pressureAngle, offset) {
|
||||
// Adapted from: Public Domain Parametric Involute Spur Gear by Leemon Baird, 2011, Leemon@Leemon.com http://www.thingiverse.com/thing:5505
|
||||
// see also http://grabcad.com/questions/tutorial-how-to-model-involute-gears-in-solidworks-and-show-design-intent
|
||||
|
||||
|
|
@ -787,10 +787,11 @@ mesh.tool = class MeshTool {
|
|||
|
||||
// gear parameter setup
|
||||
let mm_per_tooth = module * pi; // mm size of one gear tooth
|
||||
let clearance = 0.1; // freedom between two gear centers
|
||||
let backlash = 0.1; // freedom between two gear contact points
|
||||
let clearance = offset/2 || 0; // freedom between two gear centers
|
||||
let backlash = offset || 0; // freedom between two gear contact points
|
||||
let pressure_angle = degrees_to_radians(pressureAngle);
|
||||
let gear = [];
|
||||
let pitch;
|
||||
|
||||
// involute gear maker
|
||||
{
|
||||
|
|
@ -800,24 +801,27 @@ mesh.tool = class MeshTool {
|
|||
let r = p - (c - p) - clearance; // radius of root circle
|
||||
let t = mm_per_tooth / 2 - backlash / 2; // tooth thickness at pitch circle
|
||||
let k = -iang(b, p) - t / 2 / p; // angle where involute meets base circle on side of tooth
|
||||
let f = 10 + ((p/5) | 0); // increase number of tooth curve points on larger gears
|
||||
let points = [ // [x,y] points for a single gear tooth
|
||||
polar(r, -pi / numTeeth),
|
||||
polar(r, r < b ? k : -pi / numTeeth),
|
||||
...qf(10, r, b, c, k, 1),
|
||||
...qf(10, r, b, c, k, -1).reverse(),
|
||||
...qf(f, r, b, c, k, 1),
|
||||
...qf(f, r, b, c, k, -1).reverse(),
|
||||
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++) {
|
||||
gear.appendAll(rotate(points, -i * 2 * pi / numTeeth));
|
||||
}
|
||||
|
||||
mesh.log(`gear pitch radius: ${p.round(3)}`);
|
||||
pitch = p.round(3);
|
||||
mesh.log(`gear pitch radius: ${pitch}`);
|
||||
}
|
||||
|
||||
return gear;
|
||||
return { gear, pitch };
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -401,21 +401,18 @@ let model = {
|
|||
},
|
||||
|
||||
gen_gear(data, send) {
|
||||
const { teeth, module, angle, twist, shaft, z } = data;
|
||||
let points = new mesh.tool()
|
||||
.generateGear(teeth, module, angle)
|
||||
.map(v => [...v, 0]).flat();
|
||||
let poly = newPolygon().addVerts(points);
|
||||
const { teeth, module, angle, twist, shaft, offset, height } = 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);
|
||||
if (shaft) {
|
||||
poly.addInner(
|
||||
newPolygon().centerCircle({
|
||||
x:0, y:0, z:0
|
||||
}, shaft / 2, Math.min(20 + shaft,100))
|
||||
);
|
||||
const nump = Math.min(30 + shaft, 150);
|
||||
const srad = shaft / 2;
|
||||
poly.addInner( newPolygon().centerCircle({ x:0, y:0, z:0 }, srad, nump) );
|
||||
}
|
||||
let verts = poly.extrude(z || 15);
|
||||
const verts = poly.extrude(height || 15);
|
||||
if (twist) {
|
||||
let rad = base.util.toRadians(twist);
|
||||
const rad = base.util.toRadians(twist);
|
||||
for (let i=0; i<verts.length; i += 3) {
|
||||
if (Math.abs(verts[i+2]) < 0.001) {
|
||||
let [x, y] = base.util.rotate(
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ gapp.overlay(root, {
|
|||
|
||||
// add common element types
|
||||
[
|
||||
"a", "i", "hr", "div", "span", "label", "input",
|
||||
"a", "i", "hr", "div", "pre", "code", "span", "label", "input",
|
||||
"button", "svg", "textarea", "select", "option"
|
||||
].forEach(type => {
|
||||
h[type] = (attr, innr) => {
|
||||
|
|
|
|||
|
|
@ -235,8 +235,13 @@ button:hover {
|
|||
grid-template-columns: 1fr 50px;
|
||||
}
|
||||
|
||||
.addgear button {
|
||||
column-span: all;
|
||||
.addgear hr {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.addgear button, .addgear hr, .addgear code {
|
||||
grid-column: span 2;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.image-import {
|
||||
|
|
|
|||
Loading…
Reference in a new issue