Building and deploying a 3D web developer portfolio in React JS using Three.js can be a great way to showcase your skills and projects to potential clients and employers. In this tutorial, we will walk through the process of creating a stunning 3D portfolio using React JS and Three.js, and deploying it to the web.
Step 1: Setting up your development environment
Before you begin, make sure you have Node.js and npm installed on your machine. You can check if you have Node.js installed by running the following command in your terminal:
node -v
If you don’t have Node.js installed, you can download it from the official website: https://nodejs.org/
Once you have Node.js installed, you can create a new React JS project using create-react-app. Run the following command in your terminal to create a new React JS project:
npx create-react-app my-3d-portfolio
Replace "my-3d-portfolio" with the name of your project.
Step 2: Installing Three.js
Next, you need to install Three.js in your project. Three.js is a popular 3D graphics library that will allow you to create interactive 3D scenes in your portfolio.
To install Three.js, run the following command in your terminal:
npm install three
Step 3: Creating a 3D scene
Now that you have Three.js installed, you can start creating your 3D portfolio. Open the src folder in your project directory and create a new file called Scene.js. This file will contain the code for your 3D scene.
In the Scene.js file, import Three.js at the top of the file:
import * as THREE from 'three';
Next, create a new function called init() that will set up your 3D scene:
function init() {
// Create a new scene
const scene = new THREE.Scene();
// Create a camera
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
// Create a renderer
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Add a cube to the scene
const geometry = new THREE.BoxGeometry();
const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
const cube = new THREE.Mesh(geometry, material);
scene.add(cube);
// Position the camera
camera.position.z = 5;
// Animate the cube
function animate() {
requestAnimationFrame(animate);
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
renderer.render(scene, camera);
}
animate();
}
init();
Step 4: Integrating Three.js with React
Now that you have created a basic 3D scene, you can integrate it with your React JS project. Open the App.js file in your src folder and import the Scene component at the top of the file:
import Scene from './Scene';
Next, replace the code inside the App component with the following code:
function App() {
return (
<div>
<Scene />
</div>
);
}
export default App;
This code will render the 3D scene inside your React component.
Step 5: Adding interactivity to your 3D scene
To make your portfolio more interactive, you can add event listeners to the 3D scene. For example, you can rotate the cube when the user clicks on it.
In the Scene.js file, add the following code inside the init() function:
// Add interactivity to the cube
cube.addEventListener('click', function () {
cube.rotation.x += 0.1;
cube.rotation.y += 0.1;
});
Step 6: Deploying your 3D portfolio
To deploy your 3D portfolio to the web, you can use services like GitHub Pages or Netlify. Follow these steps to deploy your project to GitHub Pages:
- Create a new repository on GitHub and push your project to the repository.
- Install the gh-pages package by running the following command in your terminal:
npm install gh-pages --save-dev
- Add the following properties to the package.json file in your project:
"homepage": "https://your-username.github.io/your-repo-name",
"scripts": {
"deploy": "npm run build && gh-pages -d build"
}
Replace "your-username" with your GitHub username and "your-repo-name" with the name of your GitHub repository.
- Run the following command in your terminal to deploy your project to GitHub Pages:
npm run deploy
Your 3D portfolio should now be deployed to GitHub Pages at the URL specified in the homepage property.
In this tutorial, we walked through the process of creating a 3D web developer portfolio in React JS using Three.js. By following these steps, you can create a stunning and interactive portfolio to showcase your skills and projects. Deploying your portfolio to the web will allow you to share it with potential clients and employers.
Want to land your dream programming job in 3 – 6 months?
⭐ JSM Masterclass Experience – https://jsmastery.pro/masterclass
Become a Software Engineer. Guaranteed.
when i uploaded this on github using gh-pages, my hero section is not showing me on My mobile, it is showing white screen but it is working fine on laptop
Is it beginner friendly?
Where can I download the 3D model ?
I got an Error npm create vite@latest ./ — –template react. How to overcome this problem.
how to setup vscode terminal show command
i wish it didnt require this much copy pasting the files at first , it didnt look beginner friendly . bt thx anyways
If I don't have work experience, should I delete that part or what else should I put on it? Any suggestion pls?
hello! i have downloaded the code from github , wht should i do next ??, npm run dev is not working..
This may be silly, but I've been following along with this tutorial and ran into some road blocks… 56:43 in the video. This where you are rendering the 3D model into the website. I got all my code in but the models does not render in the browser. Any suggestions?
I just finished the project. Thanks Adrian
How can i add my own experience in this, i watched that part again but didn't understand much
I don't know is there any saltation for this error the error when i go to terminal and type npm start is give me eroor script miss and some index.js when i when i try tu my other projects it will run
I am having issues with the Contact section when I render the Earth model, this affects the computer model in the Hero section and I get this in the console WARNING: Too many active WebGL contexts. Oldest context will be lost. THREE.WebGLRenderer: Context Lost.
where can we find different models to use?
how do i change the hero background?
Well, this makes so much easier to understand that we could use saperate canvases for saperate components. As a beginner i was struggling to combine 2d and 3d. But this made my life so much easier. Also i would like to ask that how did you create the card icons?
43:50
if you are getting error in works section, white screen then change
iimport Tilt from "react-tilt"; to import Tilt from "react-parallax-tilt" it worked for me after i spent 30 minutes to find where the problem was
Thank you for this tutorial.