Merge pull request #7041 from imgntn/cellscience

Change the way cellscience entities intitialize & audio plays
This commit is contained in:
Seth Alves 2016-02-10 14:22:30 -08:00
commit 5dd044dc29
12 changed files with 1006 additions and 785 deletions

View file

@ -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;
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,19 +78,22 @@
}
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
});
Controller.mousePressEvent.connect(this.onMousePress);
self.mouseIsConnected = true;
Script.update.connect(this.update);
}
}
@ -116,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();
}
@ -136,8 +164,12 @@
// print("unload");
self.reset();
Controller.mousePressEvent.disconnect(this.onMousePress);
if (self.mouseIsConnected === true) {
Controller.mousePressEvent.disconnect(self.onMousePress);
}
if (self.initTimeout !== null) {
Script.clearTimeout(self.initTimeout);
}
}
});

View file

@ -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);

View file

@ -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);

View file

@ -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);
})

View file

@ -1,4 +1,3 @@
// Copyright 2016 High Fidelity, Inc.
//
//
@ -8,7 +7,7 @@
(function() {
var version = 1;
var version = 11;
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('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('JBP no user data yet, try again in one second')
self.initialize(entityId);
}, 1000)
} else {
// print('NAV SELF ALREADY HAS A BUTTON!!')
}
print('JBP userdata before parse attempt' + properties.userData)
self.userData = null;
try {
self.userData = JSON.parse(properties.userData);
} catch (err) {
print('JBP error parsing json');
print('JBP properties are:' + properties.userData);
return;
}
var mySavedSettings = Settings.getValue(entityId);
if (mySavedSettings.buttons !== undefined) {
print('JBP preload buttons' + mySavedSettings.buttons)
mySavedSettings.buttons.forEach(function(b) {
print('JBP deleting button' + b)
Overlays.deleteOverlay(b);
})
Settings.setValue(entityId, '')
}
self.buttonImageURL = baseURL + "GUI/GUI_" + self.userData.name + ".png?" + version;
print('JBP 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);

View file

@ -1,64 +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 = 9;
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");
self.soundOptions = {
stereo: true,
loop: true,
localOnly: true,
volume: 0.035
};
this.sound = SoundCache.getSound(self.soundURL);
}
this.getUserData = function() {
self.properties = Entities.getEntityProperties(self.entityId);
if (self.properties.userData) {
self.userData = JSON.parse(this.properties.userData);
} else {
self.userData = {};
}
}
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");
}
}
});

View file

@ -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.035
};
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: 1
};
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
});
}
});
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);
});

View file

@ -10,24 +10,51 @@
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;
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);
}

View file

@ -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 : {};

View file

@ -14,50 +14,58 @@
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 + ")");
if (self.teleportSound.downloaded) {
//print("play sound");
Audio.playSound(self.teleportSound, self.soundOptions);
} else {
//print("not downloaded");
}
this.lookAt(data.target, data.location);
MyAvatar.position = data.location;
// if (data.hasOwnProperty('entryPoint') && data.hasOwnProperty('target')) {
// this.lookAtTarget(data.entryPoint, data.target);
// }
// else{
// }
}
}
this.lookAt = function(targetPosition, avatarPosition) {
var direction = Vec3.normalize(Vec3.subtract(MyAvatar.position, targetPosition));
this.lookAtTarget = function(entryPoint,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,
y: 0,
@ -69,8 +77,10 @@
z: 0
});
MyAvatar.goToLocation(avatarPosition, true, yaw);
MyAvatar.goToLocation(entryPoint, true, yaw);
MyAvatar.headYaw = 0;
}
@ -81,9 +91,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,

View file

@ -0,0 +1,116 @@
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.1,
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.1,
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.1,
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.1,
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);
});
}
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();

View file

@ -5,7 +5,7 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
var version = 1004;
var version = 1035;
var cellLayout;
var baseLocation = "https://hifi-content.s3.amazonaws.com/DomainContent/CellScience/";
@ -79,398 +79,138 @@ 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({
entryPoint: locations.cellLayout[1],
target: locations.cellLayout[1],
location: locations.cellLayout[1],
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: 7,
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: 22,
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: 10,
userData: JSON.stringify({
grabbableKey: {
grabbable: false
@ -478,48 +218,43 @@ 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: 7,
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: 15,
userData: JSON.stringify({
grabbableKey: {
grabbable: false
@ -527,15 +262,288 @@ var scenes = [
}),
script: "",
visible: true
}],
boundary: {
radius: locations.hexokinase[2],
center: locations.hexokinase[0],
location: locations.mitochondria[1],
target: locations.mitochondria[0]
}, { //outer vesicles
model: "vesicle",
dimensions: {
x: 60,
y: 60,
z: 60
},
randomSize: 10,
offset: {
x: 0,
y: 0,
z: 0
},
radius: 1600,
number: 22,
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: 22,
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: 22,
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: 7,
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: 7,
userData: JSON.stringify({
grabbableKey: {
grabbable: false
},
target: locations.hexokinase[1],
location: locations.hexokinase[0],
}),
script: "zoom.js?" + version,
visible: true
}, {
model: "glucose_isomerase",
dimensions: {
x: 3,
y: 4,
z: 3
},
randomSize: 10,
offset: {
x: 236,
y: 8,
z: 771
},
radius: 70,
number: 7,
userData: JSON.stringify({
grabbableKey: {
grabbable: false
},
target: locations.hexokinase[1],
location: locations.hexokinase[0],
}),
script: "zoom.js?" + version,
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
},
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) {
@ -594,8 +602,6 @@ function ImportScene(scene) {
CreateInstances(scene);
CreateBoundary(scene);
CreateBackgroundAudio(scene.name, scene.location, scene.dimensions);
// print("done " + scene.name);
}
@ -637,12 +643,13 @@ function createLayoutLights() {
})
}
function CreateNavigationButton(scene, number) {
// print('NAV NAVIGATION CREATING NAV!!' +scene.name + " " + number)
Entities.addEntity({
type: "Sphere",
type: "Box",
name: scene.name + " navigation button",
color: {
red: 200,
@ -650,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({
@ -665,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,
});
}
@ -811,7 +821,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);
}
}
@ -845,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) {
@ -890,7 +879,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 +902,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,