import { Component , Input , Optional , SkipSelf } from '@angular/core' ; import { MTLLoader } from 'three/examples/jsm/loaders/MTLLoader' ; import { RendererService } from '../../renderer/renderer.service' ; import { provideParent } from '../../util' ; import { AbstractObject3D } from '../abstract-object-3d' ; import { AbstractModelLoader } from './abstract-model-loader' ; import { ObjLoaderService } from './services/obj-loader.service' ; /**
 * Component for employing THREE.OBJLoader to load [Wavefront *.obj files][1].
 *
 * [1]: https://en.wikipedia.org/wiki/Wavefront_.obj_file
 */ @ Component ( { selector : 'atft-obj-loader' , providers : [ provideParent ( ObjLoaderComponent ) ] , template : '<ng-content></ng-content>' } ) export class ObjLoaderComponent extends AbstractModelLoader { private mtlLoader = new MTLLoader ( ) ; @ Input ( ) material : string ; deprecated @ Input ( ) public set texturePath ( newTexturePath ) { this . resourcePath = newTexturePath ; } /**
     * Path relative to which resources and textures within the loaded obj file are loaded.
     */ @ Input ( ) resourcePath : string ; constructor ( protected rendererService , @ SkipSelf ( ) @ Optional ( ) protected parent , protected objLoader ) { super ( rendererService , parent ) ; } protected async loadLazyObject ( ) { if ( this . material ) { const preloadingStep = new Promise < void > ( ( resolve , reject ) => { ( this . mtlLoader as any ) . setResourcePath ( this . resourcePath ) ; this . mtlLoader . load ( this . material , materialCreator => { materialCreator . preload ( ) ; this . objLoader . setMaterials ( materialCreator ) ; resolve ( ) ; } , undefined , reject ) ; } ) ; await preloadingStep ; } const obj = await this . objLoader . load ( this . model ) ; return obj . clone ( ) ; } }