Revert "Refactor: Sculpt: Move original position restore to brush deform step"
This reverts commit 93054f9a0e.
I had forgotten the reason for this separate "restore" step before the brush
deform evaluation was because multiple symmetry steps can be processed in the
same BVH node, in which case we can't just overwrite the values from the last
symmetry step.
Fixes #126445.
This commit is contained in:
@@ -31,7 +31,6 @@ namespace blender::ed::sculpt_paint {
|
||||
inline namespace elastic_deform_cc {
|
||||
|
||||
struct LocalData {
|
||||
Vector<float3> positions;
|
||||
Vector<float> factors;
|
||||
Vector<float3> translations;
|
||||
};
|
||||
@@ -100,9 +99,8 @@ static void calc_faces(const Depsgraph &depsgraph,
|
||||
const StrokeCache &cache = *ss.cache;
|
||||
Mesh &mesh = *static_cast<Mesh *>(object.data);
|
||||
|
||||
const Span<int> verts = bke::pbvh::node_unique_verts(node);
|
||||
const Span<float3> positions = gather_data_mesh(positions_eval, verts, tls.positions);
|
||||
const OrigPositionData orig_data = orig_position_data_get_mesh(object, node);
|
||||
const Span<int> verts = bke::pbvh::node_unique_verts(node);
|
||||
|
||||
tls.factors.resize(verts.size());
|
||||
const MutableSpan<float> factors = tls.factors;
|
||||
@@ -115,8 +113,8 @@ static void calc_faces(const Depsgraph &depsgraph,
|
||||
const MutableSpan<float3> translations = tls.translations;
|
||||
calc_translations(
|
||||
brush, cache, kelvinet_params, cache.location, offset, orig_data.positions, translations);
|
||||
|
||||
scale_translations(translations, factors);
|
||||
reset_translations_to_original(translations, positions, orig_data.positions);
|
||||
|
||||
write_translations(depsgraph, sd, object, positions_eval, verts, translations, positions_orig);
|
||||
}
|
||||
@@ -133,24 +131,25 @@ static void calc_grids(const Depsgraph &depsgraph,
|
||||
SculptSession &ss = *object.sculpt;
|
||||
const StrokeCache &cache = *ss.cache;
|
||||
SubdivCCG &subdiv_ccg = *ss.subdiv_ccg;
|
||||
const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg);
|
||||
|
||||
const Span<int> grids = bke::pbvh::node_grid_indices(node);
|
||||
const Span<float3> positions = gather_grids_positions(subdiv_ccg, grids, tls.positions);
|
||||
const OrigPositionData orig_data = orig_position_data_get_grids(object, node);
|
||||
const Span<int> grids = bke::pbvh::node_grid_indices(node);
|
||||
const int grid_verts_num = grids.size() * key.grid_area;
|
||||
|
||||
tls.factors.resize(positions.size());
|
||||
tls.factors.resize(grid_verts_num);
|
||||
const MutableSpan<float> factors = tls.factors;
|
||||
fill_factor_from_hide_and_mask(subdiv_ccg, grids, factors);
|
||||
filter_region_clip_factors(ss, orig_data.positions, factors);
|
||||
|
||||
auto_mask::calc_grids_factors(depsgraph, object, cache.automasking.get(), node, grids, factors);
|
||||
|
||||
tls.translations.resize(positions.size());
|
||||
tls.translations.resize(grid_verts_num);
|
||||
const MutableSpan<float3> translations = tls.translations;
|
||||
calc_translations(
|
||||
brush, cache, kelvinet_params, cache.location, offset, orig_data.positions, translations);
|
||||
|
||||
scale_translations(translations, factors);
|
||||
reset_translations_to_original(translations, positions, orig_data.positions);
|
||||
|
||||
clip_and_lock_translations(sd, ss, orig_data.positions, translations);
|
||||
apply_translations(translations, grids, subdiv_ccg);
|
||||
@@ -169,9 +168,10 @@ static void calc_bmesh(const Depsgraph &depsgraph,
|
||||
const StrokeCache &cache = *ss.cache;
|
||||
|
||||
const Set<BMVert *, 0> &verts = BKE_pbvh_bmesh_node_unique_verts(&node);
|
||||
const Span<float3> positions = gather_bmesh_positions(verts, tls.positions);
|
||||
|
||||
Array<float3> orig_positions(verts.size());
|
||||
orig_position_data_gather_bmesh(*ss.bm_log, verts, orig_positions, {});
|
||||
Array<float3> orig_normals(verts.size());
|
||||
orig_position_data_gather_bmesh(*ss.bm_log, verts, orig_positions, orig_normals);
|
||||
|
||||
tls.factors.resize(verts.size());
|
||||
const MutableSpan<float> factors = tls.factors;
|
||||
@@ -184,8 +184,8 @@ static void calc_bmesh(const Depsgraph &depsgraph,
|
||||
const MutableSpan<float3> translations = tls.translations;
|
||||
calc_translations(
|
||||
brush, cache, kelvinet_params, cache.location, offset, orig_positions, translations);
|
||||
|
||||
scale_translations(translations, factors);
|
||||
reset_translations_to_original(translations, positions, orig_positions);
|
||||
|
||||
clip_and_lock_translations(sd, ss, orig_positions, translations);
|
||||
apply_translations(translations, verts);
|
||||
|
||||
@@ -30,7 +30,6 @@ namespace blender::ed::sculpt_paint {
|
||||
inline namespace grab_cc {
|
||||
|
||||
struct LocalData {
|
||||
Vector<float3> positions;
|
||||
Vector<float> factors;
|
||||
Vector<float> distances;
|
||||
Vector<float3> translations;
|
||||
@@ -64,9 +63,8 @@ static void calc_faces(const Depsgraph &depsgraph,
|
||||
const StrokeCache &cache = *ss.cache;
|
||||
Mesh &mesh = *static_cast<Mesh *>(object.data);
|
||||
|
||||
const Span<int> verts = bke::pbvh::node_unique_verts(node);
|
||||
const Span<float3> positions = gather_data_mesh(positions_eval, verts, tls.positions);
|
||||
const OrigPositionData orig_data = orig_position_data_get_mesh(object, node);
|
||||
const Span<int> verts = bke::pbvh::node_unique_verts(node);
|
||||
|
||||
tls.factors.resize(verts.size());
|
||||
const MutableSpan<float> factors = tls.factors;
|
||||
@@ -95,7 +93,6 @@ static void calc_faces(const Depsgraph &depsgraph,
|
||||
tls.translations.resize(verts.size());
|
||||
const MutableSpan<float3> translations = tls.translations;
|
||||
translations_from_offset_and_factors(offset, factors, translations);
|
||||
reset_translations_to_original(translations, positions, orig_data.positions);
|
||||
|
||||
write_translations(depsgraph, sd, object, positions_eval, verts, translations, positions_orig);
|
||||
}
|
||||
@@ -111,12 +108,13 @@ static void calc_grids(const Depsgraph &depsgraph,
|
||||
SculptSession &ss = *object.sculpt;
|
||||
const StrokeCache &cache = *ss.cache;
|
||||
SubdivCCG &subdiv_ccg = *ss.subdiv_ccg;
|
||||
const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg);
|
||||
|
||||
const Span<int> grids = bke::pbvh::node_grid_indices(node);
|
||||
const Span<float3> positions = gather_grids_positions(subdiv_ccg, grids, tls.positions);
|
||||
const OrigPositionData orig_data = orig_position_data_get_grids(object, node);
|
||||
const Span<int> grids = bke::pbvh::node_grid_indices(node);
|
||||
const int grid_verts_num = grids.size() * key.grid_area;
|
||||
|
||||
tls.factors.resize(positions.size());
|
||||
tls.factors.resize(grid_verts_num);
|
||||
const MutableSpan<float> factors = tls.factors;
|
||||
fill_factor_from_hide_and_mask(subdiv_ccg, grids, factors);
|
||||
filter_region_clip_factors(ss, orig_data.positions, factors);
|
||||
@@ -124,7 +122,7 @@ static void calc_grids(const Depsgraph &depsgraph,
|
||||
calc_front_face(cache.view_normal, orig_data.normals, factors);
|
||||
}
|
||||
|
||||
tls.distances.resize(positions.size());
|
||||
tls.distances.resize(grid_verts_num);
|
||||
const MutableSpan<float> distances = tls.distances;
|
||||
calc_brush_distances(
|
||||
ss, orig_data.positions, eBrushFalloffShape(brush.falloff_shape), distances);
|
||||
@@ -140,10 +138,9 @@ static void calc_grids(const Depsgraph &depsgraph,
|
||||
calc_silhouette_factors(cache, offset, orig_data.normals, factors);
|
||||
}
|
||||
|
||||
tls.translations.resize(positions.size());
|
||||
tls.translations.resize(grid_verts_num);
|
||||
const MutableSpan<float3> translations = tls.translations;
|
||||
translations_from_offset_and_factors(offset, factors, translations);
|
||||
reset_translations_to_original(translations, positions, orig_data.positions);
|
||||
|
||||
clip_and_lock_translations(sd, ss, orig_data.positions, translations);
|
||||
apply_translations(translations, grids, subdiv_ccg);
|
||||
@@ -161,7 +158,7 @@ static void calc_bmesh(const Depsgraph &depsgraph,
|
||||
const StrokeCache &cache = *ss.cache;
|
||||
|
||||
const Set<BMVert *, 0> &verts = BKE_pbvh_bmesh_node_unique_verts(&node);
|
||||
const Span<float3> positions = gather_bmesh_positions(verts, tls.positions);
|
||||
|
||||
Array<float3> orig_positions(verts.size());
|
||||
Array<float3> orig_normals(verts.size());
|
||||
orig_position_data_gather_bmesh(*ss.bm_log, verts, orig_positions, orig_normals);
|
||||
@@ -192,7 +189,6 @@ static void calc_bmesh(const Depsgraph &depsgraph,
|
||||
tls.translations.resize(verts.size());
|
||||
const MutableSpan<float3> translations = tls.translations;
|
||||
translations_from_offset_and_factors(offset, factors, translations);
|
||||
reset_translations_to_original(translations, positions, orig_positions);
|
||||
|
||||
clip_and_lock_translations(sd, ss, orig_positions, translations);
|
||||
apply_translations(translations, verts);
|
||||
|
||||
@@ -31,7 +31,6 @@ namespace blender::ed::sculpt_paint {
|
||||
inline namespace rotate_cc {
|
||||
|
||||
struct LocalData {
|
||||
Vector<float3> positions;
|
||||
Vector<float> factors;
|
||||
Vector<float> distances;
|
||||
Vector<float3> translations;
|
||||
@@ -68,9 +67,8 @@ static void calc_faces(const Depsgraph &depsgraph,
|
||||
const StrokeCache &cache = *ss.cache;
|
||||
Mesh &mesh = *static_cast<Mesh *>(object.data);
|
||||
|
||||
const Span<int> verts = bke::pbvh::node_unique_verts(node);
|
||||
const Span<float3> positions = gather_data_mesh(positions_eval, verts, tls.positions);
|
||||
const OrigPositionData orig_data = orig_position_data_get_mesh(object, node);
|
||||
const Span<int> verts = bke::pbvh::node_unique_verts(node);
|
||||
|
||||
tls.factors.resize(verts.size());
|
||||
const MutableSpan<float> factors = tls.factors;
|
||||
@@ -98,7 +96,6 @@ static void calc_faces(const Depsgraph &depsgraph,
|
||||
const MutableSpan<float3> translations = tls.translations;
|
||||
calc_translations(
|
||||
orig_data.positions, cache.sculpt_normal_symm, factors, cache.location, translations);
|
||||
reset_translations_to_original(translations, positions, orig_data.positions);
|
||||
|
||||
write_translations(depsgraph, sd, object, positions_eval, verts, translations, positions_orig);
|
||||
}
|
||||
@@ -114,12 +111,13 @@ static void calc_grids(const Depsgraph &depsgraph,
|
||||
SculptSession &ss = *object.sculpt;
|
||||
const StrokeCache &cache = *ss.cache;
|
||||
SubdivCCG &subdiv_ccg = *ss.subdiv_ccg;
|
||||
const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg);
|
||||
|
||||
const Span<int> grids = bke::pbvh::node_grid_indices(node);
|
||||
const Span<float3> positions = gather_grids_positions(subdiv_ccg, grids, tls.positions);
|
||||
const OrigPositionData orig_data = orig_position_data_get_grids(object, node);
|
||||
const Span<int> grids = bke::pbvh::node_grid_indices(node);
|
||||
const int grid_verts_num = grids.size() * key.grid_area;
|
||||
|
||||
tls.factors.resize(positions.size());
|
||||
tls.factors.resize(grid_verts_num);
|
||||
const MutableSpan<float> factors = tls.factors;
|
||||
fill_factor_from_hide_and_mask(subdiv_ccg, grids, factors);
|
||||
filter_region_clip_factors(ss, orig_data.positions, factors);
|
||||
@@ -128,7 +126,7 @@ static void calc_grids(const Depsgraph &depsgraph,
|
||||
calc_front_face(cache.view_normal, orig_data.normals, factors);
|
||||
}
|
||||
|
||||
tls.distances.resize(positions.size());
|
||||
tls.distances.resize(grid_verts_num);
|
||||
const MutableSpan<float> distances = tls.distances;
|
||||
calc_brush_distances(
|
||||
ss, orig_data.positions, eBrushFalloffShape(brush.falloff_shape), distances);
|
||||
@@ -142,11 +140,10 @@ static void calc_grids(const Depsgraph &depsgraph,
|
||||
|
||||
scale_factors(factors, angle);
|
||||
|
||||
tls.translations.resize(positions.size());
|
||||
tls.translations.resize(grid_verts_num);
|
||||
const MutableSpan<float3> translations = tls.translations;
|
||||
calc_translations(
|
||||
orig_data.positions, cache.sculpt_normal_symm, factors, cache.location, translations);
|
||||
reset_translations_to_original(translations, positions, orig_data.positions);
|
||||
|
||||
clip_and_lock_translations(sd, ss, orig_data.positions, translations);
|
||||
apply_translations(translations, grids, subdiv_ccg);
|
||||
@@ -164,7 +161,7 @@ static void calc_bmesh(const Depsgraph &depsgraph,
|
||||
const StrokeCache &cache = *ss.cache;
|
||||
|
||||
const Set<BMVert *, 0> &verts = BKE_pbvh_bmesh_node_unique_verts(&node);
|
||||
const Span<float3> positions = gather_bmesh_positions(verts, tls.positions);
|
||||
|
||||
Array<float3> orig_positions(verts.size());
|
||||
Array<float3> orig_normals(verts.size());
|
||||
orig_position_data_gather_bmesh(*ss.bm_log, verts, orig_positions, orig_normals);
|
||||
@@ -194,7 +191,6 @@ static void calc_bmesh(const Depsgraph &depsgraph,
|
||||
const MutableSpan<float3> translations = tls.translations;
|
||||
calc_translations(
|
||||
orig_positions, cache.sculpt_normal_symm, factors, cache.location, translations);
|
||||
reset_translations_to_original(translations, positions, orig_positions);
|
||||
|
||||
clip_and_lock_translations(sd, ss, orig_positions, translations);
|
||||
apply_translations(translations, verts);
|
||||
|
||||
@@ -30,7 +30,6 @@ namespace blender::ed::sculpt_paint {
|
||||
inline namespace thumb_cc {
|
||||
|
||||
struct LocalData {
|
||||
Vector<float3> positions;
|
||||
Vector<float> factors;
|
||||
Vector<float> distances;
|
||||
Vector<float3> translations;
|
||||
@@ -50,9 +49,8 @@ static void calc_faces(const Depsgraph &depsgraph,
|
||||
const StrokeCache &cache = *ss.cache;
|
||||
Mesh &mesh = *static_cast<Mesh *>(object.data);
|
||||
|
||||
const Span<int> verts = bke::pbvh::node_unique_verts(node);
|
||||
const Span<float3> positions = gather_data_mesh(positions_eval, verts, tls.positions);
|
||||
const OrigPositionData orig_data = orig_position_data_get_mesh(object, node);
|
||||
const Span<int> verts = bke::pbvh::node_unique_verts(node);
|
||||
|
||||
tls.factors.resize(verts.size());
|
||||
const MutableSpan<float> factors = tls.factors;
|
||||
@@ -78,7 +76,6 @@ static void calc_faces(const Depsgraph &depsgraph,
|
||||
tls.translations.resize(verts.size());
|
||||
const MutableSpan<float3> translations = tls.translations;
|
||||
translations_from_offset_and_factors(offset, factors, translations);
|
||||
reset_translations_to_original(translations, positions, orig_data.positions);
|
||||
|
||||
write_translations(depsgraph, sd, object, positions_eval, verts, translations, positions_orig);
|
||||
}
|
||||
@@ -96,9 +93,8 @@ static void calc_grids(const Depsgraph &depsgraph,
|
||||
SubdivCCG &subdiv_ccg = *ss.subdiv_ccg;
|
||||
const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg);
|
||||
|
||||
const Span<int> grids = bke::pbvh::node_grid_indices(node);
|
||||
const Span<float3> positions = gather_grids_positions(subdiv_ccg, grids, tls.positions);
|
||||
const OrigPositionData orig_data = orig_position_data_get_grids(object, node);
|
||||
const Span<int> grids = bke::pbvh::node_grid_indices(node);
|
||||
const int grid_verts_num = grids.size() * key.grid_area;
|
||||
|
||||
tls.factors.resize(grid_verts_num);
|
||||
@@ -125,7 +121,6 @@ static void calc_grids(const Depsgraph &depsgraph,
|
||||
tls.translations.resize(grid_verts_num);
|
||||
const MutableSpan<float3> translations = tls.translations;
|
||||
translations_from_offset_and_factors(offset, factors, translations);
|
||||
reset_translations_to_original(translations, positions, orig_data.positions);
|
||||
|
||||
clip_and_lock_translations(sd, ss, orig_data.positions, translations);
|
||||
apply_translations(translations, grids, subdiv_ccg);
|
||||
@@ -143,7 +138,7 @@ static void calc_bmesh(const Depsgraph &depsgraph,
|
||||
const StrokeCache &cache = *ss.cache;
|
||||
|
||||
const Set<BMVert *, 0> &verts = BKE_pbvh_bmesh_node_unique_verts(&node);
|
||||
const Span<float3> positions = gather_bmesh_positions(verts, tls.positions);
|
||||
|
||||
Array<float3> orig_positions(verts.size());
|
||||
Array<float3> orig_normals(verts.size());
|
||||
orig_position_data_gather_bmesh(*ss.bm_log, verts, orig_positions, orig_normals);
|
||||
@@ -171,7 +166,6 @@ static void calc_bmesh(const Depsgraph &depsgraph,
|
||||
tls.translations.resize(verts.size());
|
||||
const MutableSpan<float3> translations = tls.translations;
|
||||
translations_from_offset_and_factors(offset, factors, translations);
|
||||
reset_translations_to_original(translations, positions, orig_positions);
|
||||
|
||||
clip_and_lock_translations(sd, ss, orig_positions, translations);
|
||||
apply_translations(translations, verts);
|
||||
|
||||
@@ -5149,6 +5149,24 @@ static void sculpt_restore_mesh(const Depsgraph &depsgraph, const Sculpt &sd, Ob
|
||||
SculptSession &ss = *ob.sculpt;
|
||||
const Brush *brush = BKE_paint_brush_for_read(&sd.paint);
|
||||
|
||||
/* Brushes that use original coordinates and need a "restore" step. This has to happen separately
|
||||
* rather than in the brush deformation calculation because that is called once for each symmetry
|
||||
* pass, potentially within the same BVH node.
|
||||
*
|
||||
* Note: Despite the Cloth and Boundary brush using original coordinates, the brushes do not
|
||||
* expect this restoration to happen on every stroke step. Performing this restoration causes
|
||||
* issues with the cloth simulation mode for those brushes.
|
||||
*/
|
||||
if (ELEM(brush->sculpt_tool,
|
||||
SCULPT_TOOL_ELASTIC_DEFORM,
|
||||
SCULPT_TOOL_GRAB,
|
||||
SCULPT_TOOL_THUMB,
|
||||
SCULPT_TOOL_ROTATE))
|
||||
{
|
||||
undo::restore_from_undo_step(depsgraph, sd, ob);
|
||||
return;
|
||||
}
|
||||
|
||||
/* For the cloth brush it makes more sense to not restore the mesh state to keep running the
|
||||
* simulation from the previous state. */
|
||||
if (brush->sculpt_tool == SCULPT_TOOL_CLOTH) {
|
||||
|
||||
Reference in New Issue
Block a user