Blender V5.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
8
10
11#include "DNA_brush_types.h"
12#include "DNA_object_types.h"
13#include "DNA_scene_types.h"
14
15#include "BKE_mesh.hh"
16#include "BKE_object_types.hh"
17#include "BKE_paint.hh"
18
20#include "BLI_math_vector.hh"
21#include "BLI_task.hh"
22
23#include "PRF_profile.hh"
24
29
30#include "bmesh.hh"
31
33
34inline namespace bmesh_topology_rake_cc {
35
42
44 const float3 &direction,
45 const MutableSpan<float3> translations)
46{
48 int i = 0;
49 for (const BMVert *vert : verts) {
52 translations[i] = average - float3(vert->co);
53 i++;
54 }
55}
56
57static void calc_bmesh(const Depsgraph &depsgraph,
58 const Sculpt &sd,
59 Object &object,
60 const Brush &brush,
61 const float3 &direction,
62 const float strength,
64 LocalData &tls)
65{
66 SculptSession &ss = *object.runtime->sculpt_session;
67
69 const MutableSpan positions = gather_bmesh_positions(verts, tls.positions);
70
71 calc_factors_common_bmesh(depsgraph, brush, object, positions, node, tls.factors, tls.distances);
72
73 scale_factors(tls.factors, strength);
74
75 tls.translations.resize(verts.size());
76 const MutableSpan<float3> translations = tls.translations;
77 calc_translations(verts, direction, translations);
78 scale_translations(translations, tls.factors);
79
80 clip_and_lock_translations(sd, ss, positions, translations);
81 apply_translations(translations, verts);
82}
83
84} // namespace bmesh_topology_rake_cc
85
86void do_bmesh_topology_rake_brush(const Depsgraph &depsgraph,
87 const Sculpt &sd,
88 Object &object,
89 const IndexMask &node_mask,
90 const float input_strength)
91{
93 const SculptSession &ss = *object.runtime->sculpt_session;
96 const float strength = std::clamp(input_strength, 0.0f, 1.0f);
97
98 /* Interactions increase both strength and quality. */
99 const int iterations = 3;
100
101 const int count = iterations * strength + 1;
102 const float factor = iterations * strength / count;
103
104 float3 direction = ss.cache->grab_delta_symm;
105
106 /* TODO: Is this just the same as one of the projection utility functions? */
108 direction -= tmp;
109 direction = math::normalize(direction);
110
111 /* Cancel if there's no grab data. */
112 if (math::is_zero(direction)) {
113 return;
114 }
115
117 for ([[maybe_unused]] const int i : IndexRange(count)) {
119 node_mask.foreach_index(
120 [&](const int i) {
121 LocalData &tls = all_tls.local();
123 depsgraph, sd, object, brush, direction, factor * ss.cache->pressure, nodes[i], tls);
125 },
127 }
128 pbvh.tag_positions_changed(node_mask);
129 pbvh.flush_bounds_to_parents();
130}
131
132} // namespace blender::ed::sculpt_paint::brushes
Object is a sort of wrapper for general info.
#define PRF_scope(category)
#define BLI_NOINLINE
constexpr IndexRange()=default
int64_t size() const
Definition BLI_set.hh:606
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
float average(float2 a)
pbvh::Tree * pbvh_get(Object &object)
void update_node_bounds_bmesh(BMeshNode &node)
Definition pbvh.cc:1216
static void calc_bmesh(const Depsgraph &depsgraph, const Sculpt &sd, const Brush &brush, Object &object, bke::pbvh::BMeshNode &node, LocalData &tls, MutableSpan< float > layer_displacement_factor)
static BLI_NOINLINE void calc_translations(const Span< float3 > orig_positions, const Span< float3 > orig_normals, const Span< float3 > positions, const Span< float > displacement_factors, const Span< float > factors, const float height, const MutableSpan< float3 > r_translations)
void do_bmesh_topology_rake_brush(const Depsgraph &depsgraph, const Sculpt &sd, Object &object, const IndexMask &node_mask, const float input_strength)
void bmesh_four_neighbor_average(float avg[3], const float3 &direction, const BMVert *v)
void gather_bmesh_positions(const Set< BMVert *, 0 > &verts, MutableSpan< float3 > positions)
Definition sculpt.cc:6497
void scale_translations(MutableSpan< float3 > translations, Span< float > factors)
Definition sculpt.cc:7837
void scale_factors(MutableSpan< float > factors, float strength)
Definition sculpt.cc:7856
void clip_and_lock_translations(const Sculpt &sd, const SculptSession &ss, Span< float3 > positions, Span< int > verts, MutableSpan< float3 > translations)
Definition sculpt.cc:7664
void apply_translations(Span< float3 > translations, Span< int > verts, MutableSpan< float3 > positions)
Definition sculpt.cc:7592
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:6891
constexpr ParallelGrainSize grain_size(int grain_size)
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)
const Brush * BKE_paint_brush_for_read(const Paint *paint)
VecBase< float, 3 > float3
const Set< BMVert *, 0 > & BKE_pbvh_bmesh_node_unique_verts(bke::pbvh::BMeshNode *node)
ed::sculpt_paint::StrokeCache * cache
Definition BKE_paint.hh:409