GPv3: Overlay: only show visible and editable materials. #115740

Merged
Falk David merged 15 commits from casey-bianco-davis/blender:GPv3-Overlay-Visible-&-Editable-Materials into main 2023-12-08 10:38:22 +01:00

Makes it so that locked materials will not have their edit mode points and lines visible, and hidden materials will not have their strokes, fills, (edit) points and (edit) lines visible.

Makes it so that locked materials will not have their edit mode points and lines visible, and hidden materials will not have their strokes, fills, (edit) points and (edit) lines visible.
casey-bianco-davis added 1 commit 2023-12-04 06:31:00 +01:00
casey-bianco-davis added the
Interest
Grease Pencil
label 2023-12-04 21:31:36 +01:00
casey-bianco-davis added this to the Grease Pencil project 2023-12-04 21:31:44 +01:00
Falk David requested changes 2023-12-05 12:46:10 +01:00
Falk David left a comment
Member

Thanks. I added some comments.

Thanks. I added some comments.
@ -272,3 +275,1 @@
total_line_ids_num += curves.points_num();
/* Add one id for the last segment of every cyclic curve. */
total_line_ids_num += array_utils::count_booleans(curves.cyclic());
editable_strokes.foreach_index(GrainSize(512), [&](const int curve_i) {
Member

This shouldn't be in a loop. We should have something like:

total_line_ids_num += editable_strokes.size();
Array<int> size_per_editable_stroke(editable_strokes.size());
offset_indices::copy_group_sizes(points_by_curve, editable_strokes, size_per_editable_stroke);
total_line_ids_num += std::accumulate(size_per_editable_stroke.begin(), size_per_editable_stroke.end(), 0);
total_line_ids_num += array_utils::count_booleans(curves.cyclic(), size_per_editable_stroke);

We'd need a variant of count_booleans that also takes an IndexMask.

This shouldn't be in a loop. We should have something like: ``` total_line_ids_num += editable_strokes.size(); Array<int> size_per_editable_stroke(editable_strokes.size()); offset_indices::copy_group_sizes(points_by_curve, editable_strokes, size_per_editable_stroke); total_line_ids_num += std::accumulate(size_per_editable_stroke.begin(), size_per_editable_stroke.end(), 0); total_line_ids_num += array_utils::count_booleans(curves.cyclic(), size_per_editable_stroke); ``` We'd need a variant of `count_booleans` that also takes an `IndexMask`.
casey-bianco-davis marked this conversation as resolved
@ -282,3 +293,3 @@
".selection", ATTR_DOMAIN_POINT, true);
for (const int curve_i : curves.curves_range()) {
editable_strokes.foreach_index(GrainSize(512), [&](const int curve_i) {
Member

Using GrainSize here means that this runs in parallel, but the loop has to be run serial. So we need to remove GrainSize here.

Using `GrainSize` here means that this runs in parallel, but the loop has to be run serial. So we need to remove `GrainSize` here.
casey-bianco-davis marked this conversation as resolved
@ -314,3 +327,1 @@
for (const int curve_i : range) {
const IndexRange points = points_by_curve[curve_i];
const bool is_cyclic = cyclic[curve_i];
editable_strokes.foreach_index(GrainSize(512), [&](const int curve_i) {
Member

Same as above (the parallel_for from before is actually wrong). GPU_indexbuf_add_generic_vert can't be called in parallel as it is not atomic.

Same as above (the `parallel_for` from before is actually wrong). `GPU_indexbuf_add_generic_vert` can't be called in parallel as it is not atomic.
casey-bianco-davis marked this conversation as resolved
@ -339,3 +348,1 @@
if (!ed::curves::has_anything_selected(selection, points)) {
continue;
}
editable_strokes.foreach_index(GrainSize(512), [&](const int curve_i) {
Member

Same as above.

Same as above.
casey-bianco-davis marked this conversation as resolved
@ -408,1 +422,4 @@
int pos = 0;
for (const int curve_i : curves.curves_range()) {
IndexRange points = points_by_curve[curve_i];
if (visible_strokes.contains(curve_i)) {
Member

Note: This contains takes O(log n) which is a bit unfortunate. There might be a better way to avoid this but I can't immediatly see it. So for now I think it's fine.

Note: This `contains` takes `O(log n)` which is a bit unfortunate. There might be a better way to avoid this but I can't immediatly see it. So for now I think it's fine.
Author
Member

I noticed this to here's a some code that instead loop thru the missing curves. I think the code is a bit less readable but should more efficient.

I noticed this to here's a some code that instead loop thru the missing curves. I think the code is a bit less readable but should more efficient.
Member

Right, I think the contains is much easier to understand in comparison. Let's keep the version you had before and if this does come up in a profile at some point, we can improve it.

Right, I think the `contains` is much easier to understand in comparison. Let's keep the version you had before and if this does come up in a profile at some point, we can improve it.
casey-bianco-davis marked this conversation as resolved
@ -409,0 +434,4 @@
/* Calculate the vertex offsets for all the visible curves. */
int num_cyclic = 0;
int num_points = 0;
visible_strokes.foreach_index(GrainSize(512), [&](const int curve_i, const int pos) {
Member

Same as above. Remove GrainSize.

Same as above. Remove `GrainSize`.
casey-bianco-davis marked this conversation as resolved
@ -520,3 +539,1 @@
IndexRange verts_range = IndexRange(verts_start_offset, num_verts);
MutableSpan<GreasePencilStrokeVert> verts_slice = verts.slice(verts_range);
MutableSpan<GreasePencilColorVert> cols_slice = cols.slice(verts_range);
visible_strokes.foreach_index(GrainSize(512), [&](const int curve_i, const int pos) {
Member

Same as above.

Same as above.
casey-bianco-davis marked this conversation as resolved
casey-bianco-davis added 2 commits 2023-12-06 03:34:57 +01:00
casey-bianco-davis added 1 commit 2023-12-06 04:43:15 +01:00
Falk David requested changes 2023-12-06 10:34:40 +01:00
Falk David left a comment
Member

Added some more comments. Mix of cleanup and optimizations.

Added some more comments. Mix of cleanup and optimizations.
@ -180,0 +187,4 @@
return *static_cast<const bool *>(info.data) ? mask.size() : 0;
}
int64_t value = 0;
mask.foreach_index([&](const int64_t init) {
Member

const int64_t i

`const int64_t i`
casey-bianco-davis marked this conversation as resolved
@ -180,0 +189,4 @@
int64_t value = 0;
mask.foreach_index([&](const int64_t init) {
const bool is_cyclic = varray[init];
value += (is_cyclic ? 1 : 0);
Member

Since this is a generic version, this should be value += (varray[i] ? 1 : 0); or value += int(varray[i])

Since this is a generic version, this should be `value += (varray[i] ? 1 : 0);` or `value += int(varray[i])`
casey-bianco-davis marked this conversation as resolved
@ -324,3 +330,1 @@
}
GPU_indexbuf_add_primitive_restart(&elb);
for (const int point : points) {
Member

const int point_i

`const int point_i`
casey-bianco-davis marked this conversation as resolved
@ -170,0 +176,4 @@
if (material != nullptr && material->gp_style != nullptr &&
(material->gp_style->flag & GP_MATERIAL_HIDE) != 0)
{
hidden_material_indices.add(mat_i);
Member

Use add_new here since we know that every key we had has to be different from previously added keys.

Use `add_new` here since we know that every key we had has to be different from previously added keys.
casey-bianco-davis marked this conversation as resolved
@ -229,0 +248,4 @@
using namespace blender;
/* Get all the hidden material indices. */
VectorSet<int> hidden_material_indices = get_hidden_material_indices(object);
Member

I think it's worth it to add a small optimization here: Hiding materials is not very common (on average), so we should add a check here for hidden_material_indices.is_empty() and then just return drawing.strokes().curves_range().

I think it's worth it to add a small optimization here: Hiding materials is not very common (on average), so we should add a check here for `hidden_material_indices.is_empty()` and then just return `drawing.strokes().curves_range()`.
casey-bianco-davis marked this conversation as resolved
Hans Goudey requested changes 2023-12-06 14:39:05 +01:00
@ -180,0 +186,4 @@
if (info.type == CommonVArrayInfo::Type::Single) {
return *static_cast<const bool *>(info.data) ? mask.size() : 0;
}
int64_t value = 0;
Member

Better to modify the existing count_booleans function to have a mask argument. When the mask is a full selection, it should end up being the same anyway. Then you can provide an overload without a mask.

Better to modify the existing `count_booleans` function to have a mask argument. When the mask is a full selection, it should end up being the same anyway. Then you can provide an overload without a mask.
casey-bianco-davis marked this conversation as resolved
@ -229,0 +256,4 @@
/* Get all the strokes that have their material visible. */
const VArray<int> materials = *attributes.lookup_or_default<int>(
"material_index", ATTR_DOMAIN_CURVE, -1);
Member

Read the material index with a default of 0. But also, seems this work can be skipped when there is no attribute

Read the material index with a default of 0. But also, seems this work can be skipped when there is no attribute
casey-bianco-davis marked this conversation as resolved
casey-bianco-davis requested review from Falk David 2023-12-07 05:35:49 +01:00
casey-bianco-davis requested review from Hans Goudey 2023-12-07 05:35:49 +01:00
casey-bianco-davis added 10 commits 2023-12-07 05:35:54 +01:00
Falk David approved these changes 2023-12-07 10:18:46 +01:00
Falk David left a comment
Member

This looks good to me now. Just a cleanup comment, but will approve this.

This looks good to me now. Just a cleanup comment, but will approve this.
@ -183,0 +205,4 @@
if (locked_material_indices.contains(0)) {
return curves_range;
}
else {
Member

No need for an else after return

No need for an `else` after `return`
casey-bianco-davis marked this conversation as resolved
@ -207,0 +239,4 @@
if (locked_material_indices.contains(0)) {
return points_range;
}
else {
Member

Same as above

Same as above
casey-bianco-davis marked this conversation as resolved
Hans Goudey approved these changes 2023-12-07 15:20:54 +01:00
casey-bianco-davis added 1 commit 2023-12-08 03:25:46 +01:00
Falk David merged commit 58041799bc into main 2023-12-08 10:38:22 +01:00
Sign in to join this conversation.
No reviewers
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
3 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#115740
No description provided.