babylon.quarks - v1.0.0
    Preparing search index...

    Class QuarksLoader

    Loads effects saved as JSON into a scene: fetches the document and the geometry and image files it links, builds the nodes, particle systems, textures and materials, and returns the root. Add the systems to a BatchedRenderer with QuarksUtil.addToBatchRenderer to draw them, and free the effect with QuarksLoader.disposeEffect.

    const loader = new QuarksLoader(scene, {waitForTextures: true});
    const effect = await loader.load('effects/fireball.json');
    QuarksUtil.addToBatchRenderer(effect, renderer);
    QuarksUtil.play(effect);
    Index
    • Loads many effects in parallel for battle / level preload. Phase 1 fetches every effect JSON (optionally concurrency-limited); phase 2 resolves all linked geometries/images across the pack together so shared asset urls hit the fetch cache once; phase 3 parses.

      Parameters

      Returns Promise<TransformNode[]>

      const roots = await loader.loadAll([
      'fx/hit.json', 'fx/explosion.json', 'fx/heal.json',
      ], { concurrency: 6, continueOnError: true });
    • Loads many effects in parallel for battle / level preload. Phase 1 fetches every effect JSON (optionally concurrency-limited); phase 2 resolves all linked geometries/images across the pack together so shared asset urls hit the fetch cache once; phase 3 parses.

      Parameters

      Returns Promise<(TransformNode | null)[]>

      const roots = await loader.loadAll([
      'fx/hit.json', 'fx/explosion.json', 'fx/heal.json',
      ], { concurrency: 6, continueOnError: true });
    • Resolves linked geometry / image urls (via resolveResources) then parses. Use when the effect JSON is already in hand (File, CDN payload, editor import). json is an EffectDocumentJSON as parsed from its file; anything else throws QuarksFormatError, and a part of the wrong kind warns. json itself is left as it was, so the same document can be loaded again, into another scene or with another base url.

      Parameters

      Returns Promise<TransformNode>

    • Builds the node tree of an effect document whose linked files are already inline (see loadFromJSON). baseUrl is joined to relative image urls. Parts the loader cannot read warn and take their defaults; a document with no object throws QuarksFormatError. Free the effect with disposeEffect.

      Parameters

      • json: unknown
      • baseUrl: string = ''

      Returns TransformNode

    • Inlines external geometry files and rewrites relative image urls through the loader's QuarksResourceResolver, in place on json. Each document is resolved once: geometries already inlined and image urls this method already rewrote are left alone, so loading the same document again does not join its base url twice. Failures warn and leave the entry as is.

      Parameters

      • json: unknown
      • baseUrl: string = ''

      Returns Promise<void>

    • Disposes an effect a loader built: its nodes and systems, the materials made for it, and each texture it uses once no other loaded effect uses it (textures are shared per scene, see QuarksLoaderOptions.shareResources). Copies made with QuarksUtil.instantiate hold the textures too, so disposing the source effect leaves them drawing. The same happens when the root is disposed any other way (root.dispose(), its parent's dispose, the scene's). The materials and textures are freed even when other code was handed them; give that code its own. For a root the loader did not build, this is root.dispose().

      Parameters

      • root: TransformNode

      Returns void

    • Joins baseUrl with a relative url; leaves data/blob/absolute/root-absolute urls alone.

      Parameters

      • baseUrl: string
      • url: string

      Returns string

    • Inlines geometries that an export wrote to their own file ({uuid, type: 'QuarksGeometry', url}). Prefer load, loadFromJSON, or resolveResources — those use the loader's resolver and fetch cache. Kept for callers that already have a custom loadGeometry and no QuarksLoader instance.

      Parameters

      • json: unknown
      • loadGeometry: (url: string) => Promise<unknown>

      Returns Promise<void>

    • Same as instance resolveResources, but usable without constructing a loader (e.g. editor import that only prepares JSON). Pass scene to share the per-scene fetch cache. Like it, resolves each document once. A geometry file that fails to load goes to onResourceError (default: a console warning) and keeps its link.

      Parameters

      Returns Promise<void>