(function() { var style = { outlineUnoccludedColor: { red: 0, green: 255, blue: 250 }, outlineOccludedColor: { red: 0, green: 255, blue: 250 }, fillUnoccludedColor: { red: 255, green: 0, blue: 0 }, fillOccludedColor: { red: 255, green: 0, blue: 0 }, outlineUnoccludedAlpha: 1.0, outlineOccludedAlpha: 1.0, fillUnoccludedAlpha: 1.0, fillOccludedAlpha: 1.0, outlineWidth: 5, isOutlineSmooth: true } Selection.enableListHighlight("AvatarHighlight", style); var lastAvatarID; function getUserNameForAvatar(avatarID) { var paldata = AvatarList.getPalData().data; for (var i = 0; i < paldata.length; i++) { if (paldata[i].sessionUUID === avatarID) { return paldata[i].sessionDisplayName; } } } function getNewTextBox(avatarID, jointIdx) { var textColor = { red: 255, green: 255, blue: 255 }; var bgrColor = { red: 0, green: 0, blue: 0 }; var avatar = AvatarList.getAvatar(avatarID); var jointName = avatar.jointNames[jointIdx]; var avatarName = avatarID == MyAvatar.sessionUUID ? "Me" : getUserNameForAvatar(avatarID); console.log(avatar); var avatarInfoBoxParams = { type: "Text", lifetime: 100, parentID: MyAvatar.sessionUUID, localPosition: { x: 0, y: MyAvatar.getTargetScale(), z: 0}, dimensions: { x: 1.6, y: 0.3, z: 0.01 }, lineHeight: 0.12, faceCamera: true, drawInFront: true, ignoreRayIntersection: true, text: "Avatar: " + avatarName + "\nJoint: " + jointName, billboardMode: "yaw", textColor: textColor, color: textColor, backgroundColor: bgrColor }; return Entities.addEntity(avatarInfoBoxParams); } var style = { outlineUnoccludedColor: { red: 0, green: 255, blue: 250 }, outlineOccludedColor: { red: 0, green: 255, blue: 250 }, fillUnoccludedColor: { red: 255, green: 0, blue: 0 }, fillOccludedColor: { red: 255, green: 0, blue: 0 }, outlineUnoccludedAlpha: 1.0, outlineOccludedAlpha: 1.0, fillUnoccludedAlpha: 1.0, fillOccludedAlpha: 1.0, outlineWidth: 5, isOutlineSmooth: true } //Selection.enableListHighlight("test", style); var infoBox; var mousePressEvent = function(event) { var pickRay = Camera.computePickRay(event.x, event.y); //console.log("Direction " + pickRay.direction.x + " " + pickRay.direction.y + " " + pickRay.direction.z + " origin: " + pickRay.origin.x + " " + pickRay.origin.y + " " + pickRay.origin.z); var intersection = AvatarManager.findRayIntersection({origin: pickRay.origin, direction: pickRay.direction}, [], [], false); cleanup(); if (intersection.intersects) { lastAvatarID = intersection.avatarID; infoBox = getNewTextBox(intersection.avatarID, intersection.jointIndex); Selection.addToSelectedItemsList("AvatarHighlight", "avatar", intersection.avatarID); // var avatar = AvatarList.getAvatar(intersection.avatarID); // console.log(avatar.jointNames[intersection.jointIndex] + " ID:" + intersection.avatarID); //Selection.addToSelectedItemsList("test", "avatar", intersection.avatarID); } else { //Selection.clearSelectedItemsList("test"); } } function cleanup() { Selection.removeFromSelectedItemsList("AvatarHighlight", "avatar", lastAvatarID); Entities.deleteEntity(infoBox); } Controller.mousePressEvent.connect(mousePressEvent); Script.scriptEnding.connect(cleanup); })();