import type Armature from '../armature/Armature' ; import type Pose from '../armature/Pose' ; import type Bone from '../armature/Bone' ; import type { ISpringType } from './index' ; import SpringItem from './SpringItem' ; import SpringRot from './SpringRot' ; import SpringPos from './SpringPos' ; class SpringChain { static ROT = 0 ; static POS = 1 ; items : SpringItem [ ] = [ ] ; name : string ; spring : ISpringType ; constructor ( name , type = 0 ) { this . name = name ; this . spring = ( type == 1 ) ? new SpringPos ( ) : new SpringRot ( ) ; } setBones ( aryName , arm , osc = 5.0 , damp = 0.5 ) { let bn ; let b ; let spr ; for ( bn of aryName ) { b = arm . getBone ( bn ) ; if ( b == null ) { console . log ( 'Bone not found for spring: ' , bn ) ; continue ; } spr = new SpringItem ( b . name , b . idx ) ; spr . spring . setDamp ( damp ) ; spr . spring . setOscPerSec ( osc ) ; this . items . push ( spr ) ; } } setRestPose ( pose ) { this . spring . setRestPose ( this , pose ) ; } updatePose ( dt , pose ) { this . spring . updatePose ( this , pose , dt ) ; } } export default SpringChain ;