Advertisement
SebastianLague

Untitled

Nov 17th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1.     void Start()
  2.     {
  3.         float scale = (transform.localScale.x + transform.localScale.y + transform.localScale.z) * 0.3f;
  4.         Mesh mesh = gameObject.GetComponent<MeshFilter>().mesh;
  5.         Vector3[] peturbedVertices = new Vector3[mesh.vertices.Length];
  6.         Dictionary<Vector3, Vector3> vertexDeformations = new Dictionary<Vector3, Vector3>();
  7.  
  8.         for (int i = 0; i < mesh.vertices.Length; i++)
  9.         {
  10.             if (vertexDeformations.ContainsKey(mesh.vertices[i]))
  11.             {
  12.                 peturbedVertices[i] = vertexDeformations[mesh.vertices[i]];
  13.             }
  14.             else
  15.             {
  16.                 peturbedVertices[i] = mesh.vertices[i] + Random.onUnitSphere * .1f * scale;
  17.                 vertexDeformations.Add(mesh.vertices[i], peturbedVertices[i]);
  18.             }
  19.            
  20.         }
  21.         mesh.vertices = peturbedVertices;
  22.         mesh.RecalculateNormals();
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement