mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
constant updates
This commit is contained in:
parent
fff8bbf104
commit
02aa6ca6d1
2 changed files with 55 additions and 60 deletions
|
@ -12,12 +12,11 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
// todo: quaternion folders, color pickers, read-only properties, animation settings and other nested objects, scale gui width with window resizing
|
||||
|
||||
/*global window, EventBridge, dat, convertBinaryToBoolean, listenForSettingsUpdates,createVec3Folder,createQuatFolder,writeVec3ToInterface,writeDataToInterface*/
|
||||
|
||||
var Settings = function() {
|
||||
return;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
var controllers = [];
|
||||
var folders = [];
|
||||
|
@ -27,14 +26,13 @@ var settings = new Settings();
|
|||
|
||||
function convertBinaryToBoolean(value) {
|
||||
if (value === 0) {
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function loadGUI() {
|
||||
console.log('loadGUI ')
|
||||
console.log('loadGUI ');
|
||||
|
||||
//whether or not to autoplace
|
||||
gui = new dat.GUI({
|
||||
|
@ -43,11 +41,9 @@ function loadGUI() {
|
|||
|
||||
//if not autoplacing, put gui in a custom container
|
||||
if (gui.autoPlace === false) {
|
||||
|
||||
var customContainer = document.getElementById('my-gui-container');
|
||||
customContainer.appendChild(gui.domElement);
|
||||
gui.width = 400;
|
||||
|
||||
}
|
||||
|
||||
//add save settings ability (try not to use localstorage)
|
||||
|
@ -61,24 +57,19 @@ function loadGUI() {
|
|||
|
||||
// //FOR NOW TO SHOW THAT IT WORKS RESTRICT TO A FEW PROPERTIES. NEED TO ADD SUPPORT FOR VEC3, QUAT, COLORS
|
||||
if (key.indexOf('name') !== -1 || key.indexOf('description') !== -1 || key.indexOf('visible') !== -1 || key.indexOf('collisionsWillMove') !== -1) {
|
||||
|
||||
|
||||
// we aren't getting checkboxes for collisionsWillMove because it comes across the wire as a 1, not a true
|
||||
|
||||
if (key.indexOf('visible') !== -1) {
|
||||
settings.visible = convertBinaryToBoolean(settings.visible)
|
||||
|
||||
settings.visible = convertBinaryToBoolean(settings.visible);
|
||||
}
|
||||
if (key.indexOf('collisionsWillMove') !== -1) {
|
||||
settings.collisionsWillMove = convertBinaryToBoolean(settings.collisionsWillMove)
|
||||
|
||||
settings.collisionsWillMove = convertBinaryToBoolean(settings.collisionsWillMove);
|
||||
}
|
||||
} else {
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('key:::' + key)
|
||||
//add this key as a controller to the gui
|
||||
console.log('key:::' + key);
|
||||
//add this key as a controller to the gui
|
||||
|
||||
var controller = gui.add(settings, key).listen();
|
||||
// the call below is potentially expensive but will enable two way binding. needs testing to see how many it supports at once.
|
||||
|
@ -88,12 +79,14 @@ function loadGUI() {
|
|||
//hook into change events for this gui controller
|
||||
controller.onChange(function(value) {
|
||||
// Fires on every change, drag, keypress, etc.
|
||||
writeDataToInterface(this.property, value);
|
||||
});
|
||||
|
||||
controller.onFinishChange(function(value) {
|
||||
// Fires when a controller loses focus.
|
||||
writeDataToInterface(this.property, value)
|
||||
});
|
||||
// controller.onFinishChange(function(value) {
|
||||
// // Fires when a controller loses focus.
|
||||
// //writeDataToInterface(this.property, value);
|
||||
// return;
|
||||
// });
|
||||
|
||||
});
|
||||
|
||||
|
@ -103,36 +96,36 @@ function loadGUI() {
|
|||
createVec3Folder('acceleration');
|
||||
createVec3Folder('angularVelocity');
|
||||
createQuatFolder('rotation');
|
||||
};
|
||||
}
|
||||
|
||||
function createVec3Folder(category) {
|
||||
var folder = gui.addFolder(category);
|
||||
folder.add(settings[category], 'x').step(0.1).listen().onFinishChange(function(value) {
|
||||
folder.add(settings[category], 'x').step(0.1).listen().onChange(function(value) {
|
||||
// Fires when a controller loses focus.
|
||||
var obj = {};
|
||||
obj[category] = {};
|
||||
obj[category][this.property] = value;
|
||||
obj[category].y = settings[category].y;
|
||||
obj[category].z = settings[category].z;
|
||||
writeVec3ToInterface(obj)
|
||||
writeVec3ToInterface(obj);
|
||||
});
|
||||
folder.add(settings[category], 'y').step(0.1).listen().onFinishChange(function(value) {
|
||||
folder.add(settings[category], 'y').step(0.1).listen().onChange(function(value) {
|
||||
// Fires when a controller loses focus.
|
||||
var obj = {};
|
||||
obj[category] = {};
|
||||
obj[category][this.property] = value;
|
||||
obj[category].x = settings[category].x;
|
||||
obj[category].z = settings[category].z;
|
||||
writeVec3ToInterface(obj)
|
||||
writeVec3ToInterface(obj);
|
||||
});
|
||||
folder.add(settings[category], 'z').step(0.1).listen().onFinishChange(function(value) {
|
||||
folder.add(settings[category], 'z').step(0.1).listen().onChange(function(value) {
|
||||
// Fires when a controller loses focus.
|
||||
var obj = {};
|
||||
obj[category] = {};
|
||||
obj[category][this.property] = value;
|
||||
obj[category].y = settings[category].y;
|
||||
obj[category].x = settings[category].x;
|
||||
writeVec3ToInterface(obj)
|
||||
writeVec3ToInterface(obj);
|
||||
});
|
||||
folder.open();
|
||||
folders.push(folder);
|
||||
|
@ -140,7 +133,7 @@ function createVec3Folder(category) {
|
|||
|
||||
function createQuatFolder(category) {
|
||||
var folder = gui.addFolder(category);
|
||||
folder.add(settings[category], 'x').step(0.1).listen().onFinishChange(function(value) {
|
||||
folder.add(settings[category], 'x').step(0.1).listen().onChange(function(value) {
|
||||
// Fires when a controller loses focus.
|
||||
var obj = {};
|
||||
obj[category] = {};
|
||||
|
@ -148,9 +141,9 @@ function createQuatFolder(category) {
|
|||
obj[category].y = settings[category].y;
|
||||
obj[category].z = settings[category].z;
|
||||
obj[category].w = settings[category].w;
|
||||
writeVec3ToInterface(obj)
|
||||
writeVec3ToInterface(obj);
|
||||
});
|
||||
folder.add(settings[category], 'y').step(0.1).listen().onFinishChange(function(value) {
|
||||
folder.add(settings[category], 'y').step(0.1).listen().onChange(function(value) {
|
||||
// Fires when a controller loses focus.
|
||||
var obj = {};
|
||||
obj[category] = {};
|
||||
|
@ -158,9 +151,9 @@ function createQuatFolder(category) {
|
|||
obj[category][this.property] = value;
|
||||
obj[category].z = settings[category].z;
|
||||
obj[category].w = settings[category].w;
|
||||
writeVec3ToInterface(obj)
|
||||
writeVec3ToInterface(obj);
|
||||
});
|
||||
folder.add(settings[category], 'z').step(0.1).listen().onFinishChange(function(value) {
|
||||
folder.add(settings[category], 'z').step(0.1).listen().onChange(function(value) {
|
||||
// Fires when a controller loses focus.
|
||||
var obj = {};
|
||||
obj[category] = {};
|
||||
|
@ -168,9 +161,9 @@ function createQuatFolder(category) {
|
|||
obj[category].y = settings[category].y;
|
||||
obj[category][this.property] = value;
|
||||
obj[category].w = settings[category].w;
|
||||
writeVec3ToInterface(obj)
|
||||
writeVec3ToInterface(obj);
|
||||
});
|
||||
folder.add(settings[category], 'w').step(0.1).listen().onFinishChange(function(value) {
|
||||
folder.add(settings[category], 'w').step(0.1).listen().onChange(function(value) {
|
||||
// Fires when a controller loses focus.
|
||||
var obj = {};
|
||||
obj[category] = {};
|
||||
|
@ -178,22 +171,22 @@ function createQuatFolder(category) {
|
|||
obj[category].y = settings[category].y;
|
||||
obj[category].z = settings[category].z;
|
||||
obj[category][this.property] = value;
|
||||
writeVec3ToInterface(obj)
|
||||
writeVec3ToInterface(obj);
|
||||
});
|
||||
folder.open();
|
||||
folders.push(folder);
|
||||
}
|
||||
|
||||
function writeDataToInterface(property, value) {
|
||||
console.log('WRITE SOME DATA TO INTERFACE' + property + ":::" + value)
|
||||
console.log('WRITE SOME DATA TO INTERFACE' + property + ":::" + value);
|
||||
var data = {};
|
||||
data[property] = value;
|
||||
var sendData = {
|
||||
messageType: "settings_update",
|
||||
updatedSettings: data,
|
||||
}
|
||||
};
|
||||
|
||||
var stringifiedData = JSON.stringify(sendData)
|
||||
var stringifiedData = JSON.stringify(sendData);
|
||||
|
||||
EventBridge.emitWebEvent(
|
||||
stringifiedData
|
||||
|
@ -203,13 +196,13 @@ function writeDataToInterface(property, value) {
|
|||
}
|
||||
|
||||
function writeVec3ToInterface(obj) {
|
||||
print('VEC3 UPDATE TO INTERFACE FROM SETTINGS')
|
||||
console.log('VEC3 UPDATE TO INTERFACE FROM SETTINGS');
|
||||
var sendData = {
|
||||
messageType: "settings_update",
|
||||
updatedSettings: obj,
|
||||
}
|
||||
};
|
||||
|
||||
var stringifiedData = JSON.stringify(sendData)
|
||||
var stringifiedData = JSON.stringify(sendData);
|
||||
|
||||
EventBridge.emitWebEvent(
|
||||
stringifiedData
|
||||
|
@ -222,26 +215,27 @@ window.onload = function() {
|
|||
console.log('GUI PAGE LOADED');
|
||||
|
||||
if (typeof EventBridge !== 'undefined') {
|
||||
console.log('WE HAVE AN EVENT BRIDGE, SEND PAGE LOADED EVENT ')
|
||||
console.log('WE HAVE AN EVENT BRIDGE, SEND PAGE LOADED EVENT ');
|
||||
|
||||
var stringifiedData = JSON.stringify({
|
||||
messageType: 'page_loaded'
|
||||
})
|
||||
});
|
||||
|
||||
console.log('SEND PAGE LOADED EVENT FROM GUI TO INTERFACE ')
|
||||
console.log('SEND PAGE LOADED EVENT FROM GUI TO INTERFACE ');
|
||||
|
||||
EventBridge.emitWebEvent(
|
||||
stringifiedData
|
||||
);
|
||||
|
||||
listenForSettingsUpdates();
|
||||
} else {
|
||||
console.log('No event bridge, probably not in interface.')
|
||||
console.log('No event bridge, probably not in interface.');
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
function listenForSettingsUpdates() {
|
||||
console.log('GUI IS LISTENING FOR MESSAGES FROM INTERFACE')
|
||||
console.log('GUI IS LISTENING FOR MESSAGES FROM INTERFACE');
|
||||
EventBridge.scriptEventReceived.connect(function(data) {
|
||||
data = JSON.parse(data);
|
||||
|
||||
|
@ -252,34 +246,34 @@ function listenForSettingsUpdates() {
|
|||
settings[key] = value;
|
||||
|
||||
if (key.indexOf('visible') !== -1) {
|
||||
settings.visible = convertBinaryToBoolean(settings.visible)
|
||||
settings.visible = convertBinaryToBoolean(settings.visible);
|
||||
|
||||
}
|
||||
if (key.indexOf('collisionsWillMove') !== -1) {
|
||||
settings.collisionsWillMove = convertBinaryToBoolean(settings.collisionsWillMove)
|
||||
settings.collisionsWillMove = convertBinaryToBoolean(settings.collisionsWillMove);
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
});
|
||||
|
||||
}
|
||||
if (data.messageType === 'initial_settings') {
|
||||
console.log('INITIAL SETTINGS FROM INTERFACE:::' + JSON.stringify(data.initialSettings))
|
||||
console.log('INITIAL SETTINGS FROM INTERFACE:::' + JSON.stringify(data.initialSettings));
|
||||
|
||||
_.each(data.initialSettings, function(value, key) {
|
||||
console.log('key ' + key);
|
||||
console.log('value ' + JSON.stringify(value));
|
||||
settings[key] = {};
|
||||
settings[key] = value;
|
||||
})
|
||||
});
|
||||
|
||||
loadGUI();
|
||||
}
|
||||
if (data.messageType === 'settings_update') {
|
||||
console.log('SETTINGS UPDATE FROM INTERFACE:::' + JSON.stringify(data.updatedSettings))
|
||||
console.log('SETTINGS UPDATE FROM INTERFACE:::' + JSON.stringify(data.updatedSettings));
|
||||
_.each(data.updatedSettings, function(value, key) {
|
||||
console.log('setting,value', setting, value)
|
||||
settings[key] = value;
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
@ -291,7 +285,8 @@ function listenForSettingsUpdates() {
|
|||
|
||||
function manuallyUpdateDisplay(gui) {
|
||||
// Iterate over all controllers
|
||||
for (var i in gui.__controllers) {
|
||||
var i;
|
||||
for (i in gui.__controllers) {
|
||||
gui.__controllers[i].updateDisplay();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ var center = Vec3.sum(Vec3.sum(MyAvatar.position, {
|
|||
x: 0,
|
||||
y: 0.5,
|
||||
z: 0
|
||||
}), Vec3.multiply(0.5, Quat.getFront(Camera.getOrientation())));
|
||||
}), Vec3.multiply(2, Quat.getFront(Camera.getOrientation())));
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue