most of a music box

This commit is contained in:
James B. Pollack 2016-04-04 19:56:25 -07:00
parent d833c52e4b
commit e780e46d5f
6 changed files with 266 additions and 242 deletions

View file

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

View file

@ -74,7 +74,6 @@ Plant = function(spawnPosition, spawnRotation) {
});
var WATER_CAN_MODEL_URL = "atp:/growingPlant/waterCan.fbx";
var WATER_CAN_COLLIISION_HULL_URL = "atp:/growingPlant/can.obj";
var waterCanPosition = Vec3.sum(plantPosition, Vec3.multiply(0.6, Quat.getRight(orientation)));
var waterCanRotation = orientation;

View file

@ -10,32 +10,39 @@
}
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 OPEN_SOUND_URL = Script.resolvePath('http://public.highfidelity.io/sounds/Switches%20and%20sliders/lamp_switch_2.wav');
var BASE_ANIMATION_URL = 'http://hifi-content.s3.amazonaws.com/DomainContent/Home/musicBox/MusicBoxAnimated2.fbx';
// 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 SHUT_SOUND_URL = Script.resolvePath('atp:/openSound.wav');
var OPEN_SOUND_URL = Script.resolvePath('atp:/closeSound.wav');
Lid.prototype = {
musicInjector: null,
playingByClick: false,
preload: function(entityID) {
_this.entityID = entityID;
_this.music = SoundCache.getSound(MUSIC_URL);
_this.shutSound = SoundCache.getSound(SHUT_SOUND_URL);
_this.openSound = SoundCache.getSound(OPEN_SOUND_URL);
_this.musicIsPlaying = false;
_this.shut = true;
_this.shutSoundInjector = {
this.entityID = entityID;
this.music = SoundCache.getSound(MUSIC_URL);
this.shutSound = SoundCache.getSound(SHUT_SOUND_URL);
this.openSound = SoundCache.getSound(OPEN_SOUND_URL);
print('OPEN SOUND?? ' + this.openSound)
this.musicIsPlaying = false;
this.shut = true;
this.shutSoundInjector = {
isPlaying: false
};
_this.musicInjector = null;
_this.openSoundInjector = {
this.musicInjector = null;
this.openSoundInjector = {
isPlaying: false
}
_this.getBase();
this.getParts();
this.props = Entities.getEntityProperties(this.entityID);
},
updateSoundPositionWhileBaseIsHeld: function() {
},
startNearTrigger: function() {
this.getBase();
this.getParts();
},
continueNearTrigger: function() {
@ -59,9 +66,9 @@
},
stopMusic: function() {
this.musicIsPlaying = false;
if (this.musicInjector !== null) {
this.musicInjector.stop();
this.musicIsPlaying = false;
}
},
@ -77,10 +84,12 @@
loop: false
}
this.openSoundInjector = Audio.playSound(this.openSound, audioOptions);
print('this oppen soundinejctopr' + JSON.stringify(this.openSoundInjector))
}
},
playShutSound: function() {
print('shut injector' + JSON.stringify(this.shutSoundInjector));
if (this.shutSoundInjector.isPlaying !== true) {
var properties = Entities.getEntityProperties(this.entityID);
@ -114,10 +123,10 @@
//this might be z now that its roll
var constraint = finalRotation.x
var constraint = finalRotation.z
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
if (constraint > 20 && this.musicIsPlaying === false) {
@ -132,10 +141,14 @@
print('play open sound!!')
this.shut = false;
this.playOpenSound();
this.startHat();
this.startKey();
} else if (constraint <= 0 && this.shut === false) {
print('play shut sound!!')
this.shut = true;
this.playShutSound();
this.stopKey();
this.stopHat();
}
//handle scaling the lid angle to the animation frame
@ -144,147 +157,88 @@
//scale for going up down, and then spin when fully open ;)
var currentFrame = scaleValue(constraint, MIN_LID_ROTATION, MAX_LID_ROTAITON, 0, 30)
var animation;
if (finalRotation.x === 75) {
animation = {
loop: true,
firstFrame: 30,
lastFrame: 90,
running: true,
animationFPS: 30,
}
} else {
animation = {
url: BASE_ANIMATION_URL,
running: false,
currentFrame: currentFrame,
firstFrame: 0,
lastFrame: 30
}
}
var hatHeight = scaleValue(constraint, MIN_LID_ROTATION, MAX_LID_ROTATION, 0, 0.04);
Entities.editEntity(this.entityID, {
rotation: Quat.fromPitchYawRollDegrees(finalRotation.x, finalRotation.y, finalRotation.z)
})
Entities.editEntity(this.base, {
animation: animation
var VERTICAL_OFFSET = 0.025;
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
})
},
clickDownOnEntity: function() {
this.getBase();
if (this.playingByClick === false) {
this.playingByClick = true;
this.playByClick();
} else {
this.playingByClick = false;
this.stopByClick();
}
},
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);
},
playByClick: function() {
//turn music on
this.playMusic();
var animation;
//play frames 0 to 30 and
animation = {
url: BASE_ANIMATION_URL,
running: true,
firstFrame: 0,
lastFrame: 30,
animationFPS: 30
};
Entities.editEntity(this.base, {
animation: animation
});
// rotate the lid,
//then hold at 30-90
Script.setTimeout(function() {
animation = {
running: true,
firstFrame: 30,
lastFrame: 90,
animationFPS: 30,
loop: true,
if (props.name === 'home_music_box_base') {
print('FOUND BASE');
_this.base = result;
_this.baseProps = props;
}
Entities.editEntity(_this.base, {
animation: animation
});
}, 1000);
},
stopByClick: function() {
var animation;
//play frames 90-120 then stop animating
animation = {
running: true,
firstFrame: 90,
lastFrame: 120,
animationFPS: 30
};
Entities.editEntity(this.base, {
animation: animation
});
Script.setTimeout(function() {
//turn music off
_this.stopMusic();
animation = {
currentFrame: 120,
firstFrame: 120,
lastFrame: 120,
loop: false,
animationFPS: 0,
running: false
if (props.name === 'home_music_box_key') {
print('FOUND KEY')
_this.key = result;
_this.keyProps = props;
}
Entities.editEntity(_this.base, {
animation: animation
});
print('should stop')
}, 1000)
if (props.name === 'home_music_box_hat') {
print('FOUND HAT')
_this.hat = result;
_this.hatProps = props;
}
})
},
playThroughToClose: function() {
startHat: function() {
Entities.editEntity(this.hat, {
angularDamping: 0,
angularVelocity: {
x: 0,
y: 0.785398,
z: 0,
}
})
},
getBase: function() {
var props = Entities.getEntityProperties(this.entityID);
var data = JSON.parse(props.userData);
var base = data["hifiHomeKey"].musicBoxBase;
print('base is: ' + base);
this.base = base;
startKey: function() {
Entities.editEntity(this.key, {
angularDamping: 0,
angularVelocity: {
x: 0,
y: 0,
z: 0.785398,
}
})
},
rotateHat: function() {
stopHat: function() {
Entities.editEntity(this.hat, {
angularDamping: 0.5,
});
},
rotateKey: function() {
},
raiseHat: function() {
},
lowerHat: function() {
stopKey: function() {
Entities.editEntity(this.key, {
angularDamping: 0.5,
});
},
unload: function() {
@ -298,6 +252,26 @@
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();
})

View file

@ -60,65 +60,32 @@ HomeMusicBox = function(spawnPosition, spawnRotation) {
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, hat, key;
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);
};
function createLid(baseID) {
var baseProps = Entities.getEntityProperties(baseID);
var frontVector = Quat.getFront(baseProps.rotation);
var rightVector = Quat.getRight(baseProps.rotation);
var backVector = Vec3.multiply(-1, frontVector);
var backOffset = 0.0125;
var backPosition = baseProps.position;
var backPosition = Vec3.sum(baseProps.position, Vec3.multiply(backOffset, backVector));
backPosition.y = backPosition.y += (BASE_DIMENSIONS.y / 2)
var VERTICAL_OFFSET = 0.05;
var FORWARD_OFFSET = 0;
var LATERAL_OFFSET = -0.070;
var startPosition = getOffsetFromCenter(VERTICAL_OFFSET, FORWARD_OFFSET, LATERAL_OFFSET);
print('backPosition' + JSON.stringify(backPosition));
var lidProperties = {
name: 'hifi-home-music-box-lid',
name: 'home_music_box_lid',
type: 'Model',
modelURL: LID_MODEL_URL,
modelURL: 'atp:/MB_Lid.fbx',
dimensions: LID_DIMENSIONS,
position: baseProps.position,
position: startPosition,
parentID: baseID,
registrationPoint: LID_REGISTRATION_POINT,
dynamic: false,
script: LID_SCRIPT_URL,
collidesWith: 'myAvatar,otherAvatar',
userData: JSON.stringify({
'hifiHomeKey': {
'reset': true,
'musicBoxBase': baseID
'reset': true
},
grabConstraintsKey: {
callback: 'rotateLid',
@ -132,8 +99,8 @@ HomeMusicBox = function(spawnPosition, spawnRotation) {
min: 0,
max: 75,
startingAxis: 'y',
startingPoint: backPosition.y,
distanceToMax: backPosition.y + 0.35
startingPoint: startPosition.y,
distanceToMax: startPosition.y + 0.35
}
}
},
@ -142,69 +109,134 @@ HomeMusicBox = function(spawnPosition, spawnRotation) {
disableReleaseVelocity: true
}
})
}
};
lid = Entities.addEntity(lidProperties);
createKey(baseID)
createHat(baseID)
createKey(baseID);
createHat(baseID);
};
function createHat(baseID) {
var VERTICAL_OFFSET = 0.025;
var FORWARD_OFFSET = 0.0;
var LATERAL_OFFSET = 0.0;
var properties = {
name: 'hifi-home-music-box-hat',
type: 'Box',
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.1,
y: 0.1,
z: 0.1
x: 0.0786,
y: 0.0549,
z: 0.0810
},
}
dynamic: true,
angularDamping: 1,
angularVelocity: {
x: 0,
y: 0.785398,
z: 0,
},
userData: JSON.stringify({
'hifiHomeKey': {
'reset': true
},
'musicBoxKey': {
'startPosition': getOffsetFromCenter(VERTICAL_OFFSET, FORWARD_OFFSET, LATERAL_OFFSET)
}
})
};
hat = Entities.addEntity(properties);
}
};
function createKey(baseID) {
var properties = {
name: 'hifi-home-music-box-key',
type: 'Box',
parentID: baseID,
dimensions: {
x: 0.1,
y: 0.1,
z: 0.1
},
}
key = Entities.addEntity(properties);
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 = {
name: 'hifi-home-music-box-base',
type: 'Box',
dimensions: {
x: 0.1,
y: 0.1,
z: 0.1
},
}
base = Entities.addEntity(properties);
}
var properties = {
modelURL: "atp:/MB_Box.fbx",
name: 'home_music_box_base',
type: 'Model',
position: BASE_POSITION,
dimensions: {
x: 0.1661,
y: 0.0928,
z: 0.2022
},
userData: JSON.stringify({
'hifiHomeKey': {
'reset': true
}
})
}
base = Entities.addEntity(properties);
createLid(base);
};
function cleanup() {
Entities.deleteEntity(base);
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;
createBase();
createBaseBox();
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
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);
Entities.editEntity(_this.entityID, {
Entities.editEntity(_this.entityID) {
position: userData.originalPosition,
rotation: userData.originalRotation,
velocity: {
@ -77,12 +92,11 @@
y: -0.01,
z: 0
}
});
}, _this.ERASER_RESET_WAIT_TIME);
}
}
},
preload: function(entityID) {
_this.entityID = entityID;
_this.searchSphere = Overlays.addOverlay('sphere', {

View file

@ -49,7 +49,7 @@
_this.equipped = true;
_this.hand = params[0] == "left" ? 0 : 1;
_this.markerColor = getEntityUserData(_this.entityID).markerColor;
// search for whiteboards
// search for whiteboards
var markerPosition = Entities.getEntityProperties(_this.entityID, "position").position;
var entities = Entities.findEntities(markerPosition, 10);
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
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);
Entities.editEntity(_this.entityID, {
Entities.editEntity(_this.entityID) {
position: userData.originalPosition,
rotation: userData.originalRotation,
velocity: {
@ -78,11 +94,9 @@
y: -0.01,
z: 0
}
});
}, _this.MARKER_RESET_WAIT_TIME);
}
}
},
continueEquip: function() {
// cast a ray from marker and see if it hits anything
var markerProps = Entities.getEntityProperties(_this.entityID, ["position", "rotation"]);