I've been trying to add three.js to a React project and have mostly been successful. I can't, however, figure out why my texture images aren't loading. I'm running my own local server, have added a callback method to run when loading is complete, and have tried loading my images from multiple locations, but so far nothing has worked.
My images are stored in public/animation/js/img/texture1.png, and my animation file in public/animation/js/animation.js, and hereś the code I'm working with right now:
const Pilot = function () {
let faceMaterial;
const geometry = new THREE.CircleGeometry(10, 128);
const manager = new THREE.LoadingManager();
manager.onStart = function (url, itemsLoaded, itemsTotal) {
console.log('Started loading file: ',
url,
'.\nLoaded ',
itemsLoaded,
' of ',
itemsTotal,
' files.');
};
manager.onLoad = () => {
console.log('Loading complete!');
};
manager.onProgress = function (url, itemsLoaded, itemsTotal) {
console.log('Loading file: ',
url,
'.\nLoaded ',
itemsLoaded,
' of ',
itemsTotal,
' files.');
};
manager.onError = function (url) {
console.error( 'There was an error loading ', url);
};
const textureLoader = new THREE.TextureLoader(manager);
textureLoader.setCrossOrigin('anonymous');
textureLoader.load('/img/texture1.png',
texture => {
faceMaterial = new THREE.MeshFaceMaterial([
new THREE.MeshBasicMaterial({map: texture}),
new THREE.MeshBasicMaterial({map: texture}),
new THREE.MeshBasicMaterial({map: texture}),
new THREE.MeshBasicMaterial({map: texture}),
new THREE.MeshBasicMaterial({map: texture}),
new THREE.MeshBasicMaterial({map: texture})
]);
},
undefined,
err => {
console.error('An error occured:', err);
}
);
this.mesh = new THREE.Mesh(geometry, faceMaterial);
this.mesh.name = 'profile';
};