153 lines
4.1 KiB
JavaScript
Raw Permalink Normal View History

2014-09-02 12:56:51 -07:00
//
// 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
//
2014-09-02 12:56:51 -07:00
// Set the following variables to the values needed
2015-11-11 15:03:19 -08:00
var clip_url = null;
2014-09-02 12:56:51 -07:00
var playFromCurrentLocation = true;
2014-09-18 17:02:11 -07:00
var useDisplayName = true;
var useAttachments = true;
2015-08-31 16:53:30 +02:00
var useAvatarModel = true;
2014-09-02 12:56:51 -07:00
// ID of the agent. Two agents can't have the same ID.
var id = 0;
// 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
2015-08-31 16:53:30 +02:00
var controlEntitySize = 0.25;
2015-11-06 18:58:50 -08:00
var controlEntityPosition = { x: 0, y: 0, z: 0 };
2014-09-02 12:56:51 -07:00
// 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;
2015-11-06 18:58:50 -08:00
var LOAD = 6;
2014-09-02 12:56:51 -07:00
2015-11-16 16:50:47 -08:00
Recording.setPlayFromCurrentLocation(playFromCurrentLocation);
Recording.setPlayerUseDisplayName(useDisplayName);
Recording.setPlayerUseAttachments(useAttachments);
Recording.setPlayerUseHeadModel(false);
Recording.setPlayerUseSkeletonModel(useAvatarModel);
2015-08-31 16:53:30 +02:00
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();
2014-09-02 12:56:51 -07:00
}
2015-11-12 18:25:51 -08:00
function getAction(controlEntity) {
if (controlEntity === null) {
return DO_NOTHING;
}
var userData = JSON.parse(Entities.getEntityProperties(controlEntity, ["userData"]).userData);
2015-11-06 18:58:50 -08:00
2015-11-12 18:25:51 -08:00
var uD_id = userData.idKey.uD_id;
var uD_action = userData.actionKey.uD_action;
var uD_url = userData.clipKey.uD_url;
2015-08-31 16:53:30 +02:00
2015-11-12 18:25:51 -08:00
Entities.deleteEntity((Entities.getEntityProperties(controlEntity)).id);
2015-11-13 14:58:59 -08:00
if (uD_id === id || uD_id === -1) {
if (uD_action === 6)
2015-11-12 18:25:51 -08:00
clip_url = uD_url;
return uD_action;
} else {
return DO_NOTHING;
}
2014-09-02 12:56:51 -07:00
}
2015-08-31 16:53:30 +02:00
count = 100; // This is necessary to wait for the audio mixer to connect
2014-09-02 12:56:51 -07:00
function update(event) {
2015-08-31 16:53:30 +02:00
EntityViewer.queryOctree();
if (count > 0) {
count--;
return;
}
var controlEntity = Entities.findClosestEntity(controlEntityPosition, controlEntitySize);
2015-11-12 18:25:51 -08:00
var action = getAction(controlEntity);
2015-08-31 16:53:30 +02:00
switch(action) {
case PLAY:
print("Play");
if (!Agent.isAvatar) {
Agent.isAvatar = true;
}
2015-11-16 16:50:47 -08:00
if (!Recording.isPlaying()) {
Recording.startPlaying();
2015-08-31 16:53:30 +02:00
}
2015-11-16 16:50:47 -08:00
Recording.setPlayerLoop(false);
2015-08-31 16:53:30 +02:00
break;
case PLAY_LOOP:
print("Play loop");
if (!Agent.isAvatar) {
Agent.isAvatar = true;
}
2015-11-16 16:50:47 -08:00
if (!Recording.isPlaying()) {
Recording.startPlaying();
2015-08-31 16:53:30 +02:00
}
2015-11-16 16:50:47 -08:00
Recording.setPlayerLoop(true);
2015-08-31 16:53:30 +02:00
break;
case STOP:
print("Stop");
2015-11-16 16:50:47 -08:00
if (Recording.isPlaying()) {
Recording.stopPlaying();
2015-08-31 16:53:30 +02:00
}
break;
case SHOW:
print("Show");
if (!Agent.isAvatar) {
Agent.isAvatar = true;
}
break;
case HIDE:
print("Hide");
2015-11-16 16:50:47 -08:00
if (Recording.isPlaying()) {
Recording.stopPlaying();
2015-08-31 16:53:30 +02:00
}
Agent.isAvatar = false;
break;
2015-11-06 18:58:50 -08:00
case LOAD:
print("Load");
2015-11-09 18:14:42 -08:00
if(clip_url !== null) {
2015-11-16 16:50:47 -08:00
Recording.loadRecording(clip_url);
2015-11-06 18:58:50 -08:00
}
break;
2015-08-31 16:53:30 +02:00
case DO_NOTHING:
break;
default:
print("Unknown action: " + action);
break;
}
2015-11-16 16:50:47 -08:00
if (Recording.isPlaying()) {
Recording.play();
2015-08-31 16:53:30 +02:00
}
2014-09-02 12:56:51 -07:00
}
Script.update.connect(update);
2015-08-31 16:53:30 +02:00
setupEntityViewer();