- Home /
How to Reference Vertices of a Mesh of a meshFilter of a GameObject?
I want to move some vertices on a very simple mesh to modify its shape.
I put the mesh into the world by instantiating a Prefab as a GameObject, so all I know is how to reference the GameObject.
I don't know the first thing about referencing vertices, meshes, meshfilters or anything and cannot seem to find the answers on google.
Any help greatly appreciated!
Read the script reference and look at the examples for the $$anonymous$$esh class.
Download the free Procedural Examples from the Asset store and take a look at the scripts.
Both have script examples on how to modify vertices and/or triangles at runtime.
Answer by asafsitner · Dec 29, 2013 at 08:48 AM
Start with `GameObject.GetComponent` to reference the `MeshFilter`, then use the `MeshFilter.mesh` (in runtime) or `MeshFilter.sharedMesh` (in edit time) to reference the `Mesh` itself, then use the `Mesh.vertices` to get the vertices of the mesh.
It's important to note that the `Mesh.triangles` can also be accessed, and it's always a multiply of the `Mesh.vertexCount` by 3, where each triangle is defined by 3 vertices starting from Mesh.vertices[0]
.
Your answer
Follow this Question
Related Questions
Why vertex positions appear (0.0, 0.0, 0.0) ? 1 Answer
Mesh Vertices Welding 0 Answers
Getting the world position of mesh vertices? 2 Answers
Why does my mesh's vertices all set to 0 when I try to access it using Mesh.vertices? 1 Answer
Is it possible to make vertices defined by a mesh and mesh filters animating? 0 Answers