diff --git a/src/library/load-utils.js b/src/library/load-utils.js index e698a82b..32ea2eb3 100644 --- a/src/library/load-utils.js +++ b/src/library/load-utils.js @@ -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() @@ -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) + + } } \ No newline at end of file