File

projects/atft/src/lib/actor/ux/text/text-actor.component.ts

Extends

EmptyComponent

Implements

AfterViewInit OnChanges OnDestroy

Metadata

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(rendererService: RendererService, parent: AbstractObject3D<any>, animationService: AnimationService)
Parameters :
Name Type Optional
rendererService RendererService No
parent AbstractObject3D<any> No
animationService AnimationService No

Inputs

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
name
Type : string
Default value : uuidv4()
Inherited from AbstractObject3D
rotateX
Type : number
Inherited from AbstractObject3D

Rotation in Euler angles (radians) with order X, Y, Z.

rotateY
Type : number
Inherited from AbstractObject3D
rotateZ
Type : number
Inherited from AbstractObject3D
scaleX
Type : number
Default value : 1
Inherited from AbstractObject3D
scaleY
Type : number
Default value : 1
Inherited from AbstractObject3D
scaleZ
Type : number
Default value : 1
Inherited from AbstractObject3D
translateX
Type : number
Inherited from AbstractObject3D

Translate the geometry. This is typically done as a one time operation, and not during a loop.

translateY
Type : number
Inherited from AbstractObject3D
translateZ
Type : number
Inherited from AbstractObject3D

Outputs

changed
Type : EventEmitter
Inherited from AbstractObject3D

Methods

Public done
done()
Returns : void
Public ngAfterViewInit
ngAfterViewInit()
Inherited from AbstractObject3D
Returns : void
Public ngOnChanges
ngOnChanges(changes: SimpleChanges)
Inherited from AbstractObject3D
Parameters :
Name Type Optional
changes SimpleChanges No
Returns : void
Public ngOnDestroy
ngOnDestroy()
Inherited from AbstractObject3D
Returns : void
Private randomInt
randomInt(min: number, max: number)
Parameters :
Name Type Optional
min number No
max number No
Returns : number
Public updateAnimation
updateAnimation()
Returns : void
Protected updateText
updateText()
Returns : void
Protected newObject3DInstance
newObject3DInstance()
Inherited from AbstractObject3D
Returns : THREE.Object3D
Public addChild
addChild(object: AbstractObject3D<any>)
Inherited from AbstractObject3D
Parameters :
Name Type Optional
object AbstractObject3D<any> No
Returns : void
Protected afterInit
afterInit()
Inherited from AbstractObject3D
Returns : void
Public applyRotation
applyRotation()
Inherited from AbstractObject3D
Returns : void
Public applyScale
applyScale()
Inherited from AbstractObject3D
Returns : void
Public applyTranslation
applyTranslation()
Inherited from AbstractObject3D
Returns : void
Public findByName
findByName(name: string)
Inherited from AbstractObject3D
Parameters :
Name Type Optional
name string No
Returns : any
Public getChildren
getChildren()
Inherited from AbstractObject3D
Public getObject
getObject()
Inherited from AbstractObject3D
Returns : T
Public ngOnInit
ngOnInit()
Inherited from AbstractObject3D
Returns : void
Protected recursionByName
recursionByName(currentNode: AbstractObject3D<any>, name: string)
Inherited from AbstractObject3D
Parameters :
Name Type Optional
currentNode AbstractObject3D<any> No
name string No
Returns : any
Public removeChild
removeChild(object: AbstractObject3D<any>)
Inherited from AbstractObject3D
Parameters :
Name Type Optional
object AbstractObject3D<any> No
Returns : void
Public removeChildByName
removeChildByName(name: string)
Inherited from AbstractObject3D
Parameters :
Name Type Optional
name string No
Returns : void
Public updateParent
updateParent()
Inherited from AbstractObject3D
Returns : void

Properties

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
Protected object
Type : T
Inherited from AbstractObject3D
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();
    }

  }


}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""