GPv3: Set selected curve material as active material #114188
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
5 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#114188
Loading…
Reference in New Issue
No description provided.
Delete Branch "antoniov/blender:GPv3_Set_selected_as_actmat"
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 operator assigns the material of the first selected curve as active material.
Related to #113569
@ -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) {
I guess
/*layer_index*/
? :)@ -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>)
{
Unintentional formatting 😅
I can't avoid this. It's the autoformat when saving.
maybe revert the change from some other text editor?
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.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.
Ah sorry, I think I misunderstood the situation. Doesn't matter to me what happens here then
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
@ -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) {
This seems unrelated as well
@ -951,0 +971,4 @@
if (selected_curves.is_empty()) {
return;
}
const blender::VArray<int> materials = *curves.attributes().lookup_or_default<int>(
material_index
should be retrieved with the default of0
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.@ -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) {
Use
selected_curves.first()
rather than looping and stopping at the first iteration.@ -951,0 +975,4 @@
"material_index", ATTR_DOMAIN_CURVE, -1);
selected_curves.foreach_index([&](const int curve_index) {
if (materials[curve_index] != -1) {
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.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.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;
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. Seeed_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.
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 :)
Yes, I'm talking about having both operators.
yes, concept of "active stroke" will resolve this situation.
I also found this bit confusing while creating the task.
@ -951,0 +976,4 @@
object->actcol = materials[selected_curves.first()] + 1;
}
changed = true;
return;
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 inforeach_editable_drawing
. Then we don't need theat the top.
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.
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);
I see that there is not depsgraph tag here. Have you tested it? Is it updating correctly?
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.
@ -960,0 +973,4 @@
IndexMaskMemory memory;
IndexMask selected_curves = ed::curves::retrieve_selected_curves(curves, memory);
if (!selected_curves.is_empty()) {
Use
continue
instead of indenting the rest of the loop@ -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) {
This check can be moved to the beginning of the exec callback
@antoniov Any changes should be documented in #114419