JSFiddle - React, Tailwind, and code Playground
JavaScript
import * as THREE from 'https://cdn.skypack.dev/[email protected]/build/three.module.js';
let camera, scene, renderer;
init();
animate();
function init() {
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );
camera.position.z = 2;
scene = new THREE.Scene();
const loader = new THREE.TextureLoader();
const texture1 = loader.load( 'https://threejs.org/examples/textures/uv_grid_opengl.jpg' );
const texture2 = loader.load( 'https://threejs.org/examples/textures/crate.gif' );
const geometry = new THREE.PlaneGeometry();
const material = new THREE.MeshBasicMaterial( { map: texture1 } );
setTimeout( function() {
material.map = texture2;
}, 3000 );
const mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
}
function animate() {
requestAnimationFrame( animate );
renderer.render( scene, camera );
}