content/hifi-content/simon/BetterClientSimulationXaos.js
2022-02-14 02:04:11 +01:00

361 lines
15 KiB
JavaScript

//
// 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 AVATAR =
"https://s3-us-west-1.amazonaws.com/xaotica/XaosFresnelDress/XaosFresnelDress-33.fst";
var AVATAR_WEARABLE =
"http://mpassets.highfidelity.com/d503c1d4-a4f7-41d5-a558-66df60a6b229-v1/futvrelandHeadband.fbx";
var WEARABLE_CHANGE_PROB = 2; // %
var AVATAR_URL = AVATAR;
var RECORDINGS_ARRAY = [
"http://hifi-content.s3.amazonaws.com/simon/XaosFlowAvatar1.hfr"
];
var RECORDING_URL = RECORDINGS_ARRAY[0];
//print("RANDOM RECORDING SELECTED:" + RECORDING_URL);
// not quite what I want...
// For the 'OpenWorld' content:
var LOCATIONS_ARRAY = [
{ min_x: -15, max_x: 25, y:-1.0, min_z: -20, max_z: +20 }
];
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;
var wearableAttached = false;
// Disable the privacy bubble
Users.disableIgnoreRadius();
// Set position here if playFromCurrentLocation is true
Avatar.position = LOCATION;
Avatar.orientation = Quat.fromPitchYawRollDegrees(1, 0, 0);
Avatar.scale = 1.0;
Agent.isAvatar = true;
var entityJSON = {
"properties": {
"acceleration": {
"blue": 0,
"green": 0,
"red": 0,
"x": 0,
"y": 0,
"z": 0
},
"actionData": "",
"age": 8.7204008102417,
"ageAsText": "0 hours 0 minutes 8 seconds",
"angularDamping": 0.39346998929977417,
"angularVelocity": {
"blue": 0,
"green": 0,
"red": 0,
"x": 0,
"y": 0,
"z": 0
},
"animation": {
"allowTranslation": true,
"currentFrame": 0,
"firstFrame": 0,
"fps": 30,
"hold": false,
"lastFrame": 100000,
"loop": true,
"running": false,
"url": ""
},
"boundingBox": {
"brn": {
"blue": -1.100000023841858,
"green": 0.8999999761581421,
"red": -0.10000000149011612,
"x": -0.10000000149011612,
"y": 0.8999999761581421,
"z": -1.100000023841858
},
"center": {
"blue": -1,
"green": 1,
"red": 0,
"x": 0,
"y": 1,
"z": -1
},
"dimensions": {
"blue": 0.20000004768371582,
"green": 0.20000004768371582,
"red": 0.20000000298023224,
"x": 0.20000000298023224,
"y": 0.20000004768371582,
"z": 0.20000004768371582
},
"tfl": {
"blue": -0.8999999761581421,
"green": 1.100000023841858,
"red": 0.10000000149011612,
"x": 0.10000000149011612,
"y": 1.100000023841858,
"z": -0.8999999761581421
}
},
"canCastShadow": true,
"certificateID": "",
"clientOnly": true,
"cloneAvatarEntity": false,
"cloneDynamic": false,
"cloneLifetime": 300,
"cloneLimit": 0,
"cloneOriginID": "{00000000-0000-0000-0000-000000000000}",
"cloneable": false,
"collidesWith": "static,dynamic,kinematic,myAvatar,otherAvatar,",
"collisionMask": 31,
"collisionSoundURL": "",
"collisionless": false,
"collisionsWillMove": false,
"compoundShapeURL": "",
"created": "2018-07-26T21:58:48Z",
"damping": 0.39346998929977417,
"density": 1000,
"description": "",
"dimensions": {
"blue": 0.20000000298023224,
"green": 0.20000000298023224,
"red": 0.20000000298023224,
"x": 0.20000000298023224,
"y": 0.20000000298023224,
"z": 0.20000000298023224
},
"dynamic": false,
"editionNumber": 0,
"entityInstanceNumber": 0,
"friction": 0.5,
"gravity": {
"blue": 0,
"green": 0,
"red": 0,
"x": 0,
"y": 0,
"z": 0
},
"href": "",
"id": "{05162d5d-5e65-4837-ad50-57041c8be427}",
"ignoreForCollisions": false,
"itemArtist": "",
"itemCategories": "",
"itemDescription": "",
"itemLicense": "",
"itemName": "",
"lifetime": 3600,
"limitedRun": 4294967295,
"localPosition": {
"blue": -1,
"green": 1,
"red": 0,
"x": 0,
"y": 1,
"z": -1
},
"localRotation": {
"w": 1,
"x": 0,
"y": 0,
"z": 0
},
"locked": false,
"marketplaceID": "",
"modelURL": "http://www.capondesign.com/EXternal/models/ironman/TonyV2.fst",
"name": "FloofEntity",
"naturalDimensions": {
"blue": 0.3754480481147766,
"green": 1.8120945692062378,
"red": 1.9409140348434448,
"x": 1.9409140348434448,
"y": 1.8120945692062378,
"z": 0.3754480481147766
},
"naturalPosition": {
"blue": 0.02164822816848755,
"green": 0.9060472846031189,
"red": -1.8835067749023438e-05,
"x": -1.8835067749023438e-05,
"y": 0.9060472846031189,
"z": 0.02164822816848755
},
"originalTextures": "{\n \"Tony_Stark_Beard_Diffuse\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Beard_Diffuse.png\",\n \"Tony_Stark_Beard_Gloss\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Beard_Gloss.png\",\n \"Tony_Stark_Beard_Normal\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Beard_Normal.png\",\n \"Tony_Stark_Beard_Specular\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Beard_Specular.png\",\n \"Tony_Stark_Body_Diffuse\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Body_Diffuse.png\",\n \"Tony_Stark_Body_Gloss\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Body_Gloss.png\",\n \"Tony_Stark_Body_Normal\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Body_Normal.png\",\n \"Tony_Stark_Body_Specular\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Body_Specular.png\",\n \"Tony_Stark_Bottom_Diffuse\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Bottom_Diffuse.png\",\n \"Tony_Stark_Bottom_Gloss\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Bottom_Gloss.png\",\n \"Tony_Stark_Bottom_Normal\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Bottom_Normal.png\",\n \"Tony_Stark_Bottom_Specular\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Bottom_Specular.png\",\n \"Tony_Stark_Eyewear_Diffuse\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Eyewear_Diffuse.png\",\n \"Tony_Stark_Eyewear_Gloss\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Eyewear_Gloss.png\",\n \"Tony_Stark_Eyewear_Normal\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Eyewear_Normal.png\",\n \"Tony_Stark_Eyewear_Specular\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Eyewear_Specular.png\",\n \"Tony_Stark_Hair_Diffuse\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Hair_Diffuse.png\",\n \"Tony_Stark_Hair_Gloss\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Hair_Gloss.png\",\n \"Tony_Stark_Hair_Normal\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Hair_Normal.png\",\n \"Tony_Stark_Hair_Specular\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Hair_Specular.png\",\n \"Tony_Stark_Moustache_Diffuse\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Moustache_Diffuse.png\",\n \"Tony_Stark_Moustache_Gloss\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Moustache_Gloss.png\",\n \"Tony_Stark_Moustache_Normal\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Moustache_Normal.png\",\n \"Tony_Stark_Moustache_Specular\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Moustache_Specular.png\",\n \"Tony_Stark_Shoes_Diffuse\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Shoes_Diffuse.png\",\n \"Tony_Stark_Shoes_Gloss\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Shoes_Gloss.png\",\n \"Tony_Stark_Shoes_Normal\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Shoes_Normal.png\",\n \"Tony_Stark_Shoes_Specular\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Shoes_Specular.png\",\n \"Tony_Stark_Top_Diffuse\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Top_Diffuse.png\",\n \"Tony_Stark_Top_Gloss\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Top_Gloss.png\",\n \"Tony_Stark_Top_Normal\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Top_Normal.png\",\n \"Tony_Stark_Top_Specular\": \"http://www.capondesign.com/EXternal/models/ironman/TonyV2/textures/Tony_Stark_Top_Specular.png\"\n}\n",
"owningAvatarID": "{b5229825-2c0b-4ef5-bcfc-913858ebe7b3}",
"parentID": "{b5229825-2c0b-4ef5-bcfc-913858ebe7b3}",
"parentJointIndex": 164,
"position": {
"blue": -1,
"green": 1,
"red": 0,
"x": 0,
"y": 1,
"z": -1
},
"queryAACube": {
"scale": 1.039230465888977,
"x": 8.594402313232422,
"y": 0.9403275847434998,
"z": -29.112281799316406
},
"registrationPoint": {
"blue": 0.5,
"green": 0.5,
"red": 0.5,
"x": 0.5,
"y": 0.5,
"z": 0.5
},
"relayParentJoints": true,
"renderInfo": {
"drawCalls": 9,
"hasTransparent": false,
"texturesCount": 27,
"texturesSize": 27525120,
"verticesCount": 25745
},
"restitution": 0.5,
"rotation": {
"w": 1,
"x": 0,
"y": 0,
"z": 0
},
"script": "",
"scriptTimestamp": 0,
"serverScripts": "",
"shapeType": "none",
"staticCertificateVersion": 0,
"textures": "",
"type": "Model",
"userData": "",
"velocity": {
"blue": 0,
"green": 0,
"red": 0,
"x": 0,
"y": 0,
"z": 0
},
"visible": true
}
};
var entityJSON2 =
{
"certificateID":"",
"clientOnly":true,
"created":{},
"dimensions":{"x":0.6481595039367676,"y":0.3168869614601135,"z":0.04202471300959587},
"editionNumber":106,
"id":{},
"itemArtist":{},
"itemCategories":{},
"itemDescription":{},
"itemName":{},
"lastEdited":1544477894762957,
"lastEditedBy":{},
"marketplaceID":"",
"modelURL": AVATAR_WEARABLE,
"name":{},
"owningAvatarID":{},
"parentID":{},
"parentJointIndex":164,
"position":{"x":0,"y":0.3100000023841858,"z":0.019999999552965164},
"queryAACube":{"scale":2.168097734451294,"x":-1.2640780210494995,"y":-1.1782119274139404,"z":-0.9400527477264404},"rotation":{"w":0.9999970197677612,"x":-9.329596650786698e-8,"y":-1.4711986295878887e-8,"z":4.540197551250458e-9},
"staticCertificateVersion":2,
"type":"Model",
"userData":{}};
// 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);
}
});
count = 300; // This is necessary to wait for the audio mixer to connect
function update(event) {
if (count > 0) {
count--;
return;
}
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));
}
var randomPercent = Math.random() * 100;
//if (randomPercent < WEARABLE_CHANGE_PROB) {
if (false) {
if (wearableAttached) {
Avatar.setAvatarEntityData({});
} else {
print("ATTACHING WEARABLE");
//print(Avatar.attach(AVATAR_WEARABLE, 'Head'));
Avatar.setAvatarEntityData({ "05162d5d-5e65-4837-ad50-57041c8be427" : entityJSON });
}
wearableAttached = !wearableAttached;
}
if (!Recording.isPlaying()) {
Script.update.disconnect(update);
}
}