Update leenkx/Sources/iron/object/ObjectAnimation.hx
This commit is contained in:
@ -24,6 +24,9 @@ class ObjectAnimation extends Animation {
|
||||
|
||||
public var transformMap: Map<String, FastFloat>;
|
||||
|
||||
var defaultSampler: ActionSampler = null;
|
||||
static inline var DEFAULT_SAMPLER_ID = "__object_default_action__";
|
||||
|
||||
public static var trackNames: Array<String> = [ "xloc", "yloc", "zloc",
|
||||
"xrot", "yrot", "zrot",
|
||||
"qwrot", "qxrot", "qyrot", "qzrot",
|
||||
@ -39,7 +42,6 @@ class ObjectAnimation extends Animation {
|
||||
isSkinned = false;
|
||||
super();
|
||||
}
|
||||
|
||||
function getAction(action: String): TObj {
|
||||
for (a in oactions) if (a != null && a.objects[0].name == action) return a.objects[0];
|
||||
return null;
|
||||
@ -47,10 +49,16 @@ class ObjectAnimation extends Animation {
|
||||
|
||||
override public function play(action = "", onComplete: Void->Void = null, blendTime = 0.0, speed = 1.0, loop = true) {
|
||||
super.play(action, onComplete, blendTime, speed, loop);
|
||||
if (this.action == "" && oactions[0] != null) this.action = oactions[0].objects[0].name;
|
||||
if (this.action == "" && oactions != null && oactions[0] != null){
|
||||
this.action = oactions[0].objects[0].name;
|
||||
}
|
||||
oaction = getAction(this.action);
|
||||
if (oaction != null) {
|
||||
isSampled = oaction.sampled != null && oaction.sampled;
|
||||
setupDefaultSampler(onComplete, speed, loop);
|
||||
}
|
||||
else {
|
||||
clearDefaultSampler();
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,12 +69,12 @@ class ObjectAnimation extends Animation {
|
||||
Animation.beginProfile();
|
||||
#end
|
||||
|
||||
if(transformMap == null) transformMap = new Map();
|
||||
if (transformMap == null) transformMap = new Map();
|
||||
transformMap = initTransformMap();
|
||||
|
||||
super.update(delta);
|
||||
if (paused) return;
|
||||
if(updateAnimation == null) return;
|
||||
if (updateAnimation == null) return;
|
||||
if (!isSkinned) updateObjectAnimation();
|
||||
|
||||
#if lnx_debug
|
||||
@ -95,6 +103,39 @@ class ObjectAnimation extends Animation {
|
||||
updateAnimation = f;
|
||||
}
|
||||
|
||||
function setupDefaultSampler(onComplete: Void->Void, speed: FastFloat, loop: Bool) {
|
||||
if (defaultSampler != null) {
|
||||
deRegisterAction(DEFAULT_SAMPLER_ID);
|
||||
defaultSampler = null;
|
||||
}
|
||||
var onCompleteCallbacks:Array<Void->Void> = null;
|
||||
if (onComplete != null) onCompleteCallbacks = [onComplete];
|
||||
defaultSampler = new ActionSampler(this.action, speed, loop, false, onCompleteCallbacks);
|
||||
registerAction(DEFAULT_SAMPLER_ID, defaultSampler);
|
||||
if (paused) defaultSampler.paused = true;
|
||||
updateAnimation = function(map: Map<String, FastFloat>) {
|
||||
sampleAction(defaultSampler, map);
|
||||
};
|
||||
}
|
||||
|
||||
function clearDefaultSampler() {
|
||||
if (defaultSampler != null) {
|
||||
deRegisterAction(DEFAULT_SAMPLER_ID);
|
||||
defaultSampler = null;
|
||||
}
|
||||
updateAnimation = null;
|
||||
}
|
||||
|
||||
override public function pause() {
|
||||
super.pause();
|
||||
if (defaultSampler != null) defaultSampler.paused = true;
|
||||
}
|
||||
|
||||
override public function resume() {
|
||||
super.resume();
|
||||
if (defaultSampler != null) defaultSampler.paused = false;
|
||||
}
|
||||
|
||||
function updateObjectAnimation() {
|
||||
updateAnimation(transformMap);
|
||||
updateTransform(transformMap, object.transform);
|
||||
|
Reference in New Issue
Block a user