Blender V4.3
bmesh_topology_rake.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
7#include "DNA_brush_types.h"
8#include "DNA_object_types.h"
9#include "DNA_scene_types.h"
10
11#include "BKE_mesh.hh"
12#include "BKE_paint.hh"
13
15#include "BLI_math_vector.hh"
16#include "BLI_task.hh"
17
22
24
25inline namespace bmesh_topology_rake_cc {
26
33
35 const float3 &direction,
36 const MutableSpan<float3> translations)
37{
38 int i = 0;
39 for (const BMVert *vert : verts) {
41 smooth::bmesh_four_neighbor_average(average, direction, vert);
42 translations[i] = average - float3(vert->co);
43 i++;
44 }
45}
46
47static void calc_bmesh(const Depsgraph &depsgraph,
48 const Sculpt &sd,
49 Object &object,
50 const Brush &brush,
51 const float3 &direction,
52 const float strength,
54 LocalData &tls)
55{
56 SculptSession &ss = *object.sculpt;
57
59 const MutableSpan positions = gather_bmesh_positions(verts, tls.positions);
60
61 calc_factors_common_bmesh(depsgraph, brush, object, positions, node, tls.factors, tls.distances);
62
63 scale_factors(tls.factors, strength);
64
65 tls.translations.resize(verts.size());
66 const MutableSpan<float3> translations = tls.translations;
67 calc_translations(verts, direction, translations);
68 scale_translations(translations, tls.factors);
69
70 clip_and_lock_translations(sd, ss, positions, translations);
71 apply_translations(translations, verts);
72}
73
74} // namespace bmesh_topology_rake_cc
75
77 const Sculpt &sd,
78 Object &object,
79 const IndexMask &node_mask,
80 const float input_strength)
81{
82 const SculptSession &ss = *object.sculpt;
84 const Brush &brush = *BKE_paint_brush_for_read(&sd.paint);
85 const float strength = std::clamp(input_strength, 0.0f, 1.0f);
86
87 /* Interactions increase both strength and quality. */
88 const int iterations = 3;
89
90 const int count = iterations * strength + 1;
91 const float factor = iterations * strength / count;
92
93 float3 direction = ss.cache->grab_delta_symm;
94
95 /* TODO: Is this just the same as one of the projection utility functions? */
97 direction -= tmp;
98 direction = math::normalize(direction);
99
100 /* Cancel if there's no grab data. */
101 if (math::is_zero(direction)) {
102 return;
103 }
104
106 for ([[maybe_unused]] const int i : IndexRange(count)) {
108 node_mask.foreach_index(GrainSize(1), [&](const int i) {
109 LocalData &tls = all_tls.local();
111 depsgraph, sd, object, brush, direction, factor * ss.cache->pressure, nodes[i], tls);
113 });
114 }
115 pbvh.tag_positions_changed(node_mask);
117}
118
119} // namespace blender::ed::sculpt_paint
const Brush * BKE_paint_brush_for_read(const Paint *paint)
Definition paint.cc:654
const blender::Set< BMVert *, 0 > & BKE_pbvh_bmesh_node_unique_verts(blender::bke::pbvh::BMeshNode *node)
#define BLI_NOINLINE
Object is a sort of wrapper for general info.
void tag_positions_changed(const IndexMask &node_mask)
Definition pbvh.cc:549
Span< NodeT > nodes() const
void foreach_index(Fn &&fn) const
const Depsgraph * depsgraph
static float verts[][3]
int count
ccl_device_inline float average(const float2 a)
pbvh::Tree * pbvh_get(Object &object)
Definition paint.cc:2846
void update_node_bounds_bmesh(BMeshNode &node)
Definition pbvh.cc:1095
void flush_bounds_to_parents(Tree &pbvh)
Definition pbvh.cc:1132
static BLI_NOINLINE void calc_translations(const Set< BMVert *, 0 > &verts, const float3 &direction, const MutableSpan< float3 > translations)
static void calc_bmesh(const Depsgraph &depsgraph, const Sculpt &sd, Object &object, const Brush &brush, const float3 &direction, const float strength, bke::pbvh::BMeshNode &node, LocalData &tls)
void bmesh_four_neighbor_average(float avg[3], const float3 &direction, const BMVert *v)
void do_bmesh_topology_rake_brush(const Depsgraph &depsgraph, const Sculpt &sd, Object &object, const IndexMask &node_mask, const float input_strength)
void gather_bmesh_positions(const Set< BMVert *, 0 > &verts, MutableSpan< float3 > positions)
Definition sculpt.cc:6054
void scale_translations(MutableSpan< float3 > translations, Span< float > factors)
Definition sculpt.cc:7210
void scale_factors(MutableSpan< float > factors, float strength)
Definition sculpt.cc:7227
void clip_and_lock_translations(const Sculpt &sd, const SculptSession &ss, Span< float3 > positions, Span< int > verts, MutableSpan< float3 > translations)
Definition sculpt.cc:7022
void apply_translations(Span< float3 > translations, Span< int > verts, MutableSpan< float3 > positions)
Definition sculpt.cc:6958
void calc_factors_common_bmesh(const Depsgraph &depsgraph, const Brush &brush, const Object &object, Span< float3 > positions, bke::pbvh::BMeshNode &node, Vector< float > &r_factors, Vector< float > &r_distances)
Definition sculpt.cc:6304
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
bool is_zero(const T &a)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
VecBase< float, 3 > float3
blender::ed::sculpt_paint::StrokeCache * cache
Definition BKE_paint.hh:427