Returns the instantiated Mesh assigned to the mesh filter.
If no mesh is assigned to the mesh filter a new mesh will be created and assigned.
If a mesh is assigned to the mesh filter already, then first query ofmesh property will create a duplicate of it, and this copy
will be returned. Further queries of mesh property will return this duplicated mesh instance. If you want to avoid this automatic
mesh duplication, use MeshFilter.sharedMesh instead.By using mesh property you can modify the mesh for a single object only. The
other objects that used the same mesh will not be modified.
// Distortionates the mesh vertically. function Update () {
// Get instantiated mesh
var mesh : Mesh = GetComponent(MeshFilter).mesh;
// Randomly change vertices
var vertices : Vector3[] = mesh.vertices;
for (var p : int = 0; p < vertices.Length; p++) {
vertices[p] += Vector3(0, Random.Range(-0.3, 0.3), 0);
}
mesh.vertices = vertices;
mesh.RecalculateNormals();
}
using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { void Update() { Mesh mesh = GetComponent<MeshFilter>().mesh; Vector3[] vertices = mesh.vertices; int p = 0; while (p < vertices.Length) { vertices[p] += new Vector3(0, Random.Range(-0.3F, 0.3F), 0); p++; } mesh.vertices = vertices; mesh.RecalculateNormals(); } }
import UnityEngine import System.Collections public class ExampleClass(MonoBehaviour): def Update() as void: mesh as Mesh = GetComponent[of MeshFilter]().mesh vertices as (Vector3) = mesh.vertices p as int = 0 while p < vertices.Length: vertices[p] += Vector3(0, Random.Range(-0.3F, 0.3F), 0) p++ mesh.vertices = vertices mesh.RecalculateNormals()
See Also: Mesh class.