Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxattax97 committed Mar 12, 2019
1 parent 3519fba commit eb5f170
Show file tree
Hide file tree
Showing 9 changed files with 2,690 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/node_modules/**
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "airbnb-base"
}
19 changes: 19 additions & 0 deletions .tern-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"ecmaVersion": 6,
"libs": [],
"loadEagerly": [
"index.js"
],
"dontLoad": [],
"plugins": {
"requirejs": {
"baseURL": "./",
"paths": {}
},
"node": {},
"doc_comment": {
"fullDocs": true,
"strong": true
}
}
}
59 changes: 59 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const fs = require('fs');
const getStdin = require('get-stdin');
const { promisify } = require('util');
const { argv } = require('yargs')
.usage('Usage: $0 [options]')
.example('$0 -i input.scad -o output.scad', 'Formats input.scad and saves it as output.scad')
.example('$0 < input.scad > output.scad', 'Formats input.scad and saves it as output.scad')
.example('$0 < input.scad', 'Formats input.scad and writes to stdout')
.example('cat input.scad | $0 | less', 'Formats input.scad and displays in less')
.alias('i', 'input')
.nargs('i', 1)
.describe('i', 'Input file to read')
.alias('o', 'output')
.nargs('o', 1)
.describe('o', 'Output file to write')
.help('h')
.alias('h', 'help')
.epilog('This utility requires clang and openscad to be installed.');

function format(str) {
console.log(str);
}

async function main(input, output) {
if (input) {
argv.input = input;
}

if (output) {
argv.output = output;
}

const readFile = promisify(fs.readFile);
if (argv.input) {
try {
const str = await readFile(argv.input);
format(str.toString());
} catch (err) {
console.error(err);
}
} else {
try {
const str = await getStdin();
format(str.toString());
} catch (err) {
console.error(err);
}
}
}

if (require.main === module) {
// Called via CLI.
if (!argv.help) {
main();
}
} else {
// Called via require.
module.exports = main;
}
48 changes: 48 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "openscad-format",
"version": "0.0.1",
"description": "An opinionated formatter for the OpenSCAD language.",
"main": "index.js",
"bin": {
"openscad-format": "index.js"
},
"scripts": {
"lint": "eslint .",
"fix": "eslint . --fix",
"cmd": "node index.js",
"test": "mocha",
"demo": "node index.js -i source.scad"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Maxattax97/openscad-format.git"
},
"keywords": [
"openscad",
"format",
"cad",
"3d"
],
"author": "Max O'Cull",
"license": "GPL-3.0",
"bugs": {
"url": "https://github.com/Maxattax97/openscad-format/issues"
},
"homepage": "https://github.com/Maxattax97/openscad-format#readme",
"dependencies": {
"get-stdin": "^6.0.0",
"yargs": "^13.2.2"
},
"devDependencies": {
"chai": "^4.2.0",
"eslint": "^5.15.1",
"eslint-plugin-import": "^2.16.0",
"mocha": "^6.0.2"
},
"peerDependencies": {
"eslint-config-airbnb-base": "^13.1.0"
},
"engines": {
"node": ">=8.0.0"
}
}
71 changes: 71 additions & 0 deletions source.ast
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
function gen_facet_series(r) = [0 : (1 / get_fragments_from_r(r)) : 1.0001];
function get_fragments_from_r(r) = (($fn > 0) ? $fn : ((r < 9.53674e-07) ? 3 : ceil(max(min((360 / $fa), (((r * 2) * PI) / $fs)), 5))));
module axle(height) {
translate([0, 0, ((height * block_height) / 2)]) union() {
cube([axle_diameter, axle_spline_width, (height * block_height)], center = true);
cube([axle_spline_width, axle_diameter, (height * block_height)], center = true);
}
}
module reinforcement(height) {
union() translate([0, 0, ((height * block_height) / 2)]) union() {
cube([reinforcing_width, ((knob_spacing + knob_diameter) + (wall_thickness / 2)), (height * block_height)], center = true);
rotate(v = [0, 0, 1], a = 90) cube([reinforcing_width, ((knob_spacing + knob_diameter) + (wall_thickness / 2)), (height * block_height)], center = true);
}
}
module post(height) {
difference() {
cylinder(r = (post_diameter / 2), h = ((height * block_height) - (roof_thickness / 2)), $fs = cylinder_precision);
translate([0, 0, -(roof_thickness / 2)]) cylinder(r = (knob_diameter / 2), h = ((height * block_height) + (roof_thickness / 4)), $fs = cylinder_precision);
}
}
module block(width, length, height, axle_hole = false, reinforcement = false, hollow_knob = false, flat_top = false, circular_hole = false, solid_bottom = true, center = false) {
overall_length = ((((length - 1) * knob_spacing) + knob_diameter) + (wall_thickness * 2));
overall_width = ((((width - 1) * knob_spacing) + knob_diameter) + (wall_thickness * 2));
center = ((center == true) ? 1 : 0);
translate((center * [-(overall_length / 2), -(overall_width / 2), 0])) union() {
difference() {
union() {
cube([overall_length, overall_width, (height * block_height)]);
if((flat_top != true)) translate([((knob_diameter / 2) + wall_thickness), ((knob_diameter / 2) + wall_thickness), 0]) for(ycount = [0 : (width - 1)]) for(xcount = [0 : (length - 1)]) translate([(xcount * knob_spacing), (ycount * knob_spacing), 0]) difference() {
cylinder(r = (knob_diameter / 2), h = ((block_height * height) + knob_height), $fs = cylinder_precision);
if((hollow_knob == true)) translate([0, 0, -roof_thickness]) cylinder(r = (pin_diameter / 2), h = (((block_height * height) + knob_height) + (2 * roof_thickness)), $fs = cylinder_precision);
}
}
if((solid_bottom == false)) translate([wall_thickness, wall_thickness, -roof_thickness]) cube([(overall_length - (wall_thickness * 2)), (overall_width - (wall_thickness * 2)), (block_height * height)]);
if((flat_top == true)) {
translate([-(wall_thickness / 2), -((wall_thickness * 2) / 3), -(wall_thickness / 2)]) cube([(overall_length + wall_thickness), wall_thickness, wall_thickness]);
translate([-(wall_thickness / 2), (overall_width - (wall_thickness / 3)), -(wall_thickness / 2)]) cube([(overall_length + wall_thickness), wall_thickness, wall_thickness]);
translate([-((wall_thickness * 2) / 3), -(wall_thickness / 2), -(wall_thickness / 2)]) cube([wall_thickness, (overall_width + wall_thickness), wall_thickness]);
translate([(overall_length - (wall_thickness / 3)), 0, -(wall_thickness / 2)]) cube([wall_thickness, (overall_width + wall_thickness), wall_thickness]);
}
if((axle_hole == true)) if(((width > 1) && (length > 1))) for(ycount = [1 : (width - 1)]) for(xcount = [1 : (length - 1)]) translate([(xcount * knob_spacing), (ycount * knob_spacing), roof_thickness]) axle(height);
if((circular_hole == true)) if(((width > 1) && (length > 1))) for(ycount = [1 : (width - 1)]) for(xcount = [1 : (length - 1)]) translate([(xcount * knob_spacing), (ycount * knob_spacing), roof_thickness]) cylinder(r = (knob_diameter / 2), h = ((height * block_height) + (roof_thickness / 4)), $fs = cylinder_precision);
}
if((((reinforcement == true) && (width > 1)) && (length > 1))) difference() {
for(ycount = [1 : (width - 1)]) for(xcount = [1 : (length - 1)]) translate([(xcount * knob_spacing), (ycount * knob_spacing), 0]) reinforcement(height);
for(ycount = [1 : (width - 1)]) for(xcount = [1 : (length - 1)]) translate([(xcount * knob_spacing), (ycount * knob_spacing), -(roof_thickness / 2)]) cylinder(r = (knob_diameter / 2), h = ((height * block_height) + roof_thickness), $fs = cylinder_precision);
}
if((solid_bottom == false)) if(((width > 1) && (length > 1))) for(ycount = [1 : (width - 1)]) for(xcount = [1 : (length - 1)]) translate([(xcount * knob_spacing), (ycount * knob_spacing), 0]) post(height);
if((((reinforcement == true) && (width == 1)) && (length != 1))) for(xcount = [1 : (length - 1)]) translate([(xcount * knob_spacing), (overall_width / 2), 0]) cylinder(r = (pin_diameter / 2), h = (block_height * height), $fs = cylinder_precision);
if((((reinforcement == true) && (length == 1)) && (width != 1))) for(ycount = [1 : (width - 1)]) translate([(overall_length / 2), (ycount * knob_spacing), 0]) cylinder(r = (pin_diameter / 2), h = (block_height * height), $fs = cylinder_precision);
}
}
knob_diameter = 4.8;
knob_height = 2;
knob_spacing = 8;
wall_thickness = 1.45;
roof_thickness = 1.05;
block_height = 9.5;
pin_diameter = 3;
post_diameter = 6.5;
reinforcing_width = 1.5;
axle_spline_width = 2;
axle_diameter = 5;
cylinder_precision = 0.5;
translate([0, 0, 10]) linear_extrude(1) circle(10, $fn = 10);
linear_extrude(1) polygon([let(r = 10) for(t = gen_facet_series(r, $fn = 10)) let(angle = (t * 360)) [(cos(angle) * r), (sin(angle) * r)]]);
post(5);
reinforcement(10);
MTH_triangleAreaFromLengths(3, 3, 9);
MTH_triangleAreaFromLengths(3, 3, 9);

Loading

0 comments on commit eb5f170

Please sign in to comment.