import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader' ; import { VRMBlendShapeImporter } from './blendshape' ; import { VRMFirstPersonImporter } from './firstperson' ; import { VRMHumanoidImporter } from './humanoid/VRMHumanoidImporter' ; import { VRMLookAtImporter } from './lookat/VRMLookAtImporter' ; import { VRMMaterialImporter } from './material' ; import { VRMMetaImporter } from './meta/VRMMetaImporter' ; import { VRMSpringBoneImporter } from './springbone/VRMSpringBoneImporter' ; import { VRM } from './VRM' ; export interface VRMImporterOptions { metaImporter ? : VRMMetaImporter ; lookAtImporter ? : VRMLookAtImporter ; humanoidImporter ? : VRMHumanoidImporter ; blendShapeImporter ? : VRMBlendShapeImporter ; firstPersonImporter ? : VRMFirstPersonImporter ; materialImporter ? : VRMMaterialImporter ; springBoneImporter ? : VRMSpringBoneImporter ; } /**
 * An importer that imports a [[VRM]] from a VRM extension of a GLTF.
 */ export class VRMImporter { protected readonly _metaImporter : VRMMetaImporter ; protected readonly _blendShapeImporter : VRMBlendShapeImporter ; protected readonly _lookAtImporter : VRMLookAtImporter ; protected readonly _humanoidImporter : VRMHumanoidImporter ; protected readonly _firstPersonImporter : VRMFirstPersonImporter ; protected readonly _materialImporter : VRMMaterialImporter ; protected readonly _springBoneImporter : VRMSpringBoneImporter ; param options public constructor ( options = { } ) { this . _metaImporter = options . metaImporter || new VRMMetaImporter ( ) ; this . _blendShapeImporter = options . blendShapeImporter || new VRMBlendShapeImporter ( ) ; this . _lookAtImporter = options . lookAtImporter || new VRMLookAtImporter ( ) ; this . _humanoidImporter = options . humanoidImporter || new VRMHumanoidImporter ( ) ; this . _firstPersonImporter = options . firstPersonImporter || new VRMFirstPersonImporter ( ) ; this . _materialImporter = options . materialImporter || new VRMMaterialImporter ( ) ; this . _springBoneImporter = options . springBoneImporter || new VRMSpringBoneImporter ( ) ; } param gltf public async import ( gltf ) { if ( gltf . parser . json . extensions === undefined || gltf . parser . json . extensions . VRM === undefined ) { throw new Error ( 'Could not find VRM extension on the GLTF' ) ; } const scene = gltf . scene ; scene . updateMatrixWorld ( false ) ; scene . traverse ( ( object3d ) => { if ( ( object3d as any ) . isMesh ) { object3d . frustumCulled = false ; } } ) ; const meta = ( await this . _metaImporter . import ( gltf ) ) || undefined ; const materials = ( await this . _materialImporter . convertGLTFMaterials ( gltf ) ) || undefined ; const humanoid = ( await this . _humanoidImporter . import ( gltf ) ) || undefined ; const firstPerson = humanoid ? ( await this . _firstPersonImporter . import ( gltf , humanoid ) ) || undefined : undefined ; const blendShapeProxy = ( await this . _blendShapeImporter . import ( gltf ) ) || undefined ; const lookAt = firstPerson && blendShapeProxy && humanoid ? ( await this . _lookAtImporter . import ( gltf , firstPerson , blendShapeProxy , humanoid ) ) || undefined : undefined ; const springBoneManager = ( await this . _springBoneImporter . import ( gltf ) ) || undefined ; return new VRM ( { scene : gltf . scene , meta , materials , humanoid , firstPerson , blendShapeProxy , lookAt , springBoneManager , } ) ; } }