ohzi-core 6.3.4 → 6.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ohzi-core",
3
- "version": "6.3.4",
3
+ "version": "6.3.5",
4
4
  "description": "OHZI Core Library",
5
5
  "source": "src/index.js",
6
6
  "module": "build/index.module.js",
@@ -1,5 +1,6 @@
1
1
 
2
2
  import { Math as TMath } from 'three';
3
+ import OMath from '../utilities/OMath';
3
4
 
4
5
  export default class ActionSequencer
5
6
  {
@@ -121,9 +122,9 @@ export default class ActionSequencer
121
122
  this.channels[interpolator.attribute_name].push(keyframe);
122
123
  }
123
124
 
124
- get_property_target_value(name)
125
+ get_current_target_value(name)
125
126
  {
126
- const keyframe = this.__get_nearest_keyframe(name, this.elapsed_time);
127
+ const keyframe = this.__get_current_keyframe(name, this.elapsed_time);
127
128
 
128
129
  if (this.elapsed_time < keyframe.from)
129
130
  {
@@ -133,6 +134,21 @@ export default class ActionSequencer
133
134
  return keyframe.interpolator.evaluate(1);
134
135
  }
135
136
 
137
+ get_current_starting_value(name)
138
+ {
139
+ const keyframe = this.__get_current_keyframe(name, this.elapsed_time);
140
+
141
+ return keyframe.interpolator.evaluate(0);
142
+ }
143
+
144
+ get_current_progress(name)
145
+ {
146
+ const keyframe = this.__get_current_keyframe(name, this.elapsed_time);
147
+ const t = this.__linear_map_01(this.elapsed_time, keyframe.from, keyframe.to);
148
+
149
+ return keyframe.interpolator.easing_function(t);
150
+ }
151
+
136
152
  get_duration()
137
153
  {
138
154
  return this.duration;
@@ -154,7 +170,8 @@ export default class ActionSequencer
154
170
  for (let i = 0; i < channel_names.length; i++)
155
171
  {
156
172
  const name = channel_names[i];
157
- const keyframe = this.__get_nearest_keyframe(name, from);
173
+ const keyframe = this.__get_current_keyframe(name, from);
174
+
158
175
  this.context[name] = this.evaluate_keyframe(keyframe, from);
159
176
  }
160
177
  }
@@ -162,6 +179,7 @@ export default class ActionSequencer
162
179
  evaluate_keyframe(keyframe, time)
163
180
  {
164
181
  this.tmp_t = this.__linear_map_01(time, keyframe.from, keyframe.to);
182
+
165
183
  return keyframe.interpolator.evaluate(TMath.clamp(this.tmp_t, 0, 1));
166
184
  }
167
185
 
@@ -174,26 +192,40 @@ export default class ActionSequencer
174
192
  from_range_start_value,
175
193
  from_range_end_value)
176
194
  {
177
- return ((value - from_range_start_value) / (from_range_end_value - from_range_start_value)) * (1 - 0) + 0;
195
+ return OMath.saturate(((value - from_range_start_value) / (from_range_end_value - from_range_start_value)) * (1 - 0) + 0);
178
196
  }
179
197
 
180
- __get_nearest_keyframe(channel_name, time)
198
+ __get_current_keyframe(channel_name, time)
181
199
  {
182
- let closest = undefined;
183
- let min_time = 9999999;
200
+ let current = undefined;
201
+
184
202
  const keyframes = this.channels[channel_name];
203
+
185
204
  for (let i = 0; i < keyframes.length; i++)
186
205
  {
187
206
  const keyframe = keyframes[i];
188
- const middle_time = (keyframe.to - keyframe.from) / 2 + keyframe.from;
189
- const distance_to_middle_time = Math.abs(time - middle_time);
190
207
 
191
- if (distance_to_middle_time < min_time)
208
+ if (time >= keyframe.from && time <= keyframe.to)
192
209
  {
193
- min_time = distance_to_middle_time;
194
- closest = keyframe;
210
+ current = keyframe;
211
+ return current;
195
212
  }
196
213
  }
197
- return closest;
214
+
215
+ let min = Infinity;
216
+
217
+ for (let i = 0; i < keyframes.length; i++)
218
+ {
219
+ const keyframe = keyframes[i];
220
+ const distance = Math.abs(keyframe.to - time);
221
+
222
+ if (distance < min)
223
+ {
224
+ current = keyframe;
225
+ min = distance;
226
+ }
227
+ }
228
+
229
+ return current;
198
230
  }
199
231
  }
@@ -19,7 +19,9 @@ export class ActionSequencer {
19
19
  is_finished(): boolean;
20
20
  add_action_event(trigger_time: any, action: any): void;
21
21
  add_action_interpolator(from: any, to: any, interpolator: any, use_dynamic_from_value?: boolean): void;
22
- get_property_target_value(name: any): any;
22
+ get_current_starting_value(name: string): number;
23
+ get_current_target_value(name: string): number;
24
+ get_current_progress(name: string): number;
23
25
  get_duration(): number;
24
26
  __play_clips(from: any, to: any): void;
25
27
  evaluate_keyframe(keyframe: any, time: any): any;