import type Accessor from '../parsers/gltf2/Accessor' ; import type { Track } from '../parsers/gltf2/Animation' ; import type { ITrack } from './tracks/types' ; import { ELerp } from './tracks/types' ; import Vec3Track from './tracks/Vec3Track' ; import QuatTrack from './tracks/QuatTrack' ; class Clip { name : string = '' ; frameCount : number = 0 ; duration : number = 0 ; tracks : Array < ITrack > = [ ] ; timeStamps : Array < Float32Array > = [ ] ; /** Translate GLTF Animation to Armature Animation Clip */ static fromGLTF2 ( anim ) { const clip = new Clip ( ) ; clip . name = anim . name ; let i ; for ( i of anim . timestamps ) { if ( i . data ) clip . timeStamps . push ( new Float32Array ( i . data ) ) ; if ( i . elementCnt > clip . frameCount ) clip . frameCount = i . elementCnt ; if ( i . boundMax && i . boundMax [ 0 ] > clip . duration ) clip . duration = i . boundMax [ 0 ] ; } let t ; let track ; for ( t of anim . tracks ) { if ( t . transform == 1 && t . jointIndex != 0 ) continue ; switch ( t . transform ) { case 0 : track = new QuatTrack ( ) ; break ; case 1 : track = new Vec3Track ( ) ; break ; case 2 : continue ; break ; default : console . error ( 'unknown animation track transform' , t . transform ) ; continue ; break ; } switch ( t . interpolation ) { case 0 : track . setInterpolation ( ELerp . Step ) ; break ; case 1 : track . setInterpolation ( ELerp . Linear ) ; break ; case 2 : track . setInterpolation ( ELerp . Cubic ) ; break ; } if ( t . keyframes . data ) track . values = new Float32Array ( t . keyframes . data ) ; else console . error ( 'Track has no keyframe data' ) ; track . timeStampIndex = t . timeStampIndex ; track . boneIndex = t . jointIndex ; clip . tracks . push ( track ) ; } return clip ; } } export default Clip ;