Skip to content

Commit

Permalink
added knob model
Browse files Browse the repository at this point in the history
  • Loading branch information
drom committed May 27, 2024
1 parent e6ea8ad commit 46cdaec
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 0 deletions.
2 changes: 2 additions & 0 deletions knob/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
package-lock.json
1 change: 1 addition & 0 deletions knob/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Knob model
75 changes: 75 additions & 0 deletions knob/body.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
'use strict';

const jscad = require('@jscad/modeling');
const { colorize, hexToRgb } = jscad.colors;
const { polygon, cuboid, roundedCuboid, cylinder, cylinderElliptic, roundedCylinder } = jscad.primitives;
const { union, subtract, intersect } = jscad.booleans;
const { translate, translateX, translateY, translateZ, rotate, rotateX, rotateY, rotateZ } = jscad.transforms;
const { extrudeLinear, extrudeFromSlices, slice } = jscad.extrusions;
const { mat4 } = jscad.maths;
const { hull, hullChain } = jscad.hulls;

const outerKnob = () => subtract(
cylinderElliptic({height: 21, startRadius: [12, 12], endRadius: [11, 11], center: [0, 0, 21 / 2 + 3], segments: 36}),
cylinder({radius: 9, height: 2, center: [0, 0, 24], segments: 64}),
cylinder({radius: 4.05, height: 12, center: [0, 0, 20], segments: 64}),
cylinderElliptic({height: 8, startRadius: [10, 10], endRadius: [2, 2], center: [0, 0, 13], segments: 64}),
cylinderElliptic({height: 6, startRadius: [11, 11], endRadius: [10, 10], center: [0, 0, 6], segments: 64}),
translateZ(19,
rotateX(Math.PI / 2,
cylinder({radius: 1, height: 40, center: [0, 0, 20]}),
)
),
...Array.from({length: 18}, (e, i) => Math.PI * 2 * (i + 0.5) / 18)
.map(angle => rotateZ(angle,
translate([11.8, 0, 16],
rotateY(-.05,
roundedCylinder({height: 18, radius: 1, roundRadius: 0.5})
)
)
))
);

const outerInsert = () => translateZ(19,
subtract(
cylinder({radius: 4, height: 8}),
cylinder({radius: 3, height: 8})
)
);

const innnerKnob = () => translateZ(24, // 26
subtract(
cylinderElliptic({height: 14, startRadius: [8, 8], endRadius: [7.6, 7.6], center: [0, 0, 7], segments: 44}),
cylinder({radius: 5.7 / 2, height: 11, center: [0, 0, 5], segments: 64}),
translateZ(5,
rotateX(Math.PI / 2,
cylinder({radius: 1, height: 40, center: [0, 0, 20]}),
)
),
...Array.from({length: 11}, (e, i) => Math.PI * 2 * (i + 0.25) / 11)
.map(angle => rotateZ(angle,
translate([8, 0, 10],
rotateY(0,
roundedCylinder({height: 15, radius: 1, roundRadius: 0.5})
)
)
))

)
);

const innerInsert = () => translateZ(24,
subtract(
cylinder({radius: 5.7 / 2, height: 10, center: [0, 0, 5]}),
cylinder({radius: 3.45 / 2, height: 10, center: [0, 0, 5]})
)
);

const main = () => [
colorize(hexToRgb('#aaaaff'), outerKnob()),
colorize(hexToRgb('#ffccaa'), outerInsert()),
colorize(hexToRgb('#ffaaaa'), innnerKnob()),
colorize(hexToRgb('#ffccaa'), innerInsert()),
];

module.exports.main = main;
28 changes: 28 additions & 0 deletions knob/gen-stl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env node
'use strict';

const process = require('process');
const path = require('path');
const fs = require('fs');

const commander = require('commander');
const stlSerializer = require('@jscad/stl-serializer');

commander
.requiredOption('-m, --model <path>', 'input OpenJsCad model to render')
.option('-o, --output-stl <path>', 'output STL file to save')
.parse(commander.argv);

const options = commander.opts();

const model = require(path.join(process.cwd(), options.model));

const raw = stlSerializer.serialize({binary: true}, model.main());

const stl = Buffer.concat([Buffer.from(raw[0]), Buffer.from(raw[1]), Buffer.from(raw[2])]);

if (options.outputStl) {
fs.writeFileSync(options.outputStl, stl);
} else {
process.stdout.write(stl);
}
Binary file added knob/knob-inner-v1.stl
Binary file not shown.
Binary file added knob/knob-outer-v1.stl
Binary file not shown.
19 changes: 19 additions & 0 deletions knob/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "xapoh-knob",
"version": "0.1.0",
"description": "",
"main": "body.js",
"scripts": {
"test": "eslint body.js"
},
"author": "",
"license": "MIT",
"eslintConfig": {
"extends": "@drom/eslint-config/eslint8/node12"
},
"devDependencies": {
"@drom/eslint-config": "^0.12.0",
"@jscad/stl-serializer": "^2.1.12",
"commander": "^9"
}
}

0 comments on commit 46cdaec

Please sign in to comment.