Created
December 21, 2016 04:42
-
-
Save runewake2/a6ba641c9c9c51da62530d6176ee932e to your computer and use it in GitHub Desktop.
Revisions
-
runewake2 created this gist
Dec 21, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; [RequireComponent(typeof(GeneratePlaneMesh))] public class DeformableMesh : MonoBehaviour { public float maximumDepression; public List<Vector3> originalVertices; public List<Vector3> modifiedVertices; private GeneratePlaneMesh plane; public void MeshRegenerated() { plane = GetComponent<GeneratePlaneMesh>(); plane.mesh.MarkDynamic(); originalVertices = plane.mesh.vertices.ToList(); modifiedVertices = plane.mesh.vertices.ToList(); Debug.Log("Mesh Regenerated"); } public void AddDepression(Vector3 depressionPoint, float radius) { var worldPos4 = this.transform.worldToLocalMatrix * depressionPoint; var worldPos = new Vector3(worldPos4.x, worldPos4.y, worldPos4.z); for (int i = 0; i < modifiedVertices.Count; ++i) { var distance = (worldPos - (modifiedVertices[i] + Vector3.down * maximumDepression)).magnitude; if (distance < radius) { var newVert = originalVertices[i] + Vector3.down * maximumDepression; modifiedVertices.RemoveAt(i); modifiedVertices.Insert(i, newVert); } } plane.mesh.SetVertices(modifiedVertices); Debug.Log("Mesh Depressed"); } }