After updating to the latest version of three.js, I encountered an issue where THREE.ImageUtils.loadTexture no longer works. As a result, I tried searching for examples of cubes with different faces, but they all utilized the outdated technique "new THREE.ImageUtils.loadTexture". Determined to find a solution, I attempted to create one using "new THREE.TextureLoader.load('texture1.png')". Here is my attempt:
<!DOCTYPE html>
<html lang="en>
<head>
<title>three.js webgl - geometry - cube</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
margin: 0px;
background-color: #000000;
overflow: hidden;
}
</style>
</head>
<body>
<script src="library/threejs/build/three.js"></script>
<script>
var camera, scene, renderer;
var head;
var loader = new THREE.TextureLoader();
init();
animate();
function init() {
camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.z = 400;
scene = new THREE.Scene();
materials = [
new THREE.TextureLoader().load('textures/mob/zombie/zombie_headfront.png'),
new THREE.TextureLoader().load('textures/mob/zombie/zombie_headback.png'),
new THREE.TextureLoader().load('textures/mob/zombie/zombie_headleft.png'),
new THREE.TextureLoader().load('textures/mob/zombie/zombie_headright.png'),
new THREE.TextureLoader().load('textures/mob/zombie/zombie_headup.png'),
new THREE.TextureLoader().load('textures/mob/zombie/zombie_headdown.png')];
head = new THREE.Mesh(
new THREE.BoxBufferGeometry(80, 80, 80, 1, 1, 1, materials),
new THREE.MeshBasicMaterial({ map: materials })
);
scene.add(head);
renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
window.addEventListener('resize', onWindowResize, false);
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
function animate() {
requestAnimationFrame(animate);
head.rotation.x += 0.005;
head.rotation.y += 0.01;
renderer.render(scene, camera);
}
</script>
</body>
</html>
However, I ran into the following errors:
TypeError: offset is undefined
and
THREE.WebGLShader: Shader couldn't compile
as well as
THREE.WebGLShader: gl.getShaderInfoLog() fragment ERROR: 0:238:
'mapTexelToLinear' : no matching overloaded function found
If you have any insights on how to resolve these issues or can provide guidance on creating a cube with six distinct sides, that would be greatly appreciated! Thank you!