Add initial code to seed script

This commit is contained in:
Kurt Hutten
2021-10-17 10:23:49 +11:00
parent 0bc759cf9e
commit da0a4d6f1c

View File

@@ -55,6 +55,8 @@ async function main() {
title: 'demo-project1',
description: '# can be markdown',
mainImage: 'CadHub/kjdlgjnu0xmwksia7xox',
code: getOpenScadHingeCode(),
cadPackage: 'openscad',
user: {
connect: {
id: users[0].id,
@@ -132,3 +134,117 @@ main()
.finally(async () => {
await db.$disconnect()
})
function getOpenScadHingeCode () {
return `
baseWidth=15; // [0.1:0.1:50]
hingeLength=30; // [0.1:0.1:50]
// Hole mant mounting holes per half.
mountingHoleCount=3; // [1:20]
baseThickness=3; // [0.1:0.1:20]
pivotRadius=5; // [0.1:0.1:20]
// Pin that the hinge pivots on.
pinRadius=2; // [0.1:0.1:20]
mountingHoleRadius=1.5; // [0.1:0.1:10]
// How far away the hole is from the egde.
mountingHoleEdgeOffset=4; // [0:50]
// Depending on the accuracy of your printer this may need to be increased in order for print in place to work.
clearance=0.2; // [0.05:0.01:1]
// Radius difference in the ivot taper to stop the hinge from falling apart. Should be increased with large clearance values.
pinTaper=0.25; // [0.1:0.1:2]
// calculated values
hingeHalfExtrudeLength=hingeLength/2-clearance/2;
mountingHoleMoveIncrement=(hingeLength-2*mountingHoleEdgeOffset)/
(mountingHoleCount-1);
module costomizerEnd() {}
$fn=30;
tiny=0.005;
// modules
module hingeBaseProfile() {
translate([pivotRadius,0,0]){
square([baseWidth,baseThickness]);
}
}
module hingeBodyHalf() {
difference() {
union() {
linear_extrude(hingeHalfExtrudeLength){
offset(1)offset(-2)offset(1){
translate([0,pivotRadius,0]){
circle(pivotRadius);
}
square([pivotRadius,pivotRadius]);
hingeBaseProfile();
}
}
linear_extrude(hingeLength){
offset(1)offset(-1)hingeBaseProfile();
}
}
plateHoles();
}
}
module pin(rotateY, radiusOffset) {
translate([0,pivotRadius,hingeHalfExtrudeLength+tiny]){
rotate([0,rotateY,0]) {
cylinder(
h=hingeLength/2+clearance/2,
r1=pinRadius+radiusOffset,
r2=pinRadius+pinTaper+radiusOffset
);
}
}
}
module hingeHalfFemale() {
difference() {
hingeBodyHalf();
pin(rotateY=180, radiusOffset=clearance);
}
}
module hingeHalfMale() {
translate([0,0,hingeLength]) {
rotate([0,180,0]) {
hingeBodyHalf();
pin(rotateY=0, radiusOffset=0);
}
}
}
module plateHoles() {
for(i=[0:mountingHoleCount-1]){
translate([
baseWidth/2+pivotRadius,
-baseThickness,
i*mountingHoleMoveIncrement+mountingHoleEdgeOffset
]){
rotate([-90,0,0]){
cylinder(r=mountingHoleRadius,h=baseThickness*4);
}
}
}
}
// using high-level modules
translate([0,0,-15]) {
hingeHalfFemale();
hingeHalfMale();
}
`
}