Wondering if anyone else has attempted to create screw threads using ICESL implicit functions. Here's my first attempt using an implicit_distance_field:
-- conical screw thread
r = 20.5
height = 40
shape = implicit_distance_field( v(-r,-r,0), v(r,r,height),
[[
uniform float base_radius = 12;
uniform float top_radius = 10;
uniform float height = 15;
uniform float th = 0.9;
float distance(vec3 p)
{
// thread size ratio
float fh = p.z / th;
// conical shape
float r = base_radius + (top_radius-base_radius) * (p.z/height);
// fade in the screw thread
float tr = min(2,
min(0.2*p.z*p.z,
0.2*(height-p.z)*(height-p.z)));
float cn = sqrt((p.x*p.x)+(p.y*p.y)) - r;
float drill_hole = 4 - sqrt((p.x*p.x)+(p.y*p.y));
return max(drill_hole, min(cn, sqrt(
(p.x+tr*cos(fh))*(p.x+tr*cos(fh)) +
(p.y+tr*sin(fh))*(p.y+tr*sin(fh))
) / (2*r) - 0.51));
}
]])
set_uniform_scalar(shape, 'base_radius', 12.4)
set_uniform_scalar(shape, 'top_radius', 9.2)
set_uniform_scalar(shape, 'height', height)
set_uniform_scalar(shape, 'th', 0.9)
emit(shape, 5)