Fix for wobbly volume object outlines in the viewport #111657

Merged
Lukas Tönne merged 2 commits from LukasTonne/blender:fix_wobbly_volume_outline into main 2023-10-06 17:43:14 +02:00
1 changed files with 7 additions and 1 deletions

View File

@ -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 */