I am trying to build the Solidify modifier in geometry nodes. Generally this is simple as there are many ways to offset a copy of the geometry. And we have Extrude to create the Rim. However, I am stuck on the Thickness Clamp option, which is the primary thing I need.
The docs give this description, but its not specific enough to build from:
I've also looked into the source code. The relevant functions seem to be in source\blender\modifiers\intern\MOD_solidify_extrude.cc. This snippet seems to be it, and starts at line 869 (but there are other snippets that start with if (do_clamp) so I'm not entirely sure.) I'm not an advanced enough coder to figure out exactly what's going on here.
if (do_clamp) {
const float clamp_fac = 1 + (do_angle_clamp ? fabsf(smd->offset_fac) : 0);
const float offset = fabsf(smd->offset) * smd->offset_clamp * clamp_fac;
if (offset > FLT_EPSILON) {
float *vert_lens_sq = static_cast<float *>(
MEM_malloc_arrayN(verts_num, sizeof(float), "vert_lens_sq"));
const float offset_sq = offset * offset;
copy_vn_fl(vert_lens_sq, int(verts_num), FLT_MAX);
for (i = 0; i < edges_num; i++) {
const float ed_len = len_squared_v3v3(vert_positions[edges[i][0]],
vert_positions[edges[i][1]]);
vert_lens_sq[edges[i][0]] = min_ff(vert_lens_sq[edges[i][0]], ed_len);
vert_lens_sq[edges[i][1]] = min_ff(vert_lens_sq[edges[i][1]], ed_len);
}
if (do_angle_clamp) {
for (i = 0; i < verts_num; i++) {
float cos_ang = cosf(vert_angs[i] * 0.5f);
if (cos_ang > 0) {
float max_off = sqrtf(vert_lens_sq[i]) * 0.5f / cos_ang;
if (max_off < offset * 0.5f) {
vert_angles[i] *= max_off / offset * 2;
}
}
}
MEM_freeN(vert_angs);
}
else {
for (i = 0; i < verts_num; i++) {
if (vert_lens_sq[i] < offset_sq) {
float scalar = sqrtf(vert_lens_sq[i]) / offset;
vert_angles[i] *= scalar;
}
}
}
MEM_freeN(vert_lens_sq);
}
}
Has anybody built this already, or can explain what's happening?