Skip to content

Commit 2d742de

Browse files
committed
Added scene settings, 2 new fonts, reanimate works for 3d, new 'stippleit' operator
1 parent 1154457 commit 2d742de

File tree

305 files changed

+998
-311
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

305 files changed

+998
-311
lines changed

__init__.py

Lines changed: 98 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class GREASEPENCIL_PT_greasewriter(bpy.types.Panel):
2020
bl_space_type = "PROPERTIES"
2121
bl_region_type = "WINDOW"
2222
bl_context = "data"
23+
bl_options = {"DEFAULT_CLOSED"}
2324

2425
@classmethod
2526
def poll(self, context):
@@ -32,55 +33,98 @@ def draw(self, context):
3233
scene = context.scene
3334
gpencil = context.active_object.data
3435
layout = self.layout
35-
layout.prop(gpencil, 'draw_speed')
36-
layout.prop(gpencil, 'kerning')
37-
layout.prop(gpencil, 'line_height')
38-
layout.prop(gpencil, 'write_thickness')
39-
layout.prop(gpencil, 'write_color')
40-
#layout.prop(gpencil, 'interpolation_mode')
41-
layout.prop(gpencil, 'font')
42-
row = layout.row()
43-
row.operator("grease_writer.write", icon="FILE_TEXT")
44-
row.prop_search(gpencil, 'source_text', bpy.data, "texts", text="")
4536
row = layout.row()
4637
row.operator("grease_writer.decorate", icon="LIGHT_SUN")
4738
row.prop(gpencil, "decorator_style", text="")
39+
40+
layout.separator()
41+
4842
layout.operator("grease_writer.reanimate", icon="HAND")
43+
44+
layout.separator()
45+
46+
row = layout.row()
47+
row.prop(gpencil, 'stipple_length')
48+
row.prop(gpencil, 'stipple_skip')
49+
layout.operator("grease_writer.stippleit")
50+
51+
layout.separator()
52+
53+
layout.prop_search(gpencil, 'tracer_obj', scene, "objects", text="")
4954
row = layout.row()
5055
row.operator("grease_writer.trace", icon="PIVOT_CURSOR")
51-
row.prop_search(gpencil, 'tracer_obj', scene, "objects", text="")
56+
row.prop(gpencil, 'trace2d')
57+
58+
59+
class SCENE_PT_greasewriter(bpy.types.Panel):
60+
bl_label = "Grease Writer"
61+
bl_idname = "SCENE_PT_greasewriter"
62+
bl_space_type = "PROPERTIES"
63+
bl_region_type = "WINDOW"
64+
bl_context = "scene"
65+
bl_options = {"DEFAULT_CLOSED"}
66+
67+
def draw(self, context):
68+
scene = context.scene
69+
layout = self.layout
70+
layout.prop(scene, 'gw_scale')
71+
layout.prop(scene, 'gw_speed')
72+
layout.prop(scene, 'gw_kerning')
73+
layout.prop(scene, 'gw_word_space')
74+
layout.prop(scene, 'gw_line_height')
75+
layout.prop(scene, 'gw_thickness')
76+
layout.prop(scene, 'gw_color')
77+
layout.prop(scene, 'gw_font')
78+
row = layout.row()
79+
row.prop_search(scene, 'gw_source_text_file', bpy.data, "texts", text="")
80+
row.prop(scene, 'gw_source_text', text="")
81+
layout.operator("grease_writer.write", icon="FILE_TEXT")
5282

5383

