Uzay

Lines

3D line segments

What is a Line3D?

A Line3D renders as a line segment between two 3D points. Lines are useful for:

  • Connecting points
  • Visualizing vectors
  • Drawing edges of shapes
  • Construction lines

Basic Usage

const line = scene.create("line3d", {
  start: vec3(0, 0, 0),
  end: vec3(5, 3, 2),
  color: "cyan",
  thickness: 1,
});

Styling Lines

Color

Any CSS color string:

scene.create("line3d", {
  start: vec3(0, 0, 0),
  end: vec3(1, 0, 0),
  color: "red",
});

Thickness

Control the line width:

scene.create("line3d", {
  start: vec3(0, 0, 0),
  end: vec3(1, 0, 0),
  thickness: 0.5, // Thin
});

scene.create("line3d", {
  start: vec3(0, 1, 0),
  end: vec3(1, 1, 0),
  thickness: 2, // Thick
});

Examples

Connecting Two Points

Pass point atoms directly as line endpoints:

const p1 = scene.create("point3d", { coords: vec3(0, 0, 0), color: "red" });
const p2 = scene.create("point3d", { coords: vec3(3, 3, 3), color: "blue" });

scene.create("line3d", {
  start: p1.coords,
  end: p2.coords,
  color: "white",
  thickness: 0.5,
});

Drag either point and the line follows.

Line with Length Label

const p1 = scene.create("point3d", { coords: vec3(0, 0, 0), color: "red" });
const p2 = scene.create("point3d", { coords: vec3(3, 2, 1), color: "blue" });

scene.create("line3d", {
  start: p1.coords,
  end: p2.coords,
  color: "white",
});

// Label at the midpoint showing the line's length
const midpoint = scene.atom((get) => {
  const start = get(p1.coords);
  const end = get(p2.coords);
  return vec3((start.x + end.x) / 2, (start.y + end.y) / 2, (start.z + end.z) / 2);
});

scene.create("overlay3d", {
  position: midpoint,
  content: scene.atom((get) => {
    const diff = Vec3.subtract(get(p2.coords), get(p1.coords));
    return `d = ${Vec3.length(diff).toFixed(2)}`;
  }),
  anchor: "bottom-left",
  offset: vec2(6, -6),
});

Updating Properties

const line = scene.create("line3d", {
  start: vec3(0, 0, 0),
  end: vec3(1, 1, 1),
  color: "white",
});

// Update endpoints
line.start.set(vec3(-1, -1, -1));
line.end.set(vec3(2, 2, 2));

// Update styling
line.color.set("pink");
line.thickness.set(2);

API Reference

Options

PropertyTypeDefaultDescription
startVec3{ x: 0, y: 0, z: 0 }Starting point
endVec3{ x: 0, y: 0, z: 0 }Ending point
colorstring"white"CSS color string
thicknessnumber1Line width
visiblebooleantrueWhether the line is shown
pointerEvents"auto" | "none""auto"Whether the line receives pointer events
tagsstring[][]Custom tags for grouping

Returned Item

FieldTypeDescription
idstringUnique identifier
startBoundAtom<Vec3>Start point atom
endBoundAtom<Vec3>End point atom
colorBoundAtom<string>Color atom
thicknessBoundAtom<number>Thickness atom
visibleBoundAtom<boolean>Visibility atom
pointerEventsBoundAtom<string>Pointer events atom
tagsBoundAtom<string[]>Tags atom

On this page