├── .gitignore ├── public └── Ayo open me.jpg ├── index.html ├── package.json ├── README.md └── main.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /public/Ayo open me.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WaelYasmina/ThreeBoilerplate/HEAD/public/Ayo open me.jpg -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Wael Yasmina 8 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "threeboilerplate", 3 | "version": "1.0.0", 4 | "description": "The Three.js boilerplate that I'm using in my Tutorials.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "Wael Yasmina", 11 | "license": "ISC", 12 | "dependencies": { 13 | "three": "^0.176.0" 14 | }, 15 | "devDependencies": { 16 | "vite": "^5.3.2" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ThreeBoilerplate 2 | 3 | This is the boilerplate that I'm using for my Three.js tutorials. 4 | 5 | Wanna use it? okay then just follow these simple steps: 6 | 7 | 1. Clone the repository; 8 | 2. Open the folder in Visual Studio Code; 9 | 3. Open the terminal and type this command: npm install 10 | 5. Run the app on the server by typing this command: npx vite 11 | 6. Ctrl + click on the server link "http://localhost:5173/" to open the app in your browser; 12 | 7. Have fun! 13 | 14 | • The /public folder is where you put the images and 3D models. 15 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | import * as THREE from 'three'; 2 | import {OrbitControls} from 'three/examples/jsm/controls/OrbitControls.js'; 3 | 4 | const renderer = new THREE.WebGLRenderer({antialias: true}); 5 | renderer.setSize(window.innerWidth, window.innerHeight); 6 | document.body.appendChild(renderer.domElement); 7 | 8 | // Sets the color of the background. 9 | renderer.setClearColor(0xFEFEFE); 10 | 11 | const scene = new THREE.Scene(); 12 | const camera = new THREE.PerspectiveCamera( 13 | 45, 14 | window.innerWidth / window.innerHeight, 15 | 0.1, 16 | 1000 17 | ); 18 | 19 | // Sets orbit control to move the camera around. 20 | const orbit = new OrbitControls(camera, renderer.domElement); 21 | 22 | // Camera positioning. 23 | camera.position.set(6, 8, 14); 24 | // Has to be done everytime we update the camera position. 25 | orbit.update(); 26 | 27 | // Creates a 12 by 12 grid helper. 28 | const gridHelper = new THREE.GridHelper(12, 12); 29 | scene.add(gridHelper); 30 | 31 | // Creates an axes helper with an axis length of 4. 32 | const axesHelper = new THREE.AxesHelper(4); 33 | scene.add(axesHelper); 34 | 35 | function animate() { 36 | renderer.render(scene, camera); 37 | } 38 | 39 | renderer.setAnimationLoop(animate); 40 | 41 | window.addEventListener('resize', function() { 42 | camera.aspect = window.innerWidth / window.innerHeight; 43 | camera.updateProjectionMatrix(); 44 | renderer.setSize(window.innerWidth, window.innerHeight); 45 | }); --------------------------------------------------------------------------------