Skip to content

Instantly share code, notes, and snippets.

@zeffii
Last active August 29, 2015 14:06
Show Gist options
  • Save zeffii/30256eba0f1daba55c60 to your computer and use it in GitHub Desktop.
Save zeffii/30256eba0f1daba55c60 to your computer and use it in GitHub Desktop.
def make_geometry(origin, text, sizes):
curves = bpy.data.curves
objects = bpy.data.objects
scene = bpy.context.scene
name = 'sv_text_' + text
tcu = curves.get(name, curves.new(name=name, type='FONT'))
obj = objects.get(name, objects.new(name, tcu))
obj.location = origin
if not name in scene.objects:
scene.objects.link(obj)
obj['tracker_id'] = 'FROM_SN'
try:
tcu.font = bpy.data.fonts[node.fonts]
except:
tcu.font = bpy.data.fonts[0]
tcu.body = text
tcu.offset_x = 0
tcu.offset_y = 0
tcu.resolution_u = 2
tcu.shear = 0
tcu.size = sizes
tcu.space_character = 1
tcu.space_word = 1
tcu.align = 'CENTER'
# tcu.extrude = 0.0
tcu.fill_mode = 'NONE'
def clean_up(idx, objs):
objs = [obj.name for obj in objs if int(obj.name.split("_")[-1]) > idx]
if not objs:
return
meshes = bpy.data.meshes
objects = bpy.data.objects
scene = bpy.context.scene
# remove excess objects
for object_name in objs:
obj = objects[object_name]
obj.hide_select = False
scene.objects.unlink(obj)
objects.remove(obj)
# delete associated meshes
for object_name in objs:
meshes.remove(meshes[object_name])
def sv_main(verts=[[]], sizes=1.0):
verts_out = []
edges_out = []
in_sockets = [
['v', 'locations', verts],
['s', 'sizes', sizes]
]
out_sockets = [
['v', 'verts', verts_out],
['s', 'edges', edges_out]
]
if verts and verts[0]:
verts = verts[0]
print('locast')
for idx, v in enumerate(verts):
text = 'cola_' + str(idx)
make_geometry(v, text, sizes)
# cleanup step
objs = (obj for obj in bpy.data.objects if 'tracker_id' in obj)
clean_up(idx, objs)
return in_sockets, out_sockets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment