diff --git a/index.html b/BenedekLaszlo_IH1RZJ.html
similarity index 70%
rename from index.html
rename to BenedekLaszlo_IH1RZJ.html
index 7e33a84..82a6484 100644
--- a/index.html
+++ b/BenedekLaszlo_IH1RZJ.html
@@ -36,43 +36,104 @@
import * as THREE from "three";
import { TrackballControls } from "TrackballControls";
- let fov = 75;
- let near = 0.01;
- let far = 1000;
- let rotateSpeed = 5.0;
- let panSpeed = 1.0;
+ class SceneLoader {
+ static FromJson(data) {
+ let _scene = new THREE.Scene();
+
+ const geometryTypes = {
+ "CircleGeometry": THREE.CircleGeometry,
+ "PlaneGeometry": THREE.PlaneGeometry,
+ "BoxGeometry": THREE.BoxGeometry,
+ "SphereGeometry": THREE.SphereGeometry,
+ "ConeGeometry": THREE.ConeGeometry,
+ "CylinderGeometry": THREE.CylinderGeometry,
+ "TorusGeometry": THREE.TorusGeometry,
+ };
+
+ const materialTypes = {
+ "MeshBasicMaterial": THREE.MeshBasicMaterial
+ };
+
+ let geometries = {};
+ let materials = {};
+ let meshes = {};
+
+ for (let [key, value] of Object.entries(data.geometries)) {
+ geometries[key] = new geometryTypes[value.type](...value.options);
+ }
+
+ for (let [key, value] of Object.entries(data.materials)) {
+ materials[key] = new materialTypes[value.type](value.options);
+ }
+
+ function createMesh(data) {
+ let mesh;
+ let type = data.type ? data.type : "Mesh";
+
+ switch (type) {
+ case "empty":
+ mesh = new THREE.Object3D();
+ break;
+ case "Mesh":
+ mesh = new THREE.Mesh(geometries[data.geometry], materials[data.material]);
+ break;
+ case "LineSegments":
+ mesh = new THREE.LineSegments(geometries[data.geometry], materials[data.material]);
+ break;
+ default:
+ throw "unknown mesh type";
+ }
+
+ if (data.position) mesh.position.set(...data.position);
+ if (data.rotation) mesh.rotation.set(...Array.from(data.rotation, x => THREE.MathUtils.degToRad(x)));
+ if (data.scale) mesh.scale.set(...data.scale);
+
+ if (data.children) {
+ for (let [key, value] of Object.entries(data.children)) {
+ mesh.add(createMesh(value));
+ }
+ }
+
+ return mesh;
+ }
+
+ for (let [key, value] of Object.entries(data.meshes)) {
+ _scene.add(meshes[key] = createMesh(value));
+ }
+
+ return _scene;
+ }
+ };
+
+ const fov = 75;
+ const near = 0.01;
+ const far = 1000;
+ const rotateSpeed = 5.0;
+ const panSpeed = 1.0;
let canvas, renderer, scene, camera, controls;
- init();
- animate();
+ init().then(animate());
- function init() {
+ async function init() {
canvas = document.querySelector("#canvas");
- renderer = new THREE.WebGLRenderer({ antialias: true, canvas: canvas });
+ renderer = new THREE.WebGLRenderer({ antialias: true, canvas: canvas, alpha: true });
renderer.setSize(window.innerWidth, window.innerHeight);
-
- scene = new THREE.Scene();
+ renderer.setClearColor(0xadadad);
camera = new THREE.PerspectiveCamera(fov, window.innerWidth / window.innerHeight, near, far);
- camera.position.z = 15;
+ camera.position.set(0, 10, 50);
controls = new TrackballControls(camera, canvas);
controls.rotateSpeed = rotateSpeed;
controls.panSpeed = panSpeed;
- scene.add(new THREE.AxesHelper(5));
-
- loadScene();
-
- window.addEventListener("resize", handleWindowResize, false);
- }
-
- function loadScene() {
- fetch("scene.json")
+ scene = await fetch("scene.json")
.then((response) => response.json())
.catch(reason => console.log(`fetch failed: ${reason}`))
- .then((json) => SceneLoader.FromJson(json, scene));
+ .then((json) => SceneLoader.FromJson(json));
+
+ window.addEventListener("resize", handleWindowResize, false);
}
function handleWindowResize() {
@@ -94,61 +155,6 @@
function render() {
renderer.render(scene, camera);
}
-
- class SceneLoader {
- static FromJson(data, scene, camera) {
- let geometryTypes = {
- "CircleGeometry": THREE.CircleGeometry,
- "PlaneGeometry": THREE.PlaneGeometry,
- "BoxGeometry": THREE.BoxGeometry,
- "SphereGeometry": THREE.SphereGeometry,
- "ConeGeometry": THREE.ConeGeometry,
- "CylinderGeometry": THREE.CylinderGeometry,
- "TorusGeometry": THREE.TorusGeometry,
- };
-
- let materialTypes = {
- "MeshBasicMaterial": THREE.MeshBasicMaterial
- };
-
- let geometries = {};
- let materials = {};
- let meshes = {};
-
- for (let [key, value] of Object.entries(data.geometries)) {
- geometries[key] = new geometryTypes[value.type](...value.options);
- }
-
- for (let [key, value] of Object.entries(data.materials)) {
- materials[key] = new materialTypes[value.type](value.options);
- }
-
- function createMesh(data) {
- let mesh;
- if (data.type === "empty") {
- mesh = new THREE.Object3D();
- } else {
- mesh = new THREE.Mesh(geometries[data.geometry], materials[data.material]);
- }
-
- mesh.position.set(...data.position);
- mesh.rotation.set(...Array.from(data.rotation, x => THREE.MathUtils.degToRad(x)));
- mesh.scale.set(...data.scale);
-
- if (data.children) {
- for (let [key, value] of Object.entries(data.children)) {
- mesh.add(createMesh(value));
- }
- }
-
- return mesh;
- }
-
- for (let [key, value] of Object.entries(data.meshes)) {
- scene.add(meshes[key] = createMesh(value));
- }
- }
- };