Options
All
  • Public
  • Public/Protected
  • All
Menu

A Loader class which helps with loading video and image textures.

Hierarchy

  • TextureLoader

Index

Constructors

Methods

  • load(sources: string[], [options={}]?: { message: string; expireCache: boolean; maxConcurrent: number }): Promise<void[]>
  • Load an Array of provided source URL paths

    Parameters

    • sources: string[]

      The source URLs to load

    • [options={}]: { message: string; expireCache: boolean; maxConcurrent: number } = {}

      Additional options which modify loading

      • message: string
      • expireCache: boolean
      • maxConcurrent: number

    Returns Promise<void[]>

    A Promise which resolves once all textures are loaded

  • loadTexture(src: string): Promise<any>
  • Load a single texture or spritesheet on-demand from a given source URL path

    Parameters

    • src: string

      The source texture path to load

    Returns Promise<any>

    The loaded texture object

  • setCache(src: string, asset: any): void
  • Add an image or a sprite sheet url to the assets cache.

    Parameters

    • src: string

      The source URL.

    • asset: any

      The asset

    Returns void

  • getCache(src: string): any
  • Retrieve a texture or a sprite sheet from the assets cache

    Parameters

    • src: string

      The source URL

    Returns any

    The cached texture, a sprite sheet or undefined

  • expireCache(): Promise<void>
  • Expire and unload assets from the cache which have not been used for more than CACHE_TTL milliseconds.

    Returns Promise<void>

  • hasTextExtension(src: string): boolean
  • Check if a source has a text file extension.

    Parameters

    • src: string

      The source.

    Returns boolean

    If the source has a text extension or not.

  • loadSceneTextures(scene: Scene, [options={}]?: { expireCache: boolean; additionalSources: boolean; maxConcurrent: number }): Promise<void[]>
  • Load all the textures which are required for a particular Scene

    Parameters

    • scene: Scene

      The Scene to load

    • [options={}]: { expireCache: boolean; additionalSources: boolean; maxConcurrent: number } = {}

      Additional options that configure texture loading

      • expireCache: boolean
      • additionalSources: boolean
      • maxConcurrent: number

    Returns Promise<void[]>

  • fetchResource(src: string, [options]?: { bustCache: boolean }): Promise<Blob>
  • Use the Fetch API to retrieve a resource and return a Blob instance for it.

    Parameters

    • src: string
    • [options]: { bustCache: boolean } = {}

      Options to configure the loading behaviour.

      • bustCache: boolean

    Returns Promise<Blob>

    A Blob containing the loaded data

  • getCacheBustURL(src: string): string | boolean
  • Return a URL with a cache-busting query parameter appended.

    Parameters

    • src: string

      The source URL being attempted

    Returns string | boolean

    The new URL, or false on a failure.

  • #onProgress(src: string, progress: any): void
  • Log texture loading progress in the console and in the Scene loading bar

    Parameters

    • src: string

      The source URL being loaded

    • progress: any

      Loading progress

    Returns void

  • #onError(src: string, progress: any, error: Error): void
  • Log failed texture loading

    Parameters

    • src: string

      The source URL being loaded

    • progress: any

      Loading progress

    • error: Error

      The error which occurred

    Returns void

Properties

CACHE_TTL: number = ...

The duration in milliseconds for which a texture will remain cached

textureBufferDataMap: Map<string, any> = ...

A mapping of url to cached texture buffer data

#cacheTime: Map<any, { src: string; time: number }> = ...

Record the timestamps when each asset path is retrieved from cache.

#retryString: string = ...

Create a fixed retry string to use for CORS retries.