From fa2d8f05d58886b316369ee26cc0f680e54a8819 Mon Sep 17 00:00:00 2001 From: Onek8 Date: Tue, 30 Sep 2025 05:35:50 +0000 Subject: [PATCH] Update leenkx/Sources/iron/object/ObjectAnimation.hx --- leenkx/Sources/iron/object/ObjectAnimation.hx | 49 +++++++++++++++++-- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/leenkx/Sources/iron/object/ObjectAnimation.hx b/leenkx/Sources/iron/object/ObjectAnimation.hx index c61b6fc..db0b838 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,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:ArrayVoid> = 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) { + 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);