how to get a face of 3D model and Scale it? (programatically)

Updated on December 9, 2019 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on December 8, 2019

How can we get the face of the 3D model in unity and scale it individually? Like we do in 3D Modeling Softwares such as Blender? (See the gif below)

I want to achieve the exact same thing in unity using programming!

PS: I tried getting triangles of that face but I quite can’t figure out how to scale them. I am not much into Mesh programming.

  • Liked by
0 on December 9, 2019

If you can get the triangle (I’m not sure how you would, but I’m sure you can) that gives you the 3 vertices that make it up. So to scale it, you would just then move those vertices towards or away from their average position.

So triangle[6] may be equal to {0, 2, 3}. 0, 2, 3 being the index of the vertices.

Now that you have 0 2 3, you can get their average position by adding their Vector3 together, and dividing by 3. That Vector 3 is (roughly) center of the triangle. Then you can lerp the vertices towards it to make the face smaller (scale down) or away from it to make the face larger (scale up).


There’s a bit more to it than this, like I think you need to override the current mesh every frame to see it happen in real-time, but the functionality is this. Get the face, get the vertices, get the center position, move vertices.


Here’s Unity’s documentation on Meshes for further reading:

  • Liked by