diff --git a/examples/toys/bubblewand/bubble.js b/examples/toys/bubblewand/bubble.js index ebb5a36d2d..b52f0d326a 100644 --- a/examples/toys/bubblewand/bubble.js +++ b/examples/toys/bubblewand/bubble.js @@ -18,12 +18,6 @@ var BUBBLE_USER_DATA_KEY = "BubbleKey"; - BUBBLE_PARTICLE_COLOR = { - red: 0, - green: 40, - blue: 255, - }; - var _this = this; var properties; @@ -41,18 +35,28 @@ properties = tmpProperties; } + // var defaultBubbleData={ + // avatarID:'noAvatar' + // } + + var entityData = getEntityCustomData(BUBBLE_USER_DATA_KEY, _this.entityID); + + if (entityData && entityData.avatarID && entityData.avatarID === MyAvatar.sessionUUID) { + _this.bubbleCreator = true + + } + + + }; this.unload = function(entityID) { Script.update.disconnect(this.update); - var defaultGrabData = { - avatarId: null - }; + print('bubble unload') - var bubbleCreator = getEntityCustomData(BUBBLE_USER_DATA_KEY, entityID, defaultGrabData); - - if (bubbleCreator === MyAvatar.sessionUUID) { + if (this.bubbleCreator) { + print('PLAYING BURST') this.createBurstParticles(); } @@ -77,36 +81,36 @@ var particleBurst = Entities.addEntity({ type: "ParticleEffect", animationSettings: animationSettings, + emitRate: 100, animationIsPlaying: true, position: position, - lifetime: 0.1, + lifespan: 1, dimensions: { x: 1, y: 1, z: 1 }, emitVelocity: { - x: 0.35, - y: 0.35, - z: 0.35 + x: 1, + y: 1, + z: 1 }, velocitySpread: { - x: 0.45, - y: 0.45, - z: 0.45 + x: 1, + y: 1, + z: 1 }, emitAcceleration: { - x: 0, - y: -0.1, - z: 0 + x: 0.25, + y: 0.25, + z: 0.25 }, - particleRadius: 0.1, - alphaStart: 0.5, + radiusSpread: 0.01, + particleRadius: 0.02, + alphaStart: 1.0, alpha: 0.5, alphaFinish: 0, textures: BUBBLE_PARTICLE_TEXTURE, - // color: BUBBLE_PARTICLE_COLOR, - lifespan: 0.1, visible: true, locked: false }); diff --git a/examples/toys/bubblewand/createWand.js b/examples/toys/bubblewand/createWand.js index 37041fdbf6..a50b7185f6 100644 --- a/examples/toys/bubblewand/createWand.js +++ b/examples/toys/bubblewand/createWand.js @@ -4,20 +4,20 @@ // Script Type: Entity Spawner // Created by James B. Pollack @imgntn -- 09/03/2015 // Copyright 2015 High Fidelity, Inc. -// +// // 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 var IN_TOYBOX = false; -Script.include("../../utilities.js"); +Script.include("../../utilities.js"); Script.include("../../libraries/utils.js"); var WAND_MODEL = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/wand.fbx'; var WAND_COLLISION_SHAPE = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/collisionHull.obj'; -var WAND_SCRIPT_URL = Script.resolvePath("wand.js"); +var WAND_SCRIPT_URL = Script.resolvePath("wand.js?"+randInt(0,500)); //create the wand in front of the avatar blahy var center = Vec3.sum(Vec3.sum(MyAvatar.position, {x: 0, y: 0.5, z: 0}), Vec3.multiply(0.5, Quat.getFront(Camera.getOrientation()))); @@ -26,7 +26,7 @@ var tablePosition = { y:495.63, z:506.25 } -print('test refresh') + var wand = Entities.addEntity({ name:'Bubble Wand', type: "Model", @@ -39,9 +39,9 @@ var wand = Entities.addEntity({ z: 0, }, dimensions: { - x: 0.025, - y: 0.125, - z: 0.025 + x: 0.05, + y: 0.25, + z: 0.05 }, //must be enabled to be grabbable in the physics engine collisionsWillMove: true, diff --git a/examples/toys/bubblewand/wand.js b/examples/toys/bubblewand/wand.js index 0e960f1f64..3d574d89ca 100644 --- a/examples/toys/bubblewand/wand.js +++ b/examples/toys/bubblewand/wand.js @@ -17,8 +17,8 @@ Script.include("../../libraries/utils.js"); var BUBBLE_MODEL = "http://hifi-public.s3.amazonaws.com/james/bubblewand/models/bubble/bubble.fbx"; - var BUBBLE_SCRIPT = Script.resolvePath('bubble.js?' + randInt(0, 10000)); - + var BUBBLE_SCRIPT = Script.resolvePath('bubble.js'); +//test var BUBBLE_USER_DATA_KEY = "BubbleKey"; var BUBBLE_INITIAL_DIMENSIONS = { x: 0.01, @@ -35,7 +35,7 @@ var GROWTH_FACTOR = 0.005; var SHRINK_FACTOR = 0.001; var SHRINK_LOWER_LIMIT = 0.02; - var WAND_TIP_OFFSET = 0.05; + var WAND_TIP_OFFSET = 0.095; var VELOCITY_STRENGTH_LOWER_LIMIT = 0.01; var VELOCITY_STRENGH_MAX = 10; var VELOCITY_THRESHOLD = 0.5; @@ -58,17 +58,19 @@ Script.update.disconnect(this.update); }, update: function(deltaTime) { + print('BW update') var GRAB_USER_DATA_KEY = "grabKey"; var defaultGrabData = { activated: false, avatarId: null }; var grabData = getEntityCustomData(GRAB_USER_DATA_KEY, _this.entityID, defaultGrabData); + print('grabData'+JSON.stringify(grabData)) if (grabData.activated && grabData.avatarId === MyAvatar.sessionUUID) { // remember we're being grabbed so we can detect being released _this.beingGrabbed = true; - + print('being grabbed') //the first time we want to make a bubble if (_this.currentBubble === null) { _this.createBubbleAtTipOfWand(); @@ -87,9 +89,8 @@ }); } else if (_this.beingGrabbed) { - // if we are not being grabbed, and we previously were, then we were just released, remember that - + print('let go') _this.beingGrabbed = false; //remove the current bubble when the wand is released @@ -97,6 +98,7 @@ _this.currentBubble = null return } + print('not grabbed') }, getWandTipPosition: function(properties) { @@ -129,6 +131,7 @@ return gravity }, growBubbleWithWandVelocity: function(properties, deltaTime) { + print('grow bubble') var wandPosition = properties.position; var wandTipPosition = this.getWandTipPosition(properties) @@ -138,8 +141,7 @@ var velocityStrength = Vec3.length(velocity); - print('velocityStrength' + velocityStrength) - + velocityStrength = velocityStrength; // if (velocityStrength < VELOCITY_STRENGTH_LOWER_LIMIT) { // velocityStrength = 0 // } @@ -155,13 +157,15 @@ var dimensions = Entities.getEntityProperties(this.currentBubble).dimensions; if (velocityStrength > VELOCITY_THRESHOLD) { - + print('velocity over threshold') //add some variation in bubble sizes var bubbleSize = randInt(BUBBLE_SIZE_MIN, BUBBLE_SIZE_MAX); bubbleSize = bubbleSize / BUBBLE_DIVISOR; //release the bubble if its dimensions are bigger than the bubble size if (dimensions.x > bubbleSize) { + + print('release the bubble') //bubbles pop after existing for a bit -- so set a random lifetime var lifetime = randInt(BUBBLE_LIFETIME_MIN, BUBBLE_LIFETIME_MAX); @@ -174,9 +178,9 @@ //wait to make the bubbles collidable, so that they dont hit each other and the wand Script.setTimeout(this.addCollisionsToBubbleAfterCreation(this.currentBubble), lifetime / 2); + this.setBubbleOwner(this.currentBubble); //release the bubble -- when we create a new bubble, it will carry on and this update loop will affect the new bubble this.createBubbleAtTipOfWand(); - return } else { @@ -202,8 +206,9 @@ }); }, setBubbleOwner: function(bubble) { + print('SET BUBBLE OWNER', bubble) setEntityCustomData(BUBBLE_USER_DATA_KEY, bubble, { - avatarID: MyAvatar.sessionUUID + avatarID: MyAvatar.sessionUUID, }); }, createBubbleAtTipOfWand: function() {