JSFiddle - React, Tailwind, and code Playground
JavaScript
import * as THREE from "https://unpkg.com/three@0.112/build/three.module.js";
import { OrbitControls } from "https://unpkg.com/three@0.112/examples/jsm/controls/OrbitControls.js";
let camera, controls;
let renderer;
let scene;
init();
animate();
function init() {
// renderer
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setPixelRatio( window.devicePixelRatio );
document.body.appendChild( renderer.domElement );
// scene
scene = new THREE.Scene();
// camera
camera = new THREE.PerspectiveCamera( 90, window.innerWidth / window.innerHeight, 0.1, 100 );
//camera.position.z = 0.01;
camera.position.set( 0, 0, 0.1 );
//camera.rotation.y += 4
//camera.updateProjectionMatrix();
camera.rotateOnWorldAxis(new THREE.Vector3(0.0, 1.0, 0.0), 4); //must look at the statue, not out of the window
// controls
controls = new OrbitControls( camera, renderer.domElement ); //comment this line and camera will rotate at needed angle
//controls.enableZoom = false;
//controls.enablePan = false;
//controls.enableDamping = true;
//controls.rotateSpeed = - 0.25;
//controls.update();
const textures = getTexturesFromAtlasFile( 'https://threejs.org/examples/textures/cube/sun_temple_stripe.jpg', 6 );
const materials = [];
for ( let i = 0; i < 6; i ++ ) {
materials.push( new THREE.MeshBasicMaterial( { map: textures[ i ] } ) );
}
const skyBox = new THREE.Mesh( new THREE.BoxGeometry( 1, 1, 1 ), materials );
skyBox.geometry.scale( 1, 1, - 1 );
scene.add( skyBox );
window.addEventListener( 'resize', onWindowResize );
}
function getTexturesFromAtlasFile( atlasImgUrl, tilesNum ) {
const textures = [];
for ( let i = 0; i < tilesNum; i ++ ) {
textures[ i ] = new THREE.Texture();
}
new THREE.ImageLoader()
.load( atlasImgUrl, ( image ) => {
let canvas,...