Recently, I utilized a function to apply texture on a Cylinder shape.
function createElementMaterial() {
THREE.ImageUtils.crossOrigin = '';
var t = THREE.ImageUtils.loadTexture( IMG_MACHINE );
t.wrapS = THREE.RepeatWrapping;
t.wrapT = THREE.RepeatWrapping;
t.offset.x = 90/(2*Math.PI);
var m = new THREE.MeshBasicMaterial();
m.map = t;
return m;
}
This method effectively added the desired texture, but triggered a warning message in the console.
THREE.ImageUtils.loadTexture has been deprecated. It is recommended to use THREE.TextureLoader() instead.
Following the guidelines from this documentation provided by threejs.org, I revised the function as shown below.
function createElementMaterial() {
var loader = new THREE.TextureLoader();
// load a resource
loader.load(
// resource URL
IMG_MACHINE,
// Function when resource is loaded
function ( texture ) {
// do something with the texture
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.offset.x = 90/(2*Math.PI);
var material = new THREE.MeshBasicMaterial( {
map: texture
} );
},
// Function called when download progresses
function ( xhr ) {
console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
},
// Function called when download errors
function ( xhr ) {
console.log( 'An error happened' );
}
);
}
Despite implementing this code, I am facing difficulty in achieving the desired texture wrap around the cylinder. Here are the before and after images for reference. Thank you in advance. https://i.sstatic.net/dcI0p.jpg