From 0ac4da285c49c1c62500f3c96729e36406ea993e Mon Sep 17 00:00:00 2001 From: James Pollack Date: Wed, 9 Sep 2015 09:48:39 -0700 Subject: [PATCH 01/10] Update bubblewand to not use overlays by default. --- examples/toys/bubblewand/bubble.js | 148 ++++++++++++++---- examples/toys/bubblewand/createWand.js | 37 +++-- examples/toys/bubblewand/wand.js | 204 ++++++++++++++----------- 3 files changed, 256 insertions(+), 133 deletions(-) diff --git a/examples/toys/bubblewand/bubble.js b/examples/toys/bubblewand/bubble.js index 3cc68fecfa..e5f6d98e28 100644 --- a/examples/toys/bubblewand/bubble.js +++ b/examples/toys/bubblewand/bubble.js @@ -5,48 +5,140 @@ // Copyright 2015 High Fidelity, Inc. // // example of a nested entity. it doesn't do much now besides delete itself if it collides with something (bubbles are fragile! it would be cool if it sometimes merged with other bubbbles it hit) -// todo: play bubble sounds from the bubble itself instead of the wand. +// todo: play bubble sounds & particle bursts from the bubble itself instead of the wand. // blocker: needs some sound fixes and a way to find its own position before unload for spatialization // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html - (function() { - // Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/utilities.js"); - // Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/libraries/utils.js"); + Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/utilities.js"); + Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/libraries/utils.js"); - //var popSound; + var POP_SOUNDS = [ + SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop0.wav"), + SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop1.wav"), + SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop2.wav"), + SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop3.wav") + ] + + BUBBLE_PARTICLE_COLOR = { + red: 0, + green: 40, + blue: 255, + } + + var properties; + var checkPositionInterval; this.preload = function(entityID) { // print('bubble preload') - this.entityID = entityID; - // popSound = SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop.wav"); + // var _t = this; + // _t.entityID = entityID; + // properties = Entities.getEntityProperties(entityID); + // checkPositionInterval = Script.setInterval(function() { + // properties = Entities.getEntityProperties(entityID); + // // print('properties AT CHECK::' + JSON.stringify(properties)); + // }, 200); + + // _t.loadShader(entityID); + }; + + this.loadShader = function(entityID) { + setEntityUserData(entityID, { + "ProceduralEntity": { + "shaderUrl": "http://localhost:8080/shaders/bubble.fs?" + randInt(0, 10000), + } + }) + }; + + + this.leaveEntity = function(entityID) { + print('LEAVE ENTITY:' + entityID) + }; + + this.collisionWithEntity = function(myID, otherID, collision) { + //Entities.deleteEntity(myID); + // Entities.deleteEntity(otherID); + }; + + // this.beforeUnload = function(entityID) { + // print('BEFORE UNLOAD:' + entityID); + // var properties = Entities.getEntityProperties(entityID); + // var position = properties.position; + // print('BEFOREUNLOAD PROPS' + JSON.stringify(position)); + + // }; + + this.unload = function(entityID) { + // Script.clearInterval(checkPositionInterval); + // var position = properties.position; + // this.endOfBubble(position); + var properties = Entities.getEntityProperties(entityID) + var position = properties.position; + //print('UNLOAD PROPS' + JSON.stringify(position)); + }; + + this.endOfBubble = function(position) { + this.burstBubbleSound(position); + this.createBurstParticles(position); + } + + this.burstBubbleSound = function(position) { + var audioOptions = { + volume: 0.5, + position: position + } + Audio.playSound(POP_SOUNDS[randInt(0, 4)], audioOptions); } - this.collisionWithEntity = function(myID, otherID, collision) { - //if(Entites.getEntityProperties(otherID).userData.objectType==='') { merge bubbles?} - // Entities.deleteEntity(myID); - // this.burstBubbleSound(collision.contactPoint) + this.createBurstParticles = function(position) { + var _t = this; + //get the current position of the bubble + var position = properties.position; + //var orientation = properties.orientation; - }; + var animationSettings = JSON.stringify({ + fps: 30, + frameIndex: 0, + running: true, + firstFrame: 0, + lastFrame: 30, + loop: false + }); - this.unload = function(entityID) { - // this.properties = Entities.getEntityProperties(entityID); - //var location = this.properties.position; - //this.burstBubbleSound(); - }; - - - - this.burstBubbleSound = function(location) { - - // var audioOptions = { - // volume: 0.5, - // position: location - // } - - //Audio.playSound(popSound, audioOptions); + var particleBurst = Entities.addEntity({ + type: "ParticleEffect", + animationSettings: animationSettings, + animationIsPlaying: true, + position: position, + lifetime: 1.0, + dimensions: { + x: 1, + y: 1, + z: 1 + }, + emitVelocity: { + x: 0, + y: -1, + z: 0 + }, + velocitySpread: { + x: 1, + y: 0, + z: 1 + }, + emitAcceleration: { + x: 0, + y: -1, + z: 0 + }, + textures: "https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png", + color: BUBBLE_PARTICLE_COLOR, + lifespan: 1.0, + visible: true, + locked: false + }); } diff --git a/examples/toys/bubblewand/createWand.js b/examples/toys/bubblewand/createWand.js index 15c347d62a..943ea8fdbb 100644 --- a/examples/toys/bubblewand/createWand.js +++ b/examples/toys/bubblewand/createWand.js @@ -4,7 +4,7 @@ // Created by James B. Pollack @imgntn -- 09/03/2015 // Copyright 2015 High Fidelity, Inc. // -// Loads a wand model and attaches the bubble wand behavior. +// Loads a wand model and attaches the bubble wand behavior. // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -13,29 +13,34 @@ Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/utilities.js"); Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/libraries/utils.js"); -var wandModel = "http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/wand.fbx?" + randInt(0, 10000); -var scriptURL = "http://hifi-public.s3.amazonaws.com/james/bubblewand/scripts/wand.js?" + randInt(1, 100500) +var wandModel = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/wand.fbx?' + randInt(0, 10000); +var wandCollisionShape = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/collisionHull.obj?' + randInt(0, 10000); +var scriptURL = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/scripts/wand.js?' + randInt(0, 10000); +//for local testing +//var scriptURL = "http://localhost:8080/scripts/wand.js?" + randInt(0, 10000); //create the wand in front of the avatar var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(Camera.getOrientation()))); + var wand = Entities.addEntity({ - type: "Model", - modelURL: wandModel, - position: center, - dimensions: { - x: 0.1, - y: 1, - z: 0.1 - }, - //must be enabled to be grabbable in the physics engine - collisionsWillMove: true, - shapeType: 'box', - script: scriptURL + type: "Model", + modelURL: wandModel, + position: center, + dimensions: { + x: 0.1, + y: 1, + z: 0.1 + }, + //must be enabled to be grabbable in the physics engine + + collisionsWillMove: true, + compoundShapeURL: wandCollisionShape, + script: scriptURL }); function cleanup() { - Entities.deleteEntity(wand); + Entities.deleteEntity(wand); } diff --git a/examples/toys/bubblewand/wand.js b/examples/toys/bubblewand/wand.js index be1042ab79..d98e0a8f57 100644 --- a/examples/toys/bubblewand/wand.js +++ b/examples/toys/bubblewand/wand.js @@ -20,10 +20,22 @@ function convertRange(value, r1, r2) { Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/libraries/utils.js"); var bubbleModel = "http://hifi-public.s3.amazonaws.com/james/bubblewand/models/bubble/bubble.fbx"; - var bubbleScript = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/scripts/bubble.js?' + randInt(1, 10000); var popSound = SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop.wav"); + var bubbleScript = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/scripts/bubble.js?' + randInt(1, 10000); + //for local testing + // var bubbleScript = 'http://localhost:8080/scripts/bubble.js?' + randInt(1, 10000); - var TARGET_SIZE = 0.4; + var POP_SOUNDS = [ + SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop0.wav"), + SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop1.wav"), + SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop2.wav"), + SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop3.wav") + ] + + var overlays = false; + + //debug overlays for hand position to detect when wand is near avatar head + var TARGET_SIZE = 0.5; var TARGET_COLOR = { red: 128, green: 128, @@ -36,40 +48,46 @@ function convertRange(value, r1, r2) { }; var HAND_SIZE = 0.25; - var leftCubePosition = MyAvatar.getLeftPalmPosition(); - var rightCubePosition = MyAvatar.getRightPalmPosition(); - var leftHand = Overlays.addOverlay("cube", { - position: leftCubePosition, - size: HAND_SIZE, - color: { - red: 0, - green: 0, - blue: 255 - }, - alpha: 1, - solid: false - }); + if (overlays) { - var rightHand = Overlays.addOverlay("cube", { - position: rightCubePosition, - size: HAND_SIZE, - color: { - red: 255, - green: 0, - blue: 0 - }, - alpha: 1, - solid: false - }); - var gustZoneOverlay = Overlays.addOverlay("cube", { - position: getGustDetectorPosition(), - size: TARGET_SIZE, - color: TARGET_COLOR, - alpha: 1, - solid: false - }); + var leftCubePosition = MyAvatar.getLeftPalmPosition(); + var rightCubePosition = MyAvatar.getRightPalmPosition(); + + var leftHand = Overlays.addOverlay("cube", { + position: leftCubePosition, + size: HAND_SIZE, + color: { + red: 0, + green: 0, + blue: 255 + }, + alpha: 1, + solid: false + }); + + var rightHand = Overlays.addOverlay("cube", { + position: rightCubePosition, + size: HAND_SIZE, + color: { + red: 255, + green: 0, + blue: 0 + }, + alpha: 1, + solid: false + }); + + var gustZoneOverlay = Overlays.addOverlay("cube", { + position: getGustDetectorPosition(), + size: TARGET_SIZE, + color: TARGET_COLOR, + alpha: 1, + solid: false + }); + } + function getGustDetectorPosition() { @@ -98,6 +116,11 @@ function convertRange(value, r1, r2) { z: 0 } + var BUBBLE_PARTICLE_COLOR = { + red: 0, + blue: 255, + green: 40 + } var wandEntity = this; @@ -108,9 +131,12 @@ function convertRange(value, r1, r2) { } this.unload = function(entityID) { - Overlays.deleteOverlay(leftHand); - Overlays.deleteOverlay(rightHand); - Overlays.deleteOverlay(gustZoneOverlay) + if (overlays) { + Overlays.deleteOverlay(leftHand); + Overlays.deleteOverlay(rightHand); + Overlays.deleteOverlay(gustZoneOverlay); + } + Entities.editEntity(entityID, { name: "" }); @@ -134,35 +160,45 @@ function convertRange(value, r1, r2) { //get the current position of the wand var properties = Entities.getEntityProperties(wandEntity.entityID); var wandPosition = properties.position; - - //debug overlays for mouth mode - var leftHandPos = MyAvatar.getLeftPalmPosition(); - var rightHandPos = MyAvatar.getRightPalmPosition(); - - Overlays.editOverlay(leftHand, { - position: leftHandPos - }); - Overlays.editOverlay(rightHand, { - position: rightHandPos - }); - //if the wand is in the gust detector, activate mouth mode and change the overlay color var hitTargetWithWand = findSphereSphereHit(wandPosition, HAND_SIZE / 2, getGustDetectorPosition(), TARGET_SIZE / 2) + var velocity = Vec3.subtract(wandPosition, BubbleWand.lastPosition) + var velocityStrength = Vec3.length(velocity) * 100; + var mouthMode; + if (hitTargetWithWand) { + mouthMode = true; + } else { + mouthMode = false; + } + + + + //debug overlays for mouth mode + if (overlays) { + var leftHandPos = MyAvatar.getLeftPalmPosition(); + var rightHandPos = MyAvatar.getRightPalmPosition(); + + Overlays.editOverlay(leftHand, { + position: leftHandPos + }); + Overlays.editOverlay(rightHand, { + position: rightHandPos + }); + } + + if (mouthMode === true && overlays === true) { Overlays.editOverlay(gustZoneOverlay, { position: getGustDetectorPosition(), color: TARGET_COLOR_HIT }) - mouthMode = true; - - } else { + } else if (overlays) { Overlays.editOverlay(gustZoneOverlay, { position: getGustDetectorPosition(), color: TARGET_COLOR }) - mouthMode = false; } var volumeLevel = MyAvatar.audioAverageLoudness; @@ -170,7 +206,6 @@ function convertRange(value, r1, r2) { var convertedVolume = convertRange(volumeLevel, [0, 5000], [0, 10]); // default is 'wave mode', where waving the object around grows the bubbles - var velocity = Vec3.subtract(wandPosition, BubbleWand.lastPosition) //store the last position of the wand for velocity calculations _t.lastPosition = wandPosition; @@ -184,6 +219,8 @@ function convertRange(value, r1, r2) { //actually grow the bubble var dimensions = Entities.getEntityProperties(_t.currentBubble).dimensions; + var avatarFront = Quat.getFront(MyAvatar.orientation); + var forwardOffset = Vec3.multiply(avatarFront, 0.1); if (velocityStrength > 1 || convertedVolume > 1) { @@ -196,21 +233,17 @@ function convertRange(value, r1, r2) { //bubbles pop after existing for a bit -- so set a random lifetime var lifetime = randInt(3, 8); - //sound is somewhat unstable at the moment so this is commented out. really audio should be played by the bubbles, but there's a blocker. - // Script.setTimeout(function() { - // _t.burstBubbleSound(_t.currentBubble) - // }, lifetime * 1000) - - - //todo: angular velocity without the controller -- forward velocity for mouth mode bubbles // var angularVelocity = Controller.getSpatialControlRawAngularVelocity(hands.leftHand.tip); Entities.editEntity(_t.currentBubble, { - velocity: Vec3.normalize(velocity), + // collisionsWillMove:true, + // ignoreForCollisions:false, + velocity: mouthMode ? avatarFront : velocity, // angularVelocity: Controller.getSpatialControlRawAngularVelocity(hands.leftHand.tip), lifetime: lifetime }); + _t.lastBubble = _t.currentBubble; //release the bubble -- when we create a new bubble, it will carry on and this update loop will affect the new bubble BubbleWand.spawnBubble(); @@ -244,27 +277,18 @@ function convertRange(value, r1, r2) { }); }, - burstBubbleSound: function(bubble) { - //we want to play the sound at the same location and orientation as the bubble - var position = Entities.getEntityProperties(bubble).position; - var orientation = Entities.getEntityProperties(bubble).orientation; - - //set the options for the audio injector - var audioOptions = { - volume: 0.5, - position: position, - orientation: orientation - } - - - //var audioInjector = Audio.playSound(popSound, audioOptions); - - //remove this bubble from the array to keep things clean - var i = BubbleWand.bubbles.indexOf(bubble); - if (i != -1) { - BubbleWand.bubbles.splice(i, 1); - } - + checkForEntitiesNearBubble: function() { + var _t = this; + var arrayFound = Entities.findEntities(_t.wandTipPosition, 1); + var foundLength = arrayFound.length; + print('found length:::' + foundLength); + }, + enableCollisionsForBubble: function(bubble) { + print('enable bubble collisions:' + bubble) + Entities.editEntity(bubble, { + collisionsWillMove: true, + ignoreForCollisions: false, + }) }, spawnBubble: function() { var _t = this; @@ -275,10 +299,11 @@ function convertRange(value, r1, r2) { var wandPosition = properties.position; var upVector = Quat.getUp(properties.rotation); var frontVector = Quat.getFront(properties.rotation); - var upOffset = Vec3.multiply(upVector, 0.5); - var forwardOffset = Vec3.multiply(frontVector, 0.1); - var offsetVector = Vec3.sum(upOffset, forwardOffset); - var wandTipPosition = Vec3.sum(wandPosition, offsetVector); + var upOffset = Vec3.multiply(upVector, 0.4); + // var forwardOffset = Vec3.multiply(frontVector, 0.1); + // var offsetVector = Vec3.sum(upOffset, forwardOffset); + // var wandTipPosition = Vec3.sum(wandPosition, offsetVector); + var wandTipPosition = Vec3.sum(wandPosition, upOffset); _t.wandTipPosition = wandTipPosition; //store the position of the tip on spawn for use in velocity calculations @@ -294,10 +319,10 @@ function convertRange(value, r1, r2) { y: 0.01, z: 0.01 }, - collisionsWillMove: false, - ignoreForCollisions: true, + collisionsWillMove: false, //true + ignoreForCollisions: true, //false gravity: BUBBLE_GRAVITY, - // collisionSoundURL:popSound, + collisionSoundURL: POP_SOUNDS[randInt(0, 4)], shapeType: "sphere", script: bubbleScript, }); @@ -309,6 +334,7 @@ function convertRange(value, r1, r2) { init: function() { this.spawnBubble(); Script.update.connect(BubbleWand.update); + } } From da90b7ff087d7daa87c1e59ce0a090ad8839f1fd Mon Sep 17 00:00:00 2001 From: James Pollack Date: Wed, 9 Sep 2015 09:53:47 -0700 Subject: [PATCH 02/10] remove logging around bubble leave entity --- examples/toys/bubblewand/bubble.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/toys/bubblewand/bubble.js b/examples/toys/bubblewand/bubble.js index e5f6d98e28..fe92ea76c8 100644 --- a/examples/toys/bubblewand/bubble.js +++ b/examples/toys/bubblewand/bubble.js @@ -53,7 +53,7 @@ this.leaveEntity = function(entityID) { - print('LEAVE ENTITY:' + entityID) + // print('LEAVE ENTITY:' + entityID) }; this.collisionWithEntity = function(myID, otherID, collision) { From 8f77c0b61cedda9b8c17ec65db486650b6f3297f Mon Sep 17 00:00:00 2001 From: James Pollack Date: Thu, 10 Sep 2015 09:58:31 -0700 Subject: [PATCH 03/10] Update wand to use relative paths, remove some unused position tracking methods, remove cache busting from model file paths --- examples/toys/bubblewand/bubble.js | 23 +++++------------------ examples/toys/bubblewand/createWand.js | 8 ++++---- examples/toys/bubblewand/wand.js | 4 ++-- 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/examples/toys/bubblewand/bubble.js b/examples/toys/bubblewand/bubble.js index fe92ea76c8..b7967e81ea 100644 --- a/examples/toys/bubblewand/bubble.js +++ b/examples/toys/bubblewand/bubble.js @@ -12,8 +12,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html (function() { - Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/utilities.js"); - Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/libraries/utils.js"); + Script.include("../utilities.js"); + Script.include("../libraries/utils.js"); var POP_SOUNDS = [ SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop0.wav"), @@ -35,25 +35,20 @@ // var _t = this; // _t.entityID = entityID; // properties = Entities.getEntityProperties(entityID); - // checkPositionInterval = Script.setInterval(function() { - // properties = Entities.getEntityProperties(entityID); - // // print('properties AT CHECK::' + JSON.stringify(properties)); - // }, 200); - - // _t.loadShader(entityID); + // _t.loadShader(entityID); }; this.loadShader = function(entityID) { setEntityUserData(entityID, { "ProceduralEntity": { - "shaderUrl": "http://localhost:8080/shaders/bubble.fs?" + randInt(0, 10000), + "shaderUrl": "http://hifi-public.s3.amazonaws.com/james/bubblewand/shaders/quora.fs", } }) }; this.leaveEntity = function(entityID) { - // print('LEAVE ENTITY:' + entityID) + // print('LEAVE ENTITY:' + entityID) }; this.collisionWithEntity = function(myID, otherID, collision) { @@ -61,14 +56,6 @@ // Entities.deleteEntity(otherID); }; - // this.beforeUnload = function(entityID) { - // print('BEFORE UNLOAD:' + entityID); - // var properties = Entities.getEntityProperties(entityID); - // var position = properties.position; - // print('BEFOREUNLOAD PROPS' + JSON.stringify(position)); - - // }; - this.unload = function(entityID) { // Script.clearInterval(checkPositionInterval); // var position = properties.position; diff --git a/examples/toys/bubblewand/createWand.js b/examples/toys/bubblewand/createWand.js index 943ea8fdbb..2c1217d5ce 100644 --- a/examples/toys/bubblewand/createWand.js +++ b/examples/toys/bubblewand/createWand.js @@ -10,11 +10,11 @@ -Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/utilities.js"); -Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/libraries/utils.js"); +Script.include("../utilities.js"); +Script.include("../libraries/utils.js"); -var wandModel = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/wand.fbx?' + randInt(0, 10000); -var wandCollisionShape = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/collisionHull.obj?' + randInt(0, 10000); +var wandModel = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/wand.fbx' ; +var wandCollisionShape = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/collisionHull.obj' ; var scriptURL = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/scripts/wand.js?' + randInt(0, 10000); //for local testing diff --git a/examples/toys/bubblewand/wand.js b/examples/toys/bubblewand/wand.js index d98e0a8f57..648047fbb8 100644 --- a/examples/toys/bubblewand/wand.js +++ b/examples/toys/bubblewand/wand.js @@ -16,8 +16,8 @@ function convertRange(value, r1, r2) { } (function() { - Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/utilities.js"); - Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/libraries/utils.js"); + Script.include("../utilities.js"); +Script.include("../libraries/utils.js"); var bubbleModel = "http://hifi-public.s3.amazonaws.com/james/bubblewand/models/bubble/bubble.fbx"; var popSound = SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop.wav"); From dfa43e84bf825654a29cf1444edde1c21507dc04 Mon Sep 17 00:00:00 2001 From: James Pollack Date: Thu, 10 Sep 2015 10:31:17 -0700 Subject: [PATCH 04/10] bubble update hook --- examples/toys/bubblewand/bubble.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/examples/toys/bubblewand/bubble.js b/examples/toys/bubblewand/bubble.js index b7967e81ea..20020855cb 100644 --- a/examples/toys/bubblewand/bubble.js +++ b/examples/toys/bubblewand/bubble.js @@ -28,6 +28,8 @@ blue: 255, } + var _t = this; + var properties; var checkPositionInterval; this.preload = function(entityID) { @@ -36,8 +38,14 @@ // _t.entityID = entityID; // properties = Entities.getEntityProperties(entityID); // _t.loadShader(entityID); + Script.update.connect(_t.internalUpdate); }; + this.internalUpdate = function() { + + properties = Entities.getEntityProperties(_t.entityID) + } + this.loadShader = function(entityID) { setEntityUserData(entityID, { "ProceduralEntity": { @@ -57,12 +65,13 @@ }; this.unload = function(entityID) { - // Script.clearInterval(checkPositionInterval); - // var position = properties.position; - // this.endOfBubble(position); - var properties = Entities.getEntityProperties(entityID) + + Script.update.disconnect(this.internalUpdate); + properties = Entities.getEntityProperties(entityID) var position = properties.position; - //print('UNLOAD PROPS' + JSON.stringify(position)); + // this.endOfBubble(position); + print('UNLOAD PROPS' + JSON.stringify(position)); + }; this.endOfBubble = function(position) { From 5df483b35f3f250da36ce12340ecce38313ede70 Mon Sep 17 00:00:00 2001 From: James Pollack Date: Thu, 10 Sep 2015 11:32:21 -0700 Subject: [PATCH 05/10] ignore 0,0,0 positions so we have accurate unload for bubbles --- examples/toys/bubblewand/bubble.js | 19 +++++++++---------- examples/toys/bubblewand/createWand.js | 12 ++++++------ examples/toys/bubblewand/wand.js | 13 ++++++------- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/examples/toys/bubblewand/bubble.js b/examples/toys/bubblewand/bubble.js index 20020855cb..edb13c085a 100644 --- a/examples/toys/bubblewand/bubble.js +++ b/examples/toys/bubblewand/bubble.js @@ -12,8 +12,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html (function() { - Script.include("../utilities.js"); - Script.include("../libraries/utils.js"); + Script.include("../../utilities.js"); + Script.include("../../libraries/utils.js"); var POP_SOUNDS = [ SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop0.wav"), @@ -34,16 +34,17 @@ var checkPositionInterval; this.preload = function(entityID) { // print('bubble preload') - // var _t = this; - // _t.entityID = entityID; - // properties = Entities.getEntityProperties(entityID); + _t.entityID = entityID; + //properties = Entities.getEntityProperties(entityID); // _t.loadShader(entityID); Script.update.connect(_t.internalUpdate); }; this.internalUpdate = function() { - - properties = Entities.getEntityProperties(_t.entityID) + var tmpProperties = Entities.getEntityProperties(_t.entityID); + if (tmpProperties.position.x !== 0 && tmpProperties.position.y !== 0 && tmpProperties.position.z !== 0) { + properties = tmpProperties; + } } this.loadShader = function(entityID) { @@ -65,11 +66,9 @@ }; this.unload = function(entityID) { - Script.update.disconnect(this.internalUpdate); - properties = Entities.getEntityProperties(entityID) var position = properties.position; - // this.endOfBubble(position); + _t.endOfBubble(position); print('UNLOAD PROPS' + JSON.stringify(position)); }; diff --git a/examples/toys/bubblewand/createWand.js b/examples/toys/bubblewand/createWand.js index 2c1217d5ce..df6127cbcf 100644 --- a/examples/toys/bubblewand/createWand.js +++ b/examples/toys/bubblewand/createWand.js @@ -10,15 +10,15 @@ -Script.include("../utilities.js"); -Script.include("../libraries/utils.js"); +Script.include("../../utilities.js"); +Script.include("../../libraries/utils.js"); -var wandModel = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/wand.fbx' ; -var wandCollisionShape = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/collisionHull.obj' ; -var scriptURL = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/scripts/wand.js?' + randInt(0, 10000); +var wandModel = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/wand.fbx'; +var wandCollisionShape = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/collisionHull.obj'; +//var scriptURL = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/scripts/wand.js?' + randInt(0, 10000); //for local testing -//var scriptURL = "http://localhost:8080/scripts/wand.js?" + randInt(0, 10000); +var scriptURL = "http://localhost:8080/wand.js?" + randInt(0, 10000); //create the wand in front of the avatar var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(Camera.getOrientation()))); diff --git a/examples/toys/bubblewand/wand.js b/examples/toys/bubblewand/wand.js index 648047fbb8..3dd6ad5a19 100644 --- a/examples/toys/bubblewand/wand.js +++ b/examples/toys/bubblewand/wand.js @@ -16,14 +16,13 @@ function convertRange(value, r1, r2) { } (function() { - Script.include("../utilities.js"); -Script.include("../libraries/utils.js"); - + Script.include("../../utilities.js"); + Script.include("../../libraries/utils.js"); var bubbleModel = "http://hifi-public.s3.amazonaws.com/james/bubblewand/models/bubble/bubble.fbx"; var popSound = SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop.wav"); - var bubbleScript = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/scripts/bubble.js?' + randInt(1, 10000); + //var bubbleScript = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/scripts/bubble.js?' + randInt(1, 10000); //for local testing - // var bubbleScript = 'http://localhost:8080/scripts/bubble.js?' + randInt(1, 10000); + var bubbleScript = 'http://localhost:8080/bubble.js?' + randInt(1, 10000); var POP_SOUNDS = [ SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop0.wav"), @@ -319,8 +318,8 @@ Script.include("../libraries/utils.js"); y: 0.01, z: 0.01 }, - collisionsWillMove: false, //true - ignoreForCollisions: true, //false + collisionsWillMove: true, //true + ignoreForCollisions: false, //false gravity: BUBBLE_GRAVITY, collisionSoundURL: POP_SOUNDS[randInt(0, 4)], shapeType: "sphere", From ee7e25a137f69eddc7b9c9fc08bae711054e790b Mon Sep 17 00:00:00 2001 From: James Pollack Date: Thu, 10 Sep 2015 11:49:12 -0700 Subject: [PATCH 06/10] remove localhost refs --- examples/toys/bubblewand/bubble.js | 4 ++-- examples/toys/bubblewand/createWand.js | 4 ++-- examples/toys/bubblewand/wand.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/toys/bubblewand/bubble.js b/examples/toys/bubblewand/bubble.js index edb13c085a..845ad58e17 100644 --- a/examples/toys/bubblewand/bubble.js +++ b/examples/toys/bubblewand/bubble.js @@ -35,12 +35,13 @@ this.preload = function(entityID) { // print('bubble preload') _t.entityID = entityID; - //properties = Entities.getEntityProperties(entityID); + properties = Entities.getEntityProperties(entityID); // _t.loadShader(entityID); Script.update.connect(_t.internalUpdate); }; this.internalUpdate = function() { + // we want the position at unload but for some reason it keeps getting set to 0,0,0 -- so i just exclude that location. sorry origin bubbles. var tmpProperties = Entities.getEntityProperties(_t.entityID); if (tmpProperties.position.x !== 0 && tmpProperties.position.y !== 0 && tmpProperties.position.z !== 0) { properties = tmpProperties; @@ -62,7 +63,6 @@ this.collisionWithEntity = function(myID, otherID, collision) { //Entities.deleteEntity(myID); - // Entities.deleteEntity(otherID); }; this.unload = function(entityID) { diff --git a/examples/toys/bubblewand/createWand.js b/examples/toys/bubblewand/createWand.js index df6127cbcf..50af1b251d 100644 --- a/examples/toys/bubblewand/createWand.js +++ b/examples/toys/bubblewand/createWand.js @@ -15,10 +15,10 @@ Script.include("../../libraries/utils.js"); var wandModel = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/wand.fbx'; var wandCollisionShape = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/collisionHull.obj'; -//var scriptURL = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/scripts/wand.js?' + randInt(0, 10000); +var scriptURL = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/scripts/wand.js?' + randInt(0, 10000); //for local testing -var scriptURL = "http://localhost:8080/wand.js?" + randInt(0, 10000); +//var scriptURL = "http://localhost:8080/wand.js?" + randInt(0, 10000); //create the wand in front of the avatar var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(Camera.getOrientation()))); diff --git a/examples/toys/bubblewand/wand.js b/examples/toys/bubblewand/wand.js index 3dd6ad5a19..e4a9f7231f 100644 --- a/examples/toys/bubblewand/wand.js +++ b/examples/toys/bubblewand/wand.js @@ -20,9 +20,9 @@ function convertRange(value, r1, r2) { Script.include("../../libraries/utils.js"); var bubbleModel = "http://hifi-public.s3.amazonaws.com/james/bubblewand/models/bubble/bubble.fbx"; var popSound = SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop.wav"); - //var bubbleScript = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/scripts/bubble.js?' + randInt(1, 10000); + var bubbleScript = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/scripts/bubble.js?' + randInt(1, 10000); //for local testing - var bubbleScript = 'http://localhost:8080/bubble.js?' + randInt(1, 10000); + //var bubbleScript = 'http://localhost:8080/bubble.js?' + randInt(1, 10000); var POP_SOUNDS = [ SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop0.wav"), From 387e7b74a96c39f8b6e8ea6f78fa5369824a8691 Mon Sep 17 00:00:00 2001 From: James Pollack Date: Thu, 10 Sep 2015 16:58:39 -0700 Subject: [PATCH 07/10] Return wand to its original position if it hasnt moved for 5 seconds, better particles, wand scaled to human size --- examples/toys/bubblewand/bubble.js | 27 +++++---- examples/toys/bubblewand/createWand.js | 18 +++--- examples/toys/bubblewand/wand.js | 80 +++++++++++++++++++------- 3 files changed, 86 insertions(+), 39 deletions(-) diff --git a/examples/toys/bubblewand/bubble.js b/examples/toys/bubblewand/bubble.js index 845ad58e17..231b1cc7ca 100644 --- a/examples/toys/bubblewand/bubble.js +++ b/examples/toys/bubblewand/bubble.js @@ -12,8 +12,12 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html (function() { - Script.include("../../utilities.js"); - Script.include("../../libraries/utils.js"); + // Script.include("../../utilities.js"); + // Script.include("../../libraries/utils.js"); + + + Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/utilities.js"); + Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/libraries/utils.js"); var POP_SOUNDS = [ SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop0.wav"), @@ -69,7 +73,7 @@ Script.update.disconnect(this.internalUpdate); var position = properties.position; _t.endOfBubble(position); - print('UNLOAD PROPS' + JSON.stringify(position)); + // print('UNLOAD PROPS' + JSON.stringify(position)); }; @@ -107,7 +111,7 @@ animationSettings: animationSettings, animationIsPlaying: true, position: position, - lifetime: 1.0, + lifetime: 0.2, dimensions: { x: 1, y: 1, @@ -115,22 +119,25 @@ }, emitVelocity: { x: 0, - y: -1, + y: 0, z: 0 }, velocitySpread: { - x: 1, - y: 0, - z: 1 + x: 0.45, + y: 0.45, + z: 0.45 }, emitAcceleration: { x: 0, - y: -1, + y: -0.1, z: 0 }, + alphaStart: 1.0, + alpha: 1, + alphaFinish: 0.0, textures: "https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png", color: BUBBLE_PARTICLE_COLOR, - lifespan: 1.0, + lifespan: 0.2, visible: true, locked: false }); diff --git a/examples/toys/bubblewand/createWand.js b/examples/toys/bubblewand/createWand.js index 50af1b251d..24db08d2c1 100644 --- a/examples/toys/bubblewand/createWand.js +++ b/examples/toys/bubblewand/createWand.js @@ -10,30 +10,32 @@ -Script.include("../../utilities.js"); -Script.include("../../libraries/utils.js"); +// Script.include("../../utilities.js"); +// Script.include("../../libraries/utils.js"); + +Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/utilities.js"); +Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/libraries/utils.js"); var wandModel = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/wand.fbx'; var wandCollisionShape = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/collisionHull.obj'; -var scriptURL = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/scripts/wand.js?' + randInt(0, 10000); +var scriptURL = 'http://hifi-public.s3.amazonaws.com/scripts/bubblewand/wand.js?' + randInt(0, 10000); //for local testing //var scriptURL = "http://localhost:8080/wand.js?" + randInt(0, 10000); //create the wand in front of the avatar -var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(Camera.getOrientation()))); +var center = Vec3.sum(MyAvatar.position, Vec3.multiply(1, Quat.getFront(Camera.getOrientation()))); var wand = Entities.addEntity({ type: "Model", modelURL: wandModel, position: center, dimensions: { - x: 0.1, - y: 1, - z: 0.1 + x: 0.05, + y: 0.5, + z: 0.05 }, //must be enabled to be grabbable in the physics engine - collisionsWillMove: true, compoundShapeURL: wandCollisionShape, script: scriptURL diff --git a/examples/toys/bubblewand/wand.js b/examples/toys/bubblewand/wand.js index e4a9f7231f..87bdfc6648 100644 --- a/examples/toys/bubblewand/wand.js +++ b/examples/toys/bubblewand/wand.js @@ -16,13 +16,20 @@ function convertRange(value, r1, r2) { } (function() { - Script.include("../../utilities.js"); - Script.include("../../libraries/utils.js"); + + Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/utilities.js"); + Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/libraries/utils.js"); + + + // Script.include("../../utilities.js"); + // Script.include("../../libraries/utils.js"); + + var bubbleModel = "http://hifi-public.s3.amazonaws.com/james/bubblewand/models/bubble/bubble.fbx"; var popSound = SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop.wav"); - var bubbleScript = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/scripts/bubble.js?' + randInt(1, 10000); - //for local testing - //var bubbleScript = 'http://localhost:8080/bubble.js?' + randInt(1, 10000); + var bubbleScript = 'http://hifi-public.s3.amazonaws.com/scripts/toys/bubblewand/bubble.js?' + randInt(1, 10000); + + // var bubbleScript = 'http://localhost:8080/bubble.js?' + randInt(1, 10000); //for local testing var POP_SOUNDS = [ SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop0.wav"), @@ -127,6 +134,9 @@ function convertRange(value, r1, r2) { // print('PRELOAD') this.entityID = entityID; this.properties = Entities.getEntityProperties(this.entityID); + BubbleWand.originalProperties = this.properties; + print('rotation???' + JSON.stringify(BubbleWand.originalProperties.rotation)); + } this.unload = function(entityID) { @@ -150,11 +160,14 @@ function convertRange(value, r1, r2) { var BubbleWand = { bubbles: [], + timeSinceMoved: 0, + resetAtTime: 5, currentBubble: null, - update: function() { - BubbleWand.internalUpdate(); + update: function(dt) { + BubbleWand.internalUpdate(dt); }, - internalUpdate: function() { + internalUpdate: function(dt) { + var _t = this; //get the current position of the wand var properties = Entities.getEntityProperties(wandEntity.entityID); @@ -162,9 +175,16 @@ function convertRange(value, r1, r2) { //if the wand is in the gust detector, activate mouth mode and change the overlay color var hitTargetWithWand = findSphereSphereHit(wandPosition, HAND_SIZE / 2, getGustDetectorPosition(), TARGET_SIZE / 2) - var velocity = Vec3.subtract(wandPosition, BubbleWand.lastPosition) + var velocity = Vec3.subtract(wandPosition, _t.lastPosition) var velocityStrength = Vec3.length(velocity) * 100; + + var upVector = Quat.getUp(properties.rotation); + var frontVector = Quat.getFront(properties.rotation); + var upOffset = Vec3.multiply(upVector, 0.2); + var wandTipPosition = Vec3.sum(wandPosition, upOffset); + _t.wandTipPosition = wandTipPosition; + var mouthMode; if (hitTargetWithWand) { @@ -172,8 +192,18 @@ function convertRange(value, r1, r2) { } else { mouthMode = false; } + //print('velocityStrength'+velocityStrength) - + //we want to reset the object to its original position if its been a while since it has moved + if (velocityStrength === 0) { + _t.timeSinceMoved = _t.timeSinceMoved + dt; + if (_t.timeSinceMoved > _t.resetAtTime) { + _t.timeSinceMoved = 0; + _t.returnToOriginalLocation(); + } + } else { + _t.timeSinceMoved = 0; + } //debug overlays for mouth mode if (overlays) { @@ -225,7 +255,7 @@ function convertRange(value, r1, r2) { //add some variation in bubble sizes var bubbleSize = randInt(1, 5); - bubbleSize = bubbleSize / 10; + bubbleSize = bubbleSize / 50; //release the bubble if its dimensions are bigger than the bubble size if (dimensions.x > bubbleSize) { @@ -249,14 +279,14 @@ function convertRange(value, r1, r2) { return } else { if (mouthMode) { - dimensions.x += 0.015 * convertedVolume; - dimensions.y += 0.015 * convertedVolume; - dimensions.z += 0.015 * convertedVolume; + dimensions.x += 0.005 * convertedVolume; + dimensions.y += 0.005 * convertedVolume; + dimensions.z += 0.005 * convertedVolume; } else { - dimensions.x += 0.015 * velocityStrength; - dimensions.y += 0.015 * velocityStrength; - dimensions.z += 0.015 * velocityStrength; + dimensions.x += 0.005 * velocityStrength; + dimensions.y += 0.005 * velocityStrength; + dimensions.z += 0.005 * velocityStrength; } } @@ -298,10 +328,7 @@ function convertRange(value, r1, r2) { var wandPosition = properties.position; var upVector = Quat.getUp(properties.rotation); var frontVector = Quat.getFront(properties.rotation); - var upOffset = Vec3.multiply(upVector, 0.4); - // var forwardOffset = Vec3.multiply(frontVector, 0.1); - // var offsetVector = Vec3.sum(upOffset, forwardOffset); - // var wandTipPosition = Vec3.sum(wandPosition, offsetVector); + var upOffset = Vec3.multiply(upVector, 0.2); var wandTipPosition = Vec3.sum(wandPosition, upOffset); _t.wandTipPosition = wandTipPosition; @@ -329,8 +356,19 @@ function convertRange(value, r1, r2) { //add this bubble to an array of bubbles so we can keep track of them _t.bubbles.push(_t.currentBubble) + }, + returnToOriginalLocation: function() { + var _t = this; + Script.update.disconnect(BubbleWand.update) + _t.currentBubble = null; + Entities.deleteEntity(_t.currentBubble); + Entities.editEntity(wandEntity.entityID, _t.originalProperties) + _t.spawnBubble(); + Script.update.connect(BubbleWand.update); + }, init: function() { + var _t = this; this.spawnBubble(); Script.update.connect(BubbleWand.update); From 1cec61ebbad8b1de8f8dc5ef651f2f1bcdda0231 Mon Sep 17 00:00:00 2001 From: James Pollack Date: Thu, 10 Sep 2015 17:05:24 -0700 Subject: [PATCH 08/10] fire particles before burst sound --- examples/toys/bubblewand/bubble.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/toys/bubblewand/bubble.js b/examples/toys/bubblewand/bubble.js index 231b1cc7ca..eaabf98e44 100644 --- a/examples/toys/bubblewand/bubble.js +++ b/examples/toys/bubblewand/bubble.js @@ -78,8 +78,9 @@ }; this.endOfBubble = function(position) { - this.burstBubbleSound(position); + this.createBurstParticles(position); + this.burstBubbleSound(position); } this.burstBubbleSound = function(position) { From c3ed2d90643b6edabccfd71ce66b1dafcc514b60 Mon Sep 17 00:00:00 2001 From: James Pollack Date: Thu, 10 Sep 2015 17:10:55 -0700 Subject: [PATCH 09/10] fix file paths --- examples/toys/bubblewand/createWand.js | 2 +- examples/toys/bubblewand/wand.js | 15 +-------------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/examples/toys/bubblewand/createWand.js b/examples/toys/bubblewand/createWand.js index 24db08d2c1..158bcb3b99 100644 --- a/examples/toys/bubblewand/createWand.js +++ b/examples/toys/bubblewand/createWand.js @@ -18,7 +18,7 @@ Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examp var wandModel = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/wand.fbx'; var wandCollisionShape = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/collisionHull.obj'; -var scriptURL = 'http://hifi-public.s3.amazonaws.com/scripts/bubblewand/wand.js?' + randInt(0, 10000); +var scriptURL = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/scripts/wand.js?' + randInt(0, 10000); //for local testing //var scriptURL = "http://localhost:8080/wand.js?" + randInt(0, 10000); diff --git a/examples/toys/bubblewand/wand.js b/examples/toys/bubblewand/wand.js index 87bdfc6648..020fba9b15 100644 --- a/examples/toys/bubblewand/wand.js +++ b/examples/toys/bubblewand/wand.js @@ -27,7 +27,7 @@ function convertRange(value, r1, r2) { var bubbleModel = "http://hifi-public.s3.amazonaws.com/james/bubblewand/models/bubble/bubble.fbx"; var popSound = SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop.wav"); - var bubbleScript = 'http://hifi-public.s3.amazonaws.com/scripts/toys/bubblewand/bubble.js?' + randInt(1, 10000); + var bubbleScript = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/scripts/bubble.js?' + randInt(1, 10000); // var bubbleScript = 'http://localhost:8080/bubble.js?' + randInt(1, 10000); //for local testing @@ -306,19 +306,6 @@ function convertRange(value, r1, r2) { }); }, - checkForEntitiesNearBubble: function() { - var _t = this; - var arrayFound = Entities.findEntities(_t.wandTipPosition, 1); - var foundLength = arrayFound.length; - print('found length:::' + foundLength); - }, - enableCollisionsForBubble: function(bubble) { - print('enable bubble collisions:' + bubble) - Entities.editEntity(bubble, { - collisionsWillMove: true, - ignoreForCollisions: false, - }) - }, spawnBubble: function() { var _t = this; //create a new bubble at the tip of the wand From 37f45b57ff19acd8ddfde71498b411c3c373d041 Mon Sep 17 00:00:00 2001 From: James Pollack Date: Tue, 15 Sep 2015 18:40:54 -0700 Subject: [PATCH 10/10] wand updates --- examples/toys/bubblewand/bubble.js | 7 ++- examples/toys/bubblewand/createWand.js | 10 +++-- examples/toys/bubblewand/wand.js | 60 +++++++++++++++++++------- 3 files changed, 54 insertions(+), 23 deletions(-) diff --git a/examples/toys/bubblewand/bubble.js b/examples/toys/bubblewand/bubble.js index eaabf98e44..748c946119 100644 --- a/examples/toys/bubblewand/bubble.js +++ b/examples/toys/bubblewand/bubble.js @@ -15,12 +15,11 @@ // Script.include("../../utilities.js"); // Script.include("../../libraries/utils.js"); - - Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/utilities.js"); - Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/libraries/utils.js"); +Script.include("http://hifi-public.s3.amazonaws.com/scripts/utilities.js"); +Script.include("http://hifi-public.s3.amazonaws.com/scripts/libraries/utils.js"); var POP_SOUNDS = [ - SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop0.wav"), + SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop0.wav") , SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop1.wav"), SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop2.wav"), SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop3.wav") diff --git a/examples/toys/bubblewand/createWand.js b/examples/toys/bubblewand/createWand.js index 158bcb3b99..49481b6c1a 100644 --- a/examples/toys/bubblewand/createWand.js +++ b/examples/toys/bubblewand/createWand.js @@ -13,8 +13,8 @@ // Script.include("../../utilities.js"); // Script.include("../../libraries/utils.js"); -Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/utilities.js"); -Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/libraries/utils.js"); +Script.include("http://hifi-public.s3.amazonaws.com/scripts/utilities.js"); +Script.include("http://hifi-public.s3.amazonaws.com/scripts/libraries/utils.js"); var wandModel = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/wand.fbx'; var wandCollisionShape = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/collisionHull.obj'; @@ -25,7 +25,11 @@ var scriptURL = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/scripts/wa //create the wand in front of the avatar var center = Vec3.sum(MyAvatar.position, Vec3.multiply(1, Quat.getFront(Camera.getOrientation()))); - +var tablePosition = { + x:546.48, + y:495.63, + z:506.25 +} var wand = Entities.addEntity({ type: "Model", modelURL: wandModel, diff --git a/examples/toys/bubblewand/wand.js b/examples/toys/bubblewand/wand.js index 020fba9b15..afee5fab0c 100644 --- a/examples/toys/bubblewand/wand.js +++ b/examples/toys/bubblewand/wand.js @@ -11,22 +11,21 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +'use strict' function convertRange(value, r1, r2) { return (value - r1[0]) * (r2[1] - r2[0]) / (r1[1] - r1[0]) + r2[0]; } (function() { - Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/utilities.js"); - Script.include("https://raw.githubusercontent.com/highfidelity/hifi/master/examples/libraries/utils.js"); - + Script.include("http://hifi-public.s3.amazonaws.com/scripts/utilities.js"); + Script.include("http://hifi-public.s3.amazonaws.com/scripts/libraries/utils.js"); // Script.include("../../utilities.js"); // Script.include("../../libraries/utils.js"); var bubbleModel = "http://hifi-public.s3.amazonaws.com/james/bubblewand/models/bubble/bubble.fbx"; - var popSound = SoundCache.getSound("http://hifi-public.s3.amazonaws.com/james/bubblewand/sounds/pop.wav"); var bubbleScript = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/scripts/bubble.js?' + randInt(1, 10000); // var bubbleScript = 'http://localhost:8080/bubble.js?' + randInt(1, 10000); //for local testing @@ -118,7 +117,7 @@ function convertRange(value, r1, r2) { var BUBBLE_GRAVITY = { x: 0, - y: -0.05, + y: -0.1, z: 0 } @@ -135,8 +134,8 @@ function convertRange(value, r1, r2) { this.entityID = entityID; this.properties = Entities.getEntityProperties(this.entityID); BubbleWand.originalProperties = this.properties; - print('rotation???' + JSON.stringify(BubbleWand.originalProperties.rotation)); - + BubbleWand.init(); + print('initial position' + JSON.stringify(BubbleWand.originalProperties.position)); } this.unload = function(entityID) { @@ -161,8 +160,9 @@ function convertRange(value, r1, r2) { var BubbleWand = { bubbles: [], timeSinceMoved: 0, - resetAtTime: 5, + resetAtTime: 2, currentBubble: null, + atOriginalLocation: true, update: function(dt) { BubbleWand.internalUpdate(dt); }, @@ -176,8 +176,9 @@ function convertRange(value, r1, r2) { var hitTargetWithWand = findSphereSphereHit(wandPosition, HAND_SIZE / 2, getGustDetectorPosition(), TARGET_SIZE / 2) var velocity = Vec3.subtract(wandPosition, _t.lastPosition) - var velocityStrength = Vec3.length(velocity) * 100; + // print('VELOCITY:'+JSON.stringify(velocity)) + var velocityStrength = Vec3.length(velocity) * 100; var upVector = Quat.getUp(properties.rotation); var frontVector = Quat.getFront(properties.rotation); @@ -194,17 +195,43 @@ function convertRange(value, r1, r2) { } //print('velocityStrength'+velocityStrength) + //we want to reset the object to its original position if its been a while since it has moved + // print('wand position ' + JSON.stringify(wandPosition)) + // print('last position ' + JSON.stringify(_t.lastPosition)) + // print('at original location? ' + _t.atOriginalLocation) + + if (velocityStrength < 0.01) { + velocityStrength = 0 + } + var isMoving; if (velocityStrength === 0) { + isMoving = false; + } else { + isMoving = true; + } + + + if (isMoving === true) { + // print('MOVING') + // print('velocityStrength ' + velocityStrength) + + _t.timeSinceMoved = 0; + _t.atOriginalLocation = false; + } else { _t.timeSinceMoved = _t.timeSinceMoved + dt; + } + + if (isMoving === false && _t.atOriginalLocation === false) { if (_t.timeSinceMoved > _t.resetAtTime) { _t.timeSinceMoved = 0; _t.returnToOriginalLocation(); + } - } else { - _t.timeSinceMoved = 0; } + + //debug overlays for mouth mode if (overlays) { var leftHandPos = MyAvatar.getLeftPalmPosition(); @@ -239,8 +266,7 @@ function convertRange(value, r1, r2) { //store the last position of the wand for velocity calculations _t.lastPosition = wandPosition; - // velocity numbers are pretty small, so lets make them a bit bigger - var velocityStrength = Vec3.length(velocity) * 100; + if (velocityStrength > 10) { velocityStrength = 10 @@ -320,7 +346,7 @@ function convertRange(value, r1, r2) { _t.wandTipPosition = wandTipPosition; //store the position of the tip on spawn for use in velocity calculations - _t.lastPosition = wandTipPosition; + _t.lastPosition = wandPosition; //create a bubble at the wand tip _t.currentBubble = Entities.addEntity({ @@ -340,14 +366,16 @@ function convertRange(value, r1, r2) { script: bubbleScript, }); + //print('spawnbubble position' + JSON.stringify(wandTipPosition)); + //add this bubble to an array of bubbles so we can keep track of them _t.bubbles.push(_t.currentBubble) }, returnToOriginalLocation: function() { var _t = this; + _t.atOriginalLocation = true; Script.update.disconnect(BubbleWand.update) - _t.currentBubble = null; Entities.deleteEntity(_t.currentBubble); Entities.editEntity(wandEntity.entityID, _t.originalProperties) _t.spawnBubble(); @@ -362,6 +390,6 @@ function convertRange(value, r1, r2) { } } - BubbleWand.init(); + }) \ No newline at end of file