When stopping animation, make sure to update the meshes if the model was

outside the view frustum on the last update.


git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@109 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Andrzej Kapolka
2007-01-02 19:06:34 +00:00
parent 9dadf30d2e
commit 154ce35b3a
+42 -30
View File
@@ -601,6 +601,10 @@ public class Model extends ModelNode
if (_anim == null) { if (_anim == null) {
return; return;
} }
if (_outside) {
// make sure the meshes are in the right places when we come back into view
updateMeshes();
}
_paused = false; _paused = false;
_anim = null; _anim = null;
_animObservers.apply(new AnimCancelledOp(_animName)); _animObservers.apply(new AnimCancelledOp(_animName));
@@ -982,6 +986,44 @@ public class Model extends ModelNode
// update the target transforms and animation frame if not outside the // update the target transforms and animation frame if not outside the
// view frustum // view frustum
if (!_outside) { if (!_outside) {
updateMeshes();
}
// if the next index is the same as this one, we are finished
if (_fidx == _nidx && !_paused) {
_anim = null;
_animObservers.apply(new AnimCompletedOp(_animName));
return;
}
_elapsed += (time * _anim.frameRate);
}
/**
* Advances the frame counter by one frame.
*/
protected void advanceFrameCounter ()
{
_fidx = _nidx;
int nframes = _anim.transforms.length;
if (_anim.repeatType == Controller.RT_CLAMP) {
_nidx = Math.max(0, Math.min(_nidx + _fdir, nframes - 1));
} else if (_anim.repeatType == Controller.RT_WRAP) {
_nidx = (_nidx + _fdir) % nframes;
} else { // _anim.repeatType == Controller.RT_CYCLE
if ((_nidx + _fdir) < 0 || (_nidx + _fdir) >= nframes) {
_fdir *= -1; // reverse direction
}
_nidx += _fdir;
}
}
/**
* Updates the states of the model's meshes according to the animation state.
*/
protected void updateMeshes ()
{
if (_animMode == AnimationMode.FLIPBOOK) { if (_animMode == AnimationMode.FLIPBOOK) {
int frameId = (_anim.animId << 16) | _fidx; int frameId = (_anim.animId << 16) | _fidx;
_anim.applyFrame(_fidx); _anim.applyFrame(_fidx);
@@ -1015,36 +1057,6 @@ public class Model extends ModelNode
} }
} }
// if the next index is the same as this one, we are finished
if (_fidx == _nidx && !_paused) {
_anim = null;
_animObservers.apply(new AnimCompletedOp(_animName));
return;
}
_elapsed += (time * _anim.frameRate);
}
/**
* Advances the frame counter by one frame.
*/
protected void advanceFrameCounter ()
{
_fidx = _nidx;
int nframes = _anim.transforms.length;
if (_anim.repeatType == Controller.RT_CLAMP) {
_nidx = Math.max(0, Math.min(_nidx + _fdir, nframes - 1));
} else if (_anim.repeatType == Controller.RT_WRAP) {
_nidx = (_nidx + _fdir) % nframes;
} else { // _anim.repeatType == Controller.RT_CYCLE
if ((_nidx + _fdir) < 0 || (_nidx + _fdir) >= nframes) {
_fdir *= -1; // reverse direction
}
_nidx += _fdir;
}
}
/** A reference to the prototype, or <code>null</code> if this is a /** A reference to the prototype, or <code>null</code> if this is a
* prototype. */ * prototype. */
protected Model _prototype; protected Model _prototype;