content/hifi-public/birarda/oc-scripts/bot3.js
Dale Glass 0d14e5a379 Initial data.
Needs a lot of cleanup. Data has been de-duplicated, and where identical copies existed, one of them
has been replaced with a symlink.

Some files have been excluded, such as binaries, installers and debug dumps. Some of that may still
be present.
2022-02-13 18:59:11 +01:00

161 lines
No EOL
4.5 KiB
JavaScript

//
// ControlledAC.js
// examples
//
// Created by Clément Brisset on 8/28/14.
// Copyright 2014 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
//
// Set the following variables to the values needed
var filename = "https://s3-us-west-1.amazonaws.com/highfidelity-public/ozan/recordings/ozan_comedy_reaction_mono.hfr";
var playFromCurrentLocation = true;
var useDisplayName = false;
var useAttachments = false;
var useHeadModel = false;
var useSkeletonModel = false;
// ID of the agent. Two agents can't have the same ID.
var id = 2;
// Set head and skeleton models
Avatar.faceModelURL = "http://public.highfidelity.io/models/heads/StndAvatarHead_Carl_v1.fst";
Avatar.skeletonModelURL = "http://public.highfidelity.io/models/skeletons/StndAvatarBody_Ron_vC.fst";
// Set position/orientation/scale here if playFromCurrentLocation is true
Avatar.position = { x:199.4, y: 0.6, z: 256.3};
Avatar.orientation = Quat.fromPitchYawRollDegrees(0,93.9, 0);
Avatar.scale = 1.2;
// Those variables MUST be common to every scripts
var controlVoxelSize = 0.25;
var controlVoxelPosition = { x: 2000 , y: 1, z: 0 };
// Script. DO NOT MODIFY BEYOND THIS LINE.
var DO_NOTHING = 0;
var PLAY = 1;
var PLAY_LOOP = 2;
var STOP = 3;
var SHOW = 4;
var HIDE = 5;
var COLORS = [];
COLORS[PLAY] = { red: PLAY, green: 0, blue: 0 };
COLORS[PLAY_LOOP] = { red: PLAY_LOOP, green: 0, blue: 0 };
COLORS[STOP] = { red: STOP, green: 0, blue: 0 };
COLORS[SHOW] = { red: SHOW, green: 0, blue: 0 };
COLORS[HIDE] = { red: HIDE, green: 0, blue: 0 };
controlVoxelPosition.x += id * controlVoxelSize;
Avatar.loadRecording(filename);
Avatar.setPlayFromCurrentLocation(playFromCurrentLocation);
Avatar.setPlayerUseDisplayName(useDisplayName);
Avatar.setPlayerUseAttachments(useAttachments);
Avatar.setPlayerUseHeadModel(useHeadModel);
Avatar.setPlayerUseSkeletonModel(useSkeletonModel);
function setupVoxelViewer() {
var voxelViewerOffset = 10;
var voxelViewerPosition = JSON.parse(JSON.stringify(controlVoxelPosition));
voxelViewerPosition.x -= voxelViewerOffset;
var voxelViewerOrientation = Quat.fromPitchYawRollDegrees(0, -90, 0);
VoxelViewer.setPosition(voxelViewerPosition);
VoxelViewer.setOrientation(voxelViewerOrientation);
VoxelViewer.queryOctree();
}
function getAction(controlVoxel) {
if (controlVoxel.x != controlVoxelPosition.x ||
controlVoxel.y != controlVoxelPosition.y ||
controlVoxel.z != controlVoxelPosition.z ||
controlVoxel.s != controlVoxelSize) {
return DO_NOTHING;
}
for (i in COLORS) {
if (controlVoxel.red === COLORS[i].red &&
controlVoxel.green === COLORS[i].green &&
controlVoxel.blue === COLORS[i].blue) {
Voxels.eraseVoxel(controlVoxelPosition.x,
controlVoxelPosition.y,
controlVoxelPosition.z,
controlVoxelSize);
return parseInt(i);
}
}
return DO_NOTHING;
}
count = 300; // This is necessary to wait for the audio mixer to connect
function update(event) {
VoxelViewer.queryOctree();
if (count > 0) {
count--;
return;
}
var controlVoxel = Voxels.getVoxelAt(controlVoxelPosition.x,
controlVoxelPosition.y,
controlVoxelPosition.z,
controlVoxelSize);
var action = getAction(controlVoxel);
switch(action) {
case PLAY:
print("Play");
if (!Agent.isAvatar) {
Agent.isAvatar = true;
}
if (!Avatar.isPlaying()) {
Avatar.startPlaying();
}
Avatar.setPlayerLoop(false);
break;
case PLAY_LOOP:
print("Play loop");
if (!Agent.isAvatar) {
Agent.isAvatar = true;
}
if (!Avatar.isPlaying()) {
Avatar.startPlaying();
}
Avatar.setPlayerLoop(true);
break;
case STOP:
print("Stop");
if (Avatar.isPlaying()) {
Avatar.stopPlaying();
}
break;
case SHOW:
print("Show");
if (!Agent.isAvatar) {
Agent.isAvatar = true;
}
break;
case HIDE:
print("Hide");
if (Avatar.isPlaying()) {
Avatar.stopPlaying();
}
Agent.isAvatar = false;
break;
case DO_NOTHING:
break;
default:
print("Unknown action: " + action);
break;
}
if (Avatar.isPlaying()) {
Avatar.play();
}
}
Script.update.connect(update);
setupVoxelViewer();