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) { this.leaveEntity = function(entityID) {
Entities.editEntity(entityID, { Entities.editEntity(entityID, {
animationURL: animationURL, animation: { url: animationURL, frameIndex: 1, running: false }
animationSettings: '{ "frameIndex": 1, "running": false }'
}); });
playSound(); playSound();
@ -41,8 +40,7 @@
this.hoverEnterEntity = function(entityID) { this.hoverEnterEntity = function(entityID) {
Entities.editEntity(entityID, { Entities.editEntity(entityID, {
animationURL: animationURL, animation: { url: animationURL, fps: 24, firstFrame: 1, lastFrame: 25, frameIndex: 1, running: true, hold: true }
animationSettings: '{ "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 pitch = 0.0;
var yaw = 0.0; var yaw = 0.0;
var roll = 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 = { var originalProperties = {
type: "Model", type: "Model",
@ -37,12 +45,21 @@ var originalProperties = {
modelURL: "http://public.highfidelity.io/cozza13/club/dragon/dragon.fbx", modelURL: "http://public.highfidelity.io/cozza13/club/dragon/dragon.fbx",
rotation: rotation, 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, //animationIsPlaying: true,
animationSettings: { /*
animation: {
url: "http://public.highfidelity.io/cozza13/club/dragon/flying.fbx", 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); var modelID = Entities.addEntity(originalProperties);
@ -105,7 +122,7 @@ function moveModel(deltaTime) {
var newProperties = { var newProperties = {
//animationIsPlaying: isPlaying, //animationIsPlaying: isPlaying,
//animationFPS: animationFPS, //animationFPS: animationFPS,
animationSettings: { animation: {
running: isPlaying, running: isPlaying,
fps: animationFPS fps: animationFPS
} }
@ -114,7 +131,7 @@ function moveModel(deltaTime) {
if (resetFrame) { if (resetFrame) {
print("resetting the frame!"); print("resetting the frame!");
//newProperties.animationFrameIndex = 0; //newProperties.animationFrameIndex = 0;
newProperties.animationSettings.frameIndex = 0; newProperties.animation.frameIndex = 0;
resetFrame = false; resetFrame = false;
} }
@ -124,7 +141,7 @@ function moveModel(deltaTime) {
// register the call back so it fires before each data send // register the call back so it fires before each data send
Script.update.connect(moveModel); //Script.update.connect(moveModel);
Script.scriptEnding.connect(function () { Script.scriptEnding.connect(function () {

View file

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

View file

@ -43,7 +43,7 @@
speedSpread: 0.0, speedSpread: 0.0,
accelerationSpread: { x: 0.0, y: 0.0, z: 0.0 }, accelerationSpread: { x: 0.0, y: 0.0, z: 0.0 },
radiusSpread: 0.0, radiusSpread: 0.0,
animationIsPlaying: true isEmitting: true
}); });
break; break;
case 1: case 1:
@ -195,7 +195,7 @@
polarFinish: 0.0, polarFinish: 0.0,
azimuthStart: -PI, azimuthStart: -PI,
azimuthFinish: PI, azimuthFinish: PI,
animationIsPlaying: false isEmitting: false
}); });
Entities.editEntity(box, { Entities.editEntity(box, {
visible: true visible: true
@ -210,15 +210,7 @@
function setUp() { function setUp() {
var boxPoint, var boxPoint,
spawnPoint, spawnPoint;
animation = {
fps: 30,
frameIndex: 0,
running: true,
firstFrame: 0,
lastFrame: 30,
loop: true
};
boxPoint = Vec3.sum(MyAvatar.position, Vec3.multiply(4.0, Quat.getFront(Camera.getOrientation()))); 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 }); boxPoint = Vec3.sum(boxPoint, { x: 0.0, y: -0.5, z: 0.0 });
@ -265,8 +257,7 @@
lifespan: 5.0, lifespan: 5.0,
visible: false, visible: false,
locked: false, locked: false,
animationSettings: animation, isEmitting: false,
animationIsPlaying: false,
lifetime: 3600 // 1 hour; just in case 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 = { this.direction = {
x: randFloat(-0.4, 0.4), x: randFloat(-0.4, 0.4),
y: 1.0, y: 1.0,
@ -170,7 +161,7 @@ Rocket.prototype.explode = function(position) {
print(JSON.stringify(color)); print(JSON.stringify(color));
this.bursts.push(Entities.addEntity({ this.bursts.push(Entities.addEntity({
type: "ParticleEffect", type: "ParticleEffect",
animationSettings: this.animationSettings, isEmitting: true,
position: position, position: position,
textures: 'https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png', textures: 'https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png',
emitRate: this.emitRate, emitRate: this.emitRate,

View file

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

View file

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

View file

@ -51,15 +51,6 @@
this.emitRate = randInt(80, 120); this.emitRate = randInt(80, 120);
this.emitStrength = randInt(4.0, 6.0); 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 = { this.direction = {
x: randFloat(-0.3, 0.3), x: randFloat(-0.3, 0.3),
y: 1.0, y: 1.0,
@ -85,7 +76,7 @@
var color = colorPalette[colorIndex]; var color = colorPalette[colorIndex];
this.emitters.push(Entities.addEntity({ this.emitters.push(Entities.addEntity({
type: "ParticleEffect", type: "ParticleEffect",
animationSettings: this.animationSettings, isEmitting: true,
position: this.point, position: this.point,
textures: TEXTURE_PATH, textures: TEXTURE_PATH,
emitRate: this.emitRate, emitRate: this.emitRate,

View file

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

View file

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

View file

@ -29,17 +29,11 @@
// constructor // constructor
function TestFx(color, emitDirection, emitRate, emitStrength, blinkRate) { 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 PI = 3.141593;
var DEG_TO_RAD = PI / 180.0; var DEG_TO_RAD = PI / 180.0;
this.entity = Entities.addEntity({ type: "ParticleEffect", this.entity = Entities.addEntity({ type: "ParticleEffect",
animationSettings: animationSettings, isEmitting: true,
position: spawnPoint, position: spawnPoint,
dimensions: {x: 2, y: 2, z: 2}, dimensions: {x: 2, y: 2, z: 2},
emitSpeed: 5, emitSpeed: 5,

View file

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

View file

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

View file

@ -62,20 +62,13 @@
this.enableStream = function() { this.enableStream = function() {
var position = Entities.getEntityProperties(this.entityId, "position").position; 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 PI = 3.141593;
var DEG_TO_RAD = PI / 180.0; var DEG_TO_RAD = PI / 180.0;
this.paintStream = Entities.addEntity({ this.paintStream = Entities.addEntity({
type: "ParticleEffect", type: "ParticleEffect",
name: "streamEffect", name: "streamEffect",
animationSettings: animationSettings, isEmitting: true,
position: position, position: position,
textures: "https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png", textures: "https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png",
emitSpeed: 3, emitSpeed: 3,

View file

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

View file

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

View file

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

View file

@ -453,6 +453,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool
// Models only // Models only
if (_type == EntityTypes::Model) { if (_type == EntityTypes::Model) {
COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_MODEL_URL, modelURL); 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) { if (_type == EntityTypes::Model || _type == EntityTypes::Zone || _type == EntityTypes::ParticleEffect) {
@ -466,7 +467,6 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool
// Models & Particles // Models & Particles
if (_type == EntityTypes::Model || _type == EntityTypes::ParticleEffect) { if (_type == EntityTypes::Model || _type == EntityTypes::ParticleEffect) {
_animation.copyToScriptValue(_desiredProperties, properties, engine, skipDefaults, defaultEntityProperties);
COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_TEXTURES, textures); 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_QSCRITPTVALUE_ENUM(shapeType, ShapeType);
COPY_PROPERTY_FROM_QSCRIPTVALUE(maxParticles, float, setMaxParticles); COPY_PROPERTY_FROM_QSCRIPTVALUE(maxParticles, float, setMaxParticles);
COPY_PROPERTY_FROM_QSCRIPTVALUE(lifespan, float, setLifespan); 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(emitRate, float, setEmitRate);
COPY_PROPERTY_FROM_QSCRIPTVALUE(emitSpeed, float, setEmitSpeed); COPY_PROPERTY_FROM_QSCRIPTVALUE(emitSpeed, float, setEmitSpeed);
COPY_PROPERTY_FROM_QSCRIPTVALUE(speedSpread, float, setSpeedSpread); 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_SHAPE_TYPE, ShapeType, shapeType, ShapeType);
ADD_PROPERTY_TO_MAP(PROP_MAX_PARTICLES, MaxParticles, maxParticles, quint32); ADD_PROPERTY_TO_MAP(PROP_MAX_PARTICLES, MaxParticles, maxParticles, quint32);
ADD_PROPERTY_TO_MAP(PROP_LIFESPAN, Lifespan, lifespan, float); 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_RATE, EmitRate, emitRate, float);
ADD_PROPERTY_TO_MAP(PROP_EMIT_SPEED, EmitSpeed, emitSpeed, glm::vec3); ADD_PROPERTY_TO_MAP(PROP_EMIT_SPEED, EmitSpeed, emitSpeed, glm::vec3);
ADD_PROPERTY_TO_MAP(PROP_SPEED_SPREAD, SpeedSpread, speedSpread, 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) { 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_TEXTURES, properties.getTextures());
APPEND_ENTITY_PROPERTY(PROP_MAX_PARTICLES, properties.getMaxParticles()); APPEND_ENTITY_PROPERTY(PROP_MAX_PARTICLES, properties.getMaxParticles());
APPEND_ENTITY_PROPERTY(PROP_LIFESPAN, properties.getLifespan()); 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_RATE, properties.getEmitRate());
APPEND_ENTITY_PROPERTY(PROP_EMIT_SPEED, properties.getEmitSpeed()); APPEND_ENTITY_PROPERTY(PROP_EMIT_SPEED, properties.getEmitSpeed());
APPEND_ENTITY_PROPERTY(PROP_SPEED_SPREAD, properties.getSpeedSpread()); 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) { 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_TEXTURES, QString, setTextures);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_MAX_PARTICLES, float, setMaxParticles); 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_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_RATE, float, setEmitRate);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_EMIT_SPEED, float, setEmitSpeed); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_EMIT_SPEED, float, setEmitSpeed);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_SPEED_SPREAD, float, setSpeedSpread); 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_REF_ENUM(PROP_SHAPE_TYPE, ShapeType, shapeType, ShapeType);
DEFINE_PROPERTY(PROP_MAX_PARTICLES, MaxParticles, maxParticles, quint32); DEFINE_PROPERTY(PROP_MAX_PARTICLES, MaxParticles, maxParticles, quint32);
DEFINE_PROPERTY(PROP_LIFESPAN, Lifespan, lifespan, float); 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_RATE, EmitRate, emitRate, float);
DEFINE_PROPERTY(PROP_EMIT_SPEED, EmitSpeed, emitSpeed, float); DEFINE_PROPERTY(PROP_EMIT_SPEED, EmitSpeed, emitSpeed, float);
DEFINE_PROPERTY(PROP_SPEED_SPREAD, SpeedSpread, speedSpread, 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, ShapeType, shapeType, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, MaxParticles, maxParticles, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, MaxParticles, maxParticles, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Lifespan, lifespan, ""); 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, EmitRate, emitRate, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, EmitSpeed, emitSpeed, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, EmitSpeed, emitSpeed, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, SpeedSpread, speedSpread, ""); 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. // other properties which will never overlap with each other.
PROP_SOURCE_URL = PROP_MODEL_URL, 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 // 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_SPREAD = 0.0f;
const float ParticleEffectEntityItem::DEFAULT_ALPHA_START = DEFAULT_ALPHA; const float ParticleEffectEntityItem::DEFAULT_ALPHA_START = DEFAULT_ALPHA;
const float ParticleEffectEntityItem::DEFAULT_ALPHA_FINISH = DEFAULT_ALPHA; const float ParticleEffectEntityItem::DEFAULT_ALPHA_FINISH = DEFAULT_ALPHA;
const float ParticleEffectEntityItem::DEFAULT_ANIMATION_FRAME_INDEX = 0.0f; //const float ParticleEffectEntityItem::DEFAULT_ANIMATION_FRAME_INDEX = 0.0f;
const bool ParticleEffectEntityItem::DEFAULT_ANIMATION_IS_PLAYING = false; //const bool ParticleEffectEntityItem::DEFAULT_ANIMATION_IS_PLAYING = false;
const float ParticleEffectEntityItem::DEFAULT_ANIMATION_FPS = 30.0f; //const float ParticleEffectEntityItem::DEFAULT_ANIMATION_FPS = 30.0f;
const quint32 ParticleEffectEntityItem::DEFAULT_MAX_PARTICLES = 1000; const quint32 ParticleEffectEntityItem::DEFAULT_MAX_PARTICLES = 1000;
const float ParticleEffectEntityItem::DEFAULT_LIFESPAN = 3.0f; const float ParticleEffectEntityItem::DEFAULT_LIFESPAN = 3.0f;
const float ParticleEffectEntityItem::DEFAULT_EMIT_RATE = 15.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... // our non-pure virtual subclass for now...
ParticleEffectEntityItem::ParticleEffectEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : ParticleEffectEntityItem::ParticleEffectEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
EntityItem(entityItemID), EntityItem(entityItemID),
_lastAnimated(usecTimestampNow()), _lastSimulated(usecTimestampNow()),
_animationLoop(), _isEmitting(true),
_animationSettings(),
_particleLifetimes(DEFAULT_MAX_PARTICLES, 0.0f), _particleLifetimes(DEFAULT_MAX_PARTICLES, 0.0f),
_particlePositions(DEFAULT_MAX_PARTICLES, glm::vec3(0.0f, 0.0f, 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)), _particleVelocities(DEFAULT_MAX_PARTICLES, glm::vec3(0.0f, 0.0f, 0.0f)),
@ -109,9 +108,6 @@ ParticleEffectEntityItem::ParticleEffectEntityItem(const EntityItemID& entityIte
_type = EntityTypes::ParticleEffect; _type = EntityTypes::ParticleEffect;
setColor(DEFAULT_COLOR); setColor(DEFAULT_COLOR);
setProperties(properties); setProperties(properties);
_animationProperties.associateWithAnimationLoop(&_animationLoop);
_animationLoop.setResetOnRunning(false);
} }
ParticleEffectEntityItem::~ParticleEffectEntityItem() { ParticleEffectEntityItem::~ParticleEffectEntityItem() {
@ -176,6 +172,7 @@ EntityItemProperties ParticleEffectEntityItem::getProperties(EntityPropertyFlags
COPY_ENTITY_PROPERTY_TO_PROPERTIES(shapeType, getShapeType); COPY_ENTITY_PROPERTY_TO_PROPERTIES(shapeType, getShapeType);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(maxParticles, getMaxParticles); COPY_ENTITY_PROPERTY_TO_PROPERTIES(maxParticles, getMaxParticles);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(lifespan, getLifespan); 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(emitRate, getEmitRate);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(emitSpeed, getEmitSpeed); COPY_ENTITY_PROPERTY_TO_PROPERTIES(emitSpeed, getEmitSpeed);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(speedSpread, getSpeedSpread); 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(alphaFinish, getAlphaFinish);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(textures, getTextures); COPY_ENTITY_PROPERTY_TO_PROPERTIES(textures, getTextures);
_animationProperties.getProperties(properties);
return 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(shapeType, updateShapeType);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(maxParticles, setMaxParticles); SET_ENTITY_PROPERTY_FROM_PROPERTIES(maxParticles, setMaxParticles);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(lifespan, setLifespan); 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(emitRate, setEmitRate);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(emitSpeed, setEmitSpeed); SET_ENTITY_PROPERTY_FROM_PROPERTIES(emitSpeed, setEmitSpeed);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(speedSpread, setSpeedSpread); 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(alphaFinish, setAlphaFinish);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(textures, setTextures); SET_ENTITY_PROPERTY_FROM_PROPERTIES(textures, setTextures);
bool somethingChangedInAnimations = _animationProperties.setProperties(properties);
somethingChanged = somethingChanged || somethingChangedInAnimations;
if (somethingChanged) { if (somethingChanged) {
bool wantDebug = false; bool wantDebug = false;
if (wantDebug) { 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 // 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 // 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. // 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) { if (args.bitstreamVersion < VERSION_ENTITIES_ANIMATION_PROPERTIES_GROUP) {
READ_ENTITY_PROPERTY(PROP_ANIMATION_FPS, float, setAnimationFPS); SKIP_ENTITY_PROPERTY(PROP_ANIMATION_FPS, float);
READ_ENTITY_PROPERTY(PROP_ANIMATION_FRAME_INDEX, float, setAnimationFrameIndex); SKIP_ENTITY_PROPERTY(PROP_ANIMATION_FRAME_INDEX, float);
READ_ENTITY_PROPERTY(PROP_ANIMATION_PLAYING, bool, setAnimationIsPlaying); SKIP_ENTITY_PROPERTY(PROP_ANIMATION_PLAYING, bool);
} SKIP_ENTITY_PROPERTY(PROP_ANIMATION_SETTINGS, QString);
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
} }
READ_ENTITY_PROPERTY(PROP_SHAPE_TYPE, ShapeType, updateShapeType); READ_ENTITY_PROPERTY(PROP_SHAPE_TYPE, ShapeType, updateShapeType);
@ -393,8 +358,6 @@ EntityPropertyFlags ParticleEffectEntityItem::getEntityProperties(EncodeBitstrea
requestedProperties += PROP_AZIMUTH_START; requestedProperties += PROP_AZIMUTH_START;
requestedProperties += PROP_AZIMUTH_FINISH; requestedProperties += PROP_AZIMUTH_FINISH;
requestedProperties += _animationProperties.getEntityProperties(params);
return requestedProperties; return requestedProperties;
} }
@ -408,11 +371,6 @@ void ParticleEffectEntityItem::appendSubclassData(OctreePacketData* packetData,
bool successPropertyFits = true; bool successPropertyFits = true;
APPEND_ENTITY_PROPERTY(PROP_COLOR, getColor()); 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_SHAPE_TYPE, (uint32_t)getShapeType());
APPEND_ENTITY_PROPERTY(PROP_MAX_PARTICLES, getMaxParticles()); APPEND_ENTITY_PROPERTY(PROP_MAX_PARTICLES, getMaxParticles());
APPEND_ENTITY_PROPERTY(PROP_LIFESPAN, getLifespan()); APPEND_ENTITY_PROPERTY(PROP_LIFESPAN, getLifespan());
@ -442,9 +400,10 @@ void ParticleEffectEntityItem::appendSubclassData(OctreePacketData* packetData,
APPEND_ENTITY_PROPERTY(PROP_AZIMUTH_FINISH, getAzimuthFinish()); APPEND_ENTITY_PROPERTY(PROP_AZIMUTH_FINISH, getAzimuthFinish());
} }
bool ParticleEffectEntityItem::isAnimatingSomething() const { bool ParticleEffectEntityItem::isEmittingParticles() const {
// keep animating if there are particles still alive. // keep emitting if there are particles still alive.
return (getAnimationIsPlaying() || getLivingParticleCount() > 0) && getAnimationFPS() != 0.0f; //return (getAnimationIsPlaying() || getLivingParticleCount() > 0) && getAnimationFPS() != 0.0f;
return (getLivingParticleCount() > 0);
} }
bool ParticleEffectEntityItem::needsToCallUpdate() const { bool ParticleEffectEntityItem::needsToCallUpdate() const {
@ -453,15 +412,10 @@ bool ParticleEffectEntityItem::needsToCallUpdate() const {
void ParticleEffectEntityItem::update(const quint64& now) { void ParticleEffectEntityItem::update(const quint64& now) {
float deltaTime = (float)(now - _lastAnimated) / (float)USECS_PER_SECOND; float deltaTime = (float)(now - _lastSimulated) / (float)USECS_PER_SECOND;
_lastAnimated = now; _lastSimulated = now;
// only advance the frame index if we're playing if (isEmittingParticles()) {
if (getAnimationIsPlaying()) {
_animationLoop.simulate(deltaTime);
}
if (isAnimatingSomething()) {
stepSimulation(deltaTime); 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) { void ParticleEffectEntityItem::updateRadius(quint32 index, float age) {
_particleRadiuses[index] = Interpolate::interpolate3Points(_radiusStarts[index], _radiusMiddles[index], _particleRadiuses[index] = Interpolate::interpolate3Points(_radiusStarts[index], _radiusMiddles[index],
_radiusFinishes[index], age); _radiusFinishes[index], age);
@ -669,8 +498,8 @@ void ParticleEffectEntityItem::stepSimulation(float deltaTime) {
} }
} }
// emit new particles, but only if animation is playing // emit new particles, but only if we are emmitting
if (getAnimationIsPlaying()) { if (isEmittingParticles()) {
float timeLeftInFrame = deltaTime; float timeLeftInFrame = deltaTime;
while (_timeUntilNextEmit < timeLeftInFrame) { while (_timeUntilNextEmit < timeLeftInFrame) {

View file

@ -91,33 +91,9 @@ public:
virtual void debugDump() const; virtual void debugDump() const;
bool isEmittingParticles() const; /// emitting enabled, and there are particles alive
const AnimationPropertyGroup& getAnimationProperties() const { return _animationProperties; } bool getIsEmitting() const { return _isEmitting; }
void setIsEmitting(bool isEmitting) { _isEmitting = isEmitting; }
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(); }
static const quint32 DEFAULT_MAX_PARTICLES; static const quint32 DEFAULT_MAX_PARTICLES;
void setMaxParticles(quint32 maxParticles); void setMaxParticles(quint32 maxParticles);
@ -195,12 +171,6 @@ public:
void computeAndUpdateDimensions(); 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; static const QString DEFAULT_TEXTURES;
const QString& getTextures() const { return _textures; } const QString& getTextures() const { return _textures; }
void setTextures(const QString& textures) { void setTextures(const QString& textures) {
@ -250,12 +220,8 @@ protected:
float _radiusSpread = DEFAULT_RADIUS_SPREAD; float _radiusSpread = DEFAULT_RADIUS_SPREAD;
quint64 _lastAnimated; quint64 _lastSimulated;
AnimationPropertyGroup _animationProperties; bool _isEmitting;
AnimationLoop _animationLoop;
// FIXME - remove this
QString _animationSettings;
QString _textures = DEFAULT_TEXTURES; QString _textures = DEFAULT_TEXTURES;
bool _texturesChangedFlag = false; bool _texturesChangedFlag = false;

View file

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