import { assert , MathUtils } from "@here/harp-utils" ; import * as THREE from "three" ; /**
 * State of fading.
 */ export enum FadingState { Undefined = 0 , FadingIn = 1 , FadedIn = 2 , FadingOut = - 1 , FadedOut = - 2 } /**
 * Time to fade in/fade out the labels in milliseconds.
 */ export const DEFAULT_FADE_TIME = 800 ; hidden export class RenderState { /**
     * Current fading value [0..1]
     */ value : number = 0.0 ; /**
     * Timestamp the fading started.
     */ startTime : number = 0 ; /**
     * Computed opacity depending on value.
     */ opacity : number = 0.0 ; private m_state = FadingState . Undefined ; param fadeTime constructor ( public fadeTime = DEFAULT_FADE_TIME ) { } /**
     * Reset existing `RenderState` to appear like a fresh state.
     */ reset ( ) { this . m_state = FadingState . Undefined ; this . value = 0.0 ; this . startTime = 0.0 ; this . opacity = 0.0 ; } returns isUndefined ( ) { return this . m_state === FadingState . Undefined ; } returns isFading ( ) { const fading = this . m_state === FadingState . FadingIn || this . m_state === FadingState . FadingOut ; return fading ; } returns isFadingIn ( ) { const fadingIn = this . m_state === FadingState . FadingIn ; return fadingIn ; } returns isFadingOut ( ) { const fadingOut = this . m_state === FadingState . FadingOut ; return fadingOut ; } returns isFadedIn ( ) { const fadedIn = this . m_state === FadingState . FadedIn ; return fadedIn ; } returns isFadedOut ( ) { const fadedOut = this . m_state === FadingState . FadedOut ; return fadedOut ; } returns isVisible ( ) { return ( this . m_state !== FadingState . FadedOut && this . m_state !== FadingState . Undefined && this . opacity > 0 ) ; } param time param disableFading startFadeIn ( time , disableFading ? ) { if ( this . m_state === FadingState . FadingIn || this . m_state === FadingState . FadedIn ) { return ; } if ( disableFading === true ) { this . value = 1 ; this . opacity = 1 ; this . m_state = FadingState . FadedIn ; this . startTime = time ; return ; } if ( this . m_state === FadingState . FadingOut ) { this . value = 1.0 - this . value ; this . startTime = time - this . value * this . fadeTime ; } else { this . startTime = time ; this . value = 0.0 ; this . opacity = 0 ; } this . m_state = FadingState . FadingIn ; } param time startFadeOut ( time ) { if ( this . m_state === FadingState . FadingOut || this . m_state === FadingState . FadedOut || this . m_state === FadingState . Undefined ) { return ; } if ( this . m_state === FadingState . FadingIn ) { this . startTime = time - this . value * this . fadeTime ; this . value = 1.0 - this . value ; } else { this . startTime = time ; this . value = 0.0 ; this . opacity = 1 ; } this . m_state = FadingState . FadingOut ; } param time param disableFading updateFading ( time , disableFading ) { if ( this . m_state !== FadingState . FadingIn && this . m_state !== FadingState . FadingOut ) { return ; } if ( this . startTime === 0 ) { this . startTime = time ; } const fadingTime = time - this . startTime ; const startValue = this . m_state === FadingState . FadingIn ? 0 : 1 ; const endValue = this . m_state === FadingState . FadingIn ? 1 : 0 ; if ( disableFading || fadingTime >= this . fadeTime ) { this . value = 1.0 ; this . opacity = endValue ; this . m_state = this . m_state === FadingState . FadingIn ? FadingState . FadedIn : FadingState . FadedOut ; } else { this . value = fadingTime / this . fadeTime ; this . opacity = THREE . MathUtils . clamp ( MathUtils . smootherStep ( startValue , endValue , this . value ) , 0 , 1 ) ; assert ( this . isFading ( ) ) ; } } }