Return wand to its original position if it hasnt moved for 5 seconds, better particles, wand scaled to human size

This commit is contained in:
James Pollack 2015-09-10 16:58:39 -07:00
parent ee7e25a137
commit 387e7b74a9
3 changed files with 86 additions and 39 deletions

View file

@ -12,8 +12,12 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
(function() { (function() {
Script.include("../../utilities.js"); // Script.include("../../utilities.js");
Script.include("../../libraries/utils.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 = [ 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"),
@ -69,7 +73,7 @@
Script.update.disconnect(this.internalUpdate); Script.update.disconnect(this.internalUpdate);
var position = properties.position; var position = properties.position;
_t.endOfBubble(position); _t.endOfBubble(position);
print('UNLOAD PROPS' + JSON.stringify(position)); // print('UNLOAD PROPS' + JSON.stringify(position));
}; };
@ -107,7 +111,7 @@
animationSettings: animationSettings, animationSettings: animationSettings,
animationIsPlaying: true, animationIsPlaying: true,
position: position, position: position,
lifetime: 1.0, lifetime: 0.2,
dimensions: { dimensions: {
x: 1, x: 1,
y: 1, y: 1,
@ -115,22 +119,25 @@
}, },
emitVelocity: { emitVelocity: {
x: 0, x: 0,
y: -1, y: 0,
z: 0 z: 0
}, },
velocitySpread: { velocitySpread: {
x: 1, x: 0.45,
y: 0, y: 0.45,
z: 1 z: 0.45
}, },
emitAcceleration: { emitAcceleration: {
x: 0, x: 0,
y: -1, y: -0.1,
z: 0 z: 0
}, },
alphaStart: 1.0,
alpha: 1,
alphaFinish: 0.0,
textures: "https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png", textures: "https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png",
color: BUBBLE_PARTICLE_COLOR, color: BUBBLE_PARTICLE_COLOR,
lifespan: 1.0, lifespan: 0.2,
visible: true, visible: true,
locked: false locked: false
}); });

View file

@ -10,30 +10,32 @@
Script.include("../../utilities.js"); // Script.include("../../utilities.js");
Script.include("../../libraries/utils.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 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 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 //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 //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({ var wand = Entities.addEntity({
type: "Model", type: "Model",
modelURL: wandModel, modelURL: wandModel,
position: center, position: center,
dimensions: { dimensions: {
x: 0.1, x: 0.05,
y: 1, y: 0.5,
z: 0.1 z: 0.05
}, },
//must be enabled to be grabbable in the physics engine //must be enabled to be grabbable in the physics engine
collisionsWillMove: true, collisionsWillMove: true,
compoundShapeURL: wandCollisionShape, compoundShapeURL: wandCollisionShape,
script: scriptURL script: scriptURL

View file

@ -16,13 +16,20 @@ function convertRange(value, r1, r2) {
} }
(function() { (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 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 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/scripts/toys/bubblewand/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); //for local testing
var POP_SOUNDS = [ 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"),
@ -127,6 +134,9 @@ function convertRange(value, r1, r2) {
// print('PRELOAD') // print('PRELOAD')
this.entityID = entityID; this.entityID = entityID;
this.properties = Entities.getEntityProperties(this.entityID); this.properties = Entities.getEntityProperties(this.entityID);
BubbleWand.originalProperties = this.properties;
print('rotation???' + JSON.stringify(BubbleWand.originalProperties.rotation));
} }
this.unload = function(entityID) { this.unload = function(entityID) {
@ -150,11 +160,14 @@ function convertRange(value, r1, r2) {
var BubbleWand = { var BubbleWand = {
bubbles: [], bubbles: [],
timeSinceMoved: 0,
resetAtTime: 5,
currentBubble: null, currentBubble: null,
update: function() { update: function(dt) {
BubbleWand.internalUpdate(); BubbleWand.internalUpdate(dt);
}, },
internalUpdate: function() { internalUpdate: function(dt) {
var _t = this; var _t = this;
//get the current position of the wand //get the current position of the wand
var properties = Entities.getEntityProperties(wandEntity.entityID); 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 //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 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 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; var mouthMode;
if (hitTargetWithWand) { if (hitTargetWithWand) {
@ -172,8 +192,18 @@ function convertRange(value, r1, r2) {
} else { } else {
mouthMode = false; 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 //debug overlays for mouth mode
if (overlays) { if (overlays) {
@ -225,7 +255,7 @@ function convertRange(value, r1, r2) {
//add some variation in bubble sizes //add some variation in bubble sizes
var bubbleSize = randInt(1, 5); var bubbleSize = randInt(1, 5);
bubbleSize = bubbleSize / 10; bubbleSize = bubbleSize / 50;
//release the bubble if its dimensions are bigger than the bubble size //release the bubble if its dimensions are bigger than the bubble size
if (dimensions.x > bubbleSize) { if (dimensions.x > bubbleSize) {
@ -249,14 +279,14 @@ function convertRange(value, r1, r2) {
return return
} else { } else {
if (mouthMode) { if (mouthMode) {
dimensions.x += 0.015 * convertedVolume; dimensions.x += 0.005 * convertedVolume;
dimensions.y += 0.015 * convertedVolume; dimensions.y += 0.005 * convertedVolume;
dimensions.z += 0.015 * convertedVolume; dimensions.z += 0.005 * convertedVolume;
} else { } else {
dimensions.x += 0.015 * velocityStrength; dimensions.x += 0.005 * velocityStrength;
dimensions.y += 0.015 * velocityStrength; dimensions.y += 0.005 * velocityStrength;
dimensions.z += 0.015 * velocityStrength; dimensions.z += 0.005 * velocityStrength;
} }
} }
@ -298,10 +328,7 @@ function convertRange(value, r1, r2) {
var wandPosition = properties.position; var wandPosition = properties.position;
var upVector = Quat.getUp(properties.rotation); var upVector = Quat.getUp(properties.rotation);
var frontVector = Quat.getFront(properties.rotation); var frontVector = Quat.getFront(properties.rotation);
var upOffset = Vec3.multiply(upVector, 0.4); var upOffset = Vec3.multiply(upVector, 0.2);
// 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); var wandTipPosition = Vec3.sum(wandPosition, upOffset);
_t.wandTipPosition = wandTipPosition; _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 //add this bubble to an array of bubbles so we can keep track of them
_t.bubbles.push(_t.currentBubble) _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() { init: function() {
var _t = this;
this.spawnBubble(); this.spawnBubble();
Script.update.connect(BubbleWand.update); Script.update.connect(BubbleWand.update);