-
-
Save zeffii/e22d20918c3091062bd8 to your computer and use it in GitHub Desktop.
scriptnig grease pencli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
BEGIN GPL LICENSE BLOCK | |
This program is free software; you can redistribute it and/or | |
modify it under the terms of the GNU General Public License | |
as published by the Free Software Foundation; either version 2 | |
of the License, or (at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program; if not, write to the Free Software Foundation, | |
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
END GPL LICENCE BLOCK | |
''' | |
import math | |
import bpy | |
def get_layer(gdata_owner, layer_name): | |
grease_data = bpy.data.grease_pencil | |
if gdata_owner not in grease_data: | |
gp = grease_data.new(gdata_owner) | |
else: | |
gp = grease_data[gdata_owner] | |
# get grease pencil layer | |
if not (layer_name in gp.layers): | |
layer = gp.layers.new(layer_name) | |
layer.frames.new(1) | |
layer.line_width = 1 | |
else: | |
layer = gp.layers[layer_name] | |
layer.frames[0].clear() | |
return layer | |
def generate_gp3d_stroke(layer): | |
layer.show_points = True | |
layer.color = (0.2, 0.90, .2) | |
s = layer.frames[0].strokes.new() | |
s.draw_mode = '3DSPACE' | |
chain = [] | |
num_verts = 10 | |
r = 2.2 | |
gamma = 2 * math.pi / num_verts | |
for i in range(num_verts+1): | |
theta = gamma * i | |
world_point = (math.sin(theta) * r, math.cos(theta) * r, 1.2) | |
chain.append(world_point) | |
s.points.add(len(chain)) | |
for idx, p in enumerate(chain): | |
s.points[idx].co = p | |
class TrigGenerator(bpy.types.Operator): | |
bl_idname = 'mesh.trig_generator' | |
bl_label = 'generated trig with gpencil' | |
bl_options = {'REGISTER', 'UNDO'} | |
def execute(self, context): | |
obj = bpy.context.object | |
data_name = 'stack_data' | |
layer_name = "stack layer" | |
layer = get_layer(data_name, layer_name) | |
generate_gp3d_stroke(layer) | |
bpy.context.scene.grease_pencil = bpy.data.grease_pencil[data_name] | |
return {'FINISHED'} | |
def register(): | |
bpy.utils.register_class(TrigGenerator) | |
def unregister(): | |
bpy.utils.unregister_class(TrigGenerator) | |
if __name__ == '__main__': | |
register() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment