Blender V5.0
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
23#include "bmesh.hh"
24
26
27inline namespace bmesh_topology_rake_cc {
28
35
37 const float3 &direction,
38 const MutableSpan<float3> translations)
39{
40 int i = 0;
41 for (const BMVert *vert : verts) {
44 translations[i] = average - float3(vert->co);
45 i++;
46 }
47}
48
49static void calc_bmesh(const Depsgraph &depsgraph,
50 const Sculpt &sd,
51 Object &object,
52 const Brush &brush,
53 const float3 &direction,
54 const float strength,
56 LocalData &tls)
57{
58 SculptSession &ss = *object.sculpt;
59
61 const MutableSpan positions = gather_bmesh_positions(verts, tls.positions);
62
63 calc_factors_common_bmesh(depsgraph, brush, object, positions, node, tls.factors, tls.distances);
64
65 scale_factors(tls.factors, strength);
66
67 tls.translations.resize(verts.size());
68 const MutableSpan<float3> translations = tls.translations;
69 calc_translations(verts, direction, translations);
70 scale_translations(translations, tls.factors);
71
72 clip_and_lock_translations(sd, ss, positions, translations);
73 apply_translations(translations, verts);
74}
75
76} // namespace bmesh_topology_rake_cc
77
79 const Sculpt &sd,
80 Object &object,
81 const IndexMask &node_mask,
82 const float input_strength)
83{
84 const SculptSession &ss = *object.sculpt;
86 const Brush &brush = *BKE_paint_brush_for_read(&sd.paint);
87 const float strength = std::clamp(input_strength, 0.0f, 1.0f);
88
89 /* Interactions increase both strength and quality. */
90 const int iterations = 3;
91
92 const int count = iterations * strength + 1;
93 const float factor = iterations * strength / count;
94
95 float3 direction = ss.cache->grab_delta_symm;
96
97 /* TODO: Is this just the same as one of the projection utility functions? */
99 direction -= tmp;
100 direction = math::normalize(direction);
101
102 /* Cancel if there's no grab data. */
103 if (math::is_zero(direction)) {
104 return;
105 }
106
108 for ([[maybe_unused]] const int i : IndexRange(count)) {
110 node_mask.foreach_index(GrainSize(1), [&](const int i) {
111 LocalData &tls = all_tls.local();
113 depsgraph, sd, object, brush, direction, factor * ss.cache->pressure, nodes[i], tls);
115 });
116 }
117 pbvh.tag_positions_changed(node_mask);
119}
120
121} // namespace blender::ed::sculpt_paint::brushes
const Brush * BKE_paint_brush_for_read(const Paint *paint)
Definition paint.cc:650
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.
BPy_StructRNA * depsgraph
void tag_positions_changed(const IndexMask &node_mask)
Definition pbvh.cc:635
Span< NodeT > nodes() const
void flush_bounds_to_parents()
Definition pbvh.cc:1306
void foreach_index(Fn &&fn) const
static float verts[][3]
int count
pbvh::Tree * pbvh_get(Object &object)
Definition paint.cc:3052
void update_node_bounds_bmesh(BMeshNode &node)
Definition pbvh.cc:1294
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 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:6367
void scale_translations(MutableSpan< float3 > translations, Span< float > factors)
Definition sculpt.cc:7495
void scale_factors(MutableSpan< float > factors, float strength)
Definition sculpt.cc:7512
void clip_and_lock_translations(const Sculpt &sd, const SculptSession &ss, Span< float3 > positions, Span< int > verts, MutableSpan< float3 > translations)
Definition sculpt.cc:7335
void apply_translations(Span< float3 > translations, Span< int > verts, MutableSpan< float3 > positions)
Definition sculpt.cc:7268
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:6637
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
float average(point a)
Definition node_math.h:144
blender::ed::sculpt_paint::StrokeCache * cache
Definition BKE_paint.hh:417
i
Definition text_draw.cc:230