Generate a flat path that follows the terrain with a spline

Hello,

I would like to create a rectangular tube-shaped extrusion along a spline and a defined width. But I can’t do the extrusion correctly.

In the image we can see that the extrusion is not flat, it forms weird things. At both ends it does not touch the ground. In short, I think I didn’t really understand how shape extrusion works.

Example of a short video :

Example video of what I want to do

PG of what I started so far, which almost works, but not correctly :

The function can be found on the line 177 of PG

For use :

  • Click on Attach Control.
  • Draw a path as in the image.
  • Then click on generate path.

This currently shows the Shape, but it can be hidden by disabling comments in the function line 200-206.

Can someone help me make my extrusion straighter (like a thin rectangle), which follows the spline, which itself follows the shape of the terrain.

Thanks for your help.

Maybe @Cedric has an idea ?

1 Like

The video you linked is not an extrusion. it’s a modification of the ground height based on a 2D image.
Heights in the picture are modified by a path.

Let me try to do something…

1 Like

Thank you Cedric for your help. I wouldn’t have imagined that this could be generated by an image. I didn’t even know it was possible for an image to create vertex changes.

Here is what I had in mind. with programer art :slight_smile:

a height map with greased lines is rendered (lines 25 - 78). this height map is then used to create a terrain (lines 94 - 130)

Thanks Cedric, but this won’t work for what I want to do.

There you generate a terrain complet. What I do is a field editor. We create a flat terrain or with a heightmap and users can modify it by creating mountains, rivers by painting. Then I would like to create a tool so that it can create paths along a spline and that this path is flat on the x and z axis, but not in Y (except by softening the angles to have a fluid path )

On the other hand, your projection system could perhaps be used to apply the texture of the path, I discovered something with your PG. But that still remains a bit complicated for me to understand.

Did you look at my PG to better understand what I wanted to do? It works, but has issues.

I wish I could correct that. You can see in the image that the Shape has an angle that I don’t understand.

I use an extrusion, because with a tube it doesn’t work well. A ribbon created similar problems for me and I was advised to create an extrusion to create the shape which draws the path, then discard it once the paths have been generated.

Why is there this angle? My PG almost works except for that.

I put the PG here which I improved from the other one.

Thanks a lot for your help.

Can you try to repro your issue with a smaller PG? without any manual interaction. I guess it’s the path that introduces a up computation but I’m not sure.

I’m going to do this without the buttons

That’s it, you just have to paint then when you release the click, this will create the shape

please, also set the points that are problematic and reduce the scope of the PG

That’s it, it creates the path automatically and I removed all the unnecessary code.

I’ve drastically simplified your extrusion here
What it shows is that on a curved 3D path, the extrusion (and underlying ribbon) has to interpolate vertices that induce torsion. I don’t have a workaround for this, although I can imagine one.
on a side note, the adjustFrame parameter for extrusions only has meaning when the path exactly reverses itself between two control points, i.e. given two consecutive points on the path, pi pj, the array contains [… pi, pj, pi, pj, …]

1 Like

Thanks @lowclouds for have simplified the extrusion.
So should I understand that this is not the right approach of it this way?

This works very well with a tube, but it forms a rounded path. Which can be good for digging rivers, but not for paths. I suggested creating a square tube instead of the round one and I was told to do it with an extrusion. But that doesn’t seem to work too.

Do you have another idea that might work ?
Maybe @Cedric you have another solution.

I just had an idea. Seeing that you have a tube it seems to work, but it forms a rounded path. Is there no possibility of then flattening this path which has been rounded by the tube.

Here’s a PG with a hit. It works well, but the path takes the shape of the tube. Would it be nice if we could flatten this path next? But I don’t know how to do that. With a square tube it would simplify things for me.

The tube extrusion just hides the underlying problem; you’d still see issues where curvature is high if you tried to flatten it. Check out this modification, where I’ve used a Catmull Rom spline to increase the number of sections in the path. You can tweak the number of spline points to exaggerate this. When the curvature of the path gets high, the path begins to self-intersect, and torsion is still introduced - you could hand-draw this out to see why this happens.
Again, I don’t have a solution in hand, but I may eventually

You are right, the problem is the same with a tube which is based on a ribbon too.

I applied your changes. I don’t know how other publishers do this. I see this everywhere, but it seems that with Babylon we can’t do it. Sometimes I want to give up on everything. I’ve been stuck on this feature for 1 month and it seems that there is no solution.

Anyway, thanks for trying to help me.

This works perfectly well if my path is a bit straight. If I could get this result with a rounder path, it would be perfect.
You just need to be able to prevent the ribbon from bending. But it doesn’t seem possible to constrain this from what I understand.

1 Like

Here’s a start of an outline of how to fix this, although many details are unfinished. The above playground shows the binormals that ExtrudeShape is using to construct the road. The longer red vectors sticking out are parallel to the xz plane (constructed by crossing the tangent vector with 0,1,0. You could use these to construct a ribbon and then extrude that - but you’ll still have to deal with the curvature causing self-intersections. That’s part two.

1 Like

Thank you very much @lowclouds. It works perfectly well with your solution.

I adapted all of this in my PG and the result is just perfect. I used a ribbon, without extruding it. And the colored lines, I display them in Debug mode.

I’m sure this feature will be useful to other people.

1 Like

I have a little question @lowclouds . Is it possible to center the line so that the ribbon is centered on the line white. On the screenshot above, you can see the white line and I try to center it on the red lines.

How would you do it ?

Thank you very much for your help.