import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader' ; import { VRMBlendShapeProxy } from '../blendshape' ; import { VRMFirstPerson } from '../firstperson' ; import { VRMHumanoid } from '../humanoid' ; import { VRMSchema } from '../types' ; import { VRMCurveMapper } from './VRMCurveMapper' ; import { VRMLookAtApplyer } from './VRMLookAtApplyer' ; import { VRMLookAtBlendShapeApplyer } from './VRMLookAtBlendShapeApplyer' ; import { VRMLookAtBoneApplyer } from './VRMLookAtBoneApplyer' ; import { VRMLookAtHead } from './VRMLookAtHead' ; const DEG2RAD = Math . PI / 180 ; /**
 * An importer that imports a [[VRMLookAtHead]] from a VRM extension of a GLTF.
 */ export class VRMLookAtImporter { param gltf param blendShapeProxy param humanoid public import ( gltf , firstPerson , blendShapeProxy , humanoid ) { const vrmExt = gltf . parser . json . extensions ?. VRM ; if ( ! vrmExt ) { return null ; } const schemaFirstPerson = vrmExt . firstPerson ; if ( ! schemaFirstPerson ) { return null ; } const applyer = this . _importApplyer ( schemaFirstPerson , blendShapeProxy , humanoid ) ; return new VRMLookAtHead ( firstPerson , applyer || undefined ) ; } protected _importApplyer ( schemaFirstPerson , blendShapeProxy , humanoid ) { const lookAtHorizontalInner = schemaFirstPerson . lookAtHorizontalInner ; const lookAtHorizontalOuter = schemaFirstPerson . lookAtHorizontalOuter ; const lookAtVerticalDown = schemaFirstPerson . lookAtVerticalDown ; const lookAtVerticalUp = schemaFirstPerson . lookAtVerticalUp ; switch ( schemaFirstPerson . lookAtTypeName ) { case VRMSchema . FirstPersonLookAtTypeName . Bone : { if ( lookAtHorizontalInner === undefined || lookAtHorizontalOuter === undefined || lookAtVerticalDown === undefined || lookAtVerticalUp === undefined ) { return null ; } else { return new VRMLookAtBoneApplyer ( humanoid , this . _importCurveMapperBone ( lookAtHorizontalInner ) , this . _importCurveMapperBone ( lookAtHorizontalOuter ) , this . _importCurveMapperBone ( lookAtVerticalDown ) , this . _importCurveMapperBone ( lookAtVerticalUp ) ) ; } } case VRMSchema . FirstPersonLookAtTypeName . BlendShape : { if ( lookAtHorizontalOuter === undefined || lookAtVerticalDown === undefined || lookAtVerticalUp === undefined ) { return null ; } else { return new VRMLookAtBlendShapeApplyer ( blendShapeProxy , this . _importCurveMapperBlendShape ( lookAtHorizontalOuter ) , this . _importCurveMapperBlendShape ( lookAtVerticalDown ) , this . _importCurveMapperBlendShape ( lookAtVerticalUp ) ) ; } } default : { return null ; } } } private _importCurveMapperBone ( map ) { return new VRMCurveMapper ( typeof map . xRange === 'number' ? DEG2RAD * map . xRange : undefined , typeof map . yRange === 'number' ? DEG2RAD * map . yRange : undefined , map . curve ) ; } private _importCurveMapperBlendShape ( map ) { return new VRMCurveMapper ( typeof map . xRange === 'number' ? DEG2RAD * map . xRange : undefined , map . yRange , map . curve ) ; } }