projects/atft/src/lib/actor/ux/text/text-actor.component.ts
AfterViewInit
OnChanges
OnDestroy
providers |
provideParent(TextActorComponent)
|
selector | atft-text-actor |
template |
|
Properties |
|
Methods |
|
Inputs |
Outputs |
constructor(rendererService: RendererService, parent: AbstractObject3D<any>, animationService: AnimationService)
|
||||||||||||
Parameters :
|
animate | |
Type : boolean
|
|
Default value : false
|
|
materialColor | |
Type : string | number
|
|
Default value : '#5DADE2'
|
|
maxDelay | |
Type : number
|
|
Default value : 10
|
|
minDelay | |
Type : number
|
|
Default value : 5
|
|
text | |
Type : string
|
|
layer | |
Type : number
|
|
Default value : 0
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:42
|
name | |
Type : string
|
|
Default value : uuidv4()
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:40
|
rotateX | |
Type : number
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:24
|
|
Rotation in Euler angles (radians) with order X, Y, Z. |
rotateY | |
Type : number
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:25
|
rotateZ | |
Type : number
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:26
|
scaleX | |
Type : number
|
|
Default value : 1
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:36
|
scaleY | |
Type : number
|
|
Default value : 1
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:37
|
scaleZ | |
Type : number
|
|
Default value : 1
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:38
|
translateX | |
Type : number
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:31
|
|
Translate the geometry. This is typically done as a one time operation, and not during a loop. |
translateY | |
Type : number
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:32
|
translateZ | |
Type : number
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:33
|
changed | |
Type : EventEmitter
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:44
|
Public done |
done()
|
Returns :
void
|
Public ngAfterViewInit |
ngAfterViewInit()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:51
|
Returns :
void
|
Public ngOnChanges | ||||||
ngOnChanges(changes: SimpleChanges)
|
||||||
Inherited from
AbstractObject3D
|
||||||
Defined in
AbstractObject3D:119
|
||||||
Parameters :
Returns :
void
|
Public ngOnDestroy |
ngOnDestroy()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:80
|
Returns :
void
|
Private randomInt |
randomInt(min: number, max: number)
|
Returns :
number
|
Public updateAnimation |
updateAnimation()
|
Returns :
void
|
Protected updateText |
updateText()
|
Returns :
void
|
Protected newObject3DInstance |
newObject3DInstance()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:21
|
Returns :
THREE.Object3D
|
Public addChild | ||||||
addChild(object: AbstractObject3D<any>)
|
||||||
Inherited from
AbstractObject3D
|
||||||
Defined in
AbstractObject3D:143
|
||||||
Parameters :
Returns :
void
|
Protected afterInit |
afterInit()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:156
|
Returns :
void
|
Public applyRotation |
applyRotation()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:118
|
Returns :
void
|
Public applyScale |
applyScale()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:135
|
Returns :
void
|
Public applyTranslation |
applyTranslation()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:127
|
Returns :
void
|
Public findByName | ||||||
findByName(name: string)
|
||||||
Inherited from
AbstractObject3D
|
||||||
Defined in
AbstractObject3D:185
|
||||||
Parameters :
Returns :
any
|
Public getChildren |
getChildren()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:202
|
Returns :
Array<AbstractObject3D<any>>
|
Public getObject |
getObject()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:175
|
Returns :
T
|
Public ngOnInit |
ngOnInit()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:97
|
Returns :
void
|
Protected recursionByName | |||||||||
recursionByName(currentNode: AbstractObject3D<any>, name: string)
|
|||||||||
Inherited from
AbstractObject3D
|
|||||||||
Defined in
AbstractObject3D:192
|
|||||||||
Parameters :
Returns :
any
|
Public removeChild | ||||||
removeChild(object: AbstractObject3D<any>)
|
||||||
Inherited from
AbstractObject3D
|
||||||
Defined in
AbstractObject3D:160
|
||||||
Parameters :
Returns :
void
|
Public removeChildByName | ||||||
removeChildByName(name: string)
|
||||||
Inherited from
AbstractObject3D
|
||||||
Defined in
AbstractObject3D:206
|
||||||
Parameters :
Returns :
void
|
Public updateParent |
updateParent()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:111
|
Returns :
void
|
Protected animation |
Type : Subscription
|
Private currentDelay |
Type : number
|
Private currentPos |
Type : number
|
Default value : 0
|
Public currentText |
Type : string
|
Private i |
Type : number
|
Default value : 0
|
Private maxPos |
Type : number
|
Default value : 0
|
subscribed |
Default value : false
|
Protected childlren |
Type : Array<AbstractObject3D<any>>
|
Default value : []
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:46
|
Protected object |
Type : T
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:48
|
import {AfterViewInit, Component, Input, OnChanges, OnDestroy, Optional, SimpleChanges, SkipSelf} from '@angular/core';
import {provideParent} from '../../../util';
import {EmptyComponent} from '../../../object/helper';
import {AnimationService} from '../../../animation';
import {RendererService} from '../../../renderer';
import {AbstractObject3D} from '../../../object';
import {Subscription} from 'rxjs';
@Component({
selector: 'atft-text-actor',
providers: [provideParent(TextActorComponent)],
template: `
<atft-text-mesh [text]="currentText" [centered]="false" [materialColor]="materialColor">
</atft-text-mesh>
`
})
export class TextActorComponent extends EmptyComponent implements AfterViewInit, OnChanges, OnDestroy {
@Input()
text!: string;
@Input()
animate = false;
@Input()
materialColor: string | number = '#5DADE2';
@Input()
minDelay = 5;
@Input()
maxDelay = 10;
subscribed = false;
private currentDelay!: number;
public currentText!: string;
private currentPos = 0;
private maxPos = 0;
private i = 0;
protected animation!: Subscription;
constructor(
protected override rendererService: RendererService,
@SkipSelf() @Optional() protected override parent: AbstractObject3D<any>,
protected animationService: AnimationService
) {
super(rendererService, parent);
}
public override ngAfterViewInit() {
super.ngAfterViewInit();
// console.log('TextActorComponent.ngAfterViewInit');
this.updateText();
}
protected updateText() {
// console.log('TextActorComponent.updateText');
if (this.text && this.text.length > 0) {
// console.log('TextActorComponent.updateText', this.text);
if (this.animate) {
// console.log('TextActorComponent.animate init');
if (!this.subscribed) {
this.updateAnimation = this.updateAnimation.bind(this);
this.animation = this.animationService.animate.subscribe(this.updateAnimation);
this.subscribed = true;
this.animationService.start();
}
this.currentPos = 0;
this.maxPos = this.text.length;
this.currentText = '';
this.currentDelay = this.randomInt(this.minDelay, this.maxDelay);
} else {
this.currentText = this.text;
}
}
}
public override ngOnDestroy() {
// console.log('TextActorComponent.ngOnDestroy');
super.ngOnDestroy();
this.done();
}
public updateAnimation() {
if (this.subscribed) {
// console.log('TextActorComponent.updateAnimation');
this.i++;
if (this.i % this.currentDelay === 0) {
// console.log('TextActorComponent.updateAnimation: step');
this.currentPos++;
if (this.currentPos <= this.maxPos) {
this.currentText = this.text.substr(0, this.currentPos);
this.currentDelay = this.randomInt(this.minDelay, this.maxDelay);
// this.rendererService.render();
// console.log('TextActorComponent.updateAnimation: text', this.currentText);
} else {
this.done();
}
}
}
}
public done() {
if (this.subscribed) {
// console.log('TextActorComponent.done');
this.subscribed = false;
this.i = 0;
this.animation?.unsubscribe();
}
}
private randomInt(min: number, max: number): number {
return Math.round(Math.random() * (max - min) + min);
}
public override ngOnChanges(changes: SimpleChanges) {
// console.log('AbstractObject3D.ngOnChanges', this.name);
if (!this.object) {
return;
}
super.ngOnChanges(changes);
let modified = false;
if (['text'].some(propName => propName in changes)) {
this.updateText();
modified = true;
}
if (['animate'].some(propName => propName in changes)) {
if (this.animate) {
this.updateText();
} else {
this.done();
this.currentText = this.text;
}
modified = true;
}
if (modified) {
this.changed.emit();
this.rendererService.render();
}
}
}