mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 11:37:58 +02:00
this might make it work
This commit is contained in:
parent
0363e96f34
commit
20a9b60e7b
1 changed files with 29 additions and 26 deletions
|
@ -93,7 +93,7 @@
|
||||||
"type": "ParticleEffect"
|
"type": "ParticleEffect"
|
||||||
};
|
};
|
||||||
|
|
||||||
var currentHand;
|
var currentHand = undefined;
|
||||||
var currentHandJointIndex = -1;
|
var currentHandJointIndex = -1;
|
||||||
var state = STATES.INACTIVE;
|
var state = STATES.INACTIVE;
|
||||||
var connectingInterval;
|
var connectingInterval;
|
||||||
|
@ -101,7 +101,7 @@
|
||||||
var makingConnectionTimeout;
|
var makingConnectionTimeout;
|
||||||
var animHandlerId;
|
var animHandlerId;
|
||||||
var connectingId;
|
var connectingId;
|
||||||
var connectingHand;
|
var connectingHandString;
|
||||||
var connectingHandJointIndex = -1;
|
var connectingHandJointIndex = -1;
|
||||||
var waitingList = {};
|
var waitingList = {};
|
||||||
var particleEffect;
|
var particleEffect;
|
||||||
|
@ -116,7 +116,7 @@
|
||||||
|
|
||||||
function debug() {
|
function debug() {
|
||||||
var stateString = "<" + STATE_STRINGS[state] + ">";
|
var stateString = "<" + STATE_STRINGS[state] + ">";
|
||||||
var connecting = "[" + connectingId + "/" + connectingHand + "]";
|
var connecting = "[" + connectingId + "/" + connectingHandString + "]";
|
||||||
print.apply(null, [].concat.apply([LABEL, stateString, JSON.stringify(waitingList), connecting],
|
print.apply(null, [].concat.apply([LABEL, stateString, JSON.stringify(waitingList), connecting],
|
||||||
[].map.call(arguments, JSON.stringify)));
|
[].map.call(arguments, JSON.stringify)));
|
||||||
}
|
}
|
||||||
|
@ -187,6 +187,8 @@
|
||||||
return "LeftHand";
|
return "LeftHand";
|
||||||
}
|
}
|
||||||
debug("handToString called without valid hand!");
|
debug("handToString called without valid hand!");
|
||||||
|
debugger;
|
||||||
|
throw new Exception('hm');
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,15 +233,17 @@
|
||||||
// This returns the ideal hand joint index for the avatar.
|
// This returns the ideal hand joint index for the avatar.
|
||||||
// [hand]middle1 -> [hand]index1 -> [hand]
|
// [hand]middle1 -> [hand]index1 -> [hand]
|
||||||
function getIdealHandJointIndex(avatar, hand) {
|
function getIdealHandJointIndex(avatar, hand) {
|
||||||
debug("got hand " + hand + " for avatar " + avatar.id);
|
debug("got hand " + hand + " for avatar " + avatar.sessionUUID);
|
||||||
var handString = handToString(hand);
|
var handString = handToString(hand);
|
||||||
for (var i = 0; i < PREFERRER_HAND_JOINT_POSTFIX_ORDER.length; i++) {
|
for (var i = 0; i < PREFERRER_HAND_JOINT_POSTFIX_ORDER.length; i++) {
|
||||||
var jointName = handString + PREFERRER_HAND_JOINT_POSTFIX_ORDER[i];
|
var jointName = handString + PREFERRER_HAND_JOINT_POSTFIX_ORDER[i];
|
||||||
var jointIndex = avatar.getJointIndex(jointName);
|
var jointIndex = avatar.getJointIndex(jointName);
|
||||||
if (jointIndex !== -1) {
|
if (jointIndex !== -1) {
|
||||||
|
debug('found joint ' + jointName + ' (' + jointIndex + ')');
|
||||||
return jointIndex;
|
return jointIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
debug('no hand joint found.');
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,9 +312,6 @@
|
||||||
if (state === STATES.INACTIVE) {
|
if (state === STATES.INACTIVE) {
|
||||||
deleteParticleEffect();
|
deleteParticleEffect();
|
||||||
deleteMakeConnectionParticleEffect();
|
deleteMakeConnectionParticleEffect();
|
||||||
// this should always be true if inactive, but just in case:
|
|
||||||
currentHand = undefined;
|
|
||||||
currentHandJointIndex = -1;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,7 +388,8 @@
|
||||||
var avatar = AvatarList.getAvatar(id);
|
var avatar = AvatarList.getAvatar(id);
|
||||||
if (avatar) {
|
if (avatar) {
|
||||||
var otherHand = stringToHand(hand);
|
var otherHand = stringToHand(hand);
|
||||||
var distance = Vec3.distance(getHandPosition(avatar, otherHand), handPos);
|
var otherHandJointIndex = getIdealHandJointIndex(avatar, otherHand);
|
||||||
|
var distance = Vec3.distance(getHandPosition(avatar, otherHandJointIndex), handPos);
|
||||||
return (distance < MAX_AVATAR_DISTANCE);
|
return (distance < MAX_AVATAR_DISTANCE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -395,14 +397,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function findNearestWaitingAvatar() {
|
function findNearestWaitingAvatar() {
|
||||||
var handPos = getHandPosition(MyAvatar, currentHand);
|
var handPos = getHandPosition(MyAvatar, currentHandJointIndex);
|
||||||
var minDistance = MAX_AVATAR_DISTANCE;
|
var minDistance = MAX_AVATAR_DISTANCE;
|
||||||
var nearestAvatar = {};
|
var nearestAvatar = {};
|
||||||
Object.keys(waitingList).forEach(function (identifier) {
|
Object.keys(waitingList).forEach(function (identifier) {
|
||||||
var avatar = AvatarList.getAvatar(identifier);
|
var avatar = AvatarList.getAvatar(identifier);
|
||||||
if (avatar) {
|
if (avatar) {
|
||||||
var hand = stringToHand(waitingList[identifier]);
|
var hand = stringToHand(waitingList[identifier]);
|
||||||
var distance = Vec3.distance(getHandPosition(avatar, hand), handPos);
|
var handJointIndex = getIdealHandJointIndex(avatar, hand);
|
||||||
|
var distance = Vec3.distance(getHandPosition(avatar, handJointIndex), handPos);
|
||||||
if (distance < minDistance) {
|
if (distance < minDistance) {
|
||||||
minDistance = distance;
|
minDistance = distance;
|
||||||
nearestAvatar = {avatar: identifier, hand: hand, avatarObject: avatar};
|
nearestAvatar = {avatar: identifier, hand: hand, avatarObject: avatar};
|
||||||
|
@ -431,7 +434,7 @@
|
||||||
pollCount = 0;
|
pollCount = 0;
|
||||||
state = STATES.WAITING;
|
state = STATES.WAITING;
|
||||||
connectingId = undefined;
|
connectingId = undefined;
|
||||||
connectingHand = undefined;
|
connectingHandString = undefined;
|
||||||
connectingHandJointIndex = -1;
|
connectingHandJointIndex = -1;
|
||||||
// just in case
|
// just in case
|
||||||
stopWaiting();
|
stopWaiting();
|
||||||
|
@ -441,7 +444,7 @@
|
||||||
var nearestAvatar = findNearestWaitingAvatar();
|
var nearestAvatar = findNearestWaitingAvatar();
|
||||||
if (nearestAvatar.avatar) {
|
if (nearestAvatar.avatar) {
|
||||||
connectingId = nearestAvatar.avatar;
|
connectingId = nearestAvatar.avatar;
|
||||||
connectingHand = handToString(nearestAvatar.hand);
|
connectingHandString = handToString(nearestAvatar.hand);
|
||||||
connectingHandJointIndex = getIdealHandJointIndex(nearestAvatar.avatarObject, nearestAvatar.hand);
|
connectingHandJointIndex = getIdealHandJointIndex(nearestAvatar.avatarObject, nearestAvatar.hand);
|
||||||
currentHandJointIndex = getIdealHandJointIndex(MyAvatar, currentHand);
|
currentHandJointIndex = getIdealHandJointIndex(MyAvatar, currentHand);
|
||||||
debug("sending connectionRequest to", connectingId);
|
debug("sending connectionRequest to", connectingId);
|
||||||
|
@ -474,7 +477,7 @@
|
||||||
// below.
|
// below.
|
||||||
state = STATES.INACTIVE;
|
state = STATES.INACTIVE;
|
||||||
connectingId = undefined;
|
connectingId = undefined;
|
||||||
connectingHand = undefined;
|
connectingHandString = undefined;
|
||||||
connectingHandJointIndex = -1;
|
connectingHandJointIndex = -1;
|
||||||
stopWaiting();
|
stopWaiting();
|
||||||
stopConnecting();
|
stopConnecting();
|
||||||
|
@ -542,7 +545,7 @@
|
||||||
var nearestAvatar = findNearestWaitingAvatar();
|
var nearestAvatar = findNearestWaitingAvatar();
|
||||||
if (nearestAvatar.avatar) {
|
if (nearestAvatar.avatar) {
|
||||||
connectingId = nearestAvatar.avatar;
|
connectingId = nearestAvatar.avatar;
|
||||||
connectingHand = handToString(nearestAvatar.hand);
|
connectingHandString = handToString(nearestAvatar.hand);
|
||||||
debug("sending connectionRequest to", connectingId);
|
debug("sending connectionRequest to", connectingId);
|
||||||
messageSend({
|
messageSend({
|
||||||
key: "connectionRequest",
|
key: "connectionRequest",
|
||||||
|
@ -568,7 +571,7 @@
|
||||||
if (result.status === 'success') { // set earlier
|
if (result.status === 'success') { // set earlier
|
||||||
if (!successfulHandshakeInjector) {
|
if (!successfulHandshakeInjector) {
|
||||||
successfulHandshakeInjector = Audio.playSound(successfulHandshakeSound, {
|
successfulHandshakeInjector = Audio.playSound(successfulHandshakeSound, {
|
||||||
position: getHandPosition(MyAvatar, currentHand),
|
position: getHandPosition(MyAvatar, currentHandJointIndex),
|
||||||
volume: 0.5,
|
volume: 0.5,
|
||||||
localOnly: true
|
localOnly: true
|
||||||
});
|
});
|
||||||
|
@ -674,9 +677,9 @@
|
||||||
debug("connecting", id, "hand", hand);
|
debug("connecting", id, "hand", hand);
|
||||||
// do we need to do this?
|
// do we need to do this?
|
||||||
connectingId = id;
|
connectingId = id;
|
||||||
connectingHand = hand;
|
connectingHandString = hand;
|
||||||
connectingHandJointIndex = AvatarList.getAvatarIdentifiers().indexOf(connectingId) !== -1 ?
|
connectingHandJointIndex = AvatarList.getAvatarIdentifiers().indexOf(connectingId) !== -1 ?
|
||||||
getIdealHandJointIndex(AvatarList.getAvatar(connectingId), connectingHand) : -1;
|
getIdealHandJointIndex(AvatarList.getAvatar(connectingId), stringToHand(connectingHandString)) : -1;
|
||||||
state = STATES.CONNECTING;
|
state = STATES.CONNECTING;
|
||||||
|
|
||||||
// play sound
|
// play sound
|
||||||
|
@ -764,9 +767,9 @@
|
||||||
// you were waiting for a connection request, so send the ack. Or, you and the other
|
// you were waiting for a connection request, so send the ack. Or, you and the other
|
||||||
// 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;
|
connectingHandString = message.hand;
|
||||||
connectingHandJointIndex = AvatarList.getAvatarIdentifiers().indexOf(connectingId) !== -1 ?
|
connectingHandJointIndex = AvatarList.getAvatarIdentifiers().indexOf(connectingId) !== -1 ?
|
||||||
getIdealHandJointIndex(AvatarList.getAvatar(connectingId), connectingHand) : -1;
|
getIdealHandJointIndex(AvatarList.getAvatar(connectingId), connectingHandString) : -1;
|
||||||
messageSend({
|
messageSend({
|
||||||
key: "connectionAck",
|
key: "connectionAck",
|
||||||
id: senderID,
|
id: senderID,
|
||||||
|
@ -784,11 +787,11 @@
|
||||||
if (message.id === MyAvatar.sessionUUID) {
|
if (message.id === MyAvatar.sessionUUID) {
|
||||||
// start connecting...
|
// start connecting...
|
||||||
connectingId = senderID;
|
connectingId = senderID;
|
||||||
connectingHand = message.hand;
|
connectingHandString = message.hand;
|
||||||
connectingHandJointIndex = AvatarList.getAvatarIdentifiers().indexOf(connectingId) !== -1 ?
|
connectingHandJointIndex = AvatarList.getAvatarIdentifiers().indexOf(connectingId) !== -1 ?
|
||||||
getIdealHandJointIndex(AvatarList.getAvatar(connectingId), connectingHand) : -1;
|
getIdealHandJointIndex(AvatarList.getAvatar(connectingId), stringToHand(connectingHandString)) : -1;
|
||||||
stopWaiting();
|
stopWaiting();
|
||||||
startConnecting(senderID, message.hand);
|
startConnecting(senderID, connectingHandString);
|
||||||
} else if (connectingId) {
|
} else if (connectingId) {
|
||||||
// this is for someone else (we lost race in connectionRequest),
|
// this is for someone else (we lost race in connectionRequest),
|
||||||
// so lets start over
|
// so lets start over
|
||||||
|
@ -802,10 +805,10 @@
|
||||||
delete waitingList[senderID];
|
delete waitingList[senderID];
|
||||||
if (state === STATES.WAITING && senderID === connectingId) {
|
if (state === STATES.WAITING && senderID === connectingId) {
|
||||||
// temporary logging
|
// temporary logging
|
||||||
if (connectingHand !== message.hand) {
|
if (connectingHandString !== message.hand) {
|
||||||
debug("connecting hand", connectingHand, "not same as connecting hand in message", message.hand);
|
debug("connecting hand", connectingHandString, "not same as connecting hand in message", message.hand);
|
||||||
}
|
}
|
||||||
connectingHand = message.hand;
|
connectingHandString = message.hand;
|
||||||
if (message.id !== MyAvatar.sessionUUID) {
|
if (message.id !== MyAvatar.sessionUUID) {
|
||||||
// the person we were trying to connect is connecting to someone else
|
// the person we were trying to connect is connecting to someone else
|
||||||
// so try again
|
// so try again
|
||||||
|
@ -832,7 +835,7 @@
|
||||||
// do nothing
|
// do nothing
|
||||||
if (state !== STATES.MAKING_CONNECTION && connectingId === senderID) {
|
if (state !== STATES.MAKING_CONNECTION && connectingId === senderID) {
|
||||||
connectingId = undefined;
|
connectingId = undefined;
|
||||||
connectingHand = undefined;
|
connectingHandString = undefined;
|
||||||
connectingHandJointIndex = -1;
|
connectingHandJointIndex = -1;
|
||||||
if (state !== STATES.INACTIVE) {
|
if (state !== STATES.INACTIVE) {
|
||||||
startHandshake();
|
startHandshake();
|
||||||
|
|
Loading…
Reference in a new issue