Skip to content

Commit

Permalink
hotfix vrm0 data not being where we expect it (#10236)
Browse files Browse the repository at this point in the history
* hotfix vrm0 data not being where we expect it

* fix
  • Loading branch information
AidanCaruso authored and root committed May 29, 2024
1 parent fdacadb commit e1a098b
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions packages/engine/src/avatar/functions/avatarFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,30 @@ declare module '@pixiv/three-vrm/types/VRM' {
export const autoconvertMixamoAvatar = (model: GLTF | VRM) => {
const scene = model.scene ?? model // FBX assets do not have 'scene' property
if (!scene) return null!

//vrm1's vrm object is in the userData property
let foundModel = model
//sometimes, for some exporters, the vrm object is stored in the userData
if (model.userData?.vrm instanceof VRM) {
return model.userData.vrm
if (model.userData.vrmMeta.metaVersion > 0) return model.userData.vrm
foundModel = model.userData.vrm
}

//vrm0 is an instance of the vrm object
if (model instanceof VRM) {
const bones = model.humanoid.rawHumanBones
model.humanoid.normalizedHumanBonesRoot.removeFromParent()
if (foundModel instanceof VRM) {
const bones = foundModel.humanoid.rawHumanBones
foundModel.humanoid.normalizedHumanBonesRoot.removeFromParent()
bones.hips.node.rotateY(Math.PI)
const humanoid = new VRMHumanoid(bones)
const vrm = new VRM({
...model,
...foundModel,
humanoid,
scene: model.scene,
meta: { name: model.scene.children[0].name } as VRM1Meta
scene: foundModel.scene,
meta: { name: foundModel.scene.children[0].name } as VRM1Meta
})
if (!vrm.userData) vrm.userData = {}
return vrm
}

return avatarBoneMatching(model)
return avatarBoneMatching(foundModel)
}

export const isAvaturn = (url: string) => {
Expand Down

0 comments on commit e1a098b

Please sign in to comment.