Merge branch 'homereset' of github.com:imgntn/hifi into homereset

This commit is contained in:
James B. Pollack 2016-04-05 10:33:58 -07:00
commit 40be28a916
5 changed files with 299 additions and 130 deletions

View file

@ -21,7 +21,6 @@
}; };
function startUpdate() { function startUpdate() {
print("EBL Start CLOCK Update") print("EBL Start CLOCK Update")
//when the baton is claimed; //when the baton is claimed;
@ -101,7 +100,6 @@
} }
}, },
update: function() { update: function() {
if (iOwn === false) { if (iOwn === false) {
@ -122,16 +120,14 @@
var seconds = date.getSeconds(); var seconds = date.getSeconds();
var minutes = date.getMinutes(); var minutes = date.getMinutes();
if (seconds === 0 && minutes === 0) { if (minutes % 15 === 0 && seconds === 0) {
_this.popCuckooOut(); _this.popCuckooOut();
} }
// if (seconds % 30 === 0) {
// _this.popCuckooOut();
// }
}, },
popCuckooOut: function() { popCuckooOut: function() {
_this.checkTime = false;
// We are at the top of the hour! // We are at the top of the hour!
_this.position = Entities.getEntityProperties(_this.entityID, "position").position; _this.position = Entities.getEntityProperties(_this.entityID, "position").position;
print("EBL POP CUCKOO CLOCK!!!!!!!!!!!"); print("EBL POP CUCKOO CLOCK!!!!!!!!!!!");
@ -151,7 +147,6 @@
currentFrame: 0 currentFrame: 0
} }
}); });
_this.checkTime = false;
Script.setTimeout(function() { Script.setTimeout(function() {
_this.checkTime = true; _this.checkTime = true;
}, _this.TIME_CHECK_REFRACTORY_PERIOD); }, _this.TIME_CHECK_REFRACTORY_PERIOD);

View file

