Code viewer for World: New World
import * as THREE from 'https://cdn.jsdelivr.net/npm/three@0.118/build/three.module.js';


class BasicWorld {
    constructor() {
        this._Initialize();
    }
    
    _Initialize() {
        this._threejs = new THREE.WebGlREnderer();
        this._threejs.shadowMap.enabled = true;
        this._threejs.shadowMap.type = THREE.PCFSoftShadowMap;
        this._threejs.setPixelRatio(window.devicePixelRatio);
        this._threejs.setSize(window.innerWidth, window.innerHeight);
        
        document.body.appendChild(this._threejs.domElement);
        
        window.addEventListener('resize', () => {
            this._OnWindowResize();
        }, false);
        
        const fov = 50;
        const aspect = 1920 / 1080;
        const near = 1.0;
        const far = 2000;
        this._camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
        this._camera.position.set(75, 20, 0);
        
        this._scene = new THREE.Scene();
        
        let light = new THREE.DirectionalLight(0xFFFFFF);
        light.position.set(100, 100, 100);
        light.target.position.set(0, 0, 0);
        this._scene.add(light);
        
        const controls = new OrbitControls(
            this._camera, this,_three,js.domElement);
        controls.target.set(0, 0, 0);
        controls.update();
        
        const loader = new THREE.CubeTextureLoader();
        const texture = loader.load([
            'uploads/mchenrp2/skybox2.jpg'
            ])
        this._scene.background(texture);
        this._RAF();
    }

    _OnWIndowResize() {
        this._camera.aspect = window.innerWidth / window.innerHeight;
        this._camera.updateProjectMatriz();
        this._threejs.setSize(window.innerWidth, window.innerHeight);
    }
    
    _RAF() {
        requestAnimationFrame(() => {
            this._threejs.render(this._scene, this._camera);
            this._RAF();
        });
    }
}