Outline progress
This commit is contained in:
parent
afdc467daf
commit
8e9cdd1364
4 changed files with 114 additions and 26 deletions
|
@ -54,8 +54,8 @@ if (args.debug) {
|
|||
points_lib.dump(points)
|
||||
}
|
||||
|
||||
// if (args.outline) {
|
||||
// outline_lib.draw(points, config)
|
||||
// }
|
||||
if (args.outline) {
|
||||
outline_lib.draw(points, config)
|
||||
}
|
||||
|
||||
console.log('Done.')
|
|
@ -1,20 +1,82 @@
|
|||
const m = require('makerjs')
|
||||
const fs = require('fs-extra')
|
||||
const assert = require('assert').strict
|
||||
|
||||
const outline = (points, radius, expansion=5, patches=[]) => {
|
||||
const u = require('./utils')
|
||||
|
||||
const a_lot = 100
|
||||
|
||||
|
||||
|
||||
const outline = (points, size, config={}) => {
|
||||
const models = {}
|
||||
|
||||
// create the two tops
|
||||
assert.ok(config.top.left)
|
||||
assert.ok(config.top.right)
|
||||
const tlp = points[config.top.left]
|
||||
const trp = points[config.top.right]
|
||||
|
||||
tl = m.model.moveRelative(m.model.rotate(u.rect(a_lot, size, [-size/2, -size/2]), tlp.r), tlp.p)
|
||||
tr = m.model.moveRelative(m.model.rotate(u.rect(a_lot, size, [-a_lot+size/2, -size/2]), trp.r), trp.p)
|
||||
tl = m.model.originate(tl)
|
||||
tr = m.model.originate(tr)
|
||||
const top_intersect = m.path.intersection(tl.paths.top, tr.paths.top).intersectionPoints[0]
|
||||
console.log(tlp.p, tl, tl.paths.top, ',,,', trp.p, tr, tr.paths.top, top_intersect)
|
||||
|
||||
u.dump_model({
|
||||
a: {
|
||||
// models: {tl, tr},
|
||||
paths: {
|
||||
tll: tl.paths.top,
|
||||
trl: tr.paths.top,
|
||||
tl: u.circle(tlp.p, 1),
|
||||
tr: u.circle(trp.p, 1),
|
||||
c: u.circle(top_intersect, 1)
|
||||
}
|
||||
}
|
||||
}, 'valami', true)
|
||||
|
||||
throw 2
|
||||
|
||||
// create the two bottoms
|
||||
assert.ok(config.bottom.left)
|
||||
assert.ok(config.bottom.right)
|
||||
const blp = points[config.bottom.left]
|
||||
const brp = points[config.bottom.right]
|
||||
|
||||
// create middle "patch"
|
||||
const tll = new m.paths.Line(tlp.p, tlp.add([a_lot, 0]).rotate(tlp.r, tlp.p).p)
|
||||
const trl = new m.paths.Line(trp.p, trp.add([a_lot, 0]).rotate(trp.r, trp.p).p)
|
||||
|
||||
|
||||
const bll = new m.paths.Line(blp.p, blp.add([a_lot, 0]).rotate(blp.r, blp.p).p)
|
||||
const brl = new m.paths.Line(brp.p, brp.add([a_lot, 0]).rotate(brp.r, brp.p).p)
|
||||
const bottom_intersect = m.path.intersection(bll, brl).intersectionPoints[0]
|
||||
|
||||
|
||||
console.log(tll, trl, top_intersect)
|
||||
throw 2
|
||||
|
||||
for (const p of Object.values(points)) {
|
||||
const r = new m.models.RoundRectangle(size, size, config.corner || 0)
|
||||
}
|
||||
}
|
||||
|
||||
exports.draw = (points, config) => {
|
||||
const lefts = {}
|
||||
const rights = {}
|
||||
for (const [k, p] of Object.entries(points)) {
|
||||
if (p.meta.mirrored) {
|
||||
rights[k] = p
|
||||
} else {
|
||||
lefts[k] = p
|
||||
}
|
||||
}
|
||||
// const lefts = {}
|
||||
// const rights = {}
|
||||
// for (const [k, p] of Object.entries(points)) {
|
||||
// if (p.meta.mirrored) {
|
||||
// rights[k] = p
|
||||
// } else {
|
||||
// lefts[k] = p
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// TODO this is just a test
|
||||
outline(points, 18, config.outline)
|
||||
|
||||
|
||||
}
|
|
@ -47,7 +47,7 @@ const Point = exports.Point = class Point {
|
|||
|
||||
mirror(x) {
|
||||
this.x = 2 * x - this.x
|
||||
this.r = 180 - this.r
|
||||
this.r = -this.r
|
||||
return this
|
||||
}
|
||||
|
||||
|
@ -63,20 +63,15 @@ const Point = exports.Point = class Point {
|
|||
|
||||
const dump = exports.dump = (points, opts={}) => {
|
||||
|
||||
const line = (a, b) => ({
|
||||
type: 'line',
|
||||
origin: a,
|
||||
end: b
|
||||
})
|
||||
const s = (opts.side || 14) / 2
|
||||
|
||||
const models = {}
|
||||
for (const [key, point] of Object.entries(points)) {
|
||||
const paths = {
|
||||
l: line([-s, -s], [-s, s]),
|
||||
t: line([-s, s], [ s, s]),
|
||||
r: line([ s, s], [ s, -s]),
|
||||
b: line([ s, -s], [-s, -s])
|
||||
l: u.line([-s, -s], [-s, s]),
|
||||
t: u.line([-s, s], [ s, s]),
|
||||
r: u.line([ s, s], [ s, -s]),
|
||||
b: u.line([ s, -s], [-s, -s])
|
||||
}
|
||||
models[key] = m.model.moveRelative(m.model.rotate({paths}, point.r), point.p)
|
||||
}
|
||||
|
@ -86,7 +81,8 @@ const dump = exports.dump = (points, opts={}) => {
|
|||
units: 'mm'
|
||||
})
|
||||
|
||||
fs.writeFileSync(`${opts.file || 'dump'}.json`, JSON.stringify(points, null, ' '))
|
||||
fs.writeFileSync(`${opts.file || 'dump'}_points.json`, JSON.stringify(points, null, ' '))
|
||||
fs.writeFileSync(`${opts.file || 'dump'}_assembly.json`, JSON.stringify(assembly, null, ' '))
|
||||
fs.writeFileSync(`${opts.file || 'dump'}.dxf`, m.exporter.toDXF(assembly))
|
||||
}
|
||||
|
||||
|
|
|
@ -5,10 +5,40 @@ exports.deepcopy = (value) => JSON.parse(JSON.stringify(value))
|
|||
|
||||
exports.dump_model = (model, file='model', json=false) => {
|
||||
const assembly = m.model.originate({
|
||||
model,
|
||||
models: model,
|
||||
units: 'mm'
|
||||
})
|
||||
|
||||
fs.writeFileSync(`${file}.dxf`, m.exporter.toDXF(assembly))
|
||||
if (json) fs.writeFileSync(`${file}.json`, JSON.stringify(assembly, null, ' '))
|
||||
fs.writeFileSync(`${file}.dxf`, m.exporter.toDXF(assembly))
|
||||
}
|
||||
|
||||
const line = exports.line = (a, b) => {
|
||||
return new m.paths.Line(a, b)
|
||||
}
|
||||
|
||||
exports.circle = (p, r) => {
|
||||
return new m.paths.Circle(p, r)
|
||||
}
|
||||
|
||||
exports.rect = (w, h, o=[0, 0]) => {
|
||||
return m.model.move({paths: {
|
||||
top: line([0, h], [w, h]),
|
||||
right: line([w, h], [w, 0]),
|
||||
bottom: line([w, 0], [0, 0]),
|
||||
left: line([0, 0], [0, h])
|
||||
}}, o)
|
||||
}
|
||||
|
||||
exports.poly = (arr) => {
|
||||
let counter = 0
|
||||
let prev = arr[arr.length - 1]
|
||||
const res = {
|
||||
paths: {}
|
||||
}
|
||||
for (const p of arr) {
|
||||
res.paths['p' + (++counter)] = line(prev, p)
|
||||
prev = p
|
||||
}
|
||||
return res
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue