├── .gitignore
├── README.md
├── package-lock.json
├── package.json
├── public
├── BackedFace0.jpg
├── BackedFace1.jpg
├── BackedFace2.jpg
├── BackedFace3.jpg
├── ImpossibleBox.glb
├── Screen.jpg
├── commercejs.png
├── favicon.ico
├── index.html
├── robots.txt
├── stripe.png
└── vercel.png
└── src
├── App.js
├── components
├── Navbar.jsx
├── model
│ ├── Controls.jsx
│ ├── Cube.jsx
│ └── Model.jsx
├── pages
│ ├── Contact.jsx
│ ├── Home.jsx
│ ├── Maze.jsx
│ └── Sushi.jsx
├── shaders
│ ├── BoxContent.jsx
│ ├── Emission.jsx
│ └── RainMaterial.jsx
└── styles.js
├── index.css
└── index.js
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
25 | .vercel
26 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # James Hall's Portfolio
2 |
3 | [--Click here to visit the website--](https://impossible-box.vercel.app/)
4 |
5 | ## Available Scripts
6 |
7 | In the project directory, you can run:
8 |
9 | ### `npm start`
10 |
11 | Runs the app in the development mode.\
12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
13 |
14 | The page will reload when you make changes.\
15 | You may also see any lint errors in the console.
16 |
17 | ### `npm run build`
18 |
19 | Builds the app for production to the `build` folder.\
20 | It correctly bundles React in production mode and optimizes the build for the best performance.
21 |
22 | ---
23 |
24 | 
25 |
26 | ---
27 |
28 | ## How it works
29 |
30 | I modeled the four elements inside the box and created their textures using a process called baking in Blender.
31 | To create the effect,I converted the textures into three-fiber shaders that decides if we display the elements or not. This GLSL (close to C) language shaders lets you detect if one of the faces of the box is between camera and the textures. For each polygon of the model, we will therefore check through which side it is viewed so that we can display it or not. This way, you create an "impossible" effect where elements appear only when viewed from specific angles.
32 |
33 | Click here to see more --->[ The line segment intersection algorithm by Bryce Boe](https://bryceboe.com/2006/10/23/line-segment-intersection-algorithm/).
34 |
35 | The website is made with material ui and the contact form with email.js API.
36 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "portfolio",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@emailjs/browser": "^3.4.0",
7 | "@material-ui/core": "^4.12.3",
8 | "@material-ui/icons": "^4.11.2",
9 | "@react-three/drei": "^8.16.7",
10 | "@react-three/fiber": "^7.0.26",
11 | "framer-motion": "^6.2.8",
12 | "passive-events-support": "^1.0.33",
13 | "react": "^17.0.2",
14 | "react-dom": "^17.0.2",
15 | "react-hook-form": "^7.28.1",
16 | "react-router-dom": "^6.2.2",
17 | "react-scripts": "5.0.0",
18 | "three": "^0.138.3"
19 | },
20 | "scripts": {
21 | "start": "react-scripts start",
22 | "build": "react-scripts build",
23 | "test": "react-scripts test",
24 | "eject": "react-scripts eject"
25 | },
26 | "eslintConfig": {
27 | "extends": [
28 | "react-app",
29 | "react-app/jest"
30 | ]
31 | },
32 | "browserslist": {
33 | "production": [
34 | ">0.2%",
35 | "not dead",
36 | "not op_mini all"
37 | ],
38 | "development": [
39 | "last 1 chrome version",
40 | "last 1 firefox version",
41 | "last 1 safari version"
42 | ]
43 | },
44 | "devDependencies": {
45 | "glslify": "^7.1.1",
46 | "resize-observer-polyfill": "^1.5.1"
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/public/BackedFace0.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JamesHall38/Impossible-Box/55cba0ede0523dd48748c8e6c6a1f2752c0025f1/public/BackedFace0.jpg
--------------------------------------------------------------------------------
/public/BackedFace1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JamesHall38/Impossible-Box/55cba0ede0523dd48748c8e6c6a1f2752c0025f1/public/BackedFace1.jpg
--------------------------------------------------------------------------------
/public/BackedFace2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JamesHall38/Impossible-Box/55cba0ede0523dd48748c8e6c6a1f2752c0025f1/public/BackedFace2.jpg
--------------------------------------------------------------------------------
/public/BackedFace3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JamesHall38/Impossible-Box/55cba0ede0523dd48748c8e6c6a1f2752c0025f1/public/BackedFace3.jpg
--------------------------------------------------------------------------------
/public/ImpossibleBox.glb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JamesHall38/Impossible-Box/55cba0ede0523dd48748c8e6c6a1f2752c0025f1/public/ImpossibleBox.glb
--------------------------------------------------------------------------------
/public/Screen.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JamesHall38/Impossible-Box/55cba0ede0523dd48748c8e6c6a1f2752c0025f1/public/Screen.jpg
--------------------------------------------------------------------------------
/public/commercejs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JamesHall38/Impossible-Box/55cba0ede0523dd48748c8e6c6a1f2752c0025f1/public/commercejs.png
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JamesHall38/Impossible-Box/55cba0ede0523dd48748c8e6c6a1f2752c0025f1/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
13 |
14 | Impossible Box
15 |
16 |
17 | You need to enable JavaScript to run this app.
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/public/stripe.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JamesHall38/Impossible-Box/55cba0ede0523dd48748c8e6c6a1f2752c0025f1/public/stripe.png
--------------------------------------------------------------------------------
/public/vercel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JamesHall38/Impossible-Box/55cba0ede0523dd48748c8e6c6a1f2752c0025f1/public/vercel.png
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import React, { Suspense, useState, lazy } from 'react'
2 | import { BrowserRouter, Routes, Route, useLocation, useNavigate } from 'react-router-dom'
3 | import { default as Navbar } from './components/Navbar'
4 | import { CssBaseline, ThemeProvider } from '@material-ui/core'
5 | import { createTheme } from '@material-ui/core/styles'
6 | import useStyles from './components/styles'
7 | import { AnimatePresence } from "framer-motion"
8 |
9 | // Marking event handler as 'passive' to make the page more responsive.
10 | import { passiveSupport } from 'passive-events-support/src/utils'
11 | passiveSupport({
12 | listeners: [
13 | {
14 | element: 'canvas',
15 | event: 'wheel',
16 | prevented: true
17 | }
18 | ]
19 | })
20 |
21 |
22 | const Model = lazy(() => import('./components/model/Model'))
23 | const Maze = lazy(() => import('./components/pages/Maze'))
24 | const Contact = lazy(() => import('./components/pages/Contact'))
25 | const Sushi = lazy(() => import('./components/pages/Sushi'))
26 | const Home = lazy(() => import('./components/pages/Home'))
27 |
28 |
29 | const theme = createTheme({
30 | overrides: {
31 | MuiInputBase: {
32 | root: {
33 | height: '50px',
34 | },
35 | input: {
36 | color: 'white',
37 | },
38 | },
39 | },
40 | palette: {
41 | primary: {
42 | main: '#fff'
43 | }
44 | },
45 | typography: {
46 | fontFamily: '',
47 | h6: {
48 | fontSize: '1rem'
49 | },
50 | h5: {
51 | fontSize: '1.3rem'
52 | },
53 | body2: {
54 | fontSize: '0.7rem'
55 | }
56 |
57 | }
58 | });
59 |
60 |
61 | const Main = () => {
62 | const classes = useStyles()
63 | const location = useLocation()
64 | const navigate = useNavigate()
65 | const [path, setPath] = useState('')
66 |
67 | return (
68 |
69 |
70 | {/* */}
71 |
72 |
}>
73 |
74 |
75 |
76 |
77 |
78 | }> } />
79 | }> } />
80 | }> } />
81 | }> } />
82 |
83 |
84 |
85 | )
86 | }
87 |
88 | const App = () => {
89 | return (
90 |
91 |
92 |
93 |
94 |
95 |
96 | )
97 | }
98 |
99 | export default App
100 |
--------------------------------------------------------------------------------
/src/components/Navbar.jsx:
--------------------------------------------------------------------------------
1 | import { AppBar, Toolbar, IconButton, Typography } from '@material-ui/core';
2 | import { KeyboardArrowLeft, KeyboardArrowRight } from '@material-ui/icons';
3 | import { useEffect, useState } from 'react';
4 | import { Link, useLocation } from 'react-router-dom';
5 | import useStyles from './styles';
6 |
7 |
8 |
9 | const Navbar = ({ setPath }) => {
10 | const classes = useStyles();
11 |
12 | const location = useLocation();
13 | const [nextPage, setNextPage] = useState('/')
14 | const [previousPage, setPreviousPage] = useState('/')
15 |
16 |
17 | useEffect(() => {
18 | const paths = ['/', '/Sushi', '/Maze', '/Contact']
19 | paths.forEach((path, index) => {
20 | if (location.pathname === path) {
21 | setPreviousPage(paths[index === 0 ? 3 : index - 1])
22 | setNextPage(paths[(index + 1) % paths.length])
23 | }
24 | })
25 | }, [location])
26 |
27 | return (
28 | <>
29 |
30 |
31 | setPath(previousPage)} aria-label="previous" component={Link} to={previousPage} className={classes.hover}>
32 |
33 |
34 |
35 | setPath('/')} component={Link} to="/" variant="h5" className={classes.hover} style={{ fontWeight: '600', textDecoration: 'none' }} >
36 | James Hall
37 |
38 |
39 | setPath(nextPage)} aria-label="next" component={Link} to={nextPage} className={classes.hover} >
40 |
41 |
42 |
43 | setPath('/Sushi')} component={Link} to="/Sushi" variant="h6" className={classes.buttons} >
44 | Sushi
45 |
46 |
47 | setPath('/Maze')} component={Link} to="/Maze" variant="h6" className={classes.buttons}>
48 | Maze
49 |
50 |
51 | setPath('/Contact')} component={Link} to="/Contact" variant="h6" className={classes.buttons} >
52 | Contact
53 |
54 |
55 |
56 |
57 | >
58 | );
59 | };
60 |
61 | export default Navbar
--------------------------------------------------------------------------------
/src/components/model/Controls.jsx:
--------------------------------------------------------------------------------
1 | import { useRef, useEffect } from 'react'
2 | import { OrbitControls, AdaptiveDpr } from '@react-three/drei'
3 | import { useFrame } from '@react-three/fiber'
4 |
5 |
6 | const Controls = ({ navigate, location, path, rotate }) => {
7 | const controls = useRef()
8 |
9 | const controlsSettings = () => {
10 |
11 | controls.current.maxDistance = 4.1
12 | controls.current.minDistance = 4.1
13 | controls.current.maxPolarAngle = Math.PI / 2
14 | controls.current.minPolarAngle = Math.PI / 2.2
15 | controls.current.autoRotateSpeed *= -1
16 | controls.current.target.set(0, 0.3, 0)
17 | controls.current.enablePan = false
18 |
19 | if (window.innerWidth > 1.75 * window.innerHeight) {
20 | controls.current.target.set(0, -0.05, 0)
21 | controls.current.maxDistance = 2.5
22 | controls.current.minDistance = 2.5
23 | }
24 | }
25 |
26 | useEffect(() => {
27 | controlsSettings()
28 | const handleResize = () => {
29 | controlsSettings()
30 | }
31 | window.addEventListener("resize", handleResize);
32 | return () => {
33 | window.removeEventListener("resize", handleResize);
34 | }
35 | }, [])
36 |
37 | useFrame(({ camera }) => {
38 | const angle = controls.current.getAzimuthalAngle()
39 |
40 | if (angle > Math.PI / 4 && angle < 3 * Math.PI / 4) {
41 | if (location.pathname !== '/Sushi')
42 | navigate('/Sushi')
43 | }
44 | else if (angle > 3 * Math.PI / 4 || angle < -3 * Math.PI / 4) {
45 | if (location.pathname !== '/Maze')
46 | navigate('/Maze')
47 | }
48 | else if (angle > -3 * Math.PI / 4 && angle < -Math.PI / 4) {
49 | if (location.pathname !== '/Contact')
50 | navigate('/Contact')
51 | }
52 | else {
53 | if (location.pathname !== '/')
54 | navigate('/')
55 | }
56 |
57 | })
58 |
59 | useEffect(() => {
60 | if (path === '/Sushi')
61 | controls.current.setAzimuthalAngle(Math.PI / 2)
62 | else if (path === '/Maze')
63 | controls.current.setAzimuthalAngle(Math.PI)
64 | else if (path === '/Contact')
65 | controls.current.setAzimuthalAngle(3 * Math.PI / 2)
66 | else
67 | controls.current.setAzimuthalAngle(0)
68 |
69 | controls.current.autoRotate = false
70 | }, [path])
71 |
72 | useEffect(() => {
73 | controls.current.autoRotate = rotate
74 | }, [rotate])
75 |
76 | return (<>
77 |
78 |
79 | >
80 | )
81 | }
82 |
83 | export default Controls
--------------------------------------------------------------------------------
/src/components/model/Cube.jsx:
--------------------------------------------------------------------------------
1 | import { useRef, useEffect } from 'react'
2 | import { useGLTF } from '@react-three/drei'
3 | import { useFrame } from '@react-three/fiber'
4 | import { default as BoxContentMeshes } from '../shaders/BoxContent'
5 | import { default as EmissionMeshes } from '../shaders/Emission'
6 | import * as THREE from 'three'
7 | import '../shaders/RainMaterial'
8 |
9 |
10 | const Rain = () => {
11 | const ref = useRef()
12 | const points = useRef()
13 | const geometry = new THREE.BufferGeometry()
14 | const count = 300
15 | const positions = new Float32Array(count * 3)
16 |
17 | for (let i = 0; i < count; i++) {
18 | const i3 = i * 3
19 | positions[i3] = (Math.random() - 0.5) * 2.5
20 | positions[i3 + 1] = (Math.random() - 0.5) * 2.5
21 | positions[i3 + 2] = (Math.random() - 0.5) * 2.5 + 0.75
22 | }
23 | geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3))
24 |
25 | useEffect(() => {
26 | ref.current.depthWrite = false
27 | ref.current.blending = THREE.AdditiveBlending
28 | ref.current.vertexColors = true
29 | }, [])
30 |
31 | useFrame(({ clock }) => {
32 | ref.current.uniforms.uTime = { value: clock.elapsedTime }
33 | })
34 |
35 | return (
36 |
37 |
38 |
39 | )
40 | }
41 |
42 | const Emission = ({ face, faceName, nodes }) => {
43 | return (
44 | Object.values(nodes).map((node, index) => {
45 | if (node.type === 'Mesh')
46 | if (node.name.includes(faceName))
47 | return (
48 |
49 |
50 | )
51 | return (null)
52 | }))
53 | }
54 |
55 | const Cube = () => {
56 | const { nodes, materials } = useGLTF('/ImpossibleBox.glb')
57 | return (
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 | )
75 | }
76 | useGLTF.preload('/ImpossibleBox.glb')
77 |
78 | export default Cube
--------------------------------------------------------------------------------
/src/components/model/Model.jsx:
--------------------------------------------------------------------------------
1 | import { useState, useEffect } from 'react'
2 | import { Canvas } from '@react-three/fiber'
3 | import { default as Controls } from './Controls'
4 | import { default as Cube } from './Cube'
5 | import useStyles from './../styles'
6 | import ResizeObserver from 'resize-observer-polyfill';
7 |
8 |
9 |
10 | const Model = (props) => {
11 | const [rotate, setRotate] = useState(true)
12 | const classes = useStyles()
13 |
14 | window.ResizeObserver = ResizeObserver;
15 |
16 |
17 | // For mobile devices
18 | useEffect(() => {
19 | const handleMouseDown = () => {
20 | setRotate(false)
21 | }
22 | window.addEventListener("touchstart", handleMouseDown);
23 | return () => {
24 | window.removeEventListener("touchstart", handleMouseDown);
25 | }
26 | })
27 |
28 |
29 | return (
30 |
31 |
{ setRotate(false) }} touchStart={() => { setRotate(false) }}
36 | // set the viewport window sizes
37 | camera={{ fov: 40 }}
38 | resize={{ polyfill: ResizeObserver }}
39 | dpr={2}>
40 |
41 |
42 | { setRotate(false) }} touchStart={() => { setRotate(false) }}>
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | )
54 | }
55 |
56 | export default Model
--------------------------------------------------------------------------------
/src/components/pages/Contact.jsx:
--------------------------------------------------------------------------------
1 |
2 | import React, { useRef, useState } from 'react'
3 | import { Typography, Card, CardContent } from '@material-ui/core'
4 | import useStyles from '../styles'
5 | import { motion } from "framer-motion"
6 | import { Button, Grid, TextField } from '@material-ui/core'
7 | import { useForm, FormProvider, useFormContext, Controller } from 'react-hook-form'
8 | import emailjs from '@emailjs/browser'
9 |
10 |
11 | const FormInput = ({ name, label, required, value, onChange }) => {
12 | const { control } = useFormContext()
13 | return (
14 | (
18 |
35 | )}
36 | />
37 | )
38 | }
39 |
40 | const Contact = () => {
41 | const classes = useStyles()
42 | const methods = useForm()
43 | const form = useRef()
44 | const [nameFormContent, setNameFormContent] = useState('')
45 | const [emailFormContent, setEmailFormContent] = useState('')
46 | const [messageFormContent, setMessageFormContent] = useState('')
47 |
48 | const handleSubmit = (e) => {
49 | sendEmail(e)
50 |
51 | setNameFormContent('')
52 | setEmailFormContent('')
53 | setMessageFormContent('')
54 | }
55 |
56 | const sendEmail = (e) => {
57 | e.preventDefault()
58 | emailjs.sendForm('service_r28kgso', 'template_v20bcjf', form.current, 'pe21uc5Y6SIdkmrMv')
59 | .then((result) => {
60 | console.log(result.text)
61 | }, (error) => {
62 | console.log(error.text)
63 | })
64 | }
65 |
66 | return (
67 |
68 |
69 |
70 |
75 |
76 |
77 | Contactez-moi
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
141 |
142 |
143 |
144 |
145 | )
146 | }
147 |
148 | export default Contact
--------------------------------------------------------------------------------
/src/components/pages/Home.jsx:
--------------------------------------------------------------------------------
1 | import { Typography, Card, CardContent, Link } from '@material-ui/core'
2 | import useStyles from '../styles'
3 | import { motion } from "framer-motion"
4 |
5 |
6 | const Home = () => {
7 | const classes = useStyles()
8 |
9 | return (
10 |
11 |
12 |
13 |
18 |
19 |
20 | Bonjour, je suis développeur front-end à Grenoble
21 |
22 |
23 |
24 | Bienvenue sur mon portfolio!
25 |
26 |
27 |
28 |
29 |
30 |
35 |
36 |
37 | James Hall
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 | )
52 | }
53 |
54 | export default Home
--------------------------------------------------------------------------------
/src/components/pages/Maze.jsx:
--------------------------------------------------------------------------------
1 | import { Typography, Card, CardContent, Grid, Link } from '@material-ui/core'
2 | import useStyles from '../styles'
3 | import { motion } from "framer-motion"
4 |
5 |
6 |
7 | const Maze = () => {
8 | const classes = useStyles()
9 |
10 | return (
11 |
12 |
13 |
14 |
19 |
20 |
21 | Maze Solver
22 |
23 |
24 |
25 |
26 |
27 |
32 |
33 |
34 |
35 |
36 |
37 | Un site fait avec React qui permet de visualiser deux algorithmes: un
38 | algorithme de division récursive afin de générer un labyrinthe,
39 | et l'algorithme A*, qui permet de le résoudre en trouvant le chemin de plus court.
40 |
41 |
42 |
43 |
44 |
45 |
46 |
51 |
52 |
53 | Visiter
54 |
55 |
56 |
57 |
58 |
59 | )
60 | }
61 |
62 | export default Maze
--------------------------------------------------------------------------------
/src/components/pages/Sushi.jsx:
--------------------------------------------------------------------------------
1 | import { Typography, Card, CardContent, Grid, Link } from '@material-ui/core'
2 | import useStyles from '../styles'
3 | import { motion } from "framer-motion"
4 |
5 |
6 | const Sushi = () => {
7 | const classes = useStyles()
8 |
9 | return (
10 | <>
11 |
12 |
13 |
14 |
15 |
20 |
21 |
22 | Sushi Shop
23 |
24 |
25 |
26 |
27 |
28 |
29 |
34 |
35 |
36 |
37 |
38 | Un site d'e-commmerce qui présente les produits en 3D et utilise l'API de commerce.js pour traîter les commandes.
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 | React
47 |
48 |
49 |
50 |
51 |
52 |
53 | three.js
54 |
55 |
56 |
57 |
58 |
59 |
60 | MUI
61 |
62 |
63 |
64 |
65 |
66 |
67 | Stripe
68 |
69 |
70 |
71 |
72 |
73 |
74 | commerce
75 |
76 |
77 |
78 |
79 |
80 |
81 | Vercel
82 |
83 |
84 |
85 |
86 |
87 |
88 |
93 |
94 |
95 | Visiter
96 |
97 |
98 |
99 |
100 |
101 | >
102 | )
103 | }
104 |
105 |
106 | export default Sushi
--------------------------------------------------------------------------------
/src/components/shaders/BoxContent.jsx:
--------------------------------------------------------------------------------
1 | import { useMemo } from 'react'
2 | import { useTexture } from '@react-three/drei'
3 |
4 |
5 | const BoxContent = ({ face, faceName, nodes, screen }) => {
6 | const texture = useTexture(`BackedFace${face}.jpg`)
7 | const screenTexture = useTexture(`Screen.jpg`)
8 |
9 | texture.flipY = false
10 |
11 | const vertexShader = `
12 | out vec3 worldPosition;
13 | varying vec2 vUv;
14 | void main()
15 | {
16 | worldPosition = vec3(modelMatrix * vec4(position, 1.0));
17 | vec4 modelPosition = modelMatrix * vec4(position, 1.0);
18 | vec4 viewPosition = viewMatrix * modelPosition;
19 | vec4 projectedPosition = projectionMatrix * viewPosition;
20 | gl_Position = projectedPosition;
21 | vUv = uv;
22 | }`
23 | const fragmentShader = `
24 | in vec3 worldPosition;
25 | uniform sampler2D uTexture;
26 | varying vec2 vUv;
27 | uniform int face;
28 | const vec2 corners[4] = vec2[](vec2(0.5, 0.5), vec2(-0.5, 0.5), vec2(-0.5, -0.5), vec2(0.5, -0.5));
29 | bool order(vec2 A, vec2 B, vec2 C) {
30 | return (C.y-A.y) * (B.x-A.x) > (B.y-A.y) * (C.x-A.x);
31 | }
32 | bool intersect(vec2 A, vec2 B, vec2 C, vec2 D) {
33 | return order(A,C,D) != order(B,C,D) && order(A,B,C) != order(A,B,D);
34 | }
35 | void main() {
36 | vec2 a = worldPosition.xz;
37 | vec2 b = cameraPosition.xz;
38 | vec2 aa ;
39 | vec2 bb ;
40 | if (bool(mod(float(face),2.0))){
41 | aa = worldPosition.xy;
42 | bb = cameraPosition.xy;
43 | }
44 | else{
45 | aa = worldPosition.yz;
46 | bb = cameraPosition.yz;
47 | }
48 | int next = int(mod(float(face + 1), 4.0));
49 | vec2 c = corners[face];
50 | vec2 d = corners[next];
51 | if (!(intersect(a, b, c, d) && intersect(aa, bb, c, d))) {
52 | discard;
53 | }
54 | vec4 textureColor = texture2D(uTexture, vUv);
55 | gl_FragColor = textureColor;
56 | }`
57 |
58 | const data = useMemo(
59 | () => ({
60 | uniforms: {
61 | face: { value: face },
62 | uTexture: { value: screen ? screenTexture : texture }
63 | },
64 | fragmentShader,
65 | vertexShader
66 | }),
67 | [face, fragmentShader, vertexShader, texture, screen, screenTexture]
68 | )
69 |
70 | if (screen) {
71 | return (
72 |
73 |
74 | )
75 | }
76 |
77 | return (
78 | Object.values(nodes).map((node, index) => {
79 | if (node.type === 'Mesh')
80 | if (node.name.includes(faceName))
81 | return (
82 |
83 |
84 | )
85 | return (null)
86 | }))
87 | }
88 |
89 | export default BoxContent
--------------------------------------------------------------------------------
/src/components/shaders/Emission.jsx:
--------------------------------------------------------------------------------
1 | import * as THREE from 'three'
2 |
3 | const Emission = ({ node, face }) => {
4 | const vertexShader = `
5 | out vec3 worldPosition;
6 | varying vec2 vUv;
7 | void main()
8 | {
9 | worldPosition = vec3(modelMatrix * vec4(position, 1.0));
10 | vec4 modelPosition = modelMatrix * vec4(position, 1.0);
11 | vec4 viewPosition = viewMatrix * modelPosition;
12 | vec4 projectedPosition = projectionMatrix * viewPosition;
13 | gl_Position = projectedPosition;
14 | vUv = uv;
15 | }
16 | `
17 | const fragmentShader = `
18 | in vec3 worldPosition;
19 | uniform vec4 uTexture;
20 | varying vec2 vUv;
21 | uniform int face;
22 | const vec2 corners[4] = vec2[](vec2(0.5, 0.5), vec2(-0.5, 0.5), vec2(-0.5, -0.5), vec2(0.5, -0.5));
23 | bool order(vec2 A, vec2 B, vec2 C) {
24 | return (C.y-A.y) * (B.x-A.x) > (B.y-A.y) * (C.x-A.x);
25 | }
26 | bool intersect(vec2 A, vec2 B, vec2 C, vec2 D) {
27 | return order(A,C,D) != order(B,C,D) && order(A,B,C) != order(A,B,D);
28 | }
29 | void main() {
30 | vec2 a = worldPosition.xz;
31 | vec2 b = cameraPosition.xz;
32 | vec2 aa ;
33 | vec2 bb ;
34 |
35 | if (bool(mod(float(face),2.0))){
36 | aa = worldPosition.xy;
37 | bb = cameraPosition.xy;
38 | }
39 | else{
40 | aa = worldPosition.yz;
41 | bb = cameraPosition.yz;
42 | }
43 | int next = int(mod(float(face + 1), 4.0));
44 | vec2 c = corners[face];
45 | vec2 d = corners[next];
46 | if (!(intersect(a, b, c, d) && intersect(aa, bb, c, d))) {
47 | discard;
48 | }
49 | gl_FragColor = uTexture;
50 | }`
51 | const texture = new THREE.Vector4(node.material.emissive.r, node.material.emissive.g, node.material.emissive.b, 1)
52 | const data = {
53 | uniforms: {
54 | face: { value: face },
55 | uTexture: { value: texture }
56 | },
57 | fragmentShader,
58 | vertexShader
59 | }
60 |
61 | return
62 | }
63 |
64 | export default Emission
--------------------------------------------------------------------------------
/src/components/shaders/RainMaterial.jsx:
--------------------------------------------------------------------------------
1 | import { shaderMaterial } from '@react-three/drei'
2 | import glsl from 'glslify';
3 | import { extend } from '@react-three/fiber'
4 |
5 |
6 | const RainMaterial = shaderMaterial(
7 | { uTime: 0, uSize: 30 * window.devicePixelRatio },
8 | // vertex shader
9 | glsl`
10 | uniform float uTime;
11 | uniform float uSize;
12 | out vec3 worldPosition;
13 | attribute float aScale;
14 | void main()
15 | {
16 | worldPosition = vec3(modelMatrix * vec4(position, 1.0));
17 | vec4 modelPosition = modelMatrix * vec4(position, 1.0);
18 | // modelPosition.x = mod(-uTime * 0.5 + position.x , 1.0)-0.5;
19 | modelPosition.y = mod(-uTime * 1.75 + position.y , 1.0)-0.5;
20 | vec4 viewPosition = viewMatrix * modelPosition;
21 | gl_Position = projectionMatrix * viewPosition;
22 | gl_PointSize = uSize ;
23 | gl_PointSize *= (1.0 / - viewPosition.z);
24 | }
25 | `,
26 | // fragment shader
27 | glsl`
28 | in vec3 worldPosition;
29 | const vec2 corners[4] = vec2[](vec2(0.5, 0.5), vec2(-0.5, 0.5), vec2(-0.5, -0.5), vec2(0.5, -0.5));
30 |
31 | bool order(vec2 A, vec2 B, vec2 C) {
32 | return (C.y-A.y) * (B.x-A.x) > (B.y-A.y) * (C.x-A.x);
33 | }
34 |
35 | bool intersect(vec2 A, vec2 B, vec2 C, vec2 D) {
36 | return order(A,C,D) != order(B,C,D) && order(A,B,C) != order(A,B,D);
37 | }
38 |
39 | void main() {
40 | int face = 2;
41 | vec2 a = worldPosition.xz;
42 | vec2 b = cameraPosition.xz;
43 | vec2 aa ;
44 | vec2 bb ;
45 | if (bool(mod(float(face),2.0))){
46 | aa = worldPosition.xy;
47 | bb = cameraPosition.xy;
48 | }
49 | else{
50 | aa = worldPosition.yz;
51 | bb = cameraPosition.yz;
52 | }
53 | int next = int(mod(float(face + 1), 4.0));
54 | vec2 c = corners[face];
55 | vec2 d = corners[next];
56 | if (!(intersect(a, b, c, d) && intersect(aa, bb, c, d))) {
57 | discard;
58 | }
59 | float strength = mod(gl_PointCoord.x + 0.5 - gl_PointCoord.y * 0.1, 1.0);
60 | strength = step(0.90, strength);
61 | gl_FragColor = vec4(vec3(strength), 0.25);
62 | }
63 | `
64 | )
65 | extend({ RainMaterial })
66 |
--------------------------------------------------------------------------------
/src/components/styles.js:
--------------------------------------------------------------------------------
1 | import { makeStyles } from '@material-ui/core/styles'
2 |
3 | export default makeStyles(() => ({
4 | appbar: {
5 | background: 'rgb(32,32,35,0.5)',
6 | backdropFilter: 'blur(10px)',
7 | boxShadow: 'none',
8 | display: 'flex',
9 | alignItems: 'flex-start',
10 | height: '60px',
11 | top: 'auto',
12 | bottom: '0',
13 | overflow: 'hidden',
14 | paddingLeft: '15vw',
15 | "@media (max-width: calc(1.75*100vh))": {
16 | alignItems: 'center',
17 | paddingLeft: '0',
18 |
19 | },
20 | },
21 | hover: {
22 | textAlign: 'center',
23 | color: 'white',
24 | padding: '6px',
25 | borderRadius: '5px',
26 | '&:hover': {
27 | background: 'rgb(255,255,255,0.1)',
28 | textDecoration: 'underline',
29 | },
30 | },
31 | buttons: {
32 | color: 'white',
33 | paddingRight: '10px',
34 | textDecoration: 'none',
35 | '&:hover': {
36 | textDecoration: 'underline',
37 | },
38 | },
39 | container: {
40 | position: 'relative',
41 | margin: '10px',
42 | height: '261px',
43 | width: '450px',
44 | },
45 | responsiveCard: {
46 | position: 'absolute',
47 | left: 'calc(70vw - 200px)',
48 | width: '100%',
49 | // height: '100%',
50 | height: '261px',
51 | color: 'white',
52 | top: 'calc(50vh - 135px)',
53 | background: 'rgb(32,32,35,0.5)',
54 | backdropFilter: 'blur(10px)',
55 | "@media (max-width: calc(1.75*100vh))": {
56 | top: '0',
57 | left: 'calc(50vw - 50% - 10px)',
58 | textAlign: 'center',
59 | },
60 | },
61 | suspense: {
62 | position: 'absolute',
63 | margin: '10px',
64 | left: 'calc(70vw - 200px)',
65 | borderRadius: '5px',
66 | width: '450px',
67 | // height: '100%',
68 | height: '261px',
69 | top: 'calc(50vh - 135px)',
70 | background: 'rgb(32,32,35,0.5)',
71 | backdropFilter: 'blur(10px)',
72 | "@media (max-width: calc(1.75*100vh))": {
73 | top: '0',
74 | left: 'calc(50vw - 235px)',
75 | textAlign: 'center',
76 | },
77 | },
78 | cards: {
79 | display: 'flex',
80 | flexDirection: 'column',
81 | justifyContent: 'center',
82 | alignItems: 'center',
83 | background: 'rgb(32,32,35,0.1)',
84 | aspectRatio: '1',
85 | width: 'min(max(5px, 100%), 95px)',
86 | height: ' min(max(5px, 100%), 95px)',
87 | color: 'white',
88 | },
89 | load: {
90 | position: 'absolute',
91 | // top: '20vh',
92 | top: '20vh',
93 | left: '25vw',
94 | width: '50px',
95 | height: '50px',
96 | margin: '110px auto 0',
97 | border: 'solid 5px #fff',
98 | borderRadius: '50%',
99 | borderRightColor: 'transparent',
100 | borderBottomColor: 'transparent',
101 | transition: 'all 0.5s ease-in',
102 | animationName: '$rotate',
103 | animationDuration: ' 1.0s',
104 | animationIterationCount: 'infinite',
105 | animationTimingFunction: 'linear',
106 | "@media (max-width: calc(1.75*100vh))": {
107 | left: '45vw',
108 | top: '45vh',
109 | },
110 | },
111 | canvas: {
112 | position: 'absolute',
113 | background: '#BC2020',
114 | animationName: '$fadein',
115 | animationDuration: ' 1.0s',
116 | minWidth: '150vw',
117 | left: '-50vw',
118 | "@media (max-width: calc(1.75*100vh))": {
119 | minWidth: '100vw',
120 | left: '0',
121 | },
122 | },
123 | '@keyframes rotate': {
124 | from: {
125 | transform: 'rotate(0deg)',
126 | },
127 | to: {
128 | transform: 'rotate(360deg)',
129 | }
130 | },
131 | '@keyframes fadein': {
132 | from: {
133 | opacity: '0'
134 | },
135 | to: {
136 | opacity: '1'
137 | },
138 | }
139 | }))
--------------------------------------------------------------------------------
/src/index.css:
--------------------------------------------------------------------------------
1 | @import url('https://fonts.googleapis.com/css2?family=M+PLUS+Rounded+1c&display=swap');
2 |
3 | :root {
4 | font-family: 'M PLUS Rounded 1c', sans-serif;
5 | background: #bc2020;
6 | }
7 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import ReactDOM from 'react-dom'
3 | import './index.css'
4 | import App from './App'
5 |
6 | ReactDOM.render(
7 |
8 |
9 | ,
10 | document.getElementById('root')
11 | )
12 |
--------------------------------------------------------------------------------