@ -1,5 +1,7 @@
(function() { (function() {
//TODO -- At the part of the animation where the user starts to close the lid we need to rewind any frames past the one where it is aligned for going up/down before switching to the down animation
var _this; var _this;
function Lid() { function Lid() {
@ -8,37 +10,47 @@
} }
var MUSIC_URL = Script.resolvePath('http://hifi-content.s3.amazonaws.com/DomainContent/Home/musicBox/music_converted.wav'); var MUSIC_URL = Script.resolvePath('http://hifi-content.s3.amazonaws.com/DomainContent/Home/musicBox/music_converted.wav');
var SHUT_SOUND_URL = Script.resolvePath('http://hifi-content.s3.amazonaws.com/DomainContent/Home/Sounds/book_fall.L.wav'); // var SHUT_SOUND_URL = Script.resolvePath('http://hifi-content.s3.amazonaws.com/DomainContent/Home/Sounds/book_fall.L.wav');
var OPEN_SOUND_URL = Script.resolvePath('http://public.highfidelity.io/sounds/Switches%20and%20sliders/lamp_switch_2.wav'); // var OPEN_SOUND_URL = Script.resolvePath('http://public.highfidelity.io/sounds/Switches%20and%20sliders/lamp_switch_2.wav');
var BASE_ANIMATIONS = 'http://hifi-content.s3.amazonaws.com/DomainContent/Home/musicBox/MusicBoxAnimated2.fbx'; var SHUT_SOUND_URL = Script.resolvePath('atp:/openSound.wav');
var OPEN_SOUND_URL = Script.resolvePath('atp:/closeSound.wav');
Lid.prototype = { Lid.prototype = {
musicInjector: null, musicInjector: null,
preload: function(entityID) { preload: function(entityID) {
print('PRELOAD LID'); this.entityID = entityID;
_this.entityID = entityID; this.music = SoundCache.getSound(MUSIC_URL);
_this.music = SoundCache.getSound(MUSIC_URL); this.shutSound = SoundCache.getSound(SHUT_SOUND_URL);
_this.shutSound = SoundCache.getSound(SHUT_SOUND_URL); this.openSound = SoundCache.getSound(OPEN_SOUND_URL);
_this.openSound = SoundCache.getSound(OPEN_SOUND_URL);
_this.musicIsPlaying = false; print('OPEN SOUND?? ' + this.openSound)
_this.shut = true; this.musicIsPlaying = false;
_this.shutSoundInjector = { this.shut = true;
this.shutSoundInjector = {
isPlaying: false isPlaying: false
}; };
_this.musicInjector = null; this.musicInjector = null;
_this.openSoundInjector = { this.openSoundInjector = {
isPlaying: false isPlaying: false
} }
this.getParts();
this.props = Entities.getEntityProperties(this.entityID);
},
updateSoundPositionWhileBaseIsHeld: function() {
},
startNearTrigger: function() {
this.getParts();
}, },
continueNearTrigger: function() { continueNearTrigger: function() {
var properties = Entities.getEntityProperties(this.entityID); var properties = Entities.getEntityProperties(this.entityID);
}, },
playMusic: function() { playMusic: function() {
if (this.musicIsPlaying !== true) { if (this.musicIsPlaying !== true) {
var properties = Entities.getEntityProperties(this.entityID); var properties = Entities.getEntityProperties(this.entityID);
var audioOptions = { var audioOptions = {
@ -48,12 +60,17 @@
} }
this.musicInjector = Audio.playSound(this.music, audioOptions); this.musicInjector = Audio.playSound(this.music, audioOptions);
this.musicIsPlaying = true; this.musicIsPlaying = true;
print('music should be playing now')
} }
}, },
stopMusic: function() { stopMusic: function() {
this.musicInjector.stop();
this.musicIsPlaying = false; this.musicIsPlaying = false;
if (this.musicInjector !== null) {
this.musicInjector.stop();
}
}, },
playOpenSound: function() { playOpenSound: function() {
@ -67,9 +84,12 @@
loop: false loop: false
} }
this.openSoundInjector = Audio.playSound(this.openSound, audioOptions); this.openSoundInjector = Audio.playSound(this.openSound, audioOptions);
print('this oppen soundinejctopr' + JSON.stringify(this.openSoundInjector))
} }
}, },
playShutSound: function() { playShutSound: function() {
print('shut injector' + JSON.stringify(this.shutSoundInjector));
if (this.shutSoundInjector.isPlaying !== true) { if (this.shutSoundInjector.isPlaying !== true) {
var properties = Entities.getEntityProperties(this.entityID); var properties = Entities.getEntityProperties(this.entityID);
@ -82,6 +102,7 @@
this.shutSoundInjector = Audio.playSound(this.shutSound, audioOptions); this.shutSoundInjector = Audio.playSound(this.shutSound, audioOptions);
} }
}, },
rotateLid: function(myID, paramsArray) { rotateLid: function(myID, paramsArray) {
var finalRotation; var finalRotation;
@ -102,10 +123,10 @@
//this might be z now that its roll //this might be z now that its roll
var constraint = finalRotation.x var constraint = finalRotation.z
var MIN_LID_ROTATION = 0; var MIN_LID_ROTATION = 0;
var MAX_LID_ROTAITON = 75; var MAX_LID_ROTATION = 75;
//handle sound on open, close, and actually play the song //handle sound on open, close, and actually play the song
if (constraint > 20 && this.musicIsPlaying === false) { if (constraint > 20 && this.musicIsPlaying === false) {
@ -120,10 +141,14 @@
print('play open sound!!') print('play open sound!!')
this.shut = false; this.shut = false;
this.playOpenSound(); this.playOpenSound();
this.startHat();
this.startKey();
} else if (constraint <= 0 && this.shut === false) { } else if (constraint <= 0 && this.shut === false) {
print('play shut sound!!') print('play shut sound!!')
this.shut = true; this.shut = true;
this.playShutSound(); this.playShutSound();
this.stopKey();
this.stopHat();
} }
//handle scaling the lid angle to the animation frame //handle scaling the lid angle to the animation frame
@ -132,51 +157,88 @@
//scale for going up down, and then spin when fully open ;) //scale for going up down, and then spin when fully open ;)
var currentFrame = scaleValue(constraint, MIN_LID_ROTATION, MAX_LID_ROTAITON, 0, 30) var hatHeight = scaleValue(constraint, MIN_LID_ROTATION, MAX_LID_ROTATION, 0, 0.04);
var animation;
if (finalRotation.x === 75) {
animation = {
loop: true,
hold: true,
firstFrame: 30,
lastFrame: 90,
animationIsPlaying: true,
animationFPS: 30,
}
} else {
animation = {
url: BASE_ANIMATION_URL,
running: false,
currentFrame: currentFrame,
animationIsPlaying: false,
firstFrame: 0,
lastFrame: 30
},
}
Entities.editEntity(this.entityID, { Entities.editEntity(this.entityID, {
rotation: Quat.fromPitchYawRollDegrees(finalRotation.x, finalRotation.y, finalRotation.z) rotation: Quat.fromPitchYawRollDegrees(finalRotation.x, finalRotation.y, finalRotation.z)
}) })
Entities.editEntity(this.base, { var VERTICAL_OFFSET = 0.025;
animation: animation var FORWARD_OFFSET = 0.0;
var LATERAL_OFFSET = 0.0;
var hatOffset = getOffsetFromCenter(VERTICAL_OFFSET, FORWARD_OFFSET, LATERAL_OFFSET)
var upOffset = Vec3.sum({
x: 0,
y: hatHeight,
z: 0
}, hatOffset)
Entities.editEntity(this.hat, {
position: upOffset
}) })
}, },
getParts: function() {
var properties = Entities.getEntityProperties(this.entityID);
var results = Entities.findEntities(properties.position, 2);
results.forEach(function(result) {
clickReleaseOnEntity: function() { var props = Entities.getEntityProperties(result);
if (props.name === 'home_music_box_base') {
print('FOUND BASE');
_this.base = result;
_this.baseProps = props;
}
if (props.name === 'home_music_box_key') {
print('FOUND KEY')
_this.key = result;
_this.keyProps = props;
}
if (props.name === 'home_music_box_hat') {
print('FOUND HAT')
_this.hat = result;
_this.hatProps = props;
}
})
}, },
getBase: function() { startHat: function() {
var props = Entities.getEntityProperties(this.entityID); Entities.editEntity(this.hat, {
var data = JSON.parse(props.userData); angularDamping: 0,
var base = data["hifiHomeKey"].musicBoxBase; angularVelocity: {
print('base is: ' + base); x: 0,
this.base = base; y: 0.785398,
z: 0,
}
})
},
startKey: function() {
Entities.editEntity(this.key, {
angularDamping: 0,
angularVelocity: {
x: 0,
y: 0,
z: 0.785398,
}
})
},
stopHat: function() {
Entities.editEntity(this.hat, {
angularDamping: 0.5,
});
},
stopKey: function() {
Entities.editEntity(this.key, {
angularDamping: 0.5,
});
}, },
unload: function() { unload: function() {
@ -186,11 +248,30 @@
}, },
} }
var scaleValue = function(value, min1, max1, min2, max2) { var scaleValue = function(value, min1, max1, min2, max2) {
return min2 + (max2 - min2) * ((value - min1) / (max1 - min1)); return min2 + (max2 - min2) * ((value - min1) / (max1 - min1));
} }
function getOffsetFromCenter(VERTICAL_OFFSET, FORWARD_OFFSET, LATERAL_OFFSET) {
var properties = Entities.getEntityProperties(_this.base);
var upVector = Quat.getUp(properties.rotation);
var frontVector = Quat.getFront(properties.rotation);
var rightVector = Quat.getRight(properties.rotation);
var upOffset = Vec3.multiply(upVector, VERTICAL_OFFSET);
var frontOffset = Vec3.multiply(frontVector, FORWARD_OFFSET);
var rightOffset = Vec3.multiply(rightVector, LATERAL_OFFSET);
var finalOffset = Vec3.sum(properties.position, upOffset);
finalOffset = Vec3.sum(finalOffset, frontOffset);
finalOffset = Vec3.sum(finalOffset, rightOffset);
return finalOffset
};
return new Lid(); return new Lid();
}) })

