Dynamic Road ... in progress

#1

http://jerome.bousquie.fr/BJS/test/terrainRoad.html

The white ribbon is the road way in the map, not supposed to be rendered.
When the road way enters the terrain, it’s rendered as a textured ribbon. This ribbon is dynamically updated according to the road map data. Still bugs and weird straight lines appearing here or there : don’t care …

9 Likes

#2

Love it!

1 Like

#3

@syntheticmagus wrote a cool low-pass filter which (might) smooth that road… if you want.

It might be used to grade ground into within variation… as well. But not sure how to do that.

    { //LOW-PASS-FILTER-SMOOTHING-.
        const AVG_RANGE = 3;
        var temp = [];
        var buf = BABYLON.Vector3.Zero();
        var count;
        for (var idx = 0; idx < aPath.length; idx++) {
            buf.scaleInPlace(0.0);
            count = 0;

            for (var innerIdx = Math.max(0, idx - AVG_RANGE); innerIdx < Math.min(idx + AVG_RANGE + 1, aPath.length); innerIdx++) {
                buf.addInPlace(aPath[innerIdx]);
                count++;
            }
            buf.scaleInPlace(1.0 / count);

            temp.push(buf.clone());
        }
        aPath = temp;
    }

I can look for the PG if you’d like to try it. :slight_smile:
vcool @jerome

1 Like

#4

not sure to get where this piece of code could go, but why not trying it…
I need to fix everything before starting the optimization phase anyway.

1 Like

#5

Yep awesome “path smoothing” by syntheticmagus:

Fun to watch it work… there is a moving window in the for loop AND I don’t undersand the add and scale (yet).
HALF-PIPE-PG: https://www.babylonjs-playground.com/#GILURX#1

STEPS-TO-USE:
Create aPath array of vectors.
Low-Pass Filter the points,
Add aPath to Line, Curve, Extrusion… road. : )
Smooth.

:eagle:

1 Like

#6

updated : Test Babylon Terrain Road
still some unwanted straight lines, but I think I know how to solve this soon
the map is quite big : 1000 x 1000
the terrain is 200 x 200 (this could be less to speed it up on slower machines)
the road is 4000 points on the map, but only 600 used by the ribbon to render it.

Try to find the road, then to flight it over :wink:

1 Like

#7

straight lines issue fixed

3 Likes