Skip to content

Commit

Permalink
Improve ActionSequencer
Browse files Browse the repository at this point in the history
fedegratti committed Jun 28, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 21c1f8a commit 19289c4
Showing 4 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v5.9.6
v5.9.7
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ohzi-core",
"version": "5.9.6",
"version": "5.9.7",
"description": "OHZI Core Library",
"module": "build/index.module.js",
"source": "src/index.js",
48 changes: 30 additions & 18 deletions src/action_sequencer/ActionSequencer.js
Original file line number Diff line number Diff line change
@@ -79,31 +79,43 @@ export default class ActionSequencer
{
if (use_dynamic_from_value)
{
let actions = this.channels[interpolator.attribute_name];
let keyframes = this.channels[interpolator.attribute_name];

if (actions === undefined)
if (keyframes === undefined)
{
console.error(`${interpolator.attribute_name} missing in initial state data.`);
}

if (actions.length === 0)
if (keyframes.length === 0)
{
interpolator.from = this.initial_context[interpolator.attribute_name];
}
else
{
interpolator.from = actions[actions.length - 1].interpolator.to;
interpolator.from = keyframes[keyframes.length - 1].interpolator.to;
}
}

let action = {
let keyframe = {
from: from,
to: to,
interpolator: interpolator
};

this.duration = Math.max(this.duration, to);
this.channels[interpolator.attribute_name].push(action);
this.channels[interpolator.attribute_name].push(keyframe);
}

get_property_target_value(name)
{
let keyframe = this.__get_nearest_keyframe(name, this.elapsed_time);

if (this.elapsed_time < keyframe.from)
{
return keyframe.interpolator.evaluate(0);
}

return keyframe.interpolator.evaluate(1);
}

get_duration()
@@ -127,15 +139,15 @@ export default class ActionSequencer
for (let i = 0; i < channel_names.length; i++)
{
let name = channel_names[i];
let action = this.__get_nearest_action_interpolator(name, from);
this.context[name] = this.evaluate_action_interpolator(action, from);
let keyframe = this.__get_nearest_keyframe(name, from);
this.context[name] = this.evaluate_keyframe(keyframe, from);
}
}

evaluate_action_interpolator(action_interpolator, time)
evaluate_keyframe(keyframe, time)
{
this.tmp_t = this.__linear_map_01(time, action_interpolator.from, action_interpolator.to);
return action_interpolator.interpolator.evaluate(TMath.clamp(this.tmp_t, 0, 1));
this.tmp_t = this.__linear_map_01(time, keyframe.from, keyframe.to);
return keyframe.interpolator.evaluate(TMath.clamp(this.tmp_t, 0, 1));
}

__linear_map_01(value,
@@ -145,23 +157,23 @@ export default class ActionSequencer
return ((value - from_range_start_value) / (from_range_end_value - from_range_start_value)) * (1 - 0) + 0;
}

__get_nearest_action_interpolator(channel_name, time)
__get_nearest_keyframe(channel_name, time)
{
let closest = undefined;
let min_time = 9999999;
let actions = this.channels[channel_name];
for (let i = 0; i < actions.length; i++)
let keyframes = this.channels[channel_name];
for (let i = 0; i < keyframes.length; i++)
{
let action = actions[i];
let keyframe = keyframes[i];
let difference = Math.min(
Math.abs(action.from - time),
Math.abs(action.to - time)
Math.abs(keyframe.from - time),
Math.abs(keyframe.to - time)
);

if (difference < min_time)
{
min_time = difference;
closest = action;
closest = keyframe;
}
}
return closest;
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ export default class ViewStateTransitionHandler
if (this.transitioning)
{
this.action_sequencer.update(Time.delta_time);
this.current_state.update_transition(this.current_state_data, this.action_sequencer.get_progress());
this.current_state.update_transition(this.current_state_data, this.action_sequencer.get_progress(), this.action_sequencer);

if (this.action_sequencer.is_finished())
{

0 comments on commit 19289c4

Please sign in to comment.