* Fix animation blending from bind pose issue

* Fix look/cycle modes for animations to prevent result time from being out of range

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9262 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Sha..rd 13 years ago
parent 203bc00a7d
commit 2cdeb6ebff
  1. 84
      engine/src/core/com/jme3/animation/AnimChannel.java
  2. 31
      engine/src/core/com/jme3/animation/Animation.java

@ -68,31 +68,53 @@ public final class AnimChannel {
private float blendRate = 0; private float blendRate = 0;
private static float clampWrapTime(float t, float max, LoopMode loopMode){ private static float clampWrapTime(float t, float max, LoopMode loopMode){
if (max == Float.POSITIVE_INFINITY) if (t == 0) {
return t; return 0; // prevent division by 0 errors
}
if (t < 0f){ switch (loopMode) {
//float tMod = -(-t % max); case Cycle:
switch (loopMode){ boolean sign = ((int) (t / max) % 2) != 0;
case DontLoop: float result;
return 0; if (t < 0){
case Cycle: result = sign ? t % max : -(max + (t % max));
return t; } else {
case Loop: result = sign ? -(max - (t % max)) : t % max;
return max - t; }
} return result;
}else if (t > max){ case DontLoop:
switch (loopMode){ return t > max ? max : (t < 0 ? 0 : t);
case DontLoop: case Loop:
return max; return t % max;
case Cycle:
return /*-max;*/-(2f * max - t);
case Loop:
return t - max;
}
} }
return t; return t;
// if (max == Float.POSITIVE_INFINITY)
// return t;
//
// if (t < 0f){
// //float tMod = -(-t % max);
// switch (loopMode){
// case DontLoop:
// return 0;
// case Cycle:
// return t;
// case Loop:
// return max - t;
// }
// }else if (t > max){
// switch (loopMode){
// case DontLoop:
// return max;
// case Cycle:
// return -(2f * max - t) % max;
// case Loop:
// return t % max;
// }
// }
//
// return t;
} }
AnimChannel(AnimControl control){ AnimChannel(AnimControl control){
@ -225,6 +247,8 @@ public final class AnimChannel {
loopModeBlendFrom = loopMode; loopModeBlendFrom = loopMode;
blendAmount = 0f; blendAmount = 0f;
blendRate = 1f / blendTime; blendRate = 1f / blendTime;
}else{
blendFrom = null;
} }
animation = anim; animation = anim;
@ -335,9 +359,12 @@ public final class AnimChannel {
if (animation == null) if (animation == null)
return; return;
if (blendFrom != null){ if (blendFrom != null && blendAmount != 1.0f){
blendFrom.setTime(timeBlendFrom, 1f - blendAmount, control, this, vars); // The blendFrom anim is set, the actual animation
//blendFrom.setTime(timeBlendFrom, control.skeleton, 1f - blendAmount, affectedBones); // playing will be set
blendFrom.setTime(timeBlendFrom, 1f, control, this, vars);
// blendFrom.setTime(timeBlendFrom, 1f - blendAmount, control, this, vars);
timeBlendFrom += tpf * speedBlendFrom; timeBlendFrom += tpf * speedBlendFrom;
timeBlendFrom = clampWrapTime(timeBlendFrom, timeBlendFrom = clampWrapTime(timeBlendFrom,
blendFrom.getLength(), blendFrom.getLength(),
@ -353,9 +380,8 @@ public final class AnimChannel {
blendFrom = null; blendFrom = null;
} }
} }
animation.setTime(time, blendAmount, control, this, vars); animation.setTime(time, blendAmount, control, this, vars);
//animation.setTime(time, control.skeleton, blendAmount, affectedBones);
time += tpf * speed; time += tpf * speed;
if (animation.getLength() > 0){ if (animation.getLength() > 0){
@ -368,10 +394,10 @@ public final class AnimChannel {
time = clampWrapTime(time, animation.getLength(), loopMode); time = clampWrapTime(time, animation.getLength(), loopMode);
if (time < 0){ if (time < 0){
// Negative time indicates that speed should be inverted
// (for cycle loop mode only)
time = -time; time = -time;
speed = -speed; speed = -speed;
} }
} }
} }

@ -107,37 +107,6 @@ public class Animation implements Savable, Cloneable {
for (int i = 0; i < tracks.length; i++){ for (int i = 0; i < tracks.length; i++){
tracks[i].setTime(time, blendAmount, control, channel, vars); tracks[i].setTime(time, blendAmount, control, channel, vars);
} }
/*
if (tracks != null && tracks.length > 0) {
Track<?> trackInstance = tracks[0];
if (trackInstance instanceof SpatialTrack) {
Spatial spatial = control.getSpatial();
if (spatial != null) {
((SpatialTrack) tracks[0]).setTime(time, spatial, blendAmount);
}
} else if (trackInstance instanceof BoneTrack) {
BitSet affectedBones = channel.getAffectedBones();
Skeleton skeleton = control.getSkeleton();
for (int i = 0; i < tracks.length; ++i) {
if (affectedBones == null || affectedBones.get(((BoneTrack) tracks[i]).getTargetIndex())) {
((BoneTrack) tracks[i]).setTime(time, skeleton, blendAmount);
}
}
} else if (trackInstance instanceof PoseTrack) {
Spatial spatial = control.getSpatial();
List<Mesh> meshes = new ArrayList<Mesh>();
this.getMeshes(spatial, meshes);
if (meshes.size() > 0) {
Mesh[] targets = meshes.toArray(new Mesh[meshes.size()]);
for (int i = 0; i < tracks.length; ++i) {
((PoseTrack) tracks[i]).setTime(time, targets, blendAmount);
}
}
}
}
*/
} }
/** /**

Loading…
Cancel
Save