I'm struggling with drawing complex shape composed of curves. The drawn shape will change during execution, so I can't just use bitmaps.
My current method is:
create a series of chained bezier curves - each curve's ending point is next curve's starting point
for each curve, render it to get a list of points
concatenate all curve points into single polygon (skip first point of each curve)
call love.math.triangulate on resulting polygon to deal with potentially concave shape
use love.graphics.polygon('fill', triangulatedPointList) to draw it on screen
The problem is that triangulation will fail if polygon has duplicate points, or if it intersects itself. I don't know how to untangle the self-intersecting polygon so that it can always be triangulated and drawn.
Is there a more robust way to draw organic shapes? I saw some metaball/metaline implementations for Love, but they are outdated and they use shaders which I would like to avoid. If it makes any difference, I'm on Love 0.11.
Can you show us some example images of the kind of shapes you're trying to create?
The general problem can be solved in at least two ways (without shaders):
- Keep doing what you're doing but do the triangulation yourself. I believe there is a modified ear-clipping algorithm that can handle self-intersecting polygons.
- Refactor and use something like marching squares on a potential field - this will generate very nice metaballs.
But there are probably much easier ways to achieve what you're trying to do, depending on the type of organic shapes you want.
I'm making a face that can make gestures. Currently I'm tying to make mouth with different shapes, and the mouth shape is not drawable for some positions of control points. I used filled bezier for jaw shape, and had no problem there because shape doesn't vary as much. For brows I iterated along bezier curve and drew circles of varying radius - computationally expensive but it produced good results.
Are you aware of any 2d shape algorithms that are easy to control (few control points) and are elastic in a way that roughly preserves surface area?