# Improved/Creation a Ramp/Path function

**URL:** <https://forum.babylonjs.com/t/improved-creation-a-ramp-path-function/48002>\
**Category:** Questions\
**Created:** [February 13, 2024, 4:24pm UTC](https://forum.babylonjs.com/t/improved-creation-a-ramp-path-function/48002 "2024-02-13T16:24:08Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dad72](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dad72/32/13_2.png) [@Dad72](https://forum.babylonjs.com/u/Dad72)\
**Post date:** [February 13, 2024, 4:24pm UTC](https://forum.babylonjs.com/t/improved-creation-a-ramp-path-function/48002/1 "2024-02-13T16:24:08Z")

</div>

Hi,

I have a function that allows you to create Ramps by clicking 4 points.

I would like to modify this so that this is done by clicking 2 times (one click at the top of a vertex and one click at the bottom) by setting a ramp width instead to get the 4 points.

I don’t know how to modify this function to obtain the same result but with 2 clicks instead of 4.

Could anyone help me with this.

Thanks

> **[Babylon.js Playground](https://www.babylonjs-playground.com/#0S98UZ%231)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [February 14, 2024, 11:43am UTC](https://forum.babylonjs.com/t/improved-creation-a-ramp-path-function/48002/2 "2024-02-14T11:43:03Z")

</div>

Oh, you know I love these kind of questions 🙂

[Create Ramp | Babylon.js Playground (babylonjs-playground.com)](https://www.babylonjs-playground.com/#0S98UZ#7)

How about this? One click and drag?

Mostly using your code, and of course not error prone, but the basics are there

---

<div class="post-metadata">

**Author:** ![Dad72](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dad72/32/13_2.png) [@Dad72](https://forum.babylonjs.com/u/Dad72)\
**Post date:** [February 14, 2024, 12:24pm UTC](https://forum.babylonjs.com/t/improved-creation-a-ramp-path-function/48002/3 "2024-02-14T12:24:31Z")

</div>

I like this approach. It’s a great idea too as you did it.

At the beginning I thought of making something from a spline which follows the terrain to use the ramp code to also make paths for example.

But I’m going to study your code to try to understand all this.

Thank you very much @RaananW

---

<div class="post-metadata">

**Author:** ![Dad72](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dad72/32/13_2.png) [@Dad72](https://forum.babylonjs.com/u/Dad72)\
**Post date:** [February 14, 2024, 1:42pm UTC](https://forum.babylonjs.com/t/improved-creation-a-ramp-path-function/48002/4 "2024-02-14T13:42:47Z")

</div>

I was asking myself a question. Is it possible of create a ribbon along a line ?

On this PG:  
Draw a path by clicking and dragging. Each sphere represents a transformation node.and the line the path to create a ribbon of a width to define.

> **[Babylon.js Playground](https://www.babylonjs-playground.com/#0S98UZ%2312)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

I would like to use the same code base to create paths that follow the terrain. But here I would just like to create the ribbon that follows the line. Is this something possible?

This might be a question you would love too. @RaananW 😄  
With all my thanks for your help.

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [February 14, 2024, 2:16pm UTC](https://forum.babylonjs.com/t/improved-creation-a-ramp-path-function/48002/5 "2024-02-14T14:16:53Z")

</div>

Why, yes I do!

But don’t have the time to really dive in here. However, I think you are on the right path.  
You can use Path3D for that - generate an updated Path3D and constantly update the points array every time a new one was created. There is an example here - [Path3D | Babylon.js Documentation (babylonjs.com)](https://doc.babylonjs.com/features/featuresDeepDive/mesh/path3D#update)

Using this Path3D you can generate a ribbon, similar to the way a Tube is generated. A tube requires an array of Vector3, that you can generate from a Path3D. Technically, you don’t really need the Path3D - you can just update the path array and pass it to the tube. The reason I thought you might want to use Path3D is first because it will contain all of the math you need for paths. Second - it is a goot container. And third - i am not sure you want a tube. A tube is a specialized case of a Ribbon. Look at the Tube code - [Babylon.js/packages/dev/core/src/Meshes/Builders/tubeBuilder.ts at master · BabylonJS/Babylon.js (github.com)](https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/Meshes/Builders/tubeBuilder.ts#L172) it creates a ribbon, based on a self-generated set of Vector3. These are generated based on parameters you pass to this function - [Babylon.js/packages/dev/core/src/Meshes/Builders/tubeBuilder.ts at master · BabylonJS/Babylon.js (github.com)](https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/Meshes/Builders/tubeBuilder.ts#L80) which takes a Path3D that is based on the generated Path (a vector3 array).

So TL;dr - sorry, sadly no time to really dive in, but I would recommend you to either use an updatable tube (if that is acceptable) or create you own customized ribbon, based on the tube-creation function.

---

<div class="post-metadata">

**Author:** ![Dad72](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dad72/32/13_2.png) [@Dad72](https://forum.babylonjs.com/u/Dad72)\
**Post date:** [February 14, 2024, 2:26pm UTC](https://forum.babylonjs.com/t/improved-creation-a-ramp-path-function/48002/6 "2024-02-14T14:26:18Z")

</div>

Thank you for putting me on a trail. I’ll try to understand all of this. I understand that you have other occupations.

---

<div class="post-metadata">

**Author:** ![Dad72](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dad72/32/13_2.png) [@Dad72](https://forum.babylonjs.com/u/Dad72)\
**Post date:** [February 14, 2024, 4:17pm UTC](https://forum.babylonjs.com/t/improved-creation-a-ramp-path-function/48002/7 "2024-02-14T16:17:18Z")

</div>

For the moment I have managed to do that. Is what I am doing correct?  
I have the impression that it’s not very regular, but it seems to work.

Draw a circle. the path that we trace creates a ribbon when we release. Then I use the same function as to create the ramp.

> **[Babylon.js Playground](https://www.babylonjs-playground.com/#0S98UZ%2314)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![Dad72](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dad72/32/13_2.png) [@Dad72](https://forum.babylonjs.com/u/Dad72)\
**Post date:** [February 15, 2024, 2:14pm UTC](https://forum.babylonjs.com/t/improved-creation-a-ramp-path-function/48002/8 "2024-02-15T14:14:50Z")

</div>

I don’t understand what’s happening. On this PG if you draw a large circle on the ground, the path forms an Ellice instead of being horizontal., the ground does not flatten out following the ground. In short, I don’t think I understand anything about what’s going on.

> **[Babylon.js Playground](https://www.babylonjs-playground.com/#0S98UZ%2316)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

Does anyone have any idea ?

---

<div class="post-metadata">

**Author:** ![Dad72](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dad72/32/13_2.png) [@Dad72](https://forum.babylonjs.com/u/Dad72)\
**Post date:** [February 15, 2024, 6:09pm UTC](https://forum.babylonjs.com/t/improved-creation-a-ramp-path-function/48002/9 "2024-02-15T18:09:07Z")

</div>

Just to give you an idea of ​​what I’m trying to achieve. But I really can’t do it. Everything I try to do fails.  
So maybe I don’t have the right method to do this.

[path.mp4](https://www.realm-crafting.com/BabylonJS/path.mp4)

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [February 19, 2024, 5:26pm UTC](https://forum.babylonjs.com/t/improved-creation-a-ramp-path-function/48002/10 "2024-02-19T17:26:18Z")

</div>

Might get you a little further - [Create Path Final | Babylon.js Playground (babylonjs-playground.com)](https://www.babylonjs-playground.com/#0S98UZ#18)

Use a tube, dispose it after you are done with it, and make sure to update the ground heights to get the right heights after updating the positions (line 219)

---

<div class="post-metadata">

**Author:** ![Dad72](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dad72/32/13_2.png) [@Dad72](https://forum.babylonjs.com/u/Dad72)\
**Post date:** [February 19, 2024, 6:48pm UTC](https://forum.babylonjs.com/t/improved-creation-a-ramp-path-function/48002/11 "2024-02-19T18:48:39Z")

</div>

It’s awesome. Thank you very much @RaananW  
Little question. Can the tube follow the shape of the terrain?

There I intersect the Y position of the first click to create the tube at the right height. But can he follow the curve of the terrain?

I have the impression that I will be able to make progress on this functionality.

---

<div class="post-metadata">

**Author:** ![Dad72](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dad72/32/13_2.png) [@Dad72](https://forum.babylonjs.com/u/Dad72)\
**Post date:** [February 20, 2024, 2:25pm UTC](https://forum.babylonjs.com/t/improved-creation-a-ramp-path-function/48002/12 "2024-02-20T14:25:45Z")

</div>

I tried to foul the Y tube to flatten it. But if I do that, it no longer curves in a Y shape (it no longer follows the shape of the land)  
I can only flatten it by 40% maximum. But the path shape is rounded, which is not correct.

So I was wondering. There are cylindrical tubes, but why is there no square tube? It’s a tube too. Is it not possible to add the shape to the tube options to make a square tube?  
I’m going to open a new topic for this.

> **[Babylon.js Playground](https://www.babylonjs-playground.com/#0S98UZ%2321)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes
