@ -29,7 +29,7 @@ public class AnimComposer extends AbstractControl {
private Map < String , Layer > layers = new LinkedHashMap < > ( ) ;
private Map < String , Layer > layers = new LinkedHashMap < > ( ) ;
public AnimComposer ( ) {
public AnimComposer ( ) {
layers . put ( DEFAULT_LAYER , new Layer ( ) ) ;
layers . put ( DEFAULT_LAYER , new Layer ( this ) ) ;
}
}
/ * *
/ * *
@ -171,7 +171,7 @@ public class AnimComposer extends AbstractControl {
}
}
public void makeLayer ( String name , AnimationMask mask ) {
public void makeLayer ( String name , AnimationMask mask ) {
Layer l = new Layer ( ) ;
Layer l = new Layer ( this ) ;
l . mask = mask ;
l . mask = mask ;
layers . put ( name , l ) ;
layers . put ( name , l ) ;
}
}
@ -300,6 +300,7 @@ public class AnimComposer extends AbstractControl {
super . read ( im ) ;
super . read ( im ) ;
InputCapsule ic = im . getCapsule ( this ) ;
InputCapsule ic = im . getCapsule ( this ) ;
animClipMap = ( Map < String , AnimClip > ) ic . readStringSavableMap ( "animClipMap" , new HashMap < String , AnimClip > ( ) ) ;
animClipMap = ( Map < String , AnimClip > ) ic . readStringSavableMap ( "animClipMap" , new HashMap < String , AnimClip > ( ) ) ;
globalSpeed = ic . readFloat ( "globalSpeed" , 1f ) ;
}
}
@Override
@Override
@ -307,16 +308,22 @@ public class AnimComposer extends AbstractControl {
super . write ( ex ) ;
super . write ( ex ) ;
OutputCapsule oc = ex . getCapsule ( this ) ;
OutputCapsule oc = ex . getCapsule ( this ) ;
oc . writeStringSavableMap ( animClipMap , "animClipMap" , new HashMap < String , AnimClip > ( ) ) ;
oc . writeStringSavableMap ( animClipMap , "animClipMap" , new HashMap < String , AnimClip > ( ) ) ;
oc . write ( globalSpeed , "globalSpeed" , 1f ) ;
}
}
private class Layer implements JmeCloneable {
private static class Layer implements JmeCloneable {
private AnimComposer ac ;
private Action currentAction ;
private Action currentAction ;
private AnimationMask mask ;
private AnimationMask mask ;
private float weight ;
private float weight ;
private double time ;
private double time ;
public Layer ( AnimComposer ac ) {
this . ac = ac ;
}
public void advance ( float tpf ) {
public void advance ( float tpf ) {
time + = tpf * currentAction . getSpeed ( ) * globalSpeed ;
time + = tpf * currentAction . getSpeed ( ) * ac . globalSpeed ;
// make sure negative time is in [0, length] range
// make sure negative time is in [0, length] range
if ( time < 0 ) {
if ( time < 0 ) {
double length = currentAction . getLength ( ) ;
double length = currentAction . getLength ( ) ;
@ -337,6 +344,7 @@ public class AnimComposer extends AbstractControl {
@Override
@Override
public void cloneFields ( Cloner cloner , Object original ) {
public void cloneFields ( Cloner cloner , Object original ) {
ac = cloner . clone ( ac ) ;
currentAction = null ;
currentAction = null ;
}
}
}
}