Uzay

Spheres

3D sphere items

What is a Sphere3D?

A Sphere3D renders as a sphere with a given center and radius. Spheres are useful for:

  • Representing volumes or regions in space
  • Visualizing bounding spheres
  • Drawing planets, atoms, or other round objects
  • Creating semi-transparent enclosures around other objects

Basic Usage

const sphere = scene.create("sphere3d", {
  center: vec3(0, 2, 0),
  radius: 1.5,
  color: "dodgerblue",
});

Styling Spheres

Color

Any CSS color string works:

scene.create("sphere3d", { center: vec3(0, 0, 0), color: "red" });
scene.create("sphere3d", { center: vec3(3, 0, 0), color: "#4ecdc4" });
scene.create("sphere3d", { center: vec3(6, 0, 0), color: "hsl(280, 80%, 60%)" });

Opacity

Spheres support transparency via the opacity property (0 = fully transparent, 1 = fully opaque):

scene.create("sphere3d", {
  center: vec3(0, 0, 0),
  radius: 2,
  color: "cyan",
  opacity: 0.3, // Semi-transparent
});

This is great for showing a region without hiding the objects inside it.

Multiple transparent items that overlap can cause rendering artifacts where one hides the other. If you need overlapping items, keep at most one of them transparent.

Size

The radius property sets the sphere's size in world units:

scene.create("sphere3d", { center: vec3(0, 0, 0), radius: 0.5 }); // Small
scene.create("sphere3d", { center: vec3(3, 0, 0), radius: 1 });   // Medium
scene.create("sphere3d", { center: vec3(6, 0, 0), radius: 2 });   // Large

Interactive Spheres

Click to Change Color

Toggle the sphere's color each time it's clicked:

const colors = ["tomato", "dodgerblue", "gold", "mediumseagreen"];
let index = 0;

const sphere = scene.create("sphere3d", {
  center: vec3(0, 1, 0),
  radius: 1.5,
  color: colors[0],
});

sphere.on("click", () => {
  index = (index + 1) % colors.length;
  sphere.color.set(colors[index]);
});

Hover to Highlight

Change the sphere's opacity when the pointer enters and leaves:

const sphere = scene.create("sphere3d", {
  center: vec3(0, 1, 0),
  radius: 1.5,
  color: "dodgerblue",
  opacity: 0.4,
});

sphere.on("hover", (event) => {
  if (event.phase === "enter") {
    sphere.opacity.set(0.8);
  } else if (event.phase === "leave") {
    sphere.opacity.set(0.4);
  }
});

Updating Properties

const sphere = scene.create("sphere3d", {
  center: vec3(0, 0, 0),
  radius: 1,
  color: "white",
});

// Update properties
sphere.center.set(vec3(2, 2, 2));
sphere.radius.set(3);
sphere.color.set("purple");
sphere.opacity.set(0.5);

API Reference

Options

PropertyTypeDefaultDescription
centerVec3{ x: 0, y: 0, z: 0 }Center position in 3D space
radiusnumber1Sphere radius in world units
colorstring"white"CSS color string
opacitynumber1Opacity (0 to 1)
visiblebooleantrueWhether the sphere is shown
pointerEvents"auto" | "none""auto"Whether the sphere receives pointer events
tagsstring[][]Custom tags for grouping

Returned Item

FieldTypeDescription
idstringUnique identifier
centerBoundAtom<Vec3>Center position atom
radiusBoundAtom<number>Radius atom
colorBoundAtom<string>Color atom
opacityBoundAtom<number>Opacity atom
visibleBoundAtom<boolean>Visibility atom
pointerEventsBoundAtom<string>Pointer events atom
tagsBoundAtom<string[]>Tags atom

On this page