angular-three-soba/abstractions

December 31, 2025 ยท View on GitHub

This module provides abstract components and patterns for building reusable and composable 3D elements in Angular Three. It requires the following peer dependencies:

PackageDescription
troika-three-textRequired for using the NgtsText component.
three-mesh-bvhRequired for angular-three-soba/shaders

To install these dependencies, use one of the following commands:

npm install troika-three-text three-mesh-bvh
# yarn add troika-three-text three-mesh-bvh
# pnpm add troika-three-text three-mesh-bvh

TOC

NgtsBillboard

A component that rotates its contents to always face the camera (billboarding effect). Useful for sprites, labels, or any content that should always face the viewer.

Object Inputs (NgtsBillboardOptions)

PropertyDescriptionDefault Value
followWhether the billboard should follow (face) the camera.true
lockXLock rotation on the X axis, preventing the billboard from rotating around X.false
lockYLock rotation on the Y axis, preventing the billboard from rotating around Y.false
lockZLock rotation on the Z axis, preventing the billboard from rotating around Z.false
<ngts-billboard [options]="{ follow: true, lockY: true }">
	<ngt-mesh>
		<ngt-plane-geometry />
		<ngt-mesh-basic-material />
	</ngt-mesh>
</ngts-billboard>

NgtsRoundedBox

A component that renders a box with rounded edges. Creates smooth, beveled corners on all edges of the box.

Object Inputs (NgtsRoundedBoxOptions)

PropertyDescriptionDefault Value
widthWidth of the box (X-axis).1
heightHeight of the box (Y-axis).1
depthDepth of the box (Z-axis).1
radiusRadius of the rounded corners.0.05
smoothnessNumber of curve segments for corner smoothness.4
bevelSegmentsNumber of bevel segments.4
stepsNumber of extrusion steps.1
creaseAngleAngle threshold for creased normals calculation (radians).0.4
<ngts-rounded-box [options]="{ width: 2, height: 1, depth: 1, radius: 0.1 }">
	<ngt-mesh-standard-material color="orange" />
</ngts-rounded-box>

NgtsGrid

A y-up oriented, shader-based grid implementation.

This component renders a grid using a shader material, allowing for efficient rendering of large grids. It provides options to customize the appearance of the grid, such as cell size, cell thickness, cell color, section size, section thickness, section color, and more.

Object Inputs (NgtsGridOptions)

PropertyDescriptionDefault Value
planeArgsDefault plane-geometry arguments.[]
cellSizeCell size.0.5
cellThicknessCell thickness.0.5
cellColorCell color.'black'
sectionSizeSection size.1
sectionThicknessSection thickness.1
sectionColorSection color.'#2080ff'
infiniteGridDisplay the grid infinitely.false
followCameraFollow camera.false
fadeDistanceFade distance.100
fadeStrengthFade strength.1
fadeFromFade from camera (1) or origin (0), or somewhere in between.1
sideWhich side of the faces will be rendered. Can be THREE.FrontSide, THREE.BackSide, or THREE.DoubleSide.THREE.BackSide
<ngts-grid />

NgtsText

High-quality text rendering with signed distance fields (SDF) and antialiasing, using troika-three-text.

This component renders high-quality text using SDF and antialiasing techniques. It supports various options for customizing the appearance of the text, such as font, font size, color, alignment, and more.

Inputs

InputDescriptionRequired
textText content to render.Yes

Object Inputs (NgtsTextOptions)

