Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2022-07-22 16:39:41 +0300
committerJacques Lucke <jacques@blender.org>2022-07-22 16:39:41 +0300
commit1f94b56d774440d08eb92f2a7a47b9a6a7aa7b84 (patch)
tree06928c94d524852c7031aa310d578691735dc0a8 /source/blender/editors/sculpt_paint/curves_sculpt_puff.cc
parent98bf714b37c1f1b05a162b6ffdaca367b312de1f (diff)
Curves: support sculpting on deformed curves
Previously, curves sculpt tools only worked on original data. This was very limiting, because one could effectively only sculpt the curves when all procedural effects were turned off. This patch adds support for curves sculpting while looking the result of procedural effects (like deformation based on the surface mesh). This functionality is also known as "crazy space" support in Blender. For more details see D15407. Differential Revision: https://developer.blender.org/D15407
Diffstat (limited to 'source/blender/editors/sculpt_paint/curves_sculpt_puff.cc')
-rw-r--r--source/blender/editors/sculpt_paint/curves_sculpt_puff.cc39
1 files changed, 14 insertions, 25 deletions
diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_puff.cc b/source/blender/editors/sculpt_paint/curves_sculpt_puff.cc
index 83cfda6dc00..139e0d67e89 100644
--- a/source/blender/editors/sculpt_paint/curves_sculpt_puff.cc
+++ b/source/blender/editors/sculpt_paint/curves_sculpt_puff.cc
@@ -4,6 +4,7 @@
#include "BKE_brush.h"
#include "BKE_bvhutils.h"
#include "BKE_context.h"
+#include "BKE_crazyspace.hh"
#include "BKE_mesh.h"
#include "BKE_mesh_runtime.h"
@@ -20,6 +21,8 @@
#include "BLI_length_parameterize.hh"
+#include "GEO_add_curves_on_mesh.hh"
+
#include "curves_sculpt_intern.hh"
namespace blender::ed::sculpt_paint {
@@ -38,23 +41,6 @@ class PuffOperation : public CurvesSculptStrokeOperation {
void on_stroke_extended(const bContext &C, const StrokeExtension &stroke_extension) override;
};
-static float3 compute_surface_point_normal(const MLoopTri &looptri,
- const float3 &bary_coord,
- const Span<float3> corner_normals)
-{
- const int l0 = looptri.tri[0];
- const int l1 = looptri.tri[1];
- const int l2 = looptri.tri[2];
-
- const float3 &l0_normal = corner_normals[l0];
- const float3 &l1_normal = corner_normals[l1];
- const float3 &l2_normal = corner_normals[l2];
-
- const float3 normal = math::normalize(
- attribute_math::mix3(bary_coord, l0_normal, l1_normal, l2_normal));
- return normal;
-}
-
/**
* Utility class that actually executes the update when the stroke is updated. That's useful
* because it avoids passing a very large number of parameters between functions.
@@ -183,8 +169,6 @@ struct PuffOperationExecutor {
void find_curve_weights_projected(const float4x4 &brush_transform,
MutableSpan<float> r_curve_weights)
{
- Span<float3> positions_cu = curves_->positions();
-
const float4x4 brush_transform_inv = brush_transform.inverted();
float4x4 projection;
@@ -193,15 +177,18 @@ struct PuffOperationExecutor {
const float brush_radius_re = brush_radius_base_re_ * brush_radius_factor_;
const float brush_radius_sq_re = pow2f(brush_radius_re);
+ const bke::crazyspace::GeometryDeformation deformation =
+ bke::crazyspace::get_evaluated_curves_deformation(*ctx_.depsgraph, *object_);
+
threading::parallel_for(curve_selection_.index_range(), 256, [&](const IndexRange range) {
for (const int curve_selection_i : range) {
const int curve_i = curve_selection_[curve_selection_i];
const IndexRange points = curves_->points_for_curve(curve_i);
- const float3 first_pos_cu = brush_transform_inv * positions_cu[points[0]];
+ const float3 first_pos_cu = brush_transform_inv * deformation.positions[points[0]];
float2 prev_pos_re;
ED_view3d_project_float_v2_m4(ctx_.region, first_pos_cu, prev_pos_re, projection.values);
for (const int point_i : points.drop_front(1)) {
- const float3 pos_cu = brush_transform_inv * positions_cu[point_i];
+ const float3 pos_cu = brush_transform_inv * deformation.positions[point_i];
float2 pos_re;
ED_view3d_project_float_v2_m4(ctx_.region, pos_cu, pos_re, projection.values);
BLI_SCOPED_DEFER([&]() { prev_pos_re = pos_re; });
@@ -248,16 +235,18 @@ struct PuffOperationExecutor {
const float brush_radius_cu,
MutableSpan<float> r_curve_weights)
{
- const Span<float3> positions_cu = curves_->positions();
const float brush_radius_sq_cu = pow2f(brush_radius_cu);
+ const bke::crazyspace::GeometryDeformation deformation =
+ bke::crazyspace::get_evaluated_curves_deformation(*ctx_.depsgraph, *object_);
+
threading::parallel_for(curve_selection_.index_range(), 256, [&](const IndexRange range) {
for (const int curve_selection_i : range) {
const int curve_i = curve_selection_[curve_selection_i];
const IndexRange points = curves_->points_for_curve(curve_i);
for (const int point_i : points.drop_front(1)) {
- const float3 &prev_pos_cu = positions_cu[point_i - 1];
- const float3 &pos_cu = positions_cu[point_i];
+ const float3 &prev_pos_cu = deformation.positions[point_i - 1];
+ const float3 &pos_cu = deformation.positions[point_i];
const float dist_to_brush_sq_cu = dist_squared_to_line_segment_v3(
brush_pos_cu, prev_pos_cu, pos_cu);
if (dist_to_brush_sq_cu > brush_radius_sq_cu) {
@@ -305,7 +294,7 @@ struct PuffOperationExecutor {
const float3 &v2_su = surface_->mvert[surface_->mloop[looptri.tri[2]].v].co;
float3 bary_coords;
interp_weights_tri_v3(bary_coords, v0_su, v1_su, v2_su, closest_pos_su);
- const float3 normal_su = compute_surface_point_normal(
+ const float3 normal_su = geometry::compute_surface_point_normal(
looptri, bary_coords, corner_normals_su_);
const float3 normal_cu = math::normalize(transforms_.surface_to_curves_normal * normal_su);