mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 20:48:56 +02:00
improved the structure
This commit is contained in:
parent
8566d84709
commit
5400381583
3 changed files with 89 additions and 67 deletions
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
|
// 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 insideRecorderArea = false;
|
||||||
var enteredInTime = false;
|
var enteredInTime = false;
|
||||||
var isAvatarRecording = false;
|
var isAvatarRecording = false;
|
||||||
|
@ -25,51 +27,63 @@
|
||||||
_this = this;
|
_this = this;
|
||||||
return;
|
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 = {
|
recordingEntity.prototype = {
|
||||||
update: function(){
|
|
||||||
var userData = JSON.parse(Entities.getEntityProperties(_this.entityID, ["userData"]).userData);
|
preload: function (entityID) {
|
||||||
var isRecordingStarted = userData.recordingKey.isRecordingStarted;
|
print("RECORDING ENTITY PRELOAD");
|
||||||
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) {
|
|
||||||
this.entityID = entityID;
|
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");
|
print("entering in the recording area");
|
||||||
insideRecorderArea = true;
|
insideRecorderArea = true;
|
||||||
var userData = JSON.parse(Entities.getEntityProperties(_this.entityID, ["userData"]).userData);
|
var isRecordingStarted = getEntityCustomData("recordingKey", _this.entityID, { isRecordingStarted: false }).isRecordingStarted;
|
||||||
var isRecordingStarted = userData.recordingKey.isRecordingStarted;
|
if (!isRecordingStarted) {
|
||||||
if(!isRecordingStarted){
|
|
||||||
//i'm in the recording area in time (before the event starts)
|
//i'm in the recording area in time (before the event starts)
|
||||||
enteredInTime = true;
|
enteredInTime = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
leaveEntity: function(entityID) {
|
leaveEntity: function (entityID) {
|
||||||
print("leaving the recording area");
|
print("leaving the recording area");
|
||||||
insideRecorderArea = false;
|
insideRecorderArea = false;
|
||||||
enteredInTime = false;
|
enteredInTime = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
startRecording: function(entityID){
|
startRecording: function (entityID) {
|
||||||
if(enteredInTime && !isAvatarRecording){
|
if (enteredInTime && !isAvatarRecording) {
|
||||||
print("RECORDING STARTED");
|
print("RECORDING STARTED");
|
||||||
Recording.startRecording();
|
Recording.startRecording();
|
||||||
isAvatarRecording = true;
|
isAvatarRecording = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
stopRecording: function(entityID){
|
stopRecording: function (entityID) {
|
||||||
if(isAvatarRecording){
|
if (isAvatarRecording) {
|
||||||
print("RECORDING ENDED");
|
print("RECORDING ENDED");
|
||||||
Recording.stopRecording();
|
Recording.stopRecording();
|
||||||
Recording.loadLastRecording();
|
Recording.loadLastRecording();
|
||||||
|
@ -80,12 +94,13 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
unload: function(entityID) {
|
unload: function (entityID) {
|
||||||
Script.update.disconnect(_this.update);
|
print("RECORDING ENTITY UNLOAD");
|
||||||
|
Script.update.disconnect(update);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return new recordingEntity();
|
return new recordingEntity();
|
||||||
});
|
});
|
|
@ -5,16 +5,15 @@
|
||||||
// Created by Alessandro Signa on 11/12/15.
|
// Created by Alessandro Signa on 11/12/15.
|
||||||
// Copyright 2015 High Fidelity, Inc.
|
// 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.
|
// Distributed under the Apache License, Version 2.0.
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// 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/";
|
HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
|
||||||
Script.include("../libraries/toolBars.js");
|
Script.include(HIFI_PUBLIC_BUCKET + "scripts/libraries/toolBars.js");
|
||||||
Script.include("../libraries/utils.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 toolBar = null;
|
||||||
var recordIcon;
|
var recordIcon;
|
||||||
|
|
||||||
|
var isRecordingEntityFound = false;
|
||||||
|
|
||||||
var isRecording = false;
|
var isRecording = false;
|
||||||
|
|
||||||
var recordAreaEntity = Entities.addEntity({
|
var recordAreaEntity = null;
|
||||||
name: 'recorderEntity',
|
findRecorder();
|
||||||
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
|
|
||||||
}
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
|
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();
|
setupToolBar();
|
||||||
|
|
||||||
|
@ -70,7 +59,7 @@ function setupToolBar() {
|
||||||
Tool.IMAGE_HEIGHT /= 2;
|
Tool.IMAGE_HEIGHT /= 2;
|
||||||
Tool.IMAGE_WIDTH /= 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);
|
toolBar.setBack(COLOR_TOOL_BAR, ALPHA_OFF);
|
||||||
|
|
||||||
|
@ -81,9 +70,8 @@ function setupToolBar() {
|
||||||
width: Tool.IMAGE_WIDTH,
|
width: Tool.IMAGE_WIDTH,
|
||||||
height: Tool.IMAGE_HEIGHT,
|
height: Tool.IMAGE_HEIGHT,
|
||||||
alpha: Recording.isPlaying() ? ALPHA_OFF : ALPHA_ON,
|
alpha: Recording.isPlaying() ? ALPHA_OFF : ALPHA_ON,
|
||||||
visible: true
|
visible: isRecordingEntityFound,
|
||||||
}, true, isRecording);
|
}, true, isRecording);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function mousePressEvent(event) {
|
function mousePressEvent(event) {
|
||||||
|
@ -106,8 +94,6 @@ function mousePressEvent(event) {
|
||||||
|
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
toolBar.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