mirror of
https://github.com/nophead/NopSCADlib.git
synced 2025-08-11 18:04:02 +02:00
Refactored for readability.
This commit is contained in:
@@ -88,49 +88,50 @@ module screw(type, length, hob_point = 0, nylon = false) { //! Draw specified sc
|
|||||||
vitamin(str("screw(", type[0], "_screw, ", length, arg(hob_point, 0, "hob_point"), arg(nylon, false, "nylon"), "): ", description));
|
vitamin(str("screw(", type[0], "_screw, ", length, arg(hob_point, 0, "hob_point"), arg(nylon, false, "nylon"), "): ", description));
|
||||||
|
|
||||||
head_type = screw_head_type(type);
|
head_type = screw_head_type(type);
|
||||||
rad = screw_radius(type) - eps;
|
shaft_rad = screw_radius(type) - eps;
|
||||||
head_rad = screw_head_radius(type);
|
head_rad = screw_head_radius(type);
|
||||||
head_height = screw_head_height(type);
|
head_height = screw_head_height(type);
|
||||||
socket_af = screw_socket_af(type);
|
socket_af = screw_socket_af(type);
|
||||||
socket_depth= screw_socket_depth(type);
|
socket_depth= screw_socket_depth(type);
|
||||||
socket_rad = socket_af / cos(30) / 2;
|
socket_rad = socket_af / cos(30) / 2;
|
||||||
max_thread = screw_max_thread(type);
|
max_thread = screw_max_thread(type);
|
||||||
thread_rad = is_undef(screw_thread_diameter(type)) ? rad : screw_thread_diameter(type) / 2 - eps;
|
has_shoulder = !is_undef(screw_thread_diameter(type));
|
||||||
|
thread_rad = has_shoulder ? screw_thread_diameter(type) / 2 : screw_radius(type);
|
||||||
thread = max_thread ? length >= max_thread + 5 ? max_thread
|
thread = max_thread ? length >= max_thread + 5 ? max_thread
|
||||||
: length
|
: length
|
||||||
: length;
|
: length;
|
||||||
thread_offset = is_undef(screw_thread_diameter(type)) ? 0 : thread;
|
thread_offset = has_shoulder ? thread : 0;
|
||||||
d = 2 * (thread_rad + eps);
|
thread_d = 2 * thread_rad;
|
||||||
pitch = metric_coarse_pitch(d);
|
pitch = metric_coarse_pitch(thread_d);
|
||||||
colour = nylon || head_type == hs_grub ? grey(40) : grey(80);
|
colour = nylon || head_type == hs_grub ? grey(40) : grey(80);
|
||||||
|
|
||||||
module shaft(socket = 0, headless = false) {
|
module shaft(socket = 0, headless = false) {
|
||||||
point = screw_nut(type) ? 0 : 3 * rad;
|
point = screw_nut(type) ? 0 : 3 * shaft_rad;
|
||||||
shank = length - socket - (is_undef(screw_thread_diameter(type)) ? thread : 0);
|
shank = length - socket - (has_shoulder ? 0 : thread);
|
||||||
|
|
||||||
if(show_threads && !point && pitch)
|
if(show_threads && !point && pitch)
|
||||||
translate_z(-length - thread_offset)
|
translate_z(-length - thread_offset)
|
||||||
male_metric_thread(d, pitch, thread - (shank > 0 || headless ? 0 : socket), false, top = headless ? -1 : 0, solid = !headless, colour = colour);
|
male_metric_thread(thread_d, pitch, thread - (shank > 0 || headless ? 0 : socket), false, top = headless ? -1 : 0, solid = !headless, colour = colour);
|
||||||
else
|
else
|
||||||
color(colour * 0.9)
|
color(colour * 0.9)
|
||||||
rotate_extrude() {
|
rotate_extrude() {
|
||||||
translate([0, -length + point - thread_offset])
|
translate([0, -length + point - thread_offset])
|
||||||
square([thread_rad, length - socket - point]);
|
square([thread_rad - eps, length - socket - point]);
|
||||||
|
|
||||||
if(point)
|
if(point)
|
||||||
polygon([
|
polygon([
|
||||||
[0.4, -length], [0, point - length], [rad, point - length]
|
[0.4, -length], [0, point - length], [shaft_rad, point - length]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(shank > 0)
|
if(shank > 0)
|
||||||
color(colour)
|
color(colour)
|
||||||
translate_z(-shank - socket)
|
translate_z(-shank - socket)
|
||||||
cylinder(r = rad + eps, h = shank);
|
cylinder(r = shaft_rad + eps, h = shank);
|
||||||
}
|
}
|
||||||
|
|
||||||
module cs_head(socket_rad, socket_depth) {
|
module cs_head(socket_rad, socket_depth) {
|
||||||
head_t = rad / 5;
|
head_t = shaft_rad / 5;
|
||||||
head_height = head_rad + head_t;
|
head_height = head_rad + head_t;
|
||||||
|
|
||||||
color(colour) {
|
color(colour) {
|
||||||
@@ -176,7 +177,7 @@ module screw(type, length, hob_point = 0, nylon = false) { //! Draw specified sc
|
|||||||
}
|
}
|
||||||
if(head_type == hs_grub) {
|
if(head_type == hs_grub) {
|
||||||
color(colour) {
|
color(colour) {
|
||||||
r = show_threads ? rad - pitch / 2 : rad;
|
r = show_threads ? shaft_rad - pitch / 2 : shaft_rad;
|
||||||
translate_z(-socket_depth)
|
translate_z(-socket_depth)
|
||||||
linear_extrude(socket_depth)
|
linear_extrude(socket_depth)
|
||||||
difference() {
|
difference() {
|
||||||
|
Reference in New Issue
Block a user