Last active
September 7, 2018 00:33
-
-
Save birarda/41a3058910401738de2af69655199c73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// BetterClientSimulationBotFromRecording.js | |
// examples | |
// | |
// Created by Brad Hefta-Gaub on 2/6/17. | |
// Copyright 2017 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 WANT_DEBUGGING = false; | |
randFloat = function(low, high) { | |
return low + Math.random() * (high - low); | |
} | |
var AVATARS_ARRAY = [ | |
"http://mpassets.highfidelity.com/0c2c264b-2fd2-46a4-bf80-de681881f66b-v1/F_MotRac.fst", | |
"http://mpassets.highfidelity.com/bd80a6d7-7173-489e-87c6-f7ee56e65530-v1/M_RetFut.fst", | |
"http://mpassets.highfidelity.com/47c8d706-d486-4c2d-afcc-70d4e1e25117-v1/M_RetSpaSuit.fst", | |
"http://mpassets.highfidelity.com/548d0792-0bac-4933-bbfc-57d71912d77e-v1/M_OutMer.fst", | |
"http://mpassets.highfidelity.com/13277c09-892f-4a5e-b9a5-8994a37d68bf-v1/F_WasWar.fst", | |
"http://mpassets.highfidelity.com/2d384111-0f0e-42e2-b800-66bfcab4aefb-v1/F_VooQue.fst", | |
"http://mpassets.highfidelity.com/57e4d1cd-9f52-4c95-9051-326f9bb114ea-v1/F_SteAvi.fst", | |
"http://mpassets.highfidelity.com/da2ad4cd-47d4-41da-b764-41f39ff77e30-v1/F_JerGir.fst", | |
"http://mpassets.highfidelity.com/96c747ab-f71b-44ee-8eb9-d19fc9593dda-v1/F_CatBur.fst", | |
"http://mpassets.highfidelity.com/ede82c38-c66e-4f67-9e0b-0bb0782db18f-v1/M_WesOut.fst", | |
"http://mpassets.highfidelity.com/8872ae86-a763-4db3-8373-d27514c1481e-v1/M_VinAvi.fst", | |
"http://mpassets.highfidelity.com/faf505f1-4fd1-4ed2-8909-816af246c48f-v1/M_VicGen.fst", | |
"http://mpassets.highfidelity.com/d807a7d2-5122-4436-a6f9-3173c94d1c49-v1/M_SuaGen.fst", | |
"http://mpassets.highfidelity.com/1dd41735-06f4-45a3-9ec0-d05215ace77b-v1/M_MarSen.fst", | |
"http://mpassets.highfidelity.com/2cad3894-8ab3-4ba5-a723-0234f93fbd6a-v1/M_BowBea.fst", | |
"http://mpassets.highfidelity.com/cf0eb1be-9ec7-4756-8eaf-ac8f3ec09eba-v1/F_ClaDef.fst", | |
"http://mpassets.highfidelity.com/0cedeca3-c1a4-4be9-9fd5-dad716afcc7e-v1/F_Cyria.fst", | |
"http://mpassets.highfidelity.com/dc55803b-9215-47dd-9408-eb835dac4082-v1/F_ParGir.fst", | |
"http://mpassets.highfidelity.com/775a8fb3-cfe7-494d-b603-a0a2d6910e55-v1/F_VinCov.fst", | |
"http://mpassets.highfidelity.com/eba0d8f8-aa72-4a6b-ab64-4d3fd4695b20-v1/F_VogHei.fst" | |
]; | |
var AVATAR_URL = AVATARS_ARRAY[Math.floor(Math.random() * AVATARS_ARRAY.length)]; | |
print("RANDOM AVATAR SELECTED:" + AVATAR_URL); | |
var RECORDINGS_ARRAY = [ | |
// "eventer1.hfr", | |
// "cop1.hfr", | |
// "cop2.hfr", | |
// "waiting1.hfr", | |
// "waiting2.hfr", | |
// "waiting3.hfr", | |
// "waiting4.hfr", | |
// "waiting5.hfr", | |
// "waiting6.hfr", | |
// // "waiting7.hfr", | |
// "waiting8.hfr", | |
// // "waiting10.hfr", | |
// "bot1.hfr", | |
// "bot2.hfr", | |
// "bot3.hfr", | |
// "bot4.hfr", | |
// "check_12.hfr", | |
// // "peanuts.hfr", | |
// "claude.hfr", | |
// "usher2.hfr", | |
// "usher1.hfr", | |
"usher3.hfr", | |
// "jim.hfr" | |
]; | |
var RECORDING_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Event%20/NPC%27s/" + RECORDINGS_ARRAY[Math.floor(Math.random() * RECORDINGS_ARRAY.length)]; | |
print("RANDOM RECORDING SELECTED:" + RECORDING_URL); | |
var LOCATIONS_ARRAY = [{ min_x: -27, max_x: 7, y: -10.5, min_z: 24, max_z: -29}]; | |
var LOCATION_PARAMS = LOCATIONS_ARRAY[Math.floor(Math.random() * LOCATIONS_ARRAY.length)]; | |
var LOCATION = { x: randFloat(LOCATION_PARAMS.min_x, LOCATION_PARAMS.max_x), y: LOCATION_PARAMS.y, z: randFloat(LOCATION_PARAMS.min_z, LOCATION_PARAMS.max_z) }; | |
Vec3.print("RANDOM LOCATION SELECTED:", LOCATION); | |
var playFromCurrentLocation = true; | |
var loop = true; | |
// Disable the privacy bubble | |
Users.disableIgnoreRadius(); | |
// Set position here if playFromCurrentLocation is true | |
Avatar.position = LOCATION; | |
Avatar.orientation = Quat.fromPitchYawRollDegrees(0, 0, 0); | |
Avatar.scale = 1.0; | |
Agent.isAvatar = true; | |
// make the agent "listen" to the audio stream to cause additional audio-mixer load, technically this isn't needed when you're playing a recording | |
// but if you switch to a non-recording bot, you will need this, so we can leave this. | |
Agent.isListeningToAudioStream = true; | |
Avatar.skeletonModelURL = AVATAR_URL; // FIXME - currently setting an avatar while playing a recording doesn't work it will be ignored | |
Recording.loadRecording(RECORDING_URL, function(success) { | |
if (success) { | |
Script.update.connect(update); | |
} else { | |
print("Failed to load recording from " + RECORDING_URL); | |
} | |
}); | |
var CHANCE_OF_SOUND = 0.00005; | |
var sounds = []; | |
loadSounds(); | |
function loadSounds() { | |
var sound_filenames = ["AB1.wav", "Anchorman2.wav", "B1.wav", "B1.wav", "Bale1.wav", "Bandcamp.wav", | |
"Big1.wav", "Big2.wav", "Brian1.wav", "Buster1.wav", "CES1.wav", "CES2.wav", "CES3.wav", "CES4.wav", | |
"Carrie1.wav", "Carrie3.wav", "Charlotte1.wav", "EN1.wav", "EN2.wav", "EN3.wav", "Eugene1.wav", "Francesco1.wav", | |
"Italian1.wav", "Japanese1.wav", "Leigh1.wav", "Lucille1.wav", "Lucille2.wav", "MeanGirls.wav", "Murray2.wav", | |
"Nigel1.wav", "PennyLane.wav", "Pitt1.wav", "Ricardo.wav", "SN.wav", "Sake1.wav", "Samantha1.wav", "Samantha2.wav", | |
"Spicoli1.wav", "Supernatural.wav", "Swearengen1.wav", "TheDude.wav", "Tony.wav", "Triumph1.wav", "Uma1.wav", | |
"Walken1.wav", "Walken2.wav", "Z1.wav", "Z2.wav" | |
]; | |
var SOUND_BASE_URL = "https://s3.amazonaws.com/hifi-public/sounds/cocktail-party/"; | |
for (var i = 0; i < sound_filenames.length; i++) { | |
sounds.push(SoundCache.getSound(SOUND_BASE_URL + sound_filenames[i])); | |
} | |
} | |
// Play a random sound from a list of conversational audio clips | |
var AVERAGE_AUDIO_LENGTH = 8000; | |
function playRandomSound() { | |
if (!Agent.isPlayingAvatarSound) { | |
var whichSound = Math.floor((Math.random() * sounds.length) % sounds.length); | |
Agent.playAvatarSound(sounds[whichSound]); | |
} | |
} | |
count = 300; // Randomly wait some period of time before starting the recording | |
function update(event) { | |
if (count > 0) { | |
count--; | |
return; | |
} | |
if (Math.random() < CHANCE_OF_SOUND) { | |
playRandomSound(); | |
} | |
if (count == 0) { | |
Recording.setPlayFromCurrentLocation(playFromCurrentLocation); | |
Recording.setPlayerLoop(loop); | |
Recording.setPlayerUseDisplayName(true); | |
Recording.setPlayerUseAttachments(true); | |
Recording.setPlayerUseHeadModel(false); | |
Recording.setPlayerUseSkeletonModel(false); // FIXME - this would allow you to override the recording avatar, but that's not currently working | |
Recording.startPlaying(); | |
Vec3.print("Playing from ", Avatar.position); | |
count--; | |
} else if (WANT_DEBUGGING) { | |
count = 100; | |
Vec3.print("Avatar at: ", Avatar.position); | |
Quat.print("Avatar head orientation: ", Avatar.headOrientation); | |
print("outbound:" | |
+" GP: " + Avatar.getDataRate("globalPositionOutbound").toFixed(2) + "\n" | |
+" LP: " + Avatar.getDataRate("localPositionOutbound").toFixed(2) + "\n" | |
+" BB: " + Avatar.getDataRate("avatarBoundingBoxOutbound").toFixed(2) + "\n" | |
+" AO: " + Avatar.getDataRate("avatarOrientationOutbound").toFixed(2) + "\n" | |
+" AS: " + Avatar.getDataRate("avatarScaleOutbound").toFixed(2) + "\n" | |
+" LA: " + Avatar.getDataRate("lookAtPositionOutbound").toFixed(2) + "\n" | |
+" AL: " + Avatar.getDataRate("audioLoudnessOutbound").toFixed(2) + "\n" | |
+" SW: " + Avatar.getDataRate("sensorToWorkMatrixOutbound").toFixed(2) + "\n" | |
+" AF: " + Avatar.getDataRate("additionalFlagsOutbound").toFixed(2) + "\n" | |
+" PI: " + Avatar.getDataRate("parentInfoOutbound").toFixed(2) + "\n" | |
+" FT: " + Avatar.getDataRate("faceTrackerOutbound").toFixed(2) + "\n" | |
+" JD: " + Avatar.getDataRate("jointDataOutbound").toFixed(2)); | |
} | |
if (!Recording.isPlaying()) { | |
Script.update.disconnect(update); | |
} | |
// Avatar.displayName = "Bot_RAND" + randFloat(LOCATION_PARAMS.min_x, LOCATION_PARAMS.max_x); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment