Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/flo-bit/three-scaffold. basic three.js scaffold for quick testing/demoing flo-bit.github.io/three-scaffold
Something went wrong. Try again.
three-scaffold index.html
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990<html> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/0.148.0/three.min.js"></script> </head> <body style="overflow: hidden"> <script> class THREE_SCAFFOLD { constructor() { let w = window.innerWidth, h = window.innerHeight; this.scene = new THREE.Scene(); this.camera = new THREE.PerspectiveCamera(75, w / h); this.scene.background = new THREE.Color(0x232323); this.scene.add(this.camera);
this.renderer = new THREE.WebGLRenderer(); this.renderer.setSize(w, h); let d = this.renderer.domElement; d.style.position = "absolute"; d.style.left = "0px"; d.style.top = "0px"; document.body.appendChild(d);
this.keys = {}; document.addEventListener("keydown", this.keyDown.bind(this)); document.addEventListener("keyup", this.keyUp.bind(this)); window.addEventListener("resize", this.windowResized.bind(this));
this.lights = {}; this.lights.ambi = new THREE.AmbientLight(0xffffff, 0.2); this.scene.add(this.lights.ambi); this.lights.dir = new THREE.DirectionalLight(0xffffff, 1.0); this.lights.dir.position.set(-0.8, 0.5, 0.7); this.scene.add(this.lights.dir);
this.clock = new THREE.Clock();
this.setupScene(); this.animate(); }
setupScene() { /* setup your scene here */ /* START */ this.sphere = new THREE.Mesh( new THREE.IcosahedronGeometry(1, 1), new THREE.MeshStandardMaterial({ flatShading: true }) ); this.sphere.position.z = -2; this.scene.add(this.sphere); /* END */ } animate() { requestAnimationFrame(this.animate.bind(this)); let delta = this.clock.getDelta(); let total = this.clock.getElapsedTime();
/* Update your scene here */ /* START */ if (this.keys[" "] != true) { this.sphere.rotation.y += delta * 0.1; this.sphere.rotation.x += delta * 0.213; } /* END */
this.renderer.render(this.scene, this.camera); }
windowResized() { this.camera.aspect = window.innerWidth / window.innerHeight; this.camera.updateProjectionMatrix(); this.renderer.setSize(window.innerWidth, window.innerHeight); } keyDown(event) { this.keys[event.key] = true; } keyUp(event) { this.keys[event.key] = false; } } let app = new THREE_SCAFFOLD(); </script> </body></html>