canvas rendering issue. "quick decomp: max level (100) reached"?

Not favoritedFavorited Favorited 0 favourites
  • 12 posts
From the Asset Store
This sound pack comes with 100 high quality, ready-to-use sound effects for all kinds of games.
  • I'm currently working on making star maps like the game Stellaris.

    I'm trying to render the regions controlled by different teams. I'm using a sprite with mesh distortion to create the outline of boarders (so i get a nice sharp clean edge rather than pixelated edge), and the canvas object to draw the inner solid colour.

    The issue I'm having is in some circumstances the canvas wont render properly, 99% of the time it works though.

    The points are ordered correctly, as they use the same points as the mesh object, which is the correct shape, so i've ruled that out.

    I thought it might have to do with having "convex" checked when filling the polygon, but that made things worse.

    Then i looked in the console log and notice this.

    "quick decomp: max level (100) reached". Related to polygons.

    It only comes up when i notice the rendering error.

    I'm kind of stuck. The mesh object being square grid based cant render such complex shapes. I've tried writing a custom shader but shader files don't support token strings so each point would have to be a separate parameter, which is not feasible.

    Ashley any help?

    Thanks

    Tagged:

  • I guess you're using Drawing Canvas and filling a polygon with 'convex' unchecked. As it can only really actually fill convex polygons, in this mode it does a highly complex and not particularly reliable algorithm to split a concave polygon in to a series of convex ones, and then fills those all separately. I guess you've run in to the limit of how far the polygon decomposition will go with that process.

    I'll increase the limit to 1000 for the next release which might help, but it might run in to other problems, like algorithmic inefficiency with too many points. You may have better luck trying to draw more smaller polygons, or keeping them convex - if you're trying to draw one gigantic concave polygon with loads of points, I'd say that's likely to be a problem.

  • Unfortunately all the shapes are pretty much concave, and since its all procedural i can never be sure. I've tried convex but it never renders the shape accurately.

    I would appreciate increasing the limit to 1000.

    What I'm doing is already really complex, delaunay triangulation, centroids, creating local boundaries, joining boundaries into clusters, clusters groups within cluster groups within cluster groups etc.

    It seems to work well most of the time, with some really complex shapes.

    It would be an extra layer of complexity to split the shape up into chunks.

    I'll have to think some more.

  • A few ideas:

    Since you’re hitting the limit of the algo that the canvas object uses to convert a concave polygon to multiple convex ones, you could feed your polygon to another js library to do that and just draw the list of convex polygons it generates.

    Also as a tangent you could use a mesh distort to render convex polygons.

    For example for a 100 point polygon you’d do it roughly by:

    Set mesh size to (50x2)
    Repeat 50 times
    — set mesh at (loopindex,0) to point(loopindex).xy
    — set mesh at (50-loopindex-1,1) to point(50+loopindex).xy

    And actually you aren’t limited to just convex polygons. In general you can do any triangle strip in this way which includes some concave polygons. Also if you adjust the uvs you can get a textured polygon without using blend modes, but I guess that’s unrelated to what you’re doing.

    Anyways, the idea to explore is convert any polygon to multiple triangle strips and use mesh distorts to display them. To do that you’d slightly modify a triangulation algorithm like “Ear clipping”, which basically adds triangles at convex points if no other points are inside that triangle. To make it generate triangle strips instead of just triangles you’d zig zag moving cw then ccw on the plolygon when adding triangles.

    Alternatively you could triangulate, then merge triangles sharing edges if the result is still convex.

    I’ll be attempting to make an example of the idea when I get time.

  • I'll look into “Ear clipping”, thanks.

  • Here's the wip of the triangulation. It works with the the polygon defined by sprite instances in a CW order.

    Using a mesh to display the triangles didn't quite pan out because it gives thin transparent slivers due to math rounding. So it also lets you draw the triangles with the canvas as well since it doesn't have the slivers. It doesn't look worthwhile to extend it to generate convex polygons or triangle strips at this point. It will need reworking if you want to define the polygon in another way other than sprite instances. Doesn't work with self intersecting or CCW polygons, but the CCW case can be solved by detecting the order and reversing the list.

    dropbox.com/scl/fi/png6jg6a1qresctjq5ra6/triangulate_ear_clip_mesh_wip.c3p

    Alternately, if you want to use js for this you could look into this one:

    github.com/mapbox/earcut

    Or you could take the triangulation function out the old c2 chipmunk plugin. That one generates convex polygons.

    Edit:

    Just noticed that points ordered in CCW order could be used for a convex hull.

  • Very impressive as usual. Thanks very much for your help.

    This maybe the way to go. If so I'll probably convert it over to JavaScript.

    I was hoping there was a way to do it with a mesh, as the issue with canvas is the memory it uses soon gets quite large with big shapes.

  • Mesh is almost an option if we can avoid the thin transparent gaps. I want to investigate fiddling with the math to see if I can remove or reduce the rounding errors. In theory I could scale tue triangles up slightly to eliminate it too. If that works out then I’ll make it combine triangles to reduce object count. Anyways, I’ll let you know. As is it’s mostly trivial to change between drawing with canvas or a mesh.

  • Found if you set sampling to nearest then the thin slivers go away with meshes. It's probably not a viable solution since you'd want smoother sampling for everything else but still could be useful.

  • Would a polygon plugin be possible in c3, which uses ear clipping?

    I don't have experience making plugins, but do we have access to polygons in the sdk from meshes?

  • FWIW in r437 which just came out the new limit of 1000 for decomposing concave polygons with the 'Fill poly' action is now implemented, which hopefully solves the immediate problem. Although I suppose if you go 10 times further it will hit the new limit.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks ASHLEY.

    One of the issues with drawing canvas is that if i space the stars out more, which i need to, then that increases the memory used considerably. That's why i wanted to use a polygon, or mesh, so i can use a small sprite and stretch it. It only needs to be white so i can colour it at runtime and use blends for textures.

Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)