diff --git a/leenkx/Sources/iron/object/ObjectAnimation.hx b/leenkx/Sources/iron/object/ObjectAnimation.hx index c61b6fc..3d9b49f 100644 --- a/leenkx/Sources/iron/object/ObjectAnimation.hx +++ b/leenkx/Sources/iron/object/ObjectAnimation.hx @@ -24,6 +24,9 @@ class ObjectAnimation extends Animation { public var transformMap: Map; + var defaultSampler: ActionSampler = null; + static inline var DEFAULT_SAMPLER_ID = "__object_default_action__"; + public static var trackNames: Array = [ "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,29 @@ 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; + if (defaultSampler != null) { + deRegisterAction(DEFAULT_SAMPLER_ID); + } + var callbacks = onComplete != null ? [onComplete] : null; + defaultSampler = new ActionSampler(this.action, speed, loop, false, callbacks); + registerAction(DEFAULT_SAMPLER_ID, defaultSampler); + if (paused) defaultSampler.paused = true; + updateAnimation = function(map: Map) { + sampleAction(defaultSampler, map); + }; + } + else { + if (defaultSampler != null) { + deRegisterAction(DEFAULT_SAMPLER_ID); + defaultSampler = null; + } + updateAnimation = null; } } @@ -61,12 +82,13 @@ 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 (defaultSampler != null) defaultSampler.paused = paused; if (paused) return; - if(updateAnimation == null) return; + if (updateAnimation == null) return; if (!isSkinned) updateObjectAnimation(); #if lnx_debug