blender/scripts/presets/gpencil_material/Fill_Only.py
Falk David 7f1a798fc9 Grease Pencil: New Fill Workflow
Design: #153035 (effectively combines implementations of #148647 and #114071).

## Overview

Instead of creating and setting materials on strokes to enable/disable the fill, users can
now fill strokes using operators and tool settings. For example, the draw tool has a brush
option Stroke/Fill/Both that dictates how the curves are created and if they are filled or
not. If users want to add/remove the stroke/fill they can do so using dedicated
operators in edit mode.

Fills can now have holes. Existing operators and tools are updated to account for holes
if necessary. Additionally, there are new operators to select, create and remove fills.

## Changes

Here is a summary of the user facing changes:

* The `Draw` tool and the `Primitive` tool have a setting to toggle between creating
   strokes, fills, or both.
* A warning is displayed when trying to create a fully transparent stroke.
* The `Fill` tool can create holes now if needed.
* The `Delete` menu has two new entries:
   * `Only Strokes`: Will delete only the selected strokes, without removing any fills.
   * `Only Fills`: Will delete only the selected fills, without removing any strokes.
* Duplicating strokes will automatically separate fills into individual fills.
* New `Set Stroke Type` operator to set the stroke, fill or both on the selection.
* New `Join Fills` operator to join a set of strokes into the same fill. Inside strokes are
   automatically treated as holes (using the even-odd rule).
* New `Separate Fills` operator to separate strokes into new (individual) fills.
* New `Select Fill` operator to select all the stroke/points that are part of the same fill.
   Similar to `Select Linked`.
* New operator `Select` > `By Stroke Type` to select all the fills/strokes in a drawing.
* The `Trace Image` operator can create holes now if needed.
* The SVG importer can create holes.
* When in Stroke Selection mode, selecting a stroke automatically selects the entire fill.
   This is intentional to make working with and transforming fills easier.
* Performance of the drawing tool has been improved when drawing very long strokes.
   Overall, tools like the sculpting tools, or rendering Grease Pencil should also benefit.

## Forward & Backwards compatibility

* When loading older files materials, strokes, and brushes are versioned to the new
   fills system. Visual compatibility is kept.
* The (now deprecated) flags on the material to toggle the stroke/fill are kept for
  forward compatibility. The attributes that get created during versioning to the new
  system will just be unused in older versions.

## Technical Details

Removes the Grease Pencil materials stroke and fill toggles and replaces
them with geometry attributes:

* `hide_stroke`: Boolean value. Toggles the visibility of the stroke (both in the viewport
   and final render). Since the default value for boolean attributes is `false`, curves render
   their stroke by default.
* `fill_id`: This is a group ID. The value `0` indicates that the curve is not filled. Since this
  is the default value, curves are not filled by default. A value `!= 0` is a fill group ID. Curves
  with the same `fill_id` are triangulated together using a constrained delaunay
  triangulation (CDT) with holes (according to the even-odd rule).

For the fills in a drawing there is a lazy cache called `FillsCache` that stores the indices and
offsets of the fills. Additionally there is a `TriangleCache` that caches the triangles for each
fill. Both of these caches are optional for when there are no fills.

---

Co-authored-by: Casey Bianco-Davis <caseycasey739@gmail.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/153036
2026-02-02 17:29:38 +01:00

23 lines
671 B
Python

import bpy
material = bpy.context.object.active_material
gpcolor = material.grease_pencil
gpcolor.mode = 'LINE'
gpcolor.stroke_style = 'SOLID'
gpcolor.color = (0.0, 0.0, 0.0, 0.0)
gpcolor.stroke_image = None
gpcolor.pixel_size = 100.0
gpcolor.mix_stroke_factor = 0.0
gpcolor.alignment_mode = 'PATH'
gpcolor.fill_style = 'SOLID'
gpcolor.fill_color = (0.5, 0.5, 0.5, 1.0)
gpcolor.fill_image = None
gpcolor.gradient_type = 'LINEAR'
gpcolor.mix_color = (1.0, 1.0, 1.0, 0.2)
gpcolor.mix_factor = 0.0
gpcolor.flip = False
gpcolor.texture_offset = (0.0, 0.0)
gpcolor.texture_scale = (1.0, 1.0)
gpcolor.texture_angle = 0.0
gpcolor.texture_clamp = False
gpcolor.mix_factor = 0.0