View file

@ -60,65 +60,32 @@ HomeMusicBox = function(spawnPosition, spawnRotation) {
var LID_SCRIPT_URL = Script.resolvePath('lid.js?' + Math.random()); var LID_SCRIPT_URL = Script.resolvePath('lid.js?' + Math.random());
var LID_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/DomainContent/Home/musicBox/MusicBoxLid.fbx';
var BASE_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/DomainContent/Home/musicBox/MusicBoxAnimated2.fbx';
var BASE_ANIMATION_URL = 'http://hifi-content.s3.amazonaws.com/DomainContent/Home/musicBox/MusicBoxAnimated2.fbx';
var base, lid;
function createBase() {
var baseProperties = {
name: 'hifi-home-music-box-base',
type: 'Model',
modelURL: BASE_MODEL_URL,
position: BASE_POSITION,
dimensions: BASE_DIMENSIONS,
animation: {
url: BASE_ANIMATION_URL,
running: false,
currentFrame: 0,
firstFrame: 0,
lastFrame: 120,
loop: false
},
userData: JSON.stringify({
'hifiHomeKey': {
'reset': true
}
}),
}
base = Entities.addEntity(baseProperties);
createLid(base);
};
var base, lid, hat, key;
function createLid(baseID) { function createLid(baseID) {
var baseProps = Entities.getEntityProperties(baseID); var baseProps = Entities.getEntityProperties(baseID);
var frontVector = Quat.getFront(baseProps.rotation); var VERTICAL_OFFSET = 0.05;
var rightVector = Quat.getRight(baseProps.rotation); var FORWARD_OFFSET = 0;
var backVector = Vec3.multiply(-1, frontVector); var LATERAL_OFFSET = -0.070;
var backOffset = 0.0125;
var backPosition = baseProps.position; var startPosition = getOffsetFromCenter(VERTICAL_OFFSET, FORWARD_OFFSET, LATERAL_OFFSET);
var backPosition = Vec3.sum(baseProps.position, Vec3.multiply(backOffset, backVector));
backPosition.y = backPosition.y += (BASE_DIMENSIONS.y / 2)
print('backPosition' + JSON.stringify(backPosition));
var lidProperties = { var lidProperties = {
name: 'hifi-home-music-box-lid', name: 'home_music_box_lid',
type: 'Model', type: 'Model',
modelURL: LID_MODEL_URL, modelURL: 'atp:/MB_Lid.fbx',
dimensions: LID_DIMENSIONS, dimensions: LID_DIMENSIONS,
position: baseProps.position, position: startPosition,
parentID: baseID,
registrationPoint: LID_REGISTRATION_POINT, registrationPoint: LID_REGISTRATION_POINT,
dynamic: false, dynamic: false,
script: LID_SCRIPT_URL, script: LID_SCRIPT_URL,
collidesWith: 'myAvatar,otherAvatar', collidesWith: 'myAvatar,otherAvatar',
userData: JSON.stringify({ userData: JSON.stringify({
'hifiHomeKey': { 'hifiHomeKey': {
'reset': true, 'reset': true
'musicBoxBase': baseID
}, },
grabConstraintsKey: { grabConstraintsKey: {
callback: 'rotateLid', callback: 'rotateLid',
@ -132,8 +99,8 @@ HomeMusicBox = function(spawnPosition, spawnRotation) {
min: 0, min: 0,
max: 75, max: 75,
startingAxis: 'y', startingAxis: 'y',
startingPoint: backPosition.y, startingPoint: startPosition.y,
distanceToMax: backPosition.y + 0.35 distanceToMax: startPosition.y + 0.35
} }
} }
}, },
@ -142,34 +109,132 @@ HomeMusicBox = function(spawnPosition, spawnRotation) {
disableReleaseVelocity: true disableReleaseVelocity: true
} }
}) })
} };
lid = Entities.addEntity(lidProperties); lid = Entities.addEntity(lidProperties);
createKey(baseID);
createHat(baseID);
}; };
var theta = 0; function createHat(baseID) {
var min = 0; var VERTICAL_OFFSET = 0.025;
var max = 60; var FORWARD_OFFSET = 0.0;
var direction = "up"; var LATERAL_OFFSET = 0.0;
function animateLid() { var properties = {
theata += 1 modelURL: "atp:/MB_Hat.fbx",
} name: 'home_music_box_hat',
type: 'Model',
position: getOffsetFromCenter(VERTICAL_OFFSET, FORWARD_OFFSET, LATERAL_OFFSET),
parentID: baseID,
dimensions: {
x: 0.0786,
y: 0.0549,
z: 0.0810
},
angularDamping: 1,
angularVelocity: {
x: 0,
y: 0.785398,
z: 0,
},
userData: JSON.stringify({
'hifiHomeKey': {
'reset': true
}
})
};
// if (SHOULD_CLEANUP === true) { hat = Entities.addEntity(properties);
// Script.scriptEnding.connect(cleanup); };
// }
function createKey(baseID) {
var VERTICAL_OFFSET = 0.0;
var FORWARD_OFFSET = 0.11;
var LATERAL_OFFSET = 0.0;
var properties = {
modelURL: "atp:/MB_Key.fbx",
name: 'home_music_box_key',
type: 'Model',
parentID: baseID,
angularDamping:1,
angularVelocity: {
x: 0,
y: 0,
z: 0.785398,
},
position: getOffsetFromCenter(VERTICAL_OFFSET, FORWARD_OFFSET, LATERAL_OFFSET),
dimensions: {
x: 0.0057,
y: 0.0482,
z: 0.0435
},
userData: JSON.stringify({
'hifiHomeKey': {
'reset': true
}
})
};
key = Entities.addEntity(properties);
};
function createBaseBox() {
var properties = {
modelURL: "atp:/MB_Box.fbx",
name: 'home_music_box_base',
type: 'Model',
shapeType:'box',
position: BASE_POSITION,
dynamic:true,
dimensions: {
x: 0.1661,
y: 0.0928,
z: 0.2022
},
userData: JSON.stringify({
'hifiHomeKey': {
'reset': true
}
})
}
base = Entities.addEntity(properties);
createLid(base);
};
function cleanup() { function cleanup() {
Entities.deleteEntity(base); Entities.deleteEntity(base);
Entities.deleteEntity(lid); Entities.deleteEntity(lid);
} Entities.deleteEntity(key);
Entities.deleteEntity(hat);
};
function getOffsetFromCenter(VERTICAL_OFFSET, FORWARD_OFFSET, LATERAL_OFFSET) {
var properties = Entities.getEntityProperties(base);
var upVector = Quat.getUp(properties.rotation);
var frontVector = Quat.getFront(properties.rotation);
var rightVector = Quat.getRight(properties.rotation);
var upOffset = Vec3.multiply(upVector, VERTICAL_OFFSET);
var frontOffset = Vec3.multiply(frontVector, FORWARD_OFFSET);
var rightOffset = Vec3.multiply(rightVector, LATERAL_OFFSET);
var finalOffset = Vec3.sum(properties.position, upOffset);
finalOffset = Vec3.sum(finalOffset, frontOffset);
finalOffset = Vec3.sum(finalOffset, rightOffset);
return finalOffset
};
this.cleanup = cleanup; this.cleanup = cleanup;
createBase(); createBaseBox();
return this; return this;
} }

