I’ve decided not to automatically set the widths if the number of the points changes when the setPoints function is used. setPoints was intended to use when you want to move the existing line points. If you move the lines each frame, updating the widths will generate unnecessary overhead and the setPointswill still doesn’t know anything about the the newly added lines widths.
You’ll have to update the widths manually if you change the number of points.
However I’ve added a new helper function GetPointsCount(points: number[][]): number which will count the number of points. You can pass this value into the CompleteGreasedLineWidthTable function which will create the missing entries:
https://doc.babylonjs.com/typedoc/modules/BABYLON#CompleteGreasedLineWidthTable
https://doc.babylonjs.com/typedoc/enums/BABYLON.GreasedLineMeshWidthDistribution
So your code will look like (sets the new lines upper and lower width to 2):
const pointsCount = BABYLON.GetPointsCount(myPoints);
line2.widths = BABYLON.CompleteGreasedLineWidthTable(
pointsCount,
line2.widths,
BABYLON.GreasedLineMeshWidthDistribution.WIDTH_DISTRIBUTION_START,
2,
2);
line2.addPoints(myPoints);
Or you can create the widths table manually according to your needs.