Array generated path

Hello,

recently I found the tubeBuilder and I love it. Since I want to make it more easy for me to create tubes I try to use a function that calculates the paths for me.

https://playground.babylonjs.com/#MQJMAR#15

I was able to use angles but I am stuck with following the path with straight lines after a curve.

Do you have an idea how I can solve the issue?

Best

Do you need another direction?

i.e. you have left and straight, but straight can be vertical or horizontal?

With straight I mean the path should just go forward in the given direction. So I would be able to use:

  • left: 90°
  • straight: 5
  • right: 180°
  • straight: 10
    …

If the path would go up 90° (align with y-axis) the path should go vertical if using “straight”. Direction change is only possible with “left” “right” …

I understand what you’re trying to achieve, but with the code you have straight is ‘only’ vertical at the moment, not horizontal. The vector you describe only has two components, so it will only ever be in a single plain.

Yes, you’re right. I want to take care of vertical paths after solving the horizontal problems. It is easier to think in a 2d matrix :smiley:

Adding and using this works - so think there’s just a bit of odd maths involved in the ‘z’ part which is your y…

const createStraightHoriz = (lengthPlain, options) => {
    //const length = options.degrees < 90 ? -lengthPlain : options.degrees <= 180 ? -lengthPlain : options.degrees <= 225 ? lengthPlain : options.degrees <= 270 ? -lengthPlain : lengthPlain
    //const add = options.degrees < 90 ? 0 : options.degrees <= 180 ? -1 : options.degrees <= 225 ? 2 : options.degrees <= 270 ? 3 : 2
    //const theta = options && options.degrees ? BABYLON.Tools.ToRadians(options.degrees) * (options.degrees/90+add) : 0

    const length = -lengthPlain
    const theta = options && options.theta ? options.theta : 0
    
    const thetaDelta = options && options.theta ? options.theta : 1
    const startVector = options && options.startVector ? options.startVector : new BABYLON.Vector3.Zero()

    const newVector = new BABYLON.Vector3(
        startVector.x - length * (Math.cos(theta) - Math.sin(thetaDelta)),
        0,
        startVector.z
    )
    
    return {
        path: [newVector],
        lastVector: newVector,
        theta: options.theta
    }
}

Thank you! Unfortunately this doesn’t solve my problem. With this code the tube align with the x-axis. I try to achieve that the tube can be create completely dynamically: e.g. a form like this https://playground.babylonjs.com/#MQJMAR#18

EDIT:

Finally I got it :slight_smile: It’s beautiful: https://playground.babylonjs.com/#MQJMAR#19

1 Like

Cool. I was going to say it’s all in the maths and vectors at that, but I didn’t have time to go over it fully.

:slight_smile:

I made some progress :slight_smile:

But I am struggling with the third dimension in terms of combining y with x and z. Since it gets more and more complicated for me it would be very helpful if someone of you has an idea how to improve the formulas.

The left and right function did work perfectly on the floor but after including y it is breaking.

https://playground.babylonjs.com/#9IL3XG#10