forked from LeenkxTeam/LNXSDK
Consolidate and update
This commit is contained in:
@ -17,6 +17,7 @@ class ObjectAnimation extends Animation {
|
||||
public var oactions: Array<TSceneFormat>;
|
||||
var oaction: TObj;
|
||||
var s0: FastFloat = 0.0;
|
||||
var delta: FastFloat = 0;
|
||||
var bezierFrameIndex = -1;
|
||||
|
||||
var updateAnimation: Map<String, FastFloat> -> Void;
|
||||
@ -26,7 +27,11 @@ class ObjectAnimation extends Animation {
|
||||
public var transformMap: Map<String, FastFloat>;
|
||||
|
||||
var defaultSampler: ActionSampler = null;
|
||||
static inline var DEFAULT_SAMPLER_ID = "__object_default_action__";
|
||||
var playSamplers: Map<String, ActionSampler> = [];
|
||||
var transitionSampler: ActionSampler = null;
|
||||
var transitionMap: Map<String, FastFloat> = null;
|
||||
var transitionTime: FastFloat = 0.0;
|
||||
var transitionDuration: FastFloat = 0.0;
|
||||
|
||||
public static var trackNames: Array<String> = [ "xloc", "yloc", "zloc",
|
||||
"xrot", "yrot", "zrot",
|
||||
@ -67,27 +72,59 @@ class ObjectAnimation extends Animation {
|
||||
oaction = getAction(this.action);
|
||||
if (oaction != null) {
|
||||
isSampled = oaction.sampled != null && oaction.sampled;
|
||||
if (defaultSampler != null) {
|
||||
deRegisterAction(DEFAULT_SAMPLER_ID);
|
||||
var sampler = playSamplers.get(this.action);
|
||||
if (sampler == null) {
|
||||
if (activeActions != null) sampler = activeActions.get(this.action);
|
||||
if (sampler == null) sampler = new ActionSampler(this.action);
|
||||
playSamplers.set(this.action, sampler);
|
||||
}
|
||||
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;
|
||||
if (transitionSampler != null) {
|
||||
transitionSampler.paused = true;
|
||||
transitionSampler = null;
|
||||
}
|
||||
if (blendTime > 0 && defaultSampler != null && defaultSampler != sampler) {
|
||||
transitionSampler = defaultSampler;
|
||||
transitionMap = initTransformMap();
|
||||
transitionTime = 0.0;
|
||||
transitionDuration = blendTime;
|
||||
}
|
||||
else if (defaultSampler != null) defaultSampler.paused = true;
|
||||
defaultSampler = sampler;
|
||||
sampler.speed = speed;
|
||||
sampler.loop = loop;
|
||||
sampler.onComplete = onComplete != null ? [onComplete] : null;
|
||||
sampler.restartAction();
|
||||
registerAction(this.action, sampler);
|
||||
updateAnimation = function(map: Map<String, FastFloat>) {
|
||||
sampleAction(defaultSampler, map);
|
||||
if (transitionSampler != null) {
|
||||
sampleAction(transitionSampler, transitionMap);
|
||||
sampleAction(sampler, map);
|
||||
var f = transitionTime / transitionDuration;
|
||||
if (f > 1.0) f = 1.0;
|
||||
f = f * f * (3.0 - 2.0 * f); // Smoothstep
|
||||
blendActionObject(transitionMap, map, map, f);
|
||||
transitionTime += delta;
|
||||
if (transitionTime >= transitionDuration) {
|
||||
transitionSampler.paused = true;
|
||||
transitionSampler = null;
|
||||
}
|
||||
}
|
||||
else sampleAction(sampler, map);
|
||||
};
|
||||
}
|
||||
else {
|
||||
if (defaultSampler != null) {
|
||||
deRegisterAction(DEFAULT_SAMPLER_ID);
|
||||
defaultSampler = null;
|
||||
if (transitionSampler != null) {
|
||||
transitionSampler.paused = true;
|
||||
transitionSampler = null;
|
||||
}
|
||||
if (defaultSampler != null) defaultSampler.paused = true;
|
||||
defaultSampler = null;
|
||||
updateAnimation = null;
|
||||
}
|
||||
}
|
||||
|
||||
override public function update(delta: FastFloat) {
|
||||
this.delta = delta;
|
||||
if (!object.visible || object.culled) return;
|
||||
|
||||
#if lnx_debug
|
||||
@ -98,7 +135,6 @@ class ObjectAnimation extends Animation {
|
||||
transformMap = initTransformMap();
|
||||
|
||||
super.update(delta);
|
||||
if (defaultSampler != null) defaultSampler.paused = paused;
|
||||
if (paused) return;
|
||||
if (updateAnimation == null) return;
|
||||
if (!isSkinned) updateObjectAnimation();
|
||||
@ -160,11 +196,13 @@ class ObjectAnimation extends Animation {
|
||||
|
||||
var ti = sampler.offset;
|
||||
//ti = ti < 0 ? 1 : ti;
|
||||
var tj = ti + sign;
|
||||
if (tj < 0 || tj >= track.frames.length) tj = ti;
|
||||
|
||||
var t1 = track.frames[ti] * frameTime;
|
||||
var t2 = track.frames[ti + sign] * frameTime;
|
||||
var t2 = track.frames[tj] * frameTime;
|
||||
var v1 = track.values[ti];
|
||||
var v2 = track.values[ti + sign];
|
||||
var v2 = track.values[tj];
|
||||
|
||||
var value = interpolateLinear(t, t1, t2, v1, v2);
|
||||
|
||||
@ -202,6 +240,7 @@ class ObjectAnimation extends Animation {
|
||||
}
|
||||
|
||||
inline function interpolateLinear(t: FastFloat, t1: FastFloat, t2: FastFloat, v1: FastFloat, v2: FastFloat): Null<FastFloat> {
|
||||
if (t2 == t1) return v1;
|
||||
var s = (t - t1) / (t2 - t1);
|
||||
return (1.0 - s) * v1 + s * v2;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user