Skip to content

Commit

Permalink
Merge pull request #189 from Benjythebee/fix/morphs
Browse files Browse the repository at this point in the history
Looks good to me :)
  • Loading branch information
memelotsqui authored Jan 22, 2025
2 parents 6d42d1a + 5f6b9c8 commit 4b5542a
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/library/download-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,44 @@ function getRebindedVRMExpressionManager(avatarModel){

}

for(const expression of expressionManager.expressions){
const blendshapeNames = getBlendshapeForVRMExpression(expression)
const defaultBlendshape = blendshapeNames[0][0];
const oldBounds = expression._binds
const newBindIndex = changedDictionaries.new[defaultBlendshape].index
const binds = oldBounds.map((bind)=>{
return new VRMExpressionMorphTargetBind({
index:newBindIndex,
weight:bind.weight,
primitives:[child]
})
})
//@ts-ignore
expression._binds = binds
}

}
return expressionManager
}



function getBlendshapeForVRMExpression(expression){

const binds = expression._binds
if(!binds) return []

const blendshapes = binds.map((bind) => {
let blendshapeNames = []
bind.primitives.forEach((p)=>{
const morph = Object.entries(p.morphTargetDictionary).find(([_key,value])=>value==bind.index)
if(morph){
blendshapeNames.push(morph[0])
}
})

return blendshapeNames
})
return blendshapes

}

0 comments on commit 4b5542a

Please # to comment.