ohzi-core 6.3.4 → 6.4.0
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/build/index.module.js +1 -1
- package/build/index.module.js.map +1 -1
- package/package.json +1 -1
- package/src/action_sequencer/ActionSequencer.js +60 -13
- package/src/action_sequencer/NumberInterpolator.js +2 -1
- package/src/resource_loader/BasisLoader.js +1 -9
- package/src/resource_loader/TextureLoader.js +5 -0
- package/src/view_components/transition/ActionSequencerBuilder.js +17 -2
- package/types/action_sequencer/ActionSequencer.d.ts +3 -1
package/package.json
CHANGED
|
@@ -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
|
-
|
|
125
|
+
get_current_target_value(name)
|
|
125
126
|
{
|
|
126
|
-
const keyframe = this.
|
|
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.
|
|
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
|
-
|
|
213
|
+
__get_current_keyframe(channel_name, time)
|
|
181
214
|
{
|
|
182
|
-
let
|
|
183
|
-
|
|
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 (
|
|
223
|
+
if (time >= keyframe.from && time <= keyframe.to)
|
|
192
224
|
{
|
|
193
|
-
|
|
194
|
-
|
|
225
|
+
current = keyframe;
|
|
226
|
+
return current;
|
|
195
227
|
}
|
|
196
228
|
}
|
|
197
|
-
|
|
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)
|
|
@@ -4,19 +4,11 @@ import { sRGBEncoding } from 'three';
|
|
|
4
4
|
|
|
5
5
|
export default class BasisLoader extends AbstractLoader
|
|
6
6
|
{
|
|
7
|
-
constructor(resource_id, url,
|
|
7
|
+
constructor(resource_id, url, loader, size)
|
|
8
8
|
{
|
|
9
9
|
super(resource_id, url, size);
|
|
10
10
|
|
|
11
11
|
this.loader = loader;
|
|
12
|
-
|
|
13
|
-
this.loader.setWorkerLimit(1);
|
|
14
|
-
|
|
15
|
-
this.loader.setTranscoderPath(
|
|
16
|
-
'libs/basis/'
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
this.loader.detectSupport(renderer);
|
|
20
12
|
}
|
|
21
13
|
|
|
22
14
|
on_preloaded_finished(resource_container)
|
|
@@ -30,6 +30,11 @@ export default class TextureLoader extends AbstractLoader
|
|
|
30
30
|
this.__update_downloaded_bytes(1, 1);
|
|
31
31
|
this.__loading_ended();
|
|
32
32
|
};
|
|
33
|
+
|
|
34
|
+
image.onerror = () =>
|
|
35
|
+
{
|
|
36
|
+
console.error('Error loading texture. Maybe the resource is not an image?', this.url);
|
|
37
|
+
};
|
|
33
38
|
});
|
|
34
39
|
}
|
|
35
40
|
}
|
|
@@ -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(
|
|
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(
|
|
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
|
-
|
|
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;
|