View file

@ -67,9 +67,24 @@
}); });
// Once user releases eraser, wait a bit then put marker back to its original position and rotation // Once user releases eraser, wait a bit then put marker back to its original position and rotation
Script.setTimeout(function() { // Script.setTimeout(function() {
// var userData = getEntityUserData(_this.entityID);
// Entities.editEntity(_this.entityID, {
// position: userData.originalPosition,
// rotation: userData.originalRotation,
// velocity: {
// x: 0,
// y: -0.01,
// z: 0
// }
// });
// }, _this.ERASER_RESET_WAIT_TIME);
},
collisionWithEntity: function(myID, otherID, collision) {
var otherProps = Entities.getEntityProperties(otherID);
if (otherProps.name === 'home_model_homeset') {
var userData = getEntityUserData(_this.entityID); var userData = getEntityUserData(_this.entityID);
Entities.editEntity(_this.entityID, { Entities.editEntity(_this.entityID) {
position: userData.originalPosition, position: userData.originalPosition,
rotation: userData.originalRotation, rotation: userData.originalRotation,
velocity: { velocity: {
@ -77,12 +92,11 @@
y: -0.01, y: -0.01,
z: 0 z: 0
} }
}); }
}, _this.ERASER_RESET_WAIT_TIME); }
}, },
preload: function(entityID) { preload: function(entityID) {
_this.entityID = entityID; _this.entityID = entityID;
_this.searchSphere = Overlays.addOverlay('sphere', { _this.searchSphere = Overlays.addOverlay('sphere', {

View file

@ -49,7 +49,7 @@
_this.equipped = true; _this.equipped = true;
_this.hand = params[0] == "left" ? 0 : 1; _this.hand = params[0] == "left" ? 0 : 1;
_this.markerColor = getEntityUserData(_this.entityID).markerColor; _this.markerColor = getEntityUserData(_this.entityID).markerColor;
// search for whiteboards // search for whiteboards
var markerPosition = Entities.getEntityProperties(_this.entityID, "position").position; var markerPosition = Entities.getEntityProperties(_this.entityID, "position").position;
var entities = Entities.findEntities(markerPosition, 10); var entities = Entities.findEntities(markerPosition, 10);
entities.forEach(function(entity) { entities.forEach(function(entity) {
@ -68,9 +68,25 @@
}); });
// Once user releases marker, wait a bit then put marker back to its original position and rotation // Once user releases marker, wait a bit then put marker back to its original position and rotation
Script.setTimeout(function() { // Script.setTimeout(function() {
// var userData = getEntityUserData(_this.entityID);
// Entities.editEntity(_this.entityID, {
// position: userData.originalPosition,
// rotation: userData.originalRotation,
// velocity: {
// x: 0,
// y: -0.01,
// z: 0
// }
// });
// }, _this.MARKER_RESET_WAIT_TIME);
},
collisionWithEntity: function(myID, otherID, collision) {
var otherProps = Entities.getEntityProperties(otherID);
if (otherProps.name === 'home_model_homeset') {
var userData = getEntityUserData(_this.entityID); var userData = getEntityUserData(_this.entityID);
Entities.editEntity(_this.entityID, { Entities.editEntity(_this.entityID) {
position: userData.originalPosition, position: userData.originalPosition,
rotation: userData.originalRotation, rotation: userData.originalRotation,
velocity: { velocity: {
@ -78,11 +94,9 @@
y: -0.01, y: -0.01,
z: 0 z: 0
} }
}); }
}, _this.MARKER_RESET_WAIT_TIME); }
}, },
continueEquip: function() { continueEquip: function() {
// cast a ray from marker and see if it hits anything // cast a ray from marker and see if it hits anything
var markerProps = Entities.getEntityProperties(_this.entityID, ["position", "rotation"]); var markerProps = Entities.getEntityProperties(_this.entityID, ["position", "rotation"]);