loaders.gl icon indicating copy to clipboard operation
loaders.gl copied to clipboard

[Bug] Unable to use local Draco files/library on vite project via GLTFLoader

Open matthew-rimmer opened this issue 1 year ago • 4 comments

Loader

GLTFLoader

Description

I am unable to prevent the GLTFLoader from requesting the JS/WASM from either the unpkg or gstatic URLs when using a Draco model in Vite. I have tried the two methods on the docs:

setLoaderOptions({
    modules: {
        draco3d,
    },
});

setLoaderOptions({
  modules: {
    "draco_wasm_wrapper.js": dracoWasmWrapper,
    "draco_decoder.wasm": dracoWasm,
  },
});

And neither seem to pull the local version. This seems to happen regardless of providing a local worker via workerUrl or using the CDN one.

I noticed that when stepping through the code that the Draco3D library was lost by the time it got to the Draco parse. Could this line be related?

Expected Behavior

Be able to use Draco locally without requesting any files from CDNs

Steps to Reproduce

Minimum steps in this codesandbox: https://codesandbox.io/p/devbox/reverent-bogdan-3hy7kd View the network tab and refresh

Environment

  • Framework version: 4.3.3
  • Browser: Edge
  • Node: v20.18.2
  • OS: Windows

Logs

No response

matthew-rimmer avatar Feb 14 '25 11:02 matthew-rimmer

Try setting worker: false. (the imported module cannot be passed from the main thread to the worker thread.)

ibgreen avatar Feb 19 '25 13:02 ibgreen

Doing it like so:

setLoaderOptions({
  modules: {
    draco3d,
  },
});

const loadedModel = await load(model, GLTFLoader, { worker: false });

Seems to try and get the wasm from just the root of the server. On localhost it requests it from here

http://localhost:5173/draco_decoder.wasm

Which won't work if you've just got draco3d as a package.

And when I try to use local files gotten from the draco repo like so:

import dracoWasmWrapper from "./static_files/draco_wasm_wrapper.js?url";
import dracoWasm from "./static_files/draco_decoder.wasm?url";
...
setLoaderOptions({
  modules: {
    "draco_wasm_wrapper.js": dracoWasmWrapper,
    "draco_decoder.wasm": dracoWasm,
  },
});

const loadedModel = await load(model, GLTFLoader, { worker: false });

It requests them from the gstatic url

https://www.gstatic.com/draco/versioned/decoders/1.5.6/draco_decoder.wasm

matthew-rimmer avatar Feb 19 '25 20:02 matthew-rimmer

We are running into similar issues with using this library in our own library, iTwin.js.

This method is incomplete, it only allows you to provide an instance of the draco3d lib or will auto fetch from the cdn

aruniverse avatar Sep 12 '25 20:09 aruniverse

This method is incomplete, it only allows you to provide an instance of the draco3d lib or will auto fetch from the cdn

An update, we're able to resolve this by not importing the local draco assets ourselves, but instead by passing in the urls we'd like loaders.gl to use to fetch the assets. The libraryUrl variable in loaders.gl's loadLibrary() method expects strictly a url, and not the module itself

hl662 avatar Sep 16 '25 20:09 hl662