Skip to content

Instantly share code, notes, and snippets.

@kylemcdonald
Created January 12, 2012 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylemcdonald/1597586 to your computer and use it in GitHub Desktop.
Save kylemcdonald/1597586 to your computer and use it in GitHub Desktop.
Rhino/Python script the randomly jitters mesh vertices along their normals, scaled by the face size.
import rhinoscriptsyntax as rs
import math, random
obj = rs.GetObject("Select mesh", rs.filter.mesh, True)
sigma = rs.GetReal("Gaussian sigma", .1)
vertices = rs.MeshVertices(obj)
faces = rs.MeshFaceVertices(obj)
normals = rs.MeshVertexNormals(obj)
if vertices and faces:
modified = []
for i in range(len(vertices)):
vertex = vertices[i]
normal = normals[i]
face = faces[rs.MeshVertexFaces(obj, i)[0]]
a = vertices[face[0]]
b = vertices[face[1]]
dist = rs.Distance(a, b)
amt = dist * math.fabs(random.gauss(0, sigma))
vertex = (
vertex[0] + amt * normal[0],
vertex[1] + amt * normal[1],
vertex[2] + amt * normal[2])
modified.append(vertex)
rs.AddMesh(modified, faces)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment