import { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh.js' ; import { Nullable } from '@babylonjs/core/types.js' ; import { GUI3DManager } from '@babylonjs/gui/3D/gui3DManager.js' ; import { CreatedInstance } from '../CreatedInstance' ; import { Control3DCustomProps } from '../CustomProps' ; import BaseLifecycleListener from './BaseLifecycleListener' ; export default class GUI3DManagerLifecycleListener extends BaseLifecycleListener < GUI3DManager , any > { onMount ( instance ? ) { if ( instance === undefined ) { console . error ( 'Missing instance' ) ; return ; } this . addControls ( instance , instance ) ; } /**
     * We may have BoundComponents inbetween gui3d controls.
     */ addControls ( instance , last3DGuiControl ) { instance . children . forEach ( ( child ) => { if ( child . metadata . isGUI3DControl === true ) { if ( 'childrenAsContent' in last3DGuiControl . customProps && ( last3DGuiControl . customProps as Control3DCustomProps ) . childrenAsContent === true ) { last3DGuiControl . hostInstance . content = child . hostInstance ; child . state = { added : true , content : true } ; } else { last3DGuiControl . hostInstance . addControl ( child . hostInstance ) ; child . state = { added : true } ; if ( 'linkToTransformNodeByName' in child . customProps && ( child . customProps as Control3DCustomProps ) . linkToTransformNodeByName ) { const toLinkTo = this . scene . getMeshByName ( ( child . customProps as Control3DCustomProps ) . linkToTransformNodeByName ! ) ; if ( toLinkTo !== null ) { child . hostInstance . linkToTransformNode ( toLinkTo ) ; } else { console . error ( 'linkToTransformNode cannot find ' , ( instance . customProps as Control3DCustomProps ) . linkToTransformNodeByName , ' and does not have a scene listener for added meshes.  Declare earlier or add an issue on github.' ) ; } } } } if ( child . state && child . state . added === true && ( child . customProps as Control3DCustomProps ) . onControlAdded ) { ; ( child . customProps as Control3DCustomProps ) . onControlAdded ! ( child ) ; } if ( ! child . state || child . state . content !== true ) { const last3d = child . metadata . isGUI3DControl === true ? child : last3DGuiControl ; this . addControls ( child , last3d ) ; } } ) ; } }