-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathstippleit.py
More file actions
executable file
·70 lines (57 loc) · 2.15 KB
/
stippleit.py
File metadata and controls
executable file
·70 lines (57 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import bpy
from .utils import process_stroke_verts_linearly
class GREASEPENCIL_OT_stippleit(bpy.types.Operator):
bl_label = "Stipple It"
bl_idname = "grease_writer.stippleit"
bl_description = "Stipples the strokes of the Grease pencil layer"
bl_options = {"REGISTER", "UNDO"}
@classmethod
def poll(self, context):
obj = bpy.context.view_layer.objects.active
gpencil = obj.data
if len(gpencil.layers) > 0:
return True
else:
return False
def execute(self, context):
scene = context.scene
obj = bpy.context.view_layer.objects.active
gpencil = obj.data
stipple_length = gpencil.stipple_length
thicknesses = []
layer = gpencil.layers[0]
frame = layer.frames[-1]
glyph_strokes = []
for stroke in frame.strokes:
verts = []
thicknesses.append(stroke.line_width)
for point in stroke.points:
verts.append([point.co.x, point.co.y, point.co.z])
glyph_strokes.append(verts)
layer.clear()
stippled_strokes = []
remaining = 0
x = 0
stipple_skip = gpencil.stipple_skip + 1
for i in range(len(glyph_strokes)):
stroke_verts = glyph_strokes[i]
framed_strokes, remaining = process_stroke_verts_linearly(stroke_verts, stipple_length, remaining=remaining, stipple=True)
if x % stipple_skip > 0:
x %= stipple_skip
else:
x = 0
while x < len(framed_strokes):
if x % stipple_skip == 0:
stippled_strokes.append(framed_strokes[x])
x += 1
frame = layer.frames.new(0)
for stroke_verts in stippled_strokes:
stroke = frame.strokes.new()
stroke.line_width = thicknesses[i]
stroke.display_mode = '3DSPACE'
for vert in stroke_verts:
stroke.points.add(1)
stroke.points[-1].co.x = vert[0]
stroke.points[-1].co.y = vert[1]
stroke.points[-1].co.z = vert[2]
return {"FINISHED"}