JSFiddle - React, Tailwind, and code Playground
HTML
<!-- Import maps polyfill -->
<!-- Remove this when import maps will be widely supported -->
<script async src="https://unpkg.com/es-module-shims@1.3.6/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three/build/three.module.js"
}
}
</script>
JavaScript
import * as THREE from 'three';
// init
const t1 = new THREE.TextureLoader().load( 'https://i.imgur.com/G8eWSOY.jpg', function() {
const target = new THREE.WebGLRenderTarget( 128, 128 );
renderer.setRenderTarget( target );
renderer.render( scene, camera );
renderer.setRenderTarget( null );
t2.source = target.texture.source;
// next line triggers the error, yes
//t2.needsUpdate = true;
} );
const t2 = new THREE.Texture();
t2.wrapS = t2.wrapT = THREE.RepeatWrapping;
t2.repeat.set( 4, 4 );
const camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );
camera.position.z = 1;
const scene = new THREE.Scene();
const geometry = new THREE.BoxGeometry( 0.5, 0.5, 0.5 );
const material = new THREE.MeshBasicMaterial( { map: t1 } );
const mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
const m2 = mesh.clone();
m2.position.setScalar( 0.3 );
m2.material = new THREE.MeshBasicMaterial( { map: t2 } );
mesh.add( m2 );
const renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animation );
document.body.appendChild( renderer.domElement );
// animation
function animation( time ) {
mesh.rotation.x = time / 2000;
mesh.rotation.y = time / 1000;
renderer.render( scene, camera );
}