Hello!
Here is an example PG for widths but I do believe you must have seen it:
Here is the part of the docs which explains the widths
parameter:
https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param/greased_line#widths-and-widthdistribution
Back to your PG. You are using the lazy
parameter set to true
but you are creating only one instance so there is no need to use lazy mode. Lazy mode is intended to use when you add lines dynamically to a GreasedLine instance. Lazy mode doesn’t create the GPU buffers each time you add a line. When you call updateLazy
those buffers are created. It’s much more performant when you are adding a lot of lines this way.
So for example you can have some input data which you loop through and add lines one by one to a GreasedLine instance.
There is a for loop which calls CreateGreasesLine
in instance and lazy mode in this example PG:
So in your PG you need to define all widths for all your lines.
// 3 lines
points = [
[-2, 0, 2, 2, 0, 2],
[-2, 0, 1, 2, 0, 1],
[-2, 0, 0, 2, 0, 0],
]
// 3 lines - for each line point you can define an upperWidth and lowerWidth
widths = [
0, 0, 1, 1,
1, 1, 2, 2,
1, 1, 0, 0
]
This results in:
This works in camera facing mode BUT when you use ribbonOptions
(which sets the line into non camera facing mode - basically it creates a regular ribbon like mesh) as you did in your PG there seems to be an issue and it seems it applies the same widths to all lines.
widths = [
0.5, 0.5, 1, 1,
2, 2, 0, 0,
0, 0, 2, 2,
]
var instance;
instance = BABYLON.CreateGreasedLine("lines", {
points,
widths,
ribbonOptions: {
directions: BABYLON.Vector3.Backward()
}
}, { width: 0.5, color: BABYLON.Color3.Black() }, scene)
Result (the 3 lines are the same and that’s an issue):
I’ll check the bug ASAP.
However there is a workaround for now. You can set the ribbonOptions.directions
as an Vector3[]
so you can have different widths just by multiplying the desired direction vector (this solution unfortunatelly doesn’t allow to have different width at the start and different width at the end of the line):
widths = [
0.5,
1,
2
]
var instance;
instance = BABYLON.CreateGreasedLine("lines", {
points,
ribbonOptions: {
directions: widths.map(w => BABYLON.Vector3.Backward().multiplyByFloats(w, w, w)),
}
}, { width: 0.5, color: BABYLON.Color3.Black() }, scene)
Result:
I’ll let you know when there will be a fix available.