remove animationSettings from particles, add isEmitting

This commit is contained in:
Brad Hefta-Gaub 2015-10-02 14:17:01 -07:00
parent e6fb587a8c
commit 02536a5ab9
23 changed files with 134 additions and 400 deletions

View file

@ -32,8 +32,7 @@
this.leaveEntity = function(entityID) {
Entities.editEntity(entityID, {
animationURL: animationURL,
animationSettings: '{ "frameIndex": 1, "running": false }'
animation: { url: animationURL, frameIndex: 1, running: false }
});
playSound();
@ -41,8 +40,7 @@
this.hoverEnterEntity = function(entityID) {
Entities.editEntity(entityID, {
animationURL: animationURL,
animationSettings: '{ "fps": 24, "firstFrame": 1, "lastFrame": 25, "frameIndex": 1, "running": true, "hold": true }'
animation: { url: animationURL, fps: 24, firstFrame: 1, lastFrame: 25, frameIndex: 1, running: true, hold: true }
});
};
})

View file

@ -18,7 +18,15 @@ var stopAfter = moveUntil + 100;
var pitch = 0.0;
var yaw = 0.0;
var roll = 0.0;
var rotation = Quat.fromPitchYawRollDegrees(pitch, yaw, roll)
var rotation = Quat.fromPitchYawRollDegrees(pitch, yaw, roll);
var animationSettings = JSON.stringify({
loop: true,
running: true,
fps: 30,
firstFrame: 10,
lastFrame: 20,
});
var originalProperties = {
type: "Model",
@ -37,12 +45,21 @@ var originalProperties = {
modelURL: "http://public.highfidelity.io/cozza13/club/dragon/dragon.fbx",
rotation: rotation,
//animationURL: "http://public.highfidelity.io/cozza13/club/dragon/flying.fbx",
animationURL: "http://public.highfidelity.io/cozza13/club/dragon/flying.fbx",
animationSettings: animationSettings,
//animationIsPlaying: true,
animationSettings: {
/*
animation: {
url: "http://public.highfidelity.io/cozza13/club/dragon/flying.fbx",
running: true
running: true,
fps: 30,
firstFrame: 10,
lastFrame: 20,
loop: true
}
*/
};
var modelID = Entities.addEntity(originalProperties);
@ -105,7 +122,7 @@ function moveModel(deltaTime) {
var newProperties = {
//animationIsPlaying: isPlaying,
//animationFPS: animationFPS,
animationSettings: {
animation: {
running: isPlaying,
fps: animationFPS
}
@ -114,7 +131,7 @@ function moveModel(deltaTime) {
if (resetFrame) {
print("resetting the frame!");
//newProperties.animationFrameIndex = 0;
newProperties.animationSettings.frameIndex = 0;
newProperties.animation.frameIndex = 0;
resetFrame = false;
}
@ -124,7 +141,7 @@ function moveModel(deltaTime) {
// register the call back so it fires before each data send
Script.update.connect(moveModel);
//Script.update.connect(moveModel);
Script.scriptEnding.connect(function () {

View file

@ -85,8 +85,17 @@ function addButterfly() {
damping: 0.00001,
dimensions: dimensions,
color: color,
animationURL: "http://public.highfidelity.io/models/content/butterfly/butterfly.fbx",
animationSettings: "{\"firstFrame\":0,\"fps\":" + newFrameRate + ",\"frameIndex\":0,\"hold\":false,\"lastFrame\":10000,\"loop\":true,\"running\":true,\"startAutomatically\":false}",
animation: {
url: "http://public.highfidelity.io/models/content/butterfly/butterfly.fbx",
firstFrame: 0,
fps: newFrameRate,
frameIndex: 0,
hold: false,
lastFrame: 10000,
loop: true,
running: true,
startAutomatically:false
},
modelURL: "http://public.highfidelity.io/models/content/butterfly/butterfly.fbx"
};
butterflies.push(Entities.addEntity(properties));

View file

@ -43,7 +43,7 @@
speedSpread: 0.0,
accelerationSpread: { x: 0.0, y: 0.0, z: 0.0 },
radiusSpread: 0.0,
animationIsPlaying: true
isEmitting: true
});
break;
case 1:
@ -195,7 +195,7 @@
polarFinish: 0.0,
azimuthStart: -PI,
azimuthFinish: PI,
animationIsPlaying: false
isEmitting: false
});
Entities.editEntity(box, {
visible: true
@ -210,15 +210,7 @@
function setUp() {
var boxPoint,
spawnPoint,
animation = {
fps: 30,
frameIndex: 0,
running: true,
firstFrame: 0,
lastFrame: 30,
loop: true
};
spawnPoint;
boxPoint = Vec3.sum(MyAvatar.position, Vec3.multiply(4.0, Quat.getFront(Camera.getOrientation())));
boxPoint = Vec3.sum(boxPoint, { x: 0.0, y: -0.5, z: 0.0 });
@ -265,8 +257,7 @@
lifespan: 5.0,
visible: false,
locked: false,
animationSettings: animation,
animationIsPlaying: false,
isEmitting: false,
lifetime: 3600 // 1 hour; just in case
});

View file

@ -117,15 +117,6 @@ Rocket = function(point, colorPalette) {
}
});
this.animationSettings = JSON.stringify({
fps: 40,
frameIndex: 0,
running: true,
firstFrame: 0,
lastFrame: 20,
loop: false
});
this.direction = {
x: randFloat(-0.4, 0.4),
y: 1.0,
@ -170,7 +161,7 @@ Rocket.prototype.explode = function(position) {
print(JSON.stringify(color));
this.bursts.push(Entities.addEntity({
type: "ParticleEffect",
animationSettings: this.animationSettings,
isEmitting: true,
position: position,
textures: 'https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png',
emitRate: this.emitRate,

View file

@ -282,7 +282,6 @@
var elModelAnimationPlaying = document.getElementById("property-model-animation-playing");
var elModelAnimationFPS = document.getElementById("property-model-animation-fps");
var elModelAnimationFrame = document.getElementById("property-model-animation-frame");
var elModelAnimationSettings = document.getElementById("property-model-animation-settings");
var elModelTextures = document.getElementById("property-model-textures");
var elModelOriginalTextures = document.getElementById("property-model-original-textures");
@ -506,11 +505,10 @@
elModelURL.value = properties.modelURL;
elShapeType.value = properties.shapeType;
elCompoundShapeURL.value = properties.compoundShapeURL;
elModelAnimationURL.value = properties.animationURL;
elModelAnimationPlaying.checked = properties.animationIsPlaying;
elModelAnimationFPS.value = properties.animationFPS;
elModelAnimationFrame.value = properties.animationFrameIndex;
elModelAnimationSettings.value = properties.animationSettings;
elModelAnimationURL.value = properties.animation.url;
elModelAnimationPlaying.checked = properties.animation.running;
elModelAnimationFPS.value = properties.animation.fps;
elModelAnimationFrame.value = properties.animation.frameIndex;
elModelTextures.value = properties.textures;
elModelOriginalTextures.value = properties.originalTextures;
} else if (properties.type == "Web") {
@ -756,11 +754,11 @@
elModelURL.addEventListener('change', createEmitTextPropertyUpdateFunction('modelURL'));
elShapeType.addEventListener('change', createEmitTextPropertyUpdateFunction('shapeType'));
elCompoundShapeURL.addEventListener('change', createEmitTextPropertyUpdateFunction('compoundShapeURL'));
elModelAnimationURL.addEventListener('change', createEmitTextPropertyUpdateFunction('animationURL'));
elModelAnimationPlaying.addEventListener('change', createEmitCheckedPropertyUpdateFunction('animationIsPlaying'));
elModelAnimationFPS.addEventListener('change', createEmitNumberPropertyUpdateFunction('animationFPS'));
elModelAnimationFrame.addEventListener('change', createEmitNumberPropertyUpdateFunction('animationFrameIndex'));
elModelAnimationSettings.addEventListener('change', createEmitTextPropertyUpdateFunction('animationSettings'));
elModelAnimationURL.addEventListener('change', createEmitGroupTextPropertyUpdateFunction('animation', 'url'));
elModelAnimationPlaying.addEventListener('change', createEmitGroupCheckedPropertyUpdateFunction('animation','running'));
elModelAnimationFPS.addEventListener('change', createEmitGroupNumberPropertyUpdateFunction('animation','fps'));
elModelAnimationFrame.addEventListener('change', createEmitGroupNumberPropertyUpdateFunction('animation','frameIndex'));
elModelTextures.addEventListener('change', createEmitTextPropertyUpdateFunction('textures'));
elTextText.addEventListener('change', createEmitTextPropertyUpdateFunction('text'));

View file

@ -27,7 +27,6 @@ EntityPropertyDialogBox = (function () {
var editModelID = -1;
var previousAnimationIsPlaying;
var previousAnimationFrameIndex;
var previousAnimationSettings;
that.cleanup = function () {
};
@ -56,18 +55,15 @@ EntityPropertyDialogBox = (function () {
index++;
array.push({ label: "Compound Shape URL:", value: properties.compoundShapeURL });
index++;
array.push({ label: "Animation URL:", value: properties.animationURL });
array.push({ label: "Animation URL:", value: properties.animation.url });
index++;
array.push({ label: "Animation is playing:", type: "checkbox", value: properties.animationIsPlaying });
previousAnimationIsPlaying = properties.animationIsPlaying;
array.push({ label: "Animation is playing:", type: "checkbox", value: properties.animation.running });
previousAnimationIsPlaying = properties.animation.running;
index++;
array.push({ label: "Animation FPS:", value: properties.animationFPS });
array.push({ label: "Animation FPS:", value: properties.animation.fps });
index++;
array.push({ label: "Animation Frame:", value: properties.animationFrameIndex });
previousAnimationFrameIndex = properties.animationFrameIndex;
index++;
array.push({ label: "Animation Settings:", value: properties.animationSettings });
previousAnimationSettings = properties.animationSettings;
array.push({ label: "Animation Frame:", value: properties.animation.frameIndex });
previousAnimationFrameIndex = properties.animation.frameIndex;
index++;
array.push({ label: "Textures:", value: properties.textures });
index++;
@ -312,30 +308,24 @@ EntityPropertyDialogBox = (function () {
properties.modelURL = array[index++].value;
properties.shapeType = array[index++].value;
properties.compoundShapeURL = array[index++].value;
properties.animationURL = array[index++].value;
properties.animation.url = array[index++].value;
var newAnimationIsPlaying = array[index++].value;
if (previousAnimationIsPlaying != newAnimationIsPlaying) {
properties.animationIsPlaying = newAnimationIsPlaying;
properties.animation.running = newAnimationIsPlaying;
} else {
delete properties.animationIsPlaying;
delete properties.animation.running;
}
properties.animationFPS = array[index++].value;
properties.animation.fps = array[index++].value;
var newAnimationFrameIndex = array[index++].value;
if (previousAnimationFrameIndex != newAnimationFrameIndex) {
properties.animationFrameIndex = newAnimationFrameIndex;
properties.animation.frameIndex = newAnimationFrameIndex;
} else {
delete properties.animationFrameIndex;
delete properties.animation.frameIndex;
}
var newAnimationSettings = array[index++].value;
if (previousAnimationSettings != newAnimationSettings) {
properties.animationSettings = newAnimationSettings;
} else {
delete properties.animationSettings;
}
properties.textures = array[index++].value;
index++; // skip textureNames label
}

View file

@ -51,15 +51,6 @@
this.emitRate = randInt(80, 120);
this.emitStrength = randInt(4.0, 6.0);
this.animationSettings = JSON.stringify({
fps: 10,
frameIndex: 0,
running: true,
firstFrame: 0,
lastFrame: 50,
loop: true
});
this.direction = {
x: randFloat(-0.3, 0.3),
y: 1.0,
@ -85,7 +76,7 @@
var color = colorPalette[colorIndex];
this.emitters.push(Entities.addEntity({
type: "ParticleEffect",
animationSettings: this.animationSettings,
isEmitting: true,
position: this.point,
textures: TEXTURE_PATH,
emitRate: this.emitRate,

View file

@ -72,10 +72,7 @@ var keysToIgnore = [
'marketplaceID',
'collisionSoundURL',
'shapeType',
'animationSettings',
'animationFrameIndex',
'animationIsPlaying',
'animationFPS',
'isEmitting',
'sittingPoints',
'originalTextures'
];

View file

@ -55,15 +55,7 @@ var particleProperties;
function setUp() {
var boxPoint,
spawnPoint,
animation = {
fps: 30,
frameIndex: 0,
running: true,
firstFrame: 0,
lastFrame: 30,
loop: true
};
spawnPoint;
boxPoint = Vec3.sum(MyAvatar.position, Vec3.multiply(4.0, Quat.getFront(Camera.getOrientation())));
boxPoint = Vec3.sum(boxPoint, {
@ -138,8 +130,7 @@ function setUp() {
lifespan: 5.0,
visible: false,
locked: false,
animationSettings: animation,
animationIsPlaying: true,
isEmitting: true,
lifetime: 3600 // 1 hour; just in case
});

View file

@ -29,17 +29,11 @@
// constructor
function TestFx(color, emitDirection, emitRate, emitStrength, blinkRate) {
var animationSettings = JSON.stringify({ fps: 30,
frameIndex: 0,
running: true,
firstFrame: 0,
lastFrame: 30,
loop: true });
var PI = 3.141593;
var DEG_TO_RAD = PI / 180.0;
this.entity = Entities.addEntity({ type: "ParticleEffect",
animationSettings: animationSettings,
isEmitting: true,
position: spawnPoint,
dimensions: {x: 2, y: 2, z: 2},
emitSpeed: 5,

View file

@ -384,13 +384,14 @@ function createOverlays() {
}
var TEMPORARY_LIFETIME = 60;
var ANIMATION_SETTINGS = JSON.stringify({
var ANIMATION_SETTINGS = {
url: "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_ready.fbx",
fps: 30,
running: true,
loop: true,
firstFrame: 1,
lastFrame: 10000
});
};
var NATURAL_DIMENSIONS = { x: 1.63, y: 1.67, z: 0.31 };
var DIMENSIONS = Vec3.multiply(NATURAL_DIMENSIONS, 0.3);
@ -407,8 +408,7 @@ function createPuppet(model, location) {
type: "Model",
modelURL: model,
registrationPoint: { x: 0.5, y: 0, z: 0.5 },
animationURL: "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_ready.fbx",
animationSettings: ANIMATION_SETTINGS,
animation: ANIMATION_SETTINGS,
position: location,
ignoreForCollisions: true,
dimensions: DIMENSIONS,
@ -558,7 +558,7 @@ breakdanceUpdate = function(deltaTime) {
var props = Entities.getEntityProperties(puppetEntityID);
//print("puppetEntityID:" + puppetEntityID + "age:"+props.age);
Entities.editEntity(puppetEntityID, {
animationURL: poses[poseValue].animation,
animation: { url: poses[poseValue].animation },
lifetime: TEMPORARY_LIFETIME + props.age // renew lifetime
});
}

View file

@ -33,15 +33,6 @@ var originalPosition = null;
var isGrenade = false;
var isBurning = false;
var animationSettings = JSON.stringify({
running: true,
loop: true
});
var explodeAnimationSettings = JSON.stringify({
running: true,
loop: false
});
var GRAVITY = -9.8;
var TIME_TO_EXPLODE = 2500;
var DISTANCE_IN_FRONT_OF_ME = 1.0;
@ -85,7 +76,7 @@ function update() {
// Create fuse particles
particles = Entities.addEntity({
type: "ParticleEffect",
animationSettings: animationSettings,
isEmitting: true,
position: newProperties.position,
textures: 'https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png',
emitRate: 100,
@ -142,7 +133,7 @@ function boom() {
Audio.playSound(boomSound, audioOptions);
Entities.addEntity({
type: "ParticleEffect",
animationSettings: explodeAnimationSettings,
isEmitting: true,
position: properties.position,
textures: 'https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png',
emitRate: 200,

View file

@ -62,20 +62,13 @@
this.enableStream = function() {
var position = Entities.getEntityProperties(this.entityId, "position").position;
var animationSettings = JSON.stringify({
fps: 30,
loop: true,
firstFrame: 1,
lastFrame: 10000,
running: true
});
var PI = 3.141593;
var DEG_TO_RAD = PI / 180.0;
this.paintStream = Entities.addEntity({
type: "ParticleEffect",
name: "streamEffect",
animationSettings: animationSettings,
isEmitting: true,
position: position,
textures: "https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png",
emitSpeed: 3,

View file

@ -35,14 +35,10 @@ public:
void setStartAutomatically(bool startAutomatically);
bool getStartAutomatically() const { return _startAutomatically; }
void setFirstFrame(float firstFrame) { _firstFrame = glm::clamp(firstFrame, 0.0f, MAXIMUM_POSSIBLE_FRAME);
//qDebug() << "AnimationLoop::setFirstFrame() firstFrame:" << firstFrame << "_firstFrame:" << _firstFrame;
}
void setFirstFrame(float firstFrame) { _firstFrame = glm::clamp(firstFrame, 0.0f, MAXIMUM_POSSIBLE_FRAME); }
float getFirstFrame() const { return _firstFrame; }
void setLastFrame(float lastFrame) { _lastFrame = glm::clamp(lastFrame, 0.0f, MAXIMUM_POSSIBLE_FRAME);
//qDebug() << "AnimationLoop::setLastFrame() lastFrame:" << lastFrame<< "_lastFrame:" << _lastFrame;
}
void setLastFrame(float lastFrame) { _lastFrame = glm::clamp(lastFrame, 0.0f, MAXIMUM_POSSIBLE_FRAME); }
float getLastFrame() const { return _lastFrame; }
/// by default the AnimationLoop will always reset to the first frame on any call to setRunning
@ -64,17 +60,17 @@ public:
void simulate(float deltaTime);
private:
float _fps = 30.0f;
bool _loop = false;
bool _hold = false;
bool _startAutomatically = false;
float _firstFrame = 0.0f;
float _lastFrame = MAXIMUM_POSSIBLE_FRAME;
bool _running = false;
float _frameIndex = 0.0f;
float _maxFrameIndexHint = MAXIMUM_POSSIBLE_FRAME;
bool _resetOnRunning = false;
bool _firstRun = true;
float _fps;
bool _loop;
bool _hold;
bool _startAutomatically;
float _firstFrame;
float _lastFrame;
bool _running;
float _frameIndex;
float _maxFrameIndexHint;
bool _resetOnRunning;
bool _firstRun;
};
#endif // hifi_AnimationLoop_h

View file

@ -269,7 +269,6 @@ void RenderableModelEntityItem::render(RenderArgs* args) {
if (_model) {
// handle animations..
if (hasAnimation()) {
if (!jointsMapped()) {
QStringList modelJointNames = _model->getJointNames();
mapJoints(modelJointNames);

View file

@ -18,9 +18,10 @@
// a) toybox/windmill
// b) toybox "put me down" doll
// c) asana bugs about animations
// 5) update all scripts
//
// DONE - 5) update all scripts
// DONE - 6) remove all remnants of old member variables
// 7) research and remove animation settings from Particle Effect
// DONE - 7) research and remove animation settings from Particle Effect
// 8) make sure animations start properly when entering a domain... with previously running animations
#ifndef hifi_AnimationPropertyGroup_h
@ -95,10 +96,7 @@ public:
DEFINE_PROPERTY(PROP_ANIMATION_START_AUTOMATICALLY, StartAutomatically, startAutomatically, bool); // was animationSettings.startAutomatically
public:
void associateWithAnimationLoop(AnimationLoop* animationLoop) {
qDebug() << "associateWithAnimationLoop() this:" << this << "animationLoop:" << animationLoop;
_animationLoop = animationLoop;
}
void associateWithAnimationLoop(AnimationLoop* animationLoop) { _animationLoop = animationLoop; }
protected:
void setFromOldAnimationSettings(const QString& value);

View file

@ -453,6 +453,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool
// Models only
if (_type == EntityTypes::Model) {
COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_MODEL_URL, modelURL);
_animation.copyToScriptValue(_desiredProperties, properties, engine, skipDefaults, defaultEntityProperties);
}
if (_type == EntityTypes::Model || _type == EntityTypes::Zone || _type == EntityTypes::ParticleEffect) {
@ -466,7 +467,6 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool
// Models & Particles
if (_type == EntityTypes::Model || _type == EntityTypes::ParticleEffect) {
_animation.copyToScriptValue(_desiredProperties, properties, engine, skipDefaults, defaultEntityProperties);
COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_TEXTURES, textures);
}
@ -621,6 +621,7 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool
COPY_PROPERTY_FROM_QSCRITPTVALUE_ENUM(shapeType, ShapeType);
COPY_PROPERTY_FROM_QSCRIPTVALUE(maxParticles, float, setMaxParticles);
COPY_PROPERTY_FROM_QSCRIPTVALUE(lifespan, float, setLifespan);
COPY_PROPERTY_FROM_QSCRIPTVALUE(isEmitting, bool, setIsEmitting);
COPY_PROPERTY_FROM_QSCRIPTVALUE(emitRate, float, setEmitRate);
COPY_PROPERTY_FROM_QSCRIPTVALUE(emitSpeed, float, setEmitSpeed);
COPY_PROPERTY_FROM_QSCRIPTVALUE(speedSpread, float, setSpeedSpread);
@ -773,6 +774,7 @@ void EntityItemProperties::entityPropertyFlagsFromScriptValue(const QScriptValue
ADD_PROPERTY_TO_MAP(PROP_SHAPE_TYPE, ShapeType, shapeType, ShapeType);
ADD_PROPERTY_TO_MAP(PROP_MAX_PARTICLES, MaxParticles, maxParticles, quint32);
ADD_PROPERTY_TO_MAP(PROP_LIFESPAN, Lifespan, lifespan, float);
ADD_PROPERTY_TO_MAP(PROP_EMITTING_PARTICLES, IsEmitting, isEmitting, bool);
ADD_PROPERTY_TO_MAP(PROP_EMIT_RATE, EmitRate, emitRate, float);
ADD_PROPERTY_TO_MAP(PROP_EMIT_SPEED, EmitSpeed, emitSpeed, glm::vec3);
ADD_PROPERTY_TO_MAP(PROP_SPEED_SPREAD, SpeedSpread, speedSpread, glm::vec3);
@ -1033,12 +1035,10 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem
}
if (properties.getType() == EntityTypes::ParticleEffect) {
_staticAnimation.setProperties(properties);
_staticAnimation.appendToEditPacket(packetData, requestedProperties, propertyFlags, propertiesDidntFit, propertyCount, appendState);
APPEND_ENTITY_PROPERTY(PROP_TEXTURES, properties.getTextures());
APPEND_ENTITY_PROPERTY(PROP_MAX_PARTICLES, properties.getMaxParticles());
APPEND_ENTITY_PROPERTY(PROP_LIFESPAN, properties.getLifespan());
APPEND_ENTITY_PROPERTY(PROP_EMITTING_PARTICLES, properties.getIsEmitting());
APPEND_ENTITY_PROPERTY(PROP_EMIT_RATE, properties.getEmitRate());
APPEND_ENTITY_PROPERTY(PROP_EMIT_SPEED, properties.getEmitSpeed());
APPEND_ENTITY_PROPERTY(PROP_SPEED_SPREAD, properties.getSpeedSpread());
@ -1319,11 +1319,10 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int
}
if (properties.getType() == EntityTypes::ParticleEffect) {
properties.getAnimation().decodeFromEditPacket(propertyFlags, dataAt, processedBytes);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_TEXTURES, QString, setTextures);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_MAX_PARTICLES, float, setMaxParticles);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LIFESPAN, float, setLifespan);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_EMITTING_PARTICLES, bool, setIsEmitting);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_EMIT_RATE, float, setEmitRate);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_EMIT_SPEED, float, setEmitSpeed);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_SPEED_SPREAD, float, setSpeedSpread);

View file

@ -136,6 +136,7 @@ public:
DEFINE_PROPERTY_REF_ENUM(PROP_SHAPE_TYPE, ShapeType, shapeType, ShapeType);
DEFINE_PROPERTY(PROP_MAX_PARTICLES, MaxParticles, maxParticles, quint32);
DEFINE_PROPERTY(PROP_LIFESPAN, Lifespan, lifespan, float);
DEFINE_PROPERTY(PROP_EMITTING_PARTICLES, IsEmitting, isEmitting, bool);
DEFINE_PROPERTY(PROP_EMIT_RATE, EmitRate, emitRate, float);
DEFINE_PROPERTY(PROP_EMIT_SPEED, EmitSpeed, emitSpeed, float);
DEFINE_PROPERTY(PROP_SPEED_SPREAD, SpeedSpread, speedSpread, float);
@ -339,6 +340,7 @@ inline QDebug operator<<(QDebug debug, const EntityItemProperties& properties) {
DEBUG_PROPERTY_IF_CHANGED(debug, properties, ShapeType, shapeType, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, MaxParticles, maxParticles, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Lifespan, lifespan, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, IsEmitting, isEmitting, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, EmitRate, emitRate, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, EmitSpeed, emitSpeed, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, SpeedSpread, speedSpread, "");

View file

@ -194,6 +194,10 @@ enum EntityPropertyList {
// other properties which will never overlap with each other.
PROP_SOURCE_URL = PROP_MODEL_URL,
// Aliases/Piggyback properties for Particle Emmitter. These properties intentionally reuse the enum values for
// other properties which will never overlap with each other.
PROP_EMITTING_PARTICLES = PROP_ANIMATION_PLAYING,
// WARNING!!! DO NOT ADD PROPS_xxx here unless you really really meant to.... Add them UP above
};

View file

@ -52,9 +52,9 @@ const float ParticleEffectEntityItem::DEFAULT_ALPHA = 1.0f;
const float ParticleEffectEntityItem::DEFAULT_ALPHA_SPREAD = 0.0f;
const float ParticleEffectEntityItem::DEFAULT_ALPHA_START = DEFAULT_ALPHA;
const float ParticleEffectEntityItem::DEFAULT_ALPHA_FINISH = DEFAULT_ALPHA;
const float ParticleEffectEntityItem::DEFAULT_ANIMATION_FRAME_INDEX = 0.0f;
const bool ParticleEffectEntityItem::DEFAULT_ANIMATION_IS_PLAYING = false;
const float ParticleEffectEntityItem::DEFAULT_ANIMATION_FPS = 30.0f;
//const float ParticleEffectEntityItem::DEFAULT_ANIMATION_FRAME_INDEX = 0.0f;
//const bool ParticleEffectEntityItem::DEFAULT_ANIMATION_IS_PLAYING = false;
//const float ParticleEffectEntityItem::DEFAULT_ANIMATION_FPS = 30.0f;
const quint32 ParticleEffectEntityItem::DEFAULT_MAX_PARTICLES = 1000;
const float ParticleEffectEntityItem::DEFAULT_LIFESPAN = 3.0f;
const float ParticleEffectEntityItem::DEFAULT_EMIT_RATE = 15.0f;
@ -83,9 +83,8 @@ EntityItemPointer ParticleEffectEntityItem::factory(const EntityItemID& entityID
// our non-pure virtual subclass for now...
ParticleEffectEntityItem::ParticleEffectEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
EntityItem(entityItemID),
_lastAnimated(usecTimestampNow()),
_animationLoop(),
_animationSettings(),
_lastSimulated(usecTimestampNow()),
_isEmitting(true),
_particleLifetimes(DEFAULT_MAX_PARTICLES, 0.0f),
_particlePositions(DEFAULT_MAX_PARTICLES, glm::vec3(0.0f, 0.0f, 0.0f)),
_particleVelocities(DEFAULT_MAX_PARTICLES, glm::vec3(0.0f, 0.0f, 0.0f)),
@ -109,9 +108,6 @@ ParticleEffectEntityItem::ParticleEffectEntityItem(const EntityItemID& entityIte
_type = EntityTypes::ParticleEffect;
setColor(DEFAULT_COLOR);
setProperties(properties);
_animationProperties.associateWithAnimationLoop(&_animationLoop);
_animationLoop.setResetOnRunning(false);
}
ParticleEffectEntityItem::~ParticleEffectEntityItem() {
@ -176,6 +172,7 @@ EntityItemProperties ParticleEffectEntityItem::getProperties(EntityPropertyFlags
COPY_ENTITY_PROPERTY_TO_PROPERTIES(shapeType, getShapeType);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(maxParticles, getMaxParticles);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(lifespan, getLifespan);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(isEmitting, getIsEmitting);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(emitRate, getEmitRate);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(emitSpeed, getEmitSpeed);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(speedSpread, getSpeedSpread);
@ -200,8 +197,6 @@ EntityItemProperties ParticleEffectEntityItem::getProperties(EntityPropertyFlags
COPY_ENTITY_PROPERTY_TO_PROPERTIES(alphaFinish, getAlphaFinish);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(textures, getTextures);
_animationProperties.getProperties(properties);
return properties;
}
@ -214,6 +209,7 @@ bool ParticleEffectEntityItem::setProperties(const EntityItemProperties& propert
SET_ENTITY_PROPERTY_FROM_PROPERTIES(shapeType, updateShapeType);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(maxParticles, setMaxParticles);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(lifespan, setLifespan);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(isEmitting, setIsEmitting);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(emitRate, setEmitRate);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(emitSpeed, setEmitSpeed);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(speedSpread, setSpeedSpread);
@ -238,10 +234,6 @@ bool ParticleEffectEntityItem::setProperties(const EntityItemProperties& propert
SET_ENTITY_PROPERTY_FROM_PROPERTIES(alphaFinish, setAlphaFinish);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(textures, setTextures);
bool somethingChangedInAnimations = _animationProperties.setProperties(properties);
somethingChanged = somethingChanged || somethingChangedInAnimations;
if (somethingChanged) {
bool wantDebug = false;
if (wantDebug) {
@ -267,38 +259,11 @@ int ParticleEffectEntityItem::readEntitySubclassDataFromBuffer(const unsigned ch
// Because we're using AnimationLoop which will reset the frame index if you change it's running state
// we want to read these values in the order they appear in the buffer, but call our setters in an
// order that allows AnimationLoop to preserve the correct frame rate.
float animationFPS = getAnimationFPS();
float animationFrameIndex = getAnimationFrameIndex();
bool animationIsPlaying = getAnimationIsPlaying();
if (args.bitstreamVersion < VERSION_ENTITIES_ANIMATION_PROPERTIES_GROUP) {
READ_ENTITY_PROPERTY(PROP_ANIMATION_FPS, float, setAnimationFPS);
READ_ENTITY_PROPERTY(PROP_ANIMATION_FRAME_INDEX, float, setAnimationFrameIndex);
READ_ENTITY_PROPERTY(PROP_ANIMATION_PLAYING, bool, setAnimationIsPlaying);
}
if (propertyFlags.getHasProperty(PROP_ANIMATION_PLAYING)) {
if (animationIsPlaying != getAnimationIsPlaying()) {
setAnimationIsPlaying(animationIsPlaying);
}
}
if (propertyFlags.getHasProperty(PROP_ANIMATION_FPS)) {
setAnimationFPS(animationFPS);
}
if (propertyFlags.getHasProperty(PROP_ANIMATION_FRAME_INDEX)) {
setAnimationFrameIndex(animationFrameIndex);
}
if (args.bitstreamVersion < VERSION_ENTITIES_ANIMATION_PROPERTIES_GROUP) {
READ_ENTITY_PROPERTY(PROP_ANIMATION_SETTINGS, QString, setAnimationSettings);
}
else {
int bytesFromAnimation = _animationProperties.readEntitySubclassDataFromBuffer(dataAt, (bytesLeftToRead - bytesRead), args,
propertyFlags, overwriteLocalData);
bytesRead += bytesFromAnimation;
dataAt += bytesFromAnimation;
// FIXME -- we need to actually get the property values out of the _animationProperties
// and use them for our AnimationLoop
SKIP_ENTITY_PROPERTY(PROP_ANIMATION_FPS, float);
SKIP_ENTITY_PROPERTY(PROP_ANIMATION_FRAME_INDEX, float);
SKIP_ENTITY_PROPERTY(PROP_ANIMATION_PLAYING, bool);
SKIP_ENTITY_PROPERTY(PROP_ANIMATION_SETTINGS, QString);
}
READ_ENTITY_PROPERTY(PROP_SHAPE_TYPE, ShapeType, updateShapeType);
@ -393,8 +358,6 @@ EntityPropertyFlags ParticleEffectEntityItem::getEntityProperties(EncodeBitstrea
requestedProperties += PROP_AZIMUTH_START;
requestedProperties += PROP_AZIMUTH_FINISH;
requestedProperties += _animationProperties.getEntityProperties(params);
return requestedProperties;
}
@ -408,11 +371,6 @@ void ParticleEffectEntityItem::appendSubclassData(OctreePacketData* packetData,
bool successPropertyFits = true;
APPEND_ENTITY_PROPERTY(PROP_COLOR, getColor());
// FIXME - we probably need to make sure the _animationProperties has the latest data from the AnimationLoop
_animationProperties.appendSubclassData(packetData, params, entityTreeElementExtraEncodeData, requestedProperties,
propertyFlags, propertiesDidntFit, propertyCount, appendState);
APPEND_ENTITY_PROPERTY(PROP_SHAPE_TYPE, (uint32_t)getShapeType());
APPEND_ENTITY_PROPERTY(PROP_MAX_PARTICLES, getMaxParticles());
APPEND_ENTITY_PROPERTY(PROP_LIFESPAN, getLifespan());
@ -442,9 +400,10 @@ void ParticleEffectEntityItem::appendSubclassData(OctreePacketData* packetData,
APPEND_ENTITY_PROPERTY(PROP_AZIMUTH_FINISH, getAzimuthFinish());
}
bool ParticleEffectEntityItem::isAnimatingSomething() const {
// keep animating if there are particles still alive.
return (getAnimationIsPlaying() || getLivingParticleCount() > 0) && getAnimationFPS() != 0.0f;
bool ParticleEffectEntityItem::isEmittingParticles() const {
// keep emitting if there are particles still alive.
//return (getAnimationIsPlaying() || getLivingParticleCount() > 0) && getAnimationFPS() != 0.0f;
return (getLivingParticleCount() > 0);
}
bool ParticleEffectEntityItem::needsToCallUpdate() const {
@ -453,15 +412,10 @@ bool ParticleEffectEntityItem::needsToCallUpdate() const {
void ParticleEffectEntityItem::update(const quint64& now) {
float deltaTime = (float)(now - _lastAnimated) / (float)USECS_PER_SECOND;
_lastAnimated = now;
float deltaTime = (float)(now - _lastSimulated) / (float)USECS_PER_SECOND;
_lastSimulated = now;
// only advance the frame index if we're playing
if (getAnimationIsPlaying()) {
_animationLoop.simulate(deltaTime);
}
if (isAnimatingSomething()) {
if (isEmittingParticles()) {
stepSimulation(deltaTime);
}
@ -484,131 +438,6 @@ void ParticleEffectEntityItem::updateShapeType(ShapeType type) {
}
}
void ParticleEffectEntityItem::setAnimationFrameIndex(float value) {
#ifdef WANT_DEBUG
if (isAnimatingSomething()) {
qCDebug(entities) << "ParticleEffectEntityItem::setAnimationFrameIndex()";
qCDebug(entities) << " value:" << value;
qCDebug(entities) << " was:" << _animationLoop.getFrameIndex();
}
#endif
_animationLoop.setFrameIndex(value);
}
void ParticleEffectEntityItem::setAnimationSettings(const QString& value) {
// the animations setting is a JSON string that may contain various animation settings.
// if it includes fps, frameIndex, or running, those values will be parsed out and
// will over ride the regular animation settings
QJsonDocument settingsAsJson = QJsonDocument::fromJson(value.toUtf8());
QJsonObject settingsAsJsonObject = settingsAsJson.object();
QVariantMap settingsMap = settingsAsJsonObject.toVariantMap();
if (settingsMap.contains("fps")) {
float fps = settingsMap["fps"].toFloat();
setAnimationFPS(fps);
}
if (settingsMap.contains("frameIndex")) {
float frameIndex = settingsMap["frameIndex"].toFloat();
#ifdef WANT_DEBUG
if (isAnimatingSomething()) {
qCDebug(entities) << "ParticleEffectEntityItem::setAnimationSettings() calling setAnimationFrameIndex()...";
qCDebug(entities) << " settings:" << value;
qCDebug(entities) << " settingsMap[frameIndex]:" << settingsMap["frameIndex"];
qCDebug(entities, " frameIndex: %20.5f", frameIndex);
}
#endif
setAnimationFrameIndex(frameIndex);
}
if (settingsMap.contains("running")) {
bool running = settingsMap["running"].toBool();
if (running != getAnimationIsPlaying()) {
setAnimationIsPlaying(running);
}
}
if (settingsMap.contains("firstFrame")) {
float firstFrame = settingsMap["firstFrame"].toFloat();
setAnimationFirstFrame(firstFrame);
}
if (settingsMap.contains("lastFrame")) {
float lastFrame = settingsMap["lastFrame"].toFloat();
setAnimationLastFrame(lastFrame);
}
if (settingsMap.contains("loop")) {
bool loop = settingsMap["loop"].toBool();
setAnimationLoop(loop);
}
if (settingsMap.contains("hold")) {
bool hold = settingsMap["hold"].toBool();
setAnimationHold(hold);
}
if (settingsMap.contains("startAutomatically")) {
bool startAutomatically = settingsMap["startAutomatically"].toBool();
setAnimationStartAutomatically(startAutomatically);
}
_animationSettings = value;
_dirtyFlags |= EntityItem::DIRTY_UPDATEABLE;
}
void ParticleEffectEntityItem::setAnimationIsPlaying(bool value) {
_dirtyFlags |= EntityItem::DIRTY_UPDATEABLE;
_animationLoop.setRunning(value);
}
void ParticleEffectEntityItem::setAnimationFPS(float value) {
_dirtyFlags |= EntityItem::DIRTY_UPDATEABLE;
_animationLoop.setFPS(value);
}
QString ParticleEffectEntityItem::getAnimationSettings() const {
// the animations setting is a JSON string that may contain various animation settings.
// if it includes fps, frameIndex, or running, those values will be parsed out and
// will over ride the regular animation settings
QString value = _animationSettings;
QJsonDocument settingsAsJson = QJsonDocument::fromJson(value.toUtf8());
QJsonObject settingsAsJsonObject = settingsAsJson.object();
QVariantMap settingsMap = settingsAsJsonObject.toVariantMap();
QVariant fpsValue(getAnimationFPS());
settingsMap["fps"] = fpsValue;
QVariant frameIndexValue(getAnimationFrameIndex());
settingsMap["frameIndex"] = frameIndexValue;
QVariant runningValue(getAnimationIsPlaying());
settingsMap["running"] = runningValue;
QVariant firstFrameValue(getAnimationFirstFrame());
settingsMap["firstFrame"] = firstFrameValue;
QVariant lastFrameValue(getAnimationLastFrame());
settingsMap["lastFrame"] = lastFrameValue;
QVariant loopValue(getAnimationLoop());
settingsMap["loop"] = loopValue;
QVariant holdValue(getAnimationHold());
settingsMap["hold"] = holdValue;
QVariant startAutomaticallyValue(getAnimationStartAutomatically());
settingsMap["startAutomatically"] = startAutomaticallyValue;
settingsAsJsonObject = QJsonObject::fromVariantMap(settingsMap);
QJsonDocument newDocument(settingsAsJsonObject);
QByteArray jsonByteArray = newDocument.toJson(QJsonDocument::Compact);
QString jsonByteString(jsonByteArray);
return jsonByteString;
}
void ParticleEffectEntityItem::updateRadius(quint32 index, float age) {
_particleRadiuses[index] = Interpolate::interpolate3Points(_radiusStarts[index], _radiusMiddles[index],
_radiusFinishes[index], age);
@ -669,8 +498,8 @@ void ParticleEffectEntityItem::stepSimulation(float deltaTime) {
}
}
// emit new particles, but only if animation is playing
if (getAnimationIsPlaying()) {
// emit new particles, but only if we are emmitting
if (isEmittingParticles()) {
float timeLeftInFrame = deltaTime;
while (_timeUntilNextEmit < timeLeftInFrame) {

View file

@ -91,33 +91,9 @@ public:
virtual void debugDump() const;
const AnimationPropertyGroup& getAnimationProperties() const { return _animationProperties; }
static const float DEFAULT_ANIMATION_FRAME_INDEX;
void setAnimationFrameIndex(float value);
void setAnimationSettings(const QString& value);
static const bool DEFAULT_ANIMATION_IS_PLAYING;
void setAnimationIsPlaying(bool value);
static const float DEFAULT_ANIMATION_FPS;
void setAnimationFPS(float value);
void setAnimationLoop(bool loop) { _animationLoop.setLoop(loop); }
bool getAnimationLoop() const { return _animationLoop.getLoop(); }
void setAnimationHold(bool hold) { _animationLoop.setHold(hold); }
bool getAnimationHold() const { return _animationLoop.getHold(); }
void setAnimationStartAutomatically(bool startAutomatically) { _animationLoop.setStartAutomatically(startAutomatically); }
bool getAnimationStartAutomatically() const { return _animationLoop.getStartAutomatically(); }
void setAnimationFirstFrame(float firstFrame) { _animationLoop.setFirstFrame(firstFrame); }
float getAnimationFirstFrame() const { return _animationLoop.getFirstFrame(); }
void setAnimationLastFrame(float lastFrame) { _animationLoop.setLastFrame(lastFrame); }
float getAnimationLastFrame() const { return _animationLoop.getLastFrame(); }
bool isEmittingParticles() const; /// emitting enabled, and there are particles alive
bool getIsEmitting() const { return _isEmitting; }
void setIsEmitting(bool isEmitting) { _isEmitting = isEmitting; }
static const quint32 DEFAULT_MAX_PARTICLES;
void setMaxParticles(quint32 maxParticles);
@ -195,12 +171,6 @@ public:
void computeAndUpdateDimensions();
bool getAnimationIsPlaying() const { return _animationLoop.isRunning(); }
float getAnimationFrameIndex() const { return _animationLoop.getFrameIndex(); }
float getAnimationFPS() const { return _animationLoop.getFPS(); }
QString getAnimationSettings() const;
static const QString DEFAULT_TEXTURES;
const QString& getTextures() const { return _textures; }
void setTextures(const QString& textures) {
@ -250,12 +220,8 @@ protected:
float _radiusSpread = DEFAULT_RADIUS_SPREAD;
quint64 _lastAnimated;
AnimationPropertyGroup _animationProperties;
AnimationLoop _animationLoop;
// FIXME - remove this
QString _animationSettings;
quint64 _lastSimulated;
bool _isEmitting;
QString _textures = DEFAULT_TEXTURES;
bool _texturesChangedFlag = false;

View file

@ -112,19 +112,10 @@ function createFire() {
var myOrientation = Quat.fromPitchYawRollDegrees(-90, 0, 0.0);
var animationSettings = JSON.stringify({
fps: 30,
running: true,
loop: true,
firstFrame: 1,
lastFrame: 10000
});
var fire = Entities.addEntity({
type: "ParticleEffect",
name: "fire",
animationSettings: animationSettings,
isEmitting: true,
textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png",
position: {
x: 551.45,
@ -187,17 +178,16 @@ function createFire() {
function createCat(position) {
var scriptURL = Script.resolvePath("../examples/toys/cat.js");
var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/Dark_Cat.fbx";
var animationURL = "http://hifi-public.s3.amazonaws.com/ryan/sleeping.fbx";
var animationSettings = JSON.stringify({
var animationSettings = {
url: "http://hifi-public.s3.amazonaws.com/ryan/sleeping.fbx",
running: true,
});
};
var cat = Entities.addEntity({
type: "Model",
modelURL: modelURL,
name: "cat",
script: scriptURL,
animationURL: animationURL,
animationSettings: animationSettings,
animation: animationSettings,
position: position,
rotation: {
w: 0.35020983219146729,