ebeaufay / threedtiles

3DTiles viewer for three.js
MIT License
270 stars 32 forks source link

No DRACOLoader instance provided with Vite #15

Closed x8BitRain closed 1 year ago

x8BitRain commented 1 year ago

I get the error THREE.GLTFLoader: No DRACOLoader instance provided when loading when using this with on a project using vite. Works fine with webpack. Something to do with this perhaps? https://github.com/mrdoob/three.js/issues/24729

Repro repo: https://github.com/x8BitRain/tiles

Are there any known workarounds? Thanks.

ebeaufay commented 1 year ago

The code looks for those wasms and accompanying code in local folders "draco-decoders/" and 'ktx2-decoders/'. So what you can do is use the equivalent of the copyPlugin from webpack to copy those two folders to your build directory:

three/examples/jsm/libs/draco -> dist/draco-decoders
three/examples/jsm/libs/basis -> dist/ktx2-decoders

If those folders aren't found, they are downloaded from internet.

If adding them to the local host still doesn't work, the problem must be deeper and possibly linked to the issue you mentioned, I've never worked with vite so I can't help you. perhaps chatGPT has heard of this :)

ebeaufay commented 1 year ago

In case this is related, DracoLoader and KTXLoader are initialized asynchronously. However, threejs doesn't provide any callback or promise mechanism to deal with it.

The result was a race condition, which is fixed in v9.1.14