Skip to content

Commit 31a4b11

Browse files
committed
Allow holding at end of animation
1 parent 1f70fbb commit 31a4b11

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

src/js/mbvecpath_template.js

+30-10
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ divisions = span
44

55
var d1dims = 3
66
var mbjl_loop = true
7-
var vec_trails = 1
7+
var vec_trails = 10
8+
var end_wait_cycles = 4
9+
var vecs_per_sec = 1
10+
11+
var end_cycles_waited = 0
812
var firstidx = 0
913
var lastidx = 0
10-
var last_valid_baseidx = data1.length - 6
14+
var last_valid_baseidx = data1.length - 6 //need 2*3D points for a vector
1115
var prev_incrt = 0
12-
var vecs_per_sec = 1
1316
var vecs_delta_secs = 1/vecs_per_sec
1417
var incr_count = 0
1518
view
@@ -18,8 +21,13 @@ view
1821
height: dcols1,
1922
expr: function (emit, x, y, t, d) {
2023
var idx = x + y*drows1 // baseidx(x,y,t)
21-
if (idx <= last_valid_baseidx && idx >= firstidx && idx <= lastidx){
22-
if (vec_trails > 0 && incr_count > vec_trails && idx == firstidx){
24+
if (idx <= last_valid_baseidx
25+
&& idx >= firstidx && idx <= lastidx){ //controls which vectors in path are shown
26+
var lerpfraction = (t - prev_incrt)/vecs_delta_secs
27+
if (vec_trails > 0 && incr_count > vec_trails //interp/slide trailing bases in
28+
&& idx == firstidx //only the last visible base needs ot be interpolated
29+
&& end_cycles_waited == 0 //don't interpolate if holding/pausing at end of path anim
30+
&& idx + vec_trails*drows1 < last_valid_baseidx ){ //don't interpolate if it's the last base index (since we might be holding at the end)
2331
emit(
2432
mbbasic_lerp(data1[idx], data1[idx+3], lerpfraction),
2533
mbbasic_lerp(data1[idx+1], data1[idx+4], lerpfraction),
@@ -28,8 +36,7 @@ view
2836
}else{
2937
emit(data1[idx], data1[idx+1], data1[idx+2]) //bases
3038
}
31-
lerpfraction = (t - prev_incrt)/vecs_delta_secs
32-
if (idx == lastidx){
39+
if (idx == lastidx && end_cycles_waited == 0){
3340
emit(
3441
mbbasic_lerp(data1[idx], data1[idx+3], lerpfraction),
3542
mbbasic_lerp(data1[idx+1], data1[idx+4], lerpfraction),
@@ -42,11 +49,24 @@ view
4249
if (t - prev_incrt >= vecs_delta_secs){
4350
lastidx += d1dims
4451
incr_count += 1
45-
if(vec_trails >= 0 && incr_count > vec_trails) firstidx += d1dims
52+
if (vec_trails >= 0 && incr_count > vec_trails){
53+
firstidx += d1dims
54+
}
4655
prev_incrt = t
4756
if (mbjl_loop && lastidx > last_valid_baseidx){
48-
firstidx = lastidx = 0
49-
incr_count = 0
57+
if (end_cycles_waited >= end_wait_cycles){
58+
firstidx = lastidx = 0
59+
incr_count = 0
60+
end_cycles_waited = 0
61+
}else{
62+
//note after this is set we still wait a whole vecs_delta_secs
63+
//till a potential restart
64+
end_cycles_waited += 1
65+
lastidx -= d1dims
66+
if (vec_trails >= 0 && incr_count > vec_trails){
67+
firstidx -= d1dims
68+
}
69+
}
5070
}
5171
}
5272
},

0 commit comments

Comments
 (0)