Blender V5.3
GEO_xpbd_constraint_set_templated.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
8
9namespace blender::xpbd {
10
17template<typename Child> class TemplatedConstraintSet : public ConstraintSet {
18 public:
19 TemplatedConstraintSet(const int constraints_num, Vector<int> affected_geo_indices)
20 : ConstraintSet(constraints_num, std::move(affected_geo_indices))
21 {
22 }
23
24 void reset_forces() override
25 {
26 const Child &self = static_cast<const Child &>(*this);
27 for (const int constraint_i : IndexRange(constraints_num_)) {
28 self.reset_force(constraint_i);
29 }
30 }
31
33 GaussSeidelUpdater &updater,
34 const IndexMask &mask) override
35 {
36 const Child &self = static_cast<const Child &>(*this);
37 mask.foreach_index(
38 [&](const int64_t constraint_i) { self.solve_single(params, updater, constraint_i); });
39 }
40
42 {
43 return Child::debug_name;
44 }
45};
46
47template<typename Child> class TemplatedVelocityConstraintSet : public VelocityConstraintSet {
48 protected:
49 const int constraint_num_;
50
51 public:
52 TemplatedVelocityConstraintSet(int constraints_num, Vector<int> affected_geo_indices)
53 : VelocityConstraintSet(std::move(affected_geo_indices)), constraint_num_(constraints_num)
54 {
55 }
56
57 void reset_forces() override
58 {
59 Child &self = static_cast<Child &>(*this);
60 for (const int constraint_i : IndexRange(constraint_num_)) {
61 self.reset_force(constraint_i);
62 }
63 }
64
65 void solve_sequential(const ConstraintSetParams &params, VelocityUpdater &updater) override
66 {
67 Child &self = static_cast<Child &>(*this);
68 for (const int constraint_i : IndexRange(constraint_num_)) {
69 self.solve_single(params, updater, constraint_i);
70 }
71 }
72
74 {
75 return Child::debug_name;
76 }
77};
78
79} // namespace blender::xpbd
#define final(a, b, c)
Definition BLI_hash_c.hh:21
constexpr IndexRange()=default
ConstraintSet(int constraints_num, Vector< int > affected_geo_indices)
TemplatedConstraintSet(const int constraints_num, Vector< int > affected_geo_indices)
void solve_sequential(const ConstraintSetParams &params, GaussSeidelUpdater &updater, const IndexMask &mask) override
void solve_sequential(const ConstraintSetParams &params, VelocityUpdater &updater) override
TemplatedVelocityConstraintSet(int constraints_num, Vector< int > affected_geo_indices)
VelocityConstraintSet(Vector< int > affected_geo_indices)
__int64 int64_t
Definition BKE_text.h:90