Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dev] update version of package and adapte code #173

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions app/blob/page.jsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
'use client'

import dynamic from 'next/dynamic'

import { View } from '@react-three/drei'
const Blob = dynamic(() => import('@/components/canvas/Examples').then((mod) => mod.Blob), { ssr: false })
const View = dynamic(() => import('@/components/canvas/View').then((mod) => mod.View), {
ssr: false,
loading: () => (
<div className='flex h-96 w-full flex-col items-center justify-center'>
<svg className='-ml-1 mr-3 h-5 w-5 animate-spin text-black' fill='none' viewBox='0 0 24 24'>
<circle className='opacity-25' cx='12' cy='12' r='10' stroke='currentColor' strokeWidth='4' />
<path
className='opacity-75'
fill='currentColor'
d='M4 12a8 8 0 0 1 8-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 0 1 4 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z'
/>
</svg>
</div>
),
})
const Common = dynamic(() => import('@/components/canvas/View').then((mod) => mod.Common), { ssr: false })

const Common = dynamic(() => import('@/components/canvas/Common').then((mod) => mod.Common), { ssr: false })

export default function Page() {
return (
Expand Down
26 changes: 6 additions & 20 deletions app/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,12 @@

import dynamic from 'next/dynamic'
import { Suspense } from 'react'
import { View } from '@react-three/drei'

const Logo = dynamic(() => import('@/components/canvas/Examples').then((mod) => mod.Logo), { ssr: false })
const Dog = dynamic(() => import('@/components/canvas/Examples').then((mod) => mod.Dog), { ssr: false })
const Duck = dynamic(() => import('@/components/canvas/Examples').then((mod) => mod.Duck), { ssr: false })
const View = dynamic(() => import('@/components/canvas/View').then((mod) => mod.View), {
ssr: false,
loading: () => (
<div className='flex h-96 w-full flex-col items-center justify-center'>
<svg className='-ml-1 mr-3 h-5 w-5 animate-spin text-black' fill='none' viewBox='0 0 24 24'>
<circle className='opacity-25' cx='12' cy='12' r='10' stroke='currentColor' strokeWidth='4' />
<path
className='opacity-75'
fill='currentColor'
d='M4 12a8 8 0 0 1 8-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 0 1 4 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z'
/>
</svg>
</div>
),
})
const Common = dynamic(() => import('@/components/canvas/View').then((mod) => mod.Common), { ssr: false })
const Common = dynamic(() => import('@/components/canvas/Common').then((mod) => mod.Common), { ssr: false })

export default function Page() {
return (
Expand Down Expand Up @@ -51,19 +37,19 @@ export default function Page() {
<p className='mb-8 text-gray-600'>Drag, scroll, pinch, and rotate the canvas to explore the 3D scene.</p>
</div>
<div className='relative my-12 h-48 w-full py-6 sm:w-1/2 md:mb-40'>
<View orbit className='relative h-full sm:h-48 sm:w-full'>
<View className='relative h-full sm:h-48 sm:w-full'>
<Suspense fallback={null}>
<Dog scale={2} position={[0, -1.6, 0]} rotation={[0.0, -0.3, 0]} />
<Common color={'lightpink'} />
<Common color={'lightpink'} orbit />
</Suspense>
</View>
</div>
{/* second row */}
<div className='relative my-12 h-48 w-full py-6 sm:w-1/2 md:mb-40'>
<View orbit className='relative h-full animate-bounce sm:h-48 sm:w-full'>
<View className='relative h-full animate-bounce sm:h-48 sm:w-full'>
<Suspense fallback={null}>
<Duck route='/blob' scale={2} position={[0, -1.6, 0]} />
<Common color={'lightblue'} />
<Common color={'lightblue'} orbit />
</Suspense>
</View>
</div>
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
},
"dependencies": {
"@ducanh2912/next-pwa": "^10.0.0",
"@react-three/drei": "^9.92.7",
"@react-three/fiber": "^8.15.12",
"@react-three/drei": "^9.120.6",
"@react-three/fiber": "^8.17.10",
"glsl-random": "^0.0.5",
"next": "^14.0.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"three": "^0.160.0",
"three-stdlib": "^2.28.9",
"tunnel-rat": "^0.1.2"
"three": "^0.172.0",
"three-stdlib": "^2.28.9"
},
"devDependencies": {
"@next/bundle-analyzer": "^14.0.4",
Expand Down
15 changes: 15 additions & 0 deletions src/components/canvas/Common.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use client'

import { Suspense } from 'react'
import { PerspectiveCamera, OrbitControls } from '@react-three/drei'

export const Common = ({ color, orbit }) => (
<Suspense fallback={null}>
{color && <color attach='background' args={[color]} />}
{orbit && <OrbitControls />}
<ambientLight />
<pointLight position={[20, 30, 10]} intensity={3} decay={0.2} />
<pointLight position={[-10, -10, -10]} color='blue' decay={0.2} />
<PerspectiveCamera makeDefault fov={40} position={[0, 0, 6]} />
</Suspense>
)
10 changes: 3 additions & 7 deletions src/components/canvas/Scene.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
'use client'

import { Canvas } from '@react-three/fiber'
import { Preload } from '@react-three/drei'
import { r3f } from '@/helpers/global'
import { Preload, View } from '@react-three/drei'
import * as THREE from 'three'

export default function Scene({ ...props }) {
// Everything defined in here will persist between route changes, only children are swapped
return (
<Canvas {...props}
onCreated={(state) => (state.gl.toneMapping = THREE.AgXToneMapping)}
>
{/* @ts-ignore */}
<r3f.Out />
<Canvas {...props} onCreated={(state) => (state.gl.toneMapping = THREE.AgXToneMapping)}>
<View.Port />
<Preload all />
</Canvas>
)
Expand Down
35 changes: 0 additions & 35 deletions src/components/canvas/View.jsx

This file was deleted.

7 changes: 0 additions & 7 deletions src/helpers/components/Three.jsx

This file was deleted.

3 changes: 0 additions & 3 deletions src/helpers/global.js

This file was deleted.