Skip to content

Commit

Permalink
update downloadVRM call
Browse files Browse the repository at this point in the history
  • Loading branch information
memelotsqui committed Nov 2, 2023
1 parent 04c37d4 commit 08dafdf
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/library/load-utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { VRMLoaderPlugin, VRMUtils } from '@pixiv/three-vrm';
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader"
import { renameVRMBones } from "../library/utils"

export const loadVRM = async(url) => {
const gltfLoader = new GLTFLoader()
Expand All @@ -11,17 +12,32 @@ export const loadVRM = async(url) => {
// rotate?

const vrm = await gltfLoader.loadAsync(url);
console.log(vrm);
if (vrm.userData?.vrmMeta?.metaVersion === '0'){
vrm.scene.rotation.y = Math.PI;
vrm.scene.traverse((child)=>{
if (child.isSkinnedMesh) {
child.userData.isVRM0 = true;
for (let i =0; i < child.skeleton.bones.length;i++){
child.skeleton.bones[i].userData.vrm0RestPosition = { ... child.skeleton.bones[i].position }
}
}
})
}
URL.revokeObjectURL(url);
return vrm;
}

export const addVRMToScene = (vrm, scene) => {
const vrmData = vrm.userData.vrm;
renameVRMBones(vrmData);
console.log(vrmData);

if (vrm && scene){
console.log("add to scene")
scene.add(vrm.scene)
scene.attach(vrm.scene)


}
}

0 comments on commit 08dafdf

Please sign in to comment.