Fix broken CD_NORMAL interpolation callback (would generate non-unit vectors).

Even if the weights are normalized, the weighted sum of normalized vectors
usually does **not** give a normalized vector (unless all source vectors
are aligned).

This probably was not a big issue in most cases, since we usually interpolate
similar vectors here - but still!
This commit is contained in:
Bastien Montagne 2015-10-16 21:52:50 +02:00
parent 8172712841
commit bfdb42047a
Notes: blender-bot 2023-02-14 10:01:16 +01:00
Referenced by issue #46536, Viewport: Selecting many objects causes constant CPU usage
Referenced by issue #46520, mathutils.bvhtree crashes with distance input
Referenced by issue #46521, Python: bvh.ray_cast doesn't find a plane facing in the other direction under certain circumstances
Referenced by issue #42020, BGE crashes when LibLoading multiple files asynchronously
1 changed files with 4 additions and 1 deletions

View File

@ -307,13 +307,16 @@ static void layerInterp_normal(
const void **sources, const float *weights,
const float *UNUSED(sub_weights), int count, void *dest)
{
/* Note: This is linear interpolation, which is not optimal for vectors.
* Unfortunately, spherical interpolation of more than two values is hairy, so for now it will do... */
float no[3] = {0.0f};
while (count--) {
madd_v3_v3fl(no, (const float *)sources[count], weights[count]);
}
copy_v3_v3((float *)dest, no);
/* Weighted sum of normalized vectors will **not** be normalized, even if weights are. */
normalize_v3_v3((float *)dest, no);
}
static void layerCopyValue_normal(const void *source, void *dest, const int mixmode, const float mixfactor)