GPv3: Set selected curve material as active material #114188

Merged
Falk David merged 12 commits from antoniov/blender:GPv3_Set_selected_as_actmat into main 2023-11-08 15:00:59 +01:00

This operator assigns the material of the first selected curve as active material.

Related to #113569

This operator assigns the material of the first selected curve as active material. Related to #113569
Antonio Vazquez added 1 commit 2023-10-27 11:12:28 +02:00
cbf5ff98dd GPv3: Set selected curve material as active material
This operator assigns the material of the first selected curve as
active material.
Antonio Vazquez requested review from Falk David 2023-10-27 11:12:39 +02:00
Antonio Vazquez requested review from Matias Mendiola 2023-10-27 11:12:47 +02:00
Antonio Vazquez added this to the Grease Pencil project 2023-10-27 11:12:54 +02:00
Antonio Vazquez added 1 commit 2023-10-28 09:25:15 +02:00
Pratik Borhade reviewed 2023-10-29 22:44:18 +01:00
@ -951,0 +960,4 @@
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(object->data);
bool changed = false;
grease_pencil.foreach_editable_drawing(
scene->r.cfra, [&](int /*drawing_index*/, bke::greasepencil::Drawing &drawing) {
Member

I guess /*layer_index*/ ? :)

I guess `/*layer_index*/` ? :)
antoniov marked this conversation as resolved
Pratik Borhade reviewed 2023-10-29 22:48:36 +01:00
@ -240,2 +240,3 @@
if constexpr (std::is_same_v<T, float> || std::is_same_v<T, float2> ||
std::is_same_v<T, float3>) {
std::is_same_v<T, float3>)
{
Member

Unintentional formatting 😅

Unintentional formatting 😅
Author
Member

I can't avoid this. It's the autoformat when saving.

I can't avoid this. It's the autoformat when saving.
Member

maybe revert the change from some other text editor?

maybe revert the change from some other text editor?
Author
Member

Yes, I know.... what I mean is that this line is wrongly formatted, so every time I update the code I must revert the "right" format to set the "wrong" format again. As this format is not changing anything in the code, IMHO, it's better to keep it in the patch. If not, the real solution would be commit a make format commit.

Yes, I know.... what I mean is that this line is wrongly formatted, so every time I update the code I must revert the "right" format to set the "wrong" format again. As this format is not changing anything in the code, IMHO, it's better to keep it in the patch. If not, the real solution would be commit a `make format` commit.
Member

It is expected that every patch is properly formatted with clang format. If it's formatting incorrectly, there is something wrong with your setup, and that's worth resolving.

It is expected that every patch is properly formatted with clang format. If it's formatting incorrectly, there is something wrong with your setup, and that's worth resolving.
Member

Ah sorry, I think I misunderstood the situation. Doesn't matter to me what happens here then

Ah sorry, I think I misunderstood the situation. Doesn't matter to me what happens here then
Member

This formatting change doesn't happen for me with make format. Maybe you have a different version of clang-format? Make sure to use the one from the libs. blender-git/lib/<platform-name>/llvm/bin/clang-format

This formatting change doesn't happen for me with `make format`. Maybe you have a different version of clang-format? Make sure to use the one from the libs. `blender-git/lib/<platform-name>/llvm/bin/clang-format`
Antonio Vazquez added 1 commit 2023-10-30 08:27:11 +01:00
Antonio Vazquez added 1 commit 2023-10-30 08:30:18 +01:00
Hans Goudey requested changes 2023-10-30 21:12:24 +01:00
@ -812,3 +813,3 @@
grease_pencil.foreach_editable_drawing(
scene->r.cfra, [&](int /*drawing_index*/, bke::greasepencil::Drawing &drawing) {
scene->r.cfra, [&](int /*layer_index*/, bke::greasepencil::Drawing &drawing) {
Member

This seems unrelated as well

This seems unrelated as well
antoniov marked this conversation as resolved
@ -951,0 +971,4 @@
if (selected_curves.is_empty()) {
return;
}
const blender::VArray<int> materials = *curves.attributes().lookup_or_default<int>(
Member

material_index should be retrieved with the default of 0 rather than -1. That's the standard default value used for all integer attributes, and it means we refer to the first material when there is no attribute.

`material_index` should be retrieved with the default of `0` rather than `-1`. That's the standard default value used for all integer attributes, and it means we refer to the first material when there is no attribute.
antoniov marked this conversation as resolved
@ -951,0 +974,4 @@
const blender::VArray<int> materials = *curves.attributes().lookup_or_default<int>(
"material_index", ATTR_DOMAIN_CURVE, -1);
selected_curves.foreach_index([&](const int curve_index) {
Member

Use selected_curves.first() rather than looping and stopping at the first iteration.

Use `selected_curves.first()` rather than looping and stopping at the first iteration.
antoniov marked this conversation as resolved
@ -951,0 +975,4 @@
"material_index", ATTR_DOMAIN_CURVE, -1);
selected_curves.foreach_index([&](const int curve_index) {
if (materials[curve_index] != -1) {
Member

We should never store -1 as a material index on geometry-- the values are always means to be greater than or equal to 0. So you shouldn't need to check that here.

We should never store `-1` as a material index on geometry-- the values are always means to be greater than or equal to 0. So you shouldn't need to check that here.
antoniov marked this conversation as resolved
Antonio Vazquez added 2 commits 2023-10-31 08:47:39 +01:00
Antonio Vazquez added 1 commit 2023-10-31 08:58:36 +01:00
Antonio Vazquez added 1 commit 2023-10-31 11:07:53 +01:00
Author
Member

Format problem solved thanks to @SietseB

The problem was the clang program of Microsoft is slightly different of the clang used by make format. The solution is to set a custom clang executable in Visual Studio.

Format problem solved thanks to @SietseB The problem was the clang program of Microsoft is slightly different of the clang used by `make format`. The solution is to set a custom clang executable in Visual Studio.
Falk David requested changes 2023-11-01 10:56:32 +01:00
Falk David left a comment
Member

I think in the future this operator should probably be replaced by something else (see comment).

I think in the future this operator should probably be replaced by something else (see comment).
@ -951,0 +973,4 @@
const blender::VArray<int> materials = *curves.attributes().lookup_or_default<int>(
"material_index", ATTR_DOMAIN_CURVE, 0);
if (object->totcol > 0) {
object->actcol = materials[selected_curves.first()] + 1;
Member

It's not relevant for this PR but I find it a bit strange that the operator just looks at the first selected curve here. I wonder if a better approach would be something like pick_material where we find the closest curve and set its material as the active one. See ed_grease_pencil_select_pick. Or we finally introduce an active element for the point and curve domain. Then this operator would set the active material based on the material of the active curve.

It's not relevant for this PR but I find it a bit strange that the operator just looks at the first selected curve here. I wonder if a better approach would be something like `pick_material` where we find the closest curve and set its material as the active one. See `ed_grease_pencil_select_pick`. Or we finally introduce an active element for the point and curve domain. Then this operator would set the active material based on the material of the active curve.

This operator was introduced before Grease Pencil had the eyedropper tool.
Now that we have an eyedropper tool, we can use it with CTRL or SHIFT to pick over a stroke and change the active material instead of creating a new one. That way this operator will no longer be necessary.

This operator was introduced before Grease Pencil had the eyedropper tool. Now that we have an eyedropper tool, we can use it with CTRL or SHIFT to pick over a stroke and change the active material instead of creating a new one. That way this operator will no longer be necessary.
Author
Member

I'm not sure the eyedropper is the replace for this operator. First, this is not easy to discover and maybe you want use the actual selection.

IMHO the best solution would be to implement the concept of "active stroke"...in this way, you can select something and assign the material base on active item, not first one as is now.

I'm not sure the eyedropper is the replace for this operator. First, this is not easy to discover and maybe you want use the actual selection. IMHO the best solution would be to implement the concept of "active stroke"...in this way, you can select something and assign the material base on active item, not first one as is now.

Agree, an "active stroke" is very necessary and not only for this, but in my experience teaching Grease Pencil, artists always try to use the eyedropper to get the active material, only to realize later that what it does is create new materials/colors. Maybe we should have both: tool and operator for that functionality, but it's something to discuss outside of this PR :)

Agree, an "active stroke" is very necessary and not only for this, but in my experience teaching Grease Pencil, artists always try to use the eyedropper to get the active material, only to realize later that what it does is create new materials/colors. Maybe we should have both: tool and operator for that functionality, but it's something to discuss outside of this PR :)
Author
Member

Yes, I'm talking about having both operators.

Yes, I'm talking about having both operators.
Member

yes, concept of "active stroke" will resolve this situation.

just looks at the first selected curve here

I also found this bit confusing while creating the task.

yes, concept of "active stroke" will resolve this situation. > just looks at the first selected curve here I also found this bit confusing while creating the task.
@ -951,0 +976,4 @@
object->actcol = materials[selected_curves.first()] + 1;
}
changed = true;
return;
Member

This return doesn't do anything. The lambda function returns here anyways. We would have to introduce a way of returning a value that would exit from the loop in foreach_editable_drawing. Then we don't need the

if (changed) {
   return;
}

at the top.

This `return` doesn't do anything. The lambda function returns here anyways. We would have to introduce a way of returning a value that would exit from the loop in `foreach_editable_drawing`. Then we don't need the ``` if (changed) { return; } ``` at the top.
antoniov marked this conversation as resolved
Antonio Vazquez added 1 commit 2023-11-01 11:39:38 +01:00
c4a4edb0a5 GPv3: Remove return
This return was valid when there was a loop.
Antonio Vazquez added 2 commits 2023-11-02 18:38:16 +01:00
Matias Mendiola approved these changes 2023-11-06 17:56:11 +01:00
Author
Member

Why don't merge this operator as is today (equals to GPv2) ? and later, when active stroke concept will be ready, we can change it, but at least with this PR we have same feature of GPv2.

Why don't merge this operator as is today (equals to GPv2) ? and later, when active stroke concept will be ready, we can change it, but at least with this PR we have same feature of GPv2.
Falk David approved these changes 2023-11-07 14:03:48 +01:00
Falk David left a comment
Member

Other than my last comment, the code looks good. We can replace this with something better later.

Other than my last comment, the code looks good. We can replace this with something better later.
@ -960,0 +983,4 @@
}
};
WM_event_add_notifier(C, NC_GEOM | ND_DATA | NA_EDITED, &grease_pencil);
Member

I see that there is not depsgraph tag here. Have you tested it? Is it updating correctly?

I see that there is not depsgraph tag here. Have you tested it? Is it updating correctly?
Author
Member

Yes, I tested. The tag is not needed because what it is changed here is the active material in the object and the notifier is enough here.

Yes, I tested. The tag is not needed because what it is changed here is the active material in the object and the notifier is enough here.
Hans Goudey reviewed 2023-11-08 09:20:50 +01:00
@ -960,0 +973,4 @@
IndexMaskMemory memory;
IndexMask selected_curves = ed::curves::retrieve_selected_curves(curves, memory);
if (!selected_curves.is_empty()) {
Member

Use continue instead of indenting the rest of the loop

Use `continue` instead of indenting the rest of the loop
antoniov marked this conversation as resolved
@ -960,0 +976,4 @@
if (!selected_curves.is_empty()) {
const blender::VArray<int> materials = *curves.attributes().lookup_or_default<int>(
"material_index", ATTR_DOMAIN_CURVE, 0);
if (object->totcol > 0) {
Member

This check can be moved to the beginning of the exec callback

This check can be moved to the beginning of the exec callback
antoniov marked this conversation as resolved
Antonio Vazquez added 1 commit 2023-11-08 12:18:21 +01:00
Hans Goudey approved these changes 2023-11-08 14:11:22 +01:00
Falk David merged commit a8cb0b0ca0 into main 2023-11-08 15:00:58 +01:00
Member

@antoniov Any changes should be documented in #114419

@antoniov Any changes should be documented in #114419
Sign in to join this conversation.
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
5 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#114188
No description provided.