import type Pose from '../../../armature/Pose' ; import type { IKChain } from '../../rigs/IKChain' ; import type { IKData } from '../..' ; import type { ISolver } from './ISolver' ; import { vec3 } from 'gl-matrix' ; import SwingTwistSolver from '../SwingTwistSolver' ; class SwingTwistBase implements ISolver { _swingTwist = new SwingTwistSolver ( ) ; initData ( pose ? , chain ? ) { if ( pose && chain ) this . _swingTwist . initData ( pose , chain ) ; return this ; } setTargetDir ( e , pole ? , effectorScale ? ) { this . _swingTwist . setTargetDir ( e , pole , effectorScale ) ; return this ; } setTargetPos ( v , pole ? ) { this . _swingTwist . setTargetPos ( v , pole ) ; return this ; } setTargetPole ( v ) { this . _swingTwist . setTargetPole ( v ) ; return this ; } resolve ( chain , pose , debug ? ) { } ikDataFromPose ( chain , pose , out ) { const p0 = chain . getStartPosition ( pose ) ; const p1 = chain . getTailPosition ( pose , true ) ; const dir = vec3 . sub ( [ 0 , 0 , 0 ] , p1 , p0 ) ; out . lenScale = vec3 . len ( dir ) / chain . length ; vec3 . normalize ( out . effectorDir , dir ) ; const lnk = chain . first ( ) ; const bp = pose . bones [ lnk . idx ] ; vec3 . transformQuat ( dir , lnk . poleDir , bp . world . rot ) ; vec3 . cross ( dir , dir , out . effectorDir ) ; vec3 . cross ( dir , out . effectorDir , dir ) ; vec3 . normalize ( out . poleDir , dir ) ; } } export default SwingTwistBase ;