- Home /
Mirror vertices procedurally
For a mesh being edited procedurally, how do you mirror the manipulation operation across a particular axis/plane?
Can you assume the vertices are always zeroed around the origin?
--
Would you necessarily have to create a "buffer" to store the coordinates, to know which vertex/normal index to invert to mirror?
Is this the idea on mirroring a manipulation on position coord with yz plane symmetry?
function storeGlobal(mesh){ var vertices=mesh.vertices; var normals=mesh.normals; for(i=0;i<vertices.length;i++){ globalMeshVar[vertices[i]]=normals[i]; } }
function mirror(coord,plane,disp){ var vertices=globalMeshVar.vertices; var normals=globalMeshVar.normals; for(i=0;i<vertices.length;i++){ if((vertices[i] - coord)==0){ globalMeshVar[vertices[i]]+=disp*normals[i]; globalMeshVar[plane - vertices[i]]+=disp*(-normals[i]); } } }
Answer by duck · Mar 03, 2011 at 09:35 PM
Yes, vertices in mesh data are stored in local coordinates, so to mirror them about any of the three local axes, you can just invert the sign of the position value.
For example, flipping the vertices on the mesh's local X axis:
var vertices = mesh.vertices;
for (var i = 0; i < vertices.Length; ++i) { var v = vertices[i]; vertices[i] = Vector3( -v.x, v.y, v.z ); }
mesh.vertices = vertices; mesh.RecalculateBounds();
Still not sure how the workflow goes: would I have to store an intermediate array of mesh data to know which mesh index to "flip"? (See updated snippet above)
This looks like it just flips the vertices ins$$anonymous$$d of actually mirroring ... I guess my confusion has to do with how you assign the vertices array for a mirror operation programmatically
Answer by Martin_Th · Feb 03 at 05:46 PM
I can mirror my mesh but some faces are not visible. I recalculate the normal vector from the faces. Is their anything to do else?,I can mirror my mesh with this but some areas are not visible. Is thier any workaround?