mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-04-09 09:02:29 +02:00
cellscience
This commit is contained in:
parent
4ed38c4104
commit
0e036d3e2c
16 changed files with 18230 additions and 0 deletions
|
@ -0,0 +1,58 @@
|
|||
var spriteURL = "https://hifi-content.s3.amazonaws.com/DomainContent/CellScience/Sprites/nucleosomes_sprite.fbx";
|
||||
var spriteDimensions = {
|
||||
x: 10,
|
||||
y: 10,
|
||||
z: 10
|
||||
};
|
||||
var sprite;
|
||||
var isMouseDown = false;
|
||||
var RAD_TO_DEG = 180.0 / Math.PI;
|
||||
var Y_AXIS = { x: 0, y: 1, z: 0 };
|
||||
var X_AXIS = { x: 1, y: 0, z: 0 };
|
||||
|
||||
function MakeSprite () {
|
||||
sprite = Entities.addEntity({
|
||||
type: "Model",
|
||||
name: "sprite",
|
||||
modelURL: spriteURL,
|
||||
dimensions: spriteDimensions,
|
||||
position: Vec3.sum(MyAvatar.position, Quat.getFront(MyAvatar.orientation)),
|
||||
rotation: Quat.inverse(Quat.getFront(MyAvatar.orientation))
|
||||
});
|
||||
}
|
||||
|
||||
function UpdateOrientation (event) {
|
||||
if (isMouseDown && event.isRightButton) {
|
||||
|
||||
var direction,
|
||||
yaw,
|
||||
pitch,
|
||||
rot;
|
||||
|
||||
direction = Vec3.normalize(Vec3.subtract(MyAvatar.position, Entities.getEntityProperties(sprite).position));
|
||||
yaw = Quat.angleAxis(Math.atan2(direction.x, direction.z) * RAD_TO_DEG, Y_AXIS);
|
||||
pitch = Quat.angleAxis(Math.asin(-direction.y) * RAD_TO_DEG, X_AXIS);
|
||||
rot = Quat.multiply(yaw, pitch);
|
||||
|
||||
var avatar = Quat.safeEulerAngles(MyAvatar.orientation);
|
||||
var printRot = Quat.safeEulerAngles(rot);
|
||||
print("avatar = (" + avatar.x + ", " + avatar.y + ", " + avatar.z + ")");
|
||||
print("sprite = (" + printRot.x + ", " + printRot.y + ", " + printRot.z + ")");
|
||||
Entities.editEntity(sprite, {
|
||||
rotation: rot
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function OnMouseDown(event) {
|
||||
isMouseDown = true;
|
||||
}
|
||||
|
||||
function OnMouseUp(event) {
|
||||
isMouseDown = false;
|
||||
}
|
||||
|
||||
MakeSprite();
|
||||
Controller.mouseMoveEvent.connect(UpdateOrientation);
|
||||
Controller.mousePressEvent.connect(OnMouseDown);
|
||||
Controller.mouseReleaseEvent.connect(OnMouseUp);
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,152 @@
|
|||
(function() {
|
||||
|
||||
var TARGET_OFFSET = {
|
||||
x: -1,
|
||||
y: 1,
|
||||
z: -1
|
||||
}
|
||||
|
||||
var baseURL = "https://hifi-content.s3.amazonaws.com/DomainContent/CellScience/";
|
||||
|
||||
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.addExitButton = function() {
|
||||
this.windowDimensions = Controller.getViewportDimensions();
|
||||
this.buttonWidth = 75;
|
||||
this.buttonHeight = 75;
|
||||
this.buttonPadding = 10;
|
||||
|
||||
this.buttonPositionX = (self.windowDimensions.x - self.buttonPadding) / 2 - self.buttonWidth / 2;
|
||||
this.buttonPositionY = (self.windowDimensions.y - self.buttonHeight) - (self.buttonHeight + self.buttonPadding);
|
||||
this.exitButton = Overlays.addOverlay("image", {
|
||||
x: self.buttonPositionX,
|
||||
y: self.buttonPositionY,
|
||||
width: self.buttonWidth,
|
||||
height: self.buttonHeight,
|
||||
imageURL: self.buttonImageURL,
|
||||
visible: false,
|
||||
alpha: 1.0
|
||||
});
|
||||
}
|
||||
|
||||
this.clickReleaseOnEntity = function(entityId, mouseEvent) {
|
||||
// print('CLICKED ON MOTOR PROTEIN')
|
||||
if (mouseEvent.isLeftButton && !self.isRiding) {
|
||||
print("GET ON");
|
||||
self.isRiding = true;
|
||||
if (!self.entityId) {
|
||||
self.entityId = entityId;
|
||||
}
|
||||
self.entityLocation = Entities.getEntityProperties(this.entityId, "position").position;
|
||||
self.targetLocation = Vec3.sum(self.entityLocation, TARGET_OFFSET);
|
||||
Overlays.editOverlay(self.exitButton, {
|
||||
visible: true
|
||||
});
|
||||
Controller.mousePressEvent.connect(this.onMousePress);
|
||||
Script.update.connect(this.update);
|
||||
}
|
||||
}
|
||||
|
||||
this.lastAvatarPosition = null;
|
||||
this.lastEntityPosition = null;
|
||||
this.update = function(deltaTime) {
|
||||
if (self.isRiding !== true) {
|
||||
return
|
||||
}
|
||||
|
||||
Entities.editEntity(self.entityId, {
|
||||
velocity: {
|
||||
x: 1,
|
||||
y: 0,
|
||||
z: 0
|
||||
}
|
||||
})
|
||||
self.lastEntityLocation = self.entityLocation;
|
||||
self.lastTargetLocation = self.targetLocation
|
||||
self.entityLocation = Entities.getEntityProperties(self.entityId, "position").position;
|
||||
self.targetLocation = Vec3.sum(self.entityLocation, TARGET_OFFSET);
|
||||
// print('JBP self.lastTargetLocation' + JSON.stringify(self.lastTargetLocation))
|
||||
// print('JBP self.targetLocation' + JSON.stringify(self.targetLocation))
|
||||
var diff = Vec3.distance(self.targetLocation, self.lastTargetLocation);
|
||||
// print('JBP diff is::' + diff)
|
||||
self.addThrustToAvatar(deltaTime);
|
||||
}
|
||||
|
||||
|
||||
this.addThrustToAvatar = function(deltaTime) {
|
||||
var targetCurrentLocationToLastLocation = Vec3.subtract(self.targetLocation, self.lastTargetLocation);
|
||||
|
||||
// print('JBP targetCurrentLocationToLastLocation' + JSON.stringify(targetCurrentLocationToLastLocation));
|
||||
// print('JBP deltaTime' + deltaTime)
|
||||
// print('JBP velocity' + JSON.stringify(self.velocity))
|
||||
var thrustToAdd = Vec3.multiply(100, targetCurrentLocationToLastLocation);
|
||||
thrustToAdd = Vec3.multiply(thrustToAdd, 1 / deltaTime);
|
||||
// print('JBP adding thrust!' + JSON.stringify(thrustToAdd))
|
||||
|
||||
MyAvatar.addThrust(thrustToAdd);
|
||||
|
||||
}
|
||||
|
||||
this.onMousePress = function(event) {
|
||||
var clickedOverlay = Overlays.getOverlayAtPoint({
|
||||
x: event.x,
|
||||
y: event.y
|
||||
});
|
||||
if (event.isLeftButton && clickedOverlay === self.exitButton) {
|
||||
print("GET OFF");
|
||||
Script.update.disconnect(this.update);
|
||||
self.reset();
|
||||
}
|
||||
}
|
||||
|
||||
this.reset = function() {
|
||||
// print('reset')
|
||||
if (self.isRiding) {
|
||||
Overlays.editOverlay(this.exitButton, {
|
||||
visible: false
|
||||
});
|
||||
}
|
||||
self.isRiding = false;
|
||||
}
|
||||
|
||||
this.unload = function() {
|
||||
// print("unload");
|
||||
self.reset();
|
||||
|
||||
Controller.mousePressEvent.disconnect(this.onMousePress);
|
||||
}
|
||||
|
||||
function handleMessages(channel, message, sender) {
|
||||
// print('HANDLING A MESSAGE IN PROTEIN')
|
||||
if (sender === MyAvatar.sessionUUID) {
|
||||
if (channel === "Hifi-Motor-Protein-Channel") {
|
||||
if (message === 'delete') {
|
||||
// print('SHOULD DELETE PROTEIN')
|
||||
Entities.deleteEntity(self.entityId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Messages.messageReceived.connect(handleMessages);
|
||||
|
||||
|
||||
|
||||
});
|
|
@ -0,0 +1,11 @@
|
|||
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);
|
|
@ -0,0 +1,15 @@
|
|||
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);
|
Binary file not shown.
|
@ -0,0 +1,68 @@
|
|||
(function(){
|
||||
|
||||
var self = this;
|
||||
|
||||
this.preload = function(entityId) {
|
||||
|
||||
this.entityId = entityId;
|
||||
this.updateInterval = 100;
|
||||
this.posFrame = 0;
|
||||
this.rotFrame = 0;
|
||||
this.posInterval=100;
|
||||
this.rotInterval=100;
|
||||
this.minVelocity = 1;
|
||||
this.maxVelocity = 5;
|
||||
this.minAngularVelocity = 0.01;
|
||||
this.maxAngularVelocity = 0.03;
|
||||
|
||||
}
|
||||
|
||||
this.update = function(deltaTime) {
|
||||
|
||||
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() {
|
||||
|
||||
Script.update.disconnect(this.update);
|
||||
|
||||
}
|
||||
|
||||
Script.update.connect(this.update);
|
||||
|
||||
})
|
|
@ -0,0 +1,49 @@
|
|||
(function(){
|
||||
|
||||
var self = this;
|
||||
|
||||
this.preload = function(entityId) {
|
||||
|
||||
this.entityId = entityId;
|
||||
this.updateInterval = 30;
|
||||
this.frame = 0;
|
||||
|
||||
this.minVelocity = 0.15;
|
||||
this.maxVelocity = 0.35;
|
||||
this.minAngularVelocity = 0.3;
|
||||
this.maxAngularVelocity = 0.7;
|
||||
|
||||
}
|
||||
|
||||
this.update = function(deltaTime) {
|
||||
|
||||
self.frame++;
|
||||
|
||||
if (self.frame > self.updateInterval) {
|
||||
|
||||
self.updateInterval = 20 * Math.random() + 0;
|
||||
self.frame = 0;
|
||||
|
||||
var magnitudeV = (self.maxVelocity - self.minVelocity) * Math.random() + self.minVelocity;
|
||||
var magnitudeAV = (self.maxAngularVelocity - self.minAngularVelocity) * Math.random() + self.minAngularVelocity;
|
||||
var directionV = {x: Math.random() - 0.5, y: Math.random() - 0.5, z: Math.random() - 0.5};
|
||||
var directionAV = {x: Math.random() - 0.5, y: Math.random() - 0.5, z: Math.random() - 0.5};
|
||||
|
||||
Entities.editEntity(self.entityId, {
|
||||
velocity: Vec3.multiply(magnitudeV, Vec3.normalize(directionV)),
|
||||
angularVelocity: Vec3.multiply(magnitudeAV, Vec3.normalize(directionAV))
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.unload = function() {
|
||||
|
||||
Script.update.disconnect(this.update);
|
||||
|
||||
}
|
||||
|
||||
Script.update.connect(this.update);
|
||||
|
||||
})
|
|
@ -0,0 +1,144 @@
|
|||
(function() {
|
||||
|
||||
var version = 1;
|
||||
var added = false;
|
||||
this.frame = 0;
|
||||
var utilsScript = Script.resolvePath('utils.js');
|
||||
Script.include(utilsScript);
|
||||
|
||||
var self = this;
|
||||
var baseURL = "https://hifi-content.s3.amazonaws.com/DomainContent/CellScience/";
|
||||
|
||||
this.preload = function(entityId) {
|
||||
this.entityId = entityId;
|
||||
var mySavedSettings = Settings.getValue(entityId);
|
||||
|
||||
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();
|
||||
|
||||
} else {
|
||||
// print('NAV SELF ALREADY HAS A BUTTON!!')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.addButton = function() {
|
||||
|
||||
|
||||
self.getUserData();
|
||||
this.windowDimensions = Controller.getViewportDimensions();
|
||||
this.buttonWidth = 150;
|
||||
this.buttonHeight = 50;
|
||||
this.buttonPadding = 10;
|
||||
|
||||
this.buttonPositionX = (self.userData.offset + 1) * (this.buttonWidth + this.buttonPadding) + (self.windowDimensions.x / 2) - (this.buttonWidth * 3 + this.buttonPadding * 2.5);
|
||||
this.buttonPositionY = (self.windowDimensions.y - self.buttonHeight) - 50;
|
||||
this.button = Overlays.addOverlay("image", {
|
||||
x: self.buttonPositionX,
|
||||
y: self.buttonPositionY,
|
||||
width: self.buttonWidth,
|
||||
height: self.buttonHeight,
|
||||
imageURL: self.buttonImageURL,
|
||||
visible: true,
|
||||
alpha: 1.0
|
||||
});
|
||||
|
||||
var mySavedSettings = Settings.getValue(this.entityId);
|
||||
var buttons = [];
|
||||
if (mySavedSettings.buttons !== undefined) {
|
||||
buttons = mySavedSettings.buttons;
|
||||
buttons.push(this.button);
|
||||
} else {
|
||||
buttons.push(this.button);
|
||||
}
|
||||
// print('NAV ENTITY ID IN ADDBUTTON'+ this.entityId)
|
||||
// print('NAV BUTTONS IN ADDBUTTON:: '+ buttons)
|
||||
Settings.setValue(this.entityId, {
|
||||
buttons: buttons
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
this.update = function(deltaTime) {
|
||||
if (self.frame < 10) {
|
||||
self.frame++;
|
||||
} else {
|
||||
// this.lookAt(this.userData.target);
|
||||
}
|
||||
}
|
||||
|
||||
this.onClick = function(event) {
|
||||
var clickedOverlay = Overlays.getOverlayAtPoint({
|
||||
x: event.x,
|
||||
y: event.y
|
||||
});
|
||||
|
||||
|
||||
if (clickedOverlay == self.button) {
|
||||
// print("NAV Clicked navigation button: " + self.userData.name + ", and looking at " + self.userData.target.x + ", " + self.userData.target.y + ", " + self.userData.target.z);
|
||||
|
||||
self.lookAtTarget();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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,
|
||||
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(self.userData.entryPoint, true, yaw);
|
||||
|
||||
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() {
|
||||
// print('NAV UNLOAD - BUTTON, ENTITY -- ' + this.button + " // " + this.entityId)
|
||||
|
||||
Overlays.deleteOverlay(self.button);
|
||||
|
||||
Controller.mousePressEvent.disconnect(this.onClick);
|
||||
// Script.update.disconnect(this.update);
|
||||
}
|
||||
|
||||
Controller.mousePressEvent.connect(this.onClick);
|
||||
// Script.update.connect(this.update);
|
||||
|
||||
});
|
|
@ -0,0 +1,59 @@
|
|||
(function() {
|
||||
var self = this;
|
||||
var baseURL = "https://hifi-content.s3.amazonaws.com/DomainContent/CellScience/";
|
||||
var version = 8;
|
||||
this.preload = function(entityId) {
|
||||
self.soundPlaying = false;
|
||||
self.entityId = entityId;
|
||||
self.getUserData();
|
||||
self.soundURL = baseURL + "Audio/" + self.userData.name + ".wav?" + version;
|
||||
print("JBP creating WAV name location is " + baseURL + "Audio/" + self.userData.name + ".wav");
|
||||
|
||||
self.soundOptions = {
|
||||
stereo: true,
|
||||
loop: true,
|
||||
localOnly: true,
|
||||
volume: 0.5
|
||||
};
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
|
@ -0,0 +1,95 @@
|
|||
(function() {
|
||||
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.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);
|
||||
}
|
||||
|
||||
Controller.mousePressEvent.connect(this.onClick);
|
||||
Script.update.connect(this.update);
|
||||
|
||||
});
|
|
@ -0,0 +1,131 @@
|
|||
(function() {
|
||||
|
||||
var self = this;
|
||||
var baseURL = "https://hifi-content.s3.amazonaws.com/DomainContent/CellScience/";
|
||||
|
||||
var version = 1;
|
||||
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.5,
|
||||
position: this.position
|
||||
};
|
||||
this.sound = SoundCache.getSound(this.soundURL);
|
||||
this.buttonImageURL = baseURL + "GUI/GUI_audio.png?" + version;
|
||||
self.addButton();
|
||||
}
|
||||
|
||||
this.addButton = function() {
|
||||
this.windowDimensions = Controller.getViewportDimensions();
|
||||
this.buttonWidth = 100;
|
||||
this.buttonHeight = 100;
|
||||
this.buttonPadding = 40;
|
||||
|
||||
this.buttonPositionX = (self.windowDimensions.x - self.buttonPadding) / 2 - self.buttonWidth / 2;
|
||||
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.labelWidth = 256;
|
||||
this.labelHeight = 64;
|
||||
this.labelPadding = 0;
|
||||
|
||||
this.labelPositionX = (self.windowDimensions.x - self.labelPadding) / 2 - self.labelWidth / 2;
|
||||
this.labelPositionY = self.labelHeight + self.labelPadding;
|
||||
// print("adding label " + self.labelURL + " at position " + self.labelPositionX + ", " + self.labelPositionY);
|
||||
this.label = Overlays.addOverlay("image", {
|
||||
x: self.labelPositionX,
|
||||
y: self.labelPositionY,
|
||||
width: self.labelWidth,
|
||||
height: self.labelHeight,
|
||||
imageURL: self.labelURL,
|
||||
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.enterEntity = function(entityID) {
|
||||
|
||||
// self.getUserData();
|
||||
print("entering entity and showing" + self.labelURL);
|
||||
//self.buttonShowing = true;
|
||||
Overlays.editOverlay(self.button, {
|
||||
visible: true
|
||||
});
|
||||
Overlays.editOverlay(self.label, {
|
||||
visible: true
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
this.leaveEntity = function(entityID) {
|
||||
// self.getUserData();
|
||||
// print("leaving entity " + self.userData.name);
|
||||
//self.buttonShowing = false;
|
||||
print(Overlays);
|
||||
Overlays.editOverlay(self.button, {
|
||||
visible: false
|
||||
});
|
||||
Overlays.editOverlay(self.label, {
|
||||
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");
|
||||
|
||||
Overlays.editOverlay(self.button, {
|
||||
visible: false
|
||||
});
|
||||
this.soundPlaying = Audio.playSound(self.sound, self.soundOptions);
|
||||
} else {
|
||||
print("not downloaded");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.unload = function() {
|
||||
Overlays.deleteOverlay(self.button);
|
||||
if(this.soundPlaying!==null) {
|
||||
this.soundPlaying.stop();
|
||||
}
|
||||
|
||||
Controller.mousePressEvent.disconnect(this.onClick);
|
||||
}
|
||||
|
||||
Controller.mousePressEvent.connect(this.onClick);
|
||||
|
||||
});
|
|
@ -0,0 +1,40 @@
|
|||
setEntityUserData = function(id, data) {
|
||||
var json = JSON.stringify(data)
|
||||
Entities.editEntity(id, { userData: json });
|
||||
}
|
||||
|
||||
// FIXME do non-destructive modification of the existing user data
|
||||
getEntityUserData = function(id) {
|
||||
var results = null;
|
||||
var properties = Entities.getEntityProperties(id, "userData");
|
||||
if (properties.userData) {
|
||||
try {
|
||||
results = JSON.parse(properties.userData);
|
||||
} catch(err) {
|
||||
logDebug(err);
|
||||
logDebug(properties.userData);
|
||||
}
|
||||
}
|
||||
return results ? results : {};
|
||||
}
|
||||
|
||||
|
||||
// Non-destructively modify the user data of an entity.
|
||||
setEntityCustomData = function(customKey, id, data) {
|
||||
var userData = getEntityUserData(id);
|
||||
if (data == null) {
|
||||
delete userData[customKey];
|
||||
} else {
|
||||
userData[customKey] = data;
|
||||
}
|
||||
setEntityUserData(id, userData);
|
||||
}
|
||||
|
||||
getEntityCustomData = function(customKey, id, defaultValue) {
|
||||
var userData = getEntityUserData(id);
|
||||
if (undefined != userData[customKey]) {
|
||||
return userData[customKey];
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
80
unpublishedScripts/DomainContent/CellScience/Scripts/zoom.js
Normal file
80
unpublishedScripts/DomainContent/CellScience/Scripts/zoom.js
Normal file
|
@ -0,0 +1,80 @@
|
|||
(function(){
|
||||
var teleport;
|
||||
var portalDestination;
|
||||
var animationURL;
|
||||
var self=this;
|
||||
|
||||
this.entered = true;
|
||||
|
||||
this.preload = function(entityID) {
|
||||
|
||||
this.entityId = entityID;
|
||||
|
||||
var properties = Entities.getEntityProperties(entityID);
|
||||
portalDestination = properties.userData;
|
||||
animationURL = properties.modelURL;
|
||||
this.soundOptions = {
|
||||
stereo: true,
|
||||
loop: false,
|
||||
localOnly: false,
|
||||
position:this.position,
|
||||
volume: 0.5
|
||||
};
|
||||
this.teleportSound = SoundCache.getSound("https://hifi-content.s3.amazonaws.com/DomainContent/CellScience/Audio/whoosh.wav");
|
||||
print('JBP PRELOADING A ZOOM ENTITY')
|
||||
print(" portal destination is " + portalDestination);
|
||||
}
|
||||
|
||||
this.enterEntity = function(entityID) {
|
||||
print('ENTERED A BOUNDARY ENTITY, SHOULD ZOOM', entityID)
|
||||
|
||||
var data = JSON.parse(Entities.getEntityProperties(this.entityId).userData);
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.lookAt = function(targetPosition, avatarPosition) {
|
||||
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});
|
||||
|
||||
// var rotation = Quat.multiply(yaw, pitch);
|
||||
// MyAvatar.orientation = rotation;
|
||||
|
||||
MyAvatar.goToLocation(avatarPosition, true, yaw);
|
||||
MyAvatar.headYaw = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
this.leaveEntity = function(entityID) {
|
||||
Entities.editEntity(entityID, {
|
||||
animationURL: animationURL,
|
||||
animationSettings: '{ "frameIndex": 1, "running": false }'
|
||||
});
|
||||
this.entered = false;
|
||||
//playSound();
|
||||
}
|
||||
|
||||
this.hoverEnterEntity = function(entityID) {
|
||||
Entities.editEntity(entityID, {
|
||||
animationURL: animationURL,
|
||||
animationSettings: '{ "fps": 24, "firstFrame": 1, "lastFrame": 25, "frameIndex": 1, "running": true, "hold": true }'
|
||||
});
|
||||
}
|
||||
})
|
9055
unpublishedScripts/DomainContent/CellScience/importCellScience.js
Normal file
9055
unpublishedScripts/DomainContent/CellScience/importCellScience.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue