next: text: ‘GLTF Fat/Mesh Lines’ link: ‘./gltf-mesh-lines’
prev: false
This example shows how to use ThreePipe’s fat lines (MeshLine) to draw a thick, colorful spiral. The spiral’s shape and color are generated in code, and you can adjust its parameters live using the UI.
How it works:
MeshLine (an extension of three.js Line2) is used to make the line thick and support per-vertex colors.Key code:
function makeSpiral(radius = 1, height = 2, loops = 10) {
const positions = [], colors = []
for (let i = 0; i <= 1000; i++) {
const t = i / 1000, angle = t * Math.PI * 2 * loops
positions.push(radius * Math.cos(angle), radius * Math.sin(angle), t * height - height/2)
colors.push(t, 0, 1-t)
}
return {positions, colors}
}
const line = new MeshLine(new LineGeometry2(), new LineMaterial2())
line.material.vertexColors = true
line.material.linewidth = 5
function updateSpiral() {
const {positions, colors} = makeSpiral(spiral.radius, spiral.height, spiral.loops)
line.geometry.setPositions(positions)
line.geometry.setColors(colors)
line.material.setDirty()
}
The line and its controls are added to the UI with Tweakpane:
ui.appendChild({
type: 'folder',
label: 'Spiral',
children: generateUiConfig(spiral),
onChange: updateSpiral,
})
ui.appendChild(line.uiConfig)
Line directly (for now).
:::MeshLineThreePipe’s MeshLine is built on top of the three.js Line2 addon. Instead of drawing a single-pixel line, it creates a mesh strip along the path, allowing for thick, anti-aliased lines. The geometry stores positions and colors, and the material handles width, color, and other effects. This approach works in all modern browsers and supports advanced features like dashes and transparency.
MeshLineUse fat lines when you need:
For simple, single-pixel lines, the default three.js Line is still fastest, but for anything more advanced, MeshLine is the way to go.
When importing glTF files with embedded line geometries and materials, GLTFLoader2.UseMeshLines feature can be used to automatically convert those lines to MeshLine instances. This allows you to take advantage of the advanced line rendering capabilities without needing to modify the original GLTF files.
Checkout the article on GLTF Mesh Lines for more details on how to use this feature.