mirror of
https://github.com/overte-org/overte.git
synced 2025-04-22 06:04:24 +02:00
Merge pull request #6410 from AlessandroSigna/groupRecording
Group recording - better structure
This commit is contained in:
commit
96b877df97
3 changed files with 89 additions and 67 deletions
examples/entityScripts
21
examples/entityScripts/createRecorder.js
Normal file
21
examples/entityScripts/createRecorder.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
var rotation = Quat.safeEulerAngles(Camera.getOrientation());
|
||||
rotation = Quat.fromPitchYawRollDegrees(0, rotation.y, 0);
|
||||
var center = Vec3.sum(MyAvatar.position, Vec3.multiply(6, Quat.getFront(rotation)));
|
||||
|
||||
var recordAreaEntity = Entities.addEntity({
|
||||
name: 'recorderEntity',
|
||||
dimensions: {
|
||||
x: 10,
|
||||
y: 10,
|
||||
z: 10
|
||||
},
|
||||
type: 'Box',
|
||||
position: center,
|
||||
color: {
|
||||
red: 255,
|
||||
green: 255,
|
||||
blue: 255
|
||||
},
|
||||
visible: true,
|
||||
script: "https://hifi-public.s3.amazonaws.com/sam/record/recordingEntityScript.js",
|
||||
});
|
|
@ -13,9 +13,11 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
|
||||
(function () {
|
||||
|
||||
HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
|
||||
Script.include(HIFI_PUBLIC_BUCKET + "scripts/libraries/utils.js");
|
||||
|
||||
(function() {
|
||||
var insideRecorderArea = false;
|
||||
var enteredInTime = false;
|
||||
var isAvatarRecording = false;
|
||||
|
@ -25,51 +27,63 @@
|
|||
_this = this;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
function update() {
|
||||
var isRecordingStarted = getEntityCustomData("recordingKey", _this.entityID, { isRecordingStarted: false }).isRecordingStarted;
|
||||
if (isRecordingStarted && !isAvatarRecording) {
|
||||
_this.startRecording();
|
||||
} else if ((!isRecordingStarted && isAvatarRecording) || (isAvatarRecording && !insideRecorderArea)) {
|
||||
_this.stopRecording();
|
||||
} else if (!isRecordingStarted && insideRecorderArea && !enteredInTime) {
|
||||
//if an avatar enters the zone while a recording is started he will be able to participate to the next group recording
|
||||
enteredInTime = true;
|
||||
}
|
||||
};
|
||||
|
||||
recordingEntity.prototype = {
|
||||
update: function(){
|
||||
var userData = JSON.parse(Entities.getEntityProperties(_this.entityID, ["userData"]).userData);
|
||||
var isRecordingStarted = userData.recordingKey.isRecordingStarted;
|
||||
if(isRecordingStarted && !isAvatarRecording){
|
||||
_this.startRecording();
|
||||
}else if((!isRecordingStarted && isAvatarRecording) || (isAvatarRecording && !insideRecorderArea)){
|
||||
_this.stopRecording();
|
||||
}else if(!isRecordingStarted && insideRecorderArea && !enteredInTime){
|
||||
//if an avatar enters the zone while a recording is started he will be able to participate to the next group recording
|
||||
enteredInTime = true;
|
||||
}
|
||||
|
||||
},
|
||||
preload: function(entityID) {
|
||||
|
||||
preload: function (entityID) {
|
||||
print("RECORDING ENTITY PRELOAD");
|
||||
this.entityID = entityID;
|
||||
Script.update.connect(_this.update);
|
||||
|
||||
var entityProperties = Entities.getEntityProperties(_this.entityID);
|
||||
if (!entityProperties.ignoreForCollisions) {
|
||||
Entities.editEntity(_this.entityID, { ignoreForCollisions: true });
|
||||
}
|
||||
|
||||
//print(JSON.stringify(entityProperties));
|
||||
var recordingKey = getEntityCustomData("recordingKey", _this.entityID, undefined);
|
||||
if (recordingKey === undefined) {
|
||||
setEntityCustomData("recordingKey", _this.entityID, { isRecordingStarted: false });
|
||||
}
|
||||
|
||||
Script.update.connect(update);
|
||||
},
|
||||
enterEntity: function(entityID) {
|
||||
enterEntity: function (entityID) {
|
||||
print("entering in the recording area");
|
||||
insideRecorderArea = true;
|
||||
var userData = JSON.parse(Entities.getEntityProperties(_this.entityID, ["userData"]).userData);
|
||||
var isRecordingStarted = userData.recordingKey.isRecordingStarted;
|
||||
if(!isRecordingStarted){
|
||||
var isRecordingStarted = getEntityCustomData("recordingKey", _this.entityID, { isRecordingStarted: false }).isRecordingStarted;
|
||||
if (!isRecordingStarted) {
|
||||
//i'm in the recording area in time (before the event starts)
|
||||
enteredInTime = true;
|
||||
}
|
||||
},
|
||||
leaveEntity: function(entityID) {
|
||||
leaveEntity: function (entityID) {
|
||||
print("leaving the recording area");
|
||||
insideRecorderArea = false;
|
||||
enteredInTime = false;
|
||||
},
|
||||
|
||||
startRecording: function(entityID){
|
||||
if(enteredInTime && !isAvatarRecording){
|
||||
|
||||
startRecording: function (entityID) {
|
||||
if (enteredInTime && !isAvatarRecording) {
|
||||
print("RECORDING STARTED");
|
||||
Recording.startRecording();
|
||||
isAvatarRecording = true;
|
||||
}
|
||||
},
|
||||
|
||||
stopRecording: function(entityID){
|
||||
if(isAvatarRecording){
|
||||
|
||||
stopRecording: function (entityID) {
|
||||
if (isAvatarRecording) {
|
||||
print("RECORDING ENDED");
|
||||
Recording.stopRecording();
|
||||
Recording.loadLastRecording();
|
||||
|
@ -80,12 +94,13 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
clean: function(entityID) {
|
||||
Script.update.disconnect(_this.update);
|
||||
unload: function (entityID) {
|
||||
print("RECORDING ENTITY UNLOAD");
|
||||
Script.update.disconnect(update);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return new recordingEntity();
|
||||
});
|
||||
});
|
|
@ -5,16 +5,15 @@
|
|||
// Created by Alessandro Signa on 11/12/15.
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Run this script to spawn a box (recorder) and drive the start/end of the recording for anyone who is inside the box
|
||||
// Run this script to find the recorder (created by crateRecorder.js) and drive the start/end of the recording for anyone who is inside the box
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
var PARAMS_SCRIPT_URL = Script.resolvePath('recordingEntityScript.js');
|
||||
|
||||
HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
|
||||
Script.include("../libraries/toolBars.js");
|
||||
Script.include("../libraries/utils.js");
|
||||
Script.include(HIFI_PUBLIC_BUCKET + "scripts/libraries/toolBars.js");
|
||||
Script.include(HIFI_PUBLIC_BUCKET + "scripts/libraries/utils.js");
|
||||
|
||||
|
||||
|
||||
|
@ -30,35 +29,25 @@ var COLOR_TOOL_BAR = { red: 0, green: 0, blue: 0 };
|
|||
var toolBar = null;
|
||||
var recordIcon;
|
||||
|
||||
|
||||
var isRecordingEntityFound = false;
|
||||
|
||||
var isRecording = false;
|
||||
|
||||
var recordAreaEntity = Entities.addEntity({
|
||||
name: 'recorderEntity',
|
||||
dimensions: {
|
||||
x: 2,
|
||||
y: 1,
|
||||
z: 2
|
||||
},
|
||||
type: 'Box',
|
||||
position: center,
|
||||
color: {
|
||||
red: 255,
|
||||
green: 255,
|
||||
blue: 255
|
||||
},
|
||||
visible: true,
|
||||
ignoreForCollisions: true,
|
||||
script: PARAMS_SCRIPT_URL,
|
||||
|
||||
userData: JSON.stringify({
|
||||
recordingKey: {
|
||||
isRecordingStarted: false
|
||||
}
|
||||
})
|
||||
});
|
||||
var recordAreaEntity = null;
|
||||
findRecorder();
|
||||
|
||||
function findRecorder() {
|
||||
foundEntities = Entities.findEntities(MyAvatar.position, 50);
|
||||
for (var i = 0; i < foundEntities.length; i++) {
|
||||
var name = Entities.getEntityProperties(foundEntities[i], "name").name;
|
||||
if (name === "recorderEntity") {
|
||||
recordAreaEntity = foundEntities[i];
|
||||
isRecordingEntityFound = true;
|
||||
print("Found recorder Entity!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setupToolBar();
|
||||
|
||||
|
@ -70,7 +59,7 @@ function setupToolBar() {
|
|||
Tool.IMAGE_HEIGHT /= 2;
|
||||
Tool.IMAGE_WIDTH /= 2;
|
||||
|
||||
toolBar = new ToolBar(0, 0, ToolBar.HORIZONTAL); //put the button in the up-left corner
|
||||
toolBar = new ToolBar(0, 100, ToolBar.HORIZONTAL); //put the button in the up-left corner
|
||||
|
||||
toolBar.setBack(COLOR_TOOL_BAR, ALPHA_OFF);
|
||||
|
||||
|
@ -81,9 +70,8 @@ function setupToolBar() {
|
|||
width: Tool.IMAGE_WIDTH,
|
||||
height: Tool.IMAGE_HEIGHT,
|
||||
alpha: Recording.isPlaying() ? ALPHA_OFF : ALPHA_ON,
|
||||
visible: true
|
||||
visible: isRecordingEntityFound,
|
||||
}, true, isRecording);
|
||||
|
||||
}
|
||||
|
||||
function mousePressEvent(event) {
|
||||
|
@ -106,8 +94,6 @@ function mousePressEvent(event) {
|
|||
|
||||
function cleanup() {
|
||||
toolBar.cleanup();
|
||||
Entities.callEntityMethod(recordAreaEntity, 'clean'); //have to call this before deleting to avoid the JSON warnings
|
||||
Entities.deleteEntity(recordAreaEntity);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue