From 663dadd1b4c266041ed686d3ba49f14bcbdc3482 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 4 Feb 2016 08:51:42 -0800 Subject: [PATCH 01/15] only disconnect mouse if connected --- examples/junkyard/junkyardClientReset.js | 22 +++++++++---------- .../CellScience/Scripts/clickToRideAndLook.js | 8 ++++--- .../CellScience/Scripts/navigationButton.js | 2 +- .../Scripts/playBackgroundAudio.js | 4 ++-- .../CellScience/importCellScience.js | 2 +- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/examples/junkyard/junkyardClientReset.js b/examples/junkyard/junkyardClientReset.js index c4dfa19c4f..36c87ea0dc 100644 --- a/examples/junkyard/junkyardClientReset.js +++ b/examples/junkyard/junkyardClientReset.js @@ -13,18 +13,18 @@ // var IMPORT_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/arfs/junkyard.json"; -var PASTE_ENTITIES_LOCATION = {x: 0, y: 0, z: 0}; -reset(); - -function reset() { - // Delete everything and re-import the junkyard arf - var e = Entities.findEntities(MyAvatar.position, 1000); - for (i = 0; i < e.length; i++) { - Entities.deleteEntity(e[i]); - } - importAssetResourceFile(); -} +var PASTE_ENTITIES_LOCATION = {x: 0, y: 20, z: 0}; +// reset(); +// function reset() { +// // Delete everything and re-import the junkyard arf +// var e = Entities.findEntities(MyAvatar.position, 1000); +// for (i = 0; i < e.length; i++) { +// Entities.deleteEntity(e[i]); +// } +// importAssetResourceFile(); +// } + importAssetResourceFile() function importAssetResourceFile() { Clipboard.importEntities(IMPORT_URL); Clipboard.pasteEntities(PASTE_ENTITIES_LOCATION); diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/clickToRideAndLook.js b/unpublishedScripts/DomainContent/CellScience/Scripts/clickToRideAndLook.js index 805cdc423b..1ba0206edc 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/clickToRideAndLook.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/clickToRideAndLook.js @@ -24,7 +24,7 @@ this.buttonImageURL = baseURL + "GUI/GUI_jump_off.png"; this.addExitButton(); this.isRiding = false; - + self.mouseIsConnected = false; if (this.data && this.data.isDynein) { this.rotation = 180; } else { @@ -66,6 +66,7 @@ visible: true }); Controller.mousePressEvent.connect(this.onMousePress); + self.mouseIsConnected = true; Script.update.connect(this.update); } } @@ -136,8 +137,9 @@ // print("unload"); self.reset(); - Controller.mousePressEvent.disconnect(this.onMousePress); + if (self.mouseIsConnected === true) { + Controller.mousePressEvent.disconnect(this.onMousePress); + } } - }); \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/navigationButton.js b/unpublishedScripts/DomainContent/CellScience/Scripts/navigationButton.js index 9e1874ed00..31f6612296 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/navigationButton.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/navigationButton.js @@ -8,7 +8,7 @@ (function() { - var version = 1; + var version = 2; var added = false; this.frame = 0; var utilsScript = Script.resolvePath('utils.js'); diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/playBackgroundAudio.js b/unpublishedScripts/DomainContent/CellScience/Scripts/playBackgroundAudio.js index 856b9f8f67..ff1f772d4e 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/playBackgroundAudio.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/playBackgroundAudio.js @@ -8,13 +8,13 @@ (function() { var self = this; var baseURL = "https://hifi-content.s3.amazonaws.com/DomainContent/CellScience/"; - var version = 9; + var version = 10; this.preload = function(entityId) { self.soundPlaying = false; self.entityId = entityId; self.getUserData(); self.soundURL = baseURL + "Audio/" + self.userData.name + ".wav?" + version; - print("Script.clearTimeout creating WAV name location is " + baseURL + "Audio/" + self.userData.name + ".wav"); + print("creating WAV name location is " + baseURL + "Audio/" + self.userData.name + ".wav"); self.soundOptions = { stereo: true, diff --git a/unpublishedScripts/DomainContent/CellScience/importCellScience.js b/unpublishedScripts/DomainContent/CellScience/importCellScience.js index 58888584a9..36b60bf939 100644 --- a/unpublishedScripts/DomainContent/CellScience/importCellScience.js +++ b/unpublishedScripts/DomainContent/CellScience/importCellScience.js @@ -5,7 +5,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -var version = 1004; +var version = 1005; var cellLayout; var baseLocation = "https://hifi-content.s3.amazonaws.com/DomainContent/CellScience/"; From 82f9b3f97f21dc202306d34c135f872503bc661e Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 4 Feb 2016 11:33:54 -0800 Subject: [PATCH 02/15] increase vol for voiceover --- .../DomainContent/CellScience/Scripts/showButtonToPlaySound.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js b/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js index 65fddd7ad3..7e51dcd9d1 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js @@ -24,7 +24,7 @@ stereo: true, loop: false, localOnly: true, - volume: 0.035 + volume: 0.2 }; this.sound = SoundCache.getSound(this.soundURL); } From 708c6e8d25431dc20713dff56240110ab5b4f460 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 4 Feb 2016 11:37:46 -0800 Subject: [PATCH 03/15] volume --- .../DomainContent/CellScience/Scripts/showButtonToPlaySound.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js b/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js index 7e51dcd9d1..277896e1bd 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js @@ -24,7 +24,7 @@ stereo: true, loop: false, localOnly: true, - volume: 0.2 + volume: 0.135 }; this.sound = SoundCache.getSound(this.soundURL); } From c377254cb0f7b0aa289be43846e42e3b54445140 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 4 Feb 2016 14:34:41 -0800 Subject: [PATCH 04/15] revert junkyardreset --- examples/junkyard/junkyardClientReset.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/junkyard/junkyardClientReset.js b/examples/junkyard/junkyardClientReset.js index 36c87ea0dc..c4dfa19c4f 100644 --- a/examples/junkyard/junkyardClientReset.js +++ b/examples/junkyard/junkyardClientReset.js @@ -13,18 +13,18 @@ // var IMPORT_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/arfs/junkyard.json"; -var PASTE_ENTITIES_LOCATION = {x: 0, y: 20, z: 0}; -// reset(); +var PASTE_ENTITIES_LOCATION = {x: 0, y: 0, z: 0}; +reset(); + +function reset() { + // Delete everything and re-import the junkyard arf + var e = Entities.findEntities(MyAvatar.position, 1000); + for (i = 0; i < e.length; i++) { + Entities.deleteEntity(e[i]); + } + importAssetResourceFile(); +} -// function reset() { -// // Delete everything and re-import the junkyard arf -// var e = Entities.findEntities(MyAvatar.position, 1000); -// for (i = 0; i < e.length; i++) { -// Entities.deleteEntity(e[i]); -// } -// importAssetResourceFile(); -// } - importAssetResourceFile() function importAssetResourceFile() { Clipboard.importEntities(IMPORT_URL); Clipboard.pasteEntities(PASTE_ENTITIES_LOCATION); From 76350a39f8091239b66fd98e40ea4ff6e849ac0b Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 4 Feb 2016 14:46:58 -0800 Subject: [PATCH 05/15] increase volume more and fix not having logDebug function --- .../CellScience/Scripts/showButtonToPlaySound.js | 2 +- unpublishedScripts/DomainContent/CellScience/Scripts/utils.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js b/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js index 277896e1bd..0a4c709c69 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js @@ -24,7 +24,7 @@ stereo: true, loop: false, localOnly: true, - volume: 0.135 + volume: 0.26 }; this.sound = SoundCache.getSound(this.soundURL); } diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/utils.js b/unpublishedScripts/DomainContent/CellScience/Scripts/utils.js index a79637acc3..10a0827e9d 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/utils.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/utils.js @@ -20,8 +20,8 @@ getEntityUserData = function(id) { try { results = JSON.parse(properties.userData); } catch (err) { - logDebug(err); - logDebug(properties.userData); + print('error parsing json'); + print('properties are:'+ properties.userData); } } return results ? results : {}; From 0c92c52d267e98ebc7d46fa52519376efab2ef7e Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 4 Feb 2016 14:52:50 -0800 Subject: [PATCH 06/15] more volume --- .../DomainContent/CellScience/Scripts/showButtonToPlaySound.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js b/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js index 0a4c709c69..e505a532e3 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js @@ -24,7 +24,7 @@ stereo: true, loop: false, localOnly: true, - volume: 0.26 + volume: 0.5 }; this.sound = SoundCache.getSound(this.soundURL); } From 82789113a833a2ce9d24e77a17452bb2b6633871 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Fri, 5 Feb 2016 19:50:08 -0800 Subject: [PATCH 07/15] quiet print messages --- .../CellScience/Scripts/clickToRideAndLook.js | 64 +- .../CellScience/Scripts/moveRandomly.js | 4 +- .../CellScience/Scripts/navigationButton.js | 90 +- .../Scripts/playBackgroundAudio.js | 74 +- .../Scripts/showButtonToPlaySound.js | 190 ++-- .../CellScience/Scripts/showIdentification.js | 75 +- .../CellScience/Scripts/utils.js | 4 +- .../DomainContent/CellScience/Scripts/zoom.js | 93 +- .../CellScience/importCellScience.js | 846 +++++++++--------- 9 files changed, 792 insertions(+), 648 deletions(-) diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/clickToRideAndLook.js b/unpublishedScripts/DomainContent/CellScience/Scripts/clickToRideAndLook.js index 1ba0206edc..d6a9b79467 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/clickToRideAndLook.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/clickToRideAndLook.js @@ -18,21 +18,46 @@ var self = this; this.preload = function(entityId) { - this.entityId = entityId; - this.data = JSON.parse(Entities.getEntityProperties(this.entityId, "userData").userData); - this.buttonImageURL = baseURL + "GUI/GUI_jump_off.png"; - this.addExitButton(); - this.isRiding = false; - self.mouseIsConnected = false; - if (this.data && this.data.isDynein) { - this.rotation = 180; - } else { - this.rotation = 0; - } - + this.initialize(entityId); + self.initTimeout = null; } + this.initialize = function(entityId) { + //print(' should initialize' + entityId) + var properties = Entities.getEntityProperties(entityId); + if (properties.userData.length === 0 || properties.hasOwnProperty('userData') === false) { + self.initTimeout = Script.setTimeout(function() { + //print(' no user data yet, try again in one second') + self.initialize(entityId); + }, 1000) + + } else { + //print(' userdata before parse attempt' + properties.userData) + self.userData = null; + try { + self.userData = JSON.parse(properties.userData); + } catch (err) { + //print(' error parsing json'); + //print(' properties are:' + properties.userData); + return; + } + + self.data = self.userData; + self.buttonImageURL = baseURL + "GUI/GUI_jump_off.png"; + self.addExitButton(); + self.isRiding = false; + self.mouseIsConnected = false; + if (self.data && self.data.isDynein) { + self.rotation = 180; + } else { + self.rotation = 0; + } + } + } + + + this.addExitButton = function() { this.windowDimensions = Controller.getViewportDimensions(); this.buttonWidth = 75; @@ -53,14 +78,16 @@ } this.clickReleaseOnEntity = function(entityId, mouseEvent) { - // print('CLICKED ON MOTOR PROTEIN') + + //print('CLICKED ON MOTOR PROTEIN') + return; if (mouseEvent.isLeftButton && !self.isRiding) { - print("GET ON"); + //print("GET ON"); self.isRiding = true; if (!self.entityId) { self.entityId = entityId; } - self.entityLocation = Entities.getEntityProperties(this.entityId, "position").position; + self.entityLocation = Entities.getEntityProperties(self.entityId, "position").position; self.targetLocation = Vec3.sum(self.entityLocation, TARGET_OFFSET); Overlays.editOverlay(self.exitButton, { visible: true @@ -117,7 +144,7 @@ y: event.y }); if (event.isLeftButton && clickedOverlay === self.exitButton) { - print("GET OFF"); + //print("GET OFF"); Script.update.disconnect(this.update); self.reset(); } @@ -138,7 +165,10 @@ self.reset(); if (self.mouseIsConnected === true) { - Controller.mousePressEvent.disconnect(this.onMousePress); + Controller.mousePressEvent.disconnect(self.onMousePress); + } + if (self.initTimeout !== null) { + Script.clearTimeout(self.initTimeout); } } diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/moveRandomly.js b/unpublishedScripts/DomainContent/CellScience/Scripts/moveRandomly.js index 7a3f2cf8fd..7c880a44b6 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/moveRandomly.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/moveRandomly.js @@ -40,7 +40,7 @@ z: Math.random() - 0.5 }; - // print("POS magnitude is " + magnitudeV + " and direction is " + directionV.x); + //print("POS magnitude is " + magnitudeV + " and direction is " + directionV.x); Entities.editEntity(self.entityId, { velocity: Vec3.multiply(magnitudeV, Vec3.normalize(directionV)) @@ -60,7 +60,7 @@ y: Math.random() - 0.5, z: Math.random() - 0.5 }; - // print("ROT magnitude is " + magnitudeAV + " and direction is " + directionAV.x); + //print("ROT magnitude is " + magnitudeAV + " and direction is " + directionAV.x); Entities.editEntity(self.entityId, { angularVelocity: Vec3.multiply(magnitudeAV, Vec3.normalize(directionAV)) diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/navigationButton.js b/unpublishedScripts/DomainContent/CellScience/Scripts/navigationButton.js index 31f6612296..2798b58807 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/navigationButton.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/navigationButton.js @@ -1,4 +1,3 @@ - // Copyright 2016 High Fidelity, Inc. // // @@ -8,7 +7,7 @@ (function() { - var version = 2; + var version = 10; var added = false; this.frame = 0; var utilsScript = Script.resolvePath('utils.js'); @@ -19,35 +18,61 @@ this.preload = function(entityId) { this.entityId = entityId; - var mySavedSettings = Settings.getValue(entityId); + this.initialize(entityId); + this.initTimeout = null; + } - if (mySavedSettings.buttons !== undefined) { - // print('NAV preload buttons'+ mySavedSettings.buttons) - mySavedSettings.buttons.forEach(function(b) { - // print('NAV deleting button'+ b) - Overlays.deleteOverlay(b); - }) - Settings.setValue(entityId,'') - } - - - self.getUserData(); - this.buttonImageURL = baseURL + "GUI/GUI_" + self.userData.name + ".png?" + version; - if (self.button === undefined) { - // print('NAV NO BUTTON ADDING ONE!!') - self.button = true; - self.addButton(); + this.initialize = function(entityId) { + // print(' should initialize' + entityId) + var properties = Entities.getEntityProperties(entityId); + if (properties.userData.length === 0 || properties.hasOwnProperty('userData') === false) { + self.initTimeout = Script.setTimeout(function() { + // print(' no user data yet, try again in one second') + self.initialize(entityId); + }, 1000) } else { - // print('NAV SELF ALREADY HAS A BUTTON!!') - } + // print(' userdata before parse attempt' + properties.userData) + self.userData = null; + try { + self.userData = JSON.parse(properties.userData); + } catch (err) { + // print(' error parsing json'); + // print(' properties are:' + properties.userData); + return; + } + + var mySavedSettings = Settings.getValue(entityId); + + if (mySavedSettings.buttons !== undefined) { + //print(' preload buttons' + mySavedSettings.buttons) + mySavedSettings.buttons.forEach(function(b) { + //print(' deleting button' + b) + Overlays.deleteOverlay(b); + }) + Settings.setValue(entityId, '') + } + + + self.buttonImageURL = baseURL + "GUI/GUI_" + self.userData.name + ".png?" + version; + //print('BUTTON IMAGE URL:' + self.buttonImageURL) + if (self.button === undefined) { + // print('NAV NO BUTTON ADDING ONE!!') + self.button = true; + self.addButton(); + + } else { + // print('NAV SELF ALREADY HAS A BUTTON!!') + } + + } } + + this.addButton = function() { - - self.getUserData(); this.windowDimensions = Controller.getViewportDimensions(); this.buttonWidth = 150; this.buttonHeight = 50; @@ -87,7 +112,7 @@ if (self.frame < 10) { self.frame++; } else { - // this.lookAt(this.userData.target); + // this.lookAt(this.userData.target); } } @@ -107,7 +132,7 @@ } this.lookAtTarget = function() { - self.getUserData(); + var direction = Vec3.normalize(Vec3.subtract(self.userData.entryPoint, self.userData.target)); var pitch = Quat.angleAxis(Math.asin(-direction.y) * 180.0 / Math.PI, { x: 1, @@ -125,16 +150,6 @@ MyAvatar.headYaw = 0; } - - this.getUserData = function() { - this.properties = Entities.getEntityProperties(this.entityId); - if (self.properties.userData) { - this.userData = JSON.parse(this.properties.userData); - } else { - this.userData = {}; - } - } - var buttonDeleter; var deleterCount = 0; this.unload = function() { @@ -144,6 +159,11 @@ Controller.mousePressEvent.disconnect(this.onClick); // Script.update.disconnect(this.update); + + + if (this.initTimeout !== null) { + Script.clearTimeout(this.initTimeout); + } } Controller.mousePressEvent.connect(this.onClick); diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/playBackgroundAudio.js b/unpublishedScripts/DomainContent/CellScience/Scripts/playBackgroundAudio.js index ff1f772d4e..6edccc211c 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/playBackgroundAudio.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/playBackgroundAudio.js @@ -12,50 +12,72 @@ this.preload = function(entityId) { self.soundPlaying = false; self.entityId = entityId; - self.getUserData(); - self.soundURL = baseURL + "Audio/" + self.userData.name + ".wav?" + version; - print("creating WAV name location is " + baseURL + "Audio/" + self.userData.name + ".wav"); - - self.soundOptions = { - stereo: true, - loop: true, - localOnly: true, - volume: 0.035 - }; - - this.sound = SoundCache.getSound(self.soundURL); - + this.initTimeout = null; + this.initialize(entityId); } - this.getUserData = function() { - self.properties = Entities.getEntityProperties(self.entityId); - if (self.properties.userData) { - self.userData = JSON.parse(this.properties.userData); + this.initialize = function(entityID) { + //print(' should initialize' + entityID) + var properties = Entities.getEntityProperties(entityID); + if (properties.userData.length === 0 || properties.hasOwnProperty('userData') === false) { + self.initTimeout = Script.setTimeout(function() { + //print(' no user data yet, try again in one second') + self.initialize(entityID); + }, 1000) + } else { - self.userData = {}; + //print(' userdata before parse attempt' + properties.userData) + self.userData = null; + try { + self.userData = JSON.parse(properties.userData); + } catch (err) { + //print(' error parsing json'); + //print(' properties are:' + properties.userData); + return; + } + + + //print(' USERDATA NAME ' + self.userData.name) + self.soundURL = baseURL + "Audio/" + self.userData.name + ".wav?" + version; + //print(" creating WAV name location is " + baseURL + "Audio/" + self.userData.name + ".wav"); + //print(' self soundURL' + self.soundURL) + + self.soundOptions = { + stereo: true, + loop: true, + localOnly: true, + volume: 0.035 + }; + + self.sound = SoundCache.getSound(self.soundURL); } } this.enterEntity = function(entityID) { - print("entering audio zone"); + //print("entering audio zone"); if (self.sound.downloaded) { - print("playing background audio named " + self.userData.name + "which has been downloaded"); + //print("playing background audio named " + self.userData.name + "which has been downloaded"); this.soundPlaying = Audio.playSound(self.sound, self.soundOptions); } else { - print("sound is not downloaded"); + //print("sound is not downloaded"); } } - this.leaveEntity = function(entityID) { - print("leaving audio area " + self.userData.name); + //print("leaving audio area " + self.userData.name); if (self.soundPlaying !== false) { - print("not null"); - print("Stopped sound " + self.userData.name); + //print("not null"); + //print("Stopped sound " + self.userData.name); self.soundPlaying.stop(); } else { - print("Sound not playing"); + //print("Sound not playing"); + } + } + + this.unload = function() { + if (this.initTimeout !== null) { + Script.clearTimeout(this.initTimeout); } } diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js b/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js index e505a532e3..d37655f09b 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js @@ -6,97 +6,117 @@ // (function() { - var baseURL = "https://hifi-content.s3.amazonaws.com/hifi-content/DomainContent/CellScience/"; - var self = this; - this.buttonImageURL = baseURL + "GUI/play_audio.svg?2"; + var baseURL = "https://hifi-content.s3.amazonaws.com/hifi-content/DomainContent/CellScience/"; + var self = this; + this.buttonImageURL = baseURL + "GUI/play_audio.svg?2"; - - - this.preload = function(entityId) { - this.entityId = entityId; - self.addButton(); - this.buttonShowing = false; - self.getUserData(); - this.showDistance = self.userData.showDistance; - this.soundURL = baseURL + "Audio/" + self.userData.soundName + ".wav"; - print("distance = " + self.userData.showDistance + ", sound = " + this.soundURL); - this.soundOptions = { - stereo: true, - loop: false, - localOnly: true, - volume: 0.5 - }; - this.sound = SoundCache.getSound(this.soundURL); - } - - this.addButton = function() { - this.windowDimensions = Controller.getViewportDimensions(); - this.buttonWidth = 100; - this.buttonHeight = 100; - this.buttonPadding = 0; - - this.buttonPositionX = (self.windowDimensions.x - self.buttonPadding) / 2 - self.buttonWidth; - this.buttonPositionY = (self.windowDimensions.y - self.buttonHeight) - (self.buttonHeight + self.buttonPadding); - this.button = Overlays.addOverlay("image", { - x: self.buttonPositionX, - y: self.buttonPositionY, - width: self.buttonWidth, - height: self.buttonHeight, - imageURL: self.buttonImageURL, - visible: false, - alpha: 1.0 - }); - } - - this.getUserData = function() { - this.properties = Entities.getEntityProperties(this.entityId); - if (self.properties.userData) { - this.userData = JSON.parse(this.properties.userData); - } else { - this.userData = {}; + this.preload = function(entityId) { + this.entityId = entityId; + this.initialize(entityId) + this.initTimeout = null; } - } - this.update = function(deltaTime) { + this.initialize = function(entityId) { + print(' should initialize' + entityId) + var properties = Entities.getEntityProperties(entityId); + if (properties.userData.length === 0 || properties.hasOwnProperty('userData') === false) { + self.initTimeout = Script.setTimeout(function() { + print(' no user data yet, try again in one second') + self.initialize(entityId); + }, 1000) - self.distance = Vec3.distance(MyAvatar.position, Entities.getEntityProperties(self.entityId).position); - //print(self.distance); - if (!self.buttonShowing && self.distance < self.userData.showDistance) { - self.buttonShowing = true; - Overlays.editOverlay(self.button, { - visible: true - }); - } else if (self.buttonShowing && self.distance > self.userData.showDistance) { - self.buttonShowing = false; - Overlays.editOverlay(self.button, { - visible: false - }); - } - } - - this.onClick = function(event) { - var clickedOverlay = Overlays.getOverlayAtPoint({ - x: event.x, - y: event.y - }); - if (clickedOverlay === self.button) { - print("button was clicked"); - if (self.sound.downloaded) { - print("play sound"); - Audio.playSound(self.sound, self.soundOptions); } else { - print("not downloaded"); + print(' userdata before parse attempt' + properties.userData) + self.userData = null; + try { + self.userData = JSON.parse(properties.userData); + } catch (err) { + print(' error parsing json'); + print(' properties are:' + properties.userData); + return; + } + + + + self.addButton(); + self.buttonShowing = false; + self.showDistance = self.userData.showDistance; + self.soundURL = baseURL + "Audio/" + self.userData.soundName + ".wav"; + // print("distance = " + self.userData.showDistance + ", sound = " + self.soundURL); + self.soundOptions = { + stereo: true, + loop: false, + localOnly: true, + volume: 0.75 + }; + self.sound = SoundCache.getSound(this.soundURL); + + + } - } - } - this.unload = function() { - Overlays.deleteOverlay(self.button); - Controller.mousePressEvent.disconnect(this.onClick); - Script.update.disconnect(this.update); - } + this.addButton = function() { + this.windowDimensions = Controller.getViewportDimensions(); + this.buttonWidth = 100; + this.buttonHeight = 100; + this.buttonPadding = 0; - Controller.mousePressEvent.connect(this.onClick); - Script.update.connect(this.update); + this.buttonPositionX = (self.windowDimensions.x - self.buttonPadding) / 2 - self.buttonWidth; + this.buttonPositionY = (self.windowDimensions.y - self.buttonHeight) - (self.buttonHeight + self.buttonPadding); + this.button = Overlays.addOverlay("image", { + x: self.buttonPositionX, + y: self.buttonPositionY, + width: self.buttonWidth, + height: self.buttonHeight, + imageURL: self.buttonImageURL, + visible: false, + alpha: 1.0 + }); + } -}); \ No newline at end of file + this.update = function(deltaTime) { + + self.distance = Vec3.distance(MyAvatar.position, Entities.getEntityProperties(self.entityId).position); + //print(self.distance); + if (!self.buttonShowing && self.distance < self.userData.showDistance) { + self.buttonShowing = true; + Overlays.editOverlay(self.button, { + visible: true + }); + } else if (self.buttonShowing && self.distance > self.userData.showDistance) { + self.buttonShowing = false; + Overlays.editOverlay(self.button, { + visible: false + }); + } + } + + this.onClick = function(event) { + var clickedOverlay = Overlays.getOverlayAtPoint({ + x: event.x, + y: event.y + }); + if (clickedOverlay === self.button) { + print("button was clicked"); + if (self.sound.downloaded) { + print("play sound"); + Audio.playSound(self.sound, self.soundOptions); + } else { + print("not downloaded"); + } + } + } + + this.unload = function() { + Overlays.deleteOverlay(self.button); + Controller.mousePressEvent.disconnect(this.onClick); + Script.update.disconnect(this.update); + if (this.initTimeout !== null) { + Script.clearTimeout(this.initTimeout); + } + } + + Controller.mousePressEvent.connect(this.onClick); + Script.update.connect(this.update); + + }); \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/showIdentification.js b/unpublishedScripts/DomainContent/CellScience/Scripts/showIdentification.js index 2e37f3a51f..7c019865e9 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/showIdentification.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/showIdentification.js @@ -14,20 +14,47 @@ this.preload = function(entityId) { this.soundPlaying = null; this.entityId = entityId; - self.getUserData(); - this.labelURL = baseURL + "GUI/labels_" + self.userData.name + ".png?" + version; - this.showDistance = self.userData.showDistance; - this.soundURL = baseURL + "Audio/" + self.userData.name + ".wav"; - this.soundOptions = { - stereo: true, - loop: false, - localOnly: true, - volume: 0.035, - position: this.position - }; - this.sound = SoundCache.getSound(this.soundURL); - this.buttonImageURL = baseURL + "GUI/GUI_audio.png?" + version; - self.addButton(); + self.initTimeout = null; + this.initialize(entityId); + + + } + + this.initialize = function(entityId) { + print(' should initialize' + entityId) + var properties = Entities.getEntityProperties(entityId); + if (properties.userData.length === 0 || properties.hasOwnProperty('userData') === false) { + self.initTimeout = Script.setTimeout(function() { + //print(' no user data yet, try again in one second') + self.initialize(entityId); + }, 1000) + + } else { + //print(' userdata before parse attempt' + properties.userData) + self.userData = null; + try { + self.userData = JSON.parse(properties.userData); + } catch (err) { + //print(' error parsing json'); + //print(' properties are:' + properties.userData); + return; + } + + self.labelURL = baseURL + "GUI/labels_" + self.userData.name + ".png?" + version; + self.showDistance = self.userData.showDistance; + self.soundURL = baseURL + "Audio/" + self.userData.name + ".wav"; + self.soundOptions = { + stereo: true, + loop: false, + localOnly: true, + volume: 0.035, + position: properties.position + }; + self.sound = SoundCache.getSound(self.soundURL); + self.buttonImageURL = baseURL + "GUI/GUI_audio.png?" + version; + self.addButton(); + + } } this.addButton = function() { @@ -78,9 +105,8 @@ this.enterEntity = function(entityID) { - // self.getUserData(); - print("entering entity and showing" + self.labelURL); - //self.buttonShowing = true; + // print("entering entity and showing" + self.labelURL); + Overlays.editOverlay(self.button, { visible: true }); @@ -92,9 +118,8 @@ this.leaveEntity = function(entityID) { - // self.getUserData(); - // print("leaving entity " + self.userData.name); - //self.buttonShowing = false; + // print("leaving entity " + self.userData.name); + print(Overlays); Overlays.editOverlay(self.button, { visible: false @@ -110,16 +135,16 @@ y: event.y }); if (clickedOverlay == self.button) { - print("button was clicked"); + //print("button was clicked"); if (self.sound.downloaded) { - print("play sound"); + // print("play sound"); Overlays.editOverlay(self.button, { visible: false }); this.soundPlaying = Audio.playSound(self.sound, self.soundOptions); } else { - print("not downloaded"); + // print("not downloaded"); } } } @@ -129,7 +154,9 @@ if (this.soundPlaying !== null) { this.soundPlaying.stop(); } - + if (self.initTimeout !== null) { + Script.clearTimeout(self.initTimeout); + } Controller.mousePressEvent.disconnect(this.onClick); } diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/utils.js b/unpublishedScripts/DomainContent/CellScience/Scripts/utils.js index 10a0827e9d..8b1f5c4055 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/utils.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/utils.js @@ -20,8 +20,8 @@ getEntityUserData = function(id) { try { results = JSON.parse(properties.userData); } catch (err) { - print('error parsing json'); - print('properties are:'+ properties.userData); + // print('error parsing json'); + // print('properties are:'+ properties.userData); } } return results ? results : {}; diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/zoom.js b/unpublishedScripts/DomainContent/CellScience/Scripts/zoom.js index 101ce54a5e..8b720b7fec 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/zoom.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/zoom.js @@ -14,64 +14,76 @@ this.entered = true; this.preload = function(entityID) { - this.entityId = entityID; + this.initialize(entityID); + this.initTimeout = null; + } + this.initialize = function(entityID) { + // print(' should initialize') var properties = Entities.getEntityProperties(entityID); - portalDestination = properties.userData; - animationURL = properties.modelURL; - this.soundOptions = { - stereo: true, - loop: false, - localOnly: false, - position: this.position, - volume: 0.035 - }; - - this.teleportSound = SoundCache.getSound("https://hifi-content.s3.amazonaws.com/DomainContent/CellScience/Audio/whoosh.wav"); - //print('Script.clearTimeout PRELOADING A ZOOM ENTITY') - print(" portal destination is " + portalDestination); + if (properties.userData.length === 0 || properties.hasOwnProperty('userData') === false) { + self.initTimeout = Script.setTimeout(function() { + // print(' no user data yet, try again in one second') + self.initialize(entityID); + }, 1000) + } else { + // print(' has userData') + self.portalDestination = properties.userData; + animationURL = properties.modelURL; + self.soundOptions = { + stereo: true, + loop: false, + localOnly: false, + position: properties.position, + volume: 0.5 + }; + + self.teleportSound = SoundCache.getSound("https://hifi-content.s3.amazonaws.com/DomainContent/CellScience/Audio/whoosh.wav"); + // print(" portal destination is " + self.portalDestination); + } } this.enterEntity = function(entityID) { - print('Script.clearTimeout ENTERED A BOUNDARY ENTITY, SHOULD ZOOM', entityID) + // print(' ENTERED A BOUNDARY ENTITY, SHOULD ZOOM', entityID) var data = JSON.parse(Entities.getEntityProperties(this.entityId).userData); - - + // print(' DATA IS::' + data) if (data != null) { - print("Teleporting to (" + data.location.x + ", " + data.location.y + ", " + data.location.z + ")"); + // print("Teleporting to (" + data.location.x + ", " + data.location.y + ", " + data.location.z + ")"); if (self.teleportSound.downloaded) { //print("play sound"); + MyAvatar.position = data.location; Audio.playSound(self.teleportSound, self.soundOptions); + } else { //print("not downloaded"); } - this.lookAt(data.target, data.location); - + // this.lookAt(data.target, data.location); } } - this.lookAt = function(targetPosition, avatarPosition) { - var direction = Vec3.normalize(Vec3.subtract(MyAvatar.position, targetPosition)); + // this.lookAt = function(targetPosition, avatarPosition) { + // print('GOING TO') + // var direction = Vec3.normalize(Vec3.subtract(MyAvatar.position, targetPosition)); - var pitch = Quat.angleAxis(Math.asin(-direction.y) * 180.0 / Math.PI, { - x: 1, - y: 0, - z: 0 - }); - var yaw = Quat.angleAxis(Math.atan2(direction.x, direction.z) * 180.0 / Math.PI, { - x: 0, - y: 1, - z: 0 - }); - - MyAvatar.goToLocation(avatarPosition, true, yaw); - MyAvatar.headYaw = 0; - } + // var pitch = Quat.angleAxis(Math.asin(-direction.y) * 180.0 / Math.PI, { + // x: 1, + // y: 0, + // z: 0 + // }); + // var yaw = Quat.angleAxis(Math.atan2(direction.x, direction.z) * 180.0 / Math.PI, { + // x: 0, + // y: 1, + // z: 0 + // }); + // print('JBP ZOOM DEBUG YO') + // MyAvatar.goToLocation(avatarPosition, true, yaw); + // MyAvatar.headYaw = 0; + // } @@ -81,9 +93,18 @@ animationSettings: '{ "frameIndex": 1, "running": false }' }); this.entered = false; + if (this.initTimeout !== null) { + Script.clearTimeout(this.initTimeout); + } //playSound(); } + this.unload = function() { + if (this.initTimeout !== null) { + Script.clearTimeout(this.initTimeout); + } + } + this.hoverEnterEntity = function(entityID) { Entities.editEntity(entityID, { animationURL: animationURL, diff --git a/unpublishedScripts/DomainContent/CellScience/importCellScience.js b/unpublishedScripts/DomainContent/CellScience/importCellScience.js index 36b60bf939..ad18c2db3c 100644 --- a/unpublishedScripts/DomainContent/CellScience/importCellScience.js +++ b/unpublishedScripts/DomainContent/CellScience/importCellScience.js @@ -5,7 +5,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -var version = 1005; +var version = 1015; var cellLayout; var baseLocation = "https://hifi-content.s3.amazonaws.com/DomainContent/CellScience/"; @@ -79,398 +79,137 @@ var locations = { }, 1000] }; -var scenes = [ - { - name: "Cells", - objects: "", - location: locations.cells[0], - entryPoint: locations.cells[1], - zone: { - dimensions: { - x: 4000, - y: 4000, - z: 4000 - }, - light: { - r: 255, - g: 200, - b: 200 - }, - intensity: 1.1, - ambient: 0.7, - sun: true, - skybox: "cells_skybox_cross" +var scenes = [{ + name: "Cells", + objects: "", + location: locations.cells[0], + entryPoint: locations.cells[1], + zone: { + dimensions: { + x: 4000, + y: 4000, + z: 4000 }, - instances: [{ - model: "Cell", + light: { + r: 255, + g: 200, + b: 200 + }, + intensity: 1.1, + ambient: 0.7, + sun: true, + skybox: "cells_skybox_cross" + }, + instances: [{ + model: "Cell", + dimensions: { + x: 550, + y: 620, + z: 550 + }, + offset: { + x: 0, + y: 0, + z: 0 + }, + radius: 500, + number: 10, + userData: JSON.stringify({ + target: locations.cellLayout[1], + location: locations.cellLayout[0], + baseURL: baseLocation + }), + script: "zoom.js?" + version, + visible: true + }], + boundary: { + radius: locations.cells[2], + center: locations.cells[0], + location: locations.cellLayout[1], + target: locations.cellLayout[0] + } +}, { + name: "CellLayout", + objects: cellLayout, + location: locations.cellLayout[0], + entryPoint: locations.cellLayout[1], + zone: { + dimensions: { + x: 4000, + y: 4000, + z: 4000 + }, + light: { + r: 247, + g: 233, + b: 220 + }, + intensity: 2.3, + ambient: 0.7, + sun: true, + skybox: "cosmos_skybox_blurred" + }, + instances: [{ + model: "translation", dimensions: { - x: 550, - y: 620, - z: 550 + x: 10, + y: 16, + z: 10 }, offset: { x: 0, y: 0, z: 0 }, - radius: 500, - number: 10, + radius: 300, + number: 15, + userData: JSON.stringify({ + grabbableKey: { + grabbable: false + }, + target: locations.ribosome[1], + location: locations.ribosome[0], + baseURL: baseLocation + }), + script: "zoom.js?" + version, + visible: true + }, { + model: "vesicle", + dimensions: { + x: 60, + y: 60, + z: 60 + }, + randomSize: 10, + offset: { + x: 0, + y: 0, + z: 0 + }, + radius: 1000, + number: 45, + userData: JSON.stringify({ + grabbableKey: { + grabbable: false + } + }), script: "moveRandomly.js?" + version, visible: true - }], - boundary: { - radius: locations.cells[2], - center: locations.cells[0], - location: locations.cellLayout[1], - target: locations.cellLayout[0] - } - }, { - name: "CellLayout", - objects: cellLayout, - location: locations.cellLayout[0], - entryPoint: locations.cellLayout[1], - zone: { + }, { //golgi vesicles + model: "vesicle", dimensions: { - x: 4000, - y: 4000, - z: 4000 - }, - light: { - r: 247, - g: 233, - b: 220 - }, - intensity: 2.3, - ambient: 0.7, - sun: true, - skybox: "cosmos_skybox_blurred" - }, - instances: [{ - model: "translation", - dimensions: { - x: 10, - y: 16, - z: 10 - }, - offset: { - x: 0, - y: 0, - z: 0 - }, - radius: 300, - number: 15, - userData: JSON.stringify({ - grabbableKey: { - grabbable: false - }, - target: locations.ribosome[1], - location: locations.ribosome[0], - baseURL: baseLocation - }), - script: "zoom.js?" + version, - visible: true - }, { - model: "vesicle", - dimensions: { - x: 60, - y: 60, - z: 60 - }, - randomSize: 10, - offset: { - x: 0, - y: 0, - z: 0 - }, - radius: 1000, - number: 45, - userData: JSON.stringify({ - grabbableKey: { - grabbable: false - } - }), - script: "moveRandomly.js?" + version, - visible: true - }, { //golgi vesicles - model: "vesicle", - dimensions: { - x: 10, - y: 10, - z: 10 - }, - randomSize: 10, - offset: { - x: -319, - y: 66, - z: 976 - }, - radius: 140, - number: 20, - userData: JSON.stringify({ - grabbableKey: { - grabbable: false - } - }), - script: "", - visible: true - }, { //golgi vesicles - model: "vesicle", - dimensions: { - x: 15, - y: 15, - z: 15 - }, - randomSize: 10, - offset: { - x: -319, - y: 66, - z: 976 - }, - radius: 115, - number: 15, - userData: JSON.stringify({ - grabbableKey: { - grabbable: false - } - }), - script: "moveRandomly.js?" + version, - visible: true - }, { - model: "vesicle", - dimensions: { - x: 50, - y: 50, - z: 50 - }, - randomSize: 10, - offset: { - x: 0, - y: 0, - z: 0 - }, - radius: 600, - number: 30, - userData: JSON.stringify({ - grabbableKey: { - grabbable: false - } - }), - script: "", - visible: true - }, { //outer vesicles - model: "vesicle", - dimensions: { - x: 60, - y: 60, - z: 60 - }, - randomSize: 10, - offset: { - x: 0, - y: 0, - z: 0 - }, - radius: 1600, - number: 45, - userData: JSON.stringify({ - grabbableKey: { - grabbable: false - } - }), - script: "", - visible: true - }, { //outer vesicles - model: "vesicle", - dimensions: { - x: 40, - y: 40, - z: 40 - }, - randomSize: 10, - offset: { - x: 0, - y: 0, - z: 0 - }, - radius: 1400, - number: 45, - userData: JSON.stringify({ - grabbableKey: { - grabbable: false - } - }), - script: "moveRandomly.js?" + version, - visible: true - }, { //outer vesicles - model: "vesicle", - dimensions: { - x: 80, - y: 80, - z: 80 - }, - randomSize: 10, - offset: { - x: 0, - y: 0, - z: 0 - }, - radius: 1800, - number: 45, - userData: JSON.stringify({ - grabbableKey: { - grabbable: false - } - }), - script: "moveRandomly.js?" + version, - visible: true - }, - // {//wigglies - // model:"wiggly", - // dimensions:{x:320,y:40,z:160}, - // randomSize: 10, - // offset:{x:0,y:0,z:0}, - // radius:1800, - // number:50, - // userData:"", - // script:"moveRandomly", - // visible:true - // }, - //// {//wigglies - // model:"wiggly", - // dimensions:{x:640,y:80,z:320}, - // randomSize: 10, - // offset:{x:0,y:0,z:0}, - // radius:2100, - // number:50, - // userData:"", - // script:"moveRandomly", - // visible:true - // }, - { - model: "hexokinase", - dimensions: { - x: 3, - y: 4, - z: 3 - }, - randomSize: 10, - offset: { - x: 236, - y: 8, - z: 771 - }, - radius: 80, - number: 15, - userData: JSON.stringify({ - grabbableKey: { - grabbable: false - }, - target: locations.hexokinase[1], - location: locations.hexokinase[0], - baseURL: baseLocation - }), - script: "zoom.js?" + version, - visible: true - }, { - model: "pfructo_kinase", - dimensions: { - x: 3, - y: 4, - z: 3 - }, - randomSize: 10, - offset: { - x: 236, - y: 8, - z: 771 - }, - radius: 60, - number: 15, - userData: JSON.stringify({ - grabbableKey: { - grabbable: false - } - }), - script: "", - visible: true - }, { - model: "glucose_isomerase", - dimensions: { - x: 3, - y: 4, - z: 3 - }, - randomSize: 10, - offset: { - x: 236, - y: 8, - z: 771 - }, - radius: 70, - number: 15, - userData: JSON.stringify({ - grabbableKey: { - grabbable: false - } - }), - script: "", - visible: true - } - // { - // model:"NPC", - // dimensions:{x:20,y:20,z:20}, - // randomSize: 10, - // offset:{x:208.593693,y:6.113100222,z:153.3202277}, - // radius:520, - // number:25, - // userData: "", - // script:"", - // visible:true - // } - - - ], - boundary: { - radius: locations.cellLayout[2], - center: locations.cellLayout[0], - location: locations.cells[1], - target: locations.cells[0] - } - }, { - name: "Ribosome", - objects: "", - location: locations.ribosome[0], - entryPoint: locations.ribosome[1], - zone: { - dimensions: { - x: 4000, - y: 4000, - z: 4000 - }, - light: { - r: 250, - g: 185, - b: 182 - }, - intensity: 0.6, - ambient: 2.9, - sun: true, - skybox: "ribosome_skybox" - }, - instances: [{ - model: "translation_highres", - dimensions: { - x: 500, - y: 500, - z: 200 + x: 10, + y: 10, + z: 10 }, + randomSize: 10, offset: { - x: 0, - y: 0, - z: 0 + x: -319, + y: 66, + z: 976 }, - radius: 1, - number: 1, + radius: 140, + number: 20, userData: JSON.stringify({ grabbableKey: { grabbable: false @@ -478,48 +217,201 @@ var scenes = [ }), script: "", visible: true - }], - boundary: { - radius: locations.ribosome[2], - center: locations.ribosome[0], - location: locations.translation[1], - target: locations.translation[0] - } - }, { - name: "Hexokinase", - objects: "", - location: locations.hexokinase[0], - entryPoint: locations.hexokinase[1], - zone: { + }, { //golgi vesicles + model: "vesicle", dimensions: { - x: 4000, - y: 4000, - z: 4000 + x: 15, + y: 15, + z: 15 }, - light: { - r: 255, - g: 255, - b: 255 + randomSize: 10, + offset: { + x: -319, + y: 66, + z: 976 }, - intensity: 0.6, - ambient: 0.6, - sun: true, - skybox: "hexokinase_skybox" - }, - instances: [{ - model: "hexokinase_highres", + radius: 115, + number: 15, + userData: JSON.stringify({ + grabbableKey: { + grabbable: false + } + }), + script: "moveRandomly.js?" + version, + visible: true + }, { + model: "vesicle", dimensions: { - x: 600, - y: 600, - z: 600 + x: 50, + y: 50, + z: 50 }, + randomSize: 10, offset: { x: 0, y: 0, z: 0 }, - radius: 1, - number: 1, + radius: 600, + number: 30, + userData: JSON.stringify({ + grabbableKey: { + grabbable: false + } + }), + script: "", + visible: true + }, { //outer vesicles + model: "vesicle", + dimensions: { + x: 60, + y: 60, + z: 60 + }, + randomSize: 10, + offset: { + x: 0, + y: 0, + z: 0 + }, + radius: 1600, + number: 45, + userData: JSON.stringify({ + grabbableKey: { + grabbable: false + } + }), + script: "", + visible: true + }, { //outer vesicles + model: "vesicle", + dimensions: { + x: 40, + y: 40, + z: 40 + }, + randomSize: 10, + offset: { + x: 0, + y: 0, + z: 0 + }, + radius: 1400, + number: 45, + userData: JSON.stringify({ + grabbableKey: { + grabbable: false + } + }), + script: "moveRandomly.js?" + version, + visible: true + }, { //outer vesicles + model: "vesicle", + dimensions: { + x: 80, + y: 80, + z: 80 + }, + randomSize: 10, + offset: { + x: 0, + y: 0, + z: 0 + }, + radius: 1800, + number: 45, + userData: JSON.stringify({ + grabbableKey: { + grabbable: false + } + }), + script: "moveRandomly.js?" + version, + visible: true + }, + // {//wigglies + // model:"wiggly", + // dimensions:{x:320,y:40,z:160}, + // randomSize: 10, + // offset:{x:0,y:0,z:0}, + // radius:1800, + // number:50, + // userData:"", + // script:"moveRandomly", + // visible:true + // }, + //// {//wigglies + // model:"wiggly", + // dimensions:{x:640,y:80,z:320}, + // randomSize: 10, + // offset:{x:0,y:0,z:0}, + // radius:2100, + // number:50, + // userData:"", + // script:"moveRandomly", + // visible:true + // }, + { + model: "hexokinase", + dimensions: { + x: 3, + y: 4, + z: 3 + }, + randomSize: 10, + offset: { + x: 236, + y: 8, + z: 771 + }, + radius: 80, + number: 15, + userData: JSON.stringify({ + grabbableKey: { + grabbable: false + }, + target: locations.hexokinase[1], + location: locations.hexokinase[0], + baseURL: baseLocation + }), + script: "zoom.js?" + version, + visible: true + }, { + model: "pfructo_kinase", + dimensions: { + x: 3, + y: 4, + z: 3 + }, + randomSize: 10, + offset: { + x: 236, + y: 8, + z: 771 + }, + radius: 60, + number: 15, + userData: JSON.stringify({ + grabbableKey: { + grabbable: false + } + }), + script: "", + visible: true + }, { + model: "glucose_isomerase", + dimensions: { + x: 3, + y: 4, + z: 3 + }, + randomSize: 10, + offset: { + x: 236, + y: 8, + z: 771 + }, + radius: 70, + number: 15, userData: JSON.stringify({ grabbableKey: { grabbable: false @@ -527,15 +419,126 @@ var scenes = [ }), script: "", visible: true - }], - boundary: { - radius: locations.hexokinase[2], - center: locations.hexokinase[0], - location: locations.mitochondria[1], - target: locations.mitochondria[0] } + // { + // model:"NPC", + // dimensions:{x:20,y:20,z:20}, + // randomSize: 10, + // offset:{x:208.593693,y:6.113100222,z:153.3202277}, + // radius:520, + // number:25, + // userData: "", + // script:"", + // visible:true + // } + + + ], + boundary: { + radius: locations.cellLayout[2], + center: locations.cellLayout[0], + location: locations.cells[1], + target: locations.cells[0] } -]; +}, { + name: "Ribosome", + objects: "", + location: locations.ribosome[0], + entryPoint: locations.ribosome[1], + zone: { + dimensions: { + x: 4000, + y: 4000, + z: 4000 + }, + light: { + r: 250, + g: 185, + b: 182 + }, + intensity: 0.6, + ambient: 2.9, + sun: true, + skybox: "ribosome_skybox" + }, + instances: [{ + model: "translation_highres", + dimensions: { + x: 500, + y: 500, + z: 200 + }, + offset: { + x: 0, + y: 0, + z: 0 + }, + radius: 1, + number: 1, + userData: JSON.stringify({ + grabbableKey: { + grabbable: false + } + }), + script: "", + visible: true + }], + boundary: { + radius: locations.ribosome[2], + center: locations.ribosome[0], + location: locations.translation[1], + target: locations.translation[0] + } +}, { + name: "Hexokinase", + objects: "", + location: locations.hexokinase[0], + entryPoint: locations.hexokinase[1], + zone: { + dimensions: { + x: 4000, + y: 4000, + z: 4000 + }, + light: { + r: 255, + g: 255, + b: 255 + }, + intensity: 0.6, + ambient: 0.6, + sun: true, + skybox: "hexokinase_skybox" + }, + instances: [{ + model: "hexokinase_highres", + dimensions: { + x: 600, + y: 600, + z: 600 + }, + offset: { + x: 0, + y: 0, + z: 0 + }, + radius: 1, + number: 1, + userData: JSON.stringify({ + grabbableKey: { + grabbable: false + } + }), + script: "", + visible: true + }], + boundary: { + radius: locations.hexokinase[2], + center: locations.hexokinase[0], + location: locations.mitochondria[1], + target: locations.mitochondria[0] + } +}]; function ImportScene(scene) { @@ -637,6 +640,7 @@ function createLayoutLights() { }) } + function CreateNavigationButton(scene, number) { // print('NAV NAVIGATION CREATING NAV!!' +scene.name + " " + number) @@ -811,7 +815,7 @@ function CreateInstances(scene) { }, idBounds, 150); } - print('Script.clearTimeout SCRIPT AT CREATE ENTITY: ' + script) + //print('SCRIPT AT CREATE ENTITY: ' + script) CreateEntity(scene.instances[i].model, position, rotation, scene.instances[i].dimensions, url, script, scene.instances[i].userData, scene.instances[i].visible); } } @@ -890,7 +894,7 @@ function getPointOnSphereOfRadius(radius, number, totalNumber) { // print("inc " + inc + " off " + off + " y " + y + " r " + r + " phi " + phi); if (isNaN(r)) { - print("r is not a number"); + //print("r is not a number"); r = 1; } @@ -913,7 +917,7 @@ function CreateEntity(name, position, rotation, dimensions, url, script, userDat scriptLocation = baseLocation + "Scripts/" + script; } - print('Script.clearTimeout SCRIPT LOCATION IN CREATE ENTITY' + scriptLocation) + //print(' SCRIPT LOCATION IN CREATE ENTITY' + scriptLocation) Entities.addEntity({ type: "Model", name: name, From 720175f862779b4adb9ef64401238ed2875ac9ae Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Fri, 5 Feb 2016 19:51:02 -0800 Subject: [PATCH 08/15] a couple more prints --- .../CellScience/Scripts/showButtonToPlaySound.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js b/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js index d37655f09b..429fd0b902 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js @@ -17,22 +17,22 @@ } this.initialize = function(entityId) { - print(' should initialize' + entityId) + //print(' should initialize' + entityId) var properties = Entities.getEntityProperties(entityId); if (properties.userData.length === 0 || properties.hasOwnProperty('userData') === false) { self.initTimeout = Script.setTimeout(function() { - print(' no user data yet, try again in one second') + // print(' no user data yet, try again in one second') self.initialize(entityId); }, 1000) } else { - print(' userdata before parse attempt' + properties.userData) + //print(' userdata before parse attempt' + properties.userData) self.userData = null; try { self.userData = JSON.parse(properties.userData); } catch (err) { - print(' error parsing json'); - print(' properties are:' + properties.userData); + // print(' error parsing json'); + // print(' properties are:' + properties.userData); return; } @@ -97,12 +97,12 @@ y: event.y }); if (clickedOverlay === self.button) { - print("button was clicked"); + //print("button was clicked"); if (self.sound.downloaded) { - print("play sound"); + //print("play sound"); Audio.playSound(self.sound, self.soundOptions); } else { - print("not downloaded"); + //print("not downloaded"); } } } From a80641a2c46022d26343201fab63889ab74a7e2d Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 8 Feb 2016 13:15:49 -0800 Subject: [PATCH 09/15] changes --- .../CellScience/Scripts/navigationButton.js | 2 +- .../Scripts/playBackgroundAudio.js | 2 +- .../CellScience/Scripts/showIdentification.js | 4 +- .../CellScience/backgroundMusicAC.js | 97 +++++++++++++++++++ .../CellScience/importCellScience.js | 23 +++-- 5 files changed, 112 insertions(+), 16 deletions(-) create mode 100644 unpublishedScripts/DomainContent/CellScience/backgroundMusicAC.js diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/navigationButton.js b/unpublishedScripts/DomainContent/CellScience/Scripts/navigationButton.js index 2798b58807..ee8e3d0753 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/navigationButton.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/navigationButton.js @@ -7,7 +7,7 @@ (function() { - var version = 10; + var version = 11; var added = false; this.frame = 0; var utilsScript = Script.resolvePath('utils.js'); diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/playBackgroundAudio.js b/unpublishedScripts/DomainContent/CellScience/Scripts/playBackgroundAudio.js index 6edccc211c..87302dd743 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/playBackgroundAudio.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/playBackgroundAudio.js @@ -8,7 +8,7 @@ (function() { var self = this; var baseURL = "https://hifi-content.s3.amazonaws.com/DomainContent/CellScience/"; - var version = 10; + var version = 11; this.preload = function(entityId) { self.soundPlaying = false; self.entityId = entityId; diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/showIdentification.js b/unpublishedScripts/DomainContent/CellScience/Scripts/showIdentification.js index 7c019865e9..d8b32ab176 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/showIdentification.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/showIdentification.js @@ -10,7 +10,7 @@ var self = this; var baseURL = "https://hifi-content.s3.amazonaws.com/DomainContent/CellScience/"; - var version = 1; + var version = 2; this.preload = function(entityId) { this.soundPlaying = null; this.entityId = entityId; @@ -21,7 +21,7 @@ } this.initialize = function(entityId) { - print(' should initialize' + entityId) + //print(' should initialize' + entityId) var properties = Entities.getEntityProperties(entityId); if (properties.userData.length === 0 || properties.hasOwnProperty('userData') === false) { self.initTimeout = Script.setTimeout(function() { diff --git a/unpublishedScripts/DomainContent/CellScience/backgroundMusicAC.js b/unpublishedScripts/DomainContent/CellScience/backgroundMusicAC.js new file mode 100644 index 0000000000..b38390ed3c --- /dev/null +++ b/unpublishedScripts/DomainContent/CellScience/backgroundMusicAC.js @@ -0,0 +1,97 @@ +var soundMap = [{ + name: 'Cells', + url: "http://hifi-content.s3.amazonaws.com/DomainContent/CellScience/Audio/Cells.wav", + audioOptions: { + position: { + x: 15850, + y: 15850, + z: 15850 + }, + volume: 0.4, + loop: true + } + }, { + name: 'Cell Layout', + url: "http://hifi-content.s3.amazonaws.com/DomainContent/CellScience/Audio/CellLayout.wav", + audioOptions: { + position: { + x: 15950, + y: 15950, + z: 15950 + }, + volume: 0.4, + loop: true + } + }, { + name: 'Ribsome', + url: "http://hifi-content.s3.amazonaws.com/DomainContent/CellScience/Audio/Ribosome.wav", + audioOptions: { + position: { + x: 15650, + y: 15650, + z: 15650 + }, + volume: 0.4, + loop: true + } + }, { + name: 'Hexokinase', + url: "http://hifi-content.s3.amazonaws.com/DomainContent/CellScience/Audio/Hexokinase.wav", + audioOptions: { + position: { + x: 15750, + y: 15750, + z: 15750 + }, + volume: 0.4, + loop: true + } + } + +]; + + +function loadSounds() { + soundMap.forEach(function(soundData) { + soundData.sound = SoundCache.getSound(soundData.url); + }); +} + +function playSound(soundData) { + if (soundData.injector) { + // try/catch in case the injector QObject has been deleted already + try { + soundData.injector.stop(); + } catch (e) { + print('error playing sound' + e) + } + } + soundData.injector = Audio.playSound(soundData.sound, soundData.audioOptions); +} + +function checkDownloaded(soundData) { + if (soundData.sound.downloaded) { + + Script.clearInterval(soundData.downloadTimer); + + if (soundData.hasOwnProperty('playAtInterval')) { + soundData.playingInterval = Script.setInterval(function() { + playSound(soundData) + }, soundData.playAtInterval); + } else { + playSound(soundData); + } + + } +} + +function startCheckDownloadedTimers() { + soundMap.forEach(function(soundData) { + soundData.downloadTimer = Script.setInterval(function() { + checkDownloaded(soundData); + }, 1000); + }); +} + +loadSounds(); +startCheckDownloadedTimers(); \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/CellScience/importCellScience.js b/unpublishedScripts/DomainContent/CellScience/importCellScience.js index ad18c2db3c..fe4a3389e1 100644 --- a/unpublishedScripts/DomainContent/CellScience/importCellScience.js +++ b/unpublishedScripts/DomainContent/CellScience/importCellScience.js @@ -5,7 +5,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -var version = 1015; +var version = 1016; var cellLayout; var baseLocation = "https://hifi-content.s3.amazonaws.com/DomainContent/CellScience/"; @@ -115,8 +115,7 @@ var scenes = [{ radius: 500, number: 10, userData: JSON.stringify({ - target: locations.cellLayout[1], - location: locations.cellLayout[0], + location: locations.cellLayout[1], baseURL: baseLocation }), script: "zoom.js?" + version, @@ -597,7 +596,7 @@ function ImportScene(scene) { CreateInstances(scene); CreateBoundary(scene); - CreateBackgroundAudio(scene.name, scene.location, scene.dimensions); + // CreateBackgroundAudio(scene.name, scene.location, scene.dimensions); // print("done " + scene.name); @@ -654,9 +653,9 @@ function CreateNavigationButton(scene, number) { blue: 0 }, dimensions: { - x: 10, - y: 10, - z: 10 + x: 16000, + y: 16000, + z: 16000 }, visible: false, userData: JSON.stringify({ @@ -669,7 +668,7 @@ function CreateNavigationButton(scene, number) { grabbable: false } }), - // position:{x:3000,y:13500,z:3000}, + position:{x:0,y:0,z:0}, script: baseLocation + "Scripts/navigationButton.js?" + version, collisionless: true, @@ -853,10 +852,10 @@ function CreateBackgroundAudio(name, position) { Entities.addEntity({ type: "Sphere", name: "Location " + name + " background audio", - dimensions: { - x: 4000, - y: 4000, - z: 4000 + dimensions: { + x: 16000, + y: 16000, + z: 16000 }, position: position, visible: false, From 325c7525c7cd5dbb7f3ee597f5e4a3d89ba8c3f9 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 8 Feb 2016 13:43:41 -0800 Subject: [PATCH 10/15] work --- .../DomainContent/CellScience/Scripts/zoom.js | 39 ++++++++++--------- .../CellScience/backgroundMusicAC.js | 27 +++++++++++-- .../CellScience/importCellScience.js | 1 + 3 files changed, 45 insertions(+), 22 deletions(-) diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/zoom.js b/unpublishedScripts/DomainContent/CellScience/Scripts/zoom.js index 8b720b7fec..5e5a2d0e55 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/zoom.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/zoom.js @@ -61,29 +61,32 @@ } // this.lookAt(data.target, data.location); - + if(data.hasOwnProperty('entryPoint')&&data.hasOwnProperty('target')){ + this.lookAtTarget(data.entryPoint,data.target); + } } } - // this.lookAt = function(targetPosition, avatarPosition) { - // print('GOING TO') - // var direction = Vec3.normalize(Vec3.subtract(MyAvatar.position, targetPosition)); + this.lookAtTarget = function(entryPoint,target) { - // var pitch = Quat.angleAxis(Math.asin(-direction.y) * 180.0 / Math.PI, { - // x: 1, - // y: 0, - // z: 0 - // }); - // var yaw = Quat.angleAxis(Math.atan2(direction.x, direction.z) * 180.0 / Math.PI, { - // x: 0, - // y: 1, - // z: 0 - // }); - // print('JBP ZOOM DEBUG YO') - // MyAvatar.goToLocation(avatarPosition, true, yaw); - // MyAvatar.headYaw = 0; - // } + var direction = Vec3.normalize(Vec3.subtract(entryPoint, target)); + var pitch = Quat.angleAxis(Math.asin(-direction.y) * 180.0 / Math.PI, { + x: 1, + y: 0, + z: 0 + }); + var yaw = Quat.angleAxis(Math.atan2(direction.x, direction.z) * 180.0 / Math.PI, { + x: 0, + y: 1, + z: 0 + }); + + MyAvatar.goToLocation(entryPoint, true, yaw); + + MyAvatar.headYaw = 0; + + } diff --git a/unpublishedScripts/DomainContent/CellScience/backgroundMusicAC.js b/unpublishedScripts/DomainContent/CellScience/backgroundMusicAC.js index b38390ed3c..0ee5b3bf32 100644 --- a/unpublishedScripts/DomainContent/CellScience/backgroundMusicAC.js +++ b/unpublishedScripts/DomainContent/CellScience/backgroundMusicAC.js @@ -7,7 +7,7 @@ var soundMap = [{ y: 15850, z: 15850 }, - volume: 0.4, + volume: 0.1, loop: true } }, { @@ -19,7 +19,7 @@ var soundMap = [{ y: 15950, z: 15950 }, - volume: 0.4, + volume: 0.1, loop: true } }, { @@ -31,7 +31,7 @@ var soundMap = [{ y: 15650, z: 15650 }, - volume: 0.4, + volume: 0.1, loop: true } }, { @@ -43,7 +43,7 @@ var soundMap = [{ y: 15750, z: 15750 }, - volume: 0.4, + volume: 0.1, loop: true } } @@ -93,5 +93,24 @@ function startCheckDownloadedTimers() { }); } +Script.scriptEnding.connect(function() { + soundMap.forEach(function(soundData) { + + if (soundData.hasOwnProperty("injector")) { + soundData.injector.stop(); + } + + if (soundData.hasOwnProperty("downloadTimer")) { + Script.clearInterval(soundData.downloadTimer); + } + + if (soundData.hasOwnProperty("playingInterval")) { + Script.clearInterval(soundData.playingInterval); + } + + }); + +}); + loadSounds(); startCheckDownloadedTimers(); \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/CellScience/importCellScience.js b/unpublishedScripts/DomainContent/CellScience/importCellScience.js index fe4a3389e1..6be5311f9d 100644 --- a/unpublishedScripts/DomainContent/CellScience/importCellScience.js +++ b/unpublishedScripts/DomainContent/CellScience/importCellScience.js @@ -115,6 +115,7 @@ var scenes = [{ radius: 500, number: 10, userData: JSON.stringify({ + entryPoint:locations.cellLayout[1], location: locations.cellLayout[1], baseURL: baseLocation }), From 0368bfc4ee20c5b963dd0050b199706b6b07ef2e Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 8 Feb 2016 13:53:12 -0800 Subject: [PATCH 11/15] sound on the server --- .../CellScience/importCellScience.js | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/unpublishedScripts/DomainContent/CellScience/importCellScience.js b/unpublishedScripts/DomainContent/CellScience/importCellScience.js index 6be5311f9d..bf0e41bb62 100644 --- a/unpublishedScripts/DomainContent/CellScience/importCellScience.js +++ b/unpublishedScripts/DomainContent/CellScience/importCellScience.js @@ -115,8 +115,8 @@ var scenes = [{ radius: 500, number: 10, userData: JSON.stringify({ - entryPoint:locations.cellLayout[1], - location: locations.cellLayout[1], + target: locations.cellLayout[1], + location: locations.cellLayout[0], baseURL: baseLocation }), script: "zoom.js?" + version, @@ -597,7 +597,7 @@ function ImportScene(scene) { CreateInstances(scene); CreateBoundary(scene); - // CreateBackgroundAudio(scene.name, scene.location, scene.dimensions); + CreateBackgroundAudio(scene.name, scene.location, scene.dimensions); // print("done " + scene.name); @@ -654,9 +654,9 @@ function CreateNavigationButton(scene, number) { blue: 0 }, dimensions: { - x: 16000, - y: 16000, - z: 16000 + x: 10, + y: 10, + z: 10 }, visible: false, userData: JSON.stringify({ @@ -669,7 +669,7 @@ function CreateNavigationButton(scene, number) { grabbable: false } }), - position:{x:0,y:0,z:0}, + // position:{x:3000,y:13500,z:3000}, script: baseLocation + "Scripts/navigationButton.js?" + version, collisionless: true, @@ -853,10 +853,10 @@ function CreateBackgroundAudio(name, position) { Entities.addEntity({ type: "Sphere", name: "Location " + name + " background audio", - dimensions: { - x: 16000, - y: 16000, - z: 16000 + dimensions: { + x: 4000, + y: 4000, + z: 4000 }, position: position, visible: false, From 937ba3b79665e55c6e33d9cad65d45b52a363efb Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 8 Feb 2016 16:07:54 -0800 Subject: [PATCH 12/15] zoom differently o avoid bug --- .../DomainContent/CellScience/Scripts/zoom.js | 26 ++++++++----------- .../CellScience/importCellScience.js | 7 ++--- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/zoom.js b/unpublishedScripts/DomainContent/CellScience/Scripts/zoom.js index 5e5a2d0e55..f29d5023c9 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/zoom.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/zoom.js @@ -45,31 +45,27 @@ } this.enterEntity = function(entityID) { - // print(' ENTERED A BOUNDARY ENTITY, SHOULD ZOOM', entityID) + print('JBP ENTERED A BOUNDARY ENTITY, SHOULD ZOOM', entityID) var data = JSON.parse(Entities.getEntityProperties(this.entityId).userData); - // print(' DATA IS::' + data) + print('JBP DATA IS::' + data) if (data != null) { - // print("Teleporting to (" + data.location.x + ", " + data.location.y + ", " + data.location.z + ")"); - if (self.teleportSound.downloaded) { - //print("play sound"); - MyAvatar.position = data.location; - Audio.playSound(self.teleportSound, self.soundOptions); + print("JBP Teleporting to (" + data.location.x + ", " + data.location.y + ", " + data.location.z + ")"); - } else { - //print("not downloaded"); - } + MyAvatar.position = data.location; + + // if (data.hasOwnProperty('entryPoint') && data.hasOwnProperty('target')) { + // this.lookAtTarget(data.entryPoint, data.target); + // } + // else{ - // this.lookAt(data.target, data.location); - if(data.hasOwnProperty('entryPoint')&&data.hasOwnProperty('target')){ - this.lookAtTarget(data.entryPoint,data.target); - } + // } } } this.lookAtTarget = function(entryPoint,target) { - + print('JBP SHOULD LOOK AT TARGET') var direction = Vec3.normalize(Vec3.subtract(entryPoint, target)); var pitch = Quat.angleAxis(Math.asin(-direction.y) * 180.0 / Math.PI, { x: 1, diff --git a/unpublishedScripts/DomainContent/CellScience/importCellScience.js b/unpublishedScripts/DomainContent/CellScience/importCellScience.js index bf0e41bb62..acc68da932 100644 --- a/unpublishedScripts/DomainContent/CellScience/importCellScience.js +++ b/unpublishedScripts/DomainContent/CellScience/importCellScience.js @@ -5,7 +5,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -var version = 1016; +var version = 1021; var cellLayout; var baseLocation = "https://hifi-content.s3.amazonaws.com/DomainContent/CellScience/"; @@ -115,8 +115,9 @@ var scenes = [{ radius: 500, number: 10, userData: JSON.stringify({ + entryPoint: locations.cellLayout[1], target: locations.cellLayout[1], - location: locations.cellLayout[0], + location: locations.cellLayout[1], baseURL: baseLocation }), script: "zoom.js?" + version, @@ -597,7 +598,7 @@ function ImportScene(scene) { CreateInstances(scene); CreateBoundary(scene); - CreateBackgroundAudio(scene.name, scene.location, scene.dimensions); + // CreateBackgroundAudio(scene.name, scene.location, scene.dimensions); // print("done " + scene.name); From d920a3d7214f581e33a85fd32679ca96c4a8a79c Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 9 Feb 2016 18:05:14 -0800 Subject: [PATCH 13/15] updates --- .../CellScience/Scripts/deleteAll.js | 17 ---- .../CellScience/Scripts/findScripts.js | 21 ----- .../CellScience/Scripts/navigationButton.js | 18 ++-- .../Scripts/playBackgroundAudio.js | 86 ------------------- .../DomainContent/CellScience/Scripts/zoom.js | 9 +- .../CellScience/importCellScience.js | 74 +++++++--------- 6 files changed, 42 insertions(+), 183 deletions(-) delete mode 100644 unpublishedScripts/DomainContent/CellScience/Scripts/deleteAll.js delete mode 100644 unpublishedScripts/DomainContent/CellScience/Scripts/findScripts.js delete mode 100644 unpublishedScripts/DomainContent/CellScience/Scripts/playBackgroundAudio.js diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/deleteAll.js b/unpublishedScripts/DomainContent/CellScience/Scripts/deleteAll.js deleted file mode 100644 index 716a5a8424..0000000000 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/deleteAll.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2016 High Fidelity, Inc. -// -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -function deleteAllInRadius(r) { - var n = 0; - var arrayFound = Entities.findEntities(MyAvatar.position, r); - for (var i = 0; i < arrayFound.length; i++) { - Entities.deleteEntity(arrayFound[i]); - } - print("deleted " + arrayFound.length + " entities"); -} - -deleteAllInRadius(100000); \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/findScripts.js b/unpublishedScripts/DomainContent/CellScience/Scripts/findScripts.js deleted file mode 100644 index bdf6278f19..0000000000 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/findScripts.js +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2016 High Fidelity, Inc. -// -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -var scriptName = "Controller"; - -function findScriptsInRadius(r) { - var n = 0; - var arrayFound = Entities.findEntities(MyAvatar.position, r); - for (var i = 0; i < arrayFound.length; i++) { - if (Entities.getEntityProperties(arrayFound[i]).script.indexOf(scriptName) != -1) { - n++; - } - } - print("found " + n + " copies of " + scriptName); -} - -findScriptsInRadius(100000); \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/navigationButton.js b/unpublishedScripts/DomainContent/CellScience/Scripts/navigationButton.js index ee8e3d0753..4136f1f81b 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/navigationButton.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/navigationButton.js @@ -23,32 +23,32 @@ } this.initialize = function(entityId) { - // print(' should initialize' + entityId) + print('JBP nav button should initialize' + entityId) var properties = Entities.getEntityProperties(entityId); if (properties.userData.length === 0 || properties.hasOwnProperty('userData') === false) { self.initTimeout = Script.setTimeout(function() { - // print(' no user data yet, try again in one second') + print('JBP no user data yet, try again in one second') self.initialize(entityId); }, 1000) } else { - // print(' userdata before parse attempt' + properties.userData) + print('JBP userdata before parse attempt' + properties.userData) self.userData = null; try { self.userData = JSON.parse(properties.userData); } catch (err) { - // print(' error parsing json'); - // print(' properties are:' + properties.userData); + print('JBP error parsing json'); + print('JBP properties are:' + properties.userData); return; } - + var mySavedSettings = Settings.getValue(entityId); if (mySavedSettings.buttons !== undefined) { - //print(' preload buttons' + mySavedSettings.buttons) + print('JBP preload buttons' + mySavedSettings.buttons) mySavedSettings.buttons.forEach(function(b) { - //print(' deleting button' + b) + print('JBP deleting button' + b) Overlays.deleteOverlay(b); }) Settings.setValue(entityId, '') @@ -56,7 +56,7 @@ self.buttonImageURL = baseURL + "GUI/GUI_" + self.userData.name + ".png?" + version; - //print('BUTTON IMAGE URL:' + self.buttonImageURL) + print('JBP BUTTON IMAGE URL:' + self.buttonImageURL) if (self.button === undefined) { // print('NAV NO BUTTON ADDING ONE!!') self.button = true; diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/playBackgroundAudio.js b/unpublishedScripts/DomainContent/CellScience/Scripts/playBackgroundAudio.js deleted file mode 100644 index 87302dd743..0000000000 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/playBackgroundAudio.js +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2016 High Fidelity, Inc. -// -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -(function() { - var self = this; - var baseURL = "https://hifi-content.s3.amazonaws.com/DomainContent/CellScience/"; - var version = 11; - this.preload = function(entityId) { - self.soundPlaying = false; - self.entityId = entityId; - this.initTimeout = null; - this.initialize(entityId); - } - - this.initialize = function(entityID) { - //print(' should initialize' + entityID) - var properties = Entities.getEntityProperties(entityID); - if (properties.userData.length === 0 || properties.hasOwnProperty('userData') === false) { - self.initTimeout = Script.setTimeout(function() { - //print(' no user data yet, try again in one second') - self.initialize(entityID); - }, 1000) - - } else { - //print(' userdata before parse attempt' + properties.userData) - self.userData = null; - try { - self.userData = JSON.parse(properties.userData); - } catch (err) { - //print(' error parsing json'); - //print(' properties are:' + properties.userData); - return; - } - - - //print(' USERDATA NAME ' + self.userData.name) - self.soundURL = baseURL + "Audio/" + self.userData.name + ".wav?" + version; - //print(" creating WAV name location is " + baseURL + "Audio/" + self.userData.name + ".wav"); - //print(' self soundURL' + self.soundURL) - - self.soundOptions = { - stereo: true, - loop: true, - localOnly: true, - volume: 0.035 - }; - - self.sound = SoundCache.getSound(self.soundURL); - } - } - - this.enterEntity = function(entityID) { - //print("entering audio zone"); - if (self.sound.downloaded) { - //print("playing background audio named " + self.userData.name + "which has been downloaded"); - this.soundPlaying = Audio.playSound(self.sound, self.soundOptions); - - } else { - //print("sound is not downloaded"); - } - } - - this.leaveEntity = function(entityID) { - //print("leaving audio area " + self.userData.name); - if (self.soundPlaying !== false) { - //print("not null"); - //print("Stopped sound " + self.userData.name); - self.soundPlaying.stop(); - } else { - //print("Sound not playing"); - } - } - - this.unload = function() { - if (this.initTimeout !== null) { - Script.clearTimeout(this.initTimeout); - } - } - - - -}); \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/zoom.js b/unpublishedScripts/DomainContent/CellScience/Scripts/zoom.js index f29d5023c9..da41ec64ba 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/zoom.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/zoom.js @@ -45,12 +45,11 @@ } this.enterEntity = function(entityID) { - print('JBP ENTERED A BOUNDARY ENTITY, SHOULD ZOOM', entityID) - + //print('ENTERED A BOUNDARY ENTITY, SHOULD ZOOM', entityID) var data = JSON.parse(Entities.getEntityProperties(this.entityId).userData); - print('JBP DATA IS::' + data) + //print('DATA IS::' + data) if (data != null) { - print("JBP Teleporting to (" + data.location.x + ", " + data.location.y + ", " + data.location.z + ")"); + print("Teleporting to (" + data.location.x + ", " + data.location.y + ", " + data.location.z + ")"); MyAvatar.position = data.location; @@ -65,7 +64,7 @@ } this.lookAtTarget = function(entryPoint,target) { - print('JBP SHOULD LOOK AT TARGET') + //print('SHOULD LOOK AT TARGET') var direction = Vec3.normalize(Vec3.subtract(entryPoint, target)); var pitch = Quat.angleAxis(Math.asin(-direction.y) * 180.0 / Math.PI, { x: 1, diff --git a/unpublishedScripts/DomainContent/CellScience/importCellScience.js b/unpublishedScripts/DomainContent/CellScience/importCellScience.js index acc68da932..3885a29b89 100644 --- a/unpublishedScripts/DomainContent/CellScience/importCellScience.js +++ b/unpublishedScripts/DomainContent/CellScience/importCellScience.js @@ -5,7 +5,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -var version = 1021; +var version = 1029; var cellLayout; var baseLocation = "https://hifi-content.s3.amazonaws.com/DomainContent/CellScience/"; @@ -163,7 +163,7 @@ var scenes = [{ z: 0 }, radius: 300, - number: 15, + number: 7, userData: JSON.stringify({ grabbableKey: { grabbable: false @@ -188,7 +188,7 @@ var scenes = [{ z: 0 }, radius: 1000, - number: 45, + number: 22, userData: JSON.stringify({ grabbableKey: { grabbable: false @@ -210,7 +210,7 @@ var scenes = [{ z: 976 }, radius: 140, - number: 20, + number: 10, userData: JSON.stringify({ grabbableKey: { grabbable: false @@ -232,7 +232,7 @@ var scenes = [{ z: 976 }, radius: 115, - number: 15, + number: 7, userData: JSON.stringify({ grabbableKey: { grabbable: false @@ -254,7 +254,7 @@ var scenes = [{ z: 0 }, radius: 600, - number: 30, + number: 15, userData: JSON.stringify({ grabbableKey: { grabbable: false @@ -276,7 +276,7 @@ var scenes = [{ z: 0 }, radius: 1600, - number: 45, + number: 22, userData: JSON.stringify({ grabbableKey: { grabbable: false @@ -298,7 +298,7 @@ var scenes = [{ z: 0 }, radius: 1400, - number: 45, + number: 22, userData: JSON.stringify({ grabbableKey: { grabbable: false @@ -320,7 +320,7 @@ var scenes = [{ z: 0 }, radius: 1800, - number: 45, + number: 22, userData: JSON.stringify({ grabbableKey: { grabbable: false @@ -365,7 +365,7 @@ var scenes = [{ z: 771 }, radius: 80, - number: 15, + number: 7, userData: JSON.stringify({ grabbableKey: { grabbable: false @@ -390,13 +390,15 @@ var scenes = [{ z: 771 }, radius: 60, - number: 15, + number: 7, userData: JSON.stringify({ grabbableKey: { grabbable: false - } + }, + target: locations.hexokinase[1], + location: locations.hexokinase[0], }), - script: "", + script: "zoom.js?" + version, visible: true }, { model: "glucose_isomerase", @@ -412,13 +414,15 @@ var scenes = [{ z: 771 }, radius: 70, - number: 15, + number: 7, userData: JSON.stringify({ grabbableKey: { grabbable: false - } + }, + target: locations.hexokinase[1], + location: locations.hexokinase[0], }), - script: "", + script: "zoom.js?" + version, visible: true } // { @@ -598,8 +602,6 @@ function ImportScene(scene) { CreateInstances(scene); CreateBoundary(scene); - // CreateBackgroundAudio(scene.name, scene.location, scene.dimensions); - // print("done " + scene.name); } @@ -647,7 +649,7 @@ function CreateNavigationButton(scene, number) { Entities.addEntity({ - type: "Sphere", + type: "Box", name: scene.name + " navigation button", color: { red: 200, @@ -655,9 +657,9 @@ function CreateNavigationButton(scene, number) { blue: 0 }, dimensions: { - x: 10, - y: 10, - z: 10 + x: 16000, + y: 16000, + z: 16000 }, visible: false, userData: JSON.stringify({ @@ -670,10 +672,13 @@ function CreateNavigationButton(scene, number) { grabbable: false } }), - // position:{x:3000,y:13500,z:3000}, + position: { + x: 0, + y: 0, + z: 0 + }, script: baseLocation + "Scripts/navigationButton.js?" + version, collisionless: true, - }); } @@ -850,27 +855,6 @@ function CreateIdentification(name, position, rotation, dimensions, showDistance } -function CreateBackgroundAudio(name, position) { - Entities.addEntity({ - type: "Sphere", - name: "Location " + name + " background audio", - dimensions: { - x: 4000, - y: 4000, - z: 4000 - }, - position: position, - visible: false, - userData: JSON.stringify({ - name: name, - baseURL: baseLocation - }), - script: baseLocation + "Scripts/playBackgroundAudio.js?" + version, - collisionless: true, - - }); - -} function getPointOnSphereOfRadius(radius, number, totalNumber) { From 22c53fc395ef708300a6094587316a0b0bfd51d6 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 10 Feb 2016 10:05:26 -0800 Subject: [PATCH 14/15] full voiceover vol --- .../DomainContent/CellScience/Scripts/showButtonToPlaySound.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js b/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js index 429fd0b902..6651e435b4 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/showButtonToPlaySound.js @@ -47,7 +47,7 @@ stereo: true, loop: false, localOnly: true, - volume: 0.75 + volume: 1 }; self.sound = SoundCache.getSound(this.soundURL); From 9a34b68bffc678c08fc327bcc2f47fd771f62025 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 10 Feb 2016 12:50:11 -0800 Subject: [PATCH 15/15] add ownership hack to own and handoff movement --- .../CellScience/Scripts/moveRandomly.js | 176 ++++++++++++++---- .../CellScience/importCellScience.js | 2 +- 2 files changed, 139 insertions(+), 39 deletions(-) diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/moveRandomly.js b/unpublishedScripts/DomainContent/CellScience/Scripts/moveRandomly.js index 7c880a44b6..a975f74733 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/moveRandomly.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/moveRandomly.js @@ -9,7 +9,8 @@ var self = this; this.preload = function(entityId) { - + //print('preload move randomly') + this.isConnected = false; this.entityId = entityId; this.updateInterval = 100; this.posFrame = 0; @@ -21,62 +22,161 @@ this.minAngularVelocity = 0.01; this.maxAngularVelocity = 0.03; + this.initialize(entityId); + this.initTimeout = null; + + + var userData = { + ownershipKey: { + owner: MyAvatar.sessionUUID + }, + grabbableKey: { + grabbable: false + } + }; + + Entities.editEntity(entityId, { + userData: JSON.stringify(userData) + }) + } + + this.initialize = function(entityId) { + //print('move randomly should initialize' + entityId) + var properties = Entities.getEntityProperties(entityId); + if (properties.userData.length === 0 || properties.hasOwnProperty('userData') === false) { + self.initTimeout = Script.setTimeout(function() { + //print('no user data yet, try again in one second') + self.initialize(entityId); + }, 1000) + + } else { + //print('userdata before parse attempt' + properties.userData) + self.userData = null; + try { + self.userData = JSON.parse(properties.userData); + } catch (err) { + //print('error parsing json'); + //print('properties are:' + properties.userData); + return; + } + Script.update.connect(self.update); + this.isConnected = true; + } } this.update = function(deltaTime) { + // print('jbp in update') + var data = Entities.getEntityProperties(self.entityId, 'userData').userData; + var userData; + try { + userData = JSON.parse(data) + } catch (e) { + //print('error parsing json' + data) + return; + }; - self.posFrame++; - self.rotFrame++; - - if (self.posFrame > self.posInterval) { - - self.posInterval = 100 * Math.random() + 300; - self.posFrame = 0; - - var magnitudeV = self.maxVelocity; - var directionV = { - x: Math.random() - 0.5, - y: Math.random() - 0.5, - z: Math.random() - 0.5 - }; - - //print("POS magnitude is " + magnitudeV + " and direction is " + directionV.x); - Entities.editEntity(self.entityId, { - velocity: Vec3.multiply(magnitudeV, Vec3.normalize(directionV)) - - }); - + // print('userdata is' + data) + //if the entity doesnt have an owner set yet + if (userData.hasOwnProperty('ownershipKey') !== true) { + //print('no movement owner yet') + return; } - if (self.rotFrame > self.rotInterval) { + //print('owner is:::' + userData.ownershipKey.owner) + //get all the avatars to see if the owner is around + var avatars = AvatarList.getAvatarIdentifiers(); + var ownerIsAround = false; - self.rotInterval = 100 * Math.random() + 250; - self.rotFrame = 0; + //if the current owner is not me... + if (userData.ownershipKey.owner !== MyAvatar.sessionUUID) { - var magnitudeAV = self.maxAngularVelocity; + //look to see if the current owner is around anymore + for (var i = 0; i < avatars.length; i++) { + if (avatars[i] === userData.ownershipKey.owner) { + ownerIsAround = true + //the owner is around + return; + }; + } - var directionAV = { - x: Math.random() - 0.5, - y: Math.random() - 0.5, - z: Math.random() - 0.5 - }; - //print("ROT magnitude is " + magnitudeAV + " and direction is " + directionAV.x); - Entities.editEntity(self.entityId, { - angularVelocity: Vec3.multiply(magnitudeAV, Vec3.normalize(directionAV)) + //if the owner is not around, then take ownership + if (ownerIsAround === false) { + //print('taking ownership') - }); + var userData = { + ownershipKey: { + owner: MyAvatar.sessionUUID + }, + grabbableKey: { + grabbable: false + } + }; + Entities.editEntity(self.entityId, { + userData: JSON.stringify(data) + }) + } + } + //but if the current owner IS me, then move it + else { + //print('jbp im the owner so move it') + self.posFrame++; + self.rotFrame++; + + if (self.posFrame > self.posInterval) { + + self.posInterval = 100 * Math.random() + 300; + self.posFrame = 0; + + var magnitudeV = self.maxVelocity; + var directionV = { + x: Math.random() - 0.5, + y: Math.random() - 0.5, + z: Math.random() - 0.5 + }; + + //print("POS magnitude is " + magnitudeV + " and direction is " + directionV.x); + Entities.editEntity(self.entityId, { + velocity: Vec3.multiply(magnitudeV, Vec3.normalize(directionV)) + + }); + + } + + if (self.rotFrame > self.rotInterval) { + + self.rotInterval = 100 * Math.random() + 250; + self.rotFrame = 0; + + var magnitudeAV = self.maxAngularVelocity; + + var directionAV = { + x: Math.random() - 0.5, + y: Math.random() - 0.5, + z: Math.random() - 0.5 + }; + //print("ROT magnitude is " + magnitudeAV + " and direction is " + directionAV.x); + Entities.editEntity(self.entityId, { + angularVelocity: Vec3.multiply(magnitudeAV, Vec3.normalize(directionAV)) + + }); + + } } - } this.unload = function() { + if (this.initTimeout !== null) { + Script.clearTimeout(this.initTimeout); + } - Script.update.disconnect(this.update); + if (this.isConnected === true) { + Script.update.disconnect(this.update); + } } - Script.update.connect(this.update); + }) \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/CellScience/importCellScience.js b/unpublishedScripts/DomainContent/CellScience/importCellScience.js index 3885a29b89..ca0eb21f21 100644 --- a/unpublishedScripts/DomainContent/CellScience/importCellScience.js +++ b/unpublishedScripts/DomainContent/CellScience/importCellScience.js @@ -5,7 +5,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -var version = 1029; +var version = 1035; var cellLayout; var baseLocation = "https://hifi-content.s3.amazonaws.com/DomainContent/CellScience/";