Skip to content

Commit 179c6ef

Browse files
author
Avaer Kazmer
committed
Add prerotations flipY support
1 parent b4a0430 commit 179c6ef

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

vrarmik/Rig.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,21 @@ class Rig {
269269
armature.scale.set(1, 1, 1);
270270
armature.updateMatrix();
271271

272-
273-
const preRotations = {};
272+
const preRotations = {
273+
Hips: new Quaternion(),
274+
Left_arm: new Quaternion(),
275+
Right_arm: new Quaternion(),
276+
};
277+
if (flipY) {
278+
preRotations.Hips.premultiply(new Quaternion().setFromAxisAngle(new Vector3(1, 0, 0), -Math.PI/2));
279+
}
274280
if (!flipZ) {
275-
preRotations.Left_arm = new Quaternion().setFromAxisAngle(new Vector3(0, 0, 1), Math.PI*0.25).inverse();
276-
preRotations.Right_arm = new Quaternion().setFromAxisAngle(new Vector3(0, 0, 1), -Math.PI*0.25).inverse();
281+
preRotations.Left_arm.premultiply(new Quaternion().setFromAxisAngle(new Vector3(0, 0, 1), Math.PI*0.25).inverse());
282+
preRotations.Right_arm.premultiply(new Quaternion().setFromAxisAngle(new Vector3(0, 0, 1), -Math.PI*0.25).inverse());
277283
} else {
278-
preRotations.Hips = new Quaternion().setFromAxisAngle(new Vector3(0, 1, 0), Math.PI).inverse();
284+
preRotations.Hips.premultiply(new Quaternion().setFromAxisAngle(new Vector3(0, 1, 0), Math.PI));
279285
}
286+
preRotations.Hips.inverse();
280287
fixSkeletonZForward(skeleton.bones[0], {
281288
preRotations,
282289
});
@@ -285,6 +292,15 @@ class Rig {
285292
o.bind(skeleton);
286293
}
287294
});
295+
if (flipY) {
296+
['Hips'].forEach(name => {
297+
// const userlandBoneName = boneMappings[name];
298+
const bone = modelBones[name];// skeleton.bones.find(bone => bone.name === userlandBoneName);
299+
if (bone) {
300+
bone.quaternion.premultiply(new Quaternion().setFromAxisAngle(new Vector3(1, 0, 0), -Math.PI/2));
301+
}
302+
});
303+
}
288304
if (!flipZ) {
289305
['Left_arm', 'Right_arm'].forEach((name, i) => {
290306
// const userlandBoneName = boneMappings[name];

0 commit comments

Comments
 (0)