7
$\begingroup$

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:

enter image description here

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?

$\endgroup$

1 Answer 1

1
$\begingroup$

That code snippet really solved this headache. You get the distance between every vertex (=edge length). That is essentially it. You then use that to influence the scaling along normals you do with your solidify modifier. As my mesh had different mesh densities, and thus lower lengths in said areas, I remapped, and removed the lower ranges of mesh density/higher values.

Initial Edge lengths

remove lower range/higher values

Remap to 1:0 range for use in scaling

Full Setup, every other node doesn't relate to this question

Regarding the angle clamp, I didn't need that so I havent tried to figure it out. But feeding code into chat gpt and making it explain to you whats happening should get you further than you were.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .