Commit: c26616b2c1d69350cc75117c2bbc0bbc85138086 Author: Hans Goudey Date: Tue Jan 3 22:59:25 2023 -0500 Branches: master https://developer.blender.org/rBc26616b2c1d69350cc75117c2bbc0bbc85138086
Curves: Support boolean attribute selection type, simplifications Use the same `".selection"` attribute for both curve and point domains, instead of a different name for each. The attribute can now have either boolean or float type. Some tools create boolean selections. Other tools create float selections. Some tools "upgrade" the attribute from boolean to float. Edit mode tools that create selections from scratch can create boolean selections, but edit mode should generally be able to handle both selection types. Sculpt mode should be able to read boolean selections, but can also and write float values between zero and one. Theoretically we could just always use floats to store selections, but the type-agnosticism doesn't cost too much complexity given the existing APIs for dealing with it, and being able to use booleans is clearer in edit mode, and may allow future optimizations like more efficient ways to store boolean attributes. The attribute API is usually used directly for accessing the selection attribute. We rely on implicit type conversion and domain interpolation to simplify the rest of the code. Differential Revision: https://developer.blender.org/D16057 =================================================================== M source/blender/blenkernel/BKE_curves.hh M source/blender/blenkernel/intern/curves_geometry.cc M source/blender/blenlib/BLI_array_utils.hh M source/blender/blenlib/intern/array_utils.cc M source/blender/blenloader/intern/versioning_300.cc M source/blender/draw/engines/overlay/overlay_sculpt_curves.cc M source/blender/draw/intern/draw_cache_impl_curves.cc M source/blender/editors/curves/CMakeLists.txt M source/blender/editors/curves/intern/curves_ops.cc A source/blender/editors/curves/intern/curves_selection.cc M source/blender/editors/include/ED_curves.h M source/blender/editors/include/ED_curves_sculpt.h M source/blender/editors/sculpt_paint/curves_sculpt_add.cc M source/blender/editors/sculpt_paint/curves_sculpt_comb.cc M source/blender/editors/sculpt_paint/curves_sculpt_delete.cc M source/blender/editors/sculpt_paint/curves_sculpt_density.cc M source/blender/editors/sculpt_paint/curves_sculpt_grow_shrink.cc M source/blender/editors/sculpt_paint/curves_sculpt_intern.hh M source/blender/editors/sculpt_paint/curves_sculpt_ops.cc M source/blender/editors/sculpt_paint/curves_sculpt_pinch.cc M source/blender/editors/sculpt_paint/curves_sculpt_puff.cc M source/blender/editors/sculpt_paint/curves_sculpt_selection.cc M source/blender/editors/sculpt_paint/curves_sculpt_selection_paint.cc M source/blender/editors/sculpt_paint/curves_sculpt_slide.cc M source/blender/editors/sculpt_paint/curves_sculpt_smooth.cc M source/blender/editors/sculpt_paint/curves_sculpt_snake_hook.cc M source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc M source/blender/geometry/GEO_add_curves_on_mesh.hh M source/blender/geometry/intern/add_curves_on_mesh.cc M source/blender/modifiers/intern/MOD_mask.cc =================================================================== diff --git a/source/blender/blenkernel/BKE_curves.hh b/source/blender/blenkernel/BKE_curves.hh index 9382a912c02..31776676940 100644 --- a/source/blender/blenkernel/BKE_curves.hh +++ b/source/blender/blenkernel/BKE_curves.hh @@ -287,11 +287,6 @@ class CurvesGeometry : public ::CurvesGeometry { Span<float2> surface_uv_coords() const; MutableSpan<float2> surface_uv_coords_for_write(); - VArray<float> selection_point_float() const; - MutableSpan<float> selection_point_float_for_write(); - VArray<float> selection_curve_float() const; - MutableSpan<float> selection_curve_float_for_write(); - /** * Calculate the largest and smallest position values, only including control points * (rather than evaluated points). The existing values of `min` and `max` are taken into account. diff --git a/source/blender/blenkernel/intern/curves_geometry.cc b/source/blender/blenkernel/intern/curves_geometry.cc index 5cbb0709c91..401dd113f2c 100644 --- a/source/blender/blenkernel/intern/curves_geometry.cc +++ b/source/blender/blenkernel/intern/curves_geometry.cc @@ -38,8 +38,6 @@ static const std::string ATTR_HANDLE_POSITION_RIGHT = "handle_right"; static const std::string ATTR_NURBS_ORDER = "nurbs_order"; static const std::string ATTR_NURBS_WEIGHT = "nurbs_weight"; static const std::string ATTR_NURBS_KNOTS_MODE = "knots_mode"; -static const std::string ATTR_SELECTION_POINT_FLOAT = ".selection_point_float"; -static const std::string ATTR_SELECTION_CURVE_FLOAT = ".selection_curve_float"; static const std::string ATTR_SURFACE_UV_COORDINATE = "surface_uv_coordinate"; /* -------------------------------------------------------------------- */ @@ -433,26 +431,6 @@ MutableSpan<float2> CurvesGeometry::surface_uv_coords_for_write() return get_mutable_attribute<float2>(*this, ATTR_DOMAIN_CURVE, ATTR_SURFACE_UV_COORDINATE); } -VArray<float> CurvesGeometry::selection_point_float() const -{ - return get_varray_attribute<float>(*this, ATTR_DOMAIN_POINT, ATTR_SELECTION_POINT_FLOAT, 1.0f); -} - -MutableSpan<float> CurvesGeometry::selection_point_float_for_write() -{ - return get_mutable_attribute<float>(*this, ATTR_DOMAIN_POINT, ATTR_SELECTION_POINT_FLOAT, 1.0f); -} - -VArray<float> CurvesGeometry::selection_curve_float() const -{ - return get_varray_attribute<float>(*this, ATTR_DOMAIN_CURVE, ATTR_SELECTION_CURVE_FLOAT, 1.0f); -} - -MutableSpan<float> CurvesGeometry::selection_curve_float_for_write() -{ - return get_mutable_attribute<float>(*this, ATTR_DOMAIN_CURVE, ATTR_SELECTION_CURVE_FLOAT, 1.0f); -} - /** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/blenlib/BLI_array_utils.hh b/source/blender/blenlib/BLI_array_utils.hh index 264ac00e034..81ffa7eade8 100644 --- a/source/blender/blenlib/BLI_array_utils.hh +++ b/source/blender/blenlib/BLI_array_utils.hh @@ -112,4 +112,6 @@ inline void gather(const VArray<T> &src, }); } +void invert_booleans(MutableSpan<bool> span); + } // namespace blender::array_utils diff --git a/source/blender/blenlib/intern/array_utils.cc b/source/blender/blenlib/intern/array_utils.cc index 2a231228dcb..1b5b071f0cd 100644 --- a/source/blender/blenlib/intern/array_utils.cc +++ b/source/blender/blenlib/intern/array_utils.cc @@ -33,4 +33,13 @@ void gather(const GSpan src, const IndexMask indices, GMutableSpan dst, const in gather(GVArray::ForSpan(src), indices, dst, grain_size); } +void invert_booleans(MutableSpan<bool> span) +{ + threading::parallel_for(span.index_range(), 4096, [&](IndexRange range) { + for (const int i : range) { + span[i] = !span[i]; + } + }); +} + } // namespace blender::array_utils diff --git a/source/blender/blenloader/intern/versioning_300.cc b/source/blender/blenloader/intern/versioning_300.cc index adc88a7caf5..4d9bbdfce77 100644 --- a/source/blender/blenloader/intern/versioning_300.cc +++ b/source/blender/blenloader/intern/versioning_300.cc @@ -50,6 +50,7 @@ #include "BKE_collection.h" #include "BKE_colortools.h" #include "BKE_curve.h" +#include "BKE_curves.hh" #include "BKE_data_transfer.h" #include "BKE_deform.h" #include "BKE_fcurve.h" @@ -3850,5 +3851,9 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) LISTBASE_FOREACH (Curves *, curves_id, &bmain->hair_curves) { curves_id->flag &= ~CV_SCULPT_SELECTION_ENABLED; } + LISTBASE_FOREACH (Curves *, curves_id, &bmain->hair_curves) { + BKE_id_attribute_rename(&curves_id->id, ".selection_point_float", ".selection", nullptr); + BKE_id_attribute_rename(&curves_id->id, ".selection_curve_float", ".selection", nullptr); + } } } diff --git a/source/blender/draw/engines/overlay/overlay_sculpt_curves.cc b/source/blender/draw/engines/overlay/overlay_sculpt_curves.cc index 73edf9dc5d3..40abfad12f5 100644 --- a/source/blender/draw/engines/overlay/overlay_sculpt_curves.cc +++ b/source/blender/draw/engines/overlay/overlay_sculpt_curves.cc @@ -10,6 +10,7 @@ #include "draw_cache_impl.h" #include "overlay_private.hh" +#include "BKE_attribute.hh" #include "BKE_curves.hh" void OVERLAY_sculpt_curves_cache_init(OVERLAY_Data *vedata) @@ -31,18 +32,11 @@ void OVERLAY_sculpt_curves_cache_init(OVERLAY_Data *vedata) static bool everything_selected(const Curves &curves_id) { - const blender::bke::CurvesGeometry &curves = blender::bke::CurvesGeometry::wrap( - curves_id.geometry); - blender::VArray<float> selection; - switch (curves_id.selection_domain) { - case ATTR_DOMAIN_POINT: - selection = curves.selection_point_float(); - break; - case ATTR_DOMAIN_CURVE: - selection = curves.selection_curve_float(); - break; - } - return selection.is_single() && selection.get_internal_single() == 1.0f; + using namespace blender; + const bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id.geometry); + const VArray<bool> selection = curves.attributes().lookup_or_default<bool>( + ".selection", ATTR_DOMAIN_POINT, true); + return selection.is_single() && selection.get_internal_single(); } void OVERLAY_sculpt_curves_cache_populate(OVERLAY_Data *vedata, Object *object) @@ -56,12 +50,9 @@ void OVERLAY_sculpt_curves_cache_populate(OVERLAY_Data *vedata, Object *object) } /* Retrieve the location of the texture. */ - const char *name = curves->selection_domain == ATTR_DOMAIN_POINT ? ".selection_point_float" : - ".selection_curve_float"; - bool is_point_domain; GPUVertBuf **texture = DRW_curves_texture_for_evaluated_attribute( - curves, name, &is_point_domain); + curves, ".selection", &is_point_domain); if (texture == nullptr) { return; } diff --git a/source/blender/draw/intern/draw_cache_impl_curves.cc b/source/blender/draw/intern/draw_cache_impl_curves.cc index 43ce533f8d1..4fb25113f57 100644 --- a/source/blender/draw/intern/draw_cache_impl_curves.cc +++ b/source/blender/draw/intern/draw_cache_impl_curves.cc @@ -11,6 +11,7 @@ #include "MEM_guardedalloc.h" +#include "BLI_devirtualize_parameters.hh" #include "BLI_listbase.h" #include "BLI_math_base.h" #include "BLI_math_vec_types.hh" @@ -334,17 +335,16 @@ static void curves_batch_cache_ensure_edit_points_data(const Curves &curves_id, GPU_vertbuf_init_with_format(cache.edit_points_data, &format_data); GPU_vertbuf_data_alloc(cache.edit_points_data, curves.points_num()); - VArray<float> selection; + const VArray<bool> selection = curves.attributes().lookup_or_default<bool>( + ".selection", eAttrDomain(curves_id.selection_domain), true); switch (curves_id.selection_domain) { case ATTR_DOMAIN_POINT: - selection = curves.selection_point_float(); for (const int point_i : selection.index_range()) { const float point_selection = (selection[point_i] > 0.0f) ? 1.0f : 0.0f; GPU_vertbuf_attr_set(cache.edit_points_data, color, point_i, &point_selection); } break; case ATTR_DOMAIN_CURVE: - selection = curves.selection_curve_float(); for (const int curve_i : curves.curves_range()) { const float curve_selection = (selection[curve_i] > 0.0f) ? 1.0f : 0.0f; const IndexRange points = curves.points_for_curve(curve_i); diff --git a/source/blender/editors/curves/CMakeLists.txt b/source/blender/editors/curves/CMakeLists.txt index 945bba0a77c..4d81b4454ac 100644 --- a/source/blender/editors/curves/CMakeLists.txt +++ b/source/blender/editors/curves/CMakeLists.txt @@ -22,6 +22,7 @@ set(INC set(SRC intern/curves_add.cc intern/curves_ops.cc + intern/curves_selection.cc ) set(LIB diff --git a/source/blender/editors/curves/intern/curves_ops.cc b/source/blender/editors/curves/intern/curves_ops.cc index 880470ea66f..924967aad8a 100644 --- a/source/blender/editors/curves/intern/curves_ops.cc +++ b/source/blender/editors/curves/intern/curves_ops.cc @@ -6,7 +6,9 @@ #include <atomic> +#include "BLI_array_utils.hh" #include "BLI_devirtualize_parameters.hh" +#include "BLI_index_mask_ops.hh" #include "BLI_utildefines.h" #include "BLI_vector_set.hh" @@ -748,7 +750,6 @@ static int curves_set_selection_domain_exec(bContext *C, wmOperator *op) continue; } - const eAttrDomain old_domain = eAttrDomain(curves_id->selection_domain); curves_id->selection_domain = domain; CurvesGeometry &curves = CurvesGeometry::wrap(curves_id->geometry); @@ -756,18 +757,21 @@ static int curves_set_selection_domain_exec(bContext *C, wmOperator *op) if (curves.points_num() == 0) { continue; } - - if (old_domain == ATTR_DOMAIN_POINT && domain == ATTR_DOMAIN_CURVE) { - VArray<float> curve_selection = curves.adapt_domain( - curves.selection_point_float(), ATTR_DOMAIN_POINT, ATTR_DOMAIN_CURVE); - curve_selection.materialize(curves.selection_curve_float_for_write()); - attributes.remove(".selection_point_float"); + const GVArray src = attributes.lookup(".selection", domain); + if (src.is_empty()) { + continue; } - else if (old_domain == ATTR_DOMAIN_CURVE && domain == ATTR_DOMAIN_POINT) { - VArray<float> point_selection = curves.adapt_domain( - curves.selecti @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list [email protected] List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
