Skip to content

Commit

Permalink
add object dummy to rotate vrm0
Browse files Browse the repository at this point in the history
  • Loading branch information
memelotsqui committed Jul 19, 2024
1 parent 424da34 commit a46596a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/library/characterManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { VRMLoaderPlugin, VRMUtils } from "@pixiv/three-vrm";
import { getAsArray, disposeVRM, renameVRMBones, addModelData } from "./utils";
import { downloadGLB, downloadVRMWithAvatar } from "../library/download-utils"
import { saveVRMCollidersToUserData } from "./load-utils";
import { cullHiddenMeshes, setTextureToChildMeshes } from "./utils";
import { cullHiddenMeshes, setTextureToChildMeshes, addChildAtFirst } from "./utils";
import { LipSync } from "./lipsync";
import { LookAtManager } from "./lookatManager";
import { CharacterManifestData } from "./CharacterManifestData";
Expand Down Expand Up @@ -994,7 +994,15 @@ export class CharacterManager {
this._modelBaseSetup(vrm, item, traitID, textures, colors);

// Rotate model 180 degrees


if (vrm.meta?.metaVersion === '0'){
if (vrm.humanoid.humanBones.hips.node.parent == vrm.scene){
const dummyRotate = new THREE.Object3D();
dummyRotate.name = "newRootNode";
addChildAtFirst(vrm.scene, dummyRotate)
dummyRotate.add(vrm.humanoid.humanBones.hips.node);
}
vrm.humanoid.humanBones.hips.node.parent.rotateY(3.14159);
//VRMUtils.rotateVRM0( vrm );
console.log("Loaded VRM0 file ", vrm);
Expand Down
14 changes: 14 additions & 0 deletions src/library/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ export function getAsArray(target) {
return Array.isArray(target) ? target : [target]
}

export function addChildAtFirst(parent, newChild) {
// Store the current children of the parent
let currentChildren = parent.children.slice();

// Clear all children from the parent
currentChildren.forEach(child => parent.remove(child));

// Add the new child at the first position
parent.add(newChild);

// Re-add the original children
currentChildren.forEach(child => parent.add(child));
}

export async function setTextureToChildMeshes(scene, url){
const textureLoader = new THREE.TextureLoader();

Expand Down

0 comments on commit a46596a

Please sign in to comment.