mirror of
https://github.com/overte-org/overte.git
synced 2025-04-26 05:16:55 +02:00
157 lines
4.6 KiB
JavaScript
157 lines
4.6 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
|
|
//
|
|
|
|
HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
|
|
|
|
// Set the following variables to the values needed
|
|
var filename = "/Users/clement/Desktop/recording.hfr";
|
|
var playFromCurrentLocation = true;
|
|
var useDisplayName = true;
|
|
var useAttachments = true;
|
|
var useAvatarModel = true;
|
|
|
|
// ID of the agent. Two agents can't have the same ID.
|
|
var id = 0;
|
|
|
|
// Set avatar model URL
|
|
Avatar.skeletonModelURL = "https://hifi-public.s3.amazonaws.com/marketplace/contents/e21c0b95-e502-4d15-8c41-ea2fc40f1125/3585ddf674869a67d31d5964f7b52de1.fst?1427169998";
|
|
// Set position/orientation/scale here if playFromCurrentLocation is true
|
|
Avatar.position = { x:1, y: 1, z: 1 };
|
|
Avatar.orientation = Quat.fromPitchYawRollDegrees(0, 0, 0);
|
|
Avatar.scale = 1.0;
|
|
|
|
// Those variables MUST be common to every scripts
|
|
var controlEntitySize = 0.25;
|
|
var controlEntityPosition = { x: 2000, y: 0, 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 };
|
|
|
|
controlEntityPosition.x += id * controlEntitySize;
|
|
|
|
Avatar.loadRecording(filename);
|
|
|
|
Avatar.setPlayFromCurrentLocation(playFromCurrentLocation);
|
|
Avatar.setPlayerUseDisplayName(useDisplayName);
|
|
Avatar.setPlayerUseAttachments(useAttachments);
|
|
Avatar.setPlayerUseHeadModel(false);
|
|
Avatar.setPlayerUseSkeletonModel(useAvatarModel);
|
|
|
|
function setupEntityViewer() {
|
|
var entityViewerOffset = 10;
|
|
var entityViewerPosition = { x: controlEntityPosition.x - entityViewerOffset,
|
|
y: controlEntityPosition.y, z: controlEntityPosition.z };
|
|
var entityViewerOrientation = Quat.fromPitchYawRollDegrees(0, -90, 0);
|
|
|
|
EntityViewer.setPosition(entityViewerPosition);
|
|
EntityViewer.setOrientation(entityViewerOrientation);
|
|
EntityViewer.queryOctree();
|
|
}
|
|
|
|
function getAction(controlEntity) {
|
|
if (controlEntity === null ||
|
|
controlEntity.position.x !== controlEntityPosition.x ||
|
|
controlEntity.position.y !== controlEntityPosition.y ||
|
|
controlEntity.position.z !== controlEntityPosition.z ||
|
|
controlEntity.dimensions.x !== controlEntitySize) {
|
|
return DO_NOTHING;
|
|
}
|
|
|
|
for (i in COLORS) {
|
|
if (controlEntity.color.red === COLORS[i].red &&
|
|
controlEntity.color.green === COLORS[i].green &&
|
|
controlEntity.color.blue === COLORS[i].blue) {
|
|
Entities.deleteEntity(controlEntity.id);
|
|
return parseInt(i);
|
|
}
|
|
}
|
|
|
|
return DO_NOTHING;
|
|
}
|
|
|
|
count = 100; // This is necessary to wait for the audio mixer to connect
|
|
function update(event) {
|
|
EntityViewer.queryOctree();
|
|
if (count > 0) {
|
|
count--;
|
|
return;
|
|
}
|
|
|
|
|
|
var controlEntity = Entities.findClosestEntity(controlEntityPosition, controlEntitySize);
|
|
var action = getAction(Entities.getEntityProperties(controlEntity));
|
|
|
|
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);
|
|
setupEntityViewer();
|