import type Armature from '../../armature/Armature' ; import BoneMap , { BoneChain , BoneInfo } from '../../armature/BoneMap' ; import Pose from '../../armature/Pose' ; import HipSolver from '../solvers/HipSolver' ; import LimbSolver from '../solvers/LimbSolver' ; import SwingTwistSolver from '../solvers/SwingTwistSolver' ; import SwingTwistEndsSolver from '../solvers/SwingTwistEndsSolver' ; import { IKChain } from './IKChain' ; import IKRig from './IKRig' ; class BipedRig extends IKRig { hip ? : IKChain = undefined ; spine ? : IKChain = undefined ; neck ? : IKChain = undefined ; head ? : IKChain = undefined ; armL ? : IKChain = undefined ; armR ? : IKChain = undefined ; legL ? : IKChain = undefined ; legR ? : IKChain = undefined ; handL ? : IKChain = undefined ; handR ? : IKChain = undefined ; footL ? : IKChain = undefined ; footR ? : IKChain = undefined ; constructor ( ) { super ( ) ; } /** Try to find all the bones for each particular chains */ autoRig ( arm ) { const map = new BoneMap ( arm ) ; let isComplete = true ; let b ; let bi ; let n ; let names = [ ] ; const chains = [ { n : 'hip' , ch : [ 'hip' ] } , { n : 'spine' , ch : [ 'spine' ] } , { n : 'legL' , ch : [ 'thigh_l' , 'shin_l' ] } , { n : 'legR' , ch : [ 'thigh_r' , 'shin_r' ] } , { n : 'armL' , ch : [ 'upperarm_l' , 'forearm_l' ] } , { n : 'armR' , ch : [ 'upperarm_r' , 'forearm_r' ] } , { n : 'neck' , ch : [ 'neck' ] } , { n : 'head' , ch : [ 'head' ] } , { n : 'handL' , ch : [ 'hand_l' ] } , { n : 'handR' , ch : [ 'hand_r' ] } , { n : 'footL' , ch : [ 'foot_l' ] } , { n : 'footR' , ch : [ 'foot_r' ] } , ] ; const self = this ; for ( let itm of chains ) { n = itm . n ; names . length = 0 ; for ( let i = 0 ; i < itm . ch . length ; i ++ ) { b = map . bones . get ( itm . ch [ i ] ) ; if ( ! b ) { console . log ( 'AutoRig - Missing ' , itm . ch [ i ] ) ; isComplete = false ; break ; } if ( b instanceof BoneInfo ) names . push ( b . name ) ; else if ( b instanceof BoneChain ) for ( bi of b . items ) names . push ( bi . name ) ; } self [ n ] = this . add ( arm , n , names ) ; } this . _setAltDirection ( arm ) ; return isComplete ; } /** Use Solver Configuration for Retargeting Animation */ useSolversForRetarget ( pose ? ) { this . hip ?. setSolver ( new HipSolver ( ) . initData ( pose , this . hip ) ) ; this . head ?. setSolver ( new SwingTwistSolver ( ) . initData ( pose , this . head ) ) ; this . armL ?. setSolver ( new LimbSolver ( ) . initData ( pose , this . armL ) ) ; this . armR ?. setSolver ( new LimbSolver ( ) . initData ( pose , this . armR ) ) ; this . legL ?. setSolver ( new LimbSolver ( ) . initData ( pose , this . legL ) ) ; this . legR ?. setSolver ( new LimbSolver ( ) . initData ( pose , this . legR ) ) ; this . footL ?. setSolver ( new SwingTwistSolver ( ) . initData ( pose , this . footL ) ) ; this . footR ?. setSolver ( new SwingTwistSolver ( ) . initData ( pose , this . footR ) ) ; this . handL ?. setSolver ( new SwingTwistSolver ( ) . initData ( pose , this . handL ) ) ; this . handR ?. setSolver ( new SwingTwistSolver ( ) . initData ( pose , this . handR ) ) ; this . spine ?. setSolver ( new SwingTwistEndsSolver ( ) . initData ( pose , this . spine ) ) ; return this ; } /** Use Solver Configuration for Fullbody IK */ useSolversForFBIK ( pose ? ) { return this ; } /** Setup Chain Data & Sets Alt Directions */ bindPose ( pose ) { super . bindPose ( pose ) ; this . _setAltDirection ( pose ) ; return this ; } _setAltDirection ( pose ) { const FWD = [ 0 , 0 , 1 ] ; const UP = [ 0 , 1 , 0 ] ; const DN = [ 0 , - 1 , 0 ] ; const R = [ - 1 , 0 , 0 ] ; const L = [ 1 , 0 , 0 ] ; const BAK = [ 0 , 0 , - 1 ] ; if ( this . hip ) this . hip . bindAltDirections ( pose , FWD , UP ) ; if ( this . spine ) this . spine . bindAltDirections ( pose , UP , FWD ) ; if ( this . neck ) this . neck . bindAltDirections ( pose , FWD , UP ) ; if ( this . head ) this . head . bindAltDirections ( pose , FWD , UP ) ; if ( this . legL ) this . legL . bindAltDirections ( pose , DN , FWD ) ; if ( this . legR ) this . legR . bindAltDirections ( pose , DN , FWD ) ; if ( this . footL ) this . footL . bindAltDirections ( pose , FWD , UP ) ; if ( this . footR ) this . footR . bindAltDirections ( pose , FWD , UP ) ; if ( this . armL ) this . armL . bindAltDirections ( pose , L , BAK ) ; if ( this . armR ) this . armR . bindAltDirections ( pose , R , BAK ) ; if ( this . handL ) this . handL . bindAltDirections ( pose , L , BAK ) ; if ( this . handR ) this . handR . bindAltDirections ( pose , R , BAK ) ; } resolveToPose ( pose , debug ? ) { let ch ; for ( ch of this . items . values ( ) ) { if ( ch . solver ) ch . resolveToPose ( pose , debug ) ; } } } export default BipedRig ;