Skip to content

NgtsHTML

NgtsHTML renders HTML content positioned in 3D space. It creates a THREE.Group anchor point in the scene and projects HTML onto the canvas using CSS positioning or CSS 3D transforms.

Usage

import { NgtsHTML } from 'angular-three-soba/misc';
@Component({
imports: [NgtsHTML],
template: `
<ngt-mesh [position]="[0, 2, 0]">
<ngts-html [options]="{ transform: true }">
<div [htmlContent]="{ distanceFactor: 10 }">Label</div>
</ngts-html>
</ngt-mesh>
`
})
class MyComponent {}

NgtsHTMLContentOptions (for div[htmlContent])

PropertyDescriptionDefault
distanceFactorScales HTML based on distance from cameraundefined
centerCenters the HTML element on the projected pointfalse
spriteWhen true (with transform), HTML always faces the camerafalse
zIndexRangeRange for automatic z-index calculation [max, min][16777271, 0]
containerClassCSS class applied to the inner container div''
containerStyleInline styles applied to the inner container div{}
pointerEventsCSS pointer-events value'auto'

Outputs

OutputDescription
occludedEmits when occlusion state changes (true = hidden, false = visible)

Options

Properties

name type description
occlude boolean | 'raycast' | 'blending' | Object3D[] Controls occlusion behavior. Default: false
transform boolean When true, uses CSS 3D transforms. When false, projects to 2D screen coordinates. Default: false
castShadow boolean Forward shadow casting to occlusion mesh (blending mode only). Default: false
receiveShadow boolean Forward shadow receiving to occlusion mesh (blending mode only). Default: false

A component for rendering HTML content positioned in 3D space. Creates a THREE.Group anchor point in the scene and projects HTML onto the canvas using CSS positioning or CSS 3D transforms.

Import NgtsHTML which includes both NgtsHTMLImpl (the 3D anchor) and NgtsHTMLContent (the HTML container).

import { NgtsHTML } from 'angular-three-soba/misc';
@Component({
imports: [NgtsHTML],
template: `
<ngt-mesh [position]="[0, 2, 0]">
<ngts-html [options]="{ transform: true }">
<div [htmlContent]="{ distanceFactor: 10 }">Label</div>
</ngts-html>
</ngt-mesh>
`,
})
class MyComponent {}
PropertyDescriptionDefault
occludeControls occlusion: false, true, 'raycast', 'blending', or array of Object3D refsfalse
transformWhen true, uses CSS 3D transforms. When false, projects to 2D screen coordinatesfalse
castShadowForward shadow casting to occlusion mesh (blending mode only)false
receiveShadowForward shadow receiving to occlusion mesh (blending mode only)false

NgtsHTMLContentOptions (for div[htmlContent])

Section titled “NgtsHTMLContentOptions (for div[htmlContent])”
PropertyDescriptionDefault
epsEpsilon for position/zoom change detection0.001
zIndexRangeRange for automatic z-index calculation [max, min][16777271, 0]
centerCenters the HTML element on the projected pointfalse
prependPrepends to parent instead of appendingfalse
fullscreenMakes the container fill the entire canvas sizefalse
containerClassCSS class applied to the inner container div''
containerStyleInline styles applied to the inner container div{}
pointerEventsCSS pointer-events value'auto'
calculatePositionCustom function to calculate screen positiondefaultCalculatePosition
spriteWhen true (with transform), HTML always faces the camerafalse
distanceFactorScales HTML based on distance from cameraundefined
parentCustom parent element for the HTML contentundefined
OutputDescription
occludedEmits when occlusion state changes (true = hidden, false = visible)
<ngt-mesh [position]="[0, 1, 0]">
<ngt-box-geometry />
<ngt-mesh-standard-material />
<ngts-html>
<div [htmlContent]="{ center: true }">
<span class="label">Hello World</span>
</div>
</ngts-html>
</ngt-mesh>
<ngts-html [options]="{ transform: true }">
<div [htmlContent]="{ distanceFactor: 10, sprite: true }">
<div class="card">
<h2>Title</h2>
<p>Description text</p>
</div>
</div>
</ngts-html>
<ngts-html [options]="{ occlude: true }">
<div [htmlContent]="{}" (occluded)="isHidden = $event" [class.faded]="isHidden">
Content with custom occlusion handling
</div>
</ngts-html>
<ngts-html [options]="{ occlude: [wallRef(), floorRef()] }">
<div [htmlContent]="{}">Hidden when wall or floor blocks view</div>
</ngts-html>
<ngts-html>
<div [htmlContent]="{ fullscreen: true, pointerEvents: 'none' }">
<div class="hud">
<div class="score">Score: 100</div>
</div>
</div>
</ngts-html>
const customCalculatePosition = (el, camera, size) => {
// Custom positioning logic
return [x, y];
};
<ngts-html>
<div [htmlContent]="{ calculatePosition: customCalculatePosition }">Custom positioned content</div>
</ngts-html>