2019-12-09 18:41:42 +01:00
|
|
|
let camera, scene, renderer, loader, light1, light2, controls, model;
|
|
|
|
|
|
|
|
init();
|
|
|
|
animate();
|
|
|
|
|
|
|
|
function init() {
|
|
|
|
|
2019-12-11 16:48:29 +01:00
|
|
|
let url = document.URL.split('?')[1] || "bunny_remove.obj";
|
|
|
|
|
|
|
|
loader = new Loader('assets/' + url, 1024, 20);
|
2019-12-09 18:41:42 +01:00
|
|
|
loader.start(function(elements) {
|
|
|
|
for (let element of elements) {
|
|
|
|
if (element !== undefined) {
|
|
|
|
model.manageElement(element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.0001, 1000);
|
|
|
|
camera.position.z = 3;
|
|
|
|
|
|
|
|
scene = new THREE.Scene();
|
|
|
|
|
|
|
|
model = new Model();
|
|
|
|
scene.add(model);
|
|
|
|
|
|
|
|
light1 = new THREE.AmbientLight(0x999999);
|
|
|
|
scene.add(light1);
|
|
|
|
|
|
|
|
light2 = new THREE.DirectionalLight(0xffffff, 1.0);
|
|
|
|
light2.position.set(0.0, 1.0, 0.0);
|
|
|
|
scene.add(light2);
|
|
|
|
|
|
|
|
renderer = new THREE.WebGLRenderer({antialias: true});
|
|
|
|
renderer.setSize(window.innerWidth, window.innerHeight);
|
|
|
|
document.body.appendChild(renderer.domElement);
|
|
|
|
|
2019-12-11 16:48:29 +01:00
|
|
|
window.addEventListener('resize', onWindowResize, false);
|
2019-12-09 18:41:42 +01:00
|
|
|
controls = new THREE.OrbitControls(camera, renderer.domElement);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function animate() {
|
|
|
|
|
|
|
|
requestAnimationFrame(animate);
|
|
|
|
controls.update();
|
2019-12-11 16:48:29 +01:00
|
|
|
document.getElementById('progressbar').value = Math.floor(100 * loader.percentage()) || 0;
|
2019-12-11 16:02:46 +01:00
|
|
|
document.getElementById('percentage').innerHTML = Math.floor(100 * loader.percentage()) / 100 + "%";
|
2019-12-09 18:41:42 +01:00
|
|
|
renderer.render(scene, camera);
|
|
|
|
|
|
|
|
}
|
2019-12-11 16:48:29 +01:00
|
|
|
|
|
|
|
function onWindowResize() {
|
|
|
|
camera.aspect = window.innerWidth / window.innerHeight;
|
|
|
|
camera.updateProjectionMatrix();
|
|
|
|
|
|
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
|
}
|