Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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