Skip to content

Commit

Permalink
Merge pull request #3010 from gonnavis/PickUpTreePr
Browse files Browse the repository at this point in the history
Fix pick up tree animation problem.
  • Loading branch information
Avaer Kazmer authored May 26, 2022
2 parents e3fc4d2 + 501d188 commit aa43621
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 77 deletions.
111 changes: 56 additions & 55 deletions avatars/AnimationMapping.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,73 @@
class AnimationMapping {
constructor(animationTrackName, boneName, isTop, isPosition) {
constructor(animationTrackName, boneName, isTop, isPosition, isArm) {
this.animationTrackName = animationTrackName;
this.boneName = boneName;
this.isTop = isTop;
this.isPosition = isPosition;
this.isArm = isArm;
}

clone() {
return new AnimationMapping(this.animationTrackName, this.boneName, this.isTop, this.isPosition);
return new AnimationMapping(this.animationTrackName, this.boneName, this.isTop, this.isPosition, this.isArm);
}
}

export const animationMappingConfig = [
new AnimationMapping('mixamorigHips.position', 'Hips', false, true),
new AnimationMapping('mixamorigHips.quaternion', 'Hips', false, false),
new AnimationMapping('mixamorigSpine.quaternion', 'Spine', true, false),
new AnimationMapping('mixamorigSpine1.quaternion', 'Chest', true, false),
new AnimationMapping('mixamorigSpine2.quaternion', 'UpperChest', true, false),
new AnimationMapping('mixamorigNeck.quaternion', 'Neck', true, false),
new AnimationMapping('mixamorigHead.quaternion', 'Head', true, false),
new AnimationMapping('mixamorigHips.position', 'Hips', false, true, false),
new AnimationMapping('mixamorigHips.quaternion', 'Hips', false, false, false),
new AnimationMapping('mixamorigSpine.quaternion', 'Spine', true, false, false),
new AnimationMapping('mixamorigSpine1.quaternion', 'Chest', true, false, false),
new AnimationMapping('mixamorigSpine2.quaternion', 'UpperChest', true, false, false),
new AnimationMapping('mixamorigNeck.quaternion', 'Neck', true, false, false),
new AnimationMapping('mixamorigHead.quaternion', 'Head', true, false, false),

new AnimationMapping('mixamorigLeftShoulder.quaternion', 'Left_shoulder', true, false),
new AnimationMapping('mixamorigLeftArm.quaternion', 'Left_arm', true, false),
new AnimationMapping('mixamorigLeftForeArm.quaternion', 'Left_elbow', true, false),
new AnimationMapping('mixamorigLeftHand.quaternion', 'Left_wrist', true, false),
new AnimationMapping('mixamorigLeftHandMiddle1.quaternion', 'Left_middleFinger1', true, false),
new AnimationMapping('mixamorigLeftHandMiddle2.quaternion', 'Left_middleFinger2', true, false),
new AnimationMapping('mixamorigLeftHandMiddle3.quaternion', 'Left_middleFinger3', true, false),
new AnimationMapping('mixamorigLeftHandThumb1.quaternion', 'Left_thumb0', true, false),
new AnimationMapping('mixamorigLeftHandThumb2.quaternion', 'Left_thumb1', true, false),
new AnimationMapping('mixamorigLeftHandThumb3.quaternion', 'Left_thumb2', true, false),
new AnimationMapping('mixamorigLeftHandIndex1.quaternion', 'Left_indexFinger1', true, false),
new AnimationMapping('mixamorigLeftHandIndex2.quaternion', 'Left_indexFinger2', true, false),
new AnimationMapping('mixamorigLeftHandIndex3.quaternion', 'Left_indexFinger3', true, false),
new AnimationMapping('mixamorigLeftHandRing1.quaternion', 'Left_ringFinger1', true, false),
new AnimationMapping('mixamorigLeftHandRing2.quaternion', 'Left_ringFinger2', true, false),
new AnimationMapping('mixamorigLeftHandRing3.quaternion', 'Left_ringFinger3', true, false),
new AnimationMapping('mixamorigLeftHandPinky1.quaternion', 'Left_littleFinger1', true, false),
new AnimationMapping('mixamorigLeftHandPinky2.quaternion', 'Left_littleFinger2', true, false),
new AnimationMapping('mixamorigLeftHandPinky3.quaternion', 'Left_littleFinger3', true, false),
new AnimationMapping('mixamorigLeftShoulder.quaternion', 'Left_shoulder', true, false, true),
new AnimationMapping('mixamorigLeftArm.quaternion', 'Left_arm', true, false, true),
new AnimationMapping('mixamorigLeftForeArm.quaternion', 'Left_elbow', true, false, true),
new AnimationMapping('mixamorigLeftHand.quaternion', 'Left_wrist', true, false, true),
new AnimationMapping('mixamorigLeftHandMiddle1.quaternion', 'Left_middleFinger1', true, false, true),
new AnimationMapping('mixamorigLeftHandMiddle2.quaternion', 'Left_middleFinger2', true, false, true),
new AnimationMapping('mixamorigLeftHandMiddle3.quaternion', 'Left_middleFinger3', true, false, true),
new AnimationMapping('mixamorigLeftHandThumb1.quaternion', 'Left_thumb0', true, false, true),
new AnimationMapping('mixamorigLeftHandThumb2.quaternion', 'Left_thumb1', true, false, true),
new AnimationMapping('mixamorigLeftHandThumb3.quaternion', 'Left_thumb2', true, false, true),
new AnimationMapping('mixamorigLeftHandIndex1.quaternion', 'Left_indexFinger1', true, false, true),
new AnimationMapping('mixamorigLeftHandIndex2.quaternion', 'Left_indexFinger2', true, false, true),
new AnimationMapping('mixamorigLeftHandIndex3.quaternion', 'Left_indexFinger3', true, false, true),
new AnimationMapping('mixamorigLeftHandRing1.quaternion', 'Left_ringFinger1', true, false, true),
new AnimationMapping('mixamorigLeftHandRing2.quaternion', 'Left_ringFinger2', true, false, true),
new AnimationMapping('mixamorigLeftHandRing3.quaternion', 'Left_ringFinger3', true, false, true),
new AnimationMapping('mixamorigLeftHandPinky1.quaternion', 'Left_littleFinger1', true, false, true),
new AnimationMapping('mixamorigLeftHandPinky2.quaternion', 'Left_littleFinger2', true, false, true),
new AnimationMapping('mixamorigLeftHandPinky3.quaternion', 'Left_littleFinger3', true, false, true),

new AnimationMapping('mixamorigRightShoulder.quaternion', 'Right_shoulder', true, false),
new AnimationMapping('mixamorigRightArm.quaternion', 'Right_arm', true, false),
new AnimationMapping('mixamorigRightForeArm.quaternion', 'Right_elbow', true, false),
new AnimationMapping('mixamorigRightHand.quaternion', 'Right_wrist', true, false),
new AnimationMapping('mixamorigRightHandMiddle1.quaternion', 'Right_middleFinger1', true, false),
new AnimationMapping('mixamorigRightHandMiddle2.quaternion', 'Right_middleFinger2', true, false),
new AnimationMapping('mixamorigRightHandMiddle3.quaternion', 'Right_middleFinger3', true, false),
new AnimationMapping('mixamorigRightHandThumb1.quaternion', 'Right_thumb0', true, false),
new AnimationMapping('mixamorigRightHandThumb2.quaternion', 'Right_thumb1', true, false),
new AnimationMapping('mixamorigRightHandThumb3.quaternion', 'Right_thumb2', true, false),
new AnimationMapping('mixamorigRightHandIndex1.quaternion', 'Right_indexFinger1', true, false),
new AnimationMapping('mixamorigRightHandIndex2.quaternion', 'Right_indexFinger2', true, false),
new AnimationMapping('mixamorigRightHandIndex3.quaternion', 'Right_indexFinger3', true, false),
new AnimationMapping('mixamorigRightHandRing1.quaternion', 'Right_ringFinger1', true, false),
new AnimationMapping('mixamorigRightHandRing2.quaternion', 'Right_ringFinger2', true, false),
new AnimationMapping('mixamorigRightHandRing3.quaternion', 'Right_ringFinger3', true, false),
new AnimationMapping('mixamorigRightHandPinky1.quaternion', 'Right_littleFinger1', true, false),
new AnimationMapping('mixamorigRightHandPinky2.quaternion', 'Right_littleFinger2', true, false),
new AnimationMapping('mixamorigRightHandPinky3.quaternion', 'Right_littleFinger3', true, false),
new AnimationMapping('mixamorigRightShoulder.quaternion', 'Right_shoulder', true, false, true),
new AnimationMapping('mixamorigRightArm.quaternion', 'Right_arm', true, false, true),
new AnimationMapping('mixamorigRightForeArm.quaternion', 'Right_elbow', true, false, true),
new AnimationMapping('mixamorigRightHand.quaternion', 'Right_wrist', true, false, true),
new AnimationMapping('mixamorigRightHandMiddle1.quaternion', 'Right_middleFinger1', true, false, true),
new AnimationMapping('mixamorigRightHandMiddle2.quaternion', 'Right_middleFinger2', true, false, true),
new AnimationMapping('mixamorigRightHandMiddle3.quaternion', 'Right_middleFinger3', true, false, true),
new AnimationMapping('mixamorigRightHandThumb1.quaternion', 'Right_thumb0', true, false, true),
new AnimationMapping('mixamorigRightHandThumb2.quaternion', 'Right_thumb1', true, false, true),
new AnimationMapping('mixamorigRightHandThumb3.quaternion', 'Right_thumb2', true, false, true),
new AnimationMapping('mixamorigRightHandIndex1.quaternion', 'Right_indexFinger1', true, false, true),
new AnimationMapping('mixamorigRightHandIndex2.quaternion', 'Right_indexFinger2', true, false, true),
new AnimationMapping('mixamorigRightHandIndex3.quaternion', 'Right_indexFinger3', true, false, true),
new AnimationMapping('mixamorigRightHandRing1.quaternion', 'Right_ringFinger1', true, false, true),
new AnimationMapping('mixamorigRightHandRing2.quaternion', 'Right_ringFinger2', true, false, true),
new AnimationMapping('mixamorigRightHandRing3.quaternion', 'Right_ringFinger3', true, false, true),
new AnimationMapping('mixamorigRightHandPinky1.quaternion', 'Right_littleFinger1', true, false, true),
new AnimationMapping('mixamorigRightHandPinky2.quaternion', 'Right_littleFinger2', true, false, true),
new AnimationMapping('mixamorigRightHandPinky3.quaternion', 'Right_littleFinger3', true, false, true),

new AnimationMapping('mixamorigRightUpLeg.quaternion', 'Right_leg', false, false),
new AnimationMapping('mixamorigRightLeg.quaternion', 'Right_knee', false, false),
new AnimationMapping('mixamorigRightFoot.quaternion', 'Right_ankle', false, false),
new AnimationMapping('mixamorigRightToeBase.quaternion', 'Right_toe', false, false),
new AnimationMapping('mixamorigRightUpLeg.quaternion', 'Right_leg', false, false, false),
new AnimationMapping('mixamorigRightLeg.quaternion', 'Right_knee', false, false, false),
new AnimationMapping('mixamorigRightFoot.quaternion', 'Right_ankle', false, false, false),
new AnimationMapping('mixamorigRightToeBase.quaternion', 'Right_toe', false, false, false),

new AnimationMapping('mixamorigLeftUpLeg.quaternion', 'Left_leg', false, false),
new AnimationMapping('mixamorigLeftLeg.quaternion', 'Left_knee', false, false),
new AnimationMapping('mixamorigLeftFoot.quaternion', 'Left_ankle', false, false),
new AnimationMapping('mixamorigLeftToeBase.quaternion', 'Left_toe', false, false),
new AnimationMapping('mixamorigLeftUpLeg.quaternion', 'Left_leg', false, false, false),
new AnimationMapping('mixamorigLeftLeg.quaternion', 'Left_knee', false, false, false),
new AnimationMapping('mixamorigLeftFoot.quaternion', 'Left_ankle', false, false, false),
new AnimationMapping('mixamorigLeftToeBase.quaternion', 'Left_toe', false, false, false),
];
33 changes: 31 additions & 2 deletions avatars/animationHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const localQuaternion4 = new Quaternion();
const localQuaternion5 = new Quaternion();
const localQuaternion6 = new Quaternion();

const identityQuaternion = new Quaternion();

let animations;
let animationStepIndices;
// let animationsBaseModel;
Expand Down Expand Up @@ -760,13 +762,22 @@ export const _applyAnimation = (avatar, now, moveFactors) => {
animationTrackName: k,
dst,
// isTop,
isArm,
} = spec;

const t2 = avatar.jumpTime / 1000 * 0.6 + 0.7;
const src2 = jumpAnimation.interpolants[k];
const v2 = src2.evaluate(t2);

dst.fromArray(v2);

if (avatar.holdState && isArm) {
const holdAnimation = holdAnimations['pick_up_idle'];
const src2 = holdAnimation.interpolants[k];
const t2 = (now / 1000) % holdAnimation.duration;
const v2 = src2.evaluate(t2);
dst.fromArray(v2);
}
};
}
if (avatar.sitState) {
Expand Down Expand Up @@ -1117,8 +1128,10 @@ export const _applyAnimation = (avatar, now, moveFactors) => {
animationTrackName: k,
dst,
lerpFn,
boneName,
isTop,
isPosition,
isArm,
} = spec;

_handleDefault(spec);
Expand All @@ -1129,10 +1142,17 @@ export const _applyAnimation = (avatar, now, moveFactors) => {
const v2 = src2.evaluate(t2);

if (isTop) {
if (isPosition) {
if (boneName === 'Left_arm' || boneName === 'Right_arm') {
dst.fromArray(v2);
} else {
dst.premultiply(localQuaternion2.fromArray(v2));
if (isArm) {
dst
.slerp(identityQuaternion, walkRunFactor * 0.7 + crouchFactor * (1 - idleWalkFactor) * 0.5)
.premultiply(localQuaternion2.fromArray(v2));
} else {
dst
.premultiply(localQuaternion2.fromArray(v2));
}
}
}
};
Expand Down Expand Up @@ -1172,6 +1192,7 @@ export const _applyAnimation = (avatar, now, moveFactors) => {
animationTrackName: k,
dst,
// isTop,
isArm,
lerpFn,
} = spec;

Expand All @@ -1187,6 +1208,14 @@ export const _applyAnimation = (avatar, now, moveFactors) => {
localQuaternion.fromArray(v2),
f,
);

if (avatar.holdState && isArm) {
const holdAnimation = holdAnimations['pick_up_idle'];
const src2 = holdAnimation.interpolants[k];
const t2 = (now / 1000) % holdAnimation.duration;
const v2 = src2.evaluate(t2);
dst.fromArray(v2);
}
}
};

