GPv3: Implementation of sculpt mode tools #120508
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
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
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
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#120508
Loading…
Reference in New Issue
No description provided.
Delete Branch "LukasTonne/blender:gp3-sculpt-tools"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This implements all the sculpt tools in Grease Pencil 3.
UI changes in the 3D view header and keymap entries for sculpt mode are
still minimal, more entries should be added once the relevant operators
are supported.
A set of utility functions and a shared base class
GreasePencilStrokeOperationCommon
for sculpt operations has been addedto make individual operations less verbose.
The
GreasePencilStrokeParams
struct bundles common arguments to reducethe amount of boilerplate code. The
foreach_editable_drawing
utilityfunction takes care of setting up the parameters and finding the right
drawings, so the tool only has to modify the data. Common features like
tracking mouse movement and inverting brush influence are handled by the
common base class.
Most operations are then relatively simple, with the exception of the
Grab and Clone operations.
stroke, rather than working with the usual selection mask.
clipboard in the editor API.
During compilation I'm getting
Great work! I took a first peek at the tools: they all work smooth and behave as I expected.
I added two remarks related to multi frame editing.
Probably for a separate PR: there is no overlay yet for displaying selected strokes/points, right? I can see that sculpting on selected strokes/points is already working, but the selection state isn't visible in the viewport.
And: all is fine as long as I have one layer. With multiple layers, I get a crash in
GreasePencilStrokeParams GreasePencilStrokeParams::from_context()
, where there is something spooky going on with the context, resulting in null pointers for e.g.view3d
andob_orig
.@ -0,0 +62,4 @@
return {};
}
const Layer &active_layer = *grease_pencil.get_active_layer();
Drawing *drawing = grease_pencil.get_editable_drawing_at(active_layer, scene.r.cfra);
Multi frame editing should be taken into account here, so using something like
retrieve_editable_drawings_from_layer()
. But then a version that calculates the multi frame falloff – we don't have that flavour yet in utilities. Seeretrieve_editable_drawings_with_falloff()
how you could do that.@ -0,0 +75,4 @@
}
/* Apply to all editable drawings. */
return ed::greasepencil::retrieve_editable_drawings(scene, grease_pencil);
You can use
ed::greasepencil::retrieve_editable_drawings_with_falloff()
here. That one calculates themulti_frame_falloff
factor for the drawings.Looks pretty good. I read through a fair amount of the PR and only noticed a few things.
@ -0,0 +44,4 @@
return mouse_delta;
}
Vector<ed::greasepencil::MutableDrawingInfo> get_drawings_for_sculpt(const bContext &C)
ed
is unnecessary hereThis doesn't work for me, just using
greasepencil::MutableDrawingInfo
is turned intoblender::ed::sculpt_paint::greasepencil::MutableDrawingInfo
by the compiler. I have to add theed::
part to disambiguate it.@ -0,0 +54,4 @@
selection.foreach_index(GrainSize(4096), [&](const int64_t point_i) {
float &radius = radii[point_i];
const float influence = brush_influence(*CTX_data_scene(¶ms.context),
Seems important not to call
CTX_data_scene
for every point index. Better to retrieve as much as possible outside of theforeach_editable_drawing
loop. Same with other places--paint
andbrush
and some others can always be retrieved outside of the loop.Errors with multiple layers are caused by behavior of the
CTX_data_***
functions that return nullptr outside of the main thread. I wasn't seeing any errors in regular debug mode, but get segfaults with ASAN enabled. It's unfortunate that this isn't more obvious, you just have to know when and where calling context functions is "allowed".The advantage of the
foreach_
style of methods is that one can get the relevant context info outside of loops and implicitly bind it to the callback. That way i should be able to avoid storing everything in the params struct, and just have local variables for the context data needed for a particular operation.Did a full pass on this. Really like that all the tool implementation are this small, nice job!
Don't have any bigger concerns.
@ -4696,0 +4696,4 @@
# Invoke sculpt operator
("grease_pencil.sculpt_paint", {"type": 'LEFTMOUSE', "value": 'PRESS'}, None),
("grease_pencil.sculpt_paint", {"type": 'LEFTMOUSE', "value": 'PRESS',
"ctrl": True}, {"properties": [("mode", 'INVERT')]}), # # Selection
Looks like that comment is there by accident
# # Selection
@ -2440,0 +2391,4 @@
clipboard.curves = {};
clipboard.materials.clear_and_shrink();
clipboard.materials_in_source_num = 0;
MEM_delete(grease_pencil_clipboard);
Should be enough to call
MEM_delete
to destruct everything inside.@ -0,0 +45,4 @@
{
/* Note: GPv2 method, this does not return a different value for every invocation: the time-based
* part remains the same for one second and the pointer isn't guaranteed to be different. */
// unsigned int seed = (unsigned int)(BLI_time_now_seconds_i() & UINT_MAX);
Looks like the commented code can just be removed.
@ -0,0 +128,4 @@
changed = true;
}
if (sculpt_mode_flag & GP_SCULPT_FLAGMODE_APPLY_UV) {
/* TODO stroke_u attribute not used yet. */
Is this still a TODO?
@ -0,0 +112,4 @@
changed = true;
}
if (sculpt_mode_flag & GP_SCULPT_FLAGMODE_APPLY_UV) {
/* TODO stroke_u attribute not used yet. */
Is this still a TODO?
Should be ok with just the
rotation
attribute smoothing. GPv2 was also smoothing theuv_fac
attribute, but afaik this will never be anything other than a linear interpolation along the length, with a possible scale + offset transformation from the UV modifier. There is RNA access to these attributes in GPv2, but anything the user might set there would get discarded by the next update inBKE_gpencil_stroke_uv_update
. So the smooth tool does not actually do anything useful when smoothing the stroke UV.@blender-bot build
@blender-bot build
@blender-bot build
@ -476,0 +507,4 @@
toolsettings->gp_sculpt.cur_falloff) :
1.0f;
editable_drawings.append(
{*drawing, layer.drawing_index_at(frame_number), frame_number, falloff});
There was a bug fix in
retrieve_editable_drawings_from_layer()
that applies here too:layer.drawing_index_at(frame_number)
should in fact be alayer_index
withsomewhere outside the loop.
Thanks for catching this, fixed.
@blender-bot build
Overall structure is great. Just found one thread safety issue where the influence mask and weights are gathered.
@ -0,0 +91,4 @@
(use_pressure ? sample.pressure : 1.0f);
/* Distance falloff. */
const int2 mval_i = int2(math::round(sample.mouse_position));
There's some constant math being done for every element here. Maybe it's not noticeable, and I'm sure this will be much faster than GPv2 anyway, but just wanted to point it out as a place of possible improvement.
I think this is good enough for now. The only meaningful operation i see that might be pulled out of the point loop would be the brush radius calculation. I'd rather leave it like this and not make the functions more complicated by adding parameters.
@ -0,0 +135,4 @@
const float influence = influence_base * brush_falloff;
if (influence > 0.0f) {
indices.append(point_i);
Appending to a vector inside a threaded loop isn't threadsafe.
Maybe a good alternative is using one call to
IndexMask::from_predicate
to find the affected indices, then another loop to store the influences (using the index in the mask rather than the global index).That might also avoid the need for the temporary indices vector.
@ -0,0 +26,4 @@
/* Use a hash to generate random numbers. */
static float hash_rng(unsigned int seed1, unsigned int seed2, int index)
{
return BLI_hash_int_01(BLI_hash_int_3d(seed1, seed2, (unsigned int)index));
uint32_t
(here and elsewhere)@ -139,3 +136,1 @@
total_weight[index] += w - w2;
dst[index] = src[index] + influence * dst[index] / total_weight[index];
}
auto mix_smoothed = [&](const int index, const float influence) {
I think typically
devirtualize_varray
can apply this optimization without the code duplicationI added a few remarks concerning the UI.
In the toolbar no
+
-
icons appear for the direction. To get those:In
rna_brush.cc
:Line 1015
And in
space_view3d.py
some fixes for brush direction, falloff panel and 'Active Layer' switch:Line 475
And to show the Multiframe editing properties:
space_view3d.py
Line 876
@ -0,0 +88,4 @@
/* Basic strength factor from brush settings. */
const bool use_pressure = (brush.gpencil_settings->flag & GP_BRUSH_USE_PRESSURE);
const float influence_base = brush.alpha * multi_frame_falloff *
(use_pressure ? sample.pressure : 1.0f);
Use
BKE_brush_use_alpha_pressure(brush)
andBKE_brush_alpha_get(scene, brush)
here.I think it's correct now. Somebody should probably test this stuff with a tablet.
@ -0,0 +117,4 @@
const float radius_squared = radius * radius;
const bool use_pressure = (brush.gpencil_settings->flag & GP_BRUSH_USE_PRESSURE);
const float influence_base = brush.alpha * multi_frame_falloff *
(use_pressure ? pressure : 1.0f);
Same as above.
@ -0,0 +147,4 @@
{
/* The basic setting is the brush's setting. */
bool invert = ((brush.gpencil_settings->sculpt_flag & GP_SCULPT_FLAG_INVERT) != 0) ||
(brush.gpencil_settings->sculpt_flag & BRUSH_DIR_IN);
This should be
(brush->flag & BRUSH_DIR_IN)
Yeah, super confusing. Also the
GP_SCULPT_FLAG_INVERT
andGP_SCULPT_FLAG_TMP_INVERT
are completely unused, will throw them out.Can you merge main into this branch?
@ -0,0 +135,4 @@
IndexMask index_mask = IndexMask::from_predicate(
selection, GrainSize(4096), memory, [&](const int point_i) {
const float influence = calculate_influence(point_i);
Not sure how I feel about calculating everything twice here. How about this?
At the cost of a copy and potentially higher peak memory usage, that would avoid all the duplicate calculations.
@blender-bot build
@blender-bot build
Almost there! A last little change in the
pressure
handling and it's all good. I tested it with a tablet.And btw, the direction toggle is perfect: the
Ctrl
key inverts the direction setting in the tool bar. That's how I implemented it in the weight paint tools also, and how GPv2 behaves – so all consistent.@ -0,0 +94,4 @@
BKE_brush_alpha_get(&scene, &brush) :
1.0f;
const float influence_base = brush_pressure * multi_frame_falloff *
(use_pressure ? sample.pressure : 1.0f);
This is one pressure too many 😸 Now that we use the unified paint settings, we don't need the
GP_BRUSH_USE_PRESSURE
any more.Change line 91-97 into this and you're good to go:
@ -0,0 +126,4 @@
BKE_brush_alpha_get(&scene, &brush) :
1.0f;
const float influence_base = brush_pressure * multi_frame_falloff *
(use_pressure ? pressure : 1.0f);
Same as above. Line 124-129 can be:
@blender-bot build