GPv3: Weight Paint Mode #117890

Open
opened 2024-02-06 11:31:41 +01:00 by Falk David · 0 comments
Member

This is an overview task for adding weight painting into Gease Pencil 3.

Weight painting tools

  • WPAINT_TOOL_DRAW
  • WPAINT_TOOL_BLUR
  • WPAINT_TOOL_AVERAGE
  • WPAINT_TOOL_SMEAR

Adding the mode

We should try and use the OB_MODE_WEIGHT_PAINT and CTX_MODE_PAINT_WEIGHT flags to avoid having to add more redundant code.

  • Slightly adapt PAINT_OT_weight_paint_toggle so it works with OB_GREASE_PENCIL objects. (!117945)
    • Make sure mode_toggle_poll_test accepts grease pencil (!117945)
  • Add case in object_mode_op_string for mode toggling

Adding the main draw operator

  • In grease_pencil_draw_ops.cc implement an operator (maybe GREASE_PENCIL_OT_weight_brush_stroke) that will be used for all the weight painting tools. See GREASE_PENCIL_OT_brush_stroke for reference. The operator uses the common paint_stroke API.
  • Make sure the poll function only succedes in OB_MODE_WEIGHT_PAINT and with a valid weight paint tool/brush.
  • Make sure there is a keymap for this operator in blender_default.py.

Adding a tool

  • In source/blender/editors/sculpt_paint/grease_pencil_intern.hh declare a new operation (e.g. new_weight_draw_operation)
  • Create a file for the new draw operation (e.g. grease_pencil_weight_draw.cc).
  • In that file implement a class that inherits from GreasePencilStrokeOperation and overrides the following functions
    • void on_stroke_begin(const bContext &C, const InputSample &start_sample) override;
    • void on_stroke_extended(const bContext &C, const InputSample &extension_sample) override;
    • void on_stroke_done(const bContext &C) override;
  • In order to avoid passing tons of arguments to these function, implement an Executor struct. See e.g. PaintOperation::on_stroke_extended for how that's used.
  • In start_weight_brush_operation get the brush from BKE_paint_brush_for_read(scene.toolsettings->wpaint.paint) and check the weightpaint_tool (see eBrushWeightPaintTool) and create the new operation that was implemented.
  • For the toolbar in the UI
    • In VIEW3D_PT_tools_active the _defs_weight_paint.generate_from_brushes in 'PAINT_WEIGHT': should work.
    • Other declarations might have to be disabled for grease pencil.

Overlays

  • In source/blender/draw/intern/draw_cache_impl_grease_pencil.cc create something like grease_pencil_weight_batch_ensure. This should create a GPUVertBuf for the weights similar to grease_pencil_edit_batch_ensure which reads the selection.
  • Use this batch cache in source/blender/draw/engines/overlay/overlay_grease_pencil.cc to make the draw calls (similar to OVERLAY_edit_grease_pencil_cache_populate)
  • In blender/source/blender/draw/engines/overlay/overlay_engine.cc in this caseelse if (in_paint_mode && !pd->hide_overlays) {, call the new populate function if the object type is grease pencil.

Operators

Operators that are not painting operators should be implemented in blender/source/blender/editors/grease_pencil/intern/grease_pencil_weights.cc.

  • GPENCIL_OT_weight_toggle_direction
  • GPENCIL_OT_weight_sample
  • GPENCIL_OT_generate_weights
This is an overview task for adding weight painting into Gease Pencil 3. ## Weight painting tools - [x] `WPAINT_TOOL_DRAW` - [x] `WPAINT_TOOL_BLUR` - [x] `WPAINT_TOOL_AVERAGE` - [x] `WPAINT_TOOL_SMEAR` ## Adding the mode We should try and use the `OB_MODE_WEIGHT_PAINT` and `CTX_MODE_PAINT_WEIGHT` flags to avoid having to add more redundant code. - [x] Slightly adapt `PAINT_OT_weight_paint_toggle` so it works with `OB_GREASE_PENCIL` objects. (!117945) - [x] Make sure `mode_toggle_poll_test` accepts grease pencil (!117945) - [x] ~~Add case in `object_mode_op_string` for mode toggling~~ ## Adding the main draw operator - [x] In `grease_pencil_draw_ops.cc` implement an operator (maybe `GREASE_PENCIL_OT_weight_brush_stroke`) that will be used for all the weight painting tools. See `GREASE_PENCIL_OT_brush_stroke` for reference. The operator uses the common `paint_stroke` API. - [x] Make sure the poll function only succedes in `OB_MODE_WEIGHT_PAINT` and with a valid weight paint tool/brush. - [x] Make sure there is a keymap for this operator in `blender_default.py`. ## Adding a tool - In `source/blender/editors/sculpt_paint/grease_pencil_intern.hh` declare a new operation (e.g. `new_weight_draw_operation`) - Create a file for the new draw operation (e.g. `grease_pencil_weight_draw.cc`). - In that file implement a class that inherits from `GreasePencilStrokeOperation` and overrides the following functions - `void on_stroke_begin(const bContext &C, const InputSample &start_sample) override;` - `void on_stroke_extended(const bContext &C, const InputSample &extension_sample) override;` - `void on_stroke_done(const bContext &C) override;` - In order to avoid passing tons of arguments to these function, implement an `Executor` struct. See e.g. `PaintOperation::on_stroke_extended` for how that's used. - In `start_weight_brush_operation` get the brush from `BKE_paint_brush_for_read(scene.toolsettings->wpaint.paint)` and check the `weightpaint_tool` (see `eBrushWeightPaintTool`) and create the new operation that was implemented. - For the toolbar in the UI - In `VIEW3D_PT_tools_active` the `_defs_weight_paint.generate_from_brushes` in `'PAINT_WEIGHT':` should work. - Other declarations might have to be disabled for grease pencil. ## Overlays - [x] In `source/blender/draw/intern/draw_cache_impl_grease_pencil.cc` create something like `grease_pencil_weight_batch_ensure`. This should create a `GPUVertBuf` for the weights similar to `grease_pencil_edit_batch_ensure` which reads the selection. - [x] Use this batch cache in `source/blender/draw/engines/overlay/overlay_grease_pencil.cc` to make the draw calls (similar to `OVERLAY_edit_grease_pencil_cache_populate`) - [x] In `blender/source/blender/draw/engines/overlay/overlay_engine.cc` in this case`else if (in_paint_mode && !pd->hide_overlays) {`, call the new populate function if the object type is grease pencil. ## Operators Operators that are not painting operators should be implemented in `blender/source/blender/editors/grease_pencil/intern/grease_pencil_weights.cc`. - [ ] `GPENCIL_OT_weight_toggle_direction` - [x] `GPENCIL_OT_weight_sample` - [ ] `GPENCIL_OT_generate_weights`
Falk David added the
Type
To Do
label 2024-02-06 11:31:41 +01:00
Falk David added this to the Grease Pencil project 2024-02-06 11:31:44 +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
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#117890
No description provided.