import { AfterViewInit , Component , ElementRef , OnDestroy , OnInit , ViewChild } from '@angular/core' ; import { Globals } from '../../shared/globals' ; import { Router } from '@angular/router' ; import { GlobalEventsService } from '../../shared/global-events.service' ; import { Subscription } from 'rxjs' ; import { BabylonViewer } from '../../shared/3d/BabylonViewer' ; @ Component ( { selector : 'app-babylon' , templateUrl : './babylon.component.html' , styleUrls : [ './babylon.component.scss' ] } ) export class BabylonComponent implements OnInit , AfterViewInit , OnDestroy { @ ViewChild ( 'renderCanvas' , { static : true } ) canvas ! : ElementRef < HTMLCanvasElement > ; private sub : Subscription ; private viewer : BabylonViewer ; loading = false ; constructor ( private router , private globalEvents ) { this . sub = globalEvents . babylonLoading . subscribe ( val => this . loading = val ) ; this . viewer = new BabylonViewer ( globalEvents ) ; } ngOnInit ( ) { if ( ! Globals . scene . cameras ) { this . router . navigate ( [ '/' ] ) ; return ; } this . globalEvents . babylonLoading . next ( true ) ; this . globalEvents . is3D . next ( true ) ; } ngAfterViewInit ( ) { if ( Globals . scene . cameras ) { setTimeout ( async ( ) => { await this . viewer . init ( this . canvas . nativeElement ) ; } , 0 ) ; } } ngOnDestroy ( ) { this . viewer . onDestroy ( ) ; this . sub . unsubscribe ( ) ; this . globalEvents . is3D . next ( false ) ; } }