Unity 2D - Primitive Mesh Interpolation


I am trying to figure out how I can smoothly interpolate between any 2D primitive at runtime, this is made harder by the fact that shapes can have different amounts of vertices, for example; I may want to smoothly switch between a Triangle and a Square, or Octagon.

My question is, what is the best way about doing this? my initial thoughts were to program this by defining the shapes in code and performing some morphing algorithm, but this would not account for the change in vertex count. My other idea was to use the Animator to somehow switch out the gameobject and blend the transition, but this seems an awful lot of work and makes for a very rigid system. It would also take a lot of time to implement new shapes.

Any thoughts and ideas are welcome. As are code snippets!

Thanks for your time.

This is an interesting question. You could try building the shapes yourself, then make them all have the same number of vertices. For example, your circle needs something like 28 vertices. Build a square with the same number, then interpolate each vertex from the circle to its appropriate vertex on the square.

This could get tricky, you’ll have to make sure you rotate both objects. So if your circle has been rotated 45 degrees, you’ll have to rotate the square 45 degrees then interpolate. The problem is creating the shapes could become tedious. It should work though, as long as you’re careful.