Skip to content

Commit

Permalink
fix: fallback when no webgl detected
Browse files Browse the repository at this point in the history
  • Loading branch information
Ph0enixKM committed May 28, 2024
1 parent 5dc0583 commit 0ed39a7
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 81 deletions.
4 changes: 0 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{
"extends": "next/core-web-vitals",
"rules": {
// Use single quotes instead of double quotes
"quotes": ["error", "single"],
// Disallow semicolons
"semi": ["error", "never"],
"@next/next/no-img-element": "off",
"react-hooks/exhaustive-deps": "off"
}
Expand Down
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"nextjs-toploader": "^1.4.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.13",
"swr": "^2.2.1",
"three": "^0.155.0",
"typescript": "5.1.6",
Expand Down
Binary file removed public/images/image.jpg
Binary file not shown.
4 changes: 4 additions & 0 deletions src/app/page.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
height: var(--size);
opacity: 0.7;
margin: 0 auto;

&.fallback {
mask-image: url('/internal/amber-docs.svg');
}
}

.jumbotron .amber {
Expand Down
163 changes: 87 additions & 76 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,86 +1,97 @@
'use client'

import style from './page.module.css'
import { getTableOfContents } from '@/utils/docs'
import SideBar from '@/components/SideBar/SideBar'
import Link from 'next/link'
import SearchBar from '@/components/SearchBar/SearchBar'
import Sheet from '@/components/Sheet/Sheet'
import SettingsGrid from '@/components/SettingsGrid/SettingsGrid'
import { Canvas, useFrame } from '@react-three/fiber'
import { useGLTF } from '@react-three/drei'
import { Suspense, useRef } from 'react'
import { Mesh } from 'three'
import { EffectComposer, Bloom } from '@react-three/postprocessing'
"use client";

import style from "./page.module.css";
import { getTableOfContents } from "@/utils/docs";
import SideBar from "@/components/SideBar/SideBar";
import Link from "next/link";
import SearchBar from "@/components/SearchBar/SearchBar";
import Sheet from "@/components/Sheet/Sheet";
import SettingsGrid from "@/components/SettingsGrid/SettingsGrid";
import { Canvas, useFrame } from "@react-three/fiber";
import { useGLTF } from "@react-three/drei";
import { Suspense, useRef } from "react";
import { Mesh } from "three";
import { EffectComposer, Bloom } from "@react-three/postprocessing";
import { ErrorBoundary } from "react-error-boundary";

function Scene() {
const amberModel = useGLTF('/internal/amber.glb')
const light = useRef(null)
const amberRef = useRef(null)
let frame = 0
const amberModel = useGLTF("/internal/amber.glb");
const light = useRef(null);
const amberRef = useRef(null);
let frame = 0;

useFrame(() => {
const amber: Mesh = amberRef.current!
amber.rotation.y -= 0.01
frame++
amber.position.y = Math.sin(frame / 50) / 8
if (frame < 100) {
// Increase scale logarithmically based on frame
const factor = Math.log(frame) / 4.6
amber.scale.set(factor, factor, factor)
}

})
useFrame(() => {
const amber: Mesh = amberRef.current!;
amber.rotation.y -= 0.01;
frame++;
amber.position.y = Math.sin(frame / 50) / 8;
if (frame < 100) {
// Increase scale logarithmically based on frame
const factor = Math.log(frame) / 4.6;
amber.scale.set(factor, factor, factor);
}
});

return (
<>
<ambientLight intensity={3} />
<pointLight ref={light} position={[-1, 1.6, 1]} intensity={5} color='#FFF380' />
<primitive object={amberModel.scene} ref={amberRef} position={[0.05, 0, 0]} scale={0.001} />
<EffectComposer>
<Bloom mipmapBlur luminanceThreshold={0.3} intensity={2} />
</EffectComposer>
</>
)
return (
<>
<ambientLight intensity={3} />
<pointLight
ref={light}
position={[-1, 1.6, 1]}
intensity={5}
color="#FFF380"
/>
<primitive
object={amberModel.scene}
ref={amberRef}
position={[0.05, 0, 0]}
scale={0.001}
/>
<EffectComposer>
<Bloom mipmapBlur luminanceThreshold={0.3} intensity={2} />
</EffectComposer>
</>
);
}

export default function Post() {
const [toc] = getTableOfContents()
const [toc] = getTableOfContents();

return (
<>
<div className='left'>
<SideBar headers={[]} isFixed />
</div>
<div className='right'>
<div className={style.container}>
<div className={style.jumbotron}>
<div className={style['jumbotron-bg']} />
<Suspense>
<div className={style.amber}>
<Canvas camera={{ position: [0, 0, 20] }}>
<Scene />
</Canvas>
</div>
</Suspense>
</div>
<div className={style.title}>
<span className={style.bold}>Amber</span>
<span className={style.light}>Docs</span>
</div>
<div className={style.search}>
<SearchBar variant='title' />
</div>
<Link href={toc.path} className={style['big-link']}>
{toc.title}
</Link>
</div>
</div>
<Sheet>
<SideBar headers={[]} />
<SettingsGrid />
</Sheet>
</>
)
return (
<>
<div className="left">
<SideBar headers={[]} isFixed />
</div>
<div className="right">
<div className={style.container}>
<div className={style.jumbotron}>
<ErrorBoundary fallback={<div className={[style["jumbotron-bg"], style.fallback].join(' ')} />}>
<div className={style["jumbotron-bg"]} />
<Suspense>
<div className={style.amber}>
<Canvas camera={{ position: [0, 0, 20] }}>
<Scene />
</Canvas>
</div>
</Suspense>
</ErrorBoundary>
</div>
<div className={style.title}>
<span className={style.bold}>Amber</span>
<span className={style.light}>Docs</span>
</div>
<div className={style.search}>
<SearchBar variant="title" />
</div>
<Link href={toc.path} className={style["big-link"]}>
{toc.title}
</Link>
</div>
</div>
<Sheet>
<SideBar headers={[]} />
<SettingsGrid />
</Sheet>
</>
);
}
2 changes: 1 addition & 1 deletion src/components/Icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ export default function Icon({ src, size, color }: Props) {
className={style.icon}
/>
)
}
}

0 comments on commit 0ed39a7

Please sign in to comment.