The Loader.setPath()
method is used in three.js to set a base path for all subsequent loads made by a specified loader
object. This means that if you set a base path, you don't have to specify the full path each time you load an asset.
loader.setPath( path : string ) : void
path
- Required. A string representing the base path for all subsequent loads made by the loader
object.
// create a texture loader
var textureLoader = new THREE.TextureLoader();
// set the base path for textures
textureLoader.setPath('textures/');
// load a texture using the specified base path
var texture = textureLoader.load('texture.png');
In this example, we create a TextureLoader
object and set the base path to 'textures/'
. This means that when we call textureLoader.load('texture.png')
, three.js will look for the texture file at 'textures/texture.png'
.
loader
object. If you have multiple loaders (e.g. TextureLoader
, JSONLoader
, etc.), you'll need to set the path for each one separately.setPath()
can also be used to set a relative path, such as '../textures/'
, if your assets are located in a different directory than your HTML file.loader.setPath()
with a new path
argument.