Hi,
I use the following call to load a material map texture:
import image01 from ‘…/textures/image01.jpg’;
Later in my code I use the following call to load the texture:
const texture = new THREE.TextureLoader().load(image01)
That works as expected.
But, I have a huge amount of images and I would like to load them at runtime in a function.
I tried the following, but without success:
let image02= await import(‘…/textures/image02.jpg’)
I get the message: Uncaught (in promise) Error: Cannot find module ‘…/textures/image02.jpg’
Depends on what webserver you’re using- usually you can put the textures inside a public folder and fetch them from there by just setting loader to ex. “textures/texture1.png” (when the actual texture file is under public/textures/texture.1.png path)
Generally speaking - it’s not much useful to import / require static files.
I am using it on a hosted webserver with a wordpress environment.
My code is bundled with webpack.
How can I create a public folder?
When I debug my webpage I can see the images…
Using the import statement tells webpack to find a js module to inject in your code at buildtime.
You can use ES6 runtime imports by telling webpack to ignore that import and leave it to runtime. import(/* webpackIgnore: true */ https://path.to/file)
However in this case using the fetch api will probably help you out a lot more.