5484
def init_props():
55-
bpy.types.GreasePencil.draw_speed = bpy.props.FloatProperty(
85+
bpy.types.Scene.gw_scale = bpy.props.FloatProperty(
86+
name="Scale",
87+
description="Affects the text size",
88+
default=1.0,
89+
min=0.01
90+
)
91+
92+
bpy.types.Scene.gw_speed = bpy.props.FloatProperty(
5693
name="Draw Speed",
5794
description="The distance a stroke lengthens with each frame of animation",
58-
default=0.1,
95+
default=1.0,
5996
min=0.01
6097
)
6198

62-
bpy.types.GreasePencil.kerning = bpy.props.FloatProperty(
99+
bpy.types.Scene.gw_kerning = bpy.props.FloatProperty(
63100
name="Kerning",
64-
description="Affects the distance between characters. Default is 0.5 x the width of letter M",
65-
default=0.5,
101+
description="Affects the distance between characters.",
102+
default=1.0,
103+
min=0
104+
)
105+
106+
bpy.types.Scene.gw_word_space = bpy.props.FloatProperty(
107+
name="Word Space",
108+
description="Affects the distance between words.",
109+
default=1.0,
66110
min=0
67111
)
68112

69-
bpy.types.GreasePencil.line_height = bpy.props.FloatProperty(
113+
bpy.types.Scene.gw_line_height = bpy.props.FloatProperty(
70114
name="Line Height",
71115
description="Affects the height of a line. Default is 1.25 x the height of the letter M",
72-
default=1.25,
116+
default=1.0,
73117
min=0
74118
)
75119

76-
bpy.types.GreasePencil.write_thickness = bpy.props.IntProperty(
120+
bpy.types.Scene.gw_thickness = bpy.props.IntProperty(
77121
name="Thickness",
78122
description="Affects the default line thickness.",
79123
default=100,
80124
min=1
81125
)
82126

83-
bpy.types.GreasePencil.write_color = bpy.props.FloatVectorProperty(
127+
bpy.types.Scene.gw_color = bpy.props.FloatVectorProperty(
84128
subtype='COLOR_GAMMA',
85129
name="Color",
86130
description="Color to use when writing",
@@ -90,38 +134,27 @@ def init_props():
90134
max=1.0
91135
)
92136

93-
"""
94-
It might be cool to someday have different interpolation modes.
95-
For now, linear is ok
96-
97-
interpolation_modes = [
98-
("linear", "Linear", "Draw all strokes at the given draw speed"),
99-
("derivative", "Derivative", "Draw strokes at a rate that varies based on the stroke's rate of change in direction; the more curvaceous, the slower the draw"),
100-
("random", "Random", "Draw with a random speed that is +/- the given draw speed"),
101-
]
102-
103-
bpy.types.GreasePencil.interpolation_mode = bpy.props.EnumProperty(
104-
name="Interpolation",
105-
items=interpolation_modes,
106-
description="Select a mode for calculating how fast strokes should be drawn",
107-
default="linear",
108-
)
109-
"""
110-
111137
fonts = [
112-
("consolas", "Consolas", "A monospace font based on Consolas")
138+
("consolas", "Consolas", "A monospace font based on Consolas by doakey3"),
139+
("hershey_script_simplex", "Hershey's Script Simplex", "A cursive font made by by Dr. Allen Vincent Hershey"),
140+
("hershey_roman_simplex", "Hershey's Roman Simplex", "A sans font made by by Dr. Allen Vincent Hershey")
113141
]
114142

115-
bpy.types.GreasePencil.font = bpy.props.EnumProperty(
143+
bpy.types.Scene.gw_font = bpy.props.EnumProperty(
116144
name="Font",
117145
items=fonts,
118146
description="The font to be used for writing",
119147
default="consolas",
120148
)
121149

122-
bpy.types.GreasePencil.source_text = bpy.props.StringProperty(
150+
bpy.types.Scene.gw_source_text_file = bpy.props.StringProperty(
151+
name="source_text_file",
152+
description="The text file containing text to be written with grease pencil."
153+
)
154+
155+
bpy.types.Scene.gw_source_text = bpy.props.StringProperty(
123156
name="source_text",
124-
description="The text to be written with grease pencil"
157+
description="The text to be written with grease pencil; has priority over the source text file property"
125158
)
126159

127160
decorators = [
@@ -144,13 +177,35 @@ def init_props():
144177

145178
bpy.types.GreasePencil.tracer_obj = bpy.props.StringProperty()
146179

180+
bpy.types.GreasePencil.trace2d = bpy.props.BoolProperty(
181+
name="2D",
182+
description="Limit tracing to X and Y",
183+
default=True
184+
)
185+
186+
bpy.types.GreasePencil.stipple_length = bpy.props.FloatProperty(
187+
name="Length",
188+
description="The length of the stipples",
189+
default=0.1,
190+
min=0.01,
191+
)
192+
193+
bpy.types.GreasePencil.stipple_skip = bpy.props.IntProperty(
194+
name="Skip",
195+
description="Skips this many stipple-lengths between stipples",
196+
default=2,
197+
min=1
198+
)
199+
147200

148201
classes = [
149202
GREASEPENCIL_PT_greasewriter,
203+
SCENE_PT_greasewriter,
150204
GREASEPENCIL_OT_reanimate,
151205
GREASEPENCIL_OT_write,
152206
GREASEPENCIL_OT_trace,
153-
GREASEPENCIL_OT_decorate
207+
GREASEPENCIL_OT_decorate,
208+
GREASEPENCIL_OT_stippleit
154209
]
155210

156211
def register():

extras/consolas.blend

893 KB
Binary file not shown.

extras/export_letters.py

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import bpy
2+
import os
3+
import io
4+
from contextlib import redirect_stdout
5+
import sys
6+
7+
8+
def update_progress(job_title, progress):
9+
length = 20
10+
block = int(round(length * progress))
11+
msg = "\r{0}: [{1}] {2}%".format(job_title,
12+
"#" * block + "-" * (length-block),
13+
"%.2f" % (progress * 100))
14+
15+
if progress >= 1:
16+
msg += " DONE\r\n"
17+
sys.stdout.write(msg)
18+
sys.stdout.flush()
19+
20+
21+
def verts2points(verts):
22+
points = []
23+
for vert in verts:
24+
point = [vert.co.x, vert.co.y, vert.co.z]
25+
points.append(point)
26+
return points
27+
28+
29+
def get_glyph_size(vertices):
30+
"""
31+
Get the size of a glyph
32+
"""
33+
x_points = []
34+
y_points = []
35+
for vert in vertices:
36+
x_points.append(vert.co.x)
37+
y_points.append(vert.co.y)
38+
39+
min_x = min(x_points)
40+
max_x = max(x_points)
41+
42+
min_y = min(y_points)
43+
max_y = max(y_points)
44+
45+
return min_x, max_x, min_y, max_y
46+
47+
48+
def get_islands(obj):
49+
"""
50+
Gets a list of vertices grouped by islands
51+
"""
52+
edges = list(obj.data.edges)
53+
54+
islands = []
55+
found = False
56+
while len(edges) > 0:
57+
if found == False:
58+
islands.append(list(edges[0].vertices))
59+
edges.pop(0)
60+
61+
found = False
62+
i = 0
63+
while i < len(edges):
64+
for vert in edges[i].vertices:
65+
if vert in islands[-1]:
66+
islands[-1].extend(list(edges[i].vertices))
67+
edges.pop(i)
68+
found = True
69+
break
70+
i += 1
71+
72+
for i in range(len(islands)):
73+
islands[i] = list(set(islands[i]))
74+
return islands
75+
76+
77+
def convert_curve(obj):
78+
"""
79+
Duplicate a curve and convert the duplicate to a mesh
80+
"""
81+
bpy.ops.object.select_all(action='DESELECT')
82+
bpy.context.view_layer.objects.active = obj
83+
obj.select_set(True)
84+
bpy.ops.object.duplicate()
85+
86+
bpy.ops.object.convert(target='MESH')
87+
88+
89+
def export_glyph(obj, folder):
90+
name = obj.name
91+
path = os.path.join(folder, name + '.glyph')
92+
93+
convert_curve(obj)
94+
duplicate = bpy.context.view_layer.objects.active
95+
islands = get_islands(duplicate)
96+
left, right, bottom, top = get_glyph_size(duplicate.data.vertices)
97+
points = verts2points(duplicate.data.vertices)
98+
99+
for i in range(len(points)):
100+
points[i][0] -= left
101+
102+
decimals = 5
103+
glyph_strokes = []
104+
for i in range(len(islands)):
105+
glyph_strokes.append([])
106+
for p in range(len(points)):
107+
if p in islands[i]:
108+
v = points[p]
109+
v[0] = round(v[0], decimals)
110+
v[1] = round(v[1], decimals)
111+
v[2] = 0
112+
glyph_strokes[-1].append(v)
113+
114+
stdout = io.StringIO()
115+
with redirect_stdout(stdout):
116+
bpy.ops.object.delete()
117+
118+
text = ''
119+
for stroke in glyph_strokes:
120+
text += str(stroke) + '\n'
121+
text.strip()
122+
123+
with open(path, 'w') as f:
124+
f.write(text)
125+
126+
127+
if __name__ == "__main__":
128+
objs = bpy.data.objects
129+
name = os.path.basename(bpy.data.filepath).replace('.blend', '')
130+
folder = os.path.dirname(bpy.data.filepath)
131+
132+
path = os.path.join(folder, name)
133+
134+
if not os.path.isdir(path):
135+
os.makedirs(path)
136+
137+
for i in range(len(objs)):
138+
export_glyph(objs[i], path)
139+
update_progress("Making Glyphs", i / len(objs))
140+
update_progress("Making Glyphs", 1)
141+

extras/font website.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
A good list of fonts that might work can be found here:
2+
http://www.imajeenyus.com/computer/20150110_single_line_fonts/index.shtml

extras/hershey_roman_simplex.blend

912 KB
Binary file not shown.
962 KB
Binary file not shown.

extras/test.blend

846 KB
Binary file not shown.

extras/test_string.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
0123456789
2+
abcdefghijklmnopqrstuvwxyz
3+
ABCDEFGHIJKLMNOPQRSTUVWXYZ
4+
`~!@#$%^&*()_+`-=
5+
<>?:"{}|,./;'[]\
6+
°↑↓←→☐Δ♂♀

operators/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
from .write import GREASEPENCIL_OT_write
33
from .trace import GREASEPENCIL_OT_trace
44
from .decorate import GREASEPENCIL_OT_decorate
5+
from .stippleit import GREASEPENCIL_OT_stippleit

operators/fonts/consolas/0.glyph

100755100644
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
[[0.15828, 0.58609], [0.12932, 0.58048], [0.10457, 0.57265], [0.08358, 0.56292], [0.06593, 0.55159], [0.05124, 0.53892], [0.03914, 0.52518], [0.02931, 0.5106], [0.02142, 0.4954], [0.01038, 0.46391], [0.00408, 0.4321], [0.0, 0.37144], [0.00196, 0.31835], [0.00872, 0.27345], [0.01412, 0.2538], [0.02093, 0.2359], [0.02914, 0.21967], [0.03872, 0.20506], [0.04958, 0.19203], [0.06162, 0.18057], [0.07468, 0.17066], [0.08858, 0.16233], [0.10312, 0.15558], [0.1181, 0.15045], [0.13335, 0.14695], [0.14871, 0.14511], [0.16401, 0.14495], [0.17912, 0.14649], [0.1939, 0.14975], [0.20823, 0.15475], [0.22202, 0.16153], [0.23515, 0.1701], [0.24754, 0.18051], [0.2591, 0.1928], [0.26977, 0.20705], [0.27946, 0.22334], [0.28811, 0.24177], [0.29567, 0.26245], [0.30728, 0.31114], [0.31368, 0.37037], [0.31401, 0.40356], [0.31121, 0.43824], [0.30389, 0.47328], [0.298, 0.49048], [0.29028, 0.50717], [0.28045, 0.5231], [0.2682, 0.53801], [0.25321, 0.5516], [0.23511, 0.56356], [0.21353, 0.57354], [0.18806, 0.58118], [0.15828, 0.58609]]
2-
[[0.30242, 0.47723], [0.01168, 0.2634]]
1+
[[0.15828, 0.58609, 0], [0.12932, 0.58048, 0], [0.10457, 0.57265, 0], [0.08358, 0.56292, 0], [0.06593, 0.55159, 0], [0.05124, 0.53892, 0], [0.03914, 0.52518, 0], [0.02931, 0.5106, 0], [0.02142, 0.4954, 0], [0.01519, 0.47978, 0], [0.01038, 0.46391, 0], [0.00674, 0.44797, 0], [0.00408, 0.4321, 0], [0.00222, 0.41641, 0], [0.00099, 0.40101, 0], [0.00029, 0.386, 0], [0.0, 0.37144, 0], [6e-05, 0.35737, 0], [0.00041, 0.34383, 0], [0.00105, 0.33082, 0], [0.00196, 0.31835, 0], [0.00317, 0.30639, 0], [0.00469, 0.29493, 0], [0.00654, 0.28395, 0], [0.00872, 0.27345, 0], [0.01125, 0.2634, 0], [0.01412, 0.2538, 0], [0.01735, 0.24463, 0], [0.02093, 0.2359, 0], [0.02486, 0.22758, 0], [0.02914, 0.21967, 0], [0.03376, 0.21216, 0], [0.03872, 0.20506, 0], [0.04399, 0.19835, 0], [0.04958, 0.19203, 0], [0.05546, 0.18611, 0], [0.06162, 0.18057, 0], [0.06804, 0.17542, 0], [0.07468, 0.17066, 0], [0.08154, 0.1663, 0], [0.08858, 0.16233, 0], [0.09578, 0.15875, 0], [0.10312, 0.15558, 0], [0.11057, 0.15281, 0], [0.1181, 0.15045, 0], [0.12571, 0.1485, 0], [0.13335, 0.14695, 0], [0.14103, 0.14582, 0], [0.14871, 0.14511, 0], [0.15638, 0.14482, 0], [0.16401, 0.14495, 0], [0.1716, 0.1455, 0], [0.17912, 0.14649, 0], [0.18656, 0.1479, 0], [0.1939, 0.14975, 0], [0.20113, 0.15203, 0], [0.20823, 0.15475, 0], [0.2152, 0.15792, 0], [0.22202, 0.16153, 0], [0.22867, 0.16559, 0], [0.23515, 0.1701, 0], [0.24144, 0.17507, 0], [0.24754, 0.18051, 0], [0.25343, 0.18641, 0], [0.2591, 0.1928, 0], [0.26455, 0.19967, 0], [0.26977, 0.20705, 0], [0.27474, 0.21493, 0], [0.27946, 0.22334, 0], [0.28392, 0.23228, 0], [0.28811, 0.24177, 0], [0.29203, 0.25182, 0], [0.29567, 0.26245, 0], [0.29902, 0.27368, 0], [0.30207, 0.28553, 0], [0.30483, 0.29801, 0], [0.30728, 0.31114, 0], [0.30942, 0.32494, 0], [0.31123, 0.33943, 0], [0.31267, 0.35458, 0], [0.31368, 0.37037, 0], [0.31416, 0.38672, 0], [0.31401, 0.40356, 0], [0.31308, 0.42078, 0], [0.31121, 0.43824, 0], [0.30822, 0.45581, 0], [0.30389, 0.47328, 0], [0.298, 0.49048, 0], [0.29028, 0.50717, 0], [0.28045, 0.5231, 0], [0.2682, 0.53801, 0], [0.25321, 0.5516, 0], [0.23511, 0.56356, 0], [0.21353, 0.57354, 0], [0.18806, 0.58118, 0], [0.15828, 0.58609, 0]]
2+
[[0.30242, 0.47723, 0], [0.27599, 0.45779, 0], [0.24956, 0.43835, 0], [0.22313, 0.41892, 0], [0.1967, 0.39948, 0], [0.17027, 0.38004, 0], [0.14384, 0.3606, 0], [0.11741, 0.34116, 0], [0.09098, 0.32172, 0], [0.06454, 0.30228, 0], [0.03811, 0.28284, 0], [0.01168, 0.2634, 0]]

0 commit comments

Comments
 (0)