Curves: initial surface collision for curves sculpt mode #104469

Merged
Jacques Lucke merged 29 commits from JacquesLucke/blender:temp-curves-surface-collision into main 2023-02-11 13:46:39 +01:00
Member

During hair grooming in curves sculpt mode, it is very useful when hair strands are prevented from intersecting with the surface mesh. Unfortunately, it also decreases performance significantly so we don't want it to be turned on all the time.

The surface collision is used by the Comb, Pinch and Puff brushes currently.

This was originally based on D15451 but I changed it quite significantly do make it more feasible to integrate in master without introducing new big abstractions that we don't know we'll need. The intersection prevention quality of this patch is worse than the original patch, it's a bit faster though. Overall, perfect collision detection at the cost of bad performance is not necessary for interactive sculpting, because the user can fix small mistakes very quickly. Nevertheless, the quality can probably still be improved significantly without too big slow-downs. This can be done separately from this patch.

image

Possible future improvements:

  • "Proper" solver that can handle more complex cases without resulting in intersections.
  • Support a separate collision collection.
During hair grooming in curves sculpt mode, it is very useful when hair strands are prevented from intersecting with the surface mesh. Unfortunately, it also decreases performance significantly so we don't want it to be turned on all the time. The surface collision is used by the Comb, Pinch and Puff brushes currently. This was originally based on [D15451](https://ro.developer.blender.org/D15451) but I changed it quite significantly do make it more feasible to integrate in master without introducing new big abstractions that we don't know we'll need. The intersection prevention quality of this patch is worse than the original patch, it's a bit faster though. Overall, perfect collision detection at the cost of bad performance is not necessary for interactive sculpting, because the user can fix small mistakes very quickly. Nevertheless, the quality can probably still be improved significantly without too big slow-downs. This can be done separately from this patch. ![image](/attachments/9f31b730-ec5d-424e-a35a-13649b46c35a) Possible future improvements: * "Proper" solver that can handle more complex cases without resulting in intersections. * Support a separate collision collection.
Jacques Lucke added 17 commits 2023-02-08 14:48:01 +01:00
Author
Member

@blender-bot build

@blender-bot build
Jacques Lucke added 5 commits 2023-02-09 14:06:43 +01:00
Jacques Lucke changed title from WIP: Curves: initial surface collision for curves sculpt mode to Curves: initial surface collision for curves sculpt mode 2023-02-09 14:28:26 +01:00
Jacques Lucke requested review from Hans Goudey 2023-02-09 14:29:25 +01:00
Jacques Lucke requested review from Simon Thommes 2023-02-09 14:29:32 +01:00
Author
Member

@blender-bot build

@blender-bot build
Simon Thommes approved these changes 2023-02-10 12:24:08 +01:00
Simon Thommes left a comment
Member

Seems good to me!

Would of course be great if performance/accuracy could be tweaked more in the future but this is great for a first iteration!

Seems good to me! Would of course be great if performance/accuracy could be tweaked more in the future but this is great for a first iteration!
Hans Goudey approved these changes 2023-02-10 18:24:16 +01:00
Hans Goudey left a comment
Member

Just a couple suggestions about the index mask stuff inline, and a couple other small things. Since it worked in my testing and for Simon and it will probably be changed more in the future, I didn't think too much about the specifics of the collision algorithm. What's there seems reasonable, but I didn't really think about alternatives.

At least for the guide use cases where there are very few initial curves, the performance difference isn't noticeable. It's obviously much different when there are lots of curves though.

Just a couple suggestions about the index mask stuff inline, and a couple other small things. Since it worked in my testing and for Simon and it will probably be changed more in the future, I didn't think too much about the specifics of the collision algorithm. What's there seems reasonable, but I didn't really think about alternatives. At least for the guide use cases where there are very few initial curves, the performance difference isn't noticeable. It's obviously much different when there are lots of curves though.
@ -241,4 +241,10 @@ IndexMask find_indices_from_virtual_array(const IndexMask indices_to_check,
return detail::find_indices_based_on_predicate__merge(indices_to_check, sub_masks, r_indices);
}
IndexMask find_indices_from_array(const Span<bool> array, Vector<int64_t> &r_indices)
Member

