mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 19:59:28 +02:00
new particle effect, first pass
This commit is contained in:
parent
c425c32b8f
commit
81cb63df6b
1 changed files with 57 additions and 64 deletions
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
const version = 0.1;
|
const version = 0.1;
|
||||||
const label = "makeUserConnection";
|
const label = "makeUserConnection";
|
||||||
const MAX_AVATAR_DISTANCE = 1.25;
|
const MAX_AVATAR_DISTANCE = 0.5;
|
||||||
const GRIP_MIN = 0.05;
|
const GRIP_MIN = 0.05;
|
||||||
const MESSAGE_CHANNEL = "io.highfidelity.makeUserConnection";
|
const MESSAGE_CHANNEL = "io.highfidelity.makeUserConnection";
|
||||||
const STATES = {
|
const STATES = {
|
||||||
|
@ -30,6 +30,8 @@ const FRIENDING_TIME = 2000; // ms
|
||||||
const FRIENDING_HAPTIC_STRENGTH = 0.5;
|
const FRIENDING_HAPTIC_STRENGTH = 0.5;
|
||||||
const FRIENDING_SUCCESS_HAPTIC_STRENGTH = 1.0;
|
const FRIENDING_SUCCESS_HAPTIC_STRENGTH = 1.0;
|
||||||
const HAPTIC_DURATION = 20;
|
const HAPTIC_DURATION = 20;
|
||||||
|
const PARTICLE_RADIUS = 0.2;
|
||||||
|
const PARTICLE_ANGLE_INCREMENT = 360/45;
|
||||||
const MODEL_URL = "http://hifi-content.s3.amazonaws.com/alan/dev/Test/sphere-3-color.fbx";
|
const MODEL_URL = "http://hifi-content.s3.amazonaws.com/alan/dev/Test/sphere-3-color.fbx";
|
||||||
const TEXTURES = [
|
const TEXTURES = [
|
||||||
{"Texture": "http://hifi-content.s3.amazonaws.com/alan/dev/Test/sphere-3-color.fbx/sphere-3-color.fbm/green-50pct-opaque-64.png"},
|
{"Texture": "http://hifi-content.s3.amazonaws.com/alan/dev/Test/sphere-3-color.fbx/sphere-3-color.fbm/green-50pct-opaque-64.png"},
|
||||||
|
@ -37,44 +39,29 @@ const TEXTURES = [
|
||||||
{"Texture": "http://hifi-content.s3.amazonaws.com/alan/dev/Test/sphere-3-color.fbx/sphere-3-color.fbm/red-50pct-opaque-64.png"}
|
{"Texture": "http://hifi-content.s3.amazonaws.com/alan/dev/Test/sphere-3-color.fbx/sphere-3-color.fbm/red-50pct-opaque-64.png"}
|
||||||
];
|
];
|
||||||
const PARTICLE_EFFECT_PROPS = {
|
const PARTICLE_EFFECT_PROPS = {
|
||||||
"color": {
|
"alpha": 0.8,
|
||||||
"blue": 0,
|
"azimuthFinish": Math.PI,
|
||||||
"green": 104,
|
"azimuthStart": -1*Math.PI,
|
||||||
"red": 0
|
"emitRate": 220,
|
||||||
},
|
"emitSpeed": 0.0,
|
||||||
"colorFinish": {
|
|
||||||
"blue": 172,
|
|
||||||
"green": 75,
|
|
||||||
"red": 255
|
|
||||||
},
|
|
||||||
"colorStart": {
|
|
||||||
"blue": 0,
|
|
||||||
"green": 104,
|
|
||||||
"red": 255
|
|
||||||
},
|
|
||||||
"dimensions": {
|
|
||||||
"x": 0.03,
|
|
||||||
"y": 0.03,
|
|
||||||
"z": 0.03
|
|
||||||
},
|
|
||||||
"emitOrientation": {
|
|
||||||
"w": 0.707,
|
|
||||||
"x": -0.707,
|
|
||||||
"y": 0.0,
|
|
||||||
"z": 0.0
|
|
||||||
},
|
|
||||||
"emitRate": 100,
|
|
||||||
"emitSpeed": 0.001,//0.0003,
|
|
||||||
"emitterShouldTrail": 1,
|
"emitterShouldTrail": 1,
|
||||||
"maxParticles": 25,
|
"isEmitting": 1,
|
||||||
"polarStart" : -Math.PI/2,
|
"lifespan": 3,
|
||||||
"polarFinish": Math.PI/2,
|
"maxParticles": 1000,
|
||||||
"radiusSpread": 9,
|
"particleRadius": 0.003,
|
||||||
"radiusStart": 0.04,
|
"polarStart": 1,
|
||||||
"radiusFinish": 0.02,
|
"polarFinish": 1,
|
||||||
"speedSpread": 0.09,
|
"radiusFinish": 0.006,
|
||||||
"lifespan": 3.0,
|
"radiusStart": 0.001,
|
||||||
|
"speedSpread": 0.025,
|
||||||
"textures": "http://hifi-content.s3.amazonaws.com/alan/dev/Particles/Bokeh-Particle.png",
|
"textures": "http://hifi-content.s3.amazonaws.com/alan/dev/Particles/Bokeh-Particle.png",
|
||||||
|
"color": {"red": 255, "green": 255, "blue": 255},
|
||||||
|
"colorFinish": {"red": 0, "green": 164, "blue": 255},
|
||||||
|
"colorStart": {"red": 255, "green": 255, "blue": 255},
|
||||||
|
"emitOrientation": {"w": -0.71, "x":0.0, "y":0.0, "z": 0.71},
|
||||||
|
"emitAcceleration": {"x": 0.0, "y": 0.0, "z": 0.0},
|
||||||
|
"accelerationSpread": {"x": 0.0, "y": 0.0, "z": 0.0},
|
||||||
|
"dimensions": {"x":0.05, "y": 0.05, "z": 0.05},
|
||||||
"type": "ParticleEffect"
|
"type": "ParticleEffect"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -179,47 +166,49 @@ function positionFractionallyTowards(posA, posB, frac) {
|
||||||
return Vec3.sum(posA, Vec3.multiply(frac, Vec3.subtract(posB, posA)));
|
return Vec3.sum(posA, Vec3.multiply(frac, Vec3.subtract(posB, posA)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deleteOverlay() {
|
||||||
|
if (overlay) {
|
||||||
|
overlay = Overlays.deleteOverlay(overlay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteParticleEffect() {
|
||||||
|
if (particleEffect) {
|
||||||
|
particleEffect = Entities.deleteEntity(particleEffect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// this is called frequently, but usually does nothing
|
// this is called frequently, but usually does nothing
|
||||||
function updateVisualization() {
|
function updateVisualization() {
|
||||||
// after making friends, if you are still holding the grip lets transition
|
// after making friends, if you are still holding the grip lets transition
|
||||||
// back to waiting
|
// back to waiting
|
||||||
if (state == STATES.makingFriends && !friendingId) {
|
if (state == STATES.makingFriends && !friendingId) {
|
||||||
startHandshake();
|
startHandshake();
|
||||||
}
|
return;
|
||||||
if (state == STATES.friending) {
|
|
||||||
if (overlay) {
|
|
||||||
overlay = Overlays.deleteOverlay(overlay);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (particleEffect) {
|
|
||||||
particleEffect = Entities.deleteEntity(particleEffect);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (state == STATES.inactive) {
|
if (state == STATES.inactive) {
|
||||||
if (overlay) {
|
deleteOverlay();
|
||||||
overlay = Overlays.deleteOverlay(overlay);
|
deleteParticleEffect();
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var textures = TEXTURES[state-1];
|
var textures = TEXTURES[state-1];
|
||||||
var myHandPosition = getHandPosition(MyAvatar, currentHand);
|
var myHandPosition = getHandPosition(MyAvatar, currentHand);
|
||||||
var position = myHandPosition;
|
var position = myHandPosition;
|
||||||
|
var otherHand;
|
||||||
// TODO: make the size scale with avatar, up to
|
|
||||||
// the actual size of MAX_AVATAR_DISTANCE
|
|
||||||
var wrist = MyAvatar.getJointPosition(MyAvatar.getJointIndex(handToString(currentHand)));
|
|
||||||
var d = Vec3.distance(wrist, position);
|
|
||||||
if (friendingId) {
|
if (friendingId) {
|
||||||
// put the position between the 2 hands, if we have a friendingId
|
|
||||||
var other = AvatarList.getAvatar(friendingId);
|
var other = AvatarList.getAvatar(friendingId);
|
||||||
if (other) {
|
if (other) {
|
||||||
var otherHand = getHandPosition(other, stringToHand(friendingHand));
|
otherHand = getHandPosition(other, stringToHand(friendingHand));
|
||||||
position = positionFractionallyTowards(position, otherHand, 0.5);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// scale the dimensions of the waiting/makingFriends ball to hand, capping
|
||||||
|
// at MAX_AVATAR_DISTANCE if someone happens to be huge
|
||||||
|
var wrist = MyAvatar.getJointPosition(MyAvatar.getJointIndex(handToString(currentHand)));
|
||||||
|
var d = Math.min(MAX_AVATAR_DISTANCE, Vec3.distance(wrist, position));
|
||||||
if (state != STATES.friending) {
|
if (state != STATES.friending) {
|
||||||
var dimension = {x: d, y: d, z: d};
|
deleteParticleEffect();
|
||||||
|
var dimension = {x: d, y: d, z: d};
|
||||||
if (!overlay) {
|
if (!overlay) {
|
||||||
waitingBallScale = (state == STATES.waiting ? 1.0/32.0 : 1.0);
|
waitingBallScale = (state == STATES.waiting ? 1.0/32.0 : 1.0);
|
||||||
var props = {
|
var props = {
|
||||||
|
@ -232,18 +221,23 @@ function updateVisualization() {
|
||||||
} else {
|
} else {
|
||||||
waitingBallScale = Math.min(1.0, waitingBallScale * 1.1);
|
waitingBallScale = Math.min(1.0, waitingBallScale * 1.1);
|
||||||
Overlays.editOverlay(overlay, {textures: textures});
|
Overlays.editOverlay(overlay, {textures: textures});
|
||||||
Overlays.editOverlay(overlay, {dimensions: Vec3.multiply(waitingBallScale, dimension), position: myHandPosition});
|
Overlays.editOverlay(overlay, {dimensions: Vec3.multiply(waitingBallScale, dimension), position: state == STATES.waiting ? myHandPosition : otherHand});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
deleteOverlay();
|
||||||
var particleProps = {};
|
var particleProps = {};
|
||||||
|
// put the position between the 2 hands, if we have a friendingId. This
|
||||||
|
// helps define the plane in which the particles move.
|
||||||
|
position = positionFractionallyTowards(position, otherHand, 0.5);
|
||||||
particleProps.position = position;
|
particleProps.position = position;
|
||||||
|
// now manage the rest of the entity
|
||||||
if (!particleEffect) {
|
if (!particleEffect) {
|
||||||
particleRotationAngle = 0.0;
|
particleRotationAngle = 0.0;
|
||||||
particleProps = PARTICLE_EFFECT_PROPS;
|
particleProps = PARTICLE_EFFECT_PROPS;
|
||||||
particleEffect = Entities.addEntity(particleProps);
|
particleEffect = Entities.addEntity(particleProps);
|
||||||
} else {
|
} else {
|
||||||
particleRotationAngle += 360/45; // about 1 hz
|
particleRotationAngle += PARTICLE_ANGLE_INCREMENT; // about 1 hz
|
||||||
particleProps.position = Vec3.sum(position, Vec3.multiplyQbyV(Quat.angleAxis(particleRotationAngle, Quat.getFront(MyAvatar.orientation)), {x:0, y:0.2, z:0}));
|
particleProps.position = Vec3.sum(position, Vec3.multiplyQbyV(Quat.angleAxis(particleRotationAngle, Quat.getFront(MyAvatar.orientation)), {x:0, y:PARTICLE_RADIUS, z:0}));
|
||||||
Entities.editEntity(particleEffect, particleProps);
|
Entities.editEntity(particleEffect, particleProps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -648,9 +642,8 @@ Script.scriptEnding.connect(function () {
|
||||||
Controller.keyReleaseEvent.disconnect(keyReleaseEvent);
|
Controller.keyReleaseEvent.disconnect(keyReleaseEvent);
|
||||||
debug("disconnecting updateVisualization");
|
debug("disconnecting updateVisualization");
|
||||||
Script.update.disconnect(updateVisualization);
|
Script.update.disconnect(updateVisualization);
|
||||||
if (overlay) {
|
deleteOverlay();
|
||||||
overlay = Overlays.deleteOverlay(overlay);
|
deleteParticleEffect();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}()); // END LOCAL_SCOPE
|
}()); // END LOCAL_SCOPE
|
||||||
|
|
Loading…
Reference in a new issue