JavaScript
import * as THREE from 'https://cdn.skypack.dev/three'
let camera, scene, renderer, material, mesh;
init();
function init() {
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );
camera.position.z = 1;
scene = new THREE.Scene();
const geometry = new THREE.BoxBufferGeometry(0.5, 0.5, 0.5);
geometry.setAttribute('uv', new THREE.BufferAttribute(getUvs(), 2));
const texture = new THREE.TextureLoader().load('https://i.imgur.com/a447cgi.png');
texture.magFilter = THREE.NearestFilter;
material = new THREE.MeshBasicMaterial( {
map: texture,
side: THREE.FrontSide
} );
mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setAnimationLoop(animation);
document.body.appendChild(renderer.domElement);
}
function animation(time) {
mesh.rotation.x = time / 2000;
mesh.rotation.y = time / 1000;
renderer.render(scene, camera);
}
function getUvs() {
return new Float32Array([
24/64, 56/64, /**/ 32/64, 56/64, /**/ 24/64, 48/64, /**/ 32/64, 48/64,
24/64, 56/64, /**/ 32/64, 56/64, /**/ 24/64, 48/64, /**/ 32/64, 48/64,
24/64, 56/64, /**/ 32/64, 56/64, /**/ 24/64, 48/64, /**/ 32/64, 48/64,
24/64, 56/64, /**/ 32/64, 56/64, /**/ 24/64, 48/64, /**/ 32/64, 48/64,
24/64, 56/64, /**/ 32/64, 56/64, /**/ 24/64, 48/64, /**/ 32/64, 48/64,
24/64, 56/64, /**/ 32/64, 56/64, /**/ 24/64, 48/64, /**/ 32/64, 48/64
]);
}