Tube won't update

I’m trying to create a path to a given location using a set of points using an updateable tube. I’m creating the tube skeleton in the createScene function like this:

        const myPath = [
            new BABYLON.Vector3(5.0, 0, 0.0),
            new BABYLON.Vector3(0, 1, 0.1),
            new BABYLON.Vector3(-4.0, 6, 0.2)
        ];

        tube = BABYLON.MeshBuilder.CreateTube("tube", {
            path: myPath,
            radius: 0.5,
            sideOrientation: BABYLON.Mesh.DOUBLESIDE,
            updatable: true,
            cap: 3,
        }, scene);

and then trying to update in a jquery event call late on like this:

            tube = BABYLON.MeshBuilder.CreateTube("tube", {
                path: testPoints,
                instance: tube,
            });

But it is now giving me an error saying that babylon.js:16 Uncaught TypeError: Cannot set property ‘x’ of undefined.

I’m sure I’m doing something stupid but I can’t seem to figure it out. Any help would be greatly appreciated.

It does work here, so you will need to provide your own PG for us to be able to help.

One guess: tube you pass to the property instance is undefined. Try console.log(tube); before the call.

1 Like

https://playground.babylonjs.com/#CIQ9IX#1

Try this one. I tried just changing position.x of tube in place of the rebuild earlier and that worked fine so I can’t see how tube could be undefined. I also tried using both testPoints and routeCurve.getPoints(). Both gave the same error.

You can’t change the number of elements of the path array, only the values.

See doc:

All the parametric shapes, except for the CreateLathe, CreatePolygon and ExtrudePolygon have an *instance* property in the options. This is used to update the shape after creation provided its *updatable* options property was set to *true* . You can only change values in the shape defining data arrays not the size of the arrays.

2 Likes

Ah! I missed that in the docs. Thanks.

Would it better then to create and destroy a tube everytime I need change it or rather just to create all the tubes I’d need at the start?

If you have a fixed number of tubes then creating them from start will yield the best results.

Awesome. Thanks so much for the help!