PropertyDescriptionDefault Value
fontURL to the font file (supports .ttf, .otf, .woff).undefined
fontSizeFont size in world units.1
colorText color.undefined
fontWeightFont weight (numeric or string like 'bold').undefined
fontStyleFont style. Can be 'italic' or 'normal'.undefined
maxWidthMaximum width for text wrapping in world units.undefined
lineHeightLine height multiplier.undefined
letterSpacingLetter spacing in world units.undefined
textAlignText alignment. Can be 'left', 'right', 'center', or 'justify'.undefined
anchorXHorizontal anchor point. Can be 'left', 'center', 'right', or a number.'center'
anchorYVertical anchor point. Can be 'top', 'top-baseline', 'middle', 'bottom-baseline', 'bottom', or a number.'middle'
clipRectClipping rectangle [minX, minY, maxX, maxY].undefined
depthOffsetDepth offset for z-fighting prevention.undefined
directionText direction for bidirectional text. Can be 'auto', 'ltr', or 'rtl'.undefined
overflowWrapHow to handle text overflow and wrapping. Can be 'normal' or 'break-word'.undefined
whiteSpaceWhitespace handling mode. Can be 'normal', 'overflowWrap', or 'nowrap'.undefined
outlineWidthWidth of the text outline.undefined
outlineOffsetXHorizontal offset for the outline.undefined
outlineOffsetYVertical offset for the outline.undefined
outlineBlurBlur radius for the outline.undefined
outlineColorColor of the text outline.undefined
outlineOpacityOpacity of the text outline (0-1).undefined
strokeWidthWidth of the text stroke.undefined
strokeColorColor of the text stroke.undefined
strokeOpacityOpacity of the text stroke (0-1).undefined
fillOpacityOpacity of the text fill (0-1).undefined
sdfGlyphSizeSize of the SDF glyph texture. Higher values improve quality but use more memory.64
debugSDFEnable debug visualization of the SDF texture.undefined
charactersCharacters to pre-render for the font. Improves performance for known character sets.undefined
glyphGeometryDetailDetail level for glyph geometry.undefined

Outputs

OutputDescription
syncedEmitted when the text has been synced and is ready for rendering. Returns the Troika Text mesh instance.
<ngts-text text="Hello, World!" />

NgtsText3D

Renders 3D text using Three.js TextGeometry.

This component renders 3D text using TextGeometry. It requires fonts in JSON format generated through typeface.json.

Inputs

InputDescriptionRequired
fontFont source. Can be a URL to a typeface.json file or a preloaded font object.Yes
textText content to render as 3D geometry.Yes

Object Inputs (NgtsText3DOptions)

PropertyDescriptionDefault Value
sizeFont size.1
heightText extrusion height.0.2
curveSegmentsNumber of curve segments.8
bevelEnabledEnable bevel.false
bevelThicknessBevel thickness.0.1
bevelSizeBevel size.0.01
bevelOffsetBevel offset.0
bevelSegmentsNumber of bevel segments for smoother beveled edges.4
letterSpacingLetter spacing.0
lineHeightLine height multiplier.1
smoothThreshold for merging vertices to create smooth normals.undefined
<ngts-text-3d font="path/to/font.json" text="Hello, World!">
	<ngt-mesh-standard-material color="gold" />
</ngts-text-3d>

NgtsLine

Renders a THREE.Line2 or THREE.LineSegments2 (depending on the value of segments).

Inputs

InputDescriptionRequired
pointsArray of points. Accepts Vector3, Vector2, coordinate tuples, or flat numbers.Yes

Object Inputs (NgtsLineOptions)

PropertyDescriptionDefault Value
colorLine color.0xffffff
lineWidthLine width in pixels.1
segmentsWhether to render as THREE.LineSegments2 instead of THREE.Line2.false
dashedWhether the line is dashed.undefined
vertexColorsArray of colors for vertex coloring. Supports RGB or RGBA tuples.undefined
<ngts-line [points]="[[0, 0, 0], [1, 1, 1]]" />

NgtsQuadraticBezierLine

Renders a THREE.Line2 using THREE.QuadraticBezierCurve3 for interpolation.

Inputs

InputDescriptionDefault Value
startStarting point of the bezier curve.[0, 0, 0]
endEnding point of the bezier curve.[0, 0, 0]
midControl point. If not provided, automatically calculated.undefined

Object Inputs (NgtsQuadraticBezierLineOptions)

PropertyDescriptionDefault Value
segmentsNumber of segments to approximate the bezier curve.20
lineWidthLine width.1

Also accepts all NgtsLineOptions except segments (boolean).

<ngts-quadratic-bezier-line [start]="[0, 0, 0]" [end]="[1, 1, 1]" />

NgtsCubicBezierLine

Renders a THREE.Line2 using THREE.CubicBezierCurve3 for interpolation.

Inputs

InputDescriptionRequired
startStart point.Yes
endEnd point.Yes
midAFirst control point.Yes
midBSecond control point.Yes

Object Inputs (NgtsCubicBezierLineOptions)

