- Home /
Unity 2D - Primitive Mesh Interpolation
Hi,
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.
Answer by Rhombuster · Mar 29, 2017 at 08:57 PM
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.
Hi Rhombuster,
Thanks for your reply, I was thinking of a similar solution as performance wont be an issue with the small amount of vertices. The issue with this solution is that you have to map vertices from one shape to another, i guess if the vertices are in an ordered list and the object rotation is the same you can rely on the array index for vertex position mapping - assu$$anonymous$$g all of the vertices are initially declared in the same way (clockwise or anticlockwise).
Your answer
Follow this Question
Related Questions
How to flatten 3d image STL to 2d 0 Answers
Draw/generate shape as 2D sprite? 0 Answers
How to extend the curve created using quadratic interpolation? 0 Answers
How to generate a NavMesh only with colliders? 5 Answers
How to make 3D colliders on sprites? 0 Answers