Skip to content

Commit

Permalink
Merge pull request #2061 from webaverse/new_grab_animations
Browse files Browse the repository at this point in the history
New grab animations
  • Loading branch information
Avaer Kazmer authored Dec 23, 2021
2 parents c52c937 + 9d5f687 commit f272679
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 19 deletions.
57 changes: 41 additions & 16 deletions avatars/avatars.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,11 @@ const loadPromise = (async () => {
crouch: animations.find(a => a.isCrouch),
};
activateAnimations = {
activate: animations.find(a => a.isActivate),
grab_forward: {animation:animations.find(a => a.name === 'grab_forward.fbx'), speedFactor: 1.2},
grab_down: {animation:animations.find(a => a.name === 'grab_down.fbx'), speedFactor: 1.7},
grab_up: {animation:animations.find(a => a.name === 'grab_up.fbx'), speedFactor: 1.2},
grab_left: {animation:animations.find(a => a.name === 'grab_left.fbx'), speedFactor: 1.2},
grab_right: {animation:animations.find(a => a.name === 'grab_right.fbx'), speedFactor: 1.2},
};
narutoRunAnimations = {
narutoRun: animations.find(a => a.isNarutoRun),
Expand Down Expand Up @@ -2062,21 +2066,6 @@ class Avatar {
dst.fromArray(v2);
}
}
if (this.activateTime > 0) {
return spec => {
const {
animationTrackName: k,
dst,
isTop,
} = spec;
const activateAnimation = activateAnimations[defaultActivateAnimation];
const src2 = activateAnimation.interpolants[k];
const t2 = Math.pow(this.activateTime/1000*activateAnimation.duration/2, 0.5);
const v2 = src2.evaluate(t2);

dst.fromArray(v2);
};
}
if (this.narutoRunState) {
return spec => {
const {
Expand Down Expand Up @@ -2353,6 +2342,41 @@ class Avatar {
);
}
};

const _blendActivateAction = spec => {
const {
animationTrackName: k,
dst,
isTop,
lerpFn,
} = spec;

if (this.activateTime > 0) {

const localPlayer = metaversefile.useLocalPlayer();

let defaultAnimation = "grab_forward";

if (localPlayer.getAction('activate').animationName) {
defaultAnimation = localPlayer.getAction('activate').animationName;
}

const activateAnimation = activateAnimations[defaultAnimation].animation;
const src2 = activateAnimation.interpolants[k];
const t2 = ((this.activateTime / 1000) * activateAnimations[defaultAnimation].speedFactor) % activateAnimation.duration;
const v2 = src2.evaluate(t2);

const f = this.activateTime > 0 ? Math.min(cubicBezier(t2), 1) : (1 - Math.min(cubicBezier(t2), 1));

lerpFn
.call(
dst,
localQuaternion.fromArray(v2),
f
);
}
};

for (const spec of this.animationMappings) {
const {
animationTrackName: k,
Expand All @@ -2363,6 +2387,7 @@ class Avatar {

applyFn(spec);
_blendFly(spec);
_blendActivateAction(spec);

// ignore all animation position except y
if (isPosition) {
Expand Down
2 changes: 1 addition & 1 deletion character-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ class RemotePlayer extends InterpolatedPlayer {
function getPlayerCrouchFactor(player) {
let factor = 1;
factor *= 1 - 0.4 * player.actionInterpolants.crouch.getNormalized();
factor *= 1 - 0.8 * Math.min(player.actionInterpolants.activate.getNormalized() * 1.5, 1);
//factor *= 1 - 0.8 * Math.min(player.actionInterpolants.activate.getNormalized() * 1.5, 1);
return factor;
};

Expand Down
60 changes: 59 additions & 1 deletion game.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,61 @@ const _gameUpdate = (timestamp, timeDiff) => {
};
_handlePush();

const _updateActivateAnimation = (grabUseMeshPosition) => {

let currentDistance = 100;
let currentAnimation = "grab_forward";
let distance = 0;

// Forward
localVector.set(0, -0.5, -0.5).applyQuaternion(localPlayer.quaternion)
.add(localPlayer.position);
currentDistance = grabUseMeshPosition.distanceTo(localVector);

// Down
localVector.set(0, -1.2, -0.5).applyQuaternion(localPlayer.quaternion)
.add(localPlayer.position);
distance = grabUseMeshPosition.distanceTo(localVector);
if (distance < currentDistance) {
currentDistance = distance;
currentAnimation = "grab_down";
}

// Up
localVector.set(0, 0.0, -0.5).applyQuaternion(localPlayer.quaternion)
.add(localPlayer.position);
distance = grabUseMeshPosition.distanceTo(localVector);
if (distance < currentDistance) {
currentDistance = distance;
currentAnimation = "grab_up";
}

// Left
localVector.set(-0.8, -0.5, -0.5).applyQuaternion(localPlayer.quaternion)
.add(localPlayer.position);
distance = grabUseMeshPosition.distanceTo(localVector);
if (distance < currentDistance) {
currentDistance = distance;
currentAnimation = "grab_left";
}

// Right
localVector.set(0.8, -0.5, -0.5).applyQuaternion(localPlayer.quaternion)
.add(localPlayer.position);
distance = grabUseMeshPosition.distanceTo(localVector);
if (distance < currentDistance) {
currentDistance = distance;
currentAnimation = "grab_right";
}

if (localPlayer.getAction('activate')) {
localPlayer.getAction('activate').animationName = currentAnimation;
}

return (currentDistance < 0.8);

};

const _updateGrab = () => {
// moveMesh.visible = false;

Expand Down Expand Up @@ -759,9 +814,12 @@ const _gameUpdate = (timestamp, timeDiff) => {
grabUseMesh.quaternion.copy(camera.quaternion);
// grabUseMesh.scale.copy(grabbedObject.scale);
grabUseMesh.updateMatrixWorld();
grabUseMesh.visible = true;
//grabUseMesh.visible = true;
grabUseMesh.target = object;
grabUseMesh.setComponent('value', localPlayer.actionInterpolants.activate.getNormalized());

grabUseMesh.visible = _updateActivateAnimation(grabUseMesh.position);

}
}
}
Expand Down
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions player-avatar-binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export function applyPlayerModesToAvatar(player, session, rig) {
for (const action of player.getActionsState()) {
if (action.type === 'wear') {
const app = player.appManager.getAppByInstanceId(action.instanceId);
if (!app) {
return null;
}
for (const {key, value} of app.components) {
if (key === 'aim') {
return value;
Expand Down
Binary file removed public/animations/Gathering Objects.fbx
Binary file not shown.
Binary file modified public/animations/animations.cbor
Binary file not shown.
Binary file added public/animations/grab_down.fbx
Binary file not shown.
Binary file added public/animations/grab_forward.fbx
Binary file not shown.
Binary file added public/animations/grab_left.fbx
Binary file not shown.
Binary file added public/animations/grab_right.fbx
Binary file not shown.
Binary file added public/animations/grab_up.fbx
Binary file not shown.

0 comments on commit f272679

Please sign in to comment.