@needle-tools/engine 4.11.0-next.cc37c71 → 4.11.1

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.
@@ -125,12 +125,19 @@ export class ScrollFollow extends Behaviour {
125
125
  private _current_value: number = 0;
126
126
  private _target_value: number = 0;
127
127
  private _appliedValue: number = -1;
128
+ private _needsUpdate = false;
129
+ private _firstUpdate = false;
130
+
131
+ awake() {
132
+ this._firstUpdate = true;
133
+ }
128
134
 
129
135
 
130
136
  /** @internal */
131
137
  onEnable() {
132
138
  window.addEventListener("wheel", this.updateCurrentScrollValue, { passive: true });
133
139
  this._appliedValue = -1;
140
+ this._needsUpdate = true;
134
141
  }
135
142
 
136
143
  /** @internal */
@@ -144,7 +151,7 @@ export class ScrollFollow extends Behaviour {
144
151
  this.updateCurrentScrollValue();
145
152
 
146
153
  if (this._target_value >= 0) {
147
- if (this.damping > 0) { // apply damping
154
+ if (this.damping > 0 && !this._firstUpdate) { // apply damping
148
155
  this._current_value = Mathf.lerp(this._current_value, this._target_value, this.context.time.deltaTime / this.damping);
149
156
  if (Math.abs(this._current_value - this._target_value) < 0.001) {
150
157
  this._current_value = this._target_value;
@@ -155,8 +162,10 @@ export class ScrollFollow extends Behaviour {
155
162
  }
156
163
  }
157
164
 
158
- if (this._current_value !== this._appliedValue) {
165
+ if (this._needsUpdate || this._current_value !== this._appliedValue)
166
+ {
159
167
  this._appliedValue = this._current_value;
168
+ this._needsUpdate = false;
160
169
 
161
170
  let defaultPrevented = false;
162
171
  if (this.changed.listenerCount > 0) {
@@ -189,6 +198,8 @@ export class ScrollFollow extends Behaviour {
189
198
  console.debug(`[ScrollFollow] ${this._current_value.toFixed(5)} — ${(this._target_value * 100).toFixed(0)}%, targets [${Array.isArray(this.target) ? this.target.length : 1}]`);
190
199
  }
191
200
  }
201
+
202
+ this._firstUpdate = false;
192
203
  }
193
204
  }
194
205
 
@@ -404,13 +415,18 @@ export class ScrollFollow extends Behaviour {
404
415
  time += diff * weight;
405
416
  }
406
417
  }
407
- if (this.damping <= 0) {
418
+ if (this.damping <= 0 || this._firstUpdate) {
408
419
  director.time = time;
409
420
  }
410
421
  else {
411
422
  director.time = Mathf.lerp(director.time, time, this.context.time.deltaTime / this.damping);
412
423
  }
413
424
 
425
+ const delta = Math.abs(director.time - time);
426
+ if (delta > .001) { // if the time is > 1/100th of a second off we need another update
427
+ this._needsUpdate = true;
428
+ }
429
+
414
430
  if (debug && this.context.time.frame % 30 === 0) {
415
431
  console.log(`[ScrollFollow ] Timeline ${director.name}: ${time.toFixed(3)}`, weightsArray.map(w => `[${w.name} ${(w.weight * 100).toFixed(0)}%]`).join(", "));
416
432
  }