mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 02:03:11 +02:00
Allow skeletons with different bone structures to become friends (still requires hands)
This commit is contained in:
parent
a25584c90f
commit
0363e96f34
1 changed files with 44 additions and 15 deletions
|
@ -30,6 +30,7 @@
|
||||||
var PARTICLE_ANGLE_INCREMENT = 360/45; // 1hz
|
var PARTICLE_ANGLE_INCREMENT = 360/45; // 1hz
|
||||||
var HANDSHAKE_SOUND_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/davidkelly/production/audio/4beat_sweep.wav";
|
var HANDSHAKE_SOUND_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/davidkelly/production/audio/4beat_sweep.wav";
|
||||||
var SUCCESSFUL_HANDSHAKE_SOUND_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/davidkelly/production/audio/3rdbeat_success_bell.wav";
|
var SUCCESSFUL_HANDSHAKE_SOUND_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/davidkelly/production/audio/3rdbeat_success_bell.wav";
|
||||||
|
var PREFERRER_HAND_JOINT_POSTFIX_ORDER = ['Middle1', 'Index1', ''];
|
||||||
var HAPTIC_DATA = {
|
var HAPTIC_DATA = {
|
||||||
initial: { duration: 20, strength: 0.6 }, // duration is in ms
|
initial: { duration: 20, strength: 0.6 }, // duration is in ms
|
||||||
background: { duration: 100, strength: 0.3 }, // duration is in ms
|
background: { duration: 100, strength: 0.3 }, // duration is in ms
|
||||||
|
@ -93,6 +94,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
var currentHand;
|
var currentHand;
|
||||||
|
var currentHandJointIndex = -1;
|
||||||
var state = STATES.INACTIVE;
|
var state = STATES.INACTIVE;
|
||||||
var connectingInterval;
|
var connectingInterval;
|
||||||
var waitingInterval;
|
var waitingInterval;
|
||||||
|
@ -100,6 +102,7 @@
|
||||||
var animHandlerId;
|
var animHandlerId;
|
||||||
var connectingId;
|
var connectingId;
|
||||||
var connectingHand;
|
var connectingHand;
|
||||||
|
var connectingHandJointIndex = -1;
|
||||||
var waitingList = {};
|
var waitingList = {};
|
||||||
var particleEffect;
|
var particleEffect;
|
||||||
var particleRotationAngle = 0.0;
|
var particleRotationAngle = 0.0;
|
||||||
|
@ -225,17 +228,29 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This returns the position of the palm, really. Which relies on the avatar
|
// This returns the ideal hand joint index for the avatar.
|
||||||
// having the expected middle1 joint. TODO: fallback for when this isn't part
|
// [hand]middle1 -> [hand]index1 -> [hand]
|
||||||
// of the avatar?
|
function getIdealHandJointIndex(avatar, hand) {
|
||||||
function getHandPosition(avatar, hand) {
|
debug("got hand " + hand + " for avatar " + avatar.id);
|
||||||
if (!hand) {
|
var handString = handToString(hand);
|
||||||
debug("calling getHandPosition with no hand! (returning avatar position but this is a BUG)");
|
for (var i = 0; i < PREFERRER_HAND_JOINT_POSTFIX_ORDER.length; i++) {
|
||||||
|
var jointName = handString + PREFERRER_HAND_JOINT_POSTFIX_ORDER[i];
|
||||||
|
var jointIndex = avatar.getJointIndex(jointName);
|
||||||
|
if (jointIndex !== -1) {
|
||||||
|
return jointIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This returns the preferred hand position.
|
||||||
|
function getHandPosition(avatar, handJointIndex) {
|
||||||
|
if (handJointIndex === -1) {
|
||||||
|
debug("calling getHandPosition with no hand joint index! (returning avatar position but this is a BUG)");
|
||||||
debug(new Error().stack);
|
debug(new Error().stack);
|
||||||
return avatar.position;
|
return avatar.position;
|
||||||
}
|
}
|
||||||
var jointName = handToString(hand) + "Middle1";
|
return avatar.getJointPosition(handJointIndex);
|
||||||
return avatar.getJointPosition(avatar.getJointIndex(jointName));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function shakeHandsAnimation(animationProperties) {
|
function shakeHandsAnimation(animationProperties) {
|
||||||
|
@ -295,17 +310,18 @@
|
||||||
deleteMakeConnectionParticleEffect();
|
deleteMakeConnectionParticleEffect();
|
||||||
// this should always be true if inactive, but just in case:
|
// this should always be true if inactive, but just in case:
|
||||||
currentHand = undefined;
|
currentHand = undefined;
|
||||||
|
currentHandJointIndex = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var myHandPosition = getHandPosition(MyAvatar, currentHand);
|
var myHandPosition = getHandPosition(MyAvatar, currentHandJointIndex);
|
||||||
var otherHand;
|
var otherHand;
|
||||||
var otherOrientation;
|
var otherOrientation;
|
||||||
if (connectingId) {
|
if (connectingId) {
|
||||||
var other = AvatarList.getAvatar(connectingId);
|
var other = AvatarList.getAvatar(connectingId);
|
||||||
if (other) {
|
if (other) {
|
||||||
otherOrientation = other.orientation;
|
otherOrientation = other.orientation;
|
||||||
otherHand = getHandPosition(other, stringToHand(connectingHand));
|
otherHand = getHandPosition(other, connectingHandJointIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,7 +383,7 @@
|
||||||
|
|
||||||
function isNearby(id, hand) {
|
function isNearby(id, hand) {
|
||||||
if (currentHand) {
|
if (currentHand) {
|
||||||
var handPos = getHandPosition(MyAvatar, currentHand);
|
var handPos = getHandPosition(MyAvatar, currentHandJointIndex);
|
||||||
var avatar = AvatarList.getAvatar(id);
|
var avatar = AvatarList.getAvatar(id);
|
||||||
if (avatar) {
|
if (avatar) {
|
||||||
var otherHand = stringToHand(hand);
|
var otherHand = stringToHand(hand);
|
||||||
|
@ -389,7 +405,7 @@
|
||||||
var distance = Vec3.distance(getHandPosition(avatar, hand), handPos);
|
var distance = Vec3.distance(getHandPosition(avatar, hand), handPos);
|
||||||
if (distance < minDistance) {
|
if (distance < minDistance) {
|
||||||
minDistance = distance;
|
minDistance = distance;
|
||||||
nearestAvatar = {avatar: identifier, hand: hand};
|
nearestAvatar = {avatar: identifier, hand: hand, avatarObject: avatar};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -401,11 +417,11 @@
|
||||||
// them a connectionRequest. If nobody is close enough we send a waiting message, and wait for a
|
// them a connectionRequest. If nobody is close enough we send a waiting message, and wait for a
|
||||||
// connectionRequest. If the 2 people who want to connect are both somewhat out of range when they
|
// connectionRequest. If the 2 people who want to connect are both somewhat out of range when they
|
||||||
// initiate the shake, they will race to see who sends the connectionRequest after noticing the
|
// initiate the shake, they will race to see who sends the connectionRequest after noticing the
|
||||||
// waiting message. Either way, they will start connecting each other at that point.
|
// waiting message. Either way, they will start connecting eachother at that point.
|
||||||
function startHandshake(fromKeyboard) {
|
function startHandshake(fromKeyboard) {
|
||||||
if (fromKeyboard) {
|
if (fromKeyboard) {
|
||||||
debug("adding animation");
|
debug("adding animation");
|
||||||
// just in case order of press/release is broken
|
// just in case order of press/unpress is broken
|
||||||
if (animHandlerId) {
|
if (animHandlerId) {
|
||||||
animHandlerId = MyAvatar.removeAnimationStateHandler(animHandlerId);
|
animHandlerId = MyAvatar.removeAnimationStateHandler(animHandlerId);
|
||||||
}
|
}
|
||||||
|
@ -416,6 +432,7 @@
|
||||||
state = STATES.WAITING;
|
state = STATES.WAITING;
|
||||||
connectingId = undefined;
|
connectingId = undefined;
|
||||||
connectingHand = undefined;
|
connectingHand = undefined;
|
||||||
|
connectingHandJointIndex = -1;
|
||||||
// just in case
|
// just in case
|
||||||
stopWaiting();
|
stopWaiting();
|
||||||
stopConnecting();
|
stopConnecting();
|
||||||
|
@ -425,6 +442,8 @@
|
||||||
if (nearestAvatar.avatar) {
|
if (nearestAvatar.avatar) {
|
||||||
connectingId = nearestAvatar.avatar;
|
connectingId = nearestAvatar.avatar;
|
||||||
connectingHand = handToString(nearestAvatar.hand);
|
connectingHand = handToString(nearestAvatar.hand);
|
||||||
|
connectingHandJointIndex = getIdealHandJointIndex(nearestAvatar.avatarObject, nearestAvatar.hand);
|
||||||
|
currentHandJointIndex = getIdealHandJointIndex(MyAvatar, currentHand);
|
||||||
debug("sending connectionRequest to", connectingId);
|
debug("sending connectionRequest to", connectingId);
|
||||||
messageSend({
|
messageSend({
|
||||||
key: "connectionRequest",
|
key: "connectionRequest",
|
||||||
|
@ -448,6 +467,7 @@
|
||||||
deleteParticleEffect();
|
deleteParticleEffect();
|
||||||
deleteMakeConnectionParticleEffect();
|
deleteMakeConnectionParticleEffect();
|
||||||
currentHand = undefined;
|
currentHand = undefined;
|
||||||
|
currentHandJointIndex = -1;
|
||||||
// note that setting the state to inactive should really
|
// note that setting the state to inactive should really
|
||||||
// only be done here, unless we change how the triggering works,
|
// only be done here, unless we change how the triggering works,
|
||||||
// as we ignore the key release event when inactive. See updateTriggers
|
// as we ignore the key release event when inactive. See updateTriggers
|
||||||
|
@ -455,6 +475,7 @@
|
||||||
state = STATES.INACTIVE;
|
state = STATES.INACTIVE;
|
||||||
connectingId = undefined;
|
connectingId = undefined;
|
||||||
connectingHand = undefined;
|
connectingHand = undefined;
|
||||||
|
connectingHandJointIndex = -1;
|
||||||
stopWaiting();
|
stopWaiting();
|
||||||
stopConnecting();
|
stopConnecting();
|
||||||
stopMakingConnection();
|
stopMakingConnection();
|
||||||
|
@ -480,6 +501,7 @@
|
||||||
}
|
}
|
||||||
if (!currentHand) {
|
if (!currentHand) {
|
||||||
currentHand = hand;
|
currentHand = hand;
|
||||||
|
currentHandJointIndex = getIdealHandJointIndex(MyAvatar, currentHand);
|
||||||
}
|
}
|
||||||
// ok now, we are either initiating or quitting...
|
// ok now, we are either initiating or quitting...
|
||||||
var isGripping = value > GRIP_MIN;
|
var isGripping = value > GRIP_MIN;
|
||||||
|
@ -653,12 +675,14 @@
|
||||||
// do we need to do this?
|
// do we need to do this?
|
||||||
connectingId = id;
|
connectingId = id;
|
||||||
connectingHand = hand;
|
connectingHand = hand;
|
||||||
|
connectingHandJointIndex = AvatarList.getAvatarIdentifiers().indexOf(connectingId) !== -1 ?
|
||||||
|
getIdealHandJointIndex(AvatarList.getAvatar(connectingId), connectingHand) : -1;
|
||||||
state = STATES.CONNECTING;
|
state = STATES.CONNECTING;
|
||||||
|
|
||||||
// play sound
|
// play sound
|
||||||
if (!handshakeInjector) {
|
if (!handshakeInjector) {
|
||||||
handshakeInjector = Audio.playSound(handshakeSound, {
|
handshakeInjector = Audio.playSound(handshakeSound, {
|
||||||
position: getHandPosition(MyAvatar, currentHand),
|
position: getHandPosition(MyAvatar, currentHandJointIndex),
|
||||||
volume: 0.5,
|
volume: 0.5,
|
||||||
localOnly: true
|
localOnly: true
|
||||||
});
|
});
|
||||||
|
@ -741,6 +765,8 @@
|
||||||
// guy raced and both send connectionRequests. Handle that too
|
// guy raced and both send connectionRequests. Handle that too
|
||||||
connectingId = senderID;
|
connectingId = senderID;
|
||||||
connectingHand = message.hand;
|
connectingHand = message.hand;
|
||||||
|
connectingHandJointIndex = AvatarList.getAvatarIdentifiers().indexOf(connectingId) !== -1 ?
|
||||||
|
getIdealHandJointIndex(AvatarList.getAvatar(connectingId), connectingHand) : -1;
|
||||||
messageSend({
|
messageSend({
|
||||||
key: "connectionAck",
|
key: "connectionAck",
|
||||||
id: senderID,
|
id: senderID,
|
||||||
|
@ -759,6 +785,8 @@
|
||||||
// start connecting...
|
// start connecting...
|
||||||
connectingId = senderID;
|
connectingId = senderID;
|
||||||
connectingHand = message.hand;
|
connectingHand = message.hand;
|
||||||
|
connectingHandJointIndex = AvatarList.getAvatarIdentifiers().indexOf(connectingId) !== -1 ?
|
||||||
|
getIdealHandJointIndex(AvatarList.getAvatar(connectingId), connectingHand) : -1;
|
||||||
stopWaiting();
|
stopWaiting();
|
||||||
startConnecting(senderID, message.hand);
|
startConnecting(senderID, message.hand);
|
||||||
} else if (connectingId) {
|
} else if (connectingId) {
|
||||||
|
@ -805,6 +833,7 @@
|
||||||
if (state !== STATES.MAKING_CONNECTION && connectingId === senderID) {
|
if (state !== STATES.MAKING_CONNECTION && connectingId === senderID) {
|
||||||
connectingId = undefined;
|
connectingId = undefined;
|
||||||
connectingHand = undefined;
|
connectingHand = undefined;
|
||||||
|
connectingHandJointIndex = -1;
|
||||||
if (state !== STATES.INACTIVE) {
|
if (state !== STATES.INACTIVE) {
|
||||||
startHandshake();
|
startHandshake();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue