bubbles etc

This commit is contained in:
James B. Pollack 2016-02-29 16:21:43 -08:00
parent e152f74cae
commit c05849714b
3 changed files with 223 additions and 21 deletions

View file

@ -0,0 +1,47 @@
{
"color": {},
"isEmitting": 1,
"maxParticles": 1880,
"lifespan": 1.6,
"emitRate": 10,
"emitSpeed": 0.025,
"speedSpread": 0.025,
"emitOrientation": {
"x": 0,
"y": 0.5,
"z": 0.5,
"w": 0
},
"emitDimensions": {
"x": -0.2,
"y": 1.2000000000000002,
"z": 0
},
"polarStart": 0,
"polarFinish": 0,
"azimuthStart": 0.2,
"azimuthFinish": 0.1,
"emitAcceleration": {
"x": 0,
"y": 0.4,
"z": 0
},
"accelerationSpread": {
"x": 0.1,
"y": 0.1,
"z": 0.1
},
"particleRadius": 0.02,
"radiusSpread": 0,
"radiusStart": 0.043,
"radiusFinish": 0.02,
"colorSpread": {},
"colorStart": {},
"colorFinish": {},
"alpha": 0.2,
"alphaSpread": 0,
"alphaStart": 0.3,
"alphaFinish": 0,
"emitterShouldTrail": 0,
"textures": "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/bubble-white.png"
}

View file

