import * as THREE from 'three' ; param root export function removeUnnecessaryJoints ( root ) { const skeletonList = new Map ( ) ; root . traverse ( ( obj ) => { if ( obj . type !== 'SkinnedMesh' ) { return ; } const mesh = obj as THREE . SkinnedMesh ; const geometry = mesh . geometry ; const attribute = geometry . getAttribute ( 'skinIndex' ) as THREE . BufferAttribute ; let skeleton = skeletonList . get ( attribute ) ; if ( ! skeleton ) { const bones = [ ] ; const boneInverses = [ ] ; const boneIndexMap = { } ; const array = attribute . array as number [ ] ; for ( let i = 0 ; i < array . length ; i ++ ) { const index = array [ i ] ; if ( boneIndexMap [ index ] === undefined ) { boneIndexMap [ index ] = bones . length ; bones . push ( mesh . skeleton . bones [ index ] ) ; boneInverses . push ( mesh . skeleton . boneInverses [ index ] ) ; } array [ i ] = boneIndexMap [ index ] ; } attribute . copyArray ( array ) ; attribute . needsUpdate = true ; skeleton = new THREE . Skeleton ( bones , boneInverses ) ; skeletonList . set ( attribute , skeleton ) ; } mesh . bind ( skeleton , new THREE . Matrix4 ( ) ) ; } ) ; }