PropertyDescriptionDefault Value
segmentsNumber of segments to divide the Bezier curve into.20
lineWidthLine width.1

Also accepts all NgtsLineOptions except segments (boolean).

<ngts-cubic-bezier-line [start]="[0, 0, 0]" [end]="[1, 1, 1]" [midA]="[0.5, 0.5, 0.5]" [midB]="[0.5, 0.5, 0.5]" />

NgtsCatmullRomLine

Renders a THREE.Line2 using THREE.CatmullRomCurve3 for interpolation.

Inputs

InputDescriptionRequired
pointsArray of points.Yes

Object Inputs (NgtsCatmullRomLineOptions)

PropertyDescriptionDefault Value
closedWhether the curve should be closed (connect end to start).false
curveTypeType of curve. Can be 'centripetal', 'chordal', or 'catmullrom'.'centripetal'
tensionTension parameter for the curve (0 to 1).0.5
segmentsNumber of segments to divide the curve into for rendering.20
lineWidthLine width.1

Also accepts all NgtsLineOptions except segments (boolean).

<ngts-catmull-rom-line [points]="[[0, 0, 0], [1, 1, 1]]" />

NgtsEdges

Abstracts THREE.EdgesGeometry. It pulls the geometry automatically from its parent, optionally you can ungroup it and give it a geometry prop. You can give it children, for instance a custom material. NgtsEdges is based on NgtsLine and supports all of its options.

Object Inputs (NgtsEdgesOptions)

PropertyDescriptionDefault Value
geometryGeometry to use for the edges. If not provided, uses parent geometry.undefined
thresholdAngle threshold in degrees for edge detection.15
lineWidthWidth of the edge lines.1

Also accepts all NgtsLineOptions.

<ngt-mesh>
	<ngt-box-geometry />
	<ngt-mesh-basic-material />
	<ngts-edges [options]="{ threshold: 15, scale: 1.1, color: 'white', lineWidth: 4 }" />
</ngt-mesh>

NgtsPrismGeometry

Abstracts THREE.ExtrudeGeometry to create a prism geometry.

Inputs

InputDescriptionRequired
verticesArray of 2D vertices defining the base shape.Yes
attachDefines how the geometry attaches to its parent.No

Object Inputs (NgtsPrismGeometryOptions)

PropertyDescriptionDefault Value
heightHeight of the prism extrusion.1
bevelEnabledEnable bevel.false

Also accepts all THREE.ExtrudeGeometryOptions except depth.

<ngt-mesh>
	<ngts-prism-geometry [vertices]="[[0, 0], [1, 0], [1, 1], [0, 1]]" />
	<ngt-mesh-basic-material />
</ngt-mesh>

NgtsGradientTexture

A declarative THREE.Texture which attaches to "map" by default. You can use this to create gradient backgrounds.

Inputs

InputDescriptionRequired
stopsGradient stops array.Yes
colorsGradient colors array. Must be the same size as stopsYes
attachDefines how the texture attaches to its parent.No

Object Inputs (NgtsGradientTextureOptions)

PropertyDescriptionDefault Value
typeGradient type. Can be 'linear' or 'radial'.'linear'
sizeHeight of the gradient texture canvas in pixels.1024
widthWidth of the gradient texture canvas in pixels.16
innerCircleRadiusInner circle radius for radial gradients.0
outerCircleRadiusOuter circle radius for radial gradients.'auto'
<ngt-mesh-basic-material>
	<ngts-gradient-texture [stops]="[0, 0.5, 1]" [colors]="['red', 'green', 'blue']" />
</ngt-mesh-basic-material>

helper

A function to add helpers to existing nodes in the scene. It handles removal of the helper on destroy and auto-updates it by default.

class MyCmp {
	mesh = viewChild.required<ElementRef<Mesh>>('mesh');
	boxHelper = helper(this.mesh, () => BoxHelper, { args: () => ['cyan'] });
}

Note: injectHelper is deprecated. Use helper instead.

NgtsHelper

A declarative way to add helpers to existing nodes in the scene. It handles removal of the helper on destroy and auto-updates it by default.

<ngt-mesh>
	<ngts-helper [type]="BoxHelper" [options]="['cyan']" />
</ngt-mesh>