diff --git a/unpublishedScripts/DomainContent/Home/cuckooClock/cuckooClockMinuteHandEntityScript.js b/unpublishedScripts/DomainContent/Home/cuckooClock/cuckooClockMinuteHandEntityScript.js index 3689495d84..d55e5f5495 100644 --- a/unpublishedScripts/DomainContent/Home/cuckooClock/cuckooClockMinuteHandEntityScript.js +++ b/unpublishedScripts/DomainContent/Home/cuckooClock/cuckooClockMinuteHandEntityScript.js @@ -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,16 +120,14 @@ var seconds = date.getSeconds(); var minutes = date.getMinutes(); - if (seconds === 0 && minutes === 0) { + if (minutes % 15 === 0 && seconds === 0) { _this.popCuckooOut(); } - // if (seconds % 30 === 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!!!!!!!!!!!"); @@ -151,7 +147,6 @@ currentFrame: 0 } }); - _this.checkTime = false; Script.setTimeout(function() { _this.checkTime = true; }, _this.TIME_CHECK_REFRACTORY_PERIOD); diff --git a/unpublishedScripts/DomainContent/Home/musicBox/lid.js b/unpublishedScripts/DomainContent/Home/musicBox/lid.js index df1cd0c325..e3d74fcb01 100644 --- a/unpublishedScripts/DomainContent/Home/musicBox/lid.js +++ b/unpublishedScripts/DomainContent/Home/musicBox/lid.js @@ -1,5 +1,7 @@ (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; function Lid() { @@ -8,37 +10,47 @@ } 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_ANIMATIONS = '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, preload: function(entityID) { - print('PRELOAD LID'); - _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.getParts(); + this.props = Entities.getEntityProperties(this.entityID); + }, + + updateSoundPositionWhileBaseIsHeld: function() { + + }, + + startNearTrigger: function() { + this.getParts(); }, continueNearTrigger: function() { var properties = Entities.getEntityProperties(this.entityID); - }, playMusic: function() { if (this.musicIsPlaying !== true) { - var properties = Entities.getEntityProperties(this.entityID); var audioOptions = { @@ -48,12 +60,17 @@ } this.musicInjector = Audio.playSound(this.music, audioOptions); this.musicIsPlaying = true; + print('music should be playing now') } + }, stopMusic: function() { - this.musicInjector.stop(); this.musicIsPlaying = false; + if (this.musicInjector !== null) { + this.musicInjector.stop(); + } + }, playOpenSound: function() { @@ -67,9 +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); @@ -82,6 +102,7 @@ this.shutSoundInjector = Audio.playSound(this.shutSound, audioOptions); } }, + rotateLid: function(myID, paramsArray) { var finalRotation; @@ -102,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) { @@ -120,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 @@ -132,51 +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, - 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 - }, - } + 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 }) }, + 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() { - var props = Entities.getEntityProperties(this.entityID); - var data = JSON.parse(props.userData); - var base = data["hifiHomeKey"].musicBoxBase; - print('base is: ' + base); - this.base = base; + startHat: function() { + Entities.editEntity(this.hat, { + angularDamping: 0, + angularVelocity: { + x: 0, + 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() { @@ -186,11 +248,30 @@ }, } - var scaleValue = function(value, min1, max1, min2, max2) { 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(); }) \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/Home/musicBox/wrapper.js b/unpublishedScripts/DomainContent/Home/musicBox/wrapper.js index 3c76776300..97fcb80323 100644 --- a/unpublishedScripts/DomainContent/Home/musicBox/wrapper.js +++ b/unpublishedScripts/DomainContent/Home/musicBox/wrapper.js @@ -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; - - 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) { 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,34 +109,132 @@ HomeMusicBox = function(spawnPosition, spawnRotation) { disableReleaseVelocity: true } }) - } + }; lid = Entities.addEntity(lidProperties); + createKey(baseID); + createHat(baseID); }; - var theta = 0; - var min = 0; - var max = 60; - var direction = "up"; + function createHat(baseID) { + var VERTICAL_OFFSET = 0.025; + var FORWARD_OFFSET = 0.0; + var LATERAL_OFFSET = 0.0; - function animateLid() { - theata += 1 - } + var properties = { + 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) { - // Script.scriptEnding.connect(cleanup); - // } + hat = Entities.addEntity(properties); + }; + + 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() { 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; } \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/Home/whiteboard/eraserEntityScript.js b/unpublishedScripts/DomainContent/Home/whiteboard/eraserEntityScript.js index 1164d2d67d..9740c7380b 100644 --- a/unpublishedScripts/DomainContent/Home/whiteboard/eraserEntityScript.js +++ b/unpublishedScripts/DomainContent/Home/whiteboard/eraserEntityScript.js @@ -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', { diff --git a/unpublishedScripts/DomainContent/Home/whiteboard/markerEntityScript.js b/unpublishedScripts/DomainContent/Home/whiteboard/markerEntityScript.js index 01245f0696..6440044964 100644 --- a/unpublishedScripts/DomainContent/Home/whiteboard/markerEntityScript.js +++ b/unpublishedScripts/DomainContent/Home/whiteboard/markerEntityScript.js @@ -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"]);