-
Notifications
You must be signed in to change notification settings - Fork 26.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
static folder replaced with public folder - linting issues resolved
- Loading branch information
Afsane Fadaei
committed
Jan 28, 2020
1 parent
a181ee1
commit 4a0f340
Showing
9 changed files
with
157 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const withCSS = require('@zeit/next-css'); | ||
const withCSS = require('@zeit/next-css') | ||
module.exports = withCSS({ | ||
cssModules: true | ||
}); | ||
cssModules: true, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,83 @@ | ||
import React, { useRef, useState, useEffect, Suspense } from "react"; | ||
import * as THREE from "three"; | ||
import { Canvas, useFrame, useLoader } from "react-three-fiber"; | ||
import './index.css'; | ||
import React, { useRef, useState, useEffect, Suspense } from 'react' | ||
import * as THREE from 'three' | ||
import { Canvas, useFrame, useLoader } from 'react-three-fiber' | ||
import './index.css' | ||
|
||
let GLTFLoader; | ||
let GLTFLoader | ||
|
||
const Bird = ({ speed, factor, url, ...props }) => { | ||
const gltf = useLoader(GLTFLoader, url); | ||
const group = useRef(); | ||
const [mixer] = useState(() => new THREE.AnimationMixer()); | ||
useEffect( | ||
() => void mixer.clipAction(gltf.animations[0], group.current).play(), | ||
[] | ||
); | ||
useFrame((state, delta) => { | ||
group.current.rotation.y += | ||
Math.sin((delta * factor) / 2) * Math.cos((delta * factor) / 2) * 1.5; | ||
mixer.update(delta * speed); | ||
}); | ||
return ( | ||
<group ref={group}> | ||
<scene name="Scene" {...props}> | ||
<mesh | ||
name="Object_0" | ||
morphTargetDictionary={gltf.__$[1].morphTargetDictionary} | ||
morphTargetInfluences={gltf.__$[1].morphTargetInfluences} | ||
rotation={[1.5707964611537577, 0, 0]} | ||
> | ||
<bufferGeometry attach="geometry" {...gltf.__$[1].geometry} /> | ||
<meshStandardMaterial | ||
attach="material" | ||
{...gltf.__$[1].material} | ||
name="Material_0_COLOR_0" | ||
/> | ||
</mesh> | ||
</scene> | ||
</group> | ||
); | ||
const gltf = useLoader(GLTFLoader, url) | ||
const group = useRef() | ||
const [mixer] = useState(() => new THREE.AnimationMixer()) | ||
useEffect( | ||
() => void mixer.clipAction(gltf.animations[0], group.current).play(), | ||
[gltf.animations, mixer] | ||
) | ||
useFrame((state, delta) => { | ||
group.current.rotation.y += | ||
Math.sin((delta * factor) / 2) * Math.cos((delta * factor) / 2) * 1.5 | ||
mixer.update(delta * speed) | ||
}) | ||
return ( | ||
<group ref={group}> | ||
<scene name="Scene" {...props}> | ||
<mesh | ||
name="Object_0" | ||
morphTargetDictionary={gltf.__$[1].morphTargetDictionary} | ||
morphTargetInfluences={gltf.__$[1].morphTargetInfluences} | ||
rotation={[1.5707964611537577, 0, 0]} | ||
> | ||
<bufferGeometry attach="geometry" {...gltf.__$[1].geometry} /> | ||
<meshStandardMaterial | ||
attach="material" | ||
{...gltf.__$[1].material} | ||
name="Material_0_COLOR_0" | ||
/> | ||
</mesh> | ||
</scene> | ||
</group> | ||
) | ||
} | ||
|
||
const Birds = () => { | ||
return new Array(5).fill().map((_, i) => { | ||
const x = (15 + Math.random() * 30) * (Math.round(Math.random()) ? -1 : 1); | ||
const y = -10 + Math.random() * 20; | ||
const z = -5 + Math.random() * 10; | ||
const bird = ["stork", "parrot", "flamingo"][Math.round(Math.random() * 2)]; | ||
let speed = bird === "stork" ? 0.5 : bird === "flamingo" ? 2 : 5; | ||
let factor = | ||
bird === "stork" | ||
? 0.5 + Math.random() | ||
: bird === "flamingo" | ||
? 0.25 + Math.random() | ||
: 1 + Math.random() - 0.5; | ||
return ( | ||
<Bird | ||
key={i} | ||
position={[x, y, z]} | ||
rotation={[0, x > 0 ? Math.PI : 0, 0]} | ||
speed={speed} | ||
factor={factor} | ||
url={`/static/glb/${bird}.glb`} | ||
/> | ||
); | ||
}); | ||
return new Array(5).fill().map((_, i) => { | ||
const x = (15 + Math.random() * 30) * (Math.round(Math.random()) ? -1 : 1) | ||
const y = -10 + Math.random() * 20 | ||
const z = -5 + Math.random() * 10 | ||
const bird = ['stork', 'parrot', 'flamingo'][Math.round(Math.random() * 2)] | ||
let speed = bird === 'stork' ? 0.5 : bird === 'flamingo' ? 2 : 5 | ||
let factor = | ||
bird === 'stork' | ||
? 0.5 + Math.random() | ||
: bird === 'flamingo' | ||
? 0.25 + Math.random() | ||
: 1 + Math.random() - 0.5 | ||
return ( | ||
<Bird | ||
key={i} | ||
position={[x, y, z]} | ||
rotation={[0, x > 0 ? Math.PI : 0, 0]} | ||
speed={speed} | ||
factor={factor} | ||
url={`/glb/${bird}.glb`} | ||
/> | ||
) | ||
}) | ||
} | ||
|
||
const BirdsPage = props => { | ||
useEffect(() => { | ||
GLTFLoader = require("three/examples/jsm/loaders/GLTFLoader").GLTFLoader; | ||
}, []); | ||
return ( | ||
<Canvas camera={{ position: [0, 0, 35] }}> | ||
<ambientLight intensity={2} /> | ||
<pointLight position={[40, 40, 40]} /> | ||
<Suspense fallback={null}> | ||
<Birds /> | ||
</Suspense> | ||
</Canvas> | ||
); | ||
}; | ||
useEffect(() => { | ||
GLTFLoader = require('three/examples/jsm/loaders/GLTFLoader').GLTFLoader | ||
}, []) | ||
return ( | ||
<Canvas camera={{ position: [0, 0, 35] }}> | ||
<ambientLight intensity={2} /> | ||
<pointLight position={[40, 40, 40]} /> | ||
<Suspense fallback={null}> | ||
<Birds /> | ||
</Suspense> | ||
</Canvas> | ||
) | ||
} | ||
|
||
export default BirdsPage; | ||
export default BirdsPage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
import React, { useRef, useState, Suspense } from "react"; | ||
import { Canvas, useFrame } from "react-three-fiber"; | ||
import './index.css'; | ||
import React, { useRef, useState, Suspense } from 'react' | ||
import { Canvas, useFrame } from 'react-three-fiber' | ||
import './index.css' | ||
|
||
const Box = (props) => { | ||
const mesh = useRef(); | ||
const Box = props => { | ||
const mesh = useRef() | ||
|
||
const [hovered, setHover] = useState(false); | ||
const [active, setActive] = useState(false); | ||
const [hovered, setHover] = useState(false) | ||
const [active, setActive] = useState(false) | ||
|
||
useFrame(() => (mesh.current.rotation.x = mesh.current.rotation.y += 0.01)); | ||
useFrame(() => (mesh.current.rotation.x = mesh.current.rotation.y += 0.01)) | ||
|
||
return ( | ||
<mesh | ||
{...props} | ||
ref={mesh} | ||
scale={active ? [6, 6, 6] : [5, 5, 5]} | ||
onClick={e => setActive(!active)} | ||
onPointerOver={e => setHover(true)} | ||
onPointerOut={e => setHover(false)} | ||
> | ||
<boxBufferGeometry attach="geometry" args={[1, 1, 1]} /> | ||
<meshStandardMaterial | ||
attach="material" | ||
color={hovered ? "#2b6c76" : "#720b23"} | ||
/> | ||
</mesh> | ||
); | ||
}; | ||
return ( | ||
<mesh | ||
{...props} | ||
ref={mesh} | ||
scale={active ? [6, 6, 6] : [5, 5, 5]} | ||
onClick={e => setActive(!active)} | ||
onPointerOver={e => setHover(true)} | ||
onPointerOut={e => setHover(false)} | ||
> | ||
<boxBufferGeometry attach="geometry" args={[1, 1, 1]} /> | ||
<meshStandardMaterial | ||
attach="material" | ||
color={hovered ? '#2b6c76' : '#720b23'} | ||
/> | ||
</mesh> | ||
) | ||
} | ||
|
||
const BirdsPage = props => { | ||
return[ | ||
<h1>Click on me - Hover me :)</h1>, | ||
<Canvas camera={{ position: [0, 0, 35] }}> | ||
<ambientLight intensity={2} /> | ||
<pointLight position={[40, 40, 40]} /> | ||
<Suspense fallback={null}> | ||
<Box position={[10, 0, 0]} /> | ||
<Box position={[-10, 0, 0]} /> | ||
<Box position={[0, 10, 0]} /> | ||
<Box position={[0, -10, 0]} /> | ||
</Suspense> | ||
</Canvas>, | ||
] | ||
}; | ||
return [ | ||
<h1>Click on me - Hover me :)</h1>, | ||
<Canvas camera={{ position: [0, 0, 35] }}> | ||
<ambientLight intensity={2} /> | ||
<pointLight position={[40, 40, 40]} /> | ||
<Suspense fallback={null}> | ||
<Box position={[10, 0, 0]} /> | ||
<Box position={[-10, 0, 0]} /> | ||
<Box position={[0, 10, 0]} /> | ||
<Box position={[0, -10, 0]} /> | ||
</Suspense> | ||
</Canvas>, | ||
] | ||
} | ||
|
||
export default BirdsPage; | ||
export default BirdsPage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,43 @@ | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
width: 100%; | ||
height: 100vh; | ||
background: lavender; | ||
margin: 0; | ||
padding: 0; | ||
width: 100%; | ||
height: 100vh; | ||
background: lavender; | ||
} | ||
|
||
canvas { | ||
width: 100%; | ||
height: 100vh; | ||
width: 100%; | ||
height: 100vh; | ||
} | ||
|
||
.main { | ||
background: hotpink; | ||
padding: 50px; | ||
border-radius: 4px; | ||
display: flex; | ||
margin: 200px; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
color: white; | ||
background: hotpink; | ||
padding: 50px; | ||
border-radius: 4px; | ||
display: flex; | ||
margin: 200px; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
color: white; | ||
} | ||
|
||
a { | ||
color: white; | ||
display: block; | ||
text-decoration: unset; | ||
font-size: 20px; | ||
margin: 5px 0; | ||
color: white; | ||
display: block; | ||
text-decoration: unset; | ||
font-size: 20px; | ||
margin: 5px 0; | ||
} | ||
|
||
a:hover { | ||
color: #3f51b5; | ||
color: #3f51b5; | ||
} | ||
|
||
h1 { | ||
display: flex; | ||
justify-content: center; | ||
align-content: center; | ||
color: hotpink; | ||
display: flex; | ||
justify-content: center; | ||
align-content: center; | ||
color: hotpink; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
import React from 'react'; | ||
import Link from "next/link"; | ||
import style from './index.css'; | ||
import React from 'react' | ||
import Link from 'next/link' | ||
import style from './index.css' | ||
|
||
const Index = () => { | ||
return ( | ||
<div className={style.main}> | ||
<Link href="/birds"><a>Birds Example</a></Link> | ||
<Link href="/boxes"><a>Boxes Example</a></Link> | ||
</div> | ||
); | ||
}; | ||
return ( | ||
<div className={style.main}> | ||
<Link href="/birds"> | ||
<a>Birds Example</a> | ||
</Link> | ||
<Link href="/boxes"> | ||
<a>Boxes Example</a> | ||
</Link> | ||
</div> | ||
) | ||
} | ||
|
||
export default Index; | ||
export default Index |
File renamed without changes.
File renamed without changes.
File renamed without changes.