4
\$\begingroup\$

The Problem

I've been attempting to create some procedurally generated paths for a while now, but I've reached a problem when it comes to generating the intersections of the paths.

The paths are currently "extruded" along a catmull-rom spline, I used a bezier curve before but catmull made the whole process of placing the points easier.

My plan is to have all of the path nodes as part of one big graph, so that each node has edges to other nodes. This way it will be easier to do pathfinding on the paths later on.

public class PathNode
{
    public Vector3 Position;
    public float Width;
    public List<PathNode> Edges;
}

Here's an illustration that kinda shows what i want, think of existing games like the roads in Cities skylines:

enter image description here

TL;DR I know how generate the mesh along a curve, my biggest problem here is that i don't know how to generate the mesh at the intersections.

I've read something about creating a polygon from all of the closest vertices of an intersection, and the triangulating that polygon. but i fail to see how i would get the right vertices from the mesh, without having to calculate the distances for each of them to the intersection node.

If you need anymore information please do ask :)

Thank you in advance

Regards Holst.

\$\endgroup\$
0
\$\begingroup\$

I also stuck on how to generate junctions, however, I kinda have a solution to this.
I'm assuming that your graph is a planner graph which is probably has to be.

Step 1: You need a const for the half-width of the path and a const for half-width of the junctions.

Step 2: You generate all the segments based on the segment half-width and you offset the first and last ring by the junction half-width.

Step 3: You calculate where all the needed vertices are and generate the junction mesh.
Now because you know the direction of the segments, how wide they are and how much offset they got you can calculate where all the vertices are.

And you should have a nice path.
If you found a better way please update.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.