Last active
September 5, 2018 01:03
-
-
Save birarda/7ea6ac85116d8b83144dc098c2bf4969 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
// | |
// bot.js | |
// examples | |
// | |
// Created by Stephen Birarda on 2/20/14. | |
// Modified by Philip on 3/3/14 | |
// Copyright 2014 High Fidelity, Inc. | |
// | |
// This is an example script that demonstrates an NPC avatar. | |
// | |
// Distributed under the Apache License, Version 2.0. | |
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html | |
// | |
function getRandomFloat(min, max) { | |
return Math.random() * (max - min) + min; | |
} | |
function getRandomInt (min, max) { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
function printVector(string, vector) { | |
print(string + " " + vector.x + ", " + vector.y + ", " + vector.z); | |
} | |
var CHANCE_OF_MOVING = 0.005; | |
var CHANCE_OF_SOUND = 0.0005; | |
var CHANCE_OF_HEAD_TURNING = 0.00; | |
var CHANCE_OF_BIG_MOVE = 0.1; | |
var CHANCE_OF_WAVING = 0.001; | |
var isMoving = false; | |
var isTurningHead = false; | |
var isPlayingAudio = false; | |
var isWaving = false; | |
var waveFrequency = 0.0; | |
var waveAmplitude = 0.0; | |
var X_MIN = -27.0; | |
var X_MAX = 7.0; | |
var Z_MIN = -30; | |
var Z_MAX = 24; | |
var Y_PELVIS = -10; | |
var SPINE_JOINT_NUMBER = 13; | |
var SHOULDER_JOINT_NUMBER = 17; | |
var ELBOW_JOINT_NUMBER = 19; | |
var JOINT_R_HIP = 2; | |
var JOINT_R_KNEE = 3; | |
var JOINT_L_HIP = 7; | |
var JOINT_L_KNEE = 8; | |
var MOVE_RANGE_SMALL = 0.5; | |
var MOVE_RANGE_BIG = Math.max(X_MAX - X_MIN, Z_MAX - Z_MIN) / 2.0; | |
var TURN_RANGE = 70.0; | |
var STOP_TOLERANCE = 0.05; | |
var MOVE_RATE = 0.05; | |
var TURN_RATE = 0.15; | |
var PITCH_RATE = 0.20; | |
var PITCH_RANGE = 30.0; | |
var firstPosition = { x: getRandomFloat(X_MIN, X_MAX), y: Y_PELVIS, z: getRandomFloat(Z_MIN, Z_MAX) }; | |
var targetPosition = { x: 0, y: 0, z: 0 }; | |
var targetDirection = { x: 0, y: 0, z: 0, w: 0 }; | |
var currentDirection = { x: 0, y: 0, z: 0, w: 0 }; | |
var targetHeadPitch = 0.0; | |
var walkFrequency = 5.0; | |
var walkAmplitude = 45.0; | |
var cumulativeTime = 0.0; | |
var sounds = []; | |
loadSounds(); | |
function clamp(val, min, max){ | |
return Math.max(min, Math.min(max, val)) | |
} | |
// 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); | |
console.log("Playing sound " + whichSound); | |
Agent.playAvatarSound(sounds[whichSound]); | |
} | |
} | |
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" | |
]; | |
Avatar.skeletonModelURL = AVATARS_ARRAY[Math.floor(Math.random() * AVATARS_ARRAY.length)]; | |
Agent.isAvatar = true; | |
Agent.isListeningToAudioStream = true; | |
// change the avatar's position to the random one | |
Avatar.position = firstPosition; | |
printVector("New bot, position = ", Avatar.position); | |
function updateBehavior(deltaTime) { | |
if (Math.random() < CHANCE_OF_SOUND) { | |
playRandomSound(); | |
} | |
} | |
Script.update.connect(updateBehavior); | |
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 = "http://hifi-public.s3.amazonaws.com/sounds/cocktail-party/"; | |
for (var i = 0; i < sound_filenames.length; i++) { | |
sounds.push(SoundCache.getSound(SOUND_BASE_URL + sound_filenames[i])); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment