From 2acc88261fe950acfdd042a23e534259a09cded8 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 28 Jan 2016 13:14:36 -0800 Subject: [PATCH 01/53] added particles --- examples/edit.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/examples/edit.js b/examples/edit.js index 900eaf8e82..b68468c049 100644 --- a/examples/edit.js +++ b/examples/edit.js @@ -183,7 +183,8 @@ var toolBar = (function() { newTextButton, newWebButton, newZoneButton, - newPolyVoxButton; + newPolyVoxButton, + newParticleButton function initialize() { toolBar = new ToolBar(0, 0, ToolBar.VERTICAL, "highfidelity.edit.toolbar", function(windowDimensions, toolbar) { @@ -321,6 +322,20 @@ var toolBar = (function() { visible: false }); + newParticleButton = toolBar.addTool({ + imageURL: toolIconUrl + "polyvox.svg", + subImage: { + x: 0, + y: 0, + width: 256, + height: 256 + }, + width: toolWidth, + height: toolHeight, + alpha: 0.9, + visible: false + }); + that.setActive(false); } @@ -367,6 +382,7 @@ var toolBar = (function() { toolBar.showTool(newWebButton, doShow); toolBar.showTool(newZoneButton, doShow); toolBar.showTool(newPolyVoxButton, doShow); + toolBar.showTool(newParticleButton, doShow); }; var RESIZE_INTERVAL = 50; @@ -623,6 +639,11 @@ var toolBar = (function() { return true; } + if (newParticleButton === toolBar.clicked(clickedOverlay)) { + print("EBL: NEW PARTICLES"); + Script.load('particle_explorer/particleExplorer.js'); + } + return false; }; From 0511ff70ac87c424aff0b9bf71179e067fd8d3c0 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 28 Jan 2016 14:34:19 -0800 Subject: [PATCH 02/53] particle panel in tool window --- examples/particle_explorer/index.html | 14 +- examples/particle_explorer/main.js | 125 ++++++++---------- .../particle_explorer/particleExplorer.js | 14 +- 3 files changed, 75 insertions(+), 78 deletions(-) diff --git a/examples/particle_explorer/index.html b/examples/particle_explorer/index.html index 4b9e2a9d36..b50d100934 100644 --- a/examples/particle_explorer/index.html +++ b/examples/particle_explorer/index.html @@ -16,14 +16,16 @@ - + + + + + +
+ +
+
+
+ + + \ No newline at end of file diff --git a/examples/particle_explorer/particleExplorerTool.js b/examples/particle_explorer/particleExplorerTool.js new file mode 100644 index 0000000000..9e8d519466 --- /dev/null +++ b/examples/particle_explorer/particleExplorerTool.js @@ -0,0 +1,20 @@ +var PARTICLE_EXPLORER_HTML_URL = Script.resolvePath('particleExplorer.html'); + +ParticleExplorerTool = function() { + var that = {}; + + var url = PARTICLE_EXPLORER_HTML_URL; + var webView = new OverlayWebWindow({ + title: 'Particle Explorer', source: url, toolWindow: true + }); + + var visible = false; + webView.setVisible(visible); + + that.setVisible = function(newVisible) { + visible = newVisible; + webView.setVisible(visible); + } + + +}; From 1a7887520d7076a775ef566719d401c42beda6d5 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 28 Jan 2016 16:38:24 -0800 Subject: [PATCH 04/53] in progress --- examples/edit.js | 2 +- examples/libraries/entityList.js | 19 ++----------------- examples/particle_explorer/main.js | 5 +++-- .../particle_explorer/particleExplorer.html | 2 +- .../particle_explorer/particleExplorerTool.js | 11 ++++++++++- 5 files changed, 17 insertions(+), 22 deletions(-) diff --git a/examples/edit.js b/examples/edit.js index 7ee56ba1d0..503c90d248 100644 --- a/examples/edit.js +++ b/examples/edit.js @@ -27,7 +27,7 @@ Script.include([ "libraries/entityCameraTool.js", "libraries/gridTool.js", "libraries/entityList.js", - "particle_explorer/particleExplorerTool.js", + "particle_explorer/particleExplorerTool.js?v1" + Math.random(), "libraries/lightOverlayManager.js", ]); diff --git a/examples/libraries/entityList.js b/examples/libraries/entityList.js index aeb8226061..588568c857 100644 --- a/examples/libraries/entityList.js +++ b/examples/libraries/entityList.js @@ -8,6 +8,8 @@ EntityListTool = function(opts) { title: 'Entities', source: url, toolWindow: true }); + + var searchRadius = 100; var visible = false; @@ -71,31 +73,14 @@ EntityListTool = function(opts) { webView.eventBridge.emitScriptEvent(JSON.stringify(data)); } - that.enableParticleTab = function(entityID) { - var data = { - type: "enableParticleTab", - entity: entityID - }; - webView.eventBridge.emitScriptEvent(JSON.stringify(data)); - } webView.eventBridge.webEventReceived.connect(function(data) { data = JSON.parse(data); if (data.type == "selectionUpdate") { - print("EBL CLICKED ON SOME SHIT " + JSON.stringify(data)) var ids = data.entityIds; var entityIDs = []; for (var i = 0; i < ids.length; i++) { entityIDs.push(ids[i]); - } - if (entityIDs.length === 1) { - //We selected just one entity, so see if that entity is a particle entity - var type = Entities.getEntityProperties(entityIDs[0], "type").type; - if (type === "ParticleEffect") { - that.enableParticleTab(entityIDs[0]); - } - - } selectionManager.setSelections(entityIDs); if (data.focus) { diff --git a/examples/particle_explorer/main.js b/examples/particle_explorer/main.js index c76eef42af..a8922acb9f 100644 --- a/examples/particle_explorer/main.js +++ b/examples/particle_explorer/main.js @@ -339,6 +339,7 @@ function writeVec3ToInterface(obj) { } function listenForSettingsUpdates() { + console.log("EBL sLISTENING FOR EVENTS") EventBridge.scriptEventReceived.connect(function(data) { data = JSON.parse(data); if (data.messageType === 'initial_settings') { @@ -349,8 +350,8 @@ function listenForSettingsUpdates() { loadGUI(); } - - if (date.type === "enableParticleTab") { + console.log("EBL RECIEVED EVENT - " + JSON.stringify(data)); + if (data.type === "enableParticleTab") { console.log("EBL JUST GOT AN ENABLE MESSAGE!"); } }); diff --git a/examples/particle_explorer/particleExplorer.html b/examples/particle_explorer/particleExplorer.html index b50d100934..c187df7e6d 100644 --- a/examples/particle_explorer/particleExplorer.html +++ b/examples/particle_explorer/particleExplorer.html @@ -18,7 +18,7 @@ - + - - -
- -
-
-
- - - \ No newline at end of file diff --git a/examples/particle_explorer/main.js b/examples/particle_explorer/main.js deleted file mode 100644 index a8922acb9f..0000000000 --- a/examples/particle_explorer/main.js +++ /dev/null @@ -1,482 +0,0 @@ -// -// main.js -// -// Created by James B. Pollack @imgntn on 9/26/2015 -// Copyright 2015 High Fidelity, Inc. -// Web app side of the App - contains GUI. -// This is an example of a new, easy way to do two way bindings between dynamically created GUI and in-world entities. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// -/*global window, alert, EventBridge, dat, listenForSettingsUpdates,createVec3Folder,createQuatFolder,writeVec3ToInterface,writeDataToInterface*/ - -var Settings = function() { - this.exportSettings = function() { - //copyExportSettingsToClipboard(); - showPreselectedPrompt(); - }; - this.importSettings = function() { - importSettings(); - }; -}; - -//2-way bindings-aren't quite ready yet. see bottom of file. -var AUTO_UPDATE = false; -var UPDATE_ALL_FREQUENCY = 100; - -var controllers = []; -var colorControllers = []; -var folders = []; -var gui = null; -var settings = new Settings(); -var updateInterval; - -var currentInputField; -var storedController; -//CHANGE TO WHITELIST -var keysToAllow = [ - 'isEmitting', - 'maxParticles', - 'lifespan', - 'emitRate', - 'emitSpeed', - 'speedSpread', - 'emitOrientation', - 'emitDimensios', - 'emitRadiusStart', - 'polarStart', - 'polarFinish', - 'azimuthFinish', - 'emitAcceleration', - 'accelerationSpread', - 'particleRadius', - 'radiusSpread', - 'radiusStart', - 'radiusFinish', - 'color', - 'colorSpread', - 'colorStart', - 'colorFinish', - 'alpha', - 'alphaSpread', - 'alphaFinish', - 'emitterShouldTrail' -]; - -var individualKeys = []; -var vec3Keys = []; -var quatKeys = []; -var colorKeys = []; - -window.onload = function() { - - openEventBridge(function() { - var stringifiedData = JSON.stringify({ - messageType: 'page_loaded' - }); - - EventBridge.emitWebEvent( - stringifiedData - ); - - listenForSettingsUpdates(); - window.onresize = setGUIWidthToWindowWidth; - }) - -}; - -function loadGUI() { - //whether or not to autoplace - gui = new dat.GUI({ - autoPlace: false - }); - - //if not autoplacing, put gui in a custom container - if (gui.autoPlace === false) { - var customContainer = document.getElementById('my-gui-container'); - customContainer.appendChild(gui.domElement); - } - - // presets for the GUI itself. a little confusing and import/export is mostly what we want to do at the moment. - // gui.remember(settings); - - var keys = _.keys(settings); - - _.each(keys, function(key) { - var shouldAllow = _.contains(keysToAllow, key); - - if (shouldAllow) { - var subKeys = _.keys(settings[key]); - var hasX = _.contains(subKeys, 'x'); - var hasY = _.contains(subKeys, 'y'); - var hasZ = _.contains(subKeys, 'z'); - var hasW = _.contains(subKeys, 'w'); - var hasRed = _.contains(subKeys, 'red'); - var hasGreen = _.contains(subKeys, 'green'); - var hasBlue = _.contains(subKeys, 'blue'); - - if ((hasX && hasY && hasZ) && hasW === false) { - vec3Keys.push(key); - } else if (hasX && hasY && hasZ && hasW) { - quatKeys.push(key); - } else if (hasRed || hasGreen || hasBlue) { - colorKeys.push(key); - - } else { - individualKeys.push(key); - } - } - }); - - //alphabetize our keys - individualKeys.sort(); - vec3Keys.sort(); - quatKeys.sort(); - colorKeys.sort(); - - //add to gui in the order they should appear - gui.add(settings, 'importSettings'); - gui.add(settings, 'exportSettings'); - addIndividualKeys(); - addFolders(); - - //set the gui width to match the web window width - gui.width = window.innerWidth; - - //2-way binding stuff - // if (AUTO_UPDATE) { - // setInterval(manuallyUpdateDisplay, UPDATE_ALL_FREQUENCY); - // registerDOMElementsForListenerBlocking(); - // } - -} - -function addIndividualKeys() { - _.each(individualKeys, function(key) { - //temporary patch for not crashing when this goes below 0 - var controller; - - if (key.indexOf('emitRate') > -1) { - controller = gui.add(settings, key).min(0); - } else { - controller = gui.add(settings, key); - - } - - //2-way - need to fix not being able to input exact values if constantly listening - //controller.listen(); - - //keep track of our controller - controllers.push(controller); - - //hook into change events for this gui controller - controller.onChange(function(value) { - // Fires on every change, drag, keypress, etc. - writeDataToInterface(this.property, value); - }); - - }); -} - -function addFolders() { - _.each(colorKeys, function(key) { - createColorPicker(key); - }); - _.each(vec3Keys, function(key) { - createVec3Folder(key); - }); - _.each(quatKeys, function(key) { - createQuatFolder(key); - }); -} - -function createColorPicker(key) { - var colorObject = settings[key]; - var colorArray = convertColorObjectToArray(colorObject); - settings[key] = colorArray; - var controller = gui.addColor(settings, key); - controller.onChange(function(value) { - var obj = {}; - obj[key] = convertColorArrayToObject(value); - writeVec3ToInterface(obj); - }); - - return; -} - -function createVec3Folder(category) { - var folder = gui.addFolder(category); - - folder.add(settings[category], 'x').step(0.1).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); - }); - - folder.add(settings[category], 'y').step(0.1).onChange(function(value) { - // Fires when a controller loses focus. - var obj = {}; - obj[category] = {}; - obj[category].x = settings[category].x; - obj[category][this.property] = value; - obj[category].z = settings[category].z; - writeVec3ToInterface(obj); - }); - - folder.add(settings[category], 'z').step(0.1).onChange(function(value) { - // Fires when a controller loses focus. - var obj = {}; - obj[category] = {}; - obj[category].y = settings[category].y; - obj[category].x = settings[category].x; - obj[category][this.property] = value; - writeVec3ToInterface(obj); - }); - - folders.push(folder); - folder.open(); -} - -function createQuatFolder(category) { - var folder = gui.addFolder(category); - - folder.add(settings[category], 'x').step(0.1).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; - obj[category].w = settings[category].w; - writeVec3ToInterface(obj); - }); - - folder.add(settings[category], 'y').step(0.1).onChange(function(value) { - // Fires when a controller loses focus. - var obj = {}; - obj[category] = {}; - obj[category].x = settings[category].x; - obj[category][this.property] = value; - obj[category].z = settings[category].z; - obj[category].w = settings[category].w; - writeVec3ToInterface(obj); - }); - - folder.add(settings[category], 'z').step(0.1).onChange(function(value) { - // Fires when a controller loses focus. - var obj = {}; - obj[category] = {}; - obj[category].x = settings[category].x; - obj[category].y = settings[category].y; - obj[category][this.property] = value; - obj[category].w = settings[category].w; - writeVec3ToInterface(obj); - }); - - folder.add(settings[category], 'w').step(0.1).onChange(function(value) { - // Fires when a controller loses focus. - var obj = {}; - obj[category] = {}; - obj[category].x = settings[category].x; - obj[category].y = settings[category].y; - obj[category].z = settings[category].z; - obj[category][this.property] = value; - writeVec3ToInterface(obj); - }); - - folders.push(folder); - folder.open(); -} - -function convertColorObjectToArray(colorObject) { - var colorArray = []; - - _.each(colorObject, function(singleColor) { - colorArray.push(singleColor); - }); - - return colorArray; -} - -function convertColorArrayToObject(colorArray) { - var colorObject = { - red: colorArray[0], - green: colorArray[1], - blue: colorArray[2] - }; - - return colorObject; -} - -function writeDataToInterface(property, value) { - var data = {}; - data[property] = value; - - var sendData = { - messageType: "settings_update", - updatedSettings: data - }; - - var stringifiedData = JSON.stringify(sendData); - - EventBridge.emitWebEvent(stringifiedData); -} - -function writeVec3ToInterface(obj) { - var sendData = { - messageType: "settings_update", - updatedSettings: obj - }; - - var stringifiedData = JSON.stringify(sendData); - - EventBridge.emitWebEvent(stringifiedData); -} - -function listenForSettingsUpdates() { - console.log("EBL sLISTENING FOR EVENTS") - EventBridge.scriptEventReceived.connect(function(data) { - data = JSON.parse(data); - if (data.messageType === 'initial_settings') { - _.each(data.initialSettings, function(value, key) { - settings[key] = {}; - settings[key] = value; - }); - - loadGUI(); - } - console.log("EBL RECIEVED EVENT - " + JSON.stringify(data)); - if (data.type === "enableParticleTab") { - console.log("EBL JUST GOT AN ENABLE MESSAGE!"); - } - }); -} - -function manuallyUpdateDisplay() { - // Iterate over all controllers - // this is expensive, write a method for indiviudal controllers and use it when the value is different than a cached value, perhaps. - var i; - for (i in gui.__controllers) { - gui.__controllers[i].updateDisplay(); - } -} - -function setGUIWidthToWindowWidth() { - if (gui !== null) { - gui.width = window.innerWidth; - } -} - -function handleInputKeyPress(e) { - if (e.keyCode === 13) { - importSettings(); - } - return false; -} - -function importSettings() { - var importInput = document.getElementById('importer-input'); - - try { - var importedSettings = JSON.parse(importInput.value); - - var keys = _.keys(importedSettings); - - _.each(keys, function(key) { - var shouldIgnore = _.contains(keysToIgnore, key); - - if (shouldIgnore) { - return; - } - - settings[key] = importedSettings[key]; - }); - - writeVec3ToInterface(settings); - - manuallyUpdateDisplay(); - } catch (e) { - alert('Not properly formatted JSON'); - } -} - -function prepareSettingsForExport() { - var keys = _.keys(settings); - - var exportSettings = {}; - - _.each(keys, function(key) { - var shouldIgnore = _.contains(keysToIgnore, key); - - if (shouldIgnore) { - return; - } - - if (key.indexOf('color') > -1) { - var colorObject = convertColorArrayToObject(settings[key]); - settings[key] = colorObject; - } - - exportSettings[key] = settings[key]; - }); - - return JSON.stringify(exportSettings); -} - -function showPreselectedPrompt() { - window.prompt("Ctrl-C to copy, then Enter.", prepareSettingsForExport()); -} - -function removeContainerDomElement() { - var elem = document.getElementById("my-gui-container"); - elem.parentNode.removeChild(elem); -} - -function removeListenerFromGUI(key) { - _.each(gui.__listening, function(controller, index) { - if (controller.property === key) { - storedController = controller; - gui.__listening.splice(index, 1); - } - }); -} - -//the section below is to try to work at achieving two way bindings; - -function addListenersBackToGUI() { - gui.__listening.push(storedController); - storedController = null; -} - -function registerDOMElementsForListenerBlocking() { - _.each(gui.__controllers, function(controller) { - var input = controller.domElement.childNodes[0]; - input.addEventListener('focus', function() { - console.log('INPUT ELEMENT GOT FOCUS!' + controller.property); - removeListenerFromGUI(controller.property); - }); - }); - - _.each(gui.__controllers, function(controller) { - var input = controller.domElement.childNodes[0]; - input.addEventListener('blur', function() { - console.log('INPUT ELEMENT GOT BLUR!' + controller.property); - addListenersBackToGUI(); - }); - }); - - // also listen to inputs inside of folders - _.each(gui.__folders, function(folder) { - _.each(folder.__controllers, function(controller) { - var input = controller.__input; - input.addEventListener('focus', function() { - console.log('FOLDER ELEMENT GOT FOCUS!' + controller.property); - }); - }); - }); -} \ No newline at end of file diff --git a/examples/particle_explorer/particleExplorer.html b/examples/particle_explorer/particleExplorer.html index c187df7e6d..1dcf2423c0 100644 --- a/examples/particle_explorer/particleExplorer.html +++ b/examples/particle_explorer/particleExplorer.html @@ -18,7 +18,7 @@ - +