Can't seem to add a comment there, but this can replace

find_indices_based_on_predicate(indices_to_check, 4096, r_indices, [&](const int64_t i) { return span[i]; });

above.

Can't seem to add a comment there, but this can replace ``` find_indices_based_on_predicate(indices_to_check, 4096, r_indices, [&](const int64_t i) { return span[i]; }); ``` above.
JacquesLucke marked this conversation as resolved
@ -143,0 +147,4 @@
const IndexMask changed_curves_mask = index_mask_ops::find_indices_from_array(changed_curves,
indices);
const Mesh *surface = curves_id_->surface && curves_id_->surface->type == OB_MESH ?
static_cast<Mesh *>(curves_id_->surface->data) :
Member

static_cast<Mesh *> -> static_cast<const Mesh *>

`static_cast<Mesh *>` -> `static_cast<const Mesh *>`
JacquesLucke marked this conversation as resolved
@ -157,2 +160,3 @@
this->puff(curve_weights);
this->restore_segment_lengths();
Vector<int64_t> changed_curves_indices;
Member

What about something like this?

    Vector<int64_t> changed_curves_indices;
    index_mask_ops::find_indices_based_on_predicate(
        curve_selection_, 4096, changed_curves_indices, [&](const int64_t i) {
          return curve_weights[i] > 0.0f;
        });

Also, since the mask has to be computed, would it be possible to use the mask in this->puff()?

What about something like this? ``` Vector<int64_t> changed_curves_indices; index_mask_ops::find_indices_based_on_predicate( curve_selection_, 4096, changed_curves_indices, [&](const int64_t i) { return curve_weights[i] > 0.0f; }); ``` Also, since the mask has to be computed, would it be possible to use the mask in `this->puff()`?
Author
Member

I might be wrong, but I think that's not equivalent currently. We could refactor things separately to clean this up though.

Note that the index used in the predicate curve_weights[select_i] > 0.0f is select_i, but the index appended to changed_curves_indices is curve_selection_[select_i]. So it's a different one.

I might be wrong, but I think that's not equivalent currently. We could refactor things separately to clean this up though. Note that the index used in the predicate `curve_weights[select_i] > 0.0f` is `select_i`, but the index appended to `changed_curves_indices` is `curve_selection_[select_i]`. So it's a different one.
@ -0,0 +4,4 @@
#include "BKE_curves.hh"
namespace blender::geometry::curve_constraint_solver {
Member

Suggestion: curve_constraint_solver -> curve_constraint(s)

I'm guessing the current name is left over from when it was more object oriented

Suggestion: `curve_constraint_solver` -> `curve_constraint(s)` I'm guessing the current name is left over from when it was more object oriented
JacquesLucke marked this conversation as resolved
@ -0,0 +6,4 @@
#include "GEO_curve_constraint_solver.hh"
#include "BKE_bvhutils.h"
Member

Should probably have the note about the coordinate spaces in this file too

Should probably have the note about the coordinate spaces in this file too
JacquesLucke marked this conversation as resolved
@ -0,0 +140,4 @@
const float3 normalized_slide_direction_cu = math::normalize_and_get_length(
slide_direction_cu, slide_direction_length_cu);
/* Use pythagorian theory to determine how far to slide. */
Member

theory -> theorem?

`theory` -> `theorem`?
JacquesLucke marked this conversation as resolved
@ -456,0 +456,4 @@
prop = RNA_def_property(srna, "use_sculpt_collision", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", CV_SCULPT_COLLISION_ENABLED);
RNA_def_property_ui_text(
prop, "Use Sculpt Collision", "Enable collision handling with the surface during sculpting");
Member

Suggestion: Enable collision with the surface while sculpting

Suggestion: `Enable collision with the surface while sculpting`
Member

This should get its own icon imho.

This should get its own icon imho.
Jacques Lucke added 7 commits 2023-02-11 13:41:01 +01:00
Jacques Lucke merged commit b723a398f3 into main 2023-02-11 13:46:39 +01:00
Jacques Lucke deleted branch temp-curves-surface-collision 2023-02-11 13:46:40 +01:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#104469
No description provided.