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

Meshes and borders overlapping due to clustering of Control Points #1

Open
Wally869 opened this issue Jan 6, 2021 · 3 comments
Open

Comments

@Wally869
Copy link

Wally869 commented Jan 6, 2021

Thanks for sharing your work, it's really great stuff! I found a small problem for which I'm working on a solution, I wanted to share it with other users of your code

Problem Encountered

Mesh can overlap itself.
This is likely due to control points being created on edges intersections and forming a cluster.

Potential Fixes

I see 3 solutions to this:
1- Perform a check on the Voronoi diagram to avoid diagrams where too many intersections are clustered
2- Prune control points which are too close to one another when generating the spline
3- Perform displacement on control points which are too close to each other, and recompute spline

@Wally869
Copy link
Author

Wally869 commented Jan 6, 2021

Solution 1 seems wasteful and solution 2 might generate meshes which are too simple, so I went with solution 3.

I created a small workaround:
1- Create a new monobehaviour component (or add this stuff to the SplineCreator)
2- Expose the CreateSmoothSpline and SmoothSplineNoEdit method of the Spline class as public instead of private
3- In your monobehaviour get the Spline.AllRawPoints
4- Perform distance check between points and set the distance between them to satisfy a minimum distance condition
5- Set the modified points back to Spline.AllRawPoints (I created a public setter)
6- Call CreateSmoothSpline and SmoothSplineNoEdit
7- Now you can generate the mesh

This doesn't completely solve the problem: I'm using pairwise points comparison and pushing the points away from the midpoint, but it doesn't solve everything. A better solution might be to perform clustering, and displace the points belonging to the group away from the group's center, but I'm still unsure if this is sufficient, I'll update this issue later once I've made the changes.

Please let me know if you fixed this issue on your side. The tracks generated are incredibly versatile, it's a really great idea

@Wally869
Copy link
Author

Wally869 commented Jan 7, 2021

After some work, I realized there was a "Try to fix" button (not sure how I missed that one), but I wasn't too satisfied by the results. So I continued my work and the best solution really seems to be using iterative cluster creation based on a threshold distance, and then again iteratively displacing the points away from the cluster center.

See the result below on a complex track: the initial track generated has a lot of overlap, while the fixed version shows no such thing and is smooth. I can also confirm that sharp turns can be preserved by this approach.

racetrack_raw

racetrack_fixed

I need to do some refactoring, then I'll upload my code on another repo for everybody. Lemme know if you found a better solution

@I-Hudson
Copy link
Owner

I-Hudson commented Apr 1, 2021

@Wally869 Sorry to only just getting around to this. The overlapping issue has always been there unfortunately. From the screen shots you have posted, your solution looks very nice and I would be one I'm interested to see how it has been implemented.

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