Skip to content

Instantly share code, notes, and snippets.

@predominant
Created August 21, 2015 17:32
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 predominant/ba8029f55414dc1d00e9 to your computer and use it in GitHub Desktop.
Save predominant/ba8029f55414dc1d00e9 to your computer and use it in GitHub Desktop.
protected void PlaneSplit1() {
Mesh mesh = this.GetMesh();
Vector3[] vertices = mesh.vertices;
for (int pass = 0; pass < this.Passes; pass++) {
// Pick a random point in the Sphere
Vector3 splitVector = Random.insideUnitSphere;
for (int i = 0; i < mesh.vertices.Length; i++) {
// Get the DOT product of that random point
if (Vector3.Dot(splitVector, vertices[i].normalized - splitVector) > 0) {
// Move vertices out
vertices[i] *= (1 + this.Scale * 1.1f);
} else {
// Move vertices in
vertices[i] *= (1 - this.Scale);
}
}
}
mesh.vertices = vertices;
mesh.RecalculateNormals();
mesh.RecalculateBounds();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment