mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 18:50:00 +02:00
cleanup, switch to overlays with texture swapping, move overlay to between hands
This commit is contained in:
parent
0a35fa34f9
commit
d8719ac3a9
1 changed files with 73 additions and 20 deletions
|
@ -25,23 +25,30 @@ const STATE_STRINGS = ["inactive", "waiting", "friending", "makingFriends"];
|
||||||
const WAITING_INTERVAL = 100; // ms
|
const WAITING_INTERVAL = 100; // ms
|
||||||
const FRIENDING_INTERVAL = 100; // ms
|
const FRIENDING_INTERVAL = 100; // ms
|
||||||
const FRIENDING_TIME = 3000; // ms
|
const FRIENDING_TIME = 3000; // ms
|
||||||
const ENTITY_COLORS = [{red: 0x00, green: 0xFF, blue: 0x00}, {red: 0x00, green: 0x00, blue: 0xFF}, {red: 0xFF, green: 0x00, blue: 0x00}];
|
|
||||||
const FRIENDING_HAPTIC_STRENGTH = 0.5;
|
const FRIENDING_HAPTIC_STRENGTH = 0.5;
|
||||||
const FRIENDING_SUCCESS_HAPTIC_STRENGTH = 1.0;
|
const FRIENDING_SUCCESS_HAPTIC_STRENGTH = 1.0;
|
||||||
const HAPTIC_DURATION = 20;
|
const HAPTIC_DURATION = 20;
|
||||||
|
const MODEL_URL = "http://hifi-content.s3.amazonaws.com/alan/dev/Test/sphere-3-color.fbx";
|
||||||
|
const TEXTURES = [
|
||||||
|
{"Texture": "http://hifi-content.s3.amazonaws.com/alan/dev/Test/sphere-3-color.fbx/sphere-3-color.fbm/green-50pct-opaque-64.png"},
|
||||||
|
{"Texture": "http://hifi-content.s3.amazonaws.com/alan/dev/Test/sphere-3-color.fbx/sphere-3-color.fbm/blue-50pct-opaque-64.png"},
|
||||||
|
{"Texture": "http://hifi-content.s3.amazonaws.com/alan/dev/Test/sphere-3-color.fbx/sphere-3-color.fbm/red-50pct-opaque-64.png"}
|
||||||
|
];
|
||||||
|
|
||||||
var currentHand;
|
var currentHand;
|
||||||
var state = STATES.inactive;
|
var state = STATES.inactive;
|
||||||
var friendingInterval;
|
var friendingInterval;
|
||||||
var entity;
|
var overlay;
|
||||||
var animHandlerId;
|
var animHandlerId;
|
||||||
var entityDimensionMultiplier = 1.0;
|
var entityDimensionMultiplier = 1.0;
|
||||||
var friendingId;
|
var friendingId;
|
||||||
|
var friendingHand;
|
||||||
|
|
||||||
function debug() {
|
function debug() {
|
||||||
var stateString = "<" + STATE_STRINGS[state] + ">";
|
var stateString = "<" + STATE_STRINGS[state] + ">";
|
||||||
var versionString = "v" + version;
|
var versionString = "v" + version;
|
||||||
print.apply(null, [].concat.apply([label, versionString, stateString, friendingId], [].map.call(arguments, JSON.stringify)));
|
var friending = "[" + friendingId + "/" + friendingHand + "]";
|
||||||
|
print.apply(null, [].concat.apply([label, versionString, stateString, friending], [].map.call(arguments, JSON.stringify)));
|
||||||
}
|
}
|
||||||
|
|
||||||
function handToString(hand) {
|
function handToString(hand) {
|
||||||
|
@ -53,6 +60,16 @@ function handToString(hand) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function stringToHand(hand) {
|
||||||
|
if (hand == "RightHand") {
|
||||||
|
return Controller.Standard.RightHand;
|
||||||
|
} else if (hand == "LeftHand") {
|
||||||
|
return Controller.Standard.LeftHand;
|
||||||
|
}
|
||||||
|
debug("stringToHand called with bad hand string:", hand);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
function handToHaptic(hand) {
|
function handToHaptic(hand) {
|
||||||
if (hand === Controller.Standard.RightHand) {
|
if (hand === Controller.Standard.RightHand) {
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -62,11 +79,13 @@ function handToHaptic(hand) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This returns the position of the palm, really. Which relies on the avatar
|
||||||
|
// having the expected middle1 joint. TODO: fallback for when this isn't part
|
||||||
|
// of the avatar?
|
||||||
function getHandPosition(avatar, hand) {
|
function getHandPosition(avatar, hand) {
|
||||||
if (!hand) {
|
if (!hand) {
|
||||||
debug("calling getHandPosition with no hand!");
|
debug("calling getHandPosition with no hand! (returning avatar position but this is a BUG)");
|
||||||
return;
|
return avatar.position;
|
||||||
}
|
}
|
||||||
var jointName = handToString(hand) + "Middle1";
|
var jointName = handToString(hand) + "Middle1";
|
||||||
return avatar.getJointPosition(avatar.getJointIndex(jointName));
|
return avatar.getJointPosition(avatar.getJointIndex(jointName));
|
||||||
|
@ -92,33 +111,43 @@ function shakeHandsAnimation(animationProperties) {
|
||||||
// this is called frequently, but usually does nothing
|
// this is called frequently, but usually does nothing
|
||||||
function updateVisualization() {
|
function updateVisualization() {
|
||||||
if (state == STATES.inactive) {
|
if (state == STATES.inactive) {
|
||||||
if (entity) {
|
if (overlay) {
|
||||||
entity = Entities.deleteEntity(entity);
|
overlay = Overlays.deleteOverlay(overlay);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var color = ENTITY_COLORS[state-1];
|
var textures = TEXTURES[state-1];
|
||||||
var position = getHandPosition(MyAvatar, currentHand);
|
var position = getHandPosition(MyAvatar, currentHand);
|
||||||
|
|
||||||
// TODO: make the size scale with avatar, up to
|
// TODO: make the size scale with avatar, up to
|
||||||
// the actual size of MAX_AVATAR_DISTANCE
|
// the actual size of MAX_AVATAR_DISTANCE
|
||||||
var wrist = MyAvatar.getJointPosition(MyAvatar.getJointIndex(handToString(currentHand)));
|
var wrist = MyAvatar.getJointPosition(MyAvatar.getJointIndex(handToString(currentHand)));
|
||||||
var d = entityDimensionMultiplier * Vec3.distance(wrist, position);
|
var d = entityDimensionMultiplier * Vec3.distance(wrist, position);
|
||||||
var dimension = {x: d, y: d, z: d};
|
if (friendingId) {
|
||||||
if (!entity) {
|
// put the position between the 2 hands, if we have a friendingId
|
||||||
var props = {
|
var other = AvatarList.getAvatar(friendingId);
|
||||||
type: "Sphere",
|
if (other) {
|
||||||
color: color,
|
var otherHand = getHandPosition(other, stringToHand(friendingHand));
|
||||||
position: position,
|
position = Vec3.sum(position, Vec3.multiply(0.5, Vec3.subtract(otherHand, position)));
|
||||||
dimensions: dimension
|
|
||||||
}
|
}
|
||||||
entity = Entities.addEntity(props);
|
}
|
||||||
|
var dimension = {x: d, y: d, z: d};
|
||||||
|
if (!overlay) {
|
||||||
|
var props = {
|
||||||
|
url: MODEL_URL,
|
||||||
|
position: position,
|
||||||
|
dimensions: dimension,
|
||||||
|
textures: textures
|
||||||
|
};
|
||||||
|
overlay = Overlays.addOverlay("model", props);
|
||||||
} else {
|
} else {
|
||||||
Entities.editEntity(entity, {dimensions: dimension, position: position, color: color});
|
Overlays.editOverlay(overlay, {textures: textures});
|
||||||
|
Overlays.editOverlay(overlay, {dimensions: dimension, position: position});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function findNearbyAvatars(nearestOnly) {
|
function findNearbyAvatars(nearestOnly) {
|
||||||
var handPos = getHandPosition(MyAvatar, currentHand);
|
var handPos = getHandPosition(MyAvatar, currentHand);
|
||||||
var minDistance = MAX_AVATAR_DISTANCE;
|
var minDistance = MAX_AVATAR_DISTANCE;
|
||||||
|
@ -141,6 +170,15 @@ function findNearbyAvatars(nearestOnly) {
|
||||||
return nearbyAvatars;
|
return nearbyAvatars;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// As currently implemented, we select the closest avatar (if close enough) and send
|
||||||
|
// them a friendRequest, or if someone already has sent us one, we just send the friendAck
|
||||||
|
// back to them. If nobody is close enough or has sent us a friendRequest, we just wait
|
||||||
|
// transition to waiting and wait for a friendRequest. If the 2 people who want to connect
|
||||||
|
// are both somewhat out of range when they initiate the shake, then neither gets a message
|
||||||
|
// and they both just stand there with their hands out.
|
||||||
|
// Ideally we'd either show that (so they ungrip/regrip and adjust position), or do what I
|
||||||
|
// initially did and start an interval to look for nearby avatars. The issue with the latter
|
||||||
|
// is this introduces some race condition we may need to handle (hence I didn't do it yet).
|
||||||
function startHandshake(fromKeyboard) {
|
function startHandshake(fromKeyboard) {
|
||||||
if (fromKeyboard) {
|
if (fromKeyboard) {
|
||||||
debug("adding animation");
|
debug("adding animation");
|
||||||
|
@ -170,7 +208,7 @@ function startHandshake(fromKeyboard) {
|
||||||
messageSend({
|
messageSend({
|
||||||
key: "friendRequest",
|
key: "friendRequest",
|
||||||
id: friendingId,
|
id: friendingId,
|
||||||
hand: handToString(nearestAvatar.hand)
|
hand: handToString(currentHand)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,9 +217,14 @@ function startHandshake(fromKeyboard) {
|
||||||
function endHandshake() {
|
function endHandshake() {
|
||||||
debug("ending handshake for", currentHand);
|
debug("ending handshake for", currentHand);
|
||||||
currentHand = undefined;
|
currentHand = undefined;
|
||||||
|
// note that setting the state to inactive should really
|
||||||
|
// only be done here, unless we change how the triggering works,
|
||||||
|
// as we ignore the key release event when inactive. See updateTriggers
|
||||||
|
// below.
|
||||||
state = STATES.inactive;
|
state = STATES.inactive;
|
||||||
if (friendingInterval) {
|
if (friendingInterval) {
|
||||||
friendingId = undefined;
|
friendingId = undefined;
|
||||||
|
friendingHand = undefined;
|
||||||
friendingInterval = Script.clearInterval(friendingInterval);
|
friendingInterval = Script.clearInterval(friendingInterval);
|
||||||
// send done to let friend know you are not making friends now
|
// send done to let friend know you are not making friends now
|
||||||
messageSend({
|
messageSend({
|
||||||
|
@ -211,6 +254,7 @@ function updateTriggers(value, fromKeyboard, hand) {
|
||||||
startHandshake(fromKeyboard);
|
startHandshake(fromKeyboard);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// TODO: should we end handshake even when inactive? Ponder
|
||||||
if (state != STATES.inactive) {
|
if (state != STATES.inactive) {
|
||||||
endHandshake();
|
endHandshake();
|
||||||
} else {
|
} else {
|
||||||
|
@ -247,6 +291,7 @@ function makeFriends(id) {
|
||||||
Script.setTimeout(function () {
|
Script.setTimeout(function () {
|
||||||
state = STATES.waiting;
|
state = STATES.waiting;
|
||||||
friendingId = undefined;
|
friendingId = undefined;
|
||||||
|
friendingHand = undefined;
|
||||||
entityDimensionMultiplier = 1.0;
|
entityDimensionMultiplier = 1.0;
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
@ -270,7 +315,8 @@ function startFriending(id, hand) {
|
||||||
});
|
});
|
||||||
|
|
||||||
friendingInterval = Script.setInterval(function () {
|
friendingInterval = Script.setInterval(function () {
|
||||||
entityDimensionMultiplier = 1.0 + 2.0 * ++count * FRIENDING_INTERVAL / FRIENDING_TIME;
|
count += 1;
|
||||||
|
entityDimensionMultiplier = 1.0 + 2.0 * count * FRIENDING_INTERVAL / FRIENDING_TIME;
|
||||||
if (state != STATES.friending) {
|
if (state != STATES.friending) {
|
||||||
debug("stopping friending interval, state changed");
|
debug("stopping friending interval, state changed");
|
||||||
friendingInterval = Script.clearInterval(friendingInterval);
|
friendingInterval = Script.clearInterval(friendingInterval);
|
||||||
|
@ -282,6 +328,7 @@ function startFriending(id, hand) {
|
||||||
key: "done"
|
key: "done"
|
||||||
});
|
});
|
||||||
friendingId = undefined;
|
friendingId = undefined;
|
||||||
|
friendingHand = undefined;
|
||||||
startHandshake();
|
startHandshake();
|
||||||
} else if (count > FRIENDING_TIME/FRIENDING_INTERVAL) {
|
} else if (count > FRIENDING_TIME/FRIENDING_INTERVAL) {
|
||||||
debug("made friends with " + id);
|
debug("made friends with " + id);
|
||||||
|
@ -324,11 +371,13 @@ function messageHandler(channel, messageString, senderID) {
|
||||||
case "friendRequest":
|
case "friendRequest":
|
||||||
if (state == STATES.inactive && message.id == MyAvatar.sessionUUID) {
|
if (state == STATES.inactive && message.id == MyAvatar.sessionUUID) {
|
||||||
friendingId = senderID;
|
friendingId = senderID;
|
||||||
|
friendingHand = message.hand;
|
||||||
} else if (state == STATES.waiting && message.id == MyAvatar.sessionUUID && (!friendingId || friendingId == senderID)) {
|
} else if (state == STATES.waiting && message.id == MyAvatar.sessionUUID && (!friendingId || friendingId == senderID)) {
|
||||||
// you were waiting for a friend request, so send the ack. Or, you and the other
|
// you were waiting for a friend request, so send the ack. Or, you and the other
|
||||||
// guy raced and both send friendRequests. Handle that too
|
// guy raced and both send friendRequests. Handle that too
|
||||||
if (!friendingId) {
|
if (!friendingId) {
|
||||||
friendingId = senderID;
|
friendingId = senderID;
|
||||||
|
friendingHand = message.hand;
|
||||||
}
|
}
|
||||||
messageSend({
|
messageSend({
|
||||||
key: "friendAck",
|
key: "friendAck",
|
||||||
|
@ -343,6 +392,7 @@ function messageHandler(channel, messageString, senderID) {
|
||||||
if (state == STATES.waiting && message.id == MyAvatar.sessionUUID && (!friendingId || friendingId == senderID)) {
|
if (state == STATES.waiting && message.id == MyAvatar.sessionUUID && (!friendingId || friendingId == senderID)) {
|
||||||
// start friending...
|
// start friending...
|
||||||
friendingId = senderID;
|
friendingId = senderID;
|
||||||
|
friendingHand = message.hand;
|
||||||
startFriending(senderID, message.hand);
|
startFriending(senderID, message.hand);
|
||||||
}
|
}
|
||||||
// TODO: check to see if we are waiting for this but the person we are friending sent it to
|
// TODO: check to see if we are waiting for this but the person we are friending sent it to
|
||||||
|
@ -371,6 +421,7 @@ function messageHandler(channel, messageString, senderID) {
|
||||||
// value for isKeyboard, as we should not change the animation
|
// value for isKeyboard, as we should not change the animation
|
||||||
// state anyways (if any)
|
// state anyways (if any)
|
||||||
friendingId = undefined;
|
friendingId = undefined;
|
||||||
|
friendingHand = undefined;
|
||||||
startHandshake();
|
startHandshake();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -378,6 +429,7 @@ function messageHandler(channel, messageString, senderID) {
|
||||||
// do nothing (so you see the red for a bit)
|
// do nothing (so you see the red for a bit)
|
||||||
if (state != STATES.makingFriends && friendingId == senderID) {
|
if (state != STATES.makingFriends && friendingId == senderID) {
|
||||||
friendingId = undefined;
|
friendingId = undefined;
|
||||||
|
friendingHand = undefined;
|
||||||
if (state != STATES.inactive) {
|
if (state != STATES.inactive) {
|
||||||
startHandshake();
|
startHandshake();
|
||||||
}
|
}
|
||||||
|
@ -386,6 +438,7 @@ function messageHandler(channel, messageString, senderID) {
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
debug("unknown message", message);
|
debug("unknown message", message);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue