├── .gitignore ├── README.md ├── client ├── .gitignore ├── index.html ├── package-lock.json ├── package.json ├── postcss.config.js ├── public │ ├── react.png │ ├── shirt_baked.glb │ ├── threejs.png │ └── vite.svg ├── src │ ├── App.jsx │ ├── assets │ │ ├── ai.png │ │ ├── download.png │ │ ├── file.png │ │ ├── index.js │ │ ├── logo-tshirt.png │ │ ├── stylish-tshirt.png │ │ └── swatch.png │ ├── canvas │ │ ├── Backdrop.jsx │ │ ├── CameraRig.jsx │ │ ├── Shirt.jsx │ │ └── index.jsx │ ├── components │ │ ├── AIPicker.jsx │ │ ├── ColorPicker.jsx │ │ ├── CustomButton.jsx │ │ ├── FilePicker.jsx │ │ ├── Tab.jsx │ │ └── index.js │ ├── config │ │ ├── config.js │ │ ├── constants.js │ │ ├── helpers.js │ │ └── motion.js │ ├── index.css │ ├── main.jsx │ ├── pages │ │ ├── Customizer.jsx │ │ └── Home.jsx │ └── store │ │ └── index.js ├── tailwind.config.js └── vite.config.js └── server ├── index.js ├── package.json └── routes └── dalle.routes.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .env -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 | Project Banner 5 | 6 |
7 | 8 |
9 | react.js 10 | three.js 11 | tailwindcss 12 |
13 | 14 |

A 3D Dev Swag Website

