Closed playbyan1453 closed 1 week ago
You can try it like this
generator.worker = new Worker(workerUrl);
Haven't tried that, but still not working somehow. It returns same error, probably it's the way I hosted the project and missing something with npm packages.
The reason for this problem is that the URL for initializing the worker in the constructor of GenerateMeshBVHWorker is incorrect. You can initialize the worker externally and then assign it to the worker property of GenerateMeshBVHWorker.
Unfortunately web workers seem to give very poor errors when running into issues.
import { GenerateMeshBVHWorker } from './scripts/workers/GenerateMeshBVHWorker.js';
Without understanding your whole file structure it's difficult but if you've copied this worker to your local directory you'll need to make sure that this generateAsync.worker.js file is copied to the same directory in the correct relative file location, as well.
It is kinda fixed now updating the importmap
to
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three/build/three.module.min.js",
"three/examples/jsm/": "https://unpkg.com/three/examples/jsm/",
"three-mesh-bvh": "https://unpkg.com/three-mesh-bvh/build/index.module.js",
"three-mesh-bvh/src/workers/": "https://unpkg.com/three-mesh-bvh/src/workers/"
}
}
</script>
and change the gpuPathTracingSimple.js
import path to three-mesh-bvh
, but now I cannot access the async because I have not set CORS header yet.
now I cannot access the async because I have not set CORS header yet.
Yes browsers do not let you load workers from remote urls. This browser limitation is why the files need to be copied to your own server. You need to copy all the files in the "workers" directory and make sure that the worker path in the "GenerateMeshBVHWorker" class is correctly pointing to your local "generateAsync.worker.js" file. From there I recommend adding print statements to both files and checking the network tab to make sure they're both loading correctly first.
Both were loaded, while trying to do the first method like generator.worker = new Worker(workerUrl);
printing it to the console seems like has no difference with the original worker and pointing it to the local file basically doing things from the start.
If you provide a zip directory in addition to how you're running a local serve I can take a look if it's still not working.
As today I forgot about this, Basically I created a new project then installed three, three-mesh-bvh, and run it using npm run dev
command, thinking about building my project it seems it had circular dependency loop which vite does not support because I give the import to /node_modules/three-mesh-bvh/src/workers/ParallelMeshBVHWorker.js
.
If I understand GenerateMeshBVHWorker do not have this issue when building, because in the parallelMeshBVH.worker.js
line 12 seems like the culprit because it gives depends on itself.
The provided zip project works just fine for me.
in the parallelMeshBVH.worker.js line 12 seems like the culprit because it gives depends on itself.
I'm not seeing any issues with vite but either way this is a valid dependency for creating a new worker. If there are issues with certain build setups it should be reported with the bundler.
ah okay thank you
so this was a problem with vite.
Describe the bug
Initializing GenerateMeshBVHWorker resulting on error even when I not using it, also I'm not really sure if this even a bug. When using generate method resulting on undefined error too. I am very new to the Node js and stuffs I wanted to make my own path tracer in three js and the basic ray tracer is done but I wanted parallelized computing of the BVH in case I tried to use denser meshes I also followed the examples but still no luck. Also trying to run the examples locally and installing node.js with npm is not working too. And I tried to run mozilla worker example and running it locally and it is working as intended.
To Reproduce
Steps to reproduce the behavior:
Code
the
gpuPathTracingSimple.js
The full script
Live example
-
Expected behavior
The BVH Should generated and the data sent to GPU
Screenshots
Platform: