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

Road addnodes too sparse or to dense flips the road upside down #240

Open
gianlucafabris opened this issue Dec 12, 2023 · 6 comments
Open

Comments

@gianlucafabris
Copy link

Creating Road with addnodes and a set of nodes too sparse or to dense flips the road upside down.
This issue affects all the road or part of it, this can't be fixed with flip_direction=True.

@gianlucafabris
Copy link
Author

all the road, if all the nodes are added at once
partial (only the segment to spese or to dense), if the nodes are added one at a time

@dstark481
Copy link
Contributor

Hello Gianluca,

I don't see the road being flipped upside down in your example, but there are glitches (folding and maybe material mapping problems). You can inspect the road a bit better if you go into the World Editor (press F11) then at the top, select the Decal Road Editor.

Your points are not monotonous in the X dimension (the first 5 go left, and the rest go right) - this describes a very sharp turn, since the Y value does change, but this may explain the 'folding' appearance. The road tool is not perfect, and this pushes it quite stiff. Also - it is probably better to create the mesh before laying the decal road on top of it (although I am not sure this matters from BeamNGPy tbh).

The internal tool which creates the roads has some known issues which we are working on (it is very old), so for now it would be best to keep points from being too close together, and to avoid very sharp turns. You shouldn't need to put points that close together anyway - internally, a spline will be fitted to them, so any detail at that resolution would likely be lost in this process.

Dave

@gianlucafabris
Copy link
Author

gianlucafabris commented Dec 13, 2023

thanks for the reply
the example was made by hand, here is the corrected version (monotonic)

    road.add_nodes((-307.5, 20, 0, 30)) #dense
    road.add_nodes((-307.4, 20, 0, 30))
    road.add_nodes((-307.3, 20, 0, 30))
    road.add_nodes((-307.2, 20, 0, 30))
    road.add_nodes((-307.1, 20, 0, 30))
    road.add_nodes((-307, 20, 0, 30))
    road.add_nodes((-257, 15, 1))
    road.add_nodes((-207, 25, 2, 15)) # the 4th is width of the node
    road.add_nodes((-157, 20, 1))
    road.add_nodes((-107, 20, 0)) #sparse
    road.add_nodes((97, 20, 0))

In my project i'm using a tool to generate the nodes, and some times the nodes are to dense or to sparse, here is an example with two roads monotonic both x and y

    road1.add_nodes((220.38, 0.0, 0.0),)
    road1.add_nodes((228.222, 10.388, 0.0),)
    road1.add_nodes((257.577, 58.126, 0.0),)
    road1.add_nodes((268.611, 77.357, 3.0),)
    road1.add_nodes((304.989, 137.108, 3.0),)
    road1.add_nodes((308.183, 142.592, 3.0),) #dense
    road1.add_nodes((309.842, 145.428, 3.0),)

    road2.add_nodes((-28.224, 170.02, 3.0),)
    road2.add_nodes((47.185, 119.69, 1.0),)
    road2.add_nodes((82.989, 94.664, 1.0),)
    road2.add_nodes((123.993, 65.734, 0.0),)
    road2.add_nodes((133.075, 59.684, 0.0),) #sparse
    road2.add_nodes((220.38, 0.0, 0.0),)

Screenshot 2023-12-13 184825
the lighter areas are how the road is supposed to look like, the darker areas are where it is to dense or to sparse

btw, with nodes properly spaced works fine even with non monotonic x and y, example (circle like)

    road.add_nodes((-20, 0, 0.0),)
    road.add_nodes((0, 20, 0.0),)
    road.add_nodes((20, 0, 0.0),)
    road.add_nodes((0, -20, 0.0),)
    road.add_nodes((-40, 0, 0.0),)

@dstark481
Copy link
Contributor

You could try running a pass over the points, whereby if two consecutive points are too close (eg < some epsilon) then remove the 2nd, etc. To increase density, you could start adding midpoints. We do this kind of thing sometimes.

Dave

@gianlucafabris
Copy link
Author

ok thanks, hoping for a correction of the bug in future versions

@gianlucafabris
Copy link
Author

gianlucafabris commented Apr 2, 2024

some updates: I've done some test to better understand the cause of the problem, here are the test and analysis github.com/gianlucafabris/BeamNGpy - Road test, hoping this might help you

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