NgtsMeshDistortMaterial
import { ChangeDetectionStrategy, Component } from '@angular/core';import { SobaWrapper } from '@soba/wrapper.ts';import { NgtCanvas, provideNgtRenderer } from 'angular-three/dom';import { SceneGraph } from './scene-graph';
@Component({ selector: 'app-mesh-distort-material', template: ` <ngt-canvas [camera]="{ position: [0, 0, 3], fov: 50 }"> <app-soba-wrapper *canvasContent [grid]="false"> <app-scene-graph /> </app-soba-wrapper> </ngt-canvas> `, changeDetection: ChangeDetectionStrategy.OnPush, host: { class: 'mesh-distort-material-demo relative block h-full' }, imports: [NgtCanvas, SobaWrapper, SceneGraph],})export default class MeshDistortMaterial { static clientProviders = [provideNgtRenderer()];}import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';import { NgtArgs } from 'angular-three';import { NgtsMeshDistortMaterial } from 'angular-three-soba/materials';
@Component({ selector: 'app-scene-graph', template: ` <ngt-mesh> <ngt-icosahedron-geometry *args="[1, 4]" /> <ngts-mesh-distort-material [options]="{ color: '#f25042', speed: 2, distort: 0.5, radius: 1, }" /> </ngt-mesh> `, schemas: [CUSTOM_ELEMENTS_SCHEMA], changeDetection: ChangeDetectionStrategy.OnPush, imports: [NgtArgs, NgtsMeshDistortMaterial],})export class SceneGraph {}NgtsMeshDistortMaterial is a port of Drei’s MeshDistortMaterial that applies animated noise-based distortion to mesh surfaces. It extends THREE.MeshPhysicalMaterial with vertex displacement using simplex noise.
Usage
import { NgtsMeshDistortMaterial } from 'angular-three-soba/materials';<ngt-mesh> <ngt-sphere-geometry /> <ngts-mesh-distort-material [options]="{ speed: 2, factor: 0.5, color: 'hotpink' }" /></ngt-mesh>Advanced Example
@Component({ template: ` <ngt-mesh> <ngt-icosahedron-geometry *args="[1, 4]" /> <ngts-mesh-distort-material [options]="{ speed: 5, factor: 0.8, color: '#ff6b6b', roughness: 0, metalness: 0.8, clearcoat: 1 }" /> </ngt-mesh> `})export class DistortedSphere {}The distortion effect works best with geometries that have enough vertices for smooth deformation, such as spheres or icosahedrons with higher subdivisions.
Options
options input accepts any properties from THREE.MeshPhysicalMaterial in addition to the following:
Properties
| name | type | description |
|---|---|---|
| speed | number | Animation speed multiplier for the distortion. |
| factor | number | Distortion intensity factor. |