Getting Started

Meshes & Primitives

Create built-in geometry, control its appearance, address it by tag, author custom topology, and merge repeated objects into efficient scene meshes.

Updated Publisher Alien_AlgorithmsPine Script v6

Ready-made primitives

Geometry factoriespine
p3d.Mesh box = p3d.cube(40.0, color.orange)
p3d.Mesh brick = p3d.cuboid(18.0, 14.0, 10.0, color.red)
p3d.Mesh ball = p3d.sphere(50.0, 16, 12, color.aqua)
p3d.Mesh tube = p3d.cylinder(20.0, 60.0, 12, color.lime)
p3d.Mesh donut = p3d.torus(40.0, 12.0, 24, 12, color.fuchsia)
p3d.Mesh tip = p3d.pyramid(30.0, 50.0, color.yellow)
p3d.Mesh floor = p3d.plane(200.0, 200.0, color.gray)
p3d.Mesh ringFlat = p3d.circle(30.0, 48, color.blue)

Additional factories include grid(), disc(), surface(), bars3D(), and trail3D().

Appearance

Chain appearance methodspine
box := box
  .setColor(color.new(color.orange, 20))
  .setStyle("wireframe")
  .setTag("hero")

box.lineWidth := 3
box.lineStyle := line.style_dashed
ControlPurpose
setColor()Sets a base color for all faces.
setFaceColor()Overrides one face color.
setStyle()Chooses solid, wireframe, or front-facing wireframe display.
show() / hide()Toggles visibility without removing the mesh.
drawModeChooses linefill or legacy poly solid-face backend.
castShadowControls whether the mesh contributes to cast shadows.

Tag-based scene graph

Add, retrieve, target, removepine
scene.add(p3d.sphere(15, 10, 8, color.blue).setTag("planet"))

p3d.Mesh planet = scene.getMesh("planet")
if not na(planet)
    planet.rotateBy(0, 2, 0)

scene.lookAt("planet")
scene.remove("planet")
Keep tags unique across primitive types
Tag removal searches meshes, labels, lines, then polylines. The first match wins.

Custom meshes

Single trianglepine
array<p3d.Vec3> verts = array.from(
  p3d.vec3(-30, 0, 0),
  p3d.vec3(30, 0, 0),
  p3d.vec3(0, 50, 0))

array<p3d.Face> faces = array.new<p3d.Face>()
faces.push(p3d.Face.new(vi = array.from(0, 1, 2), col = color.orange))

p3d.Mesh tri = p3d.customMesh(verts, faces)
scene.add(tri)

Each face stores indices into the parent vertex array. Faces need at least three vertices and should be planar.

Merging meshes

mergeMeshes(meshes, tag, removeInterior) bakes source transforms and combines geometry.

  • Interior removal: coincident faces with opposing normals are removed when removeInterior = true.
  • Depth groups: repeated identical source topology preserves per-instance depth grouping.
  • Mixed topology: combining different vertex and face counts disables grouping.

Best use case

Voxel scenes, walls, grids of bars, and repeated primitives benefit most because hidden internal faces can be stripped before rendering.

Pine3D is a graphical rendering library for Pine Script. TradingView drawing, execution, and publication limits still apply. © Alien_Algorithms.