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

Minimum triangle surface area #6

Open
Korijn opened this issue Jul 31, 2023 · 1 comment
Open

Minimum triangle surface area #6

Korijn opened this issue Jul 31, 2023 · 1 comment

Comments

@Korijn
Copy link

Korijn commented Jul 31, 2023

Is it possible to implement alternative stopping criteria?

Now the library provides maxTriangles, but for example minimumArea would also be a useful criterion, in order to achieve more "uniform" subdivision.

@stevinz
Copy link
Owner

stevinz commented Jul 31, 2023

I have played with this idea before, trying to ignore triangles with a certain area, or by side length. Choosing to smooth some triangles and not others. I haven't had much success in doing so without causing a huge mess. The averaging calculations expect their neighbors to be subdivided, and to share vertex locations. Missing triangles cause gaps, and the worst part is that ignoring them doesn't provide the results you would hope.

There are some other options. The issue you're bringing up (more "uniform" subdivision) has more to do with the starting state of the geometry's vertex positions. A geometry with faces that have more even triangle distribution yield much nicer results. This can be seen most clearly in the Shape example on this site. The example uses Three.js ExtrudeGeometry, which uses the earcut algorithm for polygon partitioning. The earcut algorithm does not concern itself with being optimal in terms of minimal edge length (this readme does a good job visualizing different partitioning algorithims). In other words, it puts huge triangles in the middle and lots of tiny triangles at the edges. The triangles at the edges end up with lots of shared vertices, which do not look good when being averaged (i.e. subdivided). It would be possible (and not too hard) to create a new ExtrudeGeometry using a more optimal algorithm, but that would only help in that particular use case.

I believe the ideal solution would be to pre-process the geometry and redistribute face triangles evenly before being subdivided. The whole geometry would have to be looped through to gather faces by checking for shared edges and calculating face directions (i.e. normals). Then a new polygon partitioning algorithm would be ran on each face, with perhaps an option for triangle density. I have planned to do this as a long term goal, but haven't gotten around to giving it a serious try yet.

In the mean time, there is another, simpler idea I have tried with some success. It involves scaling the averaging function based on how many triangles share a given vertex. I have added this feature to the library, and the example (the weight parameter). Try scaling it down from 1, it may provide some improvement on certain geometries / meshes / models.

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

No branches or pull requests

2 participants