diff --git a/unpublishedScripts/DomainContent/Home/musicBox/lid.js b/unpublishedScripts/DomainContent/Home/musicBox/lid.js index b2fb8da0ca..df1cd0c325 100644 --- a/unpublishedScripts/DomainContent/Home/musicBox/lid.js +++ b/unpublishedScripts/DomainContent/Home/musicBox/lid.js @@ -7,20 +7,15 @@ return this; } - var MUSIC_URL = 'https://hifi-content.s3.amazonaws.com/DomainContent/Home/Sounds/aquarium_small.L.wav'; - var SHUT_SOUND_URL = 'http://hifi-content.s3.amazonaws.com/DomainContent/Home/Sounds/book_fall.L.wav'; - var OPEN_SOUND_URL = 'http://public.highfidelity.io/sounds/Switches%20and%20sliders/lamp_switch_2.wav' - - var GO_UP_ANIMATION = 'http://hifi-content.s3.amazonaws.com/DomainContent/Home/musicBox/MusicBox_ComesUp.fbx'; - var GO_DOWN_ANIMATION = 'http://hifi-content.s3.amazonaws.com/DomainContent/Home/musicBox/MusicBox_GoesDown.fbx'; - var HOLD_ANIMATION = ''; - var KEY_TURNING_ANIMATION = ''; - var FULLY_CLOSED_ANIMATION = 'http://hifi-content.s3.amazonaws.com/DomainContent/Home/musicBox/MusicBoxNoLidNoanimation.fbx'; + 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'; Lid.prototype = { musicInjector: null, preload: function(entityID) { - print('PRELOAD LID') + print('PRELOAD LID'); _this.entityID = entityID; _this.music = SoundCache.getSound(MUSIC_URL); _this.shutSound = SoundCache.getSound(SHUT_SOUND_URL); @@ -105,35 +100,84 @@ }); - if (finalRotation.x > 20 && this.musicIsPlaying === false) { + + //this might be z now that its roll + var constraint = finalRotation.x + + var MIN_LID_ROTATION = 0; + var MAX_LID_ROTAITON = 75; + + //handle sound on open, close, and actually play the song + if (constraint > 20 && this.musicIsPlaying === false) { this.playMusic(); print('play music!!') } - if (finalRotation.x <= 20 && this.musicIsPlaying === true) { + if (constraint <= 20 && this.musicIsPlaying === true) { print('stop music!!') this.stopMusic(); } - if (finalRotation.x > 0 && this.shut === true) { + if (constraint > 0 && this.shut === true) { print('play open sound!!') this.shut = false; this.playOpenSound(); - } else if (finalRotation.x <= 0 && this.shut === false) { + } else if (constraint <= 0 && this.shut === false) { print('play shut sound!!') this.shut = true; this.playShutSound(); } + + //handle scaling the lid angle to the animation frame + //0 to 30 hat going up + //30-90 hat spinning + + //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 + }, + } + Entities.editEntity(this.entityID, { rotation: Quat.fromPitchYawRollDegrees(finalRotation.x, finalRotation.y, finalRotation.z) }) + Entities.editEntity(this.base, { + animation: animation + }) + }, - playBaseOpeningAnimation: function() {}, - playHoldBaseOpenAnimation: function() {}, - playBaseClosingAnimation: function() {}, - stopBaseAnimation: function() {}, - playKeyTurnAnimation: function() {}, - stopKeyTurnAnimation: function() {}, + + clickReleaseOnEntity: function() { + + }, + + 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; + }, unload: function() { if (this.musicInjector !== null) { @@ -143,5 +187,10 @@ } + var scaleValue = function(value, min1, max1, min2, max2) { + return min2 + (max2 - min2) * ((value - min1) / (max1 - min1)); + } + + 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 13a3a0388b..3c76776300 100644 --- a/unpublishedScripts/DomainContent/Home/musicBox/wrapper.js +++ b/unpublishedScripts/DomainContent/Home/musicBox/wrapper.js @@ -61,8 +61,8 @@ 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/MusicBoxNoLidNoanimation.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; @@ -73,6 +73,14 @@ HomeMusicBox = function(spawnPosition, spawnRotation) { 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 @@ -94,8 +102,8 @@ HomeMusicBox = function(spawnPosition, spawnRotation) { 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) - // backPosition = Vec3.sum(backPosition,LID_OFFSET) + backPosition.y = backPosition.y += (BASE_DIMENSIONS.y / 2) + print('backPosition' + JSON.stringify(backPosition)); var lidProperties = { name: 'hifi-home-music-box-lid', @@ -118,15 +126,15 @@ HomeMusicBox = function(spawnPosition, spawnRotation) { rotationLocked: false, positionMod: false, rotationMod: { + pitch: false, + yaw: false, roll: { min: 0, max: 75, startingAxis: 'y', startingPoint: backPosition.y, - distanceToMax: backPosition.y + 0.35, - }, - yaw: false, - pitch: false + distanceToMax: backPosition.y + 0.35 + } } }, grabbableKey: {