15 | 16 |
17 | Build this project step by step with our detailed tutorial on JavaScript Mastery YouTube. Join the JSM family! 18 |
19 |
20 | 21 | ## 📋 Table of Contents 22 | 23 | 1. 🤖 [Introduction](#introduction) 24 | 2. ⚙️ [Tech Stack](#tech-stack) 25 | 3. 🔋 [Features](#features) 26 | 4. 🤸 [Quick Start](#quick-start) 27 | 5. 🕸️ [Snippets](#snippets) 28 | 6. 🔗 [Links](#links) 29 | 7. 🚀 [More](#more) 30 | 31 | ## 🚨 Tutorial 32 | 33 | This repository contains the code corresponding to an in-depth tutorial available on our YouTube channel, JavaScript Mastery. 34 | 35 | If you prefer visual learning, this is the perfect resource for you. Follow our tutorial to learn how to build projects like these step-by-step in a beginner-friendly manner! 36 | 37 | 38 | 39 | ## 🤖 Introduction 40 | 41 | Create your own style with our new 3D Swag Customization App. Pick colors, add logos, and try AI designs to make your virtual swag unique. Built using React.js, Three.js, and OpenAI to show the usage of a 3D world with AI 42 | 43 | If you're getting started and need assistance or face any bugs, join our active Discord community with over 27k+ members. It's a place where people help each other out. 44 | 45 | 46 | 47 | ## ⚙️ Tech Stack 48 | 49 | - React.js 50 | - Three.js 51 | - React Three Fiber 52 | - React Three Drei 53 | - Vite 54 | - Tailwind CSS 55 | - Node.js 56 | - Express.js 57 | - OpenAI 58 | - Framer Motion 59 | - Valtio 60 | 61 | ## 🔋 Features 62 | 63 | 👉 **3D Swag Generation**: Generate unique 3D shirts/swag items dynamically 64 | 65 | 👉 **Color Customization**: Apply any color to the 3D shirt/swag for personalized styling. 66 | 67 | 👉 **Logo Upload Functionality**: Enable users to upload any file as a logo, integrating it seamlessly onto the 3D shirt. 68 | 69 | 👉 **Texture Image Upload**: Allow users to upload texture images to style the 3D shirt/swag. 70 | 71 | 👉 **AI-Generated Logo Integration**: Utilize AI to generate logos and intelligently apply them to the 3D shirt. 72 | 73 | 👉 **AI-Generated Textures**: Implement AI-generated textures for enhanced 3D shirt customization. 74 | 75 | 👉 **Download Options**:Dynamically change the application theme based on the selected color, enhancing user experience. 76 | 77 | 👉 **Theme Change with Color Selection**: Dynamically change the application theme based on the selected color, enhancing user experience 78 | 79 | 👉 **Responsive 3D Application**: Ensure the application is responsive, delivering a seamless experience across various devices. 80 | 81 | 👉 **Framer Motion Animation**: Implement framer motion animations for smooth transitions between different 3D models. 82 | 83 | and many more, including code architecture and reusability 84 | 85 | ## 🤸 Quick Start 86 | 87 | Follow these steps to set up the project locally on your machine. 88 | 89 | **Prerequisites** 90 | 91 | Make sure you have the following installed on your machine: 92 | 93 | - [Git](https://git-scm.com/) 94 | - [Node.js](https://nodejs.org/en) 95 | - [npm](https://www.npmjs.com/) (Node Package Manager) 96 | 97 | **Cloning the Repository** 98 | 99 | ```bash 100 | git clone https://github.com/adrianhajdin/project_threejs_ai.git 101 | cd project_threejs_ai 102 | ``` 103 | 104 | **Installation** 105 | 106 | Install the project dependencies using npm in both client and server folders: 107 | 108 | ```bash 109 | npm install 110 | ``` 111 | 112 | **Set Up Environment Variables** 113 | 114 | Create a new file named `.env` in the root of your project and add the following content: 115 | 116 | ```env 117 | OPENAI_API_KEY= 118 | ``` 119 | 120 | Replace the placeholder values with your actual OpenAI credentials. You can obtain these credentials by signing up on the [Open website](https://openai.com/). 121 | 122 | **Running the Project** 123 | 124 | 1. Server 125 | ```bash 126 | npm start 127 | ``` 128 | 2. Client 129 | ```bash 130 | npm run dev 131 | ``` 132 | 133 | Open [http://localhost:5173](http://localhost:5173) in your browser to view the project. 134 | 135 | ## 🕸️ Snippets 136 | 137 |
138 | Customizer.jsx 139 | 140 | ```javascript 141 | 148 | ``` 149 |
150 | 151 |
152 | index.css 153 | 154 | ```css 155 | @import url("https://fonts.googleapis.com/css2?family=Nunito+Sans:ital,wght@0,200;0,600;1,900&display=swap"); 156 | @import url("https://rsms.me/inter/inter.css"); 157 | 158 | @tailwind base; 159 | @tailwind components; 160 | @tailwind utilities; 161 | 162 | html { 163 | font-family: "Inter", sans-serif; 164 | } 165 | 166 | @supports (font-variation-settings: normal) { 167 | html { 168 | font-family: "Inter var", sans-serif; 169 | } 170 | } 171 | 172 | .app { 173 | @apply relative w-full h-screen overflow-hidden; 174 | } 175 | 176 | .home { 177 | @apply w-fit xl:h-full flex xl:justify-between justify-start items-start flex-col xl:py-8 xl:px-36 sm:p-8 p-6 max-xl:gap-7 absolute z-10; 178 | } 179 | 180 | .home-content { 181 | @apply flex-1 xl:justify-center justify-start flex flex-col gap-10; 182 | } 183 | 184 | .head-text { 185 | @apply xl:text-[10rem] text-[6rem] xl:leading-[11rem] leading-[7rem] font-black text-black; 186 | } 187 | 188 | .download-btn { 189 | @apply w-14 h-14 flex justify-center items-center rounded-full glassmorphism cursor-pointer outline-none; 190 | } 191 | 192 | .editortabs-container { 193 | @apply glassmorphism w-16 border-[2px] rounded-lg flex flex-col justify-center items-center ml-1 py-4 gap-4; 194 | } 195 | 196 | .filtertabs-container { 197 | @apply absolute z-10 bottom-5 right-0 left-0 w-full flex justify-center items-center flex-wrap gap-4; 198 | } 199 | 200 | .aipicker-container { 201 | @apply absolute left-full ml-3 glassmorphism p-3 w-[195px] h-[220px] rounded-md flex flex-col gap-4; 202 | } 203 | 204 | .aipicker-textarea { 205 | @apply w-full bg-transparent text-sm border border-gray-300 p-2 outline-none flex-1; 206 | } 207 | 208 | .filepicker-container { 209 | @apply absolute left-full ml-3 glassmorphism p-3 w-[195px] h-[220px] flex flex-col rounded-md; 210 | } 211 | 212 | .filepicker-label { 213 | @apply border border-gray-300 py-1.5 px-2 rounded-md shadow-sm text-xs text-gray-700 focus:outline-none focus:ring-1 focus:ring-blue-500 focus:border-blue-500 cursor-pointer w-fit; 214 | } 215 | 216 | .tab-btn { 217 | @apply w-14 h-14 flex justify-center items-center cursor-pointer select-none; 218 | } 219 | 220 | .glassmorphism { 221 | background: rgba(255, 255, 255, 0.25); 222 | box-shadow: 0 2px 30px 0 rgba(31, 38, 135, 0.07); 223 | backdrop-filter: blur(4px); 224 | -webkit-backdrop-filter: blur(4px); 225 | border: 1px solid rgba(255, 255, 255, 0.18); 226 | } 227 | 228 | input[type="file"] { 229 | z-index: -1; 230 | position: absolute; 231 | opacity: 0; 232 | } 233 | 234 | .sketch-picker { 235 | width: 170px !important; 236 | background: rgba(255, 255, 255, 0.25) !important; 237 | box-shadow: 0 2px 30px 0 rgba(31, 38, 135, 0.07) !important; 238 | backdrop-filter: blur(4px) !important; 239 | -webkit-backdrop-filter: blur(4px) !important; 240 | border: 1px solid rgba(255, 255, 255, 0.18) !important; 241 | border-radius: 6px !important; 242 | } 243 | 244 | .sketch-picker > div:nth-child(3) { 245 | display: none !important; 246 | } 247 | ``` 248 |
249 | 250 | ## 🔗 Links 251 | 252 | Assets used in the project are [here](https://drive.google.com/drive/folders/166wA5NsMV_5D8NN7ujDDbPXC1X65vf2I) 253 | 254 | ## 🚀 More 255 | 256 | **Advance your skills with Next.js 14 Pro Course** 257 | 258 | Enjoyed creating this project? Dive deeper into our PRO courses for a richer learning adventure. They're packed with detailed explanations, cool features, and exercises to boost your skills. Give it a go! 259 | 260 | 261 | Project Banner 262 | 263 | 264 |
265 |
266 | 267 | **Accelerate your professional journey with the Expert Training program** 268 | 269 | And if you're hungry for more than just a course and want to understand how we learn and tackle tech challenges, hop into our personalized masterclass. We cover best practices, different web skills, and offer mentorship to boost your confidence. Let's learn and grow together! 270 | 271 | 272 | Project Banner 273 | 274 | 275 | # 276 | -------------------------------------------------------------------------------- /client/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /client/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite + React 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "client", 3 | "private": true, 4 | "version": "0.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "vite build", 9 | "preview": "vite preview" 10 | }, 11 | "dependencies": { 12 | "@react-three/drei": "^9.58.5", 13 | "@react-three/fiber": "^8.12.0", 14 | "framer-motion": "^10.9.4", 15 | "maath": "^0.5.3", 16 | "react": "^18.2.0", 17 | "react-color": "^2.19.3", 18 | "react-dom": "^18.2.0", 19 | "three": "^0.150.1", 20 | "valtio": "^1.10.3" 21 | }, 22 | "devDependencies": { 23 | "@types/react": "^18.0.28", 24 | "@types/react-dom": "^18.0.11", 25 | "@vitejs/plugin-react": "^3.1.0", 26 | "autoprefixer": "^10.4.14", 27 | "postcss": "^8.4.21", 28 | "tailwindcss": "^3.3.0", 29 | "vite": "^4.2.0" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /client/postcss.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /client/public/react.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adrianhajdin/project_threejs_ai/bbe1d55b16267a9d115555be8ed2e2a2e2bb957b/client/public/react.png -------------------------------------------------------------------------------- /client/public/shirt_baked.glb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adrianhajdin/project_threejs_ai/bbe1d55b16267a9d115555be8ed2e2a2e2bb957b/client/public/shirt_baked.glb -------------------------------------------------------------------------------- /client/public/threejs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adrianhajdin/project_threejs_ai/bbe1d55b16267a9d115555be8ed2e2a2e2bb957b/client/public/threejs.png -------------------------------------------------------------------------------- /client/public/vite.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /client/src/App.jsx: -------------------------------------------------------------------------------- 1 | import Canvas from './canvas'; 2 | import Customizer from './pages/Customizer'; 3 | import Home from './pages/Home'; 4 | 5 | function App() { 6 | return ( 7 |
8 | 9 | 10 | 11 |
12 | ) 13 | } 14 | 15 | export default App 16 | -------------------------------------------------------------------------------- /client/src/assets/ai.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adrianhajdin/project_threejs_ai/bbe1d55b16267a9d115555be8ed2e2a2e2bb957b/client/src/assets/ai.png -------------------------------------------------------------------------------- /client/src/assets/download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adrianhajdin/project_threejs_ai/bbe1d55b16267a9d115555be8ed2e2a2e2bb957b/client/src/assets/download.png -------------------------------------------------------------------------------- /client/src/assets/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adrianhajdin/project_threejs_ai/bbe1d55b16267a9d115555be8ed2e2a2e2bb957b/client/src/assets/file.png -------------------------------------------------------------------------------- /client/src/assets/index.js: -------------------------------------------------------------------------------- 1 | import ai from "./ai.png"; 2 | import fileIcon from "./file.png"; 3 | import swatch from "./swatch.png"; 4 | import download from "./download.png"; 5 | 6 | import logoShirt from "./logo-tshirt.png"; 7 | import stylishShirt from "./stylish-tshirt.png"; 8 | 9 | export { ai, fileIcon, swatch, download, logoShirt, stylishShirt }; 10 | -------------------------------------------------------------------------------- /client/src/assets/logo-tshirt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adrianhajdin/project_threejs_ai/bbe1d55b16267a9d115555be8ed2e2a2e2bb957b/client/src/assets/logo-tshirt.png -------------------------------------------------------------------------------- /client/src/assets/stylish-tshirt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adrianhajdin/project_threejs_ai/bbe1d55b16267a9d115555be8ed2e2a2e2bb957b/client/src/assets/stylish-tshirt.png -------------------------------------------------------------------------------- /client/src/assets/swatch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adrianhajdin/project_threejs_ai/bbe1d55b16267a9d115555be8ed2e2a2e2bb957b/client/src/assets/swatch.png -------------------------------------------------------------------------------- /client/src/canvas/Backdrop.jsx: -------------------------------------------------------------------------------- 1 | import React, { useRef } from 'react' 2 | import { easing } from 'maath' 3 | import { useFrame } from '@react-three/fiber' 4 | import { AccumulativeShadows, RandomizedLight } from '@react-three/drei'; 5 | 6 | const Backdrop = () => { 7 | const shadows = useRef(); 8 | 9 | return ( 10 | 19 | 26 | 33 | 34 | ) 35 | } 36 | 37 | export default Backdrop -------------------------------------------------------------------------------- /client/src/canvas/CameraRig.jsx: -------------------------------------------------------------------------------- 1 | import React, { useRef } from 'react'; 2 | import { useFrame } from '@react-three/fiber'; 3 | import { easing } from 'maath'; 4 | import { useSnapshot } from 'valtio'; 5 | 6 | import state from '../store'; 7 | 8 | const CameraRig = ({ children }) => { 9 | const group = useRef(); 10 | const snap = useSnapshot(state); 11 | 12 | useFrame((state, delta) => { 13 | const isBreakpoint = window.innerWidth <= 1260; 14 | const isMobile = window.innerWidth <= 600; 15 | 16 | // set the initial position of the model 17 | let targetPosition = [-0.4, 0, 2]; 18 | if(snap.intro) { 19 | if(isBreakpoint) targetPosition = [0, 0, 2]; 20 | if(isMobile) targetPosition = [0, 0.2, 2.5]; 21 | } else { 22 | if(isMobile) targetPosition = [0, 0, 2.5] 23 | else targetPosition = [0, 0, 2]; 24 | } 25 | 26 | // set model camera position 27 | easing.damp3(state.camera.position, targetPosition, 0.25, delta) 28 | 29 | // set the model rotation smoothly 30 | easing.dampE( 31 | group.current.rotation, 32 | [state.pointer.y / 10, -state.pointer.x / 5, 0], 33 | 0.25, 34 | delta 35 | ) 36 | }) 37 | 38 | 39 | return {children} 40 | } 41 | 42 | export default CameraRig -------------------------------------------------------------------------------- /client/src/canvas/Shirt.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { easing } from 'maath'; 3 | import { useSnapshot } from 'valtio'; 4 | import { useFrame } from '@react-three/fiber'; 5 | import { Decal, useGLTF, useTexture } from '@react-three/drei'; 6 | 7 | import state from '../store'; 8 | 9 | const Shirt = () => { 10 | const snap = useSnapshot(state); 11 | const { nodes, materials } = useGLTF('/shirt_baked.glb'); 12 | 13 | const logoTexture = useTexture(snap.logoDecal); 14 | const fullTexture = useTexture(snap.fullDecal); 15 | 16 | useFrame((state, delta) => easing.dampC(materials.lambert1.color, snap.color, 0.25, delta)); 17 | 18 | const stateString = JSON.stringify(snap); 19 | 20 | return ( 21 | 22 | 29 | {snap.isFullTexture && ( 30 | 36 | )} 37 | 38 | {snap.isLogoTexture && ( 39 | 48 | )} 49 | 50 | 51 | ) 52 | } 53 | 54 | export default Shirt -------------------------------------------------------------------------------- /client/src/canvas/index.jsx: -------------------------------------------------------------------------------- 1 | import { Canvas } from '@react-three/fiber' 2 | import { Environment, Center } from '@react-three/drei'; 3 | 4 | import Shirt from './Shirt'; 5 | import Backdrop from './Backdrop'; 6 | import CameraRig from './CameraRig'; 7 | 8 | const CanvasModel = () => { 9 | return ( 10 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 |
24 |
25 |
26 | ) 27 | } 28 | 29 | export default CanvasModel -------------------------------------------------------------------------------- /client/src/components/AIPicker.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | import CustomButton from './CustomButton'; 4 | 5 | const AIPicker = ({ prompt, setPrompt, generatingImg, handleSubmit }) => { 6 | return ( 7 |
8 |