Drawing filled organic shapes

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
josip
Prole
Posts: 21
Joined: Tue Oct 03, 2017 1:55 pm

Drawing filled organic shapes

Post by josip »

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:
  1. create a series of chained bezier curves - each curve's ending point is next curve's starting point
  2. for each curve, render it to get a list of points
  3. concatenate all curve points into single polygon (skip first point of each curve)
  4. call love.math.triangulate on resulting polygon to deal with potentially concave shape
  5. 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.
User avatar
NotARaptor
Citizen
Posts: 59
Joined: Thu Feb 22, 2018 3:15 pm

Re: Drawing filled organic shapes

Post by NotARaptor »

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.
josip
Prole
Posts: 21
Joined: Tue Oct 03, 2017 1:55 pm

Re: Drawing filled organic shapes

Post by josip »

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.

Image

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?
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests