Fix for wobbly volume object outlines in the viewport
The outlines of volume grids in the viewport are noticeable "wobbly" when they should simply represent grid boxes. This is especially noticeable on simple regular grids such as the "Volume Cube" geometry node output. The reason is that the outlines generated by taking a triangulated mesh of the grid boxes and then growing it by successively scaling each triangle. The offset for each vertex grows proportional to its degree (number of connected edges). The fix is to divide each vertex's offset by its degree. The resulting mesh is much more regular and closer to to 1% desired growth factor. Old: ![Screenshot_20230829_155602](/attachments/87fbdca3-fb9d-49d8-b4f5-6780d1c72f79) New: ![Screenshot_20230829_155648](/attachments/4452c52b-96df-4200-a02f-3d0d8aa8680e) Pull Request: https://projects.blender.org/blender/blender/pulls/111657
This commit is contained in:
parent
87bf783479
commit
711c9c5553
|
@ -385,14 +385,20 @@ static void grow_triangles(blender::MutableSpan<blender::float3> verts,
|
|||
/* Compute the offset for every vertex based on the connected edges.
|
||||
* This formula simply tries increases the length of all edges. */
|
||||
blender::Array<blender::float3> offsets(verts.size(), {0, 0, 0});
|
||||
blender::Array<float> weights(verts.size(), 0.0f);
|
||||
for (const std::array<int, 3> &tri : tris) {
|
||||
offsets[tri[0]] += factor * (2 * verts[tri[0]] - verts[tri[1]] - verts[tri[2]]);
|
||||
offsets[tri[1]] += factor * (2 * verts[tri[1]] - verts[tri[0]] - verts[tri[2]]);
|
||||
offsets[tri[2]] += factor * (2 * verts[tri[2]] - verts[tri[0]] - verts[tri[1]]);
|
||||
weights[tri[0]] += 1.0;
|
||||
weights[tri[1]] += 1.0;
|
||||
weights[tri[2]] += 1.0;
|
||||
}
|
||||
/* Apply the computed offsets. */
|
||||
for (const int i : verts.index_range()) {
|
||||
verts[i] += offsets[i];
|
||||
if (weights[i] > 0.0f) {
|
||||
verts[i] += offsets[i] / weights[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* WITH_OPENVDB */
|
||||
|
|
Loading…
Reference in New Issue