Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When I use Clipper to cut polygons, sometimes I get some separated polygons and some holes. How can I use earcut to process these separated polygons? #91

Closed
jellychen opened this issue Mar 11, 2021 · 8 comments

Comments

@jellychen
Copy link

When I use Clipper to cut polygons, sometimes I get some separated polygons and some holes. How can I use earcut to process these separated polygons?

@mrgreywater
Copy link
Collaborator

You have to invoke earcut for each individual separated polygon. If you require more specific help you can provide some polygons you get from clipper as output and I'm happy to show you how to prepare them to run earcut on them.

@jellychen
Copy link
Author

Thank you for your reply, I seem to have found a way. I'm making an SVG library, using Clipper to do clipping, and Earcut to triangulate. But because I have to run on OpenGL ES 3.0 hardware, I need to render to textures. OpenGL ES 3.0 does not yet support multi-sampling of textures. Is there any good solution for this?

@jellychen
Copy link
Author

@mrgreywater

@mrgreywater
Copy link
Collaborator

mrgreywater commented Mar 12, 2021

An alternative to multisampling is supersampling, basically you increase the size of the texture by a factor of 2x, 4x or 8x, scale the polygons by the same amount, render them to the texture and finally downscale the output texture back to your desired size.

@jellychen
Copy link
Author

This will lead to too much pixel filling, and the performance will be affected

@jellychen
Copy link
Author

I'm considering whether I can use clipper to make an edge offset, then triangulate the offset part, and then make an alpha transition in GPU shader. I don't know if this is the right direction

@mrgreywater
Copy link
Collaborator

I think your solution would be quite blurry, but you can try. Before you do, try to check if the 'EXT_multisampled_render_to_texture' extension is available and use it instead.

@jellychen
Copy link
Author

I tried to use msaa and found that the effect is not good. It should be provided by hardware, there may be many differences.
I now use clipper to cut and triangulate through earcut, but I need anti-aliasing, so I wonder if I can add some redundant data through the vertices to interpolate, and then use the shader to determine whether the current pixel is Near the edge? Is there such a technique?
@mrgreywater

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants