From c209e618dba6f61ce7c7fdcaa0fb51b52ff4f7d3 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 22 Feb 2023 14:28:12 -0500 Subject: [PATCH 1/2] Fix: Curves sculpt add creates invalid resolution values If the resolution attribute exists, it needs to be set to a non-zero value for the newly added curves. While it might also make sense to interpolate the value from neighbor curves, for now it's simplest to just set it to the default value of 12. --- source/blender/geometry/intern/add_curves_on_mesh.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source/blender/geometry/intern/add_curves_on_mesh.cc b/source/blender/geometry/intern/add_curves_on_mesh.cc index 75de44cf15e..a481ee23a03 100644 --- a/source/blender/geometry/intern/add_curves_on_mesh.cc +++ b/source/blender/geometry/intern/add_curves_on_mesh.cc @@ -380,8 +380,15 @@ AddCurvesOnMeshOutputs add_curves_on_mesh(CurvesGeometry &curves, bke::MutableAttributeAccessor attributes = curves.attributes_for_write(); + if (bke::SpanAttributeWriter resolution = attributes.lookup_for_write_span( + "resulution")) { + resolution.span.take_back(new_curves_num).fill(12); + resolution.finish(); + } + /* Explicitly set all other attributes besides those processed above to default values. */ - Set attributes_to_skip{{"position", "curve_type", "surface_uv_coordinate"}}; + Set attributes_to_skip{ + {"position", "curve_type", "surface_uv_coordinate", "resolution"}}; attributes.for_all( [&](const bke::AttributeIDRef &id, const bke::AttributeMetaData /*meta_data*/) { if (attributes_to_skip.contains(id.name())) { -- 2.30.2 From 3b5295e0f691a330846c4311503bd9b624907a92 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 22 Feb 2023 17:34:32 -0500 Subject: [PATCH 2/2] Add interpolation, fix typos, proper testing! --- .../editors/sculpt_paint/curves_sculpt_add.cc | 3 ++- .../sculpt_paint/curves_sculpt_density.cc | 1 + .../blender/geometry/GEO_add_curves_on_mesh.hh | 1 + .../geometry/intern/add_curves_on_mesh.cc | 17 +++++++++++++---- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_add.cc b/source/blender/editors/sculpt_paint/curves_sculpt_add.cc index 75d2f70ba76..432309a5e72 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_add.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_add.cc @@ -225,6 +225,7 @@ struct AddOperationExecutor { BRUSH_CURVES_SCULPT_FLAG_INTERPOLATE_SHAPE; add_inputs.interpolate_point_count = brush_settings_->flag & BRUSH_CURVES_SCULPT_FLAG_INTERPOLATE_POINT_COUNT; + add_inputs.interpolate_resolution = curves_orig_->attributes().contains("resolution"); add_inputs.fallback_curve_length = brush_settings_->curve_length; add_inputs.fallback_point_count = std::max(2, brush_settings_->points_per_curve); add_inputs.transforms = &transforms_; @@ -234,7 +235,7 @@ struct AddOperationExecutor { add_inputs.corner_normals_su = corner_normals_su; if (add_inputs.interpolate_length || add_inputs.interpolate_shape || - add_inputs.interpolate_point_count) { + add_inputs.interpolate_point_count || add_inputs.interpolate_resolution) { this->ensure_curve_roots_kdtree(); add_inputs.old_roots_kdtree = self_->curve_roots_kdtree_; } diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_density.cc b/source/blender/editors/sculpt_paint/curves_sculpt_density.cc index 29a1ea9c306..cbdaaab4dc5 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_density.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_density.cc @@ -275,6 +275,7 @@ struct DensityAddOperationExecutor { BRUSH_CURVES_SCULPT_FLAG_INTERPOLATE_SHAPE; add_inputs.interpolate_point_count = brush_settings_->flag & BRUSH_CURVES_SCULPT_FLAG_INTERPOLATE_POINT_COUNT; + add_inputs.interpolate_resolution = curves_orig_->attributes().contains("resolution"); add_inputs.fallback_curve_length = brush_settings_->curve_length; add_inputs.fallback_point_count = std::max(2, brush_settings_->points_per_curve); add_inputs.transforms = &transforms_; diff --git a/source/blender/geometry/GEO_add_curves_on_mesh.hh b/source/blender/geometry/GEO_add_curves_on_mesh.hh index ceb0a2e3f13..39fa32d536b 100644 --- a/source/blender/geometry/GEO_add_curves_on_mesh.hh +++ b/source/blender/geometry/GEO_add_curves_on_mesh.hh @@ -25,6 +25,7 @@ struct AddCurvesOnMeshInputs { bool interpolate_length = false; bool interpolate_shape = false; bool interpolate_point_count = false; + bool interpolate_resolution = false; float fallback_curve_length = 0.0f; int fallback_point_count = 0; diff --git a/source/blender/geometry/intern/add_curves_on_mesh.cc b/source/blender/geometry/intern/add_curves_on_mesh.cc index a481ee23a03..aee002c49cd 100644 --- a/source/blender/geometry/intern/add_curves_on_mesh.cc +++ b/source/blender/geometry/intern/add_curves_on_mesh.cc @@ -243,7 +243,7 @@ AddCurvesOnMeshOutputs add_curves_on_mesh(CurvesGeometry &curves, AddCurvesOnMeshOutputs outputs; const bool use_interpolation = inputs.interpolate_length || inputs.interpolate_point_count || - inputs.interpolate_shape; + inputs.interpolate_shape || inputs.interpolate_resolution; Vector root_positions_cu; Vector bary_coords; @@ -381,9 +381,18 @@ AddCurvesOnMeshOutputs add_curves_on_mesh(CurvesGeometry &curves, bke::MutableAttributeAccessor attributes = curves.attributes_for_write(); if (bke::SpanAttributeWriter resolution = attributes.lookup_for_write_span( - "resulution")) { - resolution.span.take_back(new_curves_num).fill(12); - resolution.finish(); + "resolution")) { + if (inputs.interpolate_resolution) { + interpolate_from_neighbors( + neighbors_per_curve, + 12, + [&](const int curve_i) { return resolution.span[curve_i]; }, + resolution.span.take_back(added_curves_num)); + resolution.finish(); + } + else { + resolution.span.take_back(added_curves_num).fill(12); + } } /* Explicitly set all other attributes besides those processed above to default values. */ -- 2.30.2