GPv3: Assign Material #113481

Closed
opened 2023-10-10 09:48:44 +02:00 by Pratik Borhade · 1 comment
Member

Change material of selected strokes

  • Create an operator in grease_pencil_edit.cc: GREASE_PENCIL_OT_assign_material or GREASE_PENCIL_OT_change_stroke_color
  • Add this operator in GP materials panel (properties_grease_pencil_common.py). Operator should be visible in UI only in edit mode.
  • In exec, function:
  • Get the selected material from the UIList (selected_material_index)
  • Iterate through all the drawings at current scene frame (foreach_editable_drawing)
    • Get geometry of this drawing
    • Get material attribute:
      attributes = curves.attributes_for_write();
      material_attribute = attributes.lookup_or_add_for_write_span<int>("material_index", ATTR_DOMAIN_CURVE);
    • Identify index of selected curve and assign selected material to it
      material_attribute.span[curve_index] = selected_material_index

Before exiting exec function, send depsgraph update and notifiers to other editors:

DEG_id_tag_update()
WM_event_add_notifier()

For reference:
see legacy GP operator: GPENCIL_OT_stroke_change_color
Also see other grease_pencil_* files

Change material of selected strokes - Create an operator in `grease_pencil_edit.cc`: `GREASE_PENCIL_OT_assign_material` or `GREASE_PENCIL_OT_change_stroke_color` - Add this operator in GP materials panel (`properties_grease_pencil_common.py`). Operator should be visible in UI only in edit mode. - In exec, function: - Get the selected material from the UIList (`selected_material_index`) - Iterate through all the drawings at current scene frame (`foreach_editable_drawing`) - Get geometry of this drawing - Get material attribute: `attributes = curves.attributes_for_write();` ` material_attribute = attributes.lookup_or_add_for_write_span<int>("material_index", ATTR_DOMAIN_CURVE);` - Identify index of selected curve and assign selected material to it `material_attribute.span[curve_index] = selected_material_index` Before exiting exec function, send depsgraph update and notifiers to other editors: ``` DEG_id_tag_update() WM_event_add_notifier() ``` - - - For reference: see legacy GP operator: `GPENCIL_OT_stroke_change_color` Also see other `grease_pencil_*` files
Pratik Borhade added the
Priority
Normal
Type
Report
Status
Needs Triage
labels 2023-10-10 09:48:45 +02:00
Pratik Borhade added this to the Grease Pencil project 2023-10-10 10:28:13 +02:00
Pratik Borhade changed title from GPV3: Assign Material to GPv3: Assign Material 2023-10-10 11:24:10 +02:00
Iliya Katushenock added
Type
Design
and removed
Priority
Normal
Status
Needs Triage
Type
Report
labels 2023-10-10 13:12:54 +02:00
Pratik Borhade self-assigned this 2023-10-11 15:40:33 +02:00
Pratik Borhade added the
Module
Grease Pencil
label 2023-10-12 13:02:12 +02:00
Author
Member
2a5c499585fe890b0c1c8540e1cf1f93509cec2c
Blender Bot added the
Status
Archived
label 2023-10-18 12:59:18 +02: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
1 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#113481
No description provided.