|
| 1 | +import bpy |
| 2 | + |
| 3 | +from .operators import * |
| 4 | + |
| 5 | +bl_info = { |
| 6 | + "name": "Grease Writer", |
| 7 | + "description": "Automatic hand-drawn text animation", |
| 8 | + "author": "doakey3", |
| 9 | + "version": (0, 0, 1), |
| 10 | + "blender": (2, 80, 0), |
| 11 | + "wiki_url": "https://github.com/doakey3/GreaseDraw", |
| 12 | + "tracker_url": "https://github.com/doakey3/GreaseDraw/issues", |
| 13 | + "category": "Animation", |
| 14 | + "location": "Properties, Grease Pencil Data" |
| 15 | +} |
| 16 | + |
| 17 | +class GREASEPENCIL_PT_greasewriter(bpy.types.Panel): |
| 18 | + bl_label = "Grease Writer" |
| 19 | + bl_idname = "GREASEPENCIL_PT_greasewriter" |
| 20 | + bl_space_type = "PROPERTIES" |
| 21 | + bl_region_type = "WINDOW" |
| 22 | + bl_context = "data" |
| 23 | + |
| 24 | + @classmethod |
| 25 | + def poll(self, context): |
| 26 | + if type(context.active_object.data).__name__ == "GreasePencil": |
| 27 | + return True |
| 28 | + else: |
| 29 | + return False |
| 30 | + |
| 31 | + def draw(self, context): |
| 32 | + scene = context.scene |
| 33 | + gpencil = context.active_object.data |
| 34 | + 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="") |
| 45 | + row = layout.row() |
| 46 | + row.operator("grease_writer.decorate", icon="LIGHT_SUN") |
| 47 | + row.prop(gpencil, "decorator_style", text="") |
| 48 | + layout.operator("grease_writer.reanimate", icon="HAND") |
| 49 | + row = layout.row() |
| 50 | + row.operator("grease_writer.trace", icon="PIVOT_CURSOR") |
| 51 | + row.prop_search(gpencil, 'tracer_obj', scene, "objects", text="") |
| 52 | + |
| 53 | + |
| 54 | +def init_props(): |
| 55 | + bpy.types.GreasePencil.draw_speed = bpy.props.FloatProperty( |
| 56 | + name="Draw Speed", |
| 57 | + description="The distance a stroke lengthens with each frame of animation", |
| 58 | + default=0.1, |
| 59 | + min=0.01 |
| 60 | + ) |
| 61 | + |
| 62 | + bpy.types.GreasePencil.kerning = bpy.props.FloatProperty( |
| 63 | + name="Kerning", |
| 64 | + description="Affects the distance between characters. Default is 0.5 x the width of letter M", |
| 65 | + default=0.5, |
| 66 | + min=0 |
| 67 | + ) |
| 68 | + |
| 69 | + bpy.types.GreasePencil.line_height = bpy.props.FloatProperty( |
| 70 | + name="Line Height", |
| 71 | + description="Affects the height of a line. Default is 1.25 x the height of the letter M", |
| 72 | + default=1.25, |
| 73 | + min=0 |
| 74 | + ) |
| 75 | + |
| 76 | + bpy.types.GreasePencil.write_thickness = bpy.props.IntProperty( |
| 77 | + name="Thickness", |
| 78 | + description="Affects the default line thickness.", |
| 79 | + default=100, |
| 80 | + min=1 |
| 81 | + ) |
| 82 | + |
| 83 | + bpy.types.GreasePencil.write_color = bpy.props.FloatVectorProperty( |
| 84 | + subtype='COLOR_GAMMA', |
| 85 | + name="Color", |
| 86 | + description="Color to use when writing", |
| 87 | + size=3, |
| 88 | + default=(0, 0, 0), |
| 89 | + min=0.0, |
| 90 | + max=1.0 |
| 91 | + ) |
| 92 | + |
| 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 | + |
| 111 | + fonts = [ |
| 112 | + ("consolas", "Consolas", "A monospace font based on Consolas") |
| 113 | + ] |
| 114 | + |
| 115 | + bpy.types.GreasePencil.font = bpy.props.EnumProperty( |
| 116 | + name="Font", |
| 117 | + items=fonts, |
| 118 | + description="The font to be used for writing", |
| 119 | + default="consolas", |
| 120 | + ) |
| 121 | + |
| 122 | + bpy.types.GreasePencil.source_text = bpy.props.StringProperty( |
| 123 | + name="source_text", |
| 124 | + description="The text to be written with grease pencil" |
| 125 | + ) |
| 126 | + |
| 127 | + decorators = [ |
| 128 | + ("underline", "Underline", "Draw an underline beneath the grease pencil layer"), |
| 129 | + ("over-underline", "Over-underline", "Draw an overline and underline"), |
| 130 | + ("box", "Box", "Draw a box around the grease pencil layer"), |
| 131 | + ("ellipse", "Ellipse", "Draw an ellipse around the grease pencil layer"), |
| 132 | + ("circle", "Circle", "Draw a circle around the grease pencil layer"), |
| 133 | + ("strike-through", "Strike-through", "Horizontally strike out the grease pencil layer"), |
| 134 | + ("x-out", "X-out", "X out the grease pencil layer"), |
| 135 | + ("helioid", "Helioid", "Make a sun-like decorator (spiked ellipse)") |
| 136 | + ] |
| 137 | + |
| 138 | + bpy.types.GreasePencil.decorator_style = bpy.props.EnumProperty( |
| 139 | + name="Decorators", |
| 140 | + items=decorators, |
| 141 | + description="The decorator to draw", |
| 142 | + default="underline", |
| 143 | + ) |
| 144 | + |
| 145 | + bpy.types.GreasePencil.tracer_obj = bpy.props.StringProperty() |
| 146 | + |
| 147 | + |
| 148 | +classes = [ |
| 149 | + GREASEPENCIL_PT_greasewriter, |
| 150 | + GREASEPENCIL_OT_reanimate, |
| 151 | + GREASEPENCIL_OT_write, |
| 152 | + GREASEPENCIL_OT_trace, |
| 153 | + GREASEPENCIL_OT_decorate |
| 154 | +] |
| 155 | + |
| 156 | +def register(): |
| 157 | + init_props() |
| 158 | + |
| 159 | + from bpy.utils import register_class |
| 160 | + for cls in classes: |
| 161 | + register_class(cls) |
| 162 | + |
| 163 | +def unregister(): |
| 164 | + from bpy.utils import unregister_class |
| 165 | + for cls in reversed(classes): |
| 166 | + unregister_class(cls) |
0 commit comments