Created
January 12, 2012 00:02
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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