Attributes: Implement CustomData interpolation for boolean data type

This commit fixes an issue, where for instance, when merging vertices
with the "Merge by Distance" geometry node, the resulting vertices had
their boolean attributes set unpredictably.

Boolean attributes are implemented as custom data, and when welding
vertices, the custom data for the resulting vertices comes from
interpolating the custom data of the source vertices.

This commit implements the missing interpolation function for the
boolean custom data type. This interpolation function is implemented in
terms of the logical or operation, that is to say, if any of the source
vertices (with a weight greater than zero) have the boolean set, the
boolean will also be set on the resulting vertex.

This logic matches 95981c9876.

In geometry nodes, attribute interpolation generally does not use the
CustomData API for performance reasons, but other areas of Blender
still do.

Differential Revision: https://developer.blender.org/D14172
This commit is contained in:
Aleksi Juvani 2022-03-08 15:51:53 -06:00 committed by Hans Goudey
parent 521d4190a0
commit eb326c7b40
1 changed files with 16 additions and 1 deletions

View File

@ -1450,6 +1450,21 @@ static bool layerValidate_propfloat2(void *data, const uint totitems, const bool
return has_errors;
}
static void layerInterp_propbool(const void **sources,
const float *weights,
const float *UNUSED(sub_weights),
int count,
void *dest)
{
bool result = false;
for (int i = 0; i < count; i++) {
const float interp_weight = weights[i];
const bool src = *(const bool *)sources[i];
result |= src && (interp_weight > 0.0f);
}
*(bool *)dest = result;
}
static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
/* 0: CD_MVERT */
{sizeof(MVert), "MVert", 1, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
@ -1838,7 +1853,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
N_("Boolean"),
nullptr,
nullptr,
nullptr,
layerInterp_propbool,
nullptr,
nullptr,
nullptr,