mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-05-28 07:19:55 +02:00
Merge pull request #13481 from dback2/particleExplorerOptionalPropFix
Optional particle explorer properties fixes
This commit is contained in:
commit
3e2e9826e9
3 changed files with 80 additions and 62 deletions
|
@ -2373,7 +2373,6 @@ function selectParticleEntity(entityID) {
|
||||||
particleExplorerTool.createWebView();
|
particleExplorerTool.createWebView();
|
||||||
|
|
||||||
particleExplorerTool.setActiveParticleEntity(entityID);
|
particleExplorerTool.setActiveParticleEntity(entityID);
|
||||||
particleExplorerTool.setActiveParticleProperties(properties);
|
|
||||||
|
|
||||||
// Switch to particle explorer
|
// Switch to particle explorer
|
||||||
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
|
|
|
@ -61,12 +61,18 @@ function HifiEntityUI(parent) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
this.sendPackage = {};
|
||||||
this.settingsUpdateLock = false;
|
this.settingsUpdateLock = false;
|
||||||
this.webBridgeSync = _.debounce(function (id, val) {
|
this.webBridgeSync = function(id, val) {
|
||||||
if (self.EventBridge && !self.settingsUpdateLock) {
|
if (!this.settingsUpdateLock) {
|
||||||
var sendPackage = {};
|
this.sendPackage[id] = val;
|
||||||
sendPackage[id] = val;
|
this.webBridgeSyncDebounce();
|
||||||
self.submitChanges(sendPackage);
|
}
|
||||||
|
};
|
||||||
|
this.webBridgeSyncDebounce = _.debounce(function () {
|
||||||
|
if (self.EventBridge) {
|
||||||
|
self.submitChanges(self.sendPackage);
|
||||||
|
self.sendPackage = {};
|
||||||
}
|
}
|
||||||
}, DEBOUNCE_TIMEOUT);
|
}, DEBOUNCE_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
@ -159,7 +165,6 @@ HifiEntityUI.prototype = {
|
||||||
var self = this;
|
var self = this;
|
||||||
var fields = document.getElementsByTagName("input");
|
var fields = document.getElementsByTagName("input");
|
||||||
|
|
||||||
self.settingsUpdateLock = true;
|
|
||||||
if (!currentProperties.locked) {
|
if (!currentProperties.locked) {
|
||||||
for (var i = 0; i < fields.length; i++) {
|
for (var i = 0; i < fields.length; i++) {
|
||||||
fields[i].removeAttribute("disabled");
|
fields[i].removeAttribute("disabled");
|
||||||
|
@ -179,7 +184,7 @@ HifiEntityUI.prototype = {
|
||||||
for (var e in keys) {
|
for (var e in keys) {
|
||||||
if (keys.hasOwnProperty(e)) {
|
if (keys.hasOwnProperty(e)) {
|
||||||
var value = keys[e];
|
var value = keys[e];
|
||||||
|
|
||||||
var property = currentProperties[value];
|
var property = currentProperties[value];
|
||||||
var field = self.builtRows[value];
|
var field = self.builtRows[value];
|
||||||
if (field) {
|
if (field) {
|
||||||
|
@ -235,10 +240,6 @@ HifiEntityUI.prototype = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Now unlocking settings Update lock for sending messages on callbacks.
|
|
||||||
setTimeout(function () {
|
|
||||||
self.settingsUpdateLock = false;
|
|
||||||
}, DEBOUNCE_TIMEOUT * 2.5);
|
|
||||||
},
|
},
|
||||||
connect: function (EventBridge) {
|
connect: function (EventBridge) {
|
||||||
this.EventBridge = EventBridge;
|
this.EventBridge = EventBridge;
|
||||||
|
@ -253,28 +254,9 @@ HifiEntityUI.prototype = {
|
||||||
data = JSON.parse(data);
|
data = JSON.parse(data);
|
||||||
|
|
||||||
if (data.messageType === 'particle_settings') {
|
if (data.messageType === 'particle_settings') {
|
||||||
// Update settings
|
self.settingsUpdateLock = true;
|
||||||
var currentProperties = data.currentProperties;
|
self.fillFields(data.currentProperties);
|
||||||
// Update uninitialized variables
|
self.settingsUpdateLock = false;
|
||||||
if (!currentProperties.alphaStart) {
|
|
||||||
currentProperties.alphaStart = currentProperties.alpha;
|
|
||||||
}
|
|
||||||
if (!currentProperties.alphaFinish) {
|
|
||||||
currentProperties.alphaFinish = currentProperties.alpha;
|
|
||||||
}
|
|
||||||
if (!currentProperties.radiusStart) {
|
|
||||||
currentProperties.radiusStart = currentProperties.particleRadius;
|
|
||||||
}
|
|
||||||
if (!currentProperties.radiusFinish) {
|
|
||||||
currentProperties.radiusFinish = currentProperties.particleRadius;
|
|
||||||
}
|
|
||||||
if (!currentProperties.colorStart || !currentProperties.colorStart.red) {
|
|
||||||
currentProperties.colorStart = currentProperties.color;
|
|
||||||
}
|
|
||||||
if (!currentProperties.colorFinish || !currentProperties.colorFinish.red) {
|
|
||||||
currentProperties.colorFinish = currentProperties.color;
|
|
||||||
}
|
|
||||||
self.fillFields(currentProperties);
|
|
||||||
// Do expected property match with structure;
|
// Do expected property match with structure;
|
||||||
} else if (data.messageType === 'particle_close') {
|
} else if (data.messageType === 'particle_close') {
|
||||||
self.disableFields();
|
self.disableFields();
|
||||||
|
|
|
@ -9,7 +9,8 @@
|
||||||
// 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
|
||||||
//
|
//
|
||||||
/* global window, alert, ParticleExplorerTool, EventBridge, dat, listenForSettingsUpdates,createVec3Folder,createQuatFolder,writeVec3ToInterface,writeDataToInterface*/
|
/* global window, alert, ParticleExplorerTool, EventBridge, dat, listenForSettingsUpdates, createVec3Folder,
|
||||||
|
createQuatFolder, writeVec3ToInterface, writeDataToInterface */
|
||||||
|
|
||||||
|
|
||||||
var PARTICLE_EXPLORER_HTML_URL = Script.resolvePath('particleExplorer.html');
|
var PARTICLE_EXPLORER_HTML_URL = Script.resolvePath('particleExplorer.html');
|
||||||
|
@ -17,7 +18,7 @@ var PARTICLE_EXPLORER_HTML_URL = Script.resolvePath('particleExplorer.html');
|
||||||
ParticleExplorerTool = function() {
|
ParticleExplorerTool = function() {
|
||||||
var that = {};
|
var that = {};
|
||||||
that.activeParticleEntity = 0;
|
that.activeParticleEntity = 0;
|
||||||
that.activeParticleProperties = {};
|
that.updatedActiveParticleProperties = {};
|
||||||
|
|
||||||
that.createWebView = function() {
|
that.createWebView = function() {
|
||||||
that.webView = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
that.webView = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
|
@ -30,7 +31,7 @@ ParticleExplorerTool = function() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
that.activeParticleEntity = 0;
|
that.activeParticleEntity = 0;
|
||||||
that.activeParticleProperties = {};
|
that.updatedActiveParticleProperties = {};
|
||||||
|
|
||||||
var messageData = {
|
var messageData = {
|
||||||
messageType: "particle_close"
|
messageType: "particle_close"
|
||||||
|
@ -38,46 +39,86 @@ ParticleExplorerTool = function() {
|
||||||
that.webView.emitScriptEvent(JSON.stringify(messageData));
|
that.webView.emitScriptEvent(JSON.stringify(messageData));
|
||||||
};
|
};
|
||||||
|
|
||||||
function sendActiveParticleProperties() {
|
function sendParticleProperties(properties) {
|
||||||
that.webView.emitScriptEvent(JSON.stringify({
|
that.webView.emitScriptEvent(JSON.stringify({
|
||||||
messageType: "particle_settings",
|
messageType: "particle_settings",
|
||||||
currentProperties: that.activeParticleProperties
|
currentProperties: properties
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sendActiveParticleProperties() {
|
||||||
|
var properties = Entities.getEntityProperties(that.activeParticleEntity);
|
||||||
|
if (properties.emitOrientation) {
|
||||||
|
properties.emitOrientation = Quat.safeEulerAngles(properties.emitOrientation);
|
||||||
|
}
|
||||||
|
// Update uninitialized variables
|
||||||
|
if (isNaN(properties.alphaStart)) {
|
||||||
|
properties.alphaStart = properties.alpha;
|
||||||
|
}
|
||||||
|
if (isNaN(properties.alphaFinish)) {
|
||||||
|
properties.alphaFinish = properties.alpha;
|
||||||
|
}
|
||||||
|
if (isNaN(properties.radiusStart)) {
|
||||||
|
properties.radiusStart = properties.particleRadius;
|
||||||
|
}
|
||||||
|
if (isNaN(properties.radiusFinish)) {
|
||||||
|
properties.radiusFinish = properties.particleRadius;
|
||||||
|
}
|
||||||
|
if (isNaN(properties.colorStart.red)) {
|
||||||
|
properties.colorStart = properties.color;
|
||||||
|
}
|
||||||
|
if (isNaN(properties.colorFinish.red)) {
|
||||||
|
properties.colorFinish = properties.color;
|
||||||
|
}
|
||||||
|
sendParticleProperties(properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendUpdatedActiveParticleProperties() {
|
||||||
|
sendParticleProperties(that.updatedActiveParticleProperties);
|
||||||
|
that.updatedActiveParticleProperties = {};
|
||||||
|
}
|
||||||
|
|
||||||
that.webEventReceived = function(message) {
|
that.webEventReceived = function(message) {
|
||||||
var data = JSON.parse(message);
|
var data = JSON.parse(message);
|
||||||
if (data.messageType === "settings_update") {
|
if (data.messageType === "settings_update") {
|
||||||
if (data.updatedSettings.emitOrientation) {
|
var updatedSettings = data.updatedSettings;
|
||||||
data.updatedSettings.emitOrientation = Quat.fromVec3Degrees(data.updatedSettings.emitOrientation);
|
|
||||||
}
|
|
||||||
Entities.editEntity(that.activeParticleEntity, data.updatedSettings);
|
|
||||||
|
|
||||||
for (var key in data.updatedSettings) {
|
|
||||||
if (that.activeParticleProperties.hasOwnProperty(key)) {
|
|
||||||
that.activeParticleProperties[key] = data.updatedSettings[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var optionalProps = ["alphaStart", "alphaFinish", "radiusStart", "radiusFinish", "colorStart", "colorFinish"];
|
var optionalProps = ["alphaStart", "alphaFinish", "radiusStart", "radiusFinish", "colorStart", "colorFinish"];
|
||||||
var fallbackProps = ["alpha", "particleRadius", "color"];
|
var fallbackProps = ["alpha", "particleRadius", "color"];
|
||||||
var entityProps = Entities.getEntityProperties(that.activeParticleProperties, optionalProps);
|
for (var i = 0; i < optionalProps.length; i++) {
|
||||||
|
var fallbackProp = fallbackProps[Math.floor(i / 2)];
|
||||||
|
var optionalValue = updatedSettings[optionalProps[i]];
|
||||||
|
var fallbackValue = updatedSettings[fallbackProp];
|
||||||
|
if (optionalValue && fallbackValue) {
|
||||||
|
delete updatedSettings[optionalProps[i]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updatedSettings.emitOrientation) {
|
||||||
|
updatedSettings.emitOrientation = Quat.fromVec3Degrees(updatedSettings.emitOrientation);
|
||||||
|
}
|
||||||
|
|
||||||
|
Entities.editEntity(that.activeParticleEntity, updatedSettings);
|
||||||
|
|
||||||
|
var entityProps = Entities.getEntityProperties(that.activeParticleEntity, optionalProps);
|
||||||
|
|
||||||
var needsUpdate = false;
|
var needsUpdate = false;
|
||||||
for (var i = 0; i < optionalProps.length; i++) {
|
for (var i = 0; i < optionalProps.length; i++) {
|
||||||
var fallback = fallbackProps[Math.floor(i / 2)];
|
var fallbackProp = fallbackProps[Math.floor(i / 2)];
|
||||||
if (data.updatedSettings[fallback]) {
|
var fallbackValue = updatedSettings[fallbackProp];
|
||||||
var prop = optionalProps[i];
|
if (fallbackValue) {
|
||||||
if (!that.activeParticleProperties[prop] || (fallback === "color" && !that.activeParticleProperties[prop].red)) {
|
var optionalProp = optionalProps[i];
|
||||||
that.activeParticleProperties[prop] = entityProps[fallback];
|
if ((fallbackProp !== "color" && isNaN(entityProps[optionalProp])) || (fallbackProp === "color" && isNaN(entityProps[optionalProp].red))) {
|
||||||
|
that.updatedActiveParticleProperties[optionalProp] = fallbackValue;
|
||||||
needsUpdate = true;
|
needsUpdate = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needsUpdate) {
|
if (needsUpdate) {
|
||||||
sendActiveParticleProperties();
|
sendUpdatedActiveParticleProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (data.messageType === "page_loaded") {
|
} else if (data.messageType === "page_loaded") {
|
||||||
sendActiveParticleProperties();
|
sendActiveParticleProperties();
|
||||||
}
|
}
|
||||||
|
@ -85,12 +126,8 @@ ParticleExplorerTool = function() {
|
||||||
|
|
||||||
that.setActiveParticleEntity = function(id) {
|
that.setActiveParticleEntity = function(id) {
|
||||||
that.activeParticleEntity = id;
|
that.activeParticleEntity = id;
|
||||||
};
|
|
||||||
|
|
||||||
that.setActiveParticleProperties = function(properties) {
|
|
||||||
that.activeParticleProperties = properties;
|
|
||||||
sendActiveParticleProperties();
|
sendActiveParticleProperties();
|
||||||
};
|
};
|
||||||
|
|
||||||
return that;
|
return that;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue