mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-05-09 19:40:38 +02:00
Added squeezeHands.js
This commit is contained in:
parent
84dadd1210
commit
e8fa75b4f3
2 changed files with 49 additions and 47 deletions
|
@ -1,47 +0,0 @@
|
|||
//
|
||||
// squeezeFist.js
|
||||
// examples
|
||||
//
|
||||
// Created by Philip Rosedale on 03-June-2014
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// This is an example script that demonstrates an NPC avatar running an FBX animation loop.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
var animation = AnimationCache.getAnimation("https://s3-us-west-1.amazonaws.com/highfidelity-public/animations/HandAnim.fbx");
|
||||
|
||||
var jointMapping;
|
||||
|
||||
var frameIndex = 0.0;
|
||||
|
||||
var FRAME_RATE = 30.0; // frames per second
|
||||
|
||||
Script.update.connect(function(deltaTime) {
|
||||
var triggerValue = Controller.getTriggerValue(0);
|
||||
print(triggerValue);
|
||||
if (!jointMapping) {
|
||||
var avatarJointNames = MyAvatar.jointNames;
|
||||
var animationJointNames = animation.jointNames;
|
||||
if (avatarJointNames.length === 0 || animationJointNames.length === 0) {
|
||||
return;
|
||||
}
|
||||
jointMapping = new Array(avatarJointNames.length);
|
||||
for (var i = 0; i < avatarJointNames.length; i++) {
|
||||
jointMapping[i] = animationJointNames.indexOf(avatarJointNames[i]);
|
||||
}
|
||||
}
|
||||
frameIndex += deltaTime * FRAME_RATE;
|
||||
var frames = animation.frames;
|
||||
var rotations = frames[Math.floor(frameIndex) % frames.length].rotations;
|
||||
for (var j = 0; j < jointMapping.length; j++) {
|
||||
var rotationIndex = jointMapping[j];
|
||||
if (rotationIndex != -1) {
|
||||
MyAvatar.setJointData(j, rotations[rotationIndex]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
49
examples/squeezeHands.js
Normal file
49
examples/squeezeHands.js
Normal file
|
@ -0,0 +1,49 @@
|
|||
//
|
||||
// squeezeHands.js
|
||||
// examples
|
||||
//
|
||||
// Created by Philip Rosedale on June 4, 2014
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
var rightHandAnimation = "https://s3-us-west-1.amazonaws.com/highfidelity-public/animations/HandAnim.fbx";
|
||||
var leftHandAnimation = "https://s3-us-west-1.amazonaws.com/highfidelity-public/animations/HandAnim.fbx";
|
||||
|
||||
var LEFT = 0;
|
||||
var RIGHT = 1;
|
||||
|
||||
var lastLeftFrame = 0;
|
||||
var lastRightFrame = 0;
|
||||
|
||||
var LAST_FRAME = 15.0; // What is the number of the last frame we want to use in the animation?
|
||||
|
||||
Script.update.connect(function(deltaTime) {
|
||||
var leftTriggerValue = Controller.getTriggerValue(LEFT);
|
||||
var rightTriggerValue = Controller.getTriggerValue(RIGHT);
|
||||
|
||||
var leftFrame, rightFrame;
|
||||
|
||||
// Average last two trigger frames together for a bit of smoothing
|
||||
leftFrame = (leftTriggerValue * LAST_FRAME) * 0.5 + lastLeftFrame * 0.5;
|
||||
rightFrame = (rightTriggerValue * LAST_FRAME) * 0.5 + lastRightFrame * 0.5;
|
||||
|
||||
if (leftFrame != lastLeftFrame) {
|
||||
MyAvatar.stopAnimation(leftHandAnimation);
|
||||
MyAvatar.startAnimation(leftHandAnimation, 30.0, 1.0, false, true, leftFrame, leftFrame);
|
||||
}
|
||||
if (rightFrame != lastRightFrame) {
|
||||
MyAvatar.stopAnimation(rightHandAnimation);
|
||||
MyAvatar.startAnimation(rightHandAnimation, 30.0, 1.0, false, true, rightFrame, rightFrame);
|
||||
}
|
||||
|
||||
lastLeftFrame = leftFrame;
|
||||
lastRightFrame = rightFrame;
|
||||
});
|
||||
|
||||
Script.scriptEnding.connect(function() {
|
||||
MyAvatar.stopAnimation(leftHandAnimation);
|
||||
MyAvatar.stopAnimation(rightHandAnimation);
|
||||
});
|
Loading…
Reference in a new issue