pmndrs / react-three-next

React Three Fiber, Threejs, Nextjs starter
https://react-three-next.vercel.app/
MIT License
2.52k stars 342 forks source link

V3 #95

Closed drcmda closed 2 years ago

drcmda commented 2 years ago

Downloads Discord Shield

:japanese_castle: React-Three-Next starter

A minimalist starter for React, React-three-fiber and Threejs solving some of the problems that WebGL creates, for instance bundle size, canvas being its own black box without integration, and unloading/re-loading everything on route changes.

This starter allows you to navigate seamlessly between pages with dynamic dom and/or canvas content without reloading or creating a new canvas every time. Context, routes and getStaticProps are all available inside the canvas, so that canvas contents can be swapped or react to routes.

⚫ Demo :

image

How to use

Installation

Tailwind is the default style. styled-components (styled) is also available.

yarn create r3f-app next my-app
# yarn create r3f-app <next> my-app <tailwind|styled>? -ts?

or

npx create-r3f-app next my-app

:passport_control: Typescript

For typescript add the parameter -ts or --typescript:

yarn create r3f-app next my-app -ts

or

npx create-r3f-app next my-app -ts

:mount_fuji: Features

:bullettrain_side: Architecture

Inform the nextjs page that the component is a Threejs component. For that, simply add the canvas property to the parent component.

export default function Page(props) {
  return <div>Hello !</div>
}
// Canvas contents go here
// It will receive same props as Page component (from getStaticProps, etc.)
Page.canvas = (props) => (
  <mesh>
    <boxGeometry />
    <meshBasicMaterial color='hotpink' />
  </mesh>
)

:control_knobs: Available Scripts

⬛ Stack

How to contribute :

git clone https://github.com/pmndrs/react-three-next
&& cd react-three-next && yarn install

Maintainers :

vercel[bot] commented 2 years ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
react-three-next ✅ Ready (Inspect) Visit Preview Nov 1, 2022 at 10:40AM (UTC)