GPv3: Fix Remove Material Slot and Unused Slots #114850

Merged
Falk David merged 8 commits from antoniov/blender:GPv3_remove_unused_mat into main 2023-11-17 10:38:06 +01:00

There was two problems because these operators were not supported in GPv3:

  • If you remove the slot, the material was not reasigned and the attribute could get a wrong index. This also affected the unused slots.
  • The Unused Materials operator was executed, but it was doing nothing because there was not support for new GPv3 object.

This PR adds support for new Grease Pencil object.

There was two problems because these operators were not supported in GPv3: * If you remove the slot, the material was not reasigned and the attribute could get a wrong index. This also affected the unused slots. * The Unused Materials operator was executed, but it was doing nothing because there was not support for new GPv3 object. This PR adds support for new Grease Pencil object.
Antonio Vazquez added 1 commit 2023-11-14 16:28:24 +01:00
1aec65c9d2 GPv3: Fix Remove Material Slot and Unused Slots
There was two problems:

* If you remove the slot, the material was not reasigned
and the attribute could get a wrong index.
* The Unused Materials operator was executed, but
it was doing nothing.
Antonio Vazquez requested review from Falk David 2023-11-14 16:28:46 +01:00
Antonio Vazquez requested review from Hans Goudey 2023-11-14 16:28:53 +01:00
Antonio Vazquez requested review from Matias Mendiola 2023-11-14 16:29:01 +01:00
Antonio Vazquez added this to the Grease Pencil project 2023-11-14 16:29:09 +01:00
Antonio Vazquez added 1 commit 2023-11-14 18:54:34 +01:00
Hans Goudey requested changes 2023-11-15 14:34:34 +01:00
Hans Goudey left a comment
Member

it seems better to mirror BKE_mesh_material_index_remove more directly by modifying material_data_index_remove_id.

it seems better to mirror `BKE_mesh_material_index_remove` more directly by modifying `material_data_index_remove_id`.
@ -1393,0 +1401,4 @@
greasepencil::Drawing &drawing = reinterpret_cast<GreasePencilDrawing *>(base)->wrap();
MutableAttributeAccessor attributes = drawing.strokes_for_write().attributes_for_write();
SpanAttributeWriter<int> material_indices = attributes.lookup_or_add_for_write_span<int>(
Member

Call lookup_for_write instead of lookup_or_add_for_write_span. Removing a material shouldn't add the material_index attribute. Check BKE_mesh_material_index_remove for an example.

Call `lookup_for_write` instead of `lookup_or_add_for_write_span`. Removing a material shouldn't add the `material_index` attribute. Check `BKE_mesh_material_index_remove` for an example.
antoniov marked this conversation as resolved
@ -1393,0 +1430,4 @@
greasepencil::Drawing &drawing = reinterpret_cast<GreasePencilDrawing *>(base)->wrap();
AttributeAccessor attributes = drawing.strokes().attributes();
const VArraySpan<int> material_indices = *attributes.lookup_or_default<int>(
"material_index", ATTR_DOMAIN_CURVE, -1);
Member

Read material indices with the default of 0, not -1, which is an invalid value.

Read material indices with the default of 0, not -1, which is an invalid value.
antoniov marked this conversation as resolved
Antonio Vazquez added 1 commit 2023-11-15 15:03:25 +01:00
Antonio Vazquez added 1 commit 2023-11-15 16:58:20 +01:00
Falk David requested changes 2023-11-16 10:34:32 +01:00
Falk David left a comment
Member

Thanks for working on this. Only have one comment.

Thanks for working on this. Only have one comment.
@ -1393,0 +1411,4 @@
for (const int i : indices_span.index_range()) {
if ((indices_span[i] > index) || (indices_span[i] > totcol - 1)) {
indices_span[i]--;
indices_span[i] = std::max(indices_span[i], 0);
Member

Writing this in a single line as indices_span[i] = std::max(indices_span[i] - 1, 0); seems a bit better.

Writing this in a single line as `indices_span[i] = std::max(indices_span[i] - 1, 0);` seems a bit better.
antoniov marked this conversation as resolved
Falk David requested review from Hans Goudey 2023-11-16 10:34:42 +01:00
Antonio Vazquez added 1 commit 2023-11-16 13:01:31 +01:00
Falk David approved these changes 2023-11-16 13:52:26 +01:00
Hans Goudey requested changes 2023-11-16 14:00:41 +01:00
@ -1390,6 +1390,55 @@ void BKE_grease_pencil_material_remap(GreasePencil *grease_pencil, const uint *r
}
}
void BKE_grease_pencil_material_index_reassign(GreasePencil *grease_pencil, int totcol, int index)
Member

The naming convention to copy should be from meshes: BKE_mesh_material_index_remove

The naming convention to copy should be from meshes: `BKE_mesh_material_index_remove`
antoniov marked this conversation as resolved
@ -1393,0 +1409,4 @@
MutableVArraySpan<int> indices_span(material_indices.varray);
for (const int i : indices_span.index_range()) {
if ((indices_span[i] > index) || (indices_span[i] > totcol - 1)) {
Member

These parentheses are unnecessary, std::max should be used too. Better to just copy the logic from BKE_mesh_material_index_remove directly.

These parentheses are unnecessary, `std::max` should be used too. Better to just copy the logic from `BKE_mesh_material_index_remove` directly.
antoniov marked this conversation as resolved
@ -1370,2 +1372,4 @@
BKE_gpencil_material_index_reassign((bGPdata *)ob->data, ob->totcol, actcol - 1);
}
/* check indices from greease pencil. */
else if (ob->type == OB_GREASE_PENCIL) {
Member

Please change material_data_index_remove_id instead of adding this here. We should be consistent with the way other IDs are handled.

Please change `material_data_index_remove_id` instead of adding this here. We should be consistent with the way other IDs are handled.
antoniov marked this conversation as resolved
Antonio Vazquez added 1 commit 2023-11-16 15:28:33 +01:00
e8352a653d GPv3: Changes after review
* Rename function and change logic as is done in meshes.
* MOve update to `material_data_index_remove_id`
Hans Goudey approved these changes 2023-11-16 15:41:58 +01:00
@ -464,2 +464,4 @@
BKE_curve_material_index_remove((Curve *)id, index);
break;
case ID_GP:
BKE_grease_pencil_material_index_remove((GreasePencil *)id, index);
Member

reinterpret_cast<GreasePencil *>(id)

New code should use C++ casts for pointers instead of C-style casts which can remove const.

`reinterpret_cast<GreasePencil *>(id)` New code should use C++ casts for pointers instead of C-style casts which can remove const.
antoniov marked this conversation as resolved
Antonio Vazquez added 1 commit 2023-11-16 17:33:21 +01:00
Antonio Vazquez added 1 commit 2023-11-16 17:35:41 +01:00
Falk David merged commit 00b04e1030 into main 2023-11-17 10:38:06 +01:00
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
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#114850
No description provided.