Skip to content

Instantly share code, notes, and snippets.

@ericjang
Last active December 26, 2017 19:12
Show Gist options
  • Save ericjang/dd56bbde3f9dc971c8ed6f78017c40f0 to your computer and use it in GitHub Desktop.
Save ericjang/dd56bbde3f9dc971c8ed6f78017c40f0 to your computer and use it in GitHub Desktop.
Generate 2D points randomly distributed on a flat text mesh in Blender.
# run this from a blender interpreter
# First, create text object, then <SPACE> convert it from Text to a Mesh object. Select it.
import bpy_extras.mesh_utils
import pickle
obj = bpy.context.object # get actively selected object
me = obj.data # get mesh
me.calc_tessface() # recalc tessfaces
points = bpy_extras.mesh_utils.face_random_points(10, me.tessfaces)
points = [p[:2] for p in points] # discard Z coord
with open('/Users/eric/Desktop/siggraph.pkl','wb') as f:
pickle.dump(points, f, protocol=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment