Skip to content

Commit

Permalink
Add forgotten comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gkjohnson committed Dec 25, 2023
1 parent 836ddf7 commit d799c61
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions example/src/FadeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class FadeManager {

}

// delete the object from the fade, reset the material data
deleteObject( object ) {

if ( ! object ) {
Expand All @@ -36,13 +37,17 @@ export class FadeManager {

}

this._fadeParams.delete( object );
this.completeFade( object );

const fadeParams = this._fadeParams;
object.traverse( child => {

const material = child.material;
if ( material ) {

this._fadeParams.delete( material );
fadeParams.delete( material );
material.onBeforeCompile = null;
material.needsUpdate = true;

}

Expand Down Expand Up @@ -124,7 +129,6 @@ export class FadeManager {
#endif
` );


Expand All @@ -134,6 +138,8 @@ export class FadeManager {

}

// Ensure we're storing a fade timer for the provided object
// Returns whether a new state had to be added
guaranteeState( object ) {

const fadeState = this._fadeState;
Expand Down Expand Up @@ -170,6 +176,7 @@ export class FadeManager {

}

// Force the fade to complete in the direction it is already trending
completeFade( object ) {

const fadeState = this._fadeState;
Expand All @@ -192,6 +199,7 @@ export class FadeManager {

}

// Fade the object in
fadeIn( object ) {

this.guaranteeState( object );
Expand All @@ -203,6 +211,7 @@ export class FadeManager {

}

// Fade the object out
fadeOut( object ) {

const noState = this.guaranteeState( object );
Expand All @@ -217,10 +226,17 @@ export class FadeManager {

}

// Tick the fade timer for each actively fading object
update() {

// clamp delta in case duration is really small or 0
const time = window.performance.now();
if ( this._lastTick === - 1 ) {

this._lastTick = time;

}

const delta = clamp( ( time - this._lastTick ) / this.duration, 0, 1 );
this._lastTick = time;

Expand Down

0 comments on commit d799c61

Please sign in to comment.