Skip to content

NgtsDecal

NgtsDecal is an abstraction around THREE.js DecalGeometry. It projects textures onto mesh surfaces for effects like stickers, logos, or damage marks.

The decal box must intersect the surface to be visible. If you don’t specify a rotation, it will orient toward the parent’s center point.

Usage

With Custom Material

<ngt-mesh>
<ngt-sphere-geometry />
<ngt-mesh-basic-material />
<ngts-decal [options]="{ position: [0, 0, 0], rotation: [0, 0, 0], scale: 1, debug: true }">
<ngt-mesh-basic-material [map]="texture()" [polygonOffset]="true" [polygonOffsetFactor]="-1" />
</ngts-decal>
</ngt-mesh>

With Default Material

If you don’t specify a material, a transparent MeshBasicMaterial with polygonOffsetFactor: -10 is created automatically:

<ngt-mesh>
<ngt-sphere-geometry />
<ngt-mesh-basic-material />
<ngts-decal [options]="{ map: texture() }" />
</ngt-mesh>

With External Mesh Reference

<ngts-decal [mesh]="meshRef()" [options]="{ map: texture() }">
<ngt-mesh-basic-material [map]="texture()" [polygonOffset]="true" [polygonOffsetFactor]="-1" />
</ngts-decal>

Options

Properties

name type description
map THREE.Texture The texture to use for the decal
position [number, number, number] Position of the decal. Default: [0, 0, 0]
rotation [number, number, number] | number Rotation of the decal. A single number spins around the normal
scale number | [number, number, number] Scale of the decal. Default: 1
debug boolean Makes the bounding box of the decal visible. Default: false
depthTest boolean Whether to enable depth testing. Default: false
polygonOffsetFactor number The factor by which the polygon offset is multiplied. Default: -10

Abstraction around THREE.js DecalGeometry. Projects textures onto mesh surfaces for effects like stickers, logos, or damage marks.

The decal box must intersect the surface to be visible. If you don’t specify a rotation, it will orient toward the parent’s center point. You can also pass a single number as the rotation to spin the decal.

<ngt-mesh>
<ngt-sphere-geometry />
<ngt-mesh-basic-material />
<ngts-decal [options]="{ position: [0, 0, 0], rotation: [0, 0, 0], scale: 1, debug: true }">
<ngt-mesh-basic-material [map]="texture()" [polygonOffset]="true" [polygonOffsetFactor]="-1" />
</ngts-decal>
</ngt-mesh>

If you don’t specify a material, a transparent MeshBasicMaterial with polygonOffsetFactor: -10 is created automatically:

<ngt-mesh>
<ngt-sphere-geometry />
<ngt-mesh-basic-material />
<ngts-decal [options]="{ map: texture() }" />
</ngt-mesh>

When declarative composition isn’t possible, use the mesh input:

<ngts-decal [mesh]="meshRef()" [options]="{ map: texture() }">
<ngt-mesh-basic-material [map]="texture()" [polygonOffset]="true" [polygonOffsetFactor]="-1" />
</ngts-decal>
PropertyDescriptionDefault
meshExternal mesh to attach the decal toParent
optionsDecal configuration object (see NgtsDecalOptions)-
PropertyDescriptionDefault
mapThe texture to use for the decalundefined
debugMakes the “bounding box” of the decal visiblefalse
depthTestWhether to enable depth testingfalse
polygonOffsetFactorThe factor by which the polygon offset is multiplied-10
positionPosition of the decal [x, y, z][0, 0, 0]
rotationRotation of the decal [x, y, z] or single number-
scaleScale of the decal (uniform or [x, y, z])1
@Component({
template: `
<ngt-mesh>
<ngt-capsule-geometry *args="[0.5, 1, 16, 32]" />
<ngt-mesh-standard-material color="white" />
<!-- Badge decal -->
<ngts-decal [options]="{ position: [0, 0.5, 0.5], scale: 0.3, map: badgeTexture() }" />
<!-- Number decal -->
<ngts-decal [options]="{ position: [0, -0.2, 0.5], scale: 0.2, map: numberTexture() }" />
</ngt-mesh>
`,
})
class Character {
badgeTexture = textureResource(() => 'badge.png');
numberTexture = textureResource(() => 'number.png');
}

Set debug: true to visualize the decal’s bounding box:

<ngts-decal [options]="{ debug: true, position: [0, 0, 1], scale: 0.5 }">
<ngt-mesh-basic-material color="red" />
</ngts-decal>