ohzi-core 6.3.3 → 6.3.6

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.3",
3
+ "version": "6.3.6",
4
4
  "description": "OHZI Core Library",
5
5
  "source": "src/index.js",
6
6
  "module": "build/index.module.js",
package/src/Graphics.js CHANGED
@@ -25,18 +25,20 @@ class Graphics
25
25
  this.canvas_context = undefined;
26
26
  this.context_attributes = undefined;
27
27
 
28
- this.context_attributes = context_attributes || {
28
+ this.context_attributes = {
29
29
  alpha: true,
30
30
  depth: true,
31
31
  desynchronized: false,
32
32
  stencil: false,
33
33
  antialias: false,
34
34
  premultipliedAlpha: true,
35
- preserveDrawingBuffer: false,
35
+ preserveDrawingBuffer: true,
36
36
  powerPreference: 'high-performance',
37
37
  logarithmicDepthBuffer: false
38
38
  };
39
39
 
40
+ Object.assign(this.context_attributes, context_attributes);
41
+
40
42
  if (context_attributes.force_webgl2)
41
43
  {
42
44
  this.canvas_context = canvas.getContext('webgl2', this.context_attributes) ||
@@ -57,6 +59,7 @@ class Graphics
57
59
  canvas: canvas,
58
60
  context: this.canvas_context
59
61
  });
62
+
60
63
  this._renderer.autoClear = false;
61
64
 
62
65
  this._renderer.setPixelRatio(1);
@@ -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
 
@@ -170,30 +188,59 @@ export default class ActionSequencer
170
188
  return this.channels[channel_name];
171
189
  }
172
190
 
191
+ is_channel_redefined(channel_name)
192
+ {
193
+ for (let i = 0; i < this.channels[channel_name].length; i++)
194
+ {
195
+ const keyframe = this.channels[channel_name][i];
196
+
197
+ if (keyframe.interpolator.initial)
198
+ {
199
+ return false;
200
+ }
201
+ }
202
+
203
+ return true;
204
+ }
205
+
173
206
  __linear_map_01(value,
174
207
  from_range_start_value,
175
208
  from_range_end_value)
176
209
  {
177
- return ((value - from_range_start_value) / (from_range_end_value - from_range_start_value)) * (1 - 0) + 0;
210
+ return OMath.saturate(((value - from_range_start_value) / (from_range_end_value - from_range_start_value)) * (1 - 0) + 0);
178
211
  }
179
212
 
180
- __get_nearest_keyframe(channel_name, time)
213
+ __get_current_keyframe(channel_name, time)
181
214
  {
182
- let closest = undefined;
183
- let min_time = 9999999;
215
+ let current = undefined;
216
+
184
217
  const keyframes = this.channels[channel_name];
218
+
185
219
  for (let i = 0; i < keyframes.length; i++)
186
220
  {
187
221
  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
222
 
191
- if (distance_to_middle_time < min_time)
223
+ if (time >= keyframe.from && time <= keyframe.to)
192
224
  {
193
- min_time = distance_to_middle_time;
194
- closest = keyframe;
225
+ current = keyframe;
226
+ return current;
195
227
  }
196
228
  }
197
- return closest;
229
+
230
+ let min = Infinity;
231
+
232
+ for (let i = 0; i < keyframes.length; i++)
233
+ {
234
+ const keyframe = keyframes[i];
235
+ const distance = Math.abs(keyframe.to - time);
236
+
237
+ if (distance < min)
238
+ {
239
+ current = keyframe;
240
+ min = distance;
241
+ }
242
+ }
243
+
244
+ return current;
198
245
  }
199
246
  }
@@ -3,13 +3,14 @@ import { Math as TMath } from 'three';
3
3
 
4
4
  export default class NumberInterpolator extends ActionInterpolator
5
5
  {
6
- constructor(attribute_name, from = 0, to = 1, easing_function = 'linear')
6
+ constructor(attribute_name, from = 0, to = 1, initial = false, easing_function = 'linear')
7
7
  {
8
8
  super(easing_function);
9
9
 
10
10
  this.attribute_name = attribute_name;
11
11
  this.from = from;
12
12
  this.to = to;
13
+ this.initial = initial;
13
14
  }
14
15
 
15
16
  update(context, t)
@@ -31,7 +31,14 @@ export default class ActionSequencerBuilder
31
31
  for (let i = 0; i < tracks.length; i++)
32
32
  {
33
33
  const t = tracks[i];
34
- const interpolator = new NumberInterpolator(t.attribute_name, current_context[t.attribute_name], t.to_value, t.easing_function);
34
+ const interpolator = new NumberInterpolator(
35
+ t.attribute_name,
36
+ current_context[t.attribute_name],
37
+ t.to_value,
38
+ t.initial,
39
+ t.easing_function
40
+ );
41
+
35
42
  sequencer.add_action_interpolator(t.from_time, t.to_time, interpolator, true);
36
43
  }
37
44
 
@@ -58,6 +65,7 @@ export default class ActionSequencerBuilder
58
65
  from_time: 0,
59
66
  to_time: 1,
60
67
  to_value: state[keys[i]],
68
+ initial: true,
61
69
  easing_function: 'ease_in_out_cubic'
62
70
  });
63
71
  }
@@ -75,7 +83,14 @@ export default class ActionSequencerBuilder
75
83
  for (let i = 0; i < tracks.length; i++)
76
84
  {
77
85
  const t = tracks[i];
78
- const interpolator = new NumberInterpolator(t.attribute_name, context[t.attribute_name], t.to_value, t.easing_function);
86
+ const interpolator = new NumberInterpolator(
87
+ t.attribute_name,
88
+ context[t.attribute_name],
89
+ t.to_value,
90
+ t.initial,
91
+ t.easing_function
92
+ );
93
+
79
94
  sequencer.add_action_interpolator(t.from_time, t.to_time, interpolator, true);
80
95
  }
81
96
 
@@ -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;