Skip to content

helper

helper is 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.

injectHelper is deprecated. Use helper instead.

Usage

import { helper } from 'angular-three-soba/abstractions';
import { BoxHelper, PointLightHelper } from 'three';
@Component({
selector: 'app-scene',
template: `
<ngt-mesh #mesh>
<ngt-box-geometry />
<ngt-mesh-standard-material />
</ngt-mesh>
`,
})
export class Scene {
mesh = viewChild.required<ElementRef<Mesh>>('mesh');
boxHelper = helper(this.mesh, () => BoxHelper, {
args: () => ['cyan'],
});
}

Options

PropertyTypeDescriptionDefault
args() => ConstructorParameters<Helper>Signal of constructor arguments to pass to the helper.[]
updatebooleanWhether to automatically update the helper each frame.true

With PointLightHelper

@Component({
selector: 'app-scene',
template: `
<ngt-point-light #light [position]="[5, 5, 5]" />
`,
})
export class Scene {
light = viewChild.required<ElementRef<PointLight>>('light');
lightHelper = helper(this.light, () => PointLightHelper, {
args: () => [1, 'yellow'],
});
}

With DirectionalLightHelper

@Component({
selector: 'app-scene',
template: `
<ngt-directional-light #light [position]="[10, 10, 10]" />
`,
})
export class Scene {
light = viewChild.required<ElementRef<DirectionalLight>>('light');
lightHelper = helper(this.light, () => DirectionalLightHelper, {
args: () => [5, 'red'],
});
}

Disabling Auto-Update

If you don’t need the helper to update every frame, set update: false:

boxHelper = helper(this.mesh, () => BoxHelper, {
args: () => ['cyan'],
update: false,
});

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.

Usage

import { NgtsHelper } from 'angular-three-soba/abstractions';
import { BoxHelper } from 'three';
<ngt-mesh>
<ngt-box-geometry />
<ngt-mesh-standard-material />
<ngts-helper [type]="BoxHelper" [options]="['cyan']" />
</ngt-mesh>

Inputs

InputTypeDescriptionRequired
typeType<Helper>The helper constructor type.Yes
optionsConstructorParameters<Helper>Constructor arguments to pass to the helper.No

With PointLightHelper

<ngt-point-light [position]="[5, 5, 5]">
<ngts-helper [type]="PointLightHelper" [options]="[1, 'yellow']" />
</ngt-point-light>

With CameraHelper

<ngt-perspective-camera [position]="[0, 5, 10]" #camera>
<ngts-helper [type]="CameraHelper" />
</ngt-perspective-camera>

Arguments

name type description required
target () => ElementRef<Object3D> | Object3D Signal containing the target object to attach the helper to. yes
helperType () => Type<Helper> Signal containing the helper constructor type (e.g., BoxHelper, PointLightHelper). yes
options Partial<NgtsHelperOptions<Helper>> Configuration options for the helper. no

Returns

typedescription
Signal<Helper | null>Signal containing the helper instance, or null if not yet created.