Expand Down
2 changes: 1 addition & 1 deletion character-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ class PlayerBase extends THREE.Object3D {
physicsObject.updateMatrixWorld();

physicsManager.setTransform(physicsObject, true);
physicsManager.setVelocity(physicsObject, localVector.copy(dropDirection).multiplyScalar(5), true);
physicsManager.setVelocity(physicsObject, localVector.copy(dropDirection).multiplyScalar(5).add(this.characterPhysics.velocity), true);
physicsManager.setAngularVelocity(physicsObject, zeroVector, true);

app.position.copy(physicsObject.position);
Expand Down
2 changes: 1 addition & 1 deletion constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const crouchMaxTime = 200;
export const activateMaxTime = 750;
export const useMaxTime = 750;
export const aimMaxTime = 1000;
export const throwReleaseTime = 750;
export const throwReleaseTime = 220;
export const minFov = 60;
export const maxFov = 120;
export const midFov = 90;
Expand Down
82 changes: 64 additions & 18 deletions metaverse_components/wear.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ import npcManager from '../npc-manager.js';
// import {rarityColors} from '../constants.js';

const localVector = new THREE.Vector3();
// const localVector2 = new THREE.Vector3();
const localVector2 = new THREE.Vector3();
const localVector3 = new THREE.Vector3();
const localVector4 = new THREE.Vector3();
const localQuaternion = new THREE.Quaternion();
const localQuaternion2 = new THREE.Quaternion();
const localEuler = new THREE.Euler();
const localMatrix = new THREE.Matrix4();

const identityVector = new THREE.Vector3();

export default (app, component) => {
const {useActivate} = metaversefile;
Expand Down Expand Up @@ -188,26 +195,65 @@ export default (app, component) => {

const _copyBoneAttachment = spec => {
const {boneAttachment = 'hips', position, quaternion, scale} = spec;
const boneName = Avatar.modelBoneRenames[boneAttachment];
const bone = player.avatar.foundModelBones[boneName];
if (bone) {
bone.matrixWorld
.decompose(app.position, app.quaternion, app.scale);
if (Array.isArray(position)) {
app.position.add(localVector.fromArray(position).applyQuaternion(app.quaternion));
}
if (Array.isArray(quaternion)) {
app.quaternion.multiply(localQuaternion.fromArray(quaternion));
}
if (Array.isArray(scale)) {
app.scale.multiply(localVector.fromArray(scale));
const boneAttachments = Array.isArray(boneAttachment) ? boneAttachment : [boneAttachment];

// lerp app's transform to average position/quaternion/scale of boneAttachments.
let count = 0;
boneAttachments.forEach((boneAttachment, i) => {
const boneName = Avatar.modelBoneRenames[boneAttachment];
const bone = player.avatar.foundModelBones[boneName];
if (bone) {
if (count === 0) {
bone.matrixWorld
.decompose(app.position, app.quaternion, app.scale);
count++;
} else {
bone.matrixWorld
.decompose(localVector, localQuaternion, localVector2);
const t = 1 / (count + 1);
app.position.lerp(localVector, t);
app.quaternion.slerp(localQuaternion, t);
app.scale.lerp(localVector2, t);
count++;
}
} else {
console.warn('invalid bone attachment', {app, boneAttachment});
}
app.updateMatrixWorld();
});

// console.log('copy bone attachment', app, app.position.toArray().join(','), bone);
} else {
console.warn('invalid bone attachment', {app, boneAttachment});
if (quaternion === 'upVectorHipsToPosition') {
const hipsPostion = localVector;
hipsPostion.setFromMatrixPosition(player.avatar.foundModelBones.Hips.matrixWorld);

localEuler.order = 'YXZ';
localEuler.setFromQuaternion(player.quaternion);
localEuler.x = 0;
localEuler.z = 0;
const playerQuaternion = localQuaternion2.setFromEuler(localEuler);

const eyeVector = identityVector;
const upVector = localVector3.copy(app.position).sub(hipsPostion).normalize();
const targetVector = localVector4.set(0, 0, -1);
targetVector.applyQuaternion(localQuaternion.setFromUnitVectors(
localVector.set(0, 1, 0),
localVector2.copy(upVector).normalize(),
));

localMatrix.lookAt(eyeVector, targetVector, upVector)
app.quaternion.setFromRotationMatrix(localMatrix);
app.quaternion.multiply(playerQuaternion);
}

if (Array.isArray(position)) {
app.position.add(localVector.fromArray(position).applyQuaternion(app.quaternion));
}
if (Array.isArray(quaternion)) {
app.quaternion.multiply(localQuaternion.fromArray(quaternion));
}
if (Array.isArray(scale)) {
app.scale.multiply(localVector.fromArray(scale));
}
app.updateMatrixWorld();
};
const frame = metaversefile.useFrame(({timestamp, timeDiff}) => {
if (wearSpec && player.avatar) {
Expand Down
1 change: 1 addition & 0 deletions player-avatar-binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export function applyPlayerActionsToAvatar(player, rig) {

// XXX this needs to be based on the current loadout index
rig.holdState = wearAction?.holdAnimation === 'pick_up_idle';
if (rig.holdState) rig.unuseAnimation = null;
// rig.danceState = !!danceAction;
rig.danceFactor = player.actionInterpolants.dance.get();
if (danceAction) {
Expand Down
Binary file modified public/avatars/scilly_drophunter_v31.6_Guilty.vrm
Binary file not shown.
Binary file added public/avatars/scilly_drophunter_v31_Guilty.vrm
Binary file not shown.

0 comments on commit aa43621

Please sign in to comment.