{
let camera,
renderer,
scene,
controls,
mesh
;
init();
function createCamera() {
const fov = 15;
const aspect = width / 400;
const near = 0.1;
const far = 1000;
camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
camera.position.set( -14, 4, 10 );
}
function createLights() {
const ambientLight = new THREE.HemisphereLight(0xddeeff,0x202020, 9);
const mainLight = new THREE.DirectionalLight(0xffffff, 3.0);
scene.add(ambientLight);
mainLight.position.set(10,10,10);
scene.add(ambientLight,mainLight);
}
function createMeshes() {
const geometry = new THREE.BoxBufferGeometry(2, 2, 2);
const textureLoader = new THREE.TextureLoader();
const texture = textureLoader.load('https://raw.githubusercontent.com/bumbeishvili/Assets/master/Other/junk/02_59_45_460_Earth_Diffuse_t_1%20(2).jpg')
texture.encoding = THREE.sRGBEncoding;
texture.anisotropy = 16;
const material = new THREE.MeshStandardMaterial({
map: texture
});
mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
}
function createRenderer() {
renderer = new THREE.WebGLRenderer({
antialias: true
});
renderer.setSize(width, 400);
renderer.setPixelRatio(window.devicePixelRatio);
renderer.gammaFactor = 2.2;
renderer.gammaOutput = true;
renderer.physicallyCorrectLights = true;
}
function init() {
scene = new THREE.Scene();
scene.background = new THREE.Color('#2B1658');
createCamera();
createLights();
createMeshes();
createRenderer();
controls = new THREE.OrbitControls(camera, renderer.domElement);
invalidation.then(() => (controls.dispose(), renderer.dispose()));
}
renderer.setAnimationLoop(() => {
update();
render();
})
function render() {
renderer.render(scene, camera);
}
function update() {
}
function onWindowResize() {
camera.aspect = width / 400;;
camera.updateProjectionMatrix();
renderer.setSize(width, 400)
}
window.addEventListener('resize', onWindowResize)
yield renderer.domElement
}