grease pencil volumetric shapes

import bpy, math
## skip reading this hack, it is just to setup grease pencil in blender2.79
if not bpy.context.scene.grease_pencil:
 a = [ a for a in bpy.context.screen.areas if a.type == 'VIEW_3D' ][0]
 override = {
  'scene'         : bpy.context.scene,
  'screen'        : bpy.context.screen,
  'object'        : bpy.context.object,
  'area'          : a,
  'region'        : a.regions[0],
  'window'        : bpy.context.window,
  'active_object' : bpy.context.object
 }
 bpy.ops.gpencil.data_add( override )

very transparent blue material

When many circles are rendered on top of each other, this will give the appearance of a volumetric (cloud like) shape. The fill_alpha is set very low, to 0.01
Palette = bpy.context.scene.grease_pencil.palettes.new(name='my-palette')
gmat = Palette.colors.new()
gmat.name = 'blue'
gmat.alpha = 0
gmat.fill_alpha = 0.01
gmat.fill_color = [0,0,1]
gmat.color = [0,0,0]

make_circle function

Because this block of code is called many times, it is standard to wrap it into a function. The radius parameter defaults to 1.0, and from the for loop at the bottom, the radius increases with each loop iteration.
def make_circle(radius=1.0):
 layer = bpy.context.scene.grease_pencil.layers.new('mylayer')
 frame = layer.frames.new(1)  ## 1 is the first frame
 a = frame.strokes.new()
 a.draw_mode = '3DSPACE'
 a.colorname = 'blue'
 a.draw_cyclic = True
 a.line_width = 0

 a.points.add( count=360 )
 for i in range(360):
  a.points[i].co.x = math.sin( math.radians(i) ) * radius
  a.points[i].co.y = math.cos( math.radians(i) ) * radius

 return layer

create the volume

make_circle returns the unique layer for each circle, this layer is parented to a new empty object for each loop iteration. The empty object is then rotated on the x axis.
for i in range(360):
 empty = bpy.data.objects.new(name=str(i), object_data=None)
 bpy.context.scene.objects.link(empty)
 lay = make_circle(radius=i*0.1)
 lay.parent = empty
 empty.rotation_euler.x = math.radians(i)

Comments

Popular Posts