3
\$\begingroup\$

I've been running into walls for the past week or so on my toy project in UE4. My goal is to draw procedural roads on a procedural landscape (eventually getting to intersections and buildings). The landscape is generated with libnoise and the roads are generated with a slightly modified version of the algorithm found here.

But I'm having issues draping the roads on the landscape and I can't find any straightforward algorithmic way of doing it. You can see my problem below: the geometry of the road intersects the geometry of the landscape.

Road clipping

In short, given:

  • The landscape index buffer
  • The landscape vertex buffer
  • Every road segment's X,Y,Z coordinate

How do I modify the underlying vertex/index buffer so that the landscape "wraps around" the roads?

\$\endgroup\$
  • \$\begingroup\$ Could you check out the answers? \$\endgroup\$ – Bálint May 2 '17 at 16:09
2
\$\begingroup\$

I would suggest modifying the engine to expose the Landscape functions. Then add a button to the Landscape tool palette, to force a terrain rebuild after placing roads. Terraim rebuild routine could look at the manual painting mechanisms, to see how to correctly modify vertex position.

This is not a trivial matter indeed.

Without this, I feel the best solution is to make the road always above terrain level, then fill around the road with static meshes so it avoids "floating mesh" issues.

|improve this answer|||||
\$\endgroup\$
1
\$\begingroup\$

When you place a road, you need to subdivide it into triangles based on the terrain triangles under it.

Let's forget the y axis for a moment, and do things as if they were in 2d.

First of all, get the AABB of the road, extend it in each direction a bit to avoid not checking some terrain triangles.

Next you need to get every triangle that at least partially intersects with the road. If your terrain is out of squares, then this is going to be very easy. If it isn't, then use AABBs once again. You don't need to make sure the triangle intersects with the road, you just need the triangles that could intersect with it.

Now you want to get intersection points of the triangle edges and the road's edges. Take the intersection points and add them to a list. If a corner of a triangle is inside the road, add that one too.

Now, you have the intersection points, make them line up with the terrain and use a triangulisation algorithm to convert it into polygons. The result should perfectly line up with the terrain.

|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

Obviously no one correct answer for this. I worked on a game at Sony where we had to solve this exact problem. One solution is that you'll develop a strategy where you generate road geometry that follows the procedural geometry at the triangle level, possibly even down to computing split triangles, then give it some thickness and a curb.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ That's not really an answer, is it? Could you specify how Sony solved that issue or at least point in a direction? \$\endgroup\$ – NeoTheThird Mar 26 '17 at 15:03
  • 1
    \$\begingroup\$ Even though this isn't an answer per se, thank you for at least letting me know achieving what I had in mind isn't trivial. I had made the assumption that it was, but it looks like my solution will need to (at a bare minimum) include some kind of triangulation. \$\endgroup\$ – David Titarenco Mar 27 '17 at 7:41

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.