From eb326c7b402e4914e9a619b899a388be7668255b Mon Sep 17 00:00:00 2001 From: Aleksi Juvani Date: Tue, 8 Mar 2022 15:51:53 -0600 Subject: 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 95981c9876483256b28. 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 --- source/blender/blenkernel/intern/customdata.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc index 4492f8bbc64..b348e18a6a8 100644 --- a/source/blender/blenkernel/intern/customdata.cc +++ b/source/blender/blenkernel/intern/customdata.cc @@ -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, -- cgit v1.2.3