- Home /
Optimized vertex manipulation
Hi. I need to change position of few vertices in my mesh and I need to do it often. However when I try to change vertices position like this:
_objectMeshFilter = GetComponent<MeshFilter>().mesh;
_objectMeshFilter.vertices[i] = new Vector3(50 + rand.Next()%5, 50 + rand.Next()%5, 50);
It does nothing. The value _objectMeshFilter.vertices[i] is not changed, it keeps it's old value.
I observed approach of creating some kind of own buffer Vector3 array and then assigning it to mesh vertices array. And yes, that works.
var mesh : Mesh = GetComponent(MeshFilter).mesh;
var vertices = new Vector3[baseHeight.Length];
// now modify vertices array
mesh.vertices = vertices // copy whole array ?? NOOOOOooooo, sloooow !! :-(
However that is too slow for me. I only need to change few vertices and triangles. Isn't there any other way to do this than assigning modified Vector3 array to mesh.vertices ? Also I need to do the same thing with triangles. Just edit a little bit.
Every advice appreciated, thanks in advance.
Answer by Fattie · Nov 21, 2012 at 08:43 PM
it's fully explained with excellent full examples, right on the doco page
http://docs.unity3d.com/Documentation/ScriptReference/Mesh.html
just copy and paste the example relevant to you! you're not "re-writing" the mesh.
hope it helps.
This may be useful to you ...
http://answers.unity3d.com/questions/321428/adding-mesh-collider-in-run-time-slow.html
click through to the many questions linked
be sure to pls vote up useful answers! :) hope it helps
That's exactly what I needed to know. Sorry for asking something clearly written in manual, I missed that. Thank you :)
HERE TO HELP !
pls vote up some of my other long answers, i live for points ;-)
http://answers.unity3d.com/questions/321428/adding-mesh-collider-in-run-time-slow.html