Grease Pencil - vvoovv/notes GitHub Wiki
Basic
D
+ LMB
: draw a stroke
D
+ Tab
: switching between drawing and editing strokes
Sculpting in Edit Strokes
D
+ E
: pie menu for sculpting tools
F
: scult brush size
Shift
+ F
: sculpt brush strength
E
+ LMB
: perform sculpting
↑
, ↓
: move between keyframes
→
, ←
: increase or decrease the current frame number by one
Ctrl
+ Shift
+ E
: automaticaly create an in-between frame by interpolating the neighboring frames
Python
Introduction
As one draws strokes are added to the data of the selected Grease Pencil Object.
Strokes are always associated with Layers of the Grease Pencil Object. Layers act similar to Photoshop layers.
Strokes are also associated with the current frame
Strokes are composed of points.
Grease Pencil object needs a material to be rendered properly.
In the Python API these various components are structured as a nested hierarchy. Each component has a related class:
Grease Pencil (GreasePencil)
=> Layers (GPencilLayer)
=> Frames (GPencilFrame)
=> Strokes (GPencilStroke)
=> Points (GPencilStrokePoint)
Code Sample
import bpy
#
# Create a grease pencil object
#
gp = bpy.data.grease_pencils.new("Grease Pencil")
gpo = bpy.data.objects.new(gp.name, gp)
bpy.context.collection.objects.link(gpo)
#
# Create a layer
#
gpLayer = gp.layers.new("Main Layer")
#
# Create a frame
#
gpFrame = gpLayer.frames.new(bpy.context.scene.frame_current)
#
# Clear the frame from strokes
#
#gpFrame.clear()
#
# Create a stroke
#
gpStroke = gpFrame.strokes.new()
gpStroke.line_width = 100
gpStroke.start_cap_mode = 'ROUND'
gpStroke.end_cap_mode = 'ROUND'
gpStroke.use_cyclic = True
points = [
( 0.0, 0.0, 0.0),
(20.0, 0.0, 0.0),
(20.0, 0.0, 10.0),
( 0.0, 0.0, 10.0)
]
#
# Create slots for the given number of points
#
gpStroke.points.add(len(points))
#
# Fill the slots with the points
#
for index, point in enumerate(points):
gpStroke.points[index].co = point
#
# Properties of an individual point:
# pressure
# vertex color
# strength (i.e. opacity)
gpStroke.points[0].pressure = 10
gpStroke.points[-1].vertex_color = (0., 1., 0., 1.)
gpStroke.points[1].strength = 0.5
#
# Adding a material and setting its properties
#
material = bpy.data.materials.new(name="Black")
bpy.data.materials.create_gpencil_data(material)
gpo.data.materials.append(material)
material.grease_pencil.show_fill = False
#material.grease_pencil.fill_color = (1.0, 0.0, 1.0, 1.0)
material.grease_pencil.color = (0.0, 0.0, 0.0, 1.0)
#
# Add Noise modifier to the grease pencil object
#
m = gpo.grease_pencil_modifiers.new("Noise", type="GP_NOISE")