import type Bone from '../armature/Bone' ; import type Pose from '../armature/Pose' ; import type { ISpringType } from './index' ; import type SpringChain from './SpringChain' ; import Transform from '../maths/Transform' ; import SpringItem from './SpringItem' ; class SpringPos implements ISpringType { setRestPose ( chain , pose ) { let si ; let b ; for ( si of chain . items ) { b = pose . bones [ si . index ] ; si . spring . reset ( b . world . pos ) ; si . bind . copy ( b . local ) ; } } updatePose ( chain , pose , dt ) { let si ; let b ; let pTran = new Transform ( ) ; let cTran = new Transform ( ) ; let iTran = new Transform ( ) ; si = chain . items [ 0 ] ; b = pose . bones [ si . index ] ; if ( b . pidx != - 1 ) pTran . copy ( pose . bones [ b . pidx ] . world ) ; else pTran . copy ( pose . offset ) ; for ( si of chain . items ) { b = pose . bones [ si . index ] ; cTran . fromMul ( pTran , si . bind ) ; si . spring . setTarget ( cTran . pos ) ; if ( ! si . spring . update ( dt ) ) { pTran . copy ( cTran ) ; continue ; } iTran . fromInvert ( pTran ) . transformVec3 ( si . spring . val , b . local . pos ) ; pTran . mul ( si . bind . rot , b . local . pos , si . bind . scl ) ; } } } export default SpringPos ;