API

Creating Lines

Lines

Lines are created as a contiguous series of attached line segments from a list of points. You must set at least the points option. On update, you must set the points and instance options. You can also update the colors option if previously set at construction time.

MeshBuilder

Usage:

import { MeshBuilder } from "@babylonjs/core/Meshes/meshBuilder";
const options = {
points: myPoints, //vec3 array,
updatable: true,
};
let lines = MeshBuilder.CreateLines("lines", options, scene); //scene is optional and defaults to the current scene
// Update
options.points[0].x += 6;
options.instance = lines;
lines = MeshBuilder.CreateLines("lines", options); //No scene parameter when using instance
optionvaluedefault value
points
(Vector3[]) array of Vector3, the path of the line REQUIRED
 
updatable
(boolean) true if the mesh is updatable
false
instance
(LineMesh) an instance of a line mesh to be updated
null
colors
(Color4[]) array of Color4, each point color
null
useVertexAlpha
(boolean) false if the alpha blending is not required (faster)
true

Unlike a mesh, lines are colored after creation with a color property rather than a material.

import { Color3 } from "@babylonjs/core/Maths/math.color";
lines.color = new Color3(1, 0, 0);

Examples

non updatable lines: Create Non Updatable Lines non updatable closed lines: Create Non Updatable Closed Lines updatable example: Create Updatable Closed Lines updatable spiral: Create Updatable Spiral Lines

Multi-colored lines have to be set at creation. Create Multi Colored Lines

Mesh

usage:

import { MeshBuilder } from "@babylonjs/core/Meshes/meshBuilder";
let lines = MeshBuilder.CreateLines("lines", { points }, scene);
let lines = MeshBuilder.CreateLines("lines", { points, updatable, instance }, scene);