import { IPhysicsEnabledObject , PhysicsImpostor , PhysicsImpostorParameters , } from '@babylonjs/core/Physics/physicsImpostor.js' ; import { Scene } from '@babylonjs/core/scene.js' ; import { Nullable } from '@babylonjs/core/types.js' ; import { CreatedInstance } from '../CreatedInstance' ; import DeferredCreationLifecycleListener from './DeferredCreationLifecycleListener' ; /**
 * There is a lot going on in the PhysicsImpostor constructor, so we delay instantiation so that we have a target
 * 'object' before creation.
 */ export default class PhysicsImpostorLifecycleListener extends DeferredCreationLifecycleListener < PhysicsImpostor , any > { private _parent : IPhysicsEnabledObject | undefined ; createInstance = ( instance , scene , props ) : Nullable < PhysicsImpostor > => { if ( ! this . _parent ) { return null ; } const options = props . _options ; instance . hostInstance = new PhysicsImpostor ( this . _parent , props . type , options , this . scene ! ) ; instance . hostInstance . object = this . _parent ; ( this . _parent as any ) . physicsImpostor = instance . hostInstance ; return instance . hostInstance ; } ; onParented ( parent , child ) { super . onParented ( parent , child ) ; if ( parent . hostInstance . position === undefined || parent . hostInstance . rotationQuaternion === undefined ) { console . warn ( 'PhysicsImpostor is parented to an element that does not appear to implement IPhysicsEnabledObject' ) ; } this . _parent = parent . hostInstance ; } }