Error when passing ammo.js path
fsdiogo opened this issue · comments
Hey,
I've installed ammo.js with npm and did the following:
new PHYSICS.WorldModule({
ammo: '../node_modules/ammo.js/ammo.js'
}),
I'm getting this error:
Uncaught DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The URL '../node_modules/ammo.js/ammo.js' is invalid.
I've also tried with unpkg:
new PHYSICS.WorldModule({
ammo: 'https://unpkg.com/ammo.js@0.0.10/ammo.js'
}),
And got this:
Uncaught TypeError: Ammo is not a constructor
Can you give me an example of how to do this?
Thanks!
Hey, @fsdiogo, looks like you use ammo.js instead of latest “ammonext”. This means you’re using an unsupported one.
Please check the vendor/ folder in physics module for latest ammo.js file
Hi @sasha240100, it seems that the vendor/
folder isn't published to npm. Can you show me how to import it?
That first method doesn't work because the vendor/
folder isn't there.
I've downloaded the file and tried importing it directly but it gives me:
Uncaught DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The URL '<absolute_url>/ammo.js' is invalid.
The absolute_url
is the absolute url, as the name suggests. The URL is valid, when I open it in a browser the file is there.
@fsdiogo Yeah, but what is <absolute_url>
? Is it a template variable or what?
It was just a placeholder, sorry. In my code I have /Users/diogo/whs/ammo.js
, so the error is
Uncaught DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The URL '/Users/diogo/whs/ammo.js' is invalid.
@fsdiogo Seems like worker origin error. Run a local server and try to do it so:
new PHYSICS.WorldModule({
ammo: window.origin + '/path/to/ammo.js'
})
I would recommend you to extract ammo.js
from npm folder to something like vendor/
or public/
Really sorry for late response:( *Missed msg notification.
Hey @sasha240100, no worries 👍
That solved it, thanks!
Hi, I'm getting the same error, even when I try with:
new PHYSICS.WorldModule({
gravity: new THREE.Vector3(0, -10, 0),
ammo: 'https://github.com/WhitestormJS/physics-module-ammonext/blob/master/vendor/ammo.js'
})
ReferenceError: Ammo is not defined
at Object.public_functions.init
It is finding the file and is able to load it, but says Ammo is not defined?
By the way, why are we not allowed to import it normally and just pass the object in?
EDIT:
Hosting it locally using a basic python webserver does work - I was also able to include as a static file via webpack.
Hi, I'm facing the same issue trying to implement Physics into a Vue project, so far I've tried without success :
new PHYSICS.WorldModule({
gravity: new THREE.Vector3(0, -10, 0),
ammo: "~/assets/js/ammo.js",
}),
I've also tried with the full path :
new PHYSICS.WorldModule({
gravity: new THREE.Vector3(0, -10, 0),
ammo: "./node_modules/physics-module-ammonext/vendor/ammo.js",
}),
and reference path :
new PHYSICS.WorldModule({
ammo:
"https://cdn.rawgit.com/WhitestormJS/physics-module-ammonext/75634e80/vendor/ammo.js",
}),
Always returning the error :
Uncaught DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The URL '~/assets/js/ammo.js' is invalid
Any idea how would it be possible to fix this within Vue views Router ?
Regards,