Documentation - v19.16.0-dev
    Preparing search index...

    Reads the files of one format (one extension) into InputMeshes, the engine's input: what an application gives the MeshLoader (addFileReader). A reader wraps its workers: the application only writes read, run in the workers, and the line making a worker on its own module, so that it writes no worker script:

    // MyReader.ts
    export class MyReader extends FileReader {
    readonly extension = 'my';

    // Always this line, with the path of this file: the bundlers (Vite, webpack) emit a worker
    // script only from the `new Worker(new URL('...', import.meta.url))` form, written as is.
    createWorker() {
    return new Worker(new URL('./MyReader.ts', import.meta.url), { type: 'module' });
    }

    async read(url: string, options: FileReadOptions): Promise<LoadedFile> {
    ... // runs in a worker
    }
    }

    MyReader.serve(); // in a worker: reads the files sent to it

    The engine does the rest: it makes the workers at the first file, sends them the files, one at a time each. For a file, a worker answers the download progress, the header (object count), then its objects in batches of the scene's settings.loading.batchMeshes objects or sliceMs of reading at most (sent with the file), their buffers transferred (each geometry once per file).

    Index

    Constructors

    Properties

    extension: string

    Extension of the files it reads, without the dot (e.g. mgeom); any case.

    workerCount?: number

    Workers to read with, each one file at a time; default: the cores but one, at most the scene's settings.loading.maxWorkers.

    Methods

    • Makes one of its workers, on its own module (see the class): the engine calls it at the first file, for each worker of the reader.

      Returns LoadingWorkerLike

    • Reads the file at url, in a worker: downloads it (e.g. with fetchFile), reads its header; its objects come with meshes(). Rejects when it is not of this format.

      Parameters

      Returns Promise<LoadedFile>

    • In a worker made by createWorker, makes a reader of this class (no constructor argument) and reads the files the engine sends it. Called at the bottom of the reader's module: does nothing on the main thread.

      Parameters

      • this: new () => FileReader
      • Optionalscope: LoadingScope

        Where the files come from; default: the worker's global scope, when in one.

      Returns void