loader.ts 650 B

1234567891011121314151617
  1. import type { LoaderSettings } from './types'
  2. export const DEFAULT_LOADER: LoaderSettings = { textures: true, shaders: true, threads: 0 }
  3. export const MAX_LOADER_THREADS = 64
  4. export function clampLoaderThreads(threads: unknown): number {
  5. return Number.isInteger(threads) ? Math.min(Math.max(threads as number, 0), MAX_LOADER_THREADS) : DEFAULT_LOADER.threads
  6. }
  7. export function normalizeLoader(loader: Partial<LoaderSettings> | null | undefined): LoaderSettings {
  8. return {
  9. textures: loader?.textures ?? DEFAULT_LOADER.textures,
  10. shaders: loader?.shaders ?? DEFAULT_LOADER.shaders,
  11. threads: clampLoaderThreads(loader?.threads)
  12. }
  13. }