@ -1,4 +1,4 @@
var fishtank;
var fishtank, bubbleSystem, bubbleSound;
var TANK_DIMENSIONS = {
x: 1.3393,
@ -23,11 +23,18 @@ var TANK_SCRIPT = Script.resolvePath('tank.js?' + Math.random())
var TANK_MODEL_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/aquarium-6.fbx";
var BUBBLE_SYSTEM_FORWARD_OFFSET = 0.2;
var BUBBLE_SYSTEM_LATERAL_OFFSET = 0.2;
var BUBBLE_SYSTEM_VERTICAL_OFFSET = -0.2;
var BUBBLE_SOUND_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/Sounds/aquarium_small.L.wav";
var bubbleSound = SoundCache.getSound(BUBBLE_SOUND_URL);
function createFishTank() {
var tankProperties = {
name: 'hifi-home-fishtank',
type: 'Model',
modelURL:TANK_MODEL_URL,
modelURL: TANK_MODEL_URL,
dimensions: TANK_DIMENSIONS,
position: TANK_POSITION,
color: DEBUG_COLOR,
@ -35,22 +42,127 @@ function createFishTank() {
script: TANK_SCRIPT,
userData: JSON.stringify({
'hifi-home-fishtank': {
fishLoaded: false
fishLoaded: false,
bubbleSystem: null,
bubbleSound: null,
attractors: null,
},
grabbableKey: {
grabbable: false
}
}),
visible:true
visible: true
}
fishTank = Entities.addEntity(tankProperties);
}
function createBubbleSystem() {
var tankProperties = Entities.getEntityProperties(fishTank);
var bubbleProperties = {
"color": {},
"isEmitting": 1,
"maxParticles": 1880,
"lifespan": 1.6,
"emitRate": 10,
"emitSpeed": 0.025,
"speedSpread": 0.025,
"emitOrientation": {
"x": 0,
"y": 0.5,
"z": 0.5,
"w": 0
},
"emitDimensions": {
"x": -0.2,
"y": 1.2000000000000002,
"z": 0
},
"polarStart": 0,
"polarFinish": 0,
"azimuthStart": 0.2,
"azimuthFinish": 0.1,
"emitAcceleration": {
"x": 0,
"y": 0.4,
"z": 0
},
"accelerationSpread": {
"x": 0.1,
"y": 0.1,
"z": 0.1
},
"particleRadius": 0.02,
"radiusSpread": 0,
"radiusStart": 0.043,
"radiusFinish": 0.02,
"colorSpread": {},
"colorStart": {},
"colorFinish": {},
"alpha": 0.2,
"alphaSpread": 0,
"alphaStart": 0.3,
"alphaFinish": 0,
"emitterShouldTrail": 0,
"textures": "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/bubble-white.png"
};
bubbleProperties.type = "ParticleEffect";
bubbleProperties.collisionless = true;
var upVector = Quat.getRight(tankProperties.rotation);
var frontVector = Quat.getRight(tankProperties.rotation);
var rightVector = Quat.getRight(tankProperties.rotation);
var upOffset = Vec3.multiply(upVector, BUBBLE_SYSTEM_VERTICAL_OFFSET);
var frontOffset = Vec3.multiply(frontVector, BUBBLE_SYSTEM_FORWARD_OFFSET);
var rightOffset = Vec3.multiply(rightVector, BUBBLE_SYSTEM_LATERAL_OFFSET);
var finalOffset = Vec3.sum(center, upOffset);
finalOffset = Vec3.sum(finalOffset, frontOffset);
finalOffset = Vec3.sum(finalOffset, rightOffset);
bubbleProperties.position = finalOffset;
bubbleSystem = Entities.addEntity(bubbleProperties);
}
function createBubbleSound() {
var bubbleSystemProperties = Entities.getEntityProperties(bubbleSystem);
var audioProperties = {
volume: 0.2,
position: position
};
Audio.playSound(bubbleSound, audioProperties);
}
function cleanup() {
Entities.deleteEntity(fishTank);
}
createFishTank();
// createBubbleSystem();
// createBubbleSound();
// createAttractors();
var attractors = []
//@position,radius,strength
function createAttractor(position, radius, strength) {
return {
position: position,
radius: radius,
strength: strength
};
}
Script.scriptEnding.connect(cleanup);

View file

@ -80,8 +80,8 @@
}
})
print('fish? ' + fish.length)
return fish;
print('fish? ' + fishList.length)
return fishList;
},
initialize: function(entityID) {
@ -135,13 +135,56 @@
},
update: function() {
print('AM I THE OWNER??' + iOwn);
//print('AM I THE OWNER??' + iOwn);
if (iOwn === false) {
return
}
//print('i am the owner!')
//do stuff
print('i am the owner!')
//do stuff
updateFish();
},
debugLookSpot: null,
createDebugLookAtCube: function() {
var cubePosition = {
x: 0,
y: 0,
z: 0
};
var cubeSize = 0.03;
_this.debugLookAtCube = Overlays.addOverlay("cube", {
position: cubePosition,
size: cubeSize,
color: {
red: 0,
green: 255,
blue: 0
},
alpha: 1,
solid: false
});
},
updateDebugLookAtCube: function() {
var lookAt3D = HMD.getHUDLookAtPosition3D();
_this.lookAt3D = lookAt3D;
Overlays.editOverlay(_this.debugLookAtCube, {
position: lookAt3D
});
},
seeIfOwnerIsLookingAtTheTank: function(origin,direction) {
// var cameraPosition = Camera.getPosition();
// var cameraOrientation = Camera.getOrientation();
var pickRay = {
origin: origin,
direction: direction
};
var intersection = Entities.findRayIntersection(pickRay, true, [_this.entityID], [])
if (intersection.intersects && intersection.entityID = _this.entityID) {
print('looking at the tank!! ' + JSON.stringify(intersection.intersection));
var intersectionDistance = Vec3.distance(pickRay.origin, intersection.intersection);
}
}
};
@ -160,24 +203,24 @@
var FISHTANK_USERDATA_KEY = 'hifi-home-fishtank'
var LIFETIME = 300; // Fish live for 5 minutes
var NUM_FISH = 20;
var NUM_FISH = 8;
var TANK_DIMENSIONS = {
x: 1.3393,
y: 1.3515,
z: 3.5914
};
var TANK_WIDTH = TANK_DIMENSIONS.z;
var TANK_HEIGHT = TANK_DIMENSIONS.y;
var TANK_WIDTH = TANK_DIMENSIONS.z / 3;
var TANK_HEIGHT = TANK_DIMENSIONS.y / 3;
var FISH_WIDTH = 0.03;
var FISH_LENGTH = 0.15;
var MAX_SIGHT_DISTANCE = 0.8;
var MIN_SEPARATION = 0.15;
var AVOIDANCE_FORCE = 0.2;
var COHESION_FORCE = 0.05;
var ALIGNMENT_FORCE = 0.05;
var AVOIDANCE_FORCE = 0.3;
var COHESION_FORCE = 0.025;
var ALIGNMENT_FORCE = 0.025;
var SWIMMING_FORCE = 0.05;
var SWIMMING_SPEED = 1.5;
var SWIMMING_SPEED = 0.5;
var THROTTLE = false;
var THROTTLE_RATE = 100;
@ -403,14 +446,14 @@
var center = _this.currentProperties.position;
lowerCorner = {
x: center.x - (TANK_WIDTH / 2),
x: center.x - (_this.currentProperties.dimensions.z / 2),
y: center.y,
z: center.z - (TANK_WIDTH / 2)
z: center.z - (_this.currentProperties.dimensions.z / 2)
};
upperCorner = {
x: center.x + (TANK_WIDTH / 2),
y: center.y + TANK_HEIGHT,
z: center.z + (TANK_WIDTH / 2)
x: center.x + (_this.currentProperties.dimensions.z / 2),
y: center.y + _this.currentProperties.dimensions.y,
z: center.z + (_this.currentProperties.dimensions.z / 2)
};
var fish = [];