randFloat = function(low, high) { return low + Math.random() * (high - low); } var baseURL = "https://hifi-content.s3.amazonaws.com/milad/ROLC/Organize/Projects/Testing/Flow/out/hfr/"; // Link to get the urls from var GOOGLE_SHEET_URL = "https://script.googleusercontent.com/a/macros/highfidelity.io/echo?user_content_key=z30W_Z9rqfb41pGEoxCkUM9yv8ZN8mxWuMyDWUHroj3cJ65OTSWNE_Zq7wvrTybnnFtRp6azMkya2K4Hj_UvG2HA9j2tP4Hjm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_nRPgeZU6HP_Ok_bZ6q4uc2IEwUGUhs3tubd_SaoYEJGc6Y4WQVrmGLClD6RzMAfZPxqtsdMQ32tpzl66ygAELl7JpluoKw78VudcD_Dja5DuJzk35EV1vQ&lib=MzB5vcFo1OT_VNOUwG7287OYoCQvnAuFY"; var rand = 10000; var min = 2000; var timeoutPeriod = Math.floor(Math.random()*rand)+min; var sheetXHR; Script.setTimeout(function(){ //console.log("about to run XHR"); sheetXHR = new XHR(GOOGLE_SHEET_URL, sheetSuccess, sheetFailure); }, timeoutPeriod); var TABLE = []; var TOTAL_TO_GRAB = 100; function XHR(url, successCb, failureCb, TIMEOUT) { //print("XHR: request url = " + url); var self = this; this.url = url; this.successCb = successCb; this.failureCb = failureCb; this.req = new XMLHttpRequest(); this.req.open("GET", url, true); this.req.timeout = TIMEOUT; this.req.ontimeout = function () { if (self.failureCb) { self.failureCb(0, "timeout"); } }; this.req.onreadystatechange = function () { if (self.req.readyState === self.req.DONE) { if (self.req.status === 200 || self.req.status === 203) { if (self.successCb) { self.successCb(self.req.responseText); } } else { if (self.failureCb) { self.failureCb(self.req.status, "done"); } } } }; this.req.send(); } function baseName(str) { var base = new String(str).substring(str.lastIndexOf('/') + 1); if (base.lastIndexOf(".") !== -1) { base = base.substring(0, base.lastIndexOf(".")); } return base; } function sheetFailure(status, reason) { //console.log("sheetFailure status code = " + status + ", reason = " + reason); } function sheetSuccess(response) { //console.log("sheetSuccess status, = "); TABLE = JSON.parse(response); TABLE.shift(); // strip off the header row. for (var i = 0; i < TOTAL_TO_GRAB; i++){ TABLE.map(function(recording){ return baseName(TABLE[i].avatar_HFR); }) } var randomIndex = Math.floor((Math.random() * TABLE.length) % TABLE.length); var RECORDING_URL = TABLE[randomIndex].avatar_HFR; var LOCATIONS_ARRAY = [{ min_x: -7, max_x: 17, y: -13.5, min_z: 42, max_z: 73}]; 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); // Disable the privacy bubble Users.disableIgnoreRadius(); // Set position here if playFromCurrentLocation is true Avatar.position = LOCATION; Avatar.orientation = Quat.fromPitchYawRollDegrees(0, randFloat(0, 360), 0); Avatar.scale = 1.0; Agent.isAvatar = true; Recording.loadRecording(RECORDING_URL, function(success) { if (success) { Script.update.connect(update); } else { // print("Failed to load recording from " + RECORDING_URL); } }); } count = 300; // Randomly wait some period of time before starting the recording function update(event) { if (count > 0) { count--; return; } if (count == 0) { Recording.setPlayFromCurrentLocation(true); Recording.setPlayerLoop(true); Recording.startPlaying(); //Vec3.print("Playing from ", Avatar.position); count--; } EntityViewer.setPosition(Avatar.position); EntityViewer.setOrientation(Avatar.orientation); EntityViewer.queryOctree(); if (!Recording.isPlaying()) { Script.update.disconnect(update); } }