Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Start()
- {
- float scale = (transform.localScale.x + transform.localScale.y + transform.localScale.z) * 0.3f;
- Mesh mesh = gameObject.GetComponent<MeshFilter>().mesh;
- Vector3[] peturbedVertices = new Vector3[mesh.vertices.Length];
- Dictionary<Vector3, Vector3> vertexDeformations = new Dictionary<Vector3, Vector3>();
- for (int i = 0; i < mesh.vertices.Length; i++)
- {
- if (vertexDeformations.ContainsKey(mesh.vertices[i]))
- {
- peturbedVertices[i] = vertexDeformations[mesh.vertices[i]];
- }
- else
- {
- peturbedVertices[i] = mesh.vertices[i] + Random.onUnitSphere * .1f * scale;
- vertexDeformations.Add(mesh.vertices[i], peturbedVertices[i]);
- }
- }
- mesh.vertices = peturbedVertices;
- mesh.RecalculateNormals();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement