Advertisement
Guest User

Untitled

a guest
May 24th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. '''
  2. BEGIN GPL LICENSE BLOCK
  3.  
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software Foundation,
  16. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17.  
  18. END GPL LICENCE BLOCK
  19. '''
  20.  
  21. import math
  22. import bpy
  23.  
  24.  
  25. def get_layer(gdata_owner, layer_name):
  26.  
  27. grease_data = bpy.data.grease_pencil
  28. if gdata_owner not in grease_data:
  29. gp = grease_data.new(gdata_owner)
  30. else:
  31. gp = grease_data[gdata_owner]
  32.  
  33. # get grease pencil layer
  34. if not (layer_name in gp.layers):
  35. layer = gp.layers.new(layer_name)
  36. layer.frames.new(1)
  37. layer.line_width = 1
  38. else:
  39. layer = gp.layers[layer_name]
  40. layer.frames[0].clear()
  41.  
  42. return layer
  43.  
  44.  
  45. def generate_gp3d_stroke(layer):
  46. layer.show_points = True
  47. layer.color = (0.2, 0.90, .2)
  48. s = layer.frames[0].strokes.new()
  49. s.draw_mode = '3DSPACE'
  50.  
  51. chain = []
  52. num_verts = 10
  53. r = 2.2
  54. gamma = 2 * math.pi / num_verts
  55. for i in range(num_verts+1):
  56. theta = gamma * i
  57. world_point = (math.sin(theta) * r, math.cos(theta) * r, 1.2)
  58. chain.append(world_point)
  59.  
  60. s.points.add(len(chain))
  61. for idx, p in enumerate(chain):
  62. s.points[idx].co = p
  63.  
  64.  
  65. class TrigGenerator(bpy.types.Operator):
  66.  
  67. bl_idname = 'mesh.trig_generator'
  68. bl_label = 'generated trig with gpencil'
  69. bl_options = {'REGISTER', 'UNDO'}
  70.  
  71. def execute(self, context):
  72. obj = bpy.context.object
  73. data_name = 'stack_data'
  74. layer_name = "stack layer"
  75. layer = get_layer(data_name, layer_name)
  76. generate_gp3d_stroke(layer)
  77. bpy.context.scene.grease_pencil = bpy.data.grease_pencil[data_name]
  78. return {'FINISHED'}
  79.  
  80.  
  81. def register():
  82. bpy.utils.register_class(TrigGenerator)
  83.  
  84.  
  85. def unregister():
  86. bpy.utils.unregister_class(TrigGenerator)
  87.  
  88.  
  89. if __name__ == '__